Arrow Quiver

‘GetAmmunitionItem()’ was a function we coded in ‘Quiver.cs’, and then referenced through a ‘Quiver’ call… Did you code that?

I covered that above… You should be using the if(!CheckForProjectileAndSufficientAmmo()) instead of checking the Quiver. I’m surprised you weren’t getting an NRE before.

This line just flat out removes the bow from the players’ hand if he even thinks of hovering on the enemy without any sort of ammo on him… I’ll keep this line out of it :stuck_out_tongue_winking_eye: (for now I think we can call the Arrow and Quiver system a day, we have achieved WAY more than what I initially wanted, apart from the tooltip thingy (which I might just walk it off by re-writing the description manually for every item))

Are you starting to see why Blizzard did away with ammo yet?

I’m starting to see a weak spot we took from blizzard xD, but RuneScape just wasn’t budging lel… This whole thing is really making me appreciate the fact that some people once did ALL THIS HARD WORK without guidance (WOW… Just WOW, all the simple stuff that we take for granted). Anyway, time for the next topic for another day :smiley: (for tonight let’s just celebrate the fact that we got the quiver system out of the way. You gotta admit though, I’m giving you amazing ideas as well xD)

[JUST SKIP STRAIGHT TO EDIT 3]

Uhh Brian, before we lock this down, I just noticed a glitch with the arrows in the Quiver:

Here’s the thing, I tried storing my arrows in the bank, and I went crafted some more (I have a crafting system), and then I put the new ones on. When I went and pulled my arrows out of the bank and tried equipping them, my old arrows (which are EXACTLY THE SAME) were taken off the quiver and replaced with the new ones… WHICH ARE THE EXACT SAME ARROWS AS THE OLD ONES (I tried fixing that in the ‘QuiverSlotUI.TryHandleRightClick()’ and ‘InventorySlotUI.TransferToQuiver()’ method, but both were a nightmare). I want the exact same arrows to add up, not be replaced, please :slight_smile:

At first I thought this was a mistake, but apparently not. What changes do I need to do to fix this? Once we fix this we can start the ‘XP-Based system’, I’ll tag you there

The same problem does NOT exist for unequipping ammo (they add up perfectly fine), but it exists for transferring arrows to the quiver slot (they do not add up, they replace one another, although they are the same thing). Dragging and dropping works perfectly fine, but clicking to automatically send it to the quiver does not

Edit 1: 8 hours later, still can’t figure this silly thing out… I know for a fact it has something to do with ‘InventorySlotUI.TransferToQuiver()’

Edit 2: Now it also happens in the ‘Drag and Drop’ system too… this thing gets worse the more I try… Earlier it used to add the numbers up when we drag and drop, now it just replaces the entire old quiver content entirely, if they were of the same item type (I’m still trying to edit ‘TransferToQuiver()’)

[DRAG AND DROP ISSUE NOW]
Edit 3: ahh nevermind, I figured it out… at least for the clicking system (the drag and drop now just flat out replaces the arrows completely for some reason, how do we fix that…?). Surprisingly all it took was just an extra 2-3 lines of code.

My problem now is the drag and drop system. Whilst it works perfectly fine when transferring THE SAME TYPE OF ARROWS from the quiver to the inventory, transferring THE SAME TYPE OF ARROWS from the inventory to the quiver sends absolutely nothing back to the inventory (THIS CASE ONLY APPLIES IF THEY ARE THE SAME TYPES OF ARROWS. If they’re different, it returns them completely fine). It just completely takes over the old arrows (IF THEY ARE THE SAME ARROWS) and permanently deletes them… It doesn’t stack them up or anything, it just permanently deletes them

I haven’t followed all of this, but there is one thing I noticed (and it may be completely irrelevant);
When you add items to the quiver, the method expects the full amount of items that will be in the quiver. If there are 5 and you want to add 5 more, you have to add 10. The drag-drop system is only going to pass how many items to add (in the example above, 5). If I have 3 arrows in the quiver and want to add 10 more, the click mechanic passes 13, so the arrows become 13, but the drag-drop system is going to pass 10, so the value in the quiver becomes 10, and 3 is just going to disappear. Should the quiver not perhaps add the value instead of completely replacing it?

public void AddAmmunition(AmmunitionItem item, int number)
{
    currentAmmunition = item;
    amount += number; // <- add it here instead of replacing
    quiverUpdated?.Invoke();
}

If you change it (and @Brian_Trotter will have to verify/validate/confirm) you would have to change the click to only pass number instead of number + amount


Edit
Actually, I suspect you’d need more checks, because if you are changing the ammo with different ammo, you’d want the number to be replaced instead of accumulated. Perhaps you should just update QuiverSlotUI to accumulate the items

public void AddItems(InventoryItem item, int number)
{
    if(item is AmmunitionItem ammunitionItem)
    {
        var currentAmount = quiver.GetAmount();
        quiver.AddAmmunition(ammunitionItem, currentAmount + number);
    }
}

Ahh… this one made things worse. I had a bug where it adds stuff up in the quiver, but not remove it from the inventory, so now the math keeps going on forever…

For now I’ll revert to the solution I found, until Brian returns (I wonder where is he today… hope he’s well)

I’LL READ THE EDIT NOW

Edit 2: It makes things significantly worse… it brings back the bug I was trying so hard to avoid :sweat_smile:

Yeah, there’s no checks in the QuiverSlotUI if the items are the same. It will just continue to add, regardless of what type of ammo is in the slot. You probably need to check the types and if they’re the same, accumulate. If not, replace

I’ll go through this comment again in a bit, off somewhere brb

ahh… didn’t work. Let’s wait for @Brian_Trotter

You know, skipping to Edit 3, I’m still not entirely sure… is the click to equip properly adding or not?

In any event, here’s my fix for the click handler, checking to see if they are the same before swapping:

        private void TransferToQuiver(AmmunitionItem ammunitionItem, Quiver quiver, int number)
        {
            AmmunitionItem item = quiver.GetItem();
            int amount = quiver.GetAmount();
            inventory.RemoveFromSlot(index, number);
            quiver.AddAmmunition(ammunitionItem, ammunitionItem==item? number+amount : number);
            if (item != null && ammunitionItem!=item)
            {
                inventory.AddItemToSlot(index, item, amount);
            }
        }

Then for the dragging, in QuiverSlotUI, we needed to be checking to see if the item was the same as the equipped item before adding:

        public void AddItems(InventoryItem item, int number)
        {
            if(item is AmmunitionItem ammunitionItem)
            {
                if (object.ReferenceEquals(ammunitionItem, quiver.GetItem()))
                {
                    quiver.AddAmmunition(ammunitionItem, number + quiver.GetAmount());
                } else
                {
                    quiver.AddAmmunition(ammunitionItem, number);
                }
            }
        }

I was well, but had an unexpectedly long day and was unable to access a computer. Life happens, on occassion.

Yay, welcome back Brian (gives you a long virtual hug like the one my 8 year old students give me nowadays :stuck_out_tongue_winking_eye: )

Anyway, the code works well now, thanks again Brian :slight_smile:

Eventually it did… there’s more than one way we got this to work apparently, I simply didn’t share the code in that edit :sweat_smile:

Hello again Brian. I found a minor glitch in my Arrow unequipping system in my game, where my player inventory will instantiate the ‘unequipped’ (default weapon setup of my player, if he doesn’t have a weapon on him) into my inventory. To delete this, I was thinking of adding a Coroutine that waits for some time, and then checks for whether we have an ‘unarmed’ InventoryItem in my bag or not (P.S: he does, 100% of the time). If there is, delete it. If not, don’t do anything

But this doesn’t sound too practical. Do you have any alternative suggestions I can try out?

Is your default weapon a projectile weapon?? Generally, we recommend the default weapon just be the Unarmed (effectively fists) which do not require ammo…

Hello Brian. For my player, my default weapon, set under ‘Fighter.cs’ is ‘Unarmed’

Then I guess I’m not understanding what’s going on…
You’re saying that an Unarmed SO is getting added to the inventory when the bow runs out of ammo?

If the player is in combat, he has a bow and arrow on him, and his ammo runs out and he’s forced to take the bow off during combat, then yes the Unarmed SO somehow gets instantiated in the Players’ inventory (I fixed the other bug with my player turning around, so now we have this one, and my abilities system has recently taken a messy hit as well. For now though, I want to develop a minimap first xD, so once we finish this bug we can try making a circular minimap that exists on the top right corner of my game screen)

I’m not entirely sure how this is possible… the UnequipRangedWeapon() method does add the current weapon to inventory, but it should only ever be called if the currently equipped weapon is a ranged weapon.

Go through your Fighter script and find any method that calls UnequipRangedWeapon(). Make sure that it’s only being called in the event that the weapon has a projectile assigned, has an ammo assigned, and that the quiver is out of the correct ammo.

Forgot to update this. I found this statement in the boolean ‘CheckForProjectileAndSufficientAmmo()’ function we created for this topic:

if (currentWeaponConfig.GetAmmunitionItem() && !GetComponent<Quiver>().HasSufficientAmmunition(currentWeaponConfig.GetAmmunitionItem())) {
            // If you want to keep pointing at your player without attacking them because of insufficient/wrong ammo, delete 'UnequipRangedWeapon()' below:
            UnequipRangedWeapon();
            return false;

I commented it out, and the problem was gone (since we have a ‘return false’ case for the rest of this function anyway, if none of the true conditions are met)

BUT… Now the player won’t unequip his weapon if his bow and arrow don’t match (apparently calling ‘UnequipRangedWeapon()’ in that function is the source of the problem)

Privacy & Terms