public UnitModel GetUnitAt(MyHexPosition localPosition) { if (!_units.IsPawnAt(ToGlobalPosition(localPosition))) { return(null); } return(_units.GetPawnAt(ToGlobalPosition(localPosition))); }
public BattleResults PerformBattleAtPlace(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); } } } } } // Then - our actions foreach (var orientation in OrientationUtils.AllOrientationsClockwise) { battleResults.Add(PerformSingleActiveFight(intruderUnit, orientation, battleCircumstances)); if (battleResults.UnitIncapaciated(intruderUnit)) { return(battleResults); } } return(battleResults); }