From f82b8074063ebabf76aa8a06ebfd45c24f2ac311 Mon Sep 17 00:00:00 2001 From: vylion Date: Sun, 30 Oct 2016 19:01:19 +0100 Subject: [PATCH] Created attack to area --- Assets/3rdParty/ArcherSkeleton/prefab.meta | 9 +++++++ Assets/3rdParty/DemonImp/prefab.meta | 9 +++++++ Assets/TurnManagerScript.cs | 28 ++++++++++++++++++++++ Assets/UnitBehaviour.cs | 5 ++-- Assets/UnitCreator.cs | 11 +++++---- 5 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 Assets/3rdParty/ArcherSkeleton/prefab.meta create mode 100644 Assets/3rdParty/DemonImp/prefab.meta diff --git a/Assets/3rdParty/ArcherSkeleton/prefab.meta b/Assets/3rdParty/ArcherSkeleton/prefab.meta new file mode 100644 index 0000000..42ddf7e --- /dev/null +++ b/Assets/3rdParty/ArcherSkeleton/prefab.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 456228f09d87f2c4a9df7b9ef04226bc +folderAsset: yes +timeCreated: 1477752003 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/3rdParty/DemonImp/prefab.meta b/Assets/3rdParty/DemonImp/prefab.meta new file mode 100644 index 0000000..638eafb --- /dev/null +++ b/Assets/3rdParty/DemonImp/prefab.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f69e4ae1ab31a7b429d8d29157ff18a8 +folderAsset: yes +timeCreated: 1477757782 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TurnManagerScript.cs b/Assets/TurnManagerScript.cs index 24a84db..563e41d 100644 --- a/Assets/TurnManagerScript.cs +++ b/Assets/TurnManagerScript.cs @@ -71,6 +71,7 @@ public class TurnManagerScript : MonoBehaviour { int pi = (int)go.transform.position.z; int pj = (int)go.transform.position.x; Vector2 diff = new Vector2(Math.Abs(pi - i), Math.Abs(pj - j)); + if ((diff.x+diff.y) < ub.stepLength && ra > 0 && terrain [j, i] == 0) return true; else @@ -96,6 +97,15 @@ public class TurnManagerScript : MonoBehaviour { } public void attackTo(GameObject go, int i, int j) { + int area = go.GetComponent ().attackArea; + + if (area > 1) + attackToArea (go, i, j); + else + attackToSingleTarget (go, i, j); + } + + void attackToSingleTarget(GameObject go, int i, int j) { UnitBehaviour ub = go.GetComponent (); int pi = (int)go.transform.position.z; int pj = (int)go.transform.position.x; @@ -108,6 +118,24 @@ public class TurnManagerScript : MonoBehaviour { } } + void attackToArea(GameObject go, int x, int y) { + UnitBehaviour ub = go.GetComponent (); + int pi = (int)go.transform.position.z; + int pj = (int)go.transform.position.x; + int area = ub.attackArea; + + for (int i = -area; i <= area; i++) { + for (int j = -area; j <= area; j++) { + if (x+i >= 0 && y+j >= 0 && unitMap [x+i, y+j] != null) { + GameObject t = unitMap [x+i, y+j]; + UnitBehaviour ubt = t.GetComponent (); + int damage = ub.attackAct (); + ubt.receiveDamage (damage); + } + } + } + } + void changeTeam (int newTeam) { actualPlayer = newTeam; actualNumChars = unitList [actualPlayer].Count; diff --git a/Assets/UnitBehaviour.cs b/Assets/UnitBehaviour.cs index bdd26fb..ebe4c0a 100644 --- a/Assets/UnitBehaviour.cs +++ b/Assets/UnitBehaviour.cs @@ -49,10 +49,11 @@ public class UnitBehaviour : MonoBehaviour { public Animator anim; - public void SetupStats (int pX, int pZ, Team id, int actions = 2, int steps = 5, int p = 50, int crit = 10, int pRange = 20, int critRange = 10) { + public void SetupStats (int pX, int pZ, Team id, int h = 4, int p = 50, int crit = 10, int pRange = 20, int critRange = 10, int steps = 5, int actions = 2) { posX = pX; posZ = pZ; teamID = id; + health = h; actionsPerTurn = actions; stepLength = steps; if (pRange > 0) { @@ -72,7 +73,7 @@ public class UnitBehaviour : MonoBehaviour { remainingActions = actionsPerTurn; } - public void SetupBaseAttack (int r = 1, int a = 1, int d = 1, Elemental e = Elemental.None, int act = 2) { + public void SetupBaseAttack (int r = 1, int d = 1, int a = 1, int act = 2, Elemental e = Elemental.None) { attackRange = r; attackArea = a; attackDamage = d; diff --git a/Assets/UnitCreator.cs b/Assets/UnitCreator.cs index 571b0df..43542a9 100644 --- a/Assets/UnitCreator.cs +++ b/Assets/UnitCreator.cs @@ -68,8 +68,8 @@ public class UnitCreator : MonoBehaviour { else unit = Instantiate (lichNone, new Vector3(posX, 0f, posZ), Quaternion.identity) as GameObject; - unit.GetComponent ().SetupStats (posX, posZ, team, 3, 3, 100, 0, 0, 0); - unit.GetComponent ().SetupBaseAttack (4, 2, 3); + unit.GetComponent ().SetupStats (posX, posZ, team, 10, 100, 0, 0, 0, 3, 3); + unit.GetComponent ().SetupBaseAttack (4, 3, 2); unit.transform.localScale = new Vector3 (unit.transform.localScale.x*0.3f, unit.transform.localScale.y*0.3f, unit.transform.localScale.z*0.3f); if (team == UnitBehaviour.Team.Player && playerLichScript == null ) @@ -93,8 +93,9 @@ public class UnitCreator : MonoBehaviour { unit = Instantiate (archerRed, new Vector3(posX, 0f, posZ), Quaternion.identity) as GameObject; else unit = Instantiate (archerNone, new Vector3(posX, 0f, posZ), Quaternion.identity) as GameObject; - - unit.GetComponent ().SetupStats (posX, posZ, team); + + unit.GetComponent ().SetupStats (posX, posZ, team, 2, 80, 10, 15, 5, 7, 1); + unit.GetComponent ().SetupBaseAttack (5, 2); } else if (type == UnitType.Imp) { if (team == UnitBehaviour.Team.Player) @@ -104,7 +105,7 @@ public class UnitCreator : MonoBehaviour { else unit = Instantiate (impNone, new Vector3(posX, 0f, posZ), Quaternion.identity) as GameObject; - unit.GetComponent ().SetupStats (posX, posZ, team); + unit.GetComponent ().SetupStats (posX, posZ, team, 2, 30, 10, 30, 15, 10, 2); } else if (type == UnitType.Zombie) { if (team == UnitBehaviour.Team.Player)