unsigned char mail_setitem(struct map_session_data *sd, int idx, int amount) { if( pc_istrading(sd) ) return 1; if( idx == 0 ) { // Zeny Transfer if( amount < 0 || !pc_can_give_items(sd) ) return 1; if( amount > sd->status.zeny ) amount = sd->status.zeny; sd->mail.zeny = amount; // clif->updatestatus(sd, SP_ZENY); return 0; } else { // Item Transfer idx -= 2; mail->removeitem(sd, 0); if( idx < 0 || idx >= MAX_INVENTORY ) return 1; if( amount < 0 || amount > sd->status.inventory[idx].amount ) return 1; if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time || !itemdb_canmail(&sd->status.inventory[idx],pc_get_group_level(sd)) || (sd->status.inventory[idx].bound && !pc_can_give_bound_items(sd)) ) return 1; sd->mail.index = idx; sd->mail.nameid = sd->status.inventory[idx].nameid; sd->mail.amount = amount; return 0; } }
/** * Attempt to set item or zeny to a mail * @param sd : player attaching the content * @param idx 0 - Zeny; >= 2 - Inventory item * @param amount : amout of zeny or number of item * @return True if item/zeny can be set, False if failed */ bool mail_setitem(struct map_session_data *sd, short idx, uint32 amount) { if( pc_istrading(sd) ) return false; if( idx == 0 ) { // Zeny Transfer if( !pc_can_give_items(sd) ) return false; if( amount > sd->status.zeny ) amount = sd->status.zeny; sd->mail.zeny = amount; // clif_updatestatus(sd, SP_ZENY); return true; } else { // Item Transfer idx -= 2; mail_removeitem(sd, 0); if( idx < 0 || idx >= MAX_INVENTORY ) return false; if( amount > sd->status.inventory[idx].amount ) return false; if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time || !itemdb_available(sd->status.inventory[idx].nameid) || !itemdb_canmail(&sd->status.inventory[idx],pc_get_group_level(sd)) || (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ) return false; sd->mail.index = idx; sd->mail.nameid = sd->status.inventory[idx].nameid; sd->mail.amount = amount; return true; } }
/** * Attempt to set item or zeny * @param sd * @param idx 0 - Zeny; >= 2 - Inventory item * @param amount * @return True if item/zeny can be set, False if failed */ bool mail_setitem(struct map_session_data *sd, short idx, int amount) { if( sd->state.secure_items ) { clif_displaymessage(sd->fd, "You can't attach. Blocked with @security"); return 1; } if( pc_istrading(sd) ) return false; if( battle_config.super_woe_enable ) { clif_displaymessage(sd->fd, "Super WoE don't allow send items/zeny with attachments"); return 1; } if( idx == 0 ) { // Zeny Transfer if( !pc_can_give_items(sd) ) return false; if( amount > sd->status.zeny ) amount = sd->status.zeny; sd->mail.zeny = amount; // clif_updatestatus(sd, SP_ZENY); return true; } else { // Item Transfer idx -= 2; mail_removeitem(sd, 0); if( idx < 0 || idx >= MAX_INVENTORY ) return false; if( amount > sd->status.inventory[idx].amount ) return false; if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time || !itemdb_available(sd->status.inventory[idx].nameid) || !itemdb_canmail(&sd->status.inventory[idx],pc_get_group_level(sd)) || (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ) return false; sd->mail.index = idx; sd->mail.nameid = sd->status.inventory[idx].nameid; sd->mail.amount = amount; return true; } }
/** * Attempt to set item or zeny to a mail * @param sd : player attaching the content * @param idx 0 - Zeny; >= 2 - Inventory item * @param amount : amout of zeny or number of item * @return see enum mail_attach_result in mail.h */ enum mail_attach_result mail_setitem(struct map_session_data *sd, short idx, uint32 amount) { if( pc_istrading(sd) ) return MAIL_ATTACH_ERROR; if( idx == 0 ) { // Zeny Transfer if( !pc_can_give_items(sd) ) return MAIL_ATTACH_UNTRADEABLE; #if PACKETVER < 20150513 if( amount > sd->status.zeny ) amount = sd->status.zeny; // TODO: confirm this behavior for old mail system #else if( ( amount + battle_config.mail_zeny_fee / 100 * amount ) > sd->status.zeny ) return MAIL_ATTACH_ERROR; #endif sd->mail.zeny = amount; // clif_updatestatus(sd, SP_ZENY); return MAIL_ATTACH_SUCCESS; } else { // Item Transfer int i, j, total = 0; idx -= 2; if( idx < 0 || idx >= MAX_INVENTORY ) return MAIL_ATTACH_ERROR; #if PACKETVER < 20150513 i = 0; // Remove existing item mail_removeitem(sd, 0, sd->mail.item[i].index + 2, sd->mail.item[i].amount); #else ARR_FIND(0, MAIL_MAX_ITEM, i, sd->mail.item[i].index == idx && sd->mail.item[i].nameid > 0 ); // The same item had already been added to the mail if( i < MAIL_MAX_ITEM ){ // Check if it is stackable if( !itemdb_isstackable(sd->mail.item[i].nameid) ){ return MAIL_ATTACH_ERROR; } // Check if it exceeds the total amount if( ( amount + sd->mail.item[i].amount ) > sd->inventory.u.items_inventory[idx].amount ){ return MAIL_ATTACH_ERROR; } // Check if it exceeds the total weight if( battle_config.mail_attachment_weight ){ for( j = 0; j < i; j++ ){ total += sd->mail.item[j].amount * ( sd->inventory_data[sd->mail.item[j].index]->weight / 10 ); } total += amount * sd->inventory_data[idx]->weight / 10; if( total > battle_config.mail_attachment_weight ){ return MAIL_ATTACH_WEIGHT; } } sd->mail.item[i].amount += amount; return MAIL_ATTACH_SUCCESS; }else{ ARR_FIND(0, MAIL_MAX_ITEM, i, sd->mail.item[i].nameid == 0); if( i == MAIL_MAX_ITEM ){ return MAIL_ATTACH_SPACE; } // Check if it exceeds the total weight if( battle_config.mail_attachment_weight ){ for( j = 0; j < i; j++ ){ total += sd->mail.item[j].amount * ( sd->inventory_data[sd->mail.item[j].index]->weight / 10 ); } total += amount * sd->inventory_data[idx]->weight / 10; if( total > battle_config.mail_attachment_weight ){ return MAIL_ATTACH_WEIGHT; } } } #endif if( amount > sd->inventory.u.items_inventory[idx].amount ) return MAIL_ATTACH_ERROR; if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time || !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) || !itemdb_canmail(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) || (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ) return MAIL_ATTACH_UNTRADEABLE; sd->mail.item[i].index = idx; sd->mail.item[i].nameid = sd->inventory.u.items_inventory[idx].nameid; sd->mail.item[i].amount = amount; return MAIL_ATTACH_SUCCESS; } }
/// Attaches an item to a message being written /// @param sd : The player who's writting /// @param idx : the inventory idx of the item /// @param amount : Amount of the item to be attached void rodex_add_item(struct map_session_data *sd, int16 idx, int16 amount) { int i; bool is_stack = false; nullpo_retv(sd); if (idx < 0 || idx >= MAX_INVENTORY) { clif->rodex_add_item_result(sd, idx, amount, RODEX_ADD_ITEM_FATAL_ERROR); return; } if (amount < 0 || amount > sd->status.inventory[idx].amount) { clif->rodex_add_item_result(sd, idx, amount, RODEX_ADD_ITEM_FATAL_ERROR); return; } if (!pc_can_give_items(sd) || sd->status.inventory[idx].expire_time || !itemdb_canmail(&sd->status.inventory[idx], pc_get_group_level(sd)) || (sd->status.inventory[idx].bound && !pc_can_give_bound_items(sd))) { clif->rodex_add_item_result(sd, idx, amount, RODEX_ADD_ITEM_NOT_TRADEABLE); return; } if (itemdb->isstackable(sd->status.inventory[idx].nameid) == 1) { for (i = 0; i < RODEX_MAX_ITEM; ++i) { if (sd->rodex.tmp.items[i].idx == idx) { if (sd->status.inventory[idx].nameid == sd->rodex.tmp.items[i].item.nameid && sd->status.inventory[idx].unique_id == sd->rodex.tmp.items[i].item.unique_id) { is_stack = true; break; } } } if (i == RODEX_MAX_ITEM && sd->rodex.tmp.items_count < RODEX_MAX_ITEM) { ARR_FIND(0, RODEX_MAX_ITEM, i, sd->rodex.tmp.items[i].idx == 0); } } else if (sd->rodex.tmp.items_count < RODEX_MAX_ITEM) { ARR_FIND(0, RODEX_MAX_ITEM, i, sd->rodex.tmp.items[i].idx == 0); } else { i = RODEX_MAX_ITEM; } if (i == RODEX_MAX_ITEM) { clif->rodex_add_item_result(sd, idx, amount, RODEX_ADD_ITEM_NO_SPACE); return; } if (sd->rodex.tmp.items[i].item.amount + amount > sd->status.inventory[idx].amount) { clif->rodex_add_item_result(sd, idx, amount, RODEX_ADD_ITEM_FATAL_ERROR); return; } if (sd->rodex.tmp.weight + sd->inventory_data[idx]->weight * amount > RODEX_WEIGHT_LIMIT) { clif->rodex_add_item_result(sd, idx, amount, RODEX_ADD_ITEM_FATAL_ERROR); return; } sd->rodex.tmp.items[i].idx = idx; sd->rodex.tmp.weight += sd->inventory_data[idx]->weight * amount; if (is_stack == false) { sd->rodex.tmp.items[i].item = sd->status.inventory[idx]; sd->rodex.tmp.items[i].item.amount = amount; sd->rodex.tmp.items_count++; } else { sd->rodex.tmp.items[i].item.amount += amount; } sd->rodex.tmp.type |= MAIL_TYPE_ITEM; clif->rodex_add_item_result(sd, idx, amount, RODEX_ADD_ITEM_SUCCESS); }