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().