Another way to compile maybe

Good morning,

In my case, Fighter (for the level bonus), Weapon (for the weapon’s base damage) and Projectile (some of my projectiles have an additional layer of damage).
I thought using the compiler would require us implementing the interface in each of those scripts and finally insert the method in Hit()
So we would initialize the first total not at 0 but at the base bonus from level

private float GetAdditiveModifiers(Stats stat)
        {
            float total=GetStatValueFromBaseStats(stat);
            foreach (IModifierProvider provider in GetComponents<IModifierProvider>())
            {
                foreach (float modifier in provider.GetAdditiveModifier(stat))
                {
                    total+= modifier;
                }
            }
            return total;
        }

Then in Hit()

void Hit()
        {
            if (target == null) return;
            float damage = GetComponent<BaseStats>().GetAdditiveModifiers(Stats.Stats.DamageBonus);
            if(currentWeapon.HasProjectiles())
            {
                currentWeapon.LaunchProjectile(leftHandTransform, rightHandTransform, target, gameObject, damage);
            }
            else
            {
                target.TakeDamage(gameObject, damage);
            }
        }

I tested it with multiple weapons and the damage is compiled just fine.
Also I did not implement the interface in neither Weapon.cs nor in Projectile.cs I understand that we want the currently equipped weapon from fighter, and the projectile’s damage will be added to the compiled damage that we pass in LaunchProjectile().

Sorry for the late reply to this, I must have missed this topic earlier.

When we get to the next class, Inventory, the course way of getting the stats will make much more sense. We will indeed be putting the GetAdditiveModifiers and GetPercentageModifiers on the Weapons, as well as other equipment that the character will be wearing.

When we’re done, we’ll simply ask BaseStats for the Stat (GetStat(stat)) and it will gather all of the appropriate modifiers from the equipment.

1 Like

Good morning Brian!

Thanks for the reponse. To be honest I am just glad I understood the subject well enough to explore an alternate solution.
I can’t wait to see how it all comes together.

But I was halfway through the Inventory course when I realized I was forgetting too many stuff so I am praticing what we saw in Combat again!
Do you think I should finish it all before properly practicing?

The inventory course is a bit strange, as we don’t actually integrate any of the code from the first several sections into our project, only the code from the last section. In fact, I recommend you don’t try to integrate anything until the final section or you’ll find yourself dealing with a lot of unneccesary headaches.

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