186 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			186 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名: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) {
 | |
|         if (ItemId == 0) {
 | |
|             //检查金币
 | |
|             local Money = Sq_CallFunc(S_Ptr("0x817a188"), "int", ["pointer"], SUser.C_Object);
 | |
|             if (Money >= ItemCount) {
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
|         if (ItemId == -1) {
 | |
|             //检查点券
 | |
|             if (SUser.GetCera() >= ItemCount) {
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
|         if (ItemId == -2) {
 | |
|             //检查代币券
 | |
|             if (SUser.GetCeraPoint() >= ItemCount) {
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         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) {
 | |
|         if (Id == 0) {
 | |
|             //处理金币
 | |
|             SUser.RechargeMoney(-Count);
 | |
|             return 1;
 | |
|         }
 | |
|         if (Id == -1) {
 | |
|             //处理点券
 | |
|             SUser.RechargeCera(-Count);
 | |
|             return 1;
 | |
|         }
 | |
|         if (Id == -2) {
 | |
|             //处理代币券
 | |
|             SUser.RechargeCeraPoint(-Count);
 | |
|             return 1;
 | |
|         }
 | |
| 
 | |
|         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);
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //销毁背包中指定表的道具及数量 并且需要格子匹配
 | |
|     function DeleteArrItemCountRindro(T) {
 | |
|         foreach(value in T) {
 | |
|             if (value.type == 0) {
 | |
|                 //如果是装备 按格子直接删除
 | |
|                 Sq_Inven_RemoveItemFormCount(this.C_Object, 1, value.pos, value.count, 10, 1);
 | |
|                 SUser.SendUpdateItemList(1, 0, value.pos);
 | |
|             } else {
 | |
|                 //如果不是装备 走原逻辑
 | |
|                 local Slot = GetSlotById(value.itemId);
 | |
|                 Sq_Inven_RemoveItemFormCount(this.C_Object, 1, Slot, value.count, 10, 1);
 | |
|                 SUser.SendUpdateItemList(1, 0, Slot);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //检查背包是否拥有指定表的道具及数量 并且是装备还要匹配格子
 | |
|     function CheckArrItemCountRindro(T) {
 | |
|         local Flag = true;
 | |
|         foreach(value in T) {
 | |
|             if (!CheckItemCountRindro(value.itemId, value.count, value.pos)) Flag = false;
 | |
|         }
 | |
|         return Flag;
 | |
|     }
 | |
| 
 | |
|     //检查背包是否拥有指定数量的指定道具
 | |
|     function CheckItemCountRindro(ItemId, ItemCount, Slot) {
 | |
|         if (ItemId == 0) {
 | |
|             //检查金币
 | |
|             local Money = Sq_CallFunc(S_Ptr("0x817a188"), "int", ["pointer"], SUser.C_Object);
 | |
|             if (Money >= ItemCount) {
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
|         if (ItemId == -1) {
 | |
|             //检查点券
 | |
|             if (SUser.GetCera() >= ItemCount) {
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
|         if (ItemId == -2) {
 | |
|             //检查代币券
 | |
|             if (SUser.GetCeraPoint() >= ItemCount) {
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         local SlotIdx = GetSlotById(ItemId);
 | |
|         if (SlotIdx != -1) {
 | |
|             local SlotItem = GetSlot(1, SlotIdx);
 | |
|             if (SlotItem) {
 | |
|                 if (SlotItem.GetType() != "装备") {
 | |
|                     if (SlotItem.GetAdd_Info() >= ItemCount) return true;
 | |
|                 } else {
 | |
|                     //如果是装备 检查格子所在的道具id
 | |
|                     local ItemId2 = GetSlot(1, Slot).GetIndex();
 | |
|                     //如果这个格子的道具id就是发来的id  那么返回true
 | |
|                     if (ItemId == ItemId2) {
 | |
|                         return true;
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         return false;
 | |
|     }
 | |
| } |