viewing paste Unknown #35781 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*==========================================
 * Append a card to an item ?
 *------------------------------------------*/
int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip)
{
        int i;
        unsigned short nameid;
 
        nullpo_ret(sd);
 
        if( idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL )
                return 0; //Invalid item index.
        if( idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL )
                return 0; //Invalid card index.
        if( sd->inventory.u.items_inventory[idx_equip].nameid <= 0 || sd->inventory.u.items_inventory[idx_equip].amount < 1 )
                return 0; // target item missing
        if( sd->inventory.u.items_inventory[idx_card].nameid <= 0 || sd->inventory.u.items_inventory[idx_card].amount < 1 )
                return 0; // target card missing
        if( sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR )
                return 0; // only weapons and armor are allowed
        if( sd->inventory_data[idx_card]->type != IT_CARD )
                return 0; // must be a card
        if( sd->inventory.u.items_inventory[idx_equip].identify == 0 )
                return 0; // target must be identified
        if( itemdb_isspecial(sd->inventory.u.items_inventory[idx_equip].card[0]) )
                return 0; // card slots reserved for other purposes
        if( (sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0 )
                return 0; // card cannot be compounded on this item type
        if( sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD )
                return 0; // attempted to place shield card on left-hand weapon.
        if( sd->inventory.u.items_inventory[idx_equip].equip != 0 )
                return 0; // item must be unequipped
 
        ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->inventory.u.items_inventory[idx_equip].card[i] == 0 );
        if( i == sd->inventory_data[idx_equip]->slot )
                return 0; // no free slots
 
        // remember the card id to insert
        nameid = sd->inventory.u.items_inventory[idx_card].nameid;
 
        if( pc_delitem(sd,idx_card,1,1,0,LOG_TYPE_OTHER) == 1 )
        {// failed
                clif_insert_card(sd,idx_equip,idx_card,1);
        }
        else
        {// success
                log_pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->inventory.u.items_inventory[idx_equip]);
                sd->inventory.u.items_inventory[idx_equip].card[i] = nameid;
                log_pick_pc(sd, LOG_TYPE_OTHER,  1, &sd->inventory.u.items_inventory[idx_equip]);
                clif_insert_card(sd,idx_equip,idx_card,0);
        }
 
        return 0;
}
 
Viewed 574 times, submitted by unknown.