viewing paste Unknown #35780 | 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/*==========================================
 * 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->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1 )
        return 0; // target item missing
    if( sd->status.inventory[idx_card].nameid <= 0 || sd->status.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->status.inventory[idx_equip].identify == 0 )
        return 0; // target must be identified
    if( itemdb_isspecial(sd->status.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( itemdb_isenchant(sd->status.inventory[idx_card].nameid) && sd->inventory_data[idx_equip]->slot > 3 )
        return 0; // Reserved slot for Enchant is a normal slot
    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->status.inventory[idx_equip].equip != 0 )
        return 0; // item must be unequipped
 
    // remember the card id to insert
    nameid = sd->status.inventory[idx_card].nameid;
 
    if( itemdb_isenchant(nameid) )
    {
        switch( sd->inventory_data[idx_equip]->nameid )
        { // Non Enchantable Equipment
        case 2357: return 0;
        }
        i = 3; // Enchant Slot - Can overwrite current enchant
    }
    else
    {
        ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0 );
        if( i == sd->inventory_data[idx_equip]->slot )
            return 0; // no free slots
    }
 
    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->status.inventory[idx_equip]);
        sd->status.inventory[idx_equip].card[i] = nameid;
        log_pick_pc(sd, LOG_TYPE_OTHER,  1, &sd->status.inventory[idx_equip]);
        clif_insert_card(sd,idx_equip,idx_card,0);
        if( itemdb_isenchant(nameid) )
        {
            clif_delitem(sd,idx_equip,1,3);
            clif_additem(sd,idx_equip,1,0);
        }
    }
 
    return 0;
}
Viewed 904 times, submitted by Guest.