/*
文件名:InvenClass.nut
路径:BaseClass/InvenClass/InvenClass.nut
创建日期:2024-04-18	13:26
文件用途:背包类
*/
class Inven extends Base_C_Object {

    static INVENTORY_TYPE_BODY = 0; //身上穿的装备(0-26)
    static INVENTORY_TYPE_ITEM = 1; //物品栏(0-311)
    static INVENTORY_TYPE_AVARTAR = 2; //时装栏(0-104)
    static INVENTORY_TYPE_CREATURE = 3; //宠物装备(0-241)


    SUser = null;

    constructor(CObject, gSUser) {
        base.constructor(CObject);
        SUser = gSUser;
    }

    //获得槽位里的对象
    function GetSlot(Type, Slot) {
        local P = Sq_Inven_GetItem(this.C_Object, Type, Slot);
        if (P) {
            return Item(P);
        }
        return null;
    }

    //通过ID获得槽位
    function GetSlotById(Idx) {
        return Sq_Inven_GetItemById(this.C_Object, Idx);
    }

    //检查背包是否拥有指定数量的指定道具
    function CheckItemCount(ItemId, ItemCount) {
        local SlotIdx = GetSlotById(ItemId);
        if (SlotIdx != -1) {
            local SlotItem = GetSlot(1, SlotIdx);
            if (SlotItem) {
                if (SlotItem.GetType() != "装备") {
                    if (SlotItem.GetAdd_Info() >= ItemCount) return true;
                }
            }
        }
        return false;
    }

    //检查背包是否拥有指定表的道具及数量
    function CheckArrItemCount(T) {
        local Flag = true;
        foreach(value in T) {
            if (!CheckItemCount(value.Id, value.Count)) Flag = false;
        }
        return Flag;
    }

    //销毁背包中指定表的道具及数量
    function DeleteArrItemCount(T) {
        foreach(value in T) {
            local Slot = GetSlotById(value.Id);
            Sq_Inven_RemoveItemFormCount(this.C_Object, 1, Slot, value.Count, 10, 1);
            SUser.SendUpdateItemList(1, 0, Slot);
        }
    }

    //销毁背包中指定的道具及数量
    function DeleteItemCount(Id, Count) {
        local Slot = GetSlotById(Id);
        local Ret = Sq_Inven_RemoveItemFormCount(this.C_Object, 1, Slot, Count, 10, 1);
        SUser.SendUpdateItemList(1, 0, Slot);
        return Ret;
    }

    //获取时装管理器
    function GetAvatarItemMgr() {
        return Sq_CallFunc(S_Ptr("0x80DD576"), "pointer", ["pointer"], this.C_Object);
    }
}