From 897a93c01360725e547af4a7f7919d27943b6c2c 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 10:33:46 +0200 Subject: [PATCH] Approach to turn - Random and attribute turn defines - Shuffle the character list to Random Mode - Move the camera to the character in the differents turns (if attack or move the character) Known pending tasks: - Check if the character is in a playable team - Check if the character has health - End the battle --- Assets/Scenes/test.unity | 6 +- .../Database/Characters/NewCharacter(1).asset | 14 ++ .../Database/Characters/NewCharacter(3).asset | 40 ++++- .../Database/Characters/NewCharacter.asset | 7 + Assets/TRPGMaker/Database/Database.asset | 17 ++- .../NewSpecializedClass(1).asset | 37 ++++- .../Teams/{NewTeam.asset => Prueba.asset} | 6 +- .../{NewTeam.asset.meta => Prueba.asset.meta} | 2 +- .../Windows/Battle/BattleOptionsWindow.cs | 2 +- Assets/TRPGMaker/Resources/Editor.meta | 10 ++ .../TRPGMaker/Resources/PolygonKnights.meta | 10 ++ .../Resources/PolygonKnights/Prefabs.meta | 10 ++ .../TRPGMaker/Scripts/Game/CharacterScript.cs | 46 +++++- .../TRPGMaker/Scripts/Game/GamePlayManager.cs | 139 ++++++++++++++++-- 14 files changed, 317 insertions(+), 29 deletions(-) rename Assets/TRPGMaker/Database/Teams/{NewTeam.asset => Prueba.asset} (82%) rename Assets/TRPGMaker/Database/Teams/{NewTeam.asset.meta => Prueba.asset.meta} (89%) create mode 100644 Assets/TRPGMaker/Resources/Editor.meta create mode 100644 Assets/TRPGMaker/Resources/PolygonKnights.meta create mode 100644 Assets/TRPGMaker/Resources/PolygonKnights/Prefabs.meta diff --git a/Assets/Scenes/test.unity b/Assets/Scenes/test.unity index 685fb44..59f550c 100644 --- a/Assets/Scenes/test.unity +++ b/Assets/Scenes/test.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481694, a: 1} + m_IndirectSpecularColor: {r: 0.44657868, g: 0.49641263, b: 0.5748171, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 @@ -6060,6 +6060,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: character: {fileID: 11400000, guid: 47430d8af55fb254dbd2af8d116d196d, type: 2} + team: {fileID: 11400000, guid: c7870a66a01c2a54e90fa9d468b19807, type: 2} --- !u!114 &175549501 MonoBehaviour: m_ObjectHideFlags: 0 @@ -35172,6 +35173,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: character: {fileID: 11400000, guid: 36a63a88f336fee4fbee3ca4e3812861, type: 2} + team: {fileID: 0} --- !u!114 &930472394 MonoBehaviour: m_ObjectHideFlags: 0 @@ -56300,7 +56302,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 400000, guid: 8a1da15bc40e9ac4897e6f088f39ae14, type: 2} propertyPath: m_RootOrder - value: 226 + value: 225 objectReference: {fileID: 0} - target: {fileID: 6400000, guid: 8a1da15bc40e9ac4897e6f088f39ae14, type: 2} propertyPath: m_Mesh diff --git a/Assets/TRPGMaker/Database/Characters/NewCharacter(1).asset b/Assets/TRPGMaker/Database/Characters/NewCharacter(1).asset index f9052a9..84ed76f 100644 --- a/Assets/TRPGMaker/Database/Characters/NewCharacter(1).asset +++ b/Assets/TRPGMaker/Database/Characters/NewCharacter(1).asset @@ -43,4 +43,18 @@ MonoBehaviour: minValue: 2 value: 2 isCore: 1 + - name: Move Range + id: MVR + description: + maxValue: 4 + minValue: 4 + value: 4 + isCore: 1 + - name: Agility + id: + description: + maxValue: 100 + minValue: 0 + value: 20 + isCore: 1 specializedClass: [] diff --git a/Assets/TRPGMaker/Database/Characters/NewCharacter(3).asset b/Assets/TRPGMaker/Database/Characters/NewCharacter(3).asset index 3ee6283..cbba2f4 100644 --- a/Assets/TRPGMaker/Database/Characters/NewCharacter(3).asset +++ b/Assets/TRPGMaker/Database/Characters/NewCharacter(3).asset @@ -14,8 +14,40 @@ MonoBehaviour: name: NewCharacter(3) inventory: {fileID: 0} Slots: [] - attributes: [] + attributes: + - name: Health + id: HP + description: + maxValue: 3 + minValue: 3 + value: 3 + isCore: 1 + - name: Move Range + id: MVR + description: + maxValue: 4 + minValue: 4 + value: 4 + isCore: 1 + - name: Move Height + id: MVH + description: + maxValue: 2 + minValue: 2 + value: 2 + isCore: 1 + - name: Attack Range + id: ATR + description: + maxValue: 3 + minValue: 3 + value: 3 + isCore: 1 + - name: AttackHeight + id: ATH + description: + maxValue: 2 + minValue: 2 + value: 2 + isCore: 1 specializedClass: [] - height: 0 - distance: 0 - attackRange: 0 diff --git a/Assets/TRPGMaker/Database/Characters/NewCharacter.asset b/Assets/TRPGMaker/Database/Characters/NewCharacter.asset index 958264b..8d7c984 100644 --- a/Assets/TRPGMaker/Database/Characters/NewCharacter.asset +++ b/Assets/TRPGMaker/Database/Characters/NewCharacter.asset @@ -62,4 +62,11 @@ MonoBehaviour: minValue: 2 value: 2 isCore: 1 + - name: Agility + id: + description: + maxValue: 100 + minValue: 0 + value: 10 + isCore: 1 specializedClass: [] diff --git a/Assets/TRPGMaker/Database/Database.asset b/Assets/TRPGMaker/Database/Database.asset index 4f36a0f..e3a1511 100644 --- a/Assets/TRPGMaker/Database/Database.asset +++ b/Assets/TRPGMaker/Database/Database.asset @@ -47,6 +47,13 @@ MonoBehaviour: minValue: 2 value: 2 isCore: 1 + - name: Agility + id: + description: + maxValue: 100 + minValue: 0 + value: 0 + isCore: 1 tags: - Espada - Mandoble @@ -119,10 +126,10 @@ MonoBehaviour: value: 3 isCore: 1 _attackHeight: - name: Attack Range - id: ATR + name: AttackHeight + id: ATH description: - maxValue: 3 - minValue: 3 - value: 3 + maxValue: 2 + minValue: 2 + value: 2 isCore: 1 diff --git a/Assets/TRPGMaker/Database/SpecializedClasses/NewSpecializedClass(1).asset b/Assets/TRPGMaker/Database/SpecializedClasses/NewSpecializedClass(1).asset index ae62f15..55ff20e 100644 --- a/Assets/TRPGMaker/Database/SpecializedClasses/NewSpecializedClass(1).asset +++ b/Assets/TRPGMaker/Database/SpecializedClasses/NewSpecializedClass(1).asset @@ -14,5 +14,40 @@ MonoBehaviour: name: New Specialized Class (1) tags: [] slots: [] - attributes: [] + attributes: + - name: Health + id: HP + description: + maxValue: 3 + minValue: 3 + value: 3 + isCore: 1 + - name: Move Range + id: MVR + description: + maxValue: 4 + minValue: 4 + value: 4 + isCore: 1 + - name: Move Height + id: MVH + description: + maxValue: 2 + minValue: 2 + value: 2 + isCore: 1 + - name: Attack Range + id: ATR + description: + maxValue: 3 + minValue: 3 + value: 3 + isCore: 1 + - name: AttackHeight + id: ATH + description: + maxValue: 2 + minValue: 2 + value: 2 + isCore: 1 formulas: [] diff --git a/Assets/TRPGMaker/Database/Teams/NewTeam.asset b/Assets/TRPGMaker/Database/Teams/Prueba.asset similarity index 82% rename from Assets/TRPGMaker/Database/Teams/NewTeam.asset rename to Assets/TRPGMaker/Database/Teams/Prueba.asset index c62727b..33e61b9 100644 --- a/Assets/TRPGMaker/Database/Teams/NewTeam.asset +++ b/Assets/TRPGMaker/Database/Teams/Prueba.asset @@ -9,11 +9,11 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 4a7b1fcdece9778478b2575993f98a72, type: 3} - m_Name: NewTeam + m_Name: Prueba m_EditorClassIdentifier: - name: NewTeam + name: Prueba id: 0 characters: - {fileID: 11400000, guid: 36a63a88f336fee4fbee3ca4e3812861, type: 2} - - {fileID: 11400000, guid: caa5b8cc4b5205b4297289922d3b7e33, type: 2} + - {fileID: 11400000, guid: 47430d8af55fb254dbd2af8d116d196d, type: 2} playable: 1 diff --git a/Assets/TRPGMaker/Database/Teams/NewTeam.asset.meta b/Assets/TRPGMaker/Database/Teams/Prueba.asset.meta similarity index 89% rename from Assets/TRPGMaker/Database/Teams/NewTeam.asset.meta rename to Assets/TRPGMaker/Database/Teams/Prueba.asset.meta index d3cfc7d..f27b753 100644 --- a/Assets/TRPGMaker/Database/Teams/NewTeam.asset.meta +++ b/Assets/TRPGMaker/Database/Teams/Prueba.asset.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: c7870a66a01c2a54e90fa9d468b19807 -timeCreated: 1522945787 +timeCreated: 1523297419 licenseType: Free NativeFormatImporter: externalObjects: {} diff --git a/Assets/TRPGMaker/Editor/Windows/Battle/BattleOptionsWindow.cs b/Assets/TRPGMaker/Editor/Windows/Battle/BattleOptionsWindow.cs index e95c9c2..fc48d2e 100644 --- a/Assets/TRPGMaker/Editor/Windows/Battle/BattleOptionsWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Battle/BattleOptionsWindow.cs @@ -59,7 +59,7 @@ void OnGUI() EditorGUILayout.LabelField("Turn type:"); selectedTurnStyle = EditorGUILayout.Popup(selectedTurnStyle, System.Enum.GetNames(typeof(TurnTypes))); EditorGUILayout.EndHorizontal(); - + EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Health attribute name:"); selectedHealthAttribte = EditorGUILayout.Popup(selectedHealthAttribte, Database.Instance.attributes.Select(o => o.name).ToArray()); diff --git a/Assets/TRPGMaker/Resources/Editor.meta b/Assets/TRPGMaker/Resources/Editor.meta new file mode 100644 index 0000000..b8a3a29 --- /dev/null +++ b/Assets/TRPGMaker/Resources/Editor.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 34e8954343d1d4fd79319c50bbf01c50 +folderAsset: yes +timeCreated: 1518695489 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TRPGMaker/Resources/PolygonKnights.meta b/Assets/TRPGMaker/Resources/PolygonKnights.meta new file mode 100644 index 0000000..fb1c7d5 --- /dev/null +++ b/Assets/TRPGMaker/Resources/PolygonKnights.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 31c5582ae2f324fb38e15f5b4b2bda7a +folderAsset: yes +timeCreated: 1521646865 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TRPGMaker/Resources/PolygonKnights/Prefabs.meta b/Assets/TRPGMaker/Resources/PolygonKnights/Prefabs.meta new file mode 100644 index 0000000..b28c829 --- /dev/null +++ b/Assets/TRPGMaker/Resources/PolygonKnights/Prefabs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: c30b40c00866087428749407deccd4e5 +folderAsset: yes +timeCreated: 1511801936 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs b/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs index e2e7673..71c9a4f 100644 --- a/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs +++ b/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs @@ -2,12 +2,14 @@ using System.Collections.Generic; using UnityEngine; using System.Linq; +using UnityEditor; public class CharacterScript : MonoBehaviour { private Vector2 pos; [SerializeField] public Character character; + public Team team; private void Start() { @@ -16,19 +18,57 @@ private void Start() private void OnGUI() { - if (character != null && character.attributes.Any(x => x.id == "HP")) + if (character != null) { - Attribute attribute = character.attributes.Find(x => x.id == "HP"); + Attribute attribute = character.attributes.Find(x => x.id == Database.Instance.battleOptions.healthAttribute.id); var renderer = gameObject.GetComponent(); float height = renderer.bounds.size.y * 15; pos = Camera.main.WorldToScreenPoint(transform.position); pos.y = Screen.height - pos.y - height; GUI.Box(new Rect(pos.x - 50, pos.y - 40, 100, 20), attribute.value + "/" + attribute.maxValue); - } + } } + void Update() { } } + +[CustomEditor(typeof(CharacterScript))] +public class CharacterScriptEditor : Editor +{ + private int index = -1; + private CharacterScript characterScript; + + private void OnEnable() + { + characterScript = (CharacterScript)target; + if (characterScript.team != null) { + index = Database.Instance.teams.IndexOf(characterScript.team); + } + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + SerializedProperty character = serializedObject.FindProperty("character"); + EditorGUILayout.PropertyField(character); + characterScript = (CharacterScript)target; + + EditorGUI.BeginChangeCheck(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("Team"); + index = EditorGUILayout.Popup(index, Database.Instance.teams.Where(x => x.characters.Exists(y => y.name == characterScript.character.name)).Select(item => item.name).ToArray()); + EditorGUILayout.EndHorizontal(); + + if (EditorGUI.EndChangeCheck()) { + characterScript.team = Database.Instance.teams.Where(x => x.characters.Exists(y => y.name == characterScript.character.name)).ToArray()[index]; + } + serializedObject.ApplyModifiedProperties(); + EditorUtility.SetDirty(target); + } +} \ No newline at end of file diff --git a/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs b/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs index 9f1153d..bcd5484 100644 --- a/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs +++ b/Assets/TRPGMaker/Scripts/Game/GamePlayManager.cs @@ -10,12 +10,15 @@ public class GamePlayManager : MonoBehaviour private GameObject objectCanvas; private ITRPGMapConnector connector; private CharacterScript character; + private Boolean start = false; + private int index; + private List characters; // Use this for initialization void Start() { connector = (new GameObject("IsoUnityConector")).AddComponent(); - + startCombat(); } @@ -27,25 +30,143 @@ void Update() public void startCombat() { - Turn(); + Turn(); } private void Turn() { - CharacterScript[] characters = FindObjectsOfType(); - if (character == characters[1]) + /* + * - Knowing teams in play + * - know if they are playable or not + * - Manage the turn based on the "turn type" of "battle options" + * - Random for all the characters or for equipment? ? VARIOUS TYPES OF TURN! + * + * - Defeat / victory? IN COMBAT it is analyzed, return true or false depending on... + * - If character dies, does not continue + */ + + TurnTypes turnType = Database.Instance.battleOptions.turnType; + + //Check if the battle is start to don't update constantly the characters' list + if (start == false) { - character = characters[0]; + CharacterScript[] tempCharacters = FindObjectsOfType(); + characters = new List(tempCharacters); + } + + if (characters.Count > 0) + { + if (characters.Exists(x => x.team == null)) + { + Debug.Log("Some character doesn't have any team assigned"); + } + else + { + switch (turnType) + { + case TurnTypes.Random: + // RANDOM mode. Each playable character is randomly selected on the battlefield + /* + * Given the "teams" in the field, we created a random list with each of the characters, EYE with the non-playable! + * We will pass the turn to each player in the list when performing the operation "ATTACK" or "DEFENDER", move allows you to continue using the 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(); + 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) + /* + * A list of characters is created based on the attribute (Attribute selected in battle options + * We will pass the turn to each player in the list when performing the operation "ATTACK" or "DEFENDER", move allows you to continue using the 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(); + break; + default: + Console.WriteLine("Default case"); + break; + } + } } else { - character = characters[1]; + Debug.Log("Must be at least one character"); } + } + + private void StartTurn() + { + //check if the character is in a playable team + Boolean isPlayable = true; + //Get info about character "health attribute" (battle connection) - connector.MoveCameraToCharacter(character, MoveCameraToParametrizedCallback(character, (character0, result0) => + character = characters[index]; + + if (index < characters.Count - 1) { - DrawCanvas(); - })); + index++; + } + else if (index == characters.Count - 1) + { + index = 0; + } + + if (isPlayable) // and health > 0 + { + connector.MoveCameraToCharacter(character, MoveCameraToParametrizedCallback(character, (character0, result0) => + { + DrawCanvas(); + })); + + } + else if (!isPlayable) + { + // call to IA + } // else if ( health <= 0) character dead, check if this is the last character in the team + } + + private void randomTurn() + { + if (start == false) + { + index = 0; + start = true; + reshuffle(); + Debug.Log("Random Turn Mode"); + } + + StartTurn(); + } + + private void attributeTurn() + { + if (start == false) + { + // Create the list with the characters placed according to the "attribute" + index = 0; + start = true; + Debug.Log("Attribute Turn Mode"); + Debug.Log(characters.Count); + } + + StartTurn(); + } + + /* + * Knuth shuffle algorithm + */ + private void reshuffle() + { + + for (int t = 0; t < characters.Count; t++) + { + CharacterScript tmp = characters[t]; + int r = UnityEngine.Random.Range(t, characters.Count); + characters[t] = characters[r]; + characters[r] = tmp; + } } private void DrawCanvas()