public bool Equip(Equipment newStatsToAdd, bool silent = false) { if (VendorWindow.IsOpen) { return(false); } int slotIndex = (int)newStatsToAdd.equipSlot; /// These item are set to null to start with because we invoke a callback that /// will remove the stats from olditem and add the stats on newitem. only populate them /// if we are about the replace an item. Equipment oldStatsToRemove = null; Equipment oldOffhand = null; // newItem = Bow if (slotIndex == 3 && (int)newStatsToAdd.equipType == 1) { if (DebugControl.debugInventory) { Debug.Log("Adding Bow as a new item"); } /// if player has items equipped in both main and offhand if (currentEquipment[3] != null && currentEquipment[4] != null) { if (DebugControl.debugInventory) { Debug.Log("player has items equipped in both main and offhand"); } oldStatsToRemove = currentEquipment[3]; oldOffhand = currentEquipment[4]; stats.RemoveItemStats(oldOffhand); /// if there is space for the item in the inventory if (inventory.MyEmptySlotCount >= 2) { ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex); SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItemToFirstInvSlot(oldStatsToRemove); inventory.AddItemToSecondInvSlot(oldOffhand); } else if (inventory.MyEmptySlotCount == 1) { if (DebugControl.debugInventory) { Debug.Log("Have only 1 slot available"); } SlotScript one = inventory.GetSlotScript(0); SlotScript two = inventory.GetSlotScript(1); SlotInfo firstSlot = SaveItemInfoAndClearSlot(one); SlotInfo secondSlot = SaveItemInfoAndClearSlot(two); inventory.ClearFromSlot(newStatsToAdd.MySlot); inventory.AddItemToFirstInvSlot(oldStatsToRemove); inventory.AddItemToSecondInvSlot(oldOffhand); if (firstSlot.slotItem != null) { inventory.AddItem(firstSlot.slotItem); } if (secondSlot.slotItem != null) { inventory.AddItem(secondSlot.slotItem); } ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex); } else if (inventory.MyEmptySlotCount < 1) { if (DebugControl.debugInventory) { Debug.Log("Sending Notice that player cannot perform this action"); } var text = CombatTextManager.instance.FetchText(transform.position); var textScript = text.GetComponent <CombatText>(); textScript.White("Not enough room!", transform.position); text.transform.position = player.transform.position; text.SetActive(true); textScript.FadeOut(); return(false); } } /// Player has a main hand equipped but not a shield else if (currentEquipment[3] != null && currentEquipment[4] == null) { if (DebugControl.debugInventory) { Debug.Log("Player has a main hand equipped but not a shield"); } oldStatsToRemove = currentEquipment[slotIndex]; if (inventory.MyEmptySlotCount >= 1) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItemToFirstInvSlot(oldStatsToRemove); } else if (inventory.MyEmptySlotCount == 0) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItem(oldStatsToRemove); } ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex); } /// Player does not have a main hand equipped but has a shield else if (currentEquipment[3] == null && currentEquipment[4] != null) { if (DebugControl.debugInventory) { Debug.Log("Player does not have a main hand equipped but has a shield"); } oldOffhand = currentEquipment[4]; stats.RemoveItemStats(oldOffhand); if (inventory.MyEmptySlotCount >= 1) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItemToSecondInvSlot(oldOffhand); } else if (inventory.MyEmptySlotCount == 0) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItem(oldOffhand); } ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex); } /// Nothing equipped else { SaveItemInfoAndClearSlot(newStatsToAdd); } } // if its a shield else if (slotIndex == 4 && (int)newStatsToAdd.equipType == 2) { /// if player has items equipped in both main and offhand if (currentEquipment[3] != null && currentEquipment[4] != null) { oldStatsToRemove = currentEquipment[4]; oldOffhand = currentEquipment[4]; if (inventory.MyEmptySlotCount >= 1) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItemToSecondInvSlot(oldOffhand); } else if (inventory.MyEmptySlotCount == 0) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItem(oldOffhand); } } /// Player has a main hand equipped but not a shield /// It could be a bow or a single melee weapon else if (currentEquipment[3] != null && currentEquipment[4] == null) { ///Its a bow that he has equipped if ((int)currentEquipment[3].equipType == 1) { if (DebugControl.debugInventory) { Debug.Log("Adding Shield in place of Bow"); } oldStatsToRemove = currentEquipment[3]; SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItem(oldStatsToRemove); ClearMainHandSlot(newStatsToAdd, slotIndex); } else { SaveItemInfoAndClearSlot(newStatsToAdd); } } /// Player does not have a main hand equipped but has a shield else if (currentEquipment[3] == null && currentEquipment[4] != null) { oldStatsToRemove = currentEquipment[slotIndex]; oldOffhand = currentEquipment[slotIndex]; if (inventory.MyEmptySlotCount >= 1) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItemToSecondInvSlot(oldOffhand); } else if (inventory.MyEmptySlotCount == 0) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItem(oldOffhand); } } /// Nothing equipped else { SaveItemInfoAndClearSlot(newStatsToAdd); } } /// if its not a bow but you have an item in that position /// Mainly, equipping a melee weapon and all armor else if (currentEquipment[slotIndex] != null && (int)newStatsToAdd.equipType != 1) { /// is the item in that position a bow? if ((int)currentEquipment[slotIndex].equipType == 1) { /// remove the arrow visibleGear[4].sprite = null; } oldStatsToRemove = currentEquipment[slotIndex]; if (slotIndex == 3) { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItemToFirstInvSlot(oldStatsToRemove); } else { SaveItemInfoAndClearSlot(newStatsToAdd); inventory.AddItem(oldStatsToRemove); } } /// Adding an item to a slot that has nothing in it else if (currentEquipment[slotIndex] == null) { if (!silent) { SaveItemInfoAndClearSlot(newStatsToAdd); } } // invoke the callback for change of equipment if (onEquipmentChanged != null) { onEquipmentChanged.Invoke(newStatsToAdd, oldStatsToRemove); } // if Item has a glow effect add it here if (newStatsToAdd.MyGlowSprite != null) { weaponGlowSlot.sprite = newStatsToAdd.MyGlowSprite; } // Equip the item and make the sound of equipping inventoryEquipment[slotIndex].AddItemVisuals(newStatsToAdd, silent); UpdateIteminEquipmentSlot(newStatsToAdd, slotIndex); return(true); }