//A coroutine that handles the turn-based portion of the battle mechanics IEnumerator LineProcessing() { //Before each loop we check if the battle is over while (!BattleOver()) { //We fill the temporary list if it's empty, if (battlers.Count == 0) { SortUnits(); } //And pop the first one in line. Unit current = battlers[0]; battlers.RemoveAt(0); //We set the controlling boolean, currentDone = false; //Then tell the unit to go, current.Act(); //And wait for it to be done. while (!currentDone) { yield return(null); } yield return(null); } //Here is where the end of battle code would begin. }
private void UpdateUnits(double Interval) { foreach (BaseUnit Unit in UnitsList) { Unit.Act(Interval); } }
public void PartyAct() { leader.Act(E_ActionList.MainSkill); foreach (Unit member in memberList) { member.Act(E_ActionList.SubSkill); } }
private void TileClickEvent(Tile tile) { // If the tile is occupied, select the unit stored in that tile if (tile.IsOccupied) { SelectUnit(tile.StoredId); return; } // If we have a unit and it is the active unit, move it if (IsActivePlayerUnit(selectedUnit)) { UnitAction action = new UnitAction(tile, Constants.ActionType.MOVE); selectedUnit.Act(action); GameComponents.TurnHandler.EndTurn(); } // TODO else give feedback for not being able to move }
IEnumerator LineProcessing() { SortUnits(); while (line.Count > 0) { current = line[0]; line.RemoveAt(0); current.Act(); yield return(null); } }
private void UnitTurnStartedEvent(Unit unit) { // If the Unit is on the enemy team, perform a random action then end it's turn if (unit.Stats.Team == 2) { if (GameComponents.TurnHandler.GetTurnOrder().All(unitInTurn => unitInTurn.Stats.Team == 2)) { return; // Only enemies left, don't want to keep calling AI } UnitAction action = AI.GetAction(unit); unit.Act(action); // TODO wait until the unit has finished its turn (animation/particle effects etc.) GameComponents.TurnHandler.EndTurn(); } }
IEnumerator LineProcessing() { SortUnits(); while (line.Count > 0) { current = line[0]; line.RemoveAt(0); current.Act(); yield return(new WaitForSeconds(0.5f)); } if (BattleOver()) { //BattleEnding(); yield break; } else { StartRound(); } }
IEnumerator LineProcessing() { SortUnits(); while (line.Count > 0) { current = line[0]; line.RemoveAt(0); current.Act(); //Polish stuffs - Instead of just waiting for a certain amount of time, //we wait for these booleans to be true! while (printing) { yield return(null); } animating = true; while (animating) { yield return(null); } while (!Input.GetKeyDown(KeyCode.Mouse0)) { yield return(null); } } if (BattleOver()) { BattleEnding(); yield break; } else { StartRound(); } }
public void Update() { interval = sw.ElapsedMilliseconds / timeDivider; sw.Reset(); // reset the timer (change current time to 0) sw.Start(); conMan.Update(Inter.Update(VecUnits)); List <BaseUnit> Removable = new List <BaseUnit>(); foreach (BaseUnit Unit in VecUnits) { if (Unit.Health <= 0) { Removable.Add(Unit); } Unit.Act(interval); } foreach (BaseUnit Unit in Removable) { VecUnits.Remove(Unit); } }
//AI public IEnumerator AIMakeDecision() { while (true) { if (!pauseInput) { //establish references List<Unit> enemies = new List<Unit> (); foreach (var pair in totalForcesDetails) { if (pair.Key != currentController) { enemies.AddRange (pair.Value); } } List<Unit> availableUnits = new List<Unit> (totalForcesDetails [currentController]); //all done? availableUnits.RemoveAll (i => i.done); if (availableUnits.Count == 0) { yield return new WaitForSeconds (1f); ControllerDone (); yield break; } //evaluate situation and decide which unit to move float highestEnemyPriority = float.MinValue; float highestMyPriority = float.MinValue; foreach (Unit u in enemies) { if (u.priority > highestEnemyPriority) { highestEnemyPriority = u.priority; } foreach (Unit i in availableUnits) { if (i.priority > highestMyPriority) { highestMyPriority = i.priority; } float sortiePriority = u.priority / Unit.Distance2D (u.gameObject, i.gameObject); if (sortiePriority > i.sortiePriority) { i.sortiePriority = sortiePriority; i.preferedTarget = u; } } } foreach (Unit u in availableUnits) { float formationFactor = 1f; if (u.isolated || u.morale == "overwhelmed") { formationFactor = 0.5f; } u.sortiePriority *= ((float)(u._stamina + u._focus) / (float)(u.stamina + u.focus)) * ((float)(u._hp) / (float)(u.hp)) * formationFactor; } Unit unitToAct = availableUnits.OrderByDescending (x => x.sortiePriority).First(); //decide strategy int myForce = totalForces [currentController]; int enemyForce = 0; foreach (var pair in totalForces) { if (pair.Key != currentController) { enemyForce += totalForces [pair.Key]; } } string strategy = ""; if (enemyForce >= myForce && highestEnemyPriority < highestMyPriority) { strategy = "defensive"; } else { strategy = "aggressive"; } //generate a path finding map Dictionary<GameObject, int> map = new Dictionary<GameObject, int> (); if (strategy == "defensive") { List<GameObject> _unitSpaces = new List<GameObject> (unitSpaces); _unitSpaces = _unitSpaces.OrderByDescending (x => x.GetComponent<UnitSpace> ().priority).ThenBy (x => Unit.Distance2D (unitToAct.gameObject, x)).ToList(); unitToAct.strategicPoint = _unitSpaces[0]; AIFloodFill (_unitSpaces[0], 0, map, unitToAct); } else { AIFloodFill (unitToAct.preferedTarget.currentUnitSpace, 0, map, unitToAct); } //set cam focus mainCam.GetComponent<CameraControl> ().SetFocus (unitToAct.gameObject); //wait for a bit before taking action yield return new WaitForSeconds (1f); unitToAct.Act (map, strategy); //clear records unitToAct.strategicPoint = null; foreach (Unit u in availableUnits) { u.sortiePriority = 0f; u.preferedTarget = null; } yield return new WaitForSeconds (0.5f); } else { yield return null; } } }