Ejemplo n.º 1
0
/**
 * Creates a new homunculus with the given data.
 *
 * @remark
 *   The homunculus ID is expected to be 0, and will be filled with the newly
 *   assigned ID.
 *
 * @param[in,out] hd The new homunculus' data.
 * @retval false in case of errors.
 */
bool mapif_homunculus_create(struct s_homunculus *hd)
{
	char esc_name[NAME_LENGTH*2+1];

	nullpo_retr(false, hd);
	Assert_retr(false, hd->hom_id == 0);

	SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH));

	if (SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` "
			"(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) "
			"VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
			homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
			hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize)) {
		Sql_ShowDebug(inter->sql_handle);
		return false;
	}
	hd->hom_id = (int)SQL->LastInsertId(inter->sql_handle);
	return true;
}
Ejemplo n.º 2
0
/**
 * Saves an existing homunculus.
 *
 * @param hd The homunculus' data.
 * @retval false in case of errors.
 */
bool mapif_homunculus_save(const struct s_homunculus *hd)
{
	bool flag = true;
	char esc_name[NAME_LENGTH*2+1];

	nullpo_retr(false, hd);
	Assert_retr(false, hd->hom_id > 0);

	SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH));

	if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'",
			homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
			hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id)) {
		Sql_ShowDebug(inter->sql_handle);
		flag = false;
	} else {
		int i;
		SqlStmt *stmt = SQL->StmtMalloc(inter->sql_handle);

		if (SQL_ERROR == SQL->StmtPrepare(stmt, "REPLACE INTO `%s` (`homun_id`, `id`, `lv`) VALUES (%d, ?, ?)", skill_homunculus_db, hd->hom_id)) {
			SqlStmt_ShowDebug(stmt);
			flag = false;
		} else {
			for (i = 0; i < MAX_HOMUNSKILL; ++i) {
				if (hd->hskill[i].id > 0 && hd->hskill[i].lv != 0) {
					SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, (void*)&hd->hskill[i].id, 0); // FIXME: StmtBindParam should take const void
					SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, (void*)&hd->hskill[i].lv, 0); // FIXME: StmtBindParam should take const void
					if (SQL_ERROR == SQL->StmtExecute(stmt)) {
						SqlStmt_ShowDebug(stmt);
						flag = false;
						break;
					}
				}
			}
		}
		SQL->StmtFree(stmt);
	}

	return flag;
}
Ejemplo n.º 3
0
bool mail_setattachment(struct map_session_data *sd, struct mail_message *msg)
{
	int n;

	nullpo_retr(false,sd);
	nullpo_retr(false,msg);

	if( sd->mail.zeny < 0 || sd->mail.zeny > sd->status.zeny )
		return false;

	n = sd->mail.index;
	Assert_retr(false, n >= 0 && n < MAX_INVENTORY);
	if( sd->mail.amount )
	{
		if( sd->status.inventory[n].nameid != sd->mail.nameid )
			return false;

		if( sd->status.inventory[n].amount < sd->mail.amount )
			return false;

		if( sd->weight > sd->max_weight )
			return false;

		memcpy(&msg->item, &sd->status.inventory[n], sizeof(struct item));
		msg->item.amount = sd->mail.amount;
		if (msg->item.amount != sd->mail.amount)  // check for amount overflow
			return false;
	}
	else
		memset(&msg->item, 0x00, sizeof(struct item));

	msg->zeny = sd->mail.zeny;

	// Removes the attachment from sender
	mail->removeitem(sd,1);
	mail->removezeny(sd,1);

	return true;
}