Exemplo n.º 1
0
 /// <summary>
 /// Equips the item at the specified slot
 /// </summary>
 /// <param name="item">Item.</param>
 /// <param name="index">Index.</param>
 /// <param name="slot">Slot.</param>
 public virtual void EquipItem(InventoryItem item, int index, InventorySlot slot = null)
 {
     if (InventoryType == Inventory.InventoryTypes.Main)
     {
         InventoryItem oldItem = null;
         if (InventoryItem.IsNull(item))
         {
             MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, slot, this.name, null, 0, index));
             return;
         }
         // if the object is not equipable, we do nothing and exit
         if (!item.Equippable)
         {
             return;
         }
         // if a target equipment inventory is not set, we do nothing and exit
         if (item.TargetEquipmentInventory == null)
         {
             Debug.LogWarning("InventoryEngine Warning : " + Content[index].ItemName + "'s target equipment inventory couldn't be found.");
             return;
         }
         // if the object can't be moved, we play an error sound and exit
         if (!item.CanMoveObject)
         {
             MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, slot, this.name, null, 0, index));
             return;
         }
         // call the equip method of the item
         item.Equip();
         // if this is a mono slot inventory, we prepare to swap
         if (item.TargetEquipmentInventory.Content.Length == 1)
         {
             if (!InventoryItem.IsNull(item.TargetEquipmentInventory.Content[0]))
             {
                 if (
                     (item.CanSwapObject) &&
                     (item.TargetEquipmentInventory.Content[0].CanMoveObject) &&
                     (item.TargetEquipmentInventory.Content[0].CanSwapObject)
                     )
                 {
                     // we store the item in the equipment inventory
                     oldItem = item.TargetEquipmentInventory.Content[0].Copy();
                     item.TargetEquipmentInventory.EmptyInventory();
                 }
             }
         }
         // we add one to the target equipment inventory
         item.TargetEquipmentInventory.AddItem(item.Copy(), item.Quantity);
         // remove 1 from quantity
         RemoveItem(index, item.Quantity);
         if (oldItem != null)
         {
             oldItem.Swap();
             AddItem(oldItem, oldItem.Quantity);
         }
         MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ItemEquipped, slot, this.name, item, item.Quantity, index));
     }
 }