If you want to have a trait that increases the Experience Reward
you get when you douse enemies while assigning points to it, we can’t do that due to our current setup, as the enemies would try to find modifiers for it on their components, instead of on the player, because it doesn’t exist:
So this is where the player gains experience when the enemies die, as they invoke this method & ask the BaseStat for specific modifiers for that:
void AwardExperience(GameObject instigator)
{
if (!instigator.TryGetComponent<Experience>(out var experience)) return;
float experiencePoints = baseStats.GetStat(Stat.ExperienceReward);
experience.GainExperience(experiencePoints);
}
For this reason I modified the BaseStat this way to reflect the change & it works, but I’m worried if I introduced some new unwanted errors or misconduct as I’m not familiar with that class. Perhaps there is a better way of doing it?
BaseStat:
// Introduced a new variable
GameObject player;
void Awake()
{
experience = GetComponent<Experience>();
currentLevel = new(CalculateLevel);
// Getting reference to the Player GameObject
player = GameObject.FindWithTag("Player");
}
public float GetStat(Stat stat)
{
(float additiveModifier, float percentageModifier) = GetModifiers(stat);
return (GetBaseStat(stat) + additiveModifier) * (1 + percentageModifier * 0.01f);
}
(float, float) GetModifiers(Stat stat)
{
float additiveModifier = 0f;
float percentageModifier = 0f;
// Changed the if statetement
if (!shouldUseModifier || (stat != Stat.ExperienceReward && gameObject != player)) return (additiveModifier, percentageModifier);
// Iterating over the Player's Component instead
foreach (IModifierProvider provider in player.GetComponents<IModifierProvider>())
{
foreach (float modifier in provider.GetAdditiveModifiers(stat))
{
additiveModifier += modifier;
}
foreach (float modifier in provider.GetPercentageModifiers(stat))
{
percentageModifier += modifier;
}
}
return (additiveModifier, percentageModifier);
}