public bool EquipArms(Armament arms, Slot intoSlot) { //get the equipped into slots arms.EquipRequirements(this, intoSlot, out Slot[] usedSlots, out _); //try to stop all arms in those slots foreach (Slot usedSlot in usedSlots) { ArmamentPrefab current = GetArms(usedSlot); if (current != null && CanUnequip() == false) { return(false); } } //finally, spawn/despawn prefab and update references ArmamentPrefab prefab = arms.SpawnPrefab(this, equipmentParent, usedSlots, equipmentTransforms); foreach (Slot usedSlot in usedSlots) { UnequipArms(usedSlot); equippedArms[(int)usedSlot] = prefab; OnEquipmentUpdate?.Invoke(usedSlot, prefab); } return(true); }
public bool UnequipArms(Slot fromSlot, int targetIndex = -1, bool discard = false, bool drop = false) { ArmamentPrefab prefab = equippedArms[(int)fromSlot]; if (prefab == null) { return(true); } if (CanUnequip() == false) { return(false); } Armament arms = prefab.armsScriptable; arms.DespawnPrefab(prefab); foreach (Slot usedSlot in prefab.usedSlots) { equippedArms[(int)usedSlot] = null; OnEquipmentUpdate?.Invoke(usedSlot, null); } if (discard) { return(true); } //add into inventory if (drop == false && AddItem(arms, 1, out int addedIndex)) { if (targetIndex != -1 && 1 == inventory[addedIndex].count) { Reorder(addedIndex, targetIndex); } } else { //drop onto the floor SpawnDroppedItem(new InventoryEntry(1, arms)); } return(true); }