public async Task StartCombatAsync() { log.Debug("[ac:{id}] Start combat {a} vs {b}", CombatId, Attacker.Name, Defender.Name); log.Debug("{name} bonus (a/d) {a}/{d}", Attacker.Name, Attacker.GetEquipmentBonusses().AttackBonus, Attacker.GetEquipmentBonusses().DefenceBonus); log.Debug("{name} bonus (a/d) {a}/{d}", Defender.Name, Defender.GetEquipmentBonusses().AttackBonus, Defender.GetEquipmentBonusses().DefenceBonus); while (Attacker.HpCurrent > 0 && Defender.HpCurrent > 0) { Round++; await DoRoundAsync(); } if (Attacker.HpCurrent <= 0 && Defender.HpCurrent <= 0) { Outcome = CombatOutcome.Tie; } else if (Attacker.HpCurrent > 0 && Defender.HpCurrent <= 0) { Outcome = CombatOutcome.Attacker; } else if (Attacker.HpCurrent <= 0 && Defender.HpCurrent > 0) { Outcome = CombatOutcome.Defender; } await StoreCombatLogAsync(); log.Debug("[ac:{id}] Combat ended", CombatId); }
async Task DoRoundAsync() { await Task.Run(() => { CombatLog.Add($"Begin round {Round}"); // Issue attacks // TODO: Players: Allow to set when to heal etc.. // TODO: Monsters: Heal when < x% hp (have setting to be able to heal in EncounterTemplate) AttackerAttacks.Add(new Attack($"{Attacker.Name} sword strike", Attacker.GetEquipmentBonusses().AttackBonus + DiceNotation.Dice.Roll("1d6"), Attack.DamageTypes.Physical, 1)); DefenderAttacks.Add(new Attack($"{Defender.Name} claw strike", Defender.GetEquipmentBonusses().AttackBonus + DiceNotation.Dice.Roll("1d6"), Attack.DamageTypes.Physical, 1)); // Execute all attacks with duration > 1 foreach (var a in AttackerAttacks) { if (a.Duration == 0) { continue; } a.Execute(Defender); CombatLog.Add($" {Defender.Name} got hit by {a.Name} for {a.DamageAmount} {a.DamageType} damage. {Defender.HpCurrent}hp remaining"); } foreach (var a in DefenderAttacks) { if (a.Duration == 0) { continue; } a.Execute(Attacker); CombatLog.Add($" {Attacker.Name} got hit by {a.Name} for {a.DamageAmount} {a.DamageType} damage. {Attacker.HpCurrent}hp remaining"); } // Remove all attacks with duration 0 AttackerAttacks.RemoveAll(a => a.Duration == 0); DefenderAttacks.RemoveAll(a => a.Duration == 0); }); }