public void updateDescription() { MoveSelector_Child kiddo = currentMenu.GetComponent <MoveSelector_Child>(); int sel = kiddo.currentSelection; SelectorNode selected; try { selected = current.children[sel]; } catch (ArgumentOutOfRangeException e) { selected = current.children[0]; } if (types.ContainsKey(selected.name)) { if (types[selected.name] == "move") { Move m = MoveUtils.GetMove(selected.name); kiddo.setDescription(m.description); } else if (types[selected.name] == "item") { Item i = (Item)selections[selected.name]; kiddo.setDescription(i.description); } } }
/* * Name: getMoves * Description: Returns a list of Move objects that this PlayerCharacter is authorized to use. */ public Move[] getMoves() { //TODO: Actually calculate what moves are possible. MoveUtils.InitMoves(); List <string> names = new List <string>(); List <Move> moves = new List <Move>(); names.Add("Bash"); names.Add("Wrench Throw"); names.Add("Two Handed Swing"); names.Add("Pierce The Heart"); /*if (weapon == "Wrench") { * names.Add("Bash"); * if (level >= 2) { * names.Add("Wrench Throw"); * } * if (level >= 3) { * names.Add("Two Handed Swing"); * } * } else if(weapon == "Fan Sword") { * if (level >= 4) { * names.Add("Slash"); * names.Add("Two Handed Swing"); * } * if (defense >= 5) { * names.Add("Pierce The Heart"); * } * } else { * Debug.LogWarning("The weapon held by the PlayerCharacter script doesn't have logic!"); * }*/ List <string> addedMoves = new List <string>(); foreach (string name in names) { if (!addedMoves.Contains(name)) { addedMoves.Add(name); moves.Add(MoveUtils.GetMove(name)); } } return(moves.ToArray()); }
public void Start() { /*if (GameController.player == null) { * GameController.player = new PlayerCharacter(); * Debug.LogWarning("Can't find PlayerCharacter script in the scene. This may cause issues."); * }*/ takeControl = true; Debug.Log("Player in Move Selector: " + GameController.player.strength); /*if(GameController.player == null) { * Debug.LogWarning("There is no fighter class attached to the move selector. I'm creating a fake player for testing purposes."); * GameController.player = new PlayerCharacter(); * GameController.player.testInventory(); * }*/ if (GameController.player.name == "[Test_inv]") { GameController.player.testInventory(); } MoveUtils.InitMoves(); selections = new Dictionary <string, object>(); types = new Dictionary <string, string>(); selectorMap = new Dictionary <SelectorType, GameObject>(); selectorMap[SelectorType.Loop] = loopObject; selectorMap[SelectorType.Grid] = gridObject; selectorMap[SelectorType.In_Place] = inPlaceObject; root = new SelectorNode("root", "ROOT", new List <SelectorNode>(), SelectorType.Grid); SelectorNode moves = new SelectorNode("moves", "Moves", new List <SelectorNode>(), SelectorType.Loop); root.addChild(moves); foreach (Move m in GameController.player.getMoves()) { selections.Add(m.name, MoveUtils.GetMove(m.name)); types.Add(m.name, "move"); moves.addChild(new SelectorNode(m.name, m.name)); } items = new SelectorNode("items", "Items", new List <SelectorNode>(), SelectorType.Loop); root.addChild(items); if (GameController.player.inventory.Count > 0) { foreach (Item item in GameController.player.inventory) { Debug.Log(item.getName()); if (item.getName() != "Rock" && item.getName() != "Ladder") { selections.Add(item.getName(), item); types.Add(item.getName(), "item"); items.addChild(new SelectorNode(item.getName(), item.getDisplayName())); } } } SelectorNode options = new SelectorNode("run", "Run"); root.addChild(options); SelectorNode special = new SelectorNode("special", "Special", new List <SelectorNode>(), SelectorType.Loop); root.addChild(special); current = root; updateDisplay(); }
// Update is called once per frame void Update() { animationNeeded = false; animationData = ""; moveName = ""; float jump = Input.GetAxis("Jump"); jumpFrame = false; if (jump > 0 && oldJump == 0 && moveSelector != null && !moveSelector.GetComponent <MoveSelector>().takeControl) { jumpFrame = true; } oldJump = jump; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // | | // | If you're looking for the state machine process, it's right here. | // | | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (state == "player") { //See if the player has selected a move by getting the string and then seeing if it's null. string selectedMove = GameController.player.getSelectedMove(true); if (selectedMove != null) { moveSelector.GetComponent <MoveSelector>().takeControl = false; //Check if the player has enough stamina for this move. Move m = MoveUtils.GetMove(selectedMove); if (m.moveEligible(GameController.player)) { // Check if player stats need to be changed this turn if (defenseEffect - 1 > 0) { defenseEffect -= 1; } else { // Reset defense GameController.player.defense = baseDefense; } //This block runs when the player has selected a move. Run any logic needed to process the move. string status = processMove(GameController.player, enemy, selectedMove); string prefix = ""; if (selectedMove != Constants.ItemUse && selectedMove != Constants.Stunned && selectedMove != "Run") { prefix = "You used " + selectedMove + "! "; } setStatus(prefix + status); //Set the state to display_wait to allow the player time to read what's happened. state = "display_wait"; if (runAnimation) { animationNeeded = true; if (m.animateAttacker) { animationData = "player_buff"; } else if (m.animateDefender) { animationData = "enemy_damage"; } moveName = selectedMove; } waitStart = Time.time; if (selectedMove == "Run") { gameOver = true; exitState = "run"; } if (gameOver) { nextState = "end"; } else { nextState = "enemy"; } } else { setStatus("You don't have enough stamina!"); //Set the state to display_wait. state = "display_wait"; waitStart = Time.time; nextState = "player"; } } } if (state == "enemy") { //Have the enemy player run it's logic. string selectedMove = enemy.getMove(); string status = processMove(enemy, GameController.player, selectedMove); Move m = MoveUtils.GetMove(selectedMove); if (selectedMove == Constants.Stunned || selectedMove == "NoStamina") { setStatus(status); } else { setStatus("The enemy used " + selectedMove + "! " + status); } //Set the state to display_wait to allow the player time to read what's happened. state = "display_wait"; if (runAnimation) { animationNeeded = true; if (m.animateAttacker) { animationData = "enemy_buff"; } else if (m.animateDefender) { animationData = "player_damage"; } moveName = selectedMove; } waitStart = Time.time; if (gameOver) { nextState = "end"; } else { nextState = "player"; } } if (state == "display_wait") { if (Time.time >= waitStart + waitTime) { state = nextState; if (nextState == "player") { moveSelector.GetComponent <MoveSelector>().takeControl = true; } } if (jumpFrame) { state = nextState; if (nextState == "player") { moveSelector.GetComponent <MoveSelector>().takeControl = true; } } } if (state == "end") { setStatus(finalStatus); if (jumpFrame) { //The player is ready to leave the fight. DontDestroyOnLoad(this.gameObject); state = "post-fight"; if (nextScene == "TitleScreen") { //Destroy ALL gameobjects. foreach (GameObject o in Object.FindObjectsOfType <GameObject>()) { if (o != this.gameObject) { Destroy(o); } } SceneManager.LoadScene(nextScene); } } } if (state != "post-fight") { updateUI(); } }
string processMove(Fighter attack, Fighter defend, string move) { runAnimation = false; // Check if attacker is stunned if (move == Constants.Stunned) { return(attack.name + " is stunned!"); } if (move == Constants.ItemUse) { return("You used an item!"); } if (move == "NoStamina") { return(attack.name + " has no stamina!"); } if (move == "Run") { return("You ran from the fight!"); } //Get the move from the move name. Move moveObj = MoveUtils.GetMove(move); Dictionary <string, int> moveData = moveObj.processMove(attack, defend); //Apply effects to attacker/defender. if (moveData.ContainsKey(Constants.HP)) { int damage = moveData[Constants.HP]; if (defend.invulnerable == 0) { if (defend.defense <= 4) { defend.takeDamage(damage); } else if (5 <= enemy.defense && enemy.defense <= 9) { defend.takeDamage(damage - 1); } else if (10 <= enemy.defense && enemy.defense <= 19) { defend.takeDamage(damage - 2); } else { defend.takeDamage(damage - 3); } runAnimation = true; } } if (moveData.ContainsKey(Constants.GuaranteedHP)) { int damage = moveData[Constants.GuaranteedHP]; defend.takeDamage(damage); runAnimation = true; } if (moveData.ContainsKey(Constants.Heal)) { int amt = moveData[Constants.Heal]; attack.heal(amt); runAnimation = true; } if (moveData.ContainsKey(Constants.Stunned)) { int turns = moveData[Constants.Stunned]; for (int i = 0; i < turns; ++i) { // Will add "Stunned" move to defender move queue for i turns defend.addSelectedMove(Constants.Stunned); } } if (moveData.ContainsKey(Constants.DefenseEffect)) { defenseEffect += moveData[Constants.DefenseEffect]; } if (moveData.ContainsKey(Constants.Invulnerability)) { attack.invulnerable += moveData[Constants.Invulnerability]; runAnimation = true; } //Calculate damage string here. if (defend.invulnerable > 0) { defend.invulnerable--; } return(""); }