/// <summary> /// Attempt to equip item. /// </summary> /// <param name="item">Item to equip.</param> /// <param name="alwaysEquip">Always equip item, replacing another in the same slot if needed.</param> /// <returns>True when item equipped, otherwise false.</returns> public List <DaggerfallUnityItem> EquipItem(DaggerfallUnityItem item, bool alwaysEquip = true, bool playEquipSounds = true) { if (item == null) { return(null); } // Get slot for this item EquipSlots slot = GetEquipSlot(item); if (slot == EquipSlots.None) { return(null); } // If more than one item selected, equip only one if (item.IsAStack()) { item = GameManager.Instance.PlayerEntity.Items.SplitStack(item, 1); } List <DaggerfallUnityItem> unequippedList = new List <DaggerfallUnityItem>(); // Special weapon handling if (item.ItemGroup == ItemGroups.Weapons) { // Cannot equip arrows if (item.TemplateIndex == (int)Weapons.Arrow) { return(null); } // Equipping a 2H weapons will always unequip both hands if (GetItemHands(item) == ItemHands.Both) { UnequipItem(EquipSlots.LeftHand, unequippedList); UnequipItem(EquipSlots.RightHand, unequippedList); } } // Equipping a shield will always unequip 2H weapon if (GetItemHands(item) == ItemHands.LeftOnly) { // If holding a 2H weapon then unequip DaggerfallUnityItem rightHandItem = equipTable[(int)EquipSlots.RightHand]; if (rightHandItem != null && GetItemHands(rightHandItem) == ItemHands.Both) { UnequipItem(EquipSlots.RightHand, unequippedList); } } // Unequip any previous item if (!IsSlotOpen(slot) && !alwaysEquip) { return(null); } else { UnequipItem(slot, unequippedList); } PlayerEntity player = GameManager.Instance.PlayerEntity; // Equip item to slot item.EquipSlot = slot; equipTable[(int)slot] = item; // Play equip sound if (playEquipSounds) { DaggerfallUI.Instance.PlayOneShot(item.GetEquipSound()); } // Allow entity effect manager to start any enchantments on this item StartEquippedItem(item); //Debug.Log(string.Format("Equipped {0} to {1}", item.LongName, slot.ToString())); if (parentEntity == player) { GameManager.Instance.PlayerEntity.EquipmentEncumbranceSpeedMod = GameManager.Instance.PlayerEntity.UpdateEquipmentEncumbranceState(); } return(unequippedList); }
/// <summary> /// Attempt to equip item. /// </summary> /// <param name="item">Item to equip.</param> /// <param name="alwaysEquip">Always equip item, replacing another in the same slot if needed.</param> /// <returns>True when item equipped, otherwise false.</returns> public List <DaggerfallUnityItem> EquipItem(DaggerfallUnityItem item, bool alwaysEquip = true, bool playEquipSounds = true) { if (item == null) { return(null); } // Get slot for this item EquipSlots slot = GetEquipSlot(item); if (slot == EquipSlots.None) { return(null); } List <DaggerfallUnityItem> unequippedList = new List <DaggerfallUnityItem>(); // Special weapon handling if (item.ItemGroup == ItemGroups.Weapons) { // Cannot equip arrows if (item.TemplateIndex == (int)Weapons.Arrow) { return(null); } // Equipping a 2H weapons will always unequip both hands if (GetItemHands(item) == ItemHands.Both) { UnequipItem(EquipSlots.LeftHand, unequippedList); UnequipItem(EquipSlots.RightHand, unequippedList); } } // Equipping a shield will always unequip 2H weapon if (item.ItemGroup == ItemGroups.Armor && (item.TemplateIndex == (int)Armor.Kite_Shield || item.TemplateIndex == (int)Armor.Round_Shield || item.TemplateIndex == (int)Armor.Tower_Shield || item.TemplateIndex == (int)Armor.Buckler)) { // If holding a 2H weapon then unequip DaggerfallUnityItem rightHandItem = equipTable[(int)EquipSlots.RightHand]; if (rightHandItem != null && GetItemHands(rightHandItem) == ItemHands.Both) { UnequipItem(EquipSlots.RightHand, unequippedList); } } // Unequip any previous item if (!IsSlotOpen(slot) && !alwaysEquip) { return(null); } else { UnequipItem(slot, unequippedList); } // Equip item to slot item.EquipSlot = slot; equipTable[(int)slot] = item; // Play equip sound if (playEquipSounds) { DaggerfallUI.Instance.PlayOneShot(item.GetEquipSound()); } // Allow entity effect manager to start any enchantments on this item StartEquippedItem(item); //Debug.Log(string.Format("Equipped {0} to {1}", item.LongName, slot.ToString())); return(unequippedList); }