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); }
public void Execute(BattlefieldVision vision, MyHexPosition activatingPosition, BattleEngagementResult reciever) { var unitInFront = vision.GetUnitAt(new MyHexPosition(1, 0)); Assert.IsTrue(unitInFront != null && unitInFront.Owner != vision.PossesedPawn.Owner, "There is no enemy unit in front of me"); reciever.DisplaceUnit(unitInFront, vision.ToGlobalPosition(new MyHexPosition(2, 0))); }
public void Execute(BattlefieldVision vision, MyHexPosition activatingPosition, BattleEngagementResult reciever) { var targetUnit = ShootingTarget(vision); Assert.IsNotNull(targetUnit, "There is no target"); reciever.AddProjectile(vision.PossesedPawn.Position, vision.PossesedPawn.Orientation, targetUnit.Position, _projectileType); }
public void Execute(BattlefieldVision vision, MyHexPosition activatingPosition, BattleEngagementResult reciever) { }
public void Execute(BattlefieldVision vision, MyHexPosition activatingPosition, BattleEngagementResult reciever) { var grabbedUnit = RetriveGrabbedUnit(vision); Assert.IsNotNull(grabbedUnit, "There is no target"); reciever.DisplaceUnit(grabbedUnit, vision.ToGlobalPosition(new MyHexPosition(DistanceAfterGrab, 0))); }
public void Execute(BattlefieldVision vision, MyHexPosition activatingPosition, BattleEngagementResult reciever) { Assert.IsTrue(vision.PossesedPawn is UnitModel); // TODO !!! UGLY !! if (reciever.UnitWasStruck((UnitModel)vision.PossesedPawn)) { reciever.UnStrike((UnitModel)vision.PossesedPawn); } }
public void Execute(BattlefieldVision vision, MyHexPosition activatingPosition, BattleEngagementResult reciever) { var unitInFront = vision.GetUnitAt(new MyHexPosition(0, 0)); Assert.IsTrue(unitInFront != null, "There is no enemy unit in front of me"); reciever.AddStruckUnit(unitInFront); }