Forum begins after the advertisement:


[Part 27] Bug with Treasure Chest upgrading weapons at max level

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 27] Bug with Treasure Chest upgrading weapons at max level

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #18712
    Grim Rubbish
    Level 24
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    If everything (weapons and passives) is leveld to max. and you open a treasure chest, it will still show you new weapons. Of course you don’t get theses new weapons, because you have no space in your inventory left. Shouldn’t there just extra gold be generated in this case?

    (The same applies to the level-up system; shouldn’t there only be gold or health left as bonuses after everything is upgraded?)

    #18713
    Alp Apustaja
    Level 10
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    It sounds like you’re encountering an issue with how the game handles inventory and treasure chest rewards. If you have six max-level weapons and open a chest, it should ideally prioritize giving you passive items or upgrading them instead of showing you new weapons.

    This kind of bug can be frustrating, but here are a few steps you can take:

    1. Check for Updates: Make sure your game is updated to the latest version. Sometimes bugs are fixed in patches.

    2. Report the Bug: If it’s a persistent issue, consider reporting it to the game’s support team or forum. Provide them with details, such as your inventory status and what happens when you open a treasure chest.

    3. Clear Space: If possible, try to free up inventory space before opening chests. This way, you can at least receive some rewards.

    4. Community Feedback: Look for discussions in community forums or social media groups related to the game. Other players might have similar experiences or potential workarounds.

    5. Gameplay Strategy: If the game allows, sometimes using or selling weapons you don’t need can help manage inventory better.

    If you have access to any modding tools or settings (depending on the game), check if there’s an option to tweak inventory management or rewards.

    #18714
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    1
    ::

    You’re right. Let me schedule a stream for Thursday to address these.

    Thank you for highlighting this! Here’s another badge:

    Bug Reporter
      1 anonymous person
    has upvoted this post.
    #18715
    Grim Rubbish
    Level 24
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    Thank you Terence! :)

    #18716
    Alp Apustaja
    Level 10
    AI Assistant
    (BETA)
    Helpful?
    Up
    1
    ::

    You’re welcome, Grim Rubbish! If you have any more questions or need further assistance with the game or anything else, feel free to ask. I’m here to help! 😊

      1 anonymous person
    has upvoted this post.
    #18745
    #18759
    Grim Rubbish
    Level 24
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    Hey Terence, thanks again. Sadly this didn’t fix the problem. I already had this line corrected in the “PlayerInventory.cs” but the problem explained above is still there. Maybe I can make a short video to illustrate the problem if this would help you?

    #18761
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi Grim, yes, if you can make a video that will be great.

    @Alp.Apustaja, there was a problem with the ApplyUpgradeOptions() in PlayerInventory that caused weapons / passives that were at max level to become an upgrade option. By changing the sign from <= to < in the line:

    if (obj.currentLevel <= data.maxLevel)

    It fixed the problem for me. But can you see any other area that would cause this bug to occur where weapons at max levels are still eligible for upgrades?

    Below is the full ApplyUpgradeOptions() that should be similar to what you have in your knowledge base.

    // Determines what upgrade options should appear.
    void ApplyUpgradeOptions()
    {
        // <availableUpgrades> is an empty list that will be filtered from
        // <allUpgrades>, which is the list of ALL upgrades in PlayerInventory.
        // Not all upgrades can be applied, as some may have already been
        // maxed out the player, or the player may not have enough inventory slots.
        List<ItemData> availableUpgrades = new List<ItemData>();
        List<ItemData> allUpgrades = new List<ItemData>(availableWeapons);
        allUpgrades.AddRange(availablePassives);
    
        // We need to know how many weapon / passive slots are left.
        int weaponSlotsLeft = GetSlotsLeft(weaponSlots);
        int passiveSlotsLeft = GetSlotsLeft(passiveSlots);
    
        // Filters through the available weapons and passives and add those
        // that can possibly be an option.
        foreach (ItemData data in allUpgrades)
        {
            // If a weapon of this type exists, allow for the upgrade if the
            // level of the weapon is not already maxed out.
            Item obj = Get(data);
            if (obj)
            {
                if (obj.currentLevel <= data.maxLevel) availableUpgrades.Add(data);
            }
            else
            {
                // If we don't have this item in the inventory yet, check if
                // we still have enough slots to take new items.
                if (data is WeaponData && weaponSlotsLeft > 0) availableUpgrades.Add(data);
                else if (data is PassiveData && passiveSlotsLeft > 0) availableUpgrades.Add(data);
            }
        }
    
        // Show the UI upgrade window if we still have available upgrades left.
        int availUpgradeCount = availableUpgrades.Count;
        if (availUpgradeCount > 0)
        {
            bool getExtraItem = 1f - 1f / player.Stats.luck > UnityEngine.Random.value;
            if (getExtraItem || availUpgradeCount < 4) upgradeWindow.SetUpgrades(this, availableUpgrades, 4);
            else upgradeWindow.SetUpgrades(this, availableUpgrades, 3, "Increase your Luck stat for a chance to get 4 items!");
        }
        else if (GameManager.instance != null && GameManager.instance.choosingUpgrade)
        {
            GameManager.instance.EndLevelUp();
        }
    }
    #18762
    Alp Apustaja
    Level 10
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    Based on the reference information and the provided code, there are a few potential areas that could cause max-level weapons to still be eligible for upgrades:

    1. The code change you mentioned (changing <= to <) is the primary fix for preventing max-level items from being upgrade options.

    2. Another potential issue could be in the Get(data) method or how currentLevel and maxLevel are defined in the Item class.

    3. The logic for checking weaponSlotsLeft and passiveSlotsLeft might inadvertently allow max-level items to be added.

    However, without more context about the implementation of the Item class and other related methods, I cannot definitively point to additional specific areas that would cause this bug.

    Would you be willing to share the implementation of the Item class, particularly how currentLevel and maxLevel are defined and managed?

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: