public bool HPDamage(int damage) // Returns True on Kill / False otherwise { currentHealth -= damage; if (currentHealth > 0) { StartCoroutine("HurtAnimation", damage); return(false); } else { occupiedTile.ClearUnit(); StartCoroutine("DeathAnimation"); occupiedTile.ClearUnit(); return(true); } }
public override void attack(GameObject target) { //TODO: implement this TileBehavior targettile = target.GetComponent <TestClass>().occupiedTile.GetComponent <TileBehavior>(); int curdmg = damage; if (cName == "Grunt") { //implement grunt adjacency checks, tbh idk how to do this yet List <GameObject> adjacentlist = getadjacent(targettile); curdmg = -1; foreach (GameObject unit in adjacentlist) { if (unit.GetComponent <TestClass>().faction == "insect") { curdmg += 1; } } } if (cName == "Grasshopper") { if (distmoved == 4 && canMove == false) { curdmg = 4; } } target.GetComponent <TestClass>().TakeDamage(curdmg); if (cName == "Beetle") { if (targettile.xPosition > positionx) { int place = positionx - 1; if (GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().PlaceUnit(target); targettile.ClearUnit(); } } else if (targettile.xPosition < positionx) { int place = positionx + 1; if (GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().PlaceUnit(target); targettile.ClearUnit(); } } else if (targettile.yPosition > positiony) { int place = positiony - 1; if (GameManager.GetSingleton().mapArray[positionx, place].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[positionx, place].GetComponent <TileBehavior>().PlaceUnit(target); targettile.ClearUnit(); } } if (targettile.yPosition < positiony) { int place = positiony + 1; if (GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[positionx, place].GetComponent <TileBehavior>().PlaceUnit(target); targettile.ClearUnit(); } } //check if square opposite of beetle is open //set position of the target to the spot behind beetle } }
public override void attack(GameObject target) { //TODO: implement this AttackSound(); TileBehavior targettile = target.GetComponent <TestClass>().occupiedTile.GetComponent <TileBehavior>(); int curdmg = damage; string targetname = target.GetComponent <TestClass>().unitName; if (unitName == "Grunt") { //implement grunt adjacency checks, tbh idk how to do this yet List <GameObject> adjacentlist = getadjacent(targettile); curdmg = 2; foreach (GameObject unit in adjacentlist) { if (unit.GetComponent <TestClass>().faction == "insect") { curdmg += 1; } } } if (unitName == "Geowulf") { List <GameObject> adjacentlist = getadjacent(targettile); foreach (GameObject unit in adjacentlist) { if (unit.GetComponent <TestClass>().faction != "rock") { unit.GetComponent <TestClass>().TakeDamage(1); } } } if (unitName == "Bouldef") { int dist = 0; dist += Mathf.Abs(positionx - target.GetComponent <TestClass>().positionx); dist += Mathf.Abs(positiony - target.GetComponent <TestClass>().positiony); if (dist > 1) { curdmg -= 1; } } if (unitName == "Enforcer") { int dist = 0; dist += Mathf.Abs(positionx - target.GetComponent <TestClass>().positionx); dist += Mathf.Abs(positiony - target.GetComponent <TestClass>().positiony); curdmg = dist + 1; if (canMove == false) { Mathf.Floor(curdmg / 2); } } if (unitName == "Grasshopper") { if (distmoved == 4 && canMove == false) { curdmg = 4; } } if (unitName == "Beetle") { if (targettile.xPosition > positionx) { int place = positionx - 1; if (GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().PlaceUnit(target); target.GetComponent <Character>().TileToXY(targettile); targettile.ClearUnit(); } } else if (targettile.xPosition < positionx) { int place = positionx + 1; if (GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().PlaceUnit(target); target.GetComponent <Character>().TileToXY(targettile); targettile.ClearUnit(); } } else if (targettile.yPosition > positiony) { int place = positiony - 1; if (GameManager.GetSingleton().mapArray[positionx, place].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[positionx, place].GetComponent <TileBehavior>().PlaceUnit(target); target.GetComponent <Character>().TileToXY(targettile); targettile.ClearUnit(); } } else if (targettile.yPosition < positiony) { int place = positiony + 1; if (GameManager.GetSingleton().mapArray[place, positiony].GetComponent <TileBehavior>().myUnit == null) { GameManager.GetSingleton().mapArray[positionx, place].GetComponent <TileBehavior>().PlaceUnit(target); target.GetComponent <Character>().TileToXY(targettile); targettile.ClearUnit(); } } if (targetname == "Stalmight") { TakeDamage(2); } //check if square opposite of beetle is open //set position of the target to the spot behind beetle } target.GetComponent <TestClass>().TakeDamage(curdmg); }