From 2723297c6d7e9679abf0ca6443a4c4f3ca313629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelino=20P=C3=A9rez?= <32309834+mperez01@users.noreply.github.com> Date: Tue, 10 Apr 2018 17:19:27 +0200 Subject: [PATCH] Some fixed in turn solved - Character can move and attack after - Add finish turn --- .../TRPGMaker/Scripts/Game/GamePlayManager.cs | 154 +++++++++++++++--- 1 file changed, 128 insertions(+), 26 deletions(-) diff --git a/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs b/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs index bcd5484..f8e0656 100644 --- a/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs +++ b/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs @@ -13,13 +13,16 @@ public class GamePlayManager : MonoBehaviour private Boolean start = false; private int index; private List characters; + private Boolean move; + private Boolean attack; + private int round = 0; // Use this for initialization void Start() { connector = (new GameObject("IsoUnityConector")).AddComponent(); - startCombat(); + StartCombat(); } // Update is called once per frame @@ -28,7 +31,7 @@ void Update() } - public void startCombat() + public void StartCombat() { Turn(); } @@ -52,6 +55,7 @@ private void Turn() { CharacterScript[] tempCharacters = FindObjectsOfType(); characters = new List(tempCharacters); + round = 0; } if (characters.Count > 0) @@ -72,7 +76,7 @@ private void Turn() * When only one team remains standing, the game is over. Have another list with the characters of each team and their lives. * A character, when dying, does not disappear from the battlefield, has 0 life and can be revived (future extensions) */ - randomTurn(); + RandomTurn(); break; case TurnTypes.Attribute: // ATTRIBUTE mode. Each playable character is selected on the battlefield according to its attribute (What attribute? Add it to battle options) @@ -82,7 +86,7 @@ private void Turn() * When only one team remains standing, the game is over. Have another list with the characters of each team and their lives. * A character, when dying, does not disappear from the battlefield, has 0 life and can be revived (future extensions) */ - attributeTurn(); + AttributeTurn(); break; default: Console.WriteLine("Default case"); @@ -99,10 +103,16 @@ private void Turn() private void StartTurn() { //check if the character is in a playable team + Boolean isPlayable = true; //Get info about character "health attribute" (battle connection) + int healthValue = characters[index].character.attributes.Find(x => x.id == Database.Instance.battleOptions.healthAttribute.id).value; + character = characters[index]; + //Actual round here + + isPlayable = character.team.playable; if (index < characters.Count - 1) { @@ -111,36 +121,51 @@ private void StartTurn() else if (index == characters.Count - 1) { index = 0; + round++; } - if (isPlayable) // and health > 0 + if (healthValue > 0) { - connector.MoveCameraToCharacter(character, MoveCameraToParametrizedCallback(character, (character0, result0) => + if (isPlayable) { - DrawCanvas(); - })); + move = false; + attack = false; + connector.MoveCameraToCharacter(character, MoveCameraToParametrizedCallback(character, (character0, result0) => + { + DrawCanvas(); + })); + } + else if (!isPlayable) + { + Debug.Log("Character isn't playable"); + // call to IA and next turn + Turn(); + } } - else if (!isPlayable) + else if (healthValue <= 0) { - // call to IA - } // else if ( health <= 0) character dead, check if this is the last character in the team + //character is dead, check if this is the last character in the team + //Next turn + Debug.Log("Character dead"); + Turn(); + } } - private void randomTurn() + private void RandomTurn() { if (start == false) { index = 0; start = true; - reshuffle(); + Reshuffle(); Debug.Log("Random Turn Mode"); } StartTurn(); } - private void attributeTurn() + private void AttributeTurn() { if (start == false) { @@ -148,7 +173,6 @@ private void attributeTurn() index = 0; start = true; Debug.Log("Attribute Turn Mode"); - Debug.Log(characters.Count); } StartTurn(); @@ -157,7 +181,7 @@ private void attributeTurn() /* * Knuth shuffle algorithm */ - private void reshuffle() + private void Reshuffle() { for (int t = 0; t < characters.Count; t++) @@ -210,8 +234,6 @@ private void DrawCanvas() // Button position rtButtonMove.position = new Vector2(rtButtonMove.position.x - rtCanvas.position.x + (rtButtonMove.sizeDelta.x / 2) + 20, rtButtonMove.position.y - rtCanvas.position.y + (rtButtonMove.sizeDelta.x / 2) + 20); - buttonMove.onClick.AddListener(() => moveEvent()); - // Button Attack GameObject objectButtonAttack = new GameObject("Button"); objectButtonAttack.transform.position = objectCanvas.transform.position; @@ -236,32 +258,112 @@ private void DrawCanvas() // Button position rtButtonAttack.position = new Vector2(rtButtonAttack.position.x - rtCanvas.position.x + (rtButtonAttack.sizeDelta.x / 2) + 20, rtButtonAttack.position.y - rtCanvas.position.y + (rtButtonAttack.sizeDelta.x / 2) - 20); - buttonAttack.onClick.AddListener(() => attackEvent()); + // Button Defence + GameObject objectButtonFinishTurn = new GameObject("Button"); + objectButtonFinishTurn.transform.position = objectCanvas.transform.position; + objectButtonFinishTurn.transform.parent = objectCanvas.transform; + + Button buttonFinishTurn = objectButtonFinishTurn.AddComponent