/// <summary> /// Logic for the beginning of an encounter turn. /// </summary> /// <param name="unitTurn">The <see cref="UnitTurn"/> of the current unit's turn.</param> void StartTurn(UnitTurn unitTurn) { UtilityFunctions.GetActiveUnitDetector() .FlagDelegate(DelegateFlags.OnEncounterTurnStart, new TurnStartHookBundle(unitTurn), GetEncounterUnitList()); unitTurn.isActive = true; currentTurn = unitTurn; currentUnitMoveBounds = new AreaOfEffect(unitTurn.unit.position, 5); UtilityFunctions.GetActiveUnitDetector().AddIndicatorTiles(currentUnitMoveBounds.GetAllTiles(), TileIndicatorTypes.Movement); Debug.Log(UtilityFunctions.GetUnitName(unitTurn) + ":turn started; waiting"); if (CanUnitTakeAction(currentTurn)) { if (unitTurn.unit.GetTargetType() == TargetTypes.Enemy) { //CheckEncounterAI(unitTurn); } else { //playerController.SetPlayerUnit(currentTurn.unit); //uiController.PushUI(UIScreens.EncounterScreen, true); } } else { Debug.Log("due to impairment, unit cannot take action"); EndTurn(currentTurn); } }
/// <summary> /// Checks if the unit is able to take action. /// </summary> /// <param name="unitTurn">The unit turn to check.</param> /// <returns>Returns true if the unit can take action, and false otherwise.</returns> private bool CanUnitTakeAction(UnitTurn unitTurn) { List <StatusEffects> blockingImpairments = new List <StatusEffects> { StatusEffects.Stun, StatusEffects.Grab, StatusEffects.Freeze, StatusEffects.Sleep, StatusEffects.Charm, StatusEffects.Confusion, StatusEffects.Terrify, StatusEffects.TimeStop, StatusEffects.Incapacitation }; //TODO: add the rest of the blocking impairments here foreach (StatusEffects impairment in blockingImpairments) { if (unitTurn.unit.SearchStatuses(impairment)) { return(false); } } return(true); }
/// <summary> /// Creates a new <see cref="UnitTurn"/> and inserts it into <see cref="turnOrder"/>. /// </summary> /// <param name="u">The unit that will belong to the new UnitTurn object.</param> /// <param name="isPriority">Whether or not the unit turn is prioritized in the turn order.</param> private void AddUnitTurn(Unit unit, bool isPriority) { UnitTurn unitTurn = new UnitTurn(unit, isPriority); turnOrder.Add(unitTurn); OrganizeTurnOrder(); }
///<summary> /// Adds a Unit to the Turnorder ///</summary> public void AddUnitTurn(Unit unit, bool startWithFullTimer) { UnitTurn t = new UnitTurn(unit, startWithFullTimer ? 100 : 0); turnOrder.Add(t); turnOrder = turnOrder.OrderByDescending(Turn => Turn.turnTimer).ToList(); }
/// <summary> /// Logic for the ending of an encounter turn. /// </summary> /// <param name="unitTurn">The <see cref="UnitTurn"/> of the current unit's turn.</param> void EndTurn(UnitTurn unitTurn) { Debug.Log(UtilityFunctions.GetUnitName(unitTurn) + ":turn ended; proceeding"); unitTurn.isActive = false; //uiController.PushUI(UIScreens.EncounterScreen, true); UtilityFunctions.GetActiveUnitDetector() .FlagDelegate(DelegateFlags.OnEncounterTurnEnd, new TurnEndHookBundle(unitTurn), GetEncounterUnitList()); unitTurn.isCompleted = true; }
/// <summary> /// Creates a list of <see cref="UnitTurn"/> objects from a list of <see cref="Models.OverworldObject"/> objects. /// </summary> /// <param name="unitList">The list of units to convert.</param> /// <returns>Returns a list of UnitTurn objects created from the Unit list object given.</returns> private List <UnitTurn> CreateTurnOrder(List <Unit> unitList) { List <UnitTurn> turnOrder = new List <UnitTurn>(); foreach (Unit unit in unitList) { UnitTurn unitTurn = new UnitTurn(unit); turnOrder.Add(unitTurn); } return(turnOrder); }
///<summary> /// Sets up the initial turn order from all units on the map ///</summary> public void SetupTurnOrder(Unit[] unitList) { turnOrder.Clear(); unitList = unitList.OrderByDescending(Unit => Unit.unitStats.speedRating).ToArray <Unit>(); foreach (Unit u in unitList) { UnitTurn t = new UnitTurn(u, 100); turnOrder.Add(t); } currentTurn = turnOrder [0]; }
/// <summary> /// Runs the game loop of an encounter. /// </summary> /// <returns></returns> IEnumerator EncounterLoop() { while (encounterActive) { StartRound(); for (int i = 0; i < turnOrder.Count; i++) { UnitTurn unitTurn = turnOrder[i]; Debug.Log("start of turn loop"); StartTurn(unitTurn); //Selecting actions (primary/auxiliary/...) yield return(new WaitUntil(() => unitTurn.isCompleted == true)); EndTurn(unitTurn); Debug.Log("end of turn loop"); } EndRound(); } }
public void InsertAt(UnitTurn u, int i) { for (int j = turnList.Count; j >= i; j--) { if (j == i) { turnList[i] = u; } else { if (j > 0) { if (j != turnList.Count) { turnList[j] = turnList[j - 1]; } else { turnList.Add(u); } } } } }
/// <summary> /// Removes a specified unit from the current encounter. /// </summary> /// <param name="unitTurn">The <see cref="UnitTurn"/> of the unit to be removed.</param> private void RemoveUnitFromEncounter(UnitTurn unitTurn) { //turnOrder.Remove(unitTurn); UtilityFunctions.GetActiveUnitDetector().RemoveOverworldObject(unitTurn.unit); }
public TurnEndHookBundle(UnitTurn unitTurn) { this.unitTurn = unitTurn; }
public TurnStartHookBundle(UnitTurn unitTurn) { this.unitTurn = unitTurn; }
public static string GetUnitName(UnitTurn unitTurn) { return(unitTurn.unit.GetType() + " (" + unitTurn.GetHashCode() + ")"); }