public void ShowMoveableBlocks() //FIX NAME { moveOrAttack = 0; int x = parent.GetComponent <GridStat>().x; int y = parent.GetComponent <GridStat>().y; gridBehaviorCode.FindSelectableBlock(x, y, playerStats.moveSpeed.GetValue(), false, false); }
IEnumerator EnemyAction() { GameObject p = CheckIfPlayerInDetectableRange(); attackNext = false; gridBehaviorCode.resetVisit(); pathToPlayer.Clear(); //thats mean no player in range if (p == null) { yield return(new WaitUntil(() => triggerShowMoveableBlocks == true)); ShowMoveableBlocks(); yield return(new WaitUntil(() => triggerSelectOnePositionToMove == true)); GameObject target = SelectOnePositionToMove(); if (target != null) { FinalMove(target.GetComponent <GridStat>().x, target.GetComponent <GridStat>().y); } else { print("enemy skip moving"); } print("end enemy action"); } else { bool playerInRange; ShowAttackableBlocks(parent.GetComponent <GridStat>().x, parent.GetComponent <GridStat>().y); playerInRange = IsPlayerInRange(); if (playerInRange == true)//attack { //before attack check GameObject toMoveBlock; toMoveBlock = MoveFurther(); if (toMoveBlock == null) { List <GameObject> o = new List <GameObject>(); o.Add(playerTarget); Attack(o); print("end enemy action"); } else { int currentX = parent.GetComponent <GridStat>().x; int currentY = parent.GetComponent <GridStat>().y; gridBehaviorCode.FindSelectableBlock(currentX, currentY, enemyStats.moveSpeed.GetValue(), false, true); tempList.Clear(); tempList = gridBehaviorCode.tempOfInteractableBlocks; foreach (GameObject t in tempList) { //now tempList has all the possible position to go if (t.GetComponent <GridStat>().occupied == true && t.GetComponent <GridStat>().standable == false) { tempList.Remove(t); } } print("location is " + toMoveBlock.GetComponent <GridStat>().x + "," + toMoveBlock.GetComponent <GridStat>().y); FinalMove(toMoveBlock.GetComponent <GridStat>().x, toMoveBlock.GetComponent <GridStat>().y); List <GameObject> o = new List <GameObject>(); o.Add(playerTarget); Attack(o); print("end enemy action"); } } else// find the block to be in attack range { int currentX = parent.GetComponent <GridStat>().x; int currentY = parent.GetComponent <GridStat>().y; gridBehaviorCode.FindSelectableBlock(currentX, currentY, enemyStats.moveSpeed.GetValue(), false, true); tempList.Clear(); tempList = gridBehaviorCode.tempOfInteractableBlocks; foreach (GameObject t in tempList) { //now tempList has all the possible position to go if (t.GetComponent <GridStat>().occupied == true && t.GetComponent <GridStat>().standable == false) { tempList.Remove(t); } } pathToPlayer = getPathTo(playerTarget, detectableRange); if (pathToPlayer == null) { print("pathToPlayer = null"); } print("going to " + playerTarget.name); GameObject toMoveBlock = FindTheAttackableBlock(pathToPlayer); //move first then check attackNext if (toMoveBlock != null) { print("this is to move block" + toMoveBlock.GetComponent <GridStat>().x + "," + toMoveBlock.GetComponent <GridStat>().y); FinalMove(toMoveBlock.GetComponent <GridStat>().x, toMoveBlock.GetComponent <GridStat>().y); } if (attackNext == true) { List <GameObject> d = new List <GameObject>(); d.Add(playerTarget); Attack(d); print("end enemy action"); } } } }