public void CheckTurnEnd() { List <Unit> currentTurnUnits; switch (currentTurn) { case Faction.Player: currentTurnUnits = unitHandler.GetPlayerUnitsCopy(); break; case Faction.Enemy: currentTurnUnits = unitHandler.GetEnemyUnitsCopy(); break; default: return; } foreach (Unit unit in currentTurnUnits) { if (unit.GetReady()) { return; } } EndTurn(); }
public void UnitAction(Unit unit) { List <Tile> moves = new List <Tile>(); GetUnitMoves(unit, moves); List <Tile> movePath = new List <Tile>(); List <Unit> playerUnits = unitHandler.GetPlayerUnitsCopy(); if (playerUnits.Count > 0) { if (moves.Count > 0) { Unit nearestUnit = GetNearestUnit(unit); Tile destination = GetNearestTile(map.GetTileByPosition(nearestUnit.GetZ(), nearestUnit.GetX()), moves); Tile pathTile = destination; while (pathTile.travelPath.travelpath != null) { movePath.Add(pathTile); pathTile = pathTile.travelPath.travelpath; } movePath.Add(map.GetTileByPosition(unit.GetZ(), unit.GetX())); map.MoveUnit(unit, destination, movePath); foreach (Tile tile in moves) { tile.ClearTravel(); } } List <Tile> attacks = GetAttacks(unit); if (attacks.Count > 0) { foreach (Tile tile in attacks) { if (tile.GetUnit() != null) { map.AttackUnit(unit, tile); break; } } } } }
void Update() { inputDelay -= 1; if (state == SelectionState.Menu) { if (Input.GetButtonDown("Up")) { menuController.MoveMenu(false); } else if (Input.GetButtonDown("Down")) { menuController.MoveMenu(true); } } if (Input.GetButtonDown("Click")) { switch (state) { case SelectionState.None: selectedUnit = battleCursor.GetCurrentTile().GetUnit(); if (selectedUnit != null && selectedUnit.GetReady()) { TransitionStateToMove(); } break; case SelectionState.Move: if (activeTiles.Contains(battleCursor.GetCurrentTile())) { Tile pathTile = battleCursor.GetCurrentTile(); while (pathTile.travelPath.travelpath != null) { movePath.Add(pathTile); pathTile = pathTile.travelPath.travelpath; } movePath.Add(map.GetTileByPosition(selectedUnit.GetZ(), selectedUnit.GetX())); oldLocation = map.GetTileByPosition(selectedUnit.GetZ(), selectedUnit.GetX()); map.MoveUnit(selectedUnit, battleCursor.GetCurrentTile(), movePath); CreateMenu("Select Action"); TransitionStateToMenu(); } else { TransitionStateToNone(); } break; case SelectionState.Attack: if (activeTiles.Contains(battleCursor.GetCurrentTile()) && battleCursor.GetCurrentTile().GetUnit() != null) { selectedUnit.GetEquippedAttack()(battleCursor.GetCurrentTile(), map, this); menuController.DeleteMenu(); TransitionStateToNone(); } else { //TransitionStateToNone(); } break; case SelectionState.Menu: menuController.ClickMenu(); break; } } else if (Input.GetButtonDown("Unclick")) { switch (state) { case SelectionState.None: break; case SelectionState.Move: TransitionStateToNone(); break; case SelectionState.Attack: map.MoveUnit(selectedUnit, oldLocation, movePath); selectedUnit.Ready(); TransitionStateToMove(); break; case SelectionState.Menu: menuController.DeleteMenu(); state = SelectionState.Attack; break; } } else if (Input.GetButton("Next") && inputDelay <= 0) { inputDelay = 15; Unit nextUnit = null; Unit currentUnit = battleCursor.GetCurrentTile().GetUnit(); List <Unit> units = unitHandler.GetPlayerUnitsCopy(); if (units.Count > 0) { if (currentUnit == null) { foreach (Unit unit in units) { if (unit.GetReady()) { nextUnit = unit; break; } } } else { int nextIndex = units.IndexOf(currentUnit) + 1; if (nextIndex >= units.Count) { nextIndex = 0; } int i = units.Count; while (!units[nextIndex].GetReady() && i > 0) { i--; nextIndex++; if (nextIndex >= units.Count) { nextIndex = 0; } } if (nextIndex >= units.Count) { nextIndex = 0; } if (i == 0) { nextUnit = null; } else { nextUnit = units[nextIndex]; } } } if (nextUnit != null) { battleCursor.MoveToTile(map.GetTileByPosition(nextUnit.GetZ(), nextUnit.GetX())); } } else if (Input.GetButtonDown("End") && inputDelay <= 0) { turnHandler.ForceEndTurn(); } }