Esempio n. 1
0
        public void RestoreState(object state)
        {
            equippedItems = new Dictionary <EquipLocation, EquipableItem[]>();
            equippedStats = new Dictionary <Stat, float[]>();

            SlotRecords slotRecords = (SlotRecords)state;
            var         equippedItemsForSerialization = slotRecords.locationItems;
            var         equippedItemModifiers         = (Dictionary <EquipLocation, object[]>)slotRecords.modifiers;

            foreach (var pair in equippedItemsForSerialization)
            {
                var items = new EquipableItem[pair.Value.Length];
                for (int i = 0; i < items.Length; i++)
                {
                    EquipableItem candidate = InventoryItem.GetFromID(pair.Value[i]) as EquipableItem;
                    if (candidate != null)
                    {
                        items[i] = candidate;
                        AddEquipmentStats(items[i]);
                        items[i].SetModifiers(equippedItemModifiers[pair.Key][i]);
                    }
                }
                equippedItems[pair.Key] = items;
            }
        }
Esempio n. 2
0
        // Handles equipping via right click from inventory
        public int TryAddItem(InventoryItem item)
        {
            // Check if it's an equipable item
            EquipableItem equipableItem = item as EquipableItem;

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

            // Get location and check number of slots. If 1, add or swap items
            EquipLocation equipLocation = equipableItem.GetAllowedEquipLocation();

            if (!equippedItems.ContainsKey(equipLocation))
            {
                return(-1);
            }

            if (equippedItems[equipLocation].Length == 1)
            {
                return(0);
            }

            // Otherwise check for empty slot. Don't swap if all slots for equip type are full
            int index = FindEmptySlot(equipLocation);

            if (index >= 0)
            {
                return(index);
            }

            return(-1);
        }
Esempio n. 3
0
        /// <summary>
        /// Add an item to the given equip location. Do not attempt to equip to
        /// an incompatible slot.
        /// </summary>
        public void AddItem(EquipLocation slot, EquipableItem item, int index, object state = null)
        {
            Debug.Assert(item.GetAllowedEquipLocation() == slot);

            equippedItems[slot][index] = item;

            AddEquipmentStats(item);
            if (state != null)
            {
                equippedItems[slot][index].SetModifiers(state);
            }

            if (equipmentUpdated != null)
            {
                equipmentUpdated();
                equipmentEffectsUpdated.Invoke();
            }
        }
Esempio n. 4
0
        private void AddEquipmentStats(EquipableItem item)
        {
            if (item == null)
            {
                return;
            }

            Dictionary <Stat, float[]> equipDict = item.GetStatValues();

            foreach (var pair in equipDict)
            {
                if (!equippedStats.ContainsKey(pair.Key))
                {
                    equippedStats[pair.Key] = pair.Value;
                }
                else
                {
                    equippedStats[pair.Key][0] += pair.Value[0];
                    equippedStats[pair.Key][1] += pair.Value[1];
                }
            }
        }