public void StartCombat() { //Initialize Stack TheStack = GetCombatResults(AttackerDamageParameters, DefenderDamageParameters); //Assign Sprites to each side LeftSide.AnimationObject.GetComponent <SpriteRenderer>().sprite = LeftSide.Unit.GetComponent <SpriteRenderer>().sprite; RightSide.AnimationObject.GetComponent <SpriteRenderer>().sprite = RightSide.Unit.GetComponent <SpriteRenderer>().sprite; //Swap Cameras combatCam.enabled = true; mainCam.enabled = false; //Set Flag to start animating TimeStamp = Time.time + 2.25f; SimulateCombat = true; //Disable the menu getCombatInfo menu = FindObjectOfType <getCombatInfo>(); menu.CloseMenu(); }
//A little state machine to handle different actions depending on what is being done with the selected unit private void StateMachine(RPGClass Unit) { switch (Unit.CurrentState) { case Character._State.Selected: //Put up some indicators for movement, current pathm and attackable tiles Path = UpdateCurrentPath(LevelMap[Cursor.x, Cursor.y], Unit, Path, AvailableTilesForTravel); DisplayIndicator(Indicators[1], AvailableTilesForTravel); DisplayIndicator(Indicators[0], Path); DisplayIndicator(Indicators[2], RedTiles); //If the player wants to confirm movement, move the unit to the last tile on the path if (inputs.CheckSelectDown()) { RPGClass temp = Cursor.GetUnitAtCursorPosition(); if (temp == null || temp == SelectedUnit) { Unit.CurrentState = Character._State.SelectingAction; Unit.x = Path[Path.Length - 1].x; Unit.y = Path[Path.Length - 1].y; AvailableTilesForAttack = GetRangeAtPoint(Unit.CombatParameters.EquipedWeapon, Path[Path.Length - 1], LevelMap); SoundPlayer.clip = SelectNoise; SoundPlayer.Play(); } } //If the player wants to cancel the selection, deselect the unit if (inputs.CheckCancelDown()) { DeselectUnit(Character._State.Idle); SoundPlayer.clip = CancelNoise; SoundPlayer.Play(); } break; case Character._State.SelectingAction: //Put up some indicators for what is in range DisplayIndicator(Indicators[2], AvailableTilesForAttack); //If the player wants to confirm an action if (inputs.CheckSelectDown()) { RPGClass TempUnit = Cursor.GetUnitAtCursorPosition(); if (TempUnit != null) { //If the player clicks the selected unit they will begin waiting if (TempUnit == Unit) { DeselectUnit(Character._State.Waiting); SoundPlayer.clip = SelectNoise; SoundPlayer.Play(); } //If the player clicks an enemy unit, combat will begin else if (!TempUnit.CompareTag(SelectedUnit.tag) && PathContains(LevelMap[TempUnit.x, TempUnit.y], AvailableTilesForAttack)) { SelectedUnit.CurrentState = Character._State.InCombat; //Set up the combat Manager with new stats CombatManager cManager = gameObject.GetComponent <CombatManager>(); cManager.InitializeCombatParameters(Unit, TempUnit, LevelMap[Unit.x, Unit.y], LevelMap[TempUnit.x, TempUnit.y]); //cManager.StartCombat(); SoundPlayer.clip = SelectNoise; SoundPlayer.Play(); } } } //If the player wants to cancel their move and put the unit back at the starting tile if (inputs.CheckCancelDown()) { Unit.x = Path[0].x; Unit.y = Path[0].y; SetSelectedUnit(Unit, LevelMap); //If I don't recalculate all of the pathfinding, the game crashes SoundPlayer.clip = CancelNoise; SoundPlayer.Play(); } break; case Character._State.InCombat: getCombatInfo menu = FindObjectOfType <getCombatInfo>(); CombatManager cMan = GetComponent <CombatManager>(); RPGClass tempUnit; if (Unit != cMan.LeftSide.Unit) { tempUnit = cMan.LeftSide.Unit; } else { tempUnit = cMan.RightSide.Unit; } DisplayIndicator(Indicators[2], LevelMap[tempUnit.x, tempUnit.y]); //End combat after it has been run all the way if (!cMan.SimulateCombat) { if (menu.transform.parent.name == menu.DisabledView.name) { DeselectUnit(Character._State.Waiting); } //Unit.CurrentState = Character._State.Waiting; } //on submit action, start combat (only while not already in combat) if (inputs.CheckSelectDown()) { cMan.StartCombat(); SoundPlayer.clip = SelectNoise; SoundPlayer.Play(); } //on cancel action, go back 1 state if (inputs.CheckCancelDown()) { Unit.CurrentState = Character._State.SelectingAction; menu.CloseMenu(); SoundPlayer.clip = CancelNoise; SoundPlayer.Play(); } } break; default: //If the selected unit gets put in an unintended state, deselect them and make them wait print("Defaulted. Previous State: " + Unit.CurrentState.ToString()); DeselectUnit(Character._State.Waiting); break; } }