From 3d59441ad5739d8833820d4a8e602858e422ebd7 Mon Sep 17 00:00:00 2001 From: vylion Date: Sun, 30 Oct 2016 19:10:45 +0100 Subject: [PATCH] added attack range check --- Assets/InputManagerScript.cs | 8 ++++++-- Assets/TurnManagerScript.cs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Assets/InputManagerScript.cs b/Assets/InputManagerScript.cs index 23e0655..b6b8ec0 100644 --- a/Assets/InputManagerScript.cs +++ b/Assets/InputManagerScript.cs @@ -122,8 +122,12 @@ public class InputManagerScript : MonoBehaviour { Vector3 tpos = cursor.transform.position; switch (actionOption) { case 0: - tmss.attackTo (gosel, (int)tpos.z, (int)tpos.x); - changeCursorColor (Color.cyan); + if (tmss.canAttackTo (gosel, (int)tpos.z, (int)tpos.x)) { + tmss.attackTo (gosel, (int)tpos.z, (int)tpos.x); + changeCursorColor (Color.cyan); + } else { + changeCursorColor (Color.red); + } break; case 1: if (tmss.canMoveTo (gosel, (int)tpos.z, (int)tpos.x)) { diff --git a/Assets/TurnManagerScript.cs b/Assets/TurnManagerScript.cs index ae3447f..bb3cbdf 100644 --- a/Assets/TurnManagerScript.cs +++ b/Assets/TurnManagerScript.cs @@ -96,6 +96,19 @@ public class TurnManagerScript : MonoBehaviour { ub.stopMoveAct (); } + public bool canAttackTo(GameObject go, int i, int j) { + UnitBehaviour ub = go.GetComponent (); + int ra = ub.remainingActions; + 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.attackRange && ra > 0 && terrain [j, i] == 0) + return true; + else + return false; + } + public void attackTo(GameObject go, int i, int j) { int area = go.GetComponent ().attackArea;