2h, Shield visibility and Dual-Handed Weapons

If the sword is 2H, then you have to check to see that there is room for both the equipped weapon and the shield. You should have a method that checks HasSpaceFor(IEnumerable<InventoryItem> items)

So here’s what you can do:
First, add this to Equipment.cs

public IEnumerable<InventoryItem> GetWeaponAndShieldAsIEnumerable()
{
    if(equippedItems.ContainsKey(EquipLocation.Shield)) yield return equippedItems[EquipLocation.Shield];
    if(equippedItems.ContainsKey(EquipLocation.Weapon)) yield return equippedItems[EquipLocation.Weapon];
}

Then, when checking to see if there is enough space in Inventory for the equipped weapon and shield, call inventory.HasSpaceFor(equipment.GetWeaponAndShieldAsIEnumerable()); If it’s true, you can make the swap.

The data loss issue still persists (when the player Inventory is almost full, and the weapon can’t find a slot to go to, apart from the slot that is yet-to-be-free (because there’s a weapon coming to replace the old one), it just wipes the data of the weapon that is about to go to the inventory, instead of finding a slot for it (or taking up the slot of the weapon that’s about to replace it)), and I’m still testing the system for other faults. Can you please have a look at my ‘Equipment()’ functions that we implemented here for potential errors?

public IEnumerable<InventoryItem> GetWeaponAndShieldAsIEnumerable() {
            if (equippedItems.ContainsKey(EquipLocation.Shield)) yield return equippedItems[EquipLocation.Shield];
            if (equippedItems.ContainsKey(EquipLocation.Weapon)) yield return equippedItems[EquipLocation.Weapon];
        }

        public void UnequipWeaponAndEquipShield(Inventory inventory, EquipableItem itemToEquip) {
            
            EquipLocation weaponSlot = EquipLocation.Weapon;
            EquipLocation shieldSlot = EquipLocation.Shield;
            Equipment playerEquipment = this;

            EquipableItem equippedWeapon = playerEquipment.GetItemInSlot(weaponSlot);
            EquipableItem equippedShield = playerEquipment.GetItemInSlot(shieldSlot);

            if (equippedWeapon != null && inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable())) {
                RemoveItem(weaponSlot);
                inventory.AddToFirstEmptySlot(equippedWeapon, 1);
            }
            
            if (equippedShield != null && inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable())) {
                RemoveItem(shieldSlot);
                inventory.AddToFirstEmptySlot(equippedShield, 1);
            }

            AddItem(shieldSlot, itemToEquip);   // Main difference between both functions is in this line
            inventory.RemoveItem(itemToEquip, 1);
        
        }

        public void UnequipShieldAndEquipWeapon(Inventory inventory, EquipableItem itemToEquip) {
            
            EquipLocation weaponSlot = EquipLocation.Weapon;
            EquipLocation shieldSlot = EquipLocation.Shield;
            Equipment playerEquipment = this;

            EquipableItem equippedWeapon = playerEquipment.GetItemInSlot(weaponSlot);
            EquipableItem equippedShield = playerEquipment.GetItemInSlot(shieldSlot);

            if (equippedWeapon != null && inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable())) {
                RemoveItem(weaponSlot);
                inventory.AddToFirstEmptySlot(equippedWeapon, 1);
            }
            
            if (equippedShield != null && inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable())) {
                RemoveItem(shieldSlot);
                inventory.AddToFirstEmptySlot(equippedShield, 1);
            }

            AddItem(weaponSlot, itemToEquip);   // Main difference between both functions is in this line
            inventory.RemoveItem(itemToEquip, 1);

        }

        public int MaxAcceptable(EquipLocation equipLocation, InventoryItem item)
        {

            Inventory inventory = GetComponent<Inventory>();

            if (item is EquipableItem equipableItem)
            {

                if (!equipableItem.CanEquip(equipLocation, this)) return 0;

                switch (equipLocation)

                {

                    case EquipLocation.Shield:
                        if (GetItemInSlot(EquipLocation.Weapon) is WeaponConfig weapon)
                        {
                            if (weapon == null) {
                                Debug.Log("No weapon equipped, wearing the shield");
                                return 1;
                            }
                            if (!weapon.isRightHanded) {
                                Debug.Log($"{weapon} is left handed, not going to wear the shield");
                                UnequipWeaponAndEquipShield(inventory, equipableItem);
                                return 0;
                            }
                            if (weapon.isTwoHanded) {
                                Debug.Log($"{weapon} is two-handed, not going to wear the shield");
                                UnequipWeaponAndEquipShield(inventory, equipableItem);
                                return 0;
                            }
                            Debug.Log($"{weapon} is right-handed, wearing the shield");
                            return 1;
                        }
                        return 1;

                    case EquipLocation.Weapon:
                        if (item is WeaponConfig weaponConfig)
                        {
                            if (!weaponConfig.isRightHanded) {
                                UnequipShieldAndEquipWeapon(inventory, weaponConfig);
                                return 0;
                            }
                            if (weaponConfig.isTwoHanded) {
                                UnequipShieldAndEquipWeapon(inventory, weaponConfig);
                                // Play the 2h weapon animation here
                                return 0;
                            }
                            return 1;
                        }
                        return 1;

                    default: return 1;

                }

            }

            return 0;

        }

Edit: The shield replacement with ‘Base Shield’ also persists as well unfortunately

It’s bedtime, and this 2H issue is something I expressly said was going to BREAK what we were working on in the first place. I’ll try to look at it in the morning.

[SKIP TO BELOW PROBLEM 1 BENEATH MY BIG BLOCKS OF CODE, TO KNOW EXACTLY WHAT I’M STILL STRUGGLING WITH]

No worries, thanks again Brian. Apologies for the trouble, and thank you for being patient with me :slight_smile:

OK so my guess is that Inventory.RemoveFromSlot() is the function that takes care of replacing stuff in the same slot, which I’m assuming will solve half my 2h problems. My question is, how do we get the index for the item slot to feed that function?

I also re-wrote my Unequip functions, so now they look like this:

/// <summary>
        /// Unequips the 2-Handed weapon and equips the shield, if we want to equip a shield
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="itemToEquip"></param>
        public void Unequip2HWeaponAndEquipShield(Inventory inventory, EquipableItem itemToEquip) {

            EquipLocation weaponSlot = EquipLocation.Weapon;
            EquipLocation shieldSlot = EquipLocation.Shield;
            Equipment playerEquipment = this;

            EquipableItem equippedWeapon = playerEquipment.GetItemInSlot(weaponSlot);
            EquipableItem equippedShield = playerEquipment.GetItemInSlot(shieldSlot);

            if (inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable()))
            {
                if (equippedWeapon != null)
                {
                    inventory.AddToFirstEmptySlot(equippedWeapon, 1);
                    RemoveItem(weaponSlot);
                }
                /* if (equippedShield != null)
                {
                    inventory.AddToFirstEmptySlot(equippedShield, 1);
                    RemoveItem(shieldSlot);
                } */
                AddItem(shieldSlot, itemToEquip);
                inventory.RemoveItem(itemToEquip, 1);
            }

        }

        /// <summary>
        /// Unequips the shield and equips the 2-Handed weapon, if we want to equip a 2-Handed Weapon
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="itemToEquip"></param>
        public void UnequipShieldAndEquip2HWeapon(Inventory inventory, EquipableItem itemToEquip) {
            
            EquipLocation weaponSlot = EquipLocation.Weapon;
            EquipLocation shieldSlot = EquipLocation.Shield;
            Equipment playerEquipment = this;

            EquipableItem equippedWeapon = playerEquipment.GetItemInSlot(weaponSlot);
            EquipableItem equippedShield = playerEquipment.GetItemInSlot(shieldSlot);

            if (inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable())) {
                if (equippedWeapon != null) {
                    inventory.AddToFirstEmptySlot(equippedWeapon, 1);
                    RemoveItem(weaponSlot);
                }
                if (equippedShield != null) {
                    inventory.AddToFirstEmptySlot(equippedShield, 1);
                    RemoveItem(shieldSlot);
                }
                AddItem(weaponSlot, itemToEquip);
                inventory.RemoveItem(itemToEquip, 1);
            }

        }

And after a little bit of research, and finding a ‘FindSlot()’ function in ‘Inventory.cs’ that I turned from ‘private’ to ‘internal’, I slightly modified my ‘Equipment.MaxAcceptable()’ function to look like this (Changes are labelled with a comment of ‘// New line…’:

public int MaxAcceptable(EquipLocation equipLocation, InventoryItem item)
        {

            Inventory inventory = GetComponent<Inventory>();

            if (item is EquipableItem equipableItem)
            {

                if (!equipableItem.CanEquip(equipLocation, this)) return 0;

                switch (equipLocation)

                {

                    case EquipLocation.Shield:
                        if (GetItemInSlot(EquipLocation.Weapon) is WeaponConfig weapon)
                        {
                            if (weapon == null) {
                                Debug.Log("No weapon equipped, wearing the shield");
                                return 1;
                            }
                            if (!weapon.isRightHanded) {
                                Debug.Log($"{weapon} is left handed, not going to wear the shield");
                                inventory.RemoveFromSlot(inventory.FindSlot(weapon), 1);    // New line here, finding inventory slot to attempt to replace
                                Unequip2HWeaponAndEquipShield(inventory, equipableItem);
                                return 0;
                            }
                            if (weapon.isTwoHanded) {
                                Debug.Log($"{weapon} is two-handed, not going to wear the shield");
                                inventory.RemoveFromSlot(inventory.FindSlot(weapon), 1);    // New line here, finding inventory slot to attempt to replace
                                Unequip2HWeaponAndEquipShield(inventory, equipableItem);
                                return 0;
                            }
                            Debug.Log($"{weapon} is right-handed, wearing the shield");
                            return 1;
                        }
                        return 1;

                    case EquipLocation.Weapon:
                        if (item is WeaponConfig weaponConfig)
                        {
                            if (!weaponConfig.isRightHanded) {
                                inventory.RemoveFromSlot(inventory.FindSlot(weaponConfig), 1);  // New line here, finding inventory slot to attempt to replace
                                UnequipShieldAndEquip2HWeapon(inventory, weaponConfig);
                                return 0;
                            }
                            if (weaponConfig.isTwoHanded) {
                                inventory.RemoveFromSlot(inventory.FindSlot(weaponConfig), 1);  // New line here, finding inventory slot to attempt to replace
                                UnequipShieldAndEquip2HWeapon(inventory, weaponConfig);
                                return 0;
                            }
                            return 1;
                        }
                        return 1;

                    default: return 1;

                }

            }

            return 0;

        }
        

As of right now, I reversed the slot hunting function… It only caused more issues

But all 3 issues:

  1. [THIS ONE WAS SOLVED BY RE-WRITING THE UNEQUIP FUNCTIONS (new one is the code block above the code block, right above this paragraph), AND BY TUNING InventorySlotUI.OnPointerClick(), AS SHOWN UNDER (2)] Data loss, which occurs when trying to wield a 2h weapon in a full inventory, replacing a weapon that’s already in the weapon slot (because I can’t replace stuff in the exact same slot, because I don’t know how to get the index for ‘Inventory.RemoveFromSlot()’ (the solution above failed))

[FROM HERE ONWARDS IS UNRESOLVED] Apparently wielding a normal sword over a 2h places the 2h in the inventory slot that belonged to the normal sword (WHICH IS EXACTLY HOW I WANT IT), but wielding a 2h to replace a normal slot finds the first inventory slot, and places it there, NOT UTILIZING THE FACT THAT THIS SLOT JUST BECAME FREE (although both have exactly the same code). After further investigation, after we implemented this whole 2h system, ONLY THE NORMAL SWORD equipping places other weapons in its slot (THE MECHANIC I WANT), the slot of the normal sword that’s about to be equipped. All other weapons, for some reason (I checked the inspector settings), search for an empty slot first, although this problem didn’t even exist before we introduced this system. As a result, if my inventory is full, or 1 slot away from full, I must spam click my weapons (EXCEPT THE NORMAL SWORD) to be able to wield them, or empty an extra slot to utilize for the number of items about to be unequipped

So, for example, if you’re unequipping a sword and a shield for example, you need 2 empty slots, instead of it being 1 empty slot, and the other slot being the replacement slot of what is yet-to-be-an-empty-slot (by the weapon that’s going to the equipment now (which is what works for the quiver arrows and the NORMAL SWORD, but somehow not for the rest of the weapons, and I am clueless of why)), so something is entirely wrong here…

  1. [SOLVED] Spam click issue miraculously making something that’s been coded to ensure that it’s supposed not to work, suddenly work (as much as I’d love to ignore this one, it becomes a serious issue when the players’ inventory becomes full). After a few code updates, this issue becomes extremely obvious when the players inventory is full, and pretty much null when even a single empty slot is available

Edit: I also solved the Spam Click issue, by going into ‘InventorySlotUI.OnPointerClick()’, and tuning the ‘Invoke(nameof(TimesUp), .5f);’ function, as follows:

            public void OnPointerClick(PointerEventData eventData) {

                if (LastUIClicked != this) {

                    LastUIClicked = this;
                    Invoke(nameof(TimesUp), .01f);
                    Debug.Log($"{index} was clicked once");

                }

                else {
                    HandleDoubleClick();
                }
            }

By making the timer significantly lower, the chances of successful spam issues showing up is zero, virtually eliminating the problem

and

  1. The shield being replaced by a ‘Base Shield’ (something we used to hide visibility of the shield in our game, when 2h weapons override the shield, but is now an InventoryItem that shows up when our game restores its save state, and it needs to be eliminated) when I restore my game save file (I think we had a similar issue in the quiver system once). This one is a serious problem

are still malfunctioning unfortunately

This definitely isn’t the place for that bud. I understand this is probably a bot, but if you are a real person, and you have something not related to the topic, you should make your own topic instead. I’m gonna tell you though, most people who come here aren’t thinking about how to recover cryptocurrency.

it’s definitely a bot, I just wasn’t able to find a report button or delete button to delete his comment. Anyway, back to troubleshooting, I go… I found some interesting results, but stuff isn’t adding up right now :sweat_smile: (and I turn 26 in 2.5 hours :stuck_out_tongue_winking_eye: )

1 Like

If you click the three dots and then click the flag you can report, I just reported for off topic, usually moderators catch on to these and delete them, best of luck to solving your issues!

ahh, done… thanks Christopher :slight_smile: (I’m so close to something, but also SO FAR)

1 Like

OK so after 11 LONG HOURS of debugging, I actually THOUGHT I solved my 2h system issue on my own, although believe me when I say this, I HAVE ABSOLUTELY NO CLUE WHAT MY CODE IS DOING (I kept trying and failing until one of them worked :sweat_smile:), and I am sure it can be significantly cleaner, but hey… if it works, it works (P.S: I went to ‘inventory.cs’ and changed ‘FindEmptySlot()’ from ‘private’ to ‘internal’ to get this to work)

OR SO I THOUGHT… It’s still buggy :confused: (here’s the code anyway):

/// <summary>
        /// Unequips the 2-Handed weapon and equips the shield, if we want to equip a shield
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="itemToEquip"></param>
        public void UnequipWeaponAndEquipShield(Inventory inventory, EquipableItem itemToEquip) {

            EquipLocation weaponSlot = EquipLocation.Weapon;
            EquipLocation shieldSlot = EquipLocation.Shield;
            Equipment playerEquipment = this;

            EquipableItem equippedWeapon = playerEquipment.GetItemInSlot(weaponSlot);
            EquipableItem equippedShield = playerEquipment.GetItemInSlot(shieldSlot);

            // If you can't find an empty slot, don't bother trying to swap:
            if (!inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable())) {
                Debug.Log("Not enough inventory space to swap");
                return;
            }

            // Sending stuff from the Inventory to the Equipment Slot (Equipping Shield):
            AddItem(shieldSlot, itemToEquip);
            inventory.RemoveItem(itemToEquip, 1);

            if (inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable()))
            {
                // Sending Stuff from the Equipment Slot to the Inventory (Unequipping Old Weapon and Old Shield):
                if (equippedWeapon != null)
                {
                    inventory.AddToFirstEmptySlot(equippedWeapon, 1);
                    RemoveItem(weaponSlot);
                }
                if (equippedShield != null)
                {
                    inventory.AddToFirstEmptySlot(equippedShield, 1);
                    RemoveItem(shieldSlot);
                }

                // Sending stuff from the Inventory to the Equipment Slot (Equipping Shield):
                AddItem(shieldSlot, itemToEquip);
                inventory.RemoveItem(itemToEquip, 1);
            }
        }

        /// <summary>
        /// Unequips the shield and equips the 2-Handed weapon, if we want to equip a 2-Handed Weapon
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="itemToEquip"></param>
        public void UnequipShieldAndEquipWeapon(Inventory inventory, EquipableItem itemToEquip) {
            
            EquipLocation weaponSlot = EquipLocation.Weapon;
            EquipLocation shieldSlot = EquipLocation.Shield;
            Equipment playerEquipment = this;

            EquipableItem equippedWeapon = playerEquipment.GetItemInSlot(weaponSlot);
            EquipableItem equippedShield = playerEquipment.GetItemInSlot(shieldSlot);

            // if you can't find an empty slot, don't bother trying to swap:
            if (inventory.FindEmptySlot() == -1) {
                Debug.Log("Not enough inventory space to swap");
                return;
            }

                // Sending stuff from the Inventory to the Equipment Slot (Equipping Weapon):
                AddItem(weaponSlot, itemToEquip);
                inventory.RemoveItem(itemToEquip, 1);

            if (inventory.HasSpaceFor(GetWeaponAndShieldAsIEnumerable()))
            {
                // Sending stuff from the Equipment Slot to the Inventory (Unequipping Old Weapon and Old Shield):
                if (equippedWeapon != null) {
                    inventory.AddToFirstEmptySlot(equippedWeapon, 1);
                    RemoveItem(weaponSlot);
                }
                if (equippedShield != null) {
                    inventory.AddToFirstEmptySlot(equippedShield, 1);
                    RemoveItem(shieldSlot);
                }

                // Sending stuff from the Inventory to the Equipment Slot (Equipping Weapon):
                AddItem(weaponSlot, itemToEquip);
                inventory.RemoveItem(itemToEquip, 1);
            }
        }

So here’s what won’t work when the inventory is full:

  1. 2h-weapons won’t swap
  2. right-handed weapons won’t swap together
  3. If the weapon is 1-handed, no 2h weapon will want to swap with it, unless the shield is involved
  4. Just the shield and a 2h weapon won’t swap

This is what I captured so far

After that, my last issue is my ‘Base Shield’ replacing my wooden shield when my game reloads, as mentioned below:

If we can solve this, then 2h is golden :slight_smile:

If your goal was to completely confuse me, congratulations, you have succeeded admirably.
At this point, I cannot keep straight what is fixed and what is still a problem in the slightest. Not the first time you’ve done this, btw…

A few notes… but I don’t know if you’ve already resolved these issues because this code is all over the place.

You made space, and then told the caller there was no space…

Same here
In both of these cases, if you’re going to clear the space, then the return should be 1, because now there is space.

At this point, neither do I…

It shouldn’t be being saved at all??? You shouldn’t be equipping the Base Shield when there is no item in the shield slot, you should only be calling the Base Sheild’s spawn function to clear the shield slot full stop. The Equipment’s shield slot should remain empty. Similarly, you shouldn’t be equipping Unarmed, the weapon slot in Equipment should remain empty. (If Fighter.cs is saving anything, don’t, we don’t need Fighter.cs to Capture or Restore anything, just remove any ISaveables from Fighter).

What class are these UnequipShieldAndEquipWeapon in?

OK let’s just focus on the latest code. I agree, my code is all jumbled up, and I apologize for the complete mess. For now, let’s focus on my latest comment, it has my most recent code and requests, the rest has been addressed in one way or the other

As for this one, I ended up removing the ‘RemoveFromSlot()’ lines in the end

Ok, reading a little further, I think I see what you’re attempting to do. The problem is that where you are trying to do it (from Equipment.MaxAcceptable()) means that you have absolutely no idea where the item came from. Your issue is that you don’t know what slot it was coming from, and, MaxAcceptable has no idea…
If you’re dragging and dropping, these methods will equip the item you’re trying to see if they’re acceptable and should (based on how DragItem works, when it sees that there is no MaxAcceptable) BOUNCE that item back into the slot it came from, and bounce the item you unequipped and put back in Inventory back into the Equipment slot… This will likely lead to item duplication and frustration…

In fact, Drag and Drop is one of the primary reasons I strongly suggested that this wasn’t a good idea in the first place, because I don’t want to rewrite the Drag and Drop code, and I strongly in no uncertain terms suggest you don’t either…

So… to make this work with HandleRightClick instead, this should be done from within InventorySlotUI, not from within Equipment.cs…

Apologies, I just saw that. Currently they are stored in ‘Equipment.cs’

I’m kind of terrified of asking which code goes where at this point in time

(Ran out of edits, pardon me for the additional comment) Fighter has no saveables on it tbh, so now I’m even more confused where this issue is coming from. By all means, I’ll eliminate the changes I did to see where the issue is coming from

Start by returning Equipment.MaxAcceptable to a previous state. Understand that I’m writing this in my Spellborn Hunter, because that’s where I implemented the MaxAcceptable code, so I’ll be using IsLeftHanded instead of !rightHanded, and I have no interest in breaking this project… To make this a bit easier on yourself, add this to your WeaponConfig:

public bool IsLeftHanded => !isRightHanded;

Old Equipment.MaxAcceptable:

        public int MaxAcceptable(EquipLocation equipLocation, InventoryItem item)
        {
            if (item is EquipableItem equipableItem)
            {
                if (!equipableItem.CanEquip(equipLocation, this)) return 0;
                switch (equipLocation)
                {
                    case EquipLocation.Shield:
                        if (GetItemInSlot(EquipLocation.Weapon) is WeaponConfig weapon)
                        {
                            if (weapon == null) return 1;
                            if (weapon.IsLeftHanded || weapon.IsTwoHanded) return 0;
                        }
                        return 1;
                    case EquipLocation.Weapon:
                        if (item is WeaponConfig weaponConfig)
                        {
                            if (weaponConfig.IsLeftHanded || weaponConfig.IsTwoHanded)
                                return GetItemInSlot(EquipLocation.Shield) == null ? 1 : 0;
                            return 0;
                        }
                        return 1;
                    default: return 1;
                }
            }
            return 0;
        }

This is just to restore Drag and Drop to it’s normal functionality.

Next, in InventorySlotUI, we need to add two methods:

        private void TryEquipWeapon(WeaponConfig weapon)
        {
            RemoveItems(1);
            WeaponConfig otherWeapon = (WeaponConfig)equipment.GetItemInSlot(EquipLocation.Weapon);
            ShieldConfig otherShield = (ShieldConfig)equipment.GetItemInSlot(EquipLocation.Shield);
            if (weapon.IsTwoHanded)
            {
                if (!inventory.HasSpaceFor(equipment.GetWeaponAndShieldAsIEnumerable()))
                {
                    AddItems(weapon, 1);
                    return;
                }
                equipment.RemoveItem(EquipLocation.Shield);
                equipment.RemoveItem(EquipLocation.Weapon);
                if(otherWeapon) AddItems(otherWeapon, 1);
                if(otherShield) AddItems(otherShield, 1); //If you try to AddItems and an item exist, it goes to first empty slot
                equipment.AddItem(EquipLocation.Weapon, weapon);
                return;
            }
            if (weapon.IsLeftHanded)
            {
                if (otherShield) 
                {
                    equipment.RemoveItem(EquipLocation.Shield);
                    AddItems(otherShield, 1);
                } 
            }
            //regardless of weapon hand, otherWeapon must be removed
            if (otherWeapon)
            {
                equipment.RemoveItem(EquipLocation.Weapon);
                AddItems(otherWeapon, 1);
            }
            equipment.AddItem(EquipLocation.Weapon, weapon);
        }

        private void TryEquipShield(ShieldConfig shield)
        {
            RemoveItems(1);
            WeaponConfig otherWeapon = (WeaponConfig)equipment.GetItemInSlot(EquipLocation.Weapon);
            ShieldConfig otherShield = (ShieldConfig)equipment.GetItemInSlot(EquipLocation.Shield);
            if (otherWeapon!=null && otherWeapon.IsLeftHanded || otherWeapon.IsTwoHanded) //by definition, if this is true then we have space and can swap
            {
                equipment.RemoveItem(EquipLocation.Weapon);
                AddItems(otherWeapon, 1);
            }
            else if (otherShield)
            {
                equipment.RemoveItem(EquipLocation.Shield);
                AddItems(otherShield, 1);
            }
            equipment.AddItem(EquipLocation.Shield, shield);
        }

now in HandleDoubleClick, Once you determine that the item is an EquipableItem, check to see if the item is a WeaponConfig…

if(equipableItem is WeaponConfig weapon)
{
     TryEquipWeapon(weapon);
      return;
}
if(equipableItem is ShieldConfig shield)
{
    TryEquipShield(shield);
    return;
}
//perform the normal Equip item code

Are you Equipping the base shield or simply calling the base shield’s spawn with the transform?

I believe I’m equipping the base shield. The issue occurs when I save my game and then try to restore it, for some reason

Don’t equip the base shield. Paste in your UpdateWeapon method from Fighter, let’s take a look.

Sure thing:

private void UpdateWeapon() {

        var weapon = equipment.GetItemInSlot(EquipLocation.Weapon) as WeaponConfig;
        var shield = equipment.GetItemInSlot(EquipLocation.Shield) as ShieldConfig;

        /* if (weapon == null) EquipWeapon(defaultWeapon);
        else EquipWeapon(weapon); */


        EquipWeapon(weapon != null ? weapon : defaultWeapon);
        EquipShield(shield != null ? shield : baseShield);

    }

Now let’s see EquipShield

Privacy & Terms