//get attacker enemy and player's floor, return which player lobster enemy should attack public EnemyMove GetTarget(Lobster attacker, GameObject playerFloor) { if (attacker.GetClaw() == 0) { return(EnemyMove.Defend); } else //attack is not 0, check if there are anything it can attack { int targetIndex = -1; int targetAttack = 0; int targetLevel = 0; List <Lobster> attackable = playerFloor.GetComponent <Floor>().GetAttackableLobsters(); //player has no lobsters, let's attack the poor player if (attackable.Count == 0) { return(EnemyMove.AttackPlayer); } for (int index = 0; index < attackable.Count; ++index) { Lobster playerLob = attackable[index]; int playerClaw = playerLob.GetClaw(); int playerShell = playerLob.GetShell(); int playerLevel = playerLob.GetLevel(); //check if able to attack if (attacker.GetClaw() >= playerLob.GetShell()) { //beat lobster with highest level if (playerLevel > targetLevel) { targetIndex = index; targetLevel = playerLevel; //with the same level, beat the one with highest attack } else if (playerLevel == targetLevel && playerClaw > targetAttack) { targetIndex = index; targetAttack = playerClaw; //if can only attack 1 level card, attack rock first } else if (playerLevel == 1 && playerLob.data.cardName == "Rock") { targetAttack = index; } } } //if has a target to attack if (targetIndex >= 0) { return((EnemyMove)System.Array.IndexOf(playerFloor.GetComponent <Floor>().spots, attackable[targetIndex].floorAssigned)); } else //have nothing to attack { if (attacker.GetClaw() >= 2) { return(EnemyMove.Idle); } else { return(EnemyMove.Defend); } } } }