Example #1
0
 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));
 }
Example #2
0
 public void UpdateNewFlag(float deltaTime)
 {
     for (int i = 0; i < mSlotListArray.Length; i++)
     {
         SlotList list = mSlotListArray [i];
         list.UpdateNewFlag(deltaTime);
     }
 }
Example #3
0
        public ItemObject GetItem(ESlotType slotType, int index)
        {
            SlotList slotList = GetSlotList(slotType);

            if (null == slotList)
            {
                return(null);
            }

            return(slotList[index]);
        }
Example #4
0
        public int GetVacancySlotIndex(ESlotType slotType)
        {
            SlotList list = GetSlotList(slotType);

            if (null == list)
            {
                return(-1);
            }

            return(list.VacancyIndex());
        }
Example #5
0
        public ItemObject FindItemByProtoId(int protoId)
        {
            SlotList slotList = GetSlotList(protoId);

            if (null == slotList)
            {
                return(null);
            }

            return(slotList.FindItemByProtoId(protoId));
        }
Example #6
0
        public void Sort(ESlotType type)
        {
            SlotList slotList = GetSlotList(type);

            if (null == slotList)
            {
                return;
            }

            slotList.Reduce();
            slotList.Sort();
        }
Example #7
0
        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);
        }
Example #8
0
        bool SetSlotList(ESlotType itemClass, SlotList list)
        {
            if (itemClass == ESlotType.Max)
            {
                return(false);
            }

            mSlotListArray[(int)itemClass] = list;

            RegisterSlotEvent(itemClass);

            return(true);
        }
Example #9
0
        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));
        }
Example #10
0
        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));
        }
Example #11
0
        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);
            }
        }
Example #12
0
        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));
        }
Example #13
0
        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));
        }
Example #14
0
        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);
        }
Example #15
0
 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);
                 }
             }
         }
     }
 }
Example #16
0
        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);
        }
Example #17
0
        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);
        }
Example #18
0
        /// <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);
        }
Example #19
0
        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;
            }
        }