Пример #1
0
        public virtual EquippableSlot GetBestEquipSlot(ICharacterCollection equipCollection)
        {
            Assert.IsNotNull(equipCollection);

            var equipSlots = equipCollection.GetEquippableSlots(this);

            if (equipSlots.Length == 0)
            {
                DevdogLogger.LogVerbose("No equipment location found for item: #" + ID + " " + name);
                return(null);
            }

            EquippableSlot equipSlot = equipSlots[0];

            foreach (var e in equipSlots)
            {
                if (equipCollection.equippableSlots[e.index].slot.item == null)
                {
                    equipSlot = e; // Prefer an empty slot over swapping a filled one.
                    break;
                }
            }

            return(equipSlot);
        }
Пример #2
0
        /// <summary>
        /// Some item's require multiple slots, for example a 2 handed item forces the left handed item to be empty.
        /// </summary>
        /// <returns>true if items were removed, false if items were not removed.</returns>
        protected virtual bool HandleLocks(EquippableSlot equipSlot, EquippableInventoryItem equippable)
        {
            var toBeRemoved = new List <uint>(8);

            // Loop through things we want to block
            foreach (var blockType in equippable.equipmentType.blockTypes)
            {
                // Check every slot against this block type
                foreach (var field in equippableSlots)
                {
                    var item = items[field.index].item;
                    if (item != null)
                    {
                        var eq = (EquippableInventoryItem)item;
                        if (eq.equipmentType == blockType && field.index != equipSlot.index)
                        {
                            toBeRemoved.Add(field.index);
                            bool canAdd = InventoryManager.CanAddItem(eq);
                            if (canAdd == false)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            foreach (uint i in toBeRemoved)
            {
                bool added = InventoryManager.AddItemAndRemove(items[i].item);
                Assert.IsTrue(added, "Item could not be saved, even after check, please report this bug + stacktrace.");
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Called by the collection once the item is successfully equipped.
        /// </summary>
        public virtual void NotifyItemEquipped(EquippableSlot equipSlot, uint amountEquipped)
        {
            this.equippedToCollection = equipSlot.characterCollection;
            Assert.IsNotNull(equippedToCollection, "ICharacterCollection's player reference not set! Forgot to assign to player?");

            equipSlot.characterCollection.character.stats.ChangeAll(stats, 1f);
            AudioManager.AudioPlayOneShot(playOnEquip);
        }
        public override CharacterEquipmentTypeBinder FindEquipmentLocation(EquippableSlot slot)
        {
            foreach (var binder in characterCollection.character.equipmentBinders)
            {
                if (binder.equippableSlot == slot)
                {
                    return(binder);
                }
            }

            return(null);
        }
        /// <summary>
        /// Called by the collection once the item is successfully equipped.
        /// </summary>
        public virtual void NotifyItemEquipped(EquippableSlot equipSlot, uint amountEquipped)
        {
            this.equippedToCollection = equipSlot.characterCollection;
            Assert.IsNotNull(equippedToCollection, "ICharacterCollection's player reference not set! Forgot to assign to player?");

            foreach (var stat in stats)
            {
                stat.actionEffect = StatDecorator.ActionEffect.Add; // Force add effect for equippable stats.
            }

            equipSlot.characterCollection.character.stats.SetAll(stats, 1f);
            AudioManager.AudioPlayOneShot(playOnEquip);
        }
Пример #6
0
        public bool EquipItem(EquippableSlot equipSlot, EquippableInventoryItem item)
        {
            Assert.IsNotNull(item);

            bool handled = HandleLocks(equipSlot, item);

            if (handled == false)
            {
                return(false);
            }

            // The values before the collection / slot changed.
            uint fromIndex      = item.index;
            var  fromCollection = item.itemCollection;

            // There was already an item in this slot, un-equip that one first
            if (items[equipSlot.index].item != null)
            {
                bool unEquipped = UnEquipItem((EquippableInventoryItem)items[equipSlot.index].item, true);
                if (unEquipped == false)
                {
                    return(false);
                }
            }

            // EquippedItem the item -> Will swap as merge is not possible
            bool canSet = CanSetItem(equipSlot.index, item);

            if (canSet)
            {
                bool set = SetItem(equipSlot.index, item);
                if (set && fromCollection != null)
                {
                    if (useReferences == false)
                    {
                        fromCollection.SetItem(fromIndex, null);
                        fromCollection.NotifyItemRemoved(item, item.ID, fromIndex, item.currentStackSize);
                        fromCollection[fromIndex].Repaint();
                    }
                }

                NotifyItemAdded(item, item.currentStackSize, true);
                items[equipSlot.index].Repaint();

                return(true);
            }

            return(true);
        }
        /// <summary>
        /// Called by the collection once the item is successfully equipped.
        /// </summary>
        public virtual void NotifyItemEquipped(EquippableSlot equipSlot, uint amountEquipped)
        {
            this.equippedToCollection = equipSlot.characterCollection;
            Assert.IsNotNull(equippedToCollection, "ICharacterCollection's player reference not set! Forgot to assign to player?");

            foreach (var stat in stats)
            {
                stat.actionEffect = StatDecorator.ActionEffect.Add; // Force add effect for equippable stats.
            }

            equipSlot.characterCollection.character.stats.SetAll(stats, 1f);
            GameObject p = GameObject.FindGameObjectWithTag("Player");

            Debug.Log(p.name);
            p.GetComponent <PlayerMovement>().UpdateEquippedGear();
            AudioManager.AudioPlayOneShot(playOnEquip);
        }
        public override void EquipItemVisually(EquippableInventoryItem item, EquippableSlot slot)
        {
            if (item.equipVisually == false)
            {
                return;
            }

            var binder = FindEquipmentLocation(slot);

            if (binder != null)
            {
                var t = GetEquippableTypeFromItem(binder, item);
                item.visuallyEquippedToBinder = binder;
                var copy = t.equipmentHandler.Equip(item, binder, true);

                binder.currentItem = copy.gameObject;
                NotifyItemEquippedVisually(binder, copy);
            }
        }
Пример #9
0
        public virtual void UpdateEquippableSlots()
        {
            equippableSlots = new EquippableSlot[items.Length];
            for (int i = 0; i < items.Length; i++)
            {
                var c = items[i] as UnityEngine.Component;
                if (c != null)
                {
                    equippableSlots[i] = c.gameObject.GetComponent <EquippableSlot>();
                    Assert.IsNotNull(equippableSlots[i], "CharacterUI manually defined collection contains gameObject without InventoryEquippableField component.");

                    if (equippableSlots[i].equipmentTypes.Any(o => o == null))
                    {
                        DevdogLogger.LogError("CharacterUI's equipTypes contains null (empty) field.", equippableSlots[i].gameObject);
                    }
                }
            }

            if (equippableSlots.Any(o => o == null))
            {
                DevdogLogger.LogError("This characterUI has an empty reference in the equip slot fields (EquippableFields has empty row)", gameObject);
            }
        }
Пример #10
0
 public bool Equip(EquippableSlot equipSlot)
 {
     return(equipSlot.characterCollection.EquipItem(equipSlot, this));
 }
Пример #11
0
 public CharacterEquipmentTypeBinder(EquippableSlot equippableSlot, Transform equipTransform)
 {
     this.equippableSlot = equippableSlot;
     this.equipTransform = equipTransform;
 }
 public abstract void EquipItemVisually(EquippableInventoryItem item, EquippableSlot specificSlot);
 public abstract CharacterEquipmentTypeBinder FindEquipmentLocation(EquippableSlot slot);