public BattleResults PerformPassiveBattleAtPlace(MyHexPosition battleActivatorPosition, BattleCircumstances battleCircumstances) { var battleResults = new BattleResults(); var intruderUnit = _units.GetPawnAt(battleActivatorPosition); // First - Passive effects of all neighbours foreach (var pair in battleActivatorPosition.NeighboursWithDirections) { if (_mapModel.HasTileAt(pair.NeighbourPosition)) // is valid position { if (_units.IsPawnAt(pair.NeighbourPosition)) { var neighbourUnit = _units.GetPawnAt(pair.NeighbourPosition); if (!battleResults.UnitIncapaciated(neighbourUnit)) { battleResults.Add(PerformSingleFight(intruderUnit, neighbourUnit, pair.NeighbourDirection, symbol => symbol.PassiveEffect, battleCircumstances)); if (battleResults.UnitIncapaciated(intruderUnit)) { return(battleResults); } } } } } foreach (var pair in battleActivatorPosition.NeighboursWithDirections) { if (_mapModel.HasTileAt(pair.NeighbourPosition)) // is valid position { if (_units.IsPawnAt(pair.NeighbourPosition)) { var neighbourUnit = _units.GetPawnAt(pair.NeighbourPosition); if (!battleResults.UnitIncapaciated(neighbourUnit)) { battleResults.Add(PerformSingleFight(neighbourUnit, intruderUnit, pair.NeighbourDirection.Opposite(), symbol => symbol.PassiveEffect, battleCircumstances)); if (battleResults.UnitIncapaciated(intruderUnit)) { return(battleResults); } } } } } return(battleResults); }
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); }