I need help with weapon damage

I have the whole system of mods in place but I don’t understand how to deal with weapons with their damage. Do we have to reassign all the damage ranges using the additive modifier or did I miss a step?

In other words the damage does not work as before on weapons?

The weapon damage should work as before, where Fighter will return the Additive Modifier based on the Current WeaponConfig.

thank you for your answer, I must have a problem then because my damage is currently only equal to that of the player + those of the additive bonuses but that does not take into account the damage of my weapons. can you show me what the fighter and weaponconfig scripts should look like please and i will check on my side as well.

Actually, I was wrong about Fighter, this is all handled within WeaponConfig now (in Core Combat, Fighter was an IModifierProvider and got it’s information from reading the weapon damage.

Like StatsEquipableItem, WeaponConfig should be implementing the IModifierProvider interface. This will allow the StatsEquipment to get the data when GetAdditiveModifiers is called by BaseStats.

With the IModifierProvider interface added to the class declaration, here are the methods from the course that should be in plalce

        public IEnumerable<float> GetAdditiveModifiers(Stat stat)
        {
            if (stat == Stat.Damage) yield return weaponDamage;
        }

        public IEnumerable<float> GetPercentageModifiers(Stat stat)
        {
            if (stat == Stat.Damage) yield return percentageBonus;
        }

You’ll also need a [SerializeField] for the percentage Bonus in your fields.

Thank you for your help ! after a lot of debugging and testing I realized that the problem was adding duplicate weaponDamage. So I went step by step to understand and the problem was present only on a weapon that adds another bonus (in addition to a damage bonus). In this case the weaponDamage was added twice. So I did this in my method, it may not be very clean but it works. I have my total damage which is equal to weaponDamage + additive damage + base damage + percentageBonus

image

You can do this without the weaponDamageReturned trap.

public IEnumerable<float> GetAdditiveModifier(Stat stat)
{
    foreach(var modifier in additiveModifiers)
    {
          if(modifier.stat==stat)
          {
               yield return modifier.value;
          }
    }
    if(stat==Stat.Damage)
    {
         yield return weaponDamage;
     }
}
1 Like

Once again thank you for your valuable feedback !

I don’t know if there is a link but I just noticed an error during the first scene change in game if anyone has ever encountered this problem.

Looks like there's a duplicate GameDevTV.UI.InventorySystem ID for objects: Bow (RPG.Combat.WeaponConfig) and Bow (RPG.Combat.WeaponConfig)
UnityEngine.Debug:LogError (object)
RPG.Inventories.InventoryItem:GetFromID (string) (at Assets/Scripts/Inventories/InventoryItem.cs:58)
RPG.Inventories.Inventory:RPG.Saving.ISaveable.RestoreState (object) (at Assets/Scripts/Inventories/Inventory.cs:249)
RPG.Saving.SaveableEntity:RestoreState (object) (at Assets/Scripts/Saving/SaveableEntity.cs:64)
RPG.Saving.SavingSystem:RestoreState (System.Collections.Generic.Dictionary`2<string, object>) (at Assets/Scripts/Saving/SavingSystem.cs:104)
RPG.Saving.SavingSystem/<LoadLastScene>d__0:MoveNext () (at Assets/Scripts/Saving/SavingSystem.cs:34)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

This happens when you copy an existing Inventory Item to make modifications to it.
The ID doesn’t change automatically.
In this case, it looks like you have two copies of Bow.
Go into one of them and select the contents of the ItemID and delete it. A new one will be automagically generated.

1 Like

What speed! thank you for your help, the problem did not come from the itemId but it put me on the track! I had two nested resources folders … I cleaned up and now everything is ok with no error message! Many thanks !

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms