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(); }
private void ToAwaitingScale(BattleUnitsStack stack) { double initiativeRandom = -currentMainScale.GetPriority(stack) % 1; currentMainScale.Remove(stack); currentAwaitingScale.Enqueue(stack, stack.metaUnit.initiative + initiativeRandom); }
public BattleUnitsStack(BattleUnitsStack otherStack) { unitsType = otherStack.unitsType; totalHitPoints = otherStack.totalHitPoints; state = otherStack.state; fightedBack = otherStack.fightedBack; initHitPoints = otherStack.initHitPoints; _metaUnit = new BattleUnit(otherStack.metaUnit); foreach (IModifier mod in otherStack.Modifiers.Keys) { Modifiers.Add(mod, (double)otherStack.Modifiers[mod]); } foreach (BaseEffect effect in otherStack.Effects.Keys) { AddEffect(effect, double.PositiveInfinity); } GetLastEffect()?.Init(); foreach (var cast in otherStack.Casts) { Casts.Add(cast); } parentArmy = otherStack.parentArmy; }
public void AddStack(BattleUnitsStack newUnitsStack) { if (_unitsStackList.Count == MAXSIZE) { throw new ArmyOverflowException($"Trying to add too many stacks to BattleArmy.\nBattleArmy.MAXSIZE is {MAXSIZE}"); } _unitsStackList.Add(new BattleUnitsStack(newUnitsStack)); }
public BattleArmy(Army otherArmy) { otherArmy.unitsStackList.ForEach((currentStack) => { var newStack = new BattleUnitsStack(currentStack); newStack.parentArmy = this; _unitsStackList.Add(newStack); }); }
public void Surrender(BattleUnitsStack stack) { if (stack.parentArmy == firstPlayerArmy) { winner = secondPlayerArmy; } else if (stack.parentArmy == secondPlayerArmy) { winner = firstPlayerArmy; } }
public BattleArmy(IEnumerable <BattleUnitsStack> otherUnitsStackList) { foreach (BattleUnitsStack currentStack in otherUnitsStackList) { if (_unitsStackList.Count == MAXSIZE) { throw new ArmyOverflowException($"Trying to make battle army of [{string.Join(", ", otherUnitsStackList)}]\nBattleArmy.MAXSIZE = {MAXSIZE}"); } var newStack = new BattleUnitsStack(currentStack); newStack.parentArmy = this; _unitsStackList.Add(newStack); } }
public BattleArmy(params UnitsStack[] otherUnitsStackList) { if (otherUnitsStackList.Length > MAXSIZE) { throw new ArmyOverflowException($"Trying to make battle army of [{string.Join<UnitsStack>(", ", otherUnitsStackList)}]\nBattleArmy.MAXSIZE = {MAXSIZE}"); } foreach (UnitsStack currentStack in otherUnitsStackList) { var newStack = new BattleUnitsStack(currentStack); newStack.parentArmy = this; _unitsStackList.Add(newStack); } }
private void ChangeInitiative(BattleUnitsStack stack, double newValue) { if (currentMainScale.Contains(stack)) { currentMainScale.UpdatePriority(stack, -newValue + currentMainScale.GetPriority(stack) % 1); } if (currentAwaitingScale.Contains(stack)) { currentAwaitingScale.UpdatePriority(stack, newValue + currentAwaitingScale.GetPriority(stack) % 1); } if (nextMainScale.Contains(stack)) { nextMainScale.UpdatePriority(stack, -newValue + nextMainScale.GetPriority(stack) % 1); } if (!(currentMainScale.Contains(stack) || currentAwaitingScale.Contains(stack) || nextMainScale.Contains(stack))) { throw new InitiativeException("Trying to change initiative of stack which is not in scale"); } }
private void ToNextRound(BattleUnitsStack stack) { Random rnd = new Random(); double initiativeRandom = 0; if (currentMainScale.Contains(stack)) { initiativeRandom = currentMainScale.GetPriority(stack) % 1; currentMainScale.Remove(stack); } else if (currentAwaitingScale.Contains(stack)) { initiativeRandom = -currentAwaitingScale.GetPriority(stack) % 1; currentAwaitingScale.Remove(stack); } if (!nextMainScale.Contains(stack)) { nextMainScale.Enqueue(stack, -(stack.unitsType.initiative + (initiativeRandom == 0 ? rnd.NextDouble() / 100 : initiativeRandom))); } }
public static void PureAttack(BattleUnitsStack attackingStack, BattleUnitsStack defendingStack) { Unit attackingUnit = attackingStack.metaUnit; Unit defendingUnit = defendingStack.metaUnit; (uint minDamage, uint maxDamage)finalDamage; if (attackingUnit.attack > defendingUnit.defence) { finalDamage.minDamage = (uint)Math.Ceiling(attackingStack.unitsCount * attackingUnit.damage.minDamage * (1 + 0.05 * (attackingUnit.attack - defendingUnit.defence))); finalDamage.maxDamage = (uint)Math.Ceiling(attackingStack.unitsCount * attackingUnit.damage.maxDamage * (1 + 0.05 * (attackingUnit.attack - defendingUnit.defence))); } else { finalDamage.minDamage = (uint)Math.Ceiling(attackingStack.unitsCount * attackingUnit.damage.minDamage / (1 + 0.05 * (defendingUnit.defence - attackingUnit.attack))); finalDamage.maxDamage = (uint)Math.Ceiling(attackingStack.unitsCount * attackingUnit.damage.maxDamage / (1 + 0.05 * (defendingUnit.defence - attackingUnit.attack))); } var random = new Random(); defendingStack.Damage((uint)random.Next((int)finalDamage.minDamage, (int)finalDamage.maxDamage)); }
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); }
public EndGameInterface(Battle _battle, BattleUnitsStack _surrenderedStack = null) { surrenderedStack = _surrenderedStack; battle = _battle; }
public abstract void AfterFightBack(BattleUnitsStack attacker, BattleUnitsStack target);
public static void Defend(BattleUnitsStack defendingStack) { defendingStack.state = State.Defending; defendingStack.AddModifier(MDefense.Instance, 1); }
public static void Wait(BattleUnitsStack waitingStack) { waitingStack.state = State.Awaiting; }
public abstract void AfterCast(ICast cast, BattleUnitsStack caster, params BattleUnitsStack[] targets);
public void RemoveStack(BattleUnitsStack stackToRemove) { _unitsStackList.Remove(stackToRemove); }
public CastInterface(Battle _battle, BattleUnitsStack _stack) { battle = _battle; stack = _stack; }
// attacker - стек, который изначально атаковал // target - стек, который дает сдачу public abstract void BeforeFightBack(BattleUnitsStack attacker, BattleUnitsStack target);
public UnitsStack(BattleUnitsStack otherStack) { unitsType = otherStack.unitsType; unitsCount = otherStack.unitsCount; }