public void ExtendPackage(int itemMax, int equipmentMax, int recourceMax, int armorMax) { SetSlotList(ESlotType.Item, SlotList.ResetCapacity(GetSlotList(ESlotType.Item), itemMax)); SetSlotList(ESlotType.Equipment, SlotList.ResetCapacity(GetSlotList(ESlotType.Equipment), equipmentMax)); SetSlotList(ESlotType.Resource, SlotList.ResetCapacity(GetSlotList(ESlotType.Resource), recourceMax)); SetSlotList(ESlotType.Armor, SlotList.ResetCapacity(GetSlotList(ESlotType.Armor), armorMax)); }
public void UpdateNewFlag(float deltaTime) { for (int i = 0; i < mSlotListArray.Length; i++) { SlotList list = mSlotListArray [i]; list.UpdateNewFlag(deltaTime); } }
public ItemObject GetItem(ESlotType slotType, int index) { SlotList slotList = GetSlotList(slotType); if (null == slotList) { return(null); } return(slotList[index]); }
public int GetVacancySlotIndex(ESlotType slotType) { SlotList list = GetSlotList(slotType); if (null == list) { return(-1); } return(list.VacancyIndex()); }
public ItemObject FindItemByProtoId(int protoId) { SlotList slotList = GetSlotList(protoId); if (null == slotList) { return(null); } return(slotList.FindItemByProtoId(protoId)); }
public void Sort(ESlotType type) { SlotList slotList = GetSlotList(type); if (null == slotList) { return; } slotList.Reduce(); slotList.Sort(); }
public static SlotList ResetCapacity(SlotList origin, int capacity) { SlotList slots = new SlotList(capacity); if (null == origin) { return(slots); } Array.Copy(origin.mSlots, slots.mSlots, Mathf.Min(origin.Length, capacity)); return(slots); }
bool SetSlotList(ESlotType itemClass, SlotList list) { if (itemClass == ESlotType.Max) { return(false); } mSlotListArray[(int)itemClass] = list; RegisterSlotEvent(itemClass); return(true); }
public int PutItem(ItemObject item, int slotIndex, ESlotType slotType) { if (slotType == ESlotType.Max) { slotType = (ESlotType)item.protoData.tabIndex; } SlotList slotList = GetSlotList(slotType); SetItem(slotList, item, slotIndex); return(CodeIndex(slotType, slotIndex)); }
public int FindItemIndexByProtoId(int protoId) { ESlotType eSlotType = GetSlotType(protoId); SlotList slotList = GetSlotList(eSlotType); if (null == slotList) { return(-1); } int index = slotList.FindItemIndexByProtoId(protoId); return(CodeIndex(eSlotType, index)); }
public void Export(BinaryWriter w) { for (int i = (int)ESlotType.Item; i < (int)ESlotType.Max; i++) { byte[] buff = null; SlotList list = GetSlotList((ESlotType)i); if (null != list) { buff = list.Export(); } PETools.Serialize.WriteBytes(buff, w); } }
public int AddItem(ItemObject itemObject, bool isNew = false) { ESlotType eSlotType = GetSlotType(itemObject.protoId); SlotList slotList = GetSlotList(eSlotType); int vacancyIndex = slotList.VacancyIndex(); if (-1 == vacancyIndex) { return(InvalidIndex); } SetItem(slotList, itemObject, vacancyIndex, isNew); return(CodeIndex(eSlotType, vacancyIndex)); }
public bool HasItemObj(ItemObject itemObject) { if (null == itemObject) { return(false); } SlotList list = GetSlotList(itemObject.protoId); if (null == list) { return(false); } return(list.HasItem(itemObject.instanceId)); }
public int GetItemIndexById(int instanceId) { for (int i = (int)ESlotType.Item; i < (int)ESlotType.Max; i++) { SlotList list = mSlotListArray[i]; if (null != list) { int slotIndex = list.FindItemIndexById(instanceId); if (slotIndex != -1) { return(CodeIndex((ESlotType)i, slotIndex)); } } } return(InvalidIndex); }
public void Import(byte[] buffer) { using (MemoryStream ms = new MemoryStream(buffer, false)) { using (BinaryReader r = new BinaryReader(ms)) { for (int i = (int)ESlotType.Item; i < (int)ESlotType.Max; i++) { byte[] buff = PETools.Serialize.ReadBytes(r); if (null != buff && buff.Length > 0) { SlotList list = new SlotList(); list.Import(buff); SetSlotList((ESlotType)i, list); } } } } }
void SetItem(SlotList slotList, ItemObject item, int index, bool isNew = false) { slotList[index] = item; if (isNew) { slotList.newFlagMgr.Add(index); } else { slotList.newFlagMgr.Remove(index); } EventArg e = new EventArg() { op = (item == null? EventArg.Op.Reset : EventArg.Op.Put), itemObj = item }; changeEventor.Dispatch(e); }
public bool CanAddItemList(IEnumerable <ItemObject> items) { int[] itemCount = new int[(int)ESlotType.Max]; foreach (ItemObject obj in items) { itemCount[obj.protoData.tabIndex]++; } for (int i = 0; i < (int)ESlotType.Max; i++) { SlotList list = GetSlotList((ESlotType)i); if (list.GetVacancyCount() < itemCount[i]) { return(false); } } return(true); }
/// <summary> /// remove an item by coded index /// </summary> /// <param name="codedIndex">coded index, create by CodeIndex()</param> public bool RemoveItem(int codedIndex) { int slotIndex; ESlotType slotType; if (!DecodeIndex(codedIndex, out slotType, out slotIndex)) { return(false); } SlotList slotList = GetSlotList(slotType); if (slotList == null) { return(false); } SetItem(slotList, null, slotIndex); return(true); }
void RegisterSlotEvent(ESlotType slotType) { SlotList list = GetSlotList(slotType); switch (slotType) { case ESlotType.Item: if (null != list) { list.eventor.Subscribe(ItemSlotListMsgHandler); } break; case ESlotType.Equipment: if (null != list) { list.eventor.Subscribe(EquipmentSlotListMsgHandler); } break; case ESlotType.Resource: if (null != list) { list.eventor.Subscribe(ResourceSlotListMsgHandler); } break; case ESlotType.Armor: if (null != list) { list.eventor.Subscribe(ArmorSlotListMsgHandler); } break; default: break; } }