public BattleResults PerformProjectileHitAtPlace(MyHexPosition projectileHitPosition) { Assert.IsTrue(_units.IsPawnAt(projectileHitPosition), "There is no unit at " + projectileHitPosition); Assert.IsTrue(_projectiles.IsPawnAt(projectileHitPosition), "There is no projectile at " + projectileHitPosition); var unit = _units.GetPawnAt(projectileHitPosition); var projectile = _projectiles.GetPawnAt(projectileHitPosition); var projectileOrientation = projectile.Orientation; var projectileEffect = projectile.HitEffect; BattleEngagementResult engagementResult = new BattleEngagementResult(); var engagement = new BattleEngagement(engagementResult); AddEngagementElement(projectile, unit, engagement, projectileEffect); projectileEffect.Execute(new BattlefieldVision(projectile, projectileOrientation, _units, _mapModel, BattleCircumstances.ProjectileHit), projectileHitPosition, engagementResult); var defenderSymbolOrientation = unit.Orientation.CalculateLocalDirection(projectileOrientation.Opposite()); if (unit.Symbols.ContainsKey(defenderSymbolOrientation)) { var reactEffect = unit.Symbols[defenderSymbolOrientation].ReactEffect; AddEngagementElement(unit, projectile, engagement, reactEffect); BattlefieldVision vision = new BattlefieldVision(unit, projectileOrientation, _units, _mapModel, BattleCircumstances.ProjectileHit); reactEffect.Execute(vision, projectileHitPosition, engagementResult); } var results = new BattleResults(); results.Add(engagement); return(results); }
private BattleEngagement PerformSingleActiveFight(UnitModel attacker, Orientation orientation, BattleCircumstances battleCircumstances) { var engagementResult = new BattleEngagementResult(); var engagement = new BattleEngagement(engagementResult); var attackerSymbolLocalDirection = attacker.Orientation.CalculateLocalDirection(orientation); if (!attacker.Symbols.ContainsKey(attackerSymbolLocalDirection)) { return(engagement); } var symbol = attacker.Symbols[attackerSymbolLocalDirection]; var effect = symbol.ActiveEffect; var attackerBattlefieldVision = new BattlefieldVision(attacker, attackerSymbolLocalDirection, _units, _mapModel, battleCircumstances); if (!effect.IsActivated(attackerBattlefieldVision, attacker.Position)) { return(engagement); } var defender = effect.RetriveTarget(attackerBattlefieldVision, attacker.Position); var defendingSymbolLocalDirection = defender.Orientation.CalculateLocalDirection(orientation.Opposite()); AddEngagementElement(attacker, defender, engagement, effect); effect.Execute(attackerBattlefieldVision, attacker.Position, engagementResult); if (!effect.IsDefendableEffect) { return(engagement); } if (!defender.Symbols.ContainsKey(defendingSymbolLocalDirection)) { return(engagement); } var defenderBattlefieldVision = new BattlefieldVision(defender, defendingSymbolLocalDirection, _units, _mapModel, battleCircumstances); var defenderEffect = defender.Symbols[defendingSymbolLocalDirection].ReactEffect; if (defenderEffect.IsActivated(defenderBattlefieldVision, attacker.Position)) { AddEngagementElement(defender, attacker, engagement, defenderEffect); defenderEffect.Execute(defenderBattlefieldVision, attacker.Position, engagementResult); } return(engagement); }
private BattleEngagement PerformSingleFight(UnitModel defender, UnitModel attacker, Orientation attackerDirectionFromDefender, Func <SymbolModel, IEffect> attackingEffectExtractor, BattleCircumstances battleCircumstances) { var engagementResult = new BattleEngagementResult(); var engagement = new BattleEngagement(engagementResult); if (defender.Owner == attacker.Owner) { return(engagement); } var attackerSymbolLocalDirection = attacker.Orientation.CalculateLocalDirection(attackerDirectionFromDefender.Opposite()); var defendingSymbolLocalDirection = defender.Orientation.CalculateLocalDirection(attackerDirectionFromDefender); if (attacker.Symbols.ContainsKey(attackerSymbolLocalDirection)) { var symbol = attacker.Symbols[attackerSymbolLocalDirection]; var effect = attackingEffectExtractor(symbol); var attackerBattlefieldVision = new BattlefieldVision(attacker, attackerSymbolLocalDirection, _units, _mapModel, battleCircumstances); if (effect.IsActivated(attackerBattlefieldVision, attacker.Position)) { AddEngagementElement(attacker, defender, engagement, effect); effect.Execute(attackerBattlefieldVision, attacker.Position, engagementResult); } if (!effect.IsDefendableEffect) { return(engagement); } if (defender.Symbols.ContainsKey(defendingSymbolLocalDirection)) { var defenderBattlefieldVision = new BattlefieldVision(defender, defendingSymbolLocalDirection, _units, _mapModel, battleCircumstances); var defenderEffect = defender.Symbols[defendingSymbolLocalDirection].ReactEffect; if (defenderEffect.IsActivated(defenderBattlefieldVision, attacker.Position)) { AddEngagementElement(defender, attacker, engagement, defenderEffect); defenderEffect.Execute(defenderBattlefieldVision, attacker.Position, engagementResult); } } } return(engagement); }