public static void Cast(ICast cast, BattleUnitsStack caster, params BattleUnitsStack[] targets) { caster.state = State.MadeMove; caster.GetLastEffect()?.BeforeCast(cast, caster, targets); foreach (var target in targets) { target.GetLastEffect()?.BeforeCast(cast, caster, targets); } if (cast is ISingleCast) { if (targets.Length != 1) { throw new GameException($"Invalid number of targets: {targets.Length} (Cast {cast.type})"); } ((ISingleCast)cast).Cast(caster, targets[0]); } caster.GetLastEffect()?.AfterCast(cast, caster, targets); foreach (var target in targets) { target.GetLastEffect()?.AfterCast(cast, caster, targets); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{cast.type} casted!"); Console.ResetColor(); }
public static void Attack(BattleUnitsStack attackingStack, BattleUnitsStack defendingStack) { attackingStack.state = State.MadeMove; attackingStack.GetLastEffect()?.BeforeAttack(attackingStack, defendingStack); defendingStack.GetLastEffect()?.BeforeAttack(attackingStack, defendingStack); PureAttack(attackingStack, defendingStack); attackingStack.GetLastEffect()?.AfterAttack(attackingStack, defendingStack); defendingStack.GetLastEffect()?.AfterAttack(attackingStack, defendingStack); attackingStack.GetLastEffect()?.BeforeFightBack(attackingStack, defendingStack); defendingStack.GetLastEffect()?.BeforeFightBack(attackingStack, defendingStack); if (!defendingStack.fightedBack) { defendingStack.fightedBack = true; PureAttack(defendingStack, attackingStack); } attackingStack.GetLastEffect()?.AfterFightBack(attackingStack, defendingStack); defendingStack.GetLastEffect()?.AfterFightBack(attackingStack, defendingStack); }