The Damage Modifier function has been extended in this example and should be fairly expandable as you add more modifiers to the BattleStats array. The expression string may get a bit unruly, but as long as you keep track of where your stats are in the array, you should be fine.
The function has gained a new parameter that allows the system to define whether it's the player or the opponent's turn, so the correct set of values in the array can be used. During the attack functions, the Damage Modifier function is called with either the string Player or Opponent to pick the correct set of values.
The function starts by resetting the CriticalHit Boolean and calling the random number function to obtain a new random number to determine if a critical hit is triggered. If the random number is less than the Critical Chance value stored in the BattleStats array then the attack continues as normal – the damage modifier calculation only factors in the random variance and the Modifier value stored in the array.
If the random number generated is greater than the Critical Chatvalue in the array then the CriticalHit Boolean is set to true (which affects the text displayed during the turn) and the damage modifier calculation will include the CRITMODIFIER variable.
If you need to add more modifiers into the array, you can simply add their cell references to the calculation. If the value doesn't always need to be used, set it to one in the array initially and change it at runtime for when you need it. This could be applied to all sorts of things, from status effects to item boosts, weather effects, type matchups and more.