Page 1 of 1

Item Duplication Bug?

PostPosted: Wed Dec 28, 2016 1:25 am
by zach_holbrook
I think I've noticed my first bug -- when playtesting, I can get duplicates of items by selecting a blank square in the inventory screen and pressing "equip selected." For each square I perform this action on, I get an item duplicate of what's in my main hand when I return to the inventory screen, as in the image below. I've tried this in mods and can replicate it there.

item_duplicates.png
item_duplicates.png (190.49 KiB) Viewed 1580 times

Re: Item Duplication Bug?

PostPosted: Wed Dec 28, 2016 3:42 am
by slowdive
HaHa, never saw that one before...sounds more like a special feature then a bug to me :oops:

I fixed it with this check:
Code: Select all
if (GetCurrentlySelectedItemRefs().resref.Equals("none"))
{
    return;
}

full method:
Code: Select all
public void switchEquipment()
        {
            Player pc = mod.playerList[gv.cc.partyScreenPcIndex];
            if (GetCurrentlySelectedItemRefs().resref.Equals("none"))
            {
                return;
            }
            if (gv.cc.partyItemSlotIndex == 0) //Main Hand
            {
                if (!pc.MainHandRefs.resref.Equals("none"))
                {
                    //move currently equipped item to the party inventory (list and taglist)
                    mod.partyInventoryRefsList.Add(pc.MainHandRefs.DeepCopy());
                    //place the item into the main hand
                    pc.MainHandRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    //remove the item from the party inventory
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else //there was no item equipped so add item to main-hand but no need to move anything to party inventory
                {
                    pc.MainHandRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                //if the item being equipped is a two-handed weapon, remove the item in off-hand if exists and place in inventory
                if (mod.getItemByResRef(pc.MainHandRefs.resref).twoHanded)
                {
                    if (!pc.OffHandRefs.resref.Equals("none"))
                    {
                        mod.partyInventoryRefsList.Add(pc.OffHandRefs.DeepCopy());
                        pc.OffHandRefs = new ItemRefs();

                        gv.sf.MessageBoxHtml("Equipping a two-handed weapon, removing item from off-hand and placing it in the party's inventory.");
                    }
                }
                //if the item is a ranged weapon that uses ammo, check ammo slot to see if need to remove ammo not this type
                Item itMH = mod.getItemByResRef(pc.MainHandRefs.resref);
                Item itA = mod.getItemByResRef(pc.AmmoRefs.resref);
                if ((itA != null) && (itMH != null))
                {
                    if ((itMH.category.Equals("Ranged")) && (!itMH.ammoType.Equals("none")) && (itMH.ammoType.Equals(itA.ammoType)))
                    {
                        //compatible ammo so leave as is
                    }
                    else //ammo not compatible so remove ItemRefs
                    {
                        pc.AmmoRefs = new ItemRefs();
                        gv.sf.MessageBoxHtml("Currently assigned ammo is not compatible with this weapon, unassigning ammo.");
                    }
                }
            }
            else if (gv.cc.partyItemSlotIndex == 1) //Head
            {
                // if equip slot has an item, move it to inventory first
                if (!pc.HeadRefs.resref.Equals("none"))
                {
                    mod.partyInventoryRefsList.Add(pc.HeadRefs.DeepCopy());
                    pc.HeadRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else //equip slot was empty
                {
                    pc.HeadRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
            }
            else if (gv.cc.partyItemSlotIndex == 2) //Neck
            {
                // if equip slot has an item, move it to inventory first
                if (!pc.NeckRefs.resref.Equals("none"))
                {
                    mod.partyInventoryRefsList.Add(pc.NeckRefs.DeepCopy());
                    pc.NeckRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else //equip slot was empty
                {
                    pc.NeckRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
            }
            else if (gv.cc.partyItemSlotIndex == 3) //Off Hand
            {
                if (!pc.OffHandRefs.resref.Equals("none"))
                {
                    mod.partyInventoryRefsList.Add(pc.OffHandRefs.DeepCopy());
                    pc.OffHandRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else
                {
                    pc.OffHandRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
            }
            else if (gv.cc.partyItemSlotIndex == 4)//Ring
            {
                if (!pc.RingRefs.resref.Equals("none"))
                {
                    mod.partyInventoryRefsList.Add(pc.RingRefs.DeepCopy());
                    pc.RingRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else
                {
                    pc.RingRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
            }
            else if (gv.cc.partyItemSlotIndex == 5) //Body
            {
                // if equip slot has an item, move it to inventory first
                if (!pc.BodyRefs.resref.Equals("none"))
                {
                    mod.partyInventoryRefsList.Add(pc.BodyRefs.DeepCopy());
                    pc.BodyRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else //equip slot was empty
                {
                    pc.BodyRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
            }
            else if (gv.cc.partyItemSlotIndex == 6) //Feet
            {
                // if equip slot has an item, move it to inventory first
                if (!pc.FeetRefs.resref.Equals("none"))
                {
                    mod.partyInventoryRefsList.Add(pc.FeetRefs.DeepCopy());
                    pc.FeetRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else //equip slot was empty
                {
                    pc.FeetRefs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
            }
            else if (gv.cc.partyItemSlotIndex == 7) //Ring2
            {
                if (!pc.Ring2Refs.resref.Equals("none"))
                {
                    mod.partyInventoryRefsList.Add(pc.Ring2Refs.DeepCopy());
                    pc.Ring2Refs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
                else
                {
                    pc.Ring2Refs = GetCurrentlySelectedItemRefs().DeepCopy();
                    mod.partyInventoryRefsList.Remove(GetCurrentlySelectedItemRefs());
                }
            }
            else if (gv.cc.partyItemSlotIndex == 8) //Ammo
            {
                // if equip slot has an ammo, no need to move it to inventory since it is only a ref                     
                pc.AmmoRefs = GetCurrentlySelectedItemRefs().DeepCopy();
            }
        }

So when double clicking on an empty square or clicking on the "equip" button while an empty square is highlighted, the above check is made first before actually attempting to equip the item. If the item slot is empty, the resref is "none" and so it will return early from the switchEquipment method and not execute the item switching. I tested it and it now works (I was able to replicate the bug as Zach mentioned).

P.S. Love the custom UI buttons...will be interesting to see more of what you are up to as the story unfolds and building updates are hopefully presented in time.

Re: Item Duplication Bug?

PostPosted: Wed Dec 28, 2016 6:51 am
by youngneil1
Good find there, Zach. Never ever noticed all the time. And thank you, Jer, for going into details of the fix, will be easy to add into IB2 this way.

Re: Item Duplication Bug?

PostPosted: Sun Jan 28, 2018 7:03 pm
by zach_holbrook
I've noticed another item duplication bug, but I haven't been able to reproduce this one, so I'm not sure what caused it. I'll keep you posted if I learn more, but the only thing I can think of is that it has something to do with equipping or unequipping items in combat and perhaps saving the game?

Re: Item Duplication Bug?

PostPosted: Mon Jan 29, 2018 9:49 pm
by youngneil1
Thank you for the heads up and keep us in the loop, please, Zach. I remember new duplication issues when working on charged items, so it might be connected to this.