//---------------------------------------------------------------------------------------------- // Reason() is used to determine the conditions to transition out of the melee attack state, // and what state to transition into public override void Reason() { Transform adolescentTransform = npcAdolescentController.transform; Vector3 closestplayer = npcAdolescentController.GetClosestPlayer(); if (health && health.IsDead()) { //if the health script is present on the adolescent and its dead, transition to the dead //state npcAdolescentController.PerformTransition(Transition.NoHealth); return; } bool playersDead = true; for (int i = 0; i < GameManager.instance.Players.Count; i++) { if (playerHealths[i] && !playerHealths[i].IsDead()) { playersDead = false; break; } } if (playersDead) { npcAdolescentController.PerformTransition(Transition.PlayerDead); return; } if ((health && health.CurrentHealth <= 10) || GameManager.instance.AdolescentCount == 1) { npcAdolescentController.PerformTransition(Transition.InDanger); return; } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.ATTACK_DIST)) { adolescentAttack.Attacking = true; } else if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.CHASE_DIST)) { //if the player's distance is in range of the chase distance, stop firing and chase //the player adolescentAttack.Attacking = false; npcAdolescentController.PerformTransition(Transition.SawPlayer); } else { adolescentAttack.Attacking = false; npcAdolescentController.PerformTransition(Transition.LostPlayer); } }
//---------------------------------------------------------------------------------------------- // Reason() is used to determine the conditions to transition out of the idle state, // and what state to transition into public override void Reason() { Transform adolescentTransform = npcAdolescentController.transform; Vector3 closestplayer = npcAdolescentController.GetClosestPlayer(); if (health && health.IsDead()) { npcAdolescentController.PerformTransition(Transition.NoHealth); } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.FLEE_DIST)) { if ((health && health.CurrentHealth <= 10) || GameManager.instance.AdolescentCount == 1) { npcAdolescentController.PerformTransition(Transition.InDanger); return; } } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.CHASE_DIST)) { npcAdolescentController.PerformTransition(Transition.SawPlayer); return; } }
//---------------------------------------------------------------------------------------------- // Reason() is used to determine the conditions to transition out of the charge state, // and what state to transition into public override void Reason() { Transform adolescentTransform = npcAdolescentController.transform; Vector3 closestplayer = npcAdolescentController.GetClosestPlayer(); closestPlayerSlots = npcAdolescentController.GetPlayerSlotManager(npcAdolescentController.PlayerTarget); if (health && health.IsDead()) { //if the health script is present on the adolescent and its dead, transition to the dead state npcAdolescentController.PerformTransition(Transition.NoHealth); return; } bool playersDead = true; for (int i = 0; i < 2; i++) { if (playerHealths[i] && !playerHealths[i].IsDead()) { playersDead = false; break; } } if (playersDead) { npcAdolescentController.PerformTransition(Transition.PlayerDead); return; } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.FLEE_DIST)) { if ((health && health.CurrentHealth <= 10) || GameManager.instance.AdolescentCount == 1) { npcAdolescentController.PerformTransition(Transition.InDanger); return; } } // Keep track of the player slots and release and grab new one every so often... elapsedTime += Time.deltaTime; if (elapsedTime > intervalTime) { elapsedTime = 0.0f; closestPlayerSlots.ReleaseSlot(availSlotIndex); availSlotIndex = closestPlayerSlots.ReserveSlotAroundObject(npcAdolescentController.gameObject); if (availSlotIndex != -1) { destPos = closestPlayerSlots.GetSlotPosition(availSlotIndex); } else { destPos = closestplayer; } } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.CHASE_DIST)) { // want to check if we are close to our destination position and then transition to attack if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.SLOT_DIST)) { npcAdolescentController.PerformTransition(Transition.ReachPlayer); } } else { //lost player npcAdolescentController.PerformTransition(Transition.LostPlayer); } }