public void ApplyEffect(EffectData effect, CombatantController source) { if (effect.IsEmpty()) { Debug.Log("Empty effect - skipping"); return; } Debug.Log("Applying effect " + effect.name + " to combatant " + Name + "[" + BattleID + "]"); string statStr = effect.stat.ToLowerInvariant(); if (statStr == "hp") { // Calculate the magnitude of this effect int magnitude = effect.amount; // Scale it with strength if (magnitude > 0) { magnitude = (int)(magnitude + (source.Strength * effect.strengthScaling)); } else if (magnitude < 0) { magnitude = (int)(magnitude - (source.Strength * effect.strengthScaling)); } // Calculate if it crit or not if (effect.canCrit) { // Crit chance is a 3% base plus an amount based on agility float critChance = BASE_CRIT_CHANCE + (CRIT_AGIL_SCALING * source.Agility); critChance /= 100.0f; // Roll and see if this effect is critting if (Random.value >= 1.0f - critChance) { Debug.Log(source.Name + "'s " + effect.name + " effect crit!"); magnitude *= 2; } } // Apply the effect HP = Mathf.Max(HP + magnitude, 0); if (magnitude <= 0) { Debug.Log(Name + "[" + BattleID + "] took " + (-magnitude) + " damage from " + effect.name); } else { Debug.Log(Name + "[" + BattleID + "] was healed by " + magnitude + " from " + effect.name); } Debug.Log("It now has HP " + HP + "/" + MaxHP); } else if (statStr == "agility") { int magnitude = effect.amount; // Calculate if it crit or not if (effect.canCrit) { // Crit chance is a 3% base plus an amount based on agility float critChance = BASE_CRIT_CHANCE + (CRIT_AGIL_SCALING * source.Agility); critChance /= 100.0f; // Roll and see if this effect is critting if (Random.value >= 1.0f - critChance) { Debug.Log(source.Name + "'s " + effect.name + " effect crit!"); magnitude *= 2; } } // Cannot have less than 1 agility Agility = Mathf.Max(Agility + magnitude, 1); // Since agility has changed, turn order may have too battleController.RefreshTurnOrder(); } else { Debug.Log("Unsupported effect type received!"); Debug.Break(); } }