public override bool perform(GameObject agent) { ZombieAgent za = agent.GetComponent <ZombieAgent>(); if (za.PlayerNear || za.nearbyEntities.Find(c => c ? c.gameObject.GetComponent <BasicZombie>() : null) == null) { Destroy(target.gameObject); return(false); } target.transform.position = targetZombie.gameObject.transform.position + (targetZombie.transform.position - targetPlayer.position).normalized * (za.attackRange / 4); za.moveAgent(this); if (Time.time - lastAttack > za.timeBetweenAttacks) { lastAttack = Time.time; agent.GetComponent <Animator>().SetBool("isAttacking", true); za.nearbyEntities.ForEach(c => { if (c && c.GetComponent <BasicZombie>()) { c.GetComponent <ZombieAgent>().Boost(); } }); } else { agent.GetComponent <Animator>().SetBool("isAttacking", false); } return(true); }
public override bool checkProceduralPrecondition(GameObject agent) { ZombieAgent za = agent.GetComponent <ZombieAgent>(); Transform nearestPlayer = null; float nearestPlayerDistance = 0; foreach (PlayerController2 pc in GameObject.FindObjectsOfType <PlayerController2>()) { if (nearestPlayer == null) { nearestPlayer = pc.transform; nearestPlayerDistance = (nearestPlayer.position - za.transform.position).magnitude; } else if ((pc.transform.position - za.transform.position).magnitude < nearestPlayerDistance) { nearestPlayer = pc.transform; nearestPlayerDistance = (pc.transform.position - za.transform.position).magnitude; } } if (target != null) { Destroy(target.gameObject); } targetPlayer = nearestPlayer; target = new GameObject("Necro target"); target.transform.position = za.transform.position + (za.transform.position - nearestPlayer.position).normalized * 2; cost = 1; return(true); }
// Realise the action. public override bool perform(GameObject agent) { ZombieAgent zombieAgent = GetComponent <ZombieAgent>(); if ((target.transform.position - agent.transform.position).magnitude > zombieAgent.attackRange) { return(false); } // If the last attack was realised more than timeBetweenAttacks secs ago. if (Time.time - lastAttack > zombieAgent.timeBetweenAttacks) { // Do a new attack. targetPlayerHealth.TakeDamage(zombieAgent.Damages); agent.GetComponent <Animator>().SetBool("isAttacking", true); lastAttack = Time.time; if (targetPlayerHealth.currentHealth <= 0) { playerIsDead = true; } } else if (Time.time - lastAttack > 0.5f) { agent.GetComponent <Animator>().SetBool("isAttacking", false); } return(true); }
private void OnSceneGUI() { ZombieAgent za = (ZombieAgent)target; if (za) { drawRanges(za); } }
public override void reset() { if (target != null) { Destroy(target.gameObject); } targetZombie = null; targetPlayer = null; lastAttack = 0; }
private void drawRanges(ZombieAgent agent) { Handles.color = Color.blue; Handles.DrawWireArc(agent.transform.position, Vector3.up, agent.transform.position + Vector3.right, 360, agent.hiddenByTankRange); Handles.color = Color.red; Handles.DrawWireArc(agent.transform.position, Vector3.up, agent.transform.position + Vector3.right, 360, agent.attackRange); Handles.color = new Color(1, 0.2f, 0.2f); Handles.DrawWireArc(agent.transform.position, Vector3.up, agent.transform.position + Vector3.right, 360, agent.closeAttackRange); Handles.color = Color.yellow; Handles.DrawWireArc(agent.transform.position, Vector3.up, agent.transform.position + Vector3.right, 360, agent.nearbyTankArea); Handles.color = Color.cyan; Handles.DrawWireArc(agent.transform.position, Vector3.up, agent.transform.position + Vector3.right, 360, agent.nearbyPlayerArea); }
public override bool checkProceduralPrecondition(GameObject agent) { ZombieAgent za = agent.GetComponent <ZombieAgent>(); if (za.PlayerNear) { return(false); } Collider col = za.nearbyEntities.Find(c => c ? c.gameObject.GetComponent <BasicZombie>() : null); if (col == null) { return(false); } targetZombie = col.GetComponent <ZombieAgent>(); Transform nearestPlayer = null; float nearestPlayerDistance = 0; foreach (PlayerController2 pc in GameObject.FindObjectsOfType <PlayerController2>()) { if (nearestPlayer == null) { nearestPlayer = pc.transform; nearestPlayerDistance = (nearestPlayer.position - za.transform.position).magnitude; } else if ((pc.transform.position - za.transform.position).magnitude < nearestPlayerDistance) { nearestPlayer = pc.transform; nearestPlayerDistance = (pc.transform.position - za.transform.position).magnitude; } } if (target != null) { Destroy(target.gameObject); } targetPlayer = nearestPlayer; target = new GameObject("Necro target"); target.transform.position = targetZombie.gameObject.transform.position + (targetZombie.transform.position - nearestPlayer.position).normalized * (za.attackRange / 4); cost = 1; return(true); }
public override bool perform(GameObject agent) { ZombieAgent za = agent.GetComponent <ZombieAgent>(); if (!za.PlayerNear) { if (target) { Destroy(target.gameObject); } return(false); } target.transform.position = za.transform.position + (za.transform.position - targetPlayer.position).normalized * 2; za.moveAgent(this); return(true); }
// Realise the action. public override bool perform(GameObject agent) { ZombieAgent zombieAgent = GetComponent <ZombieAgent>(); zombieAgent.moveAgent(this); // if tank dead abort the plan if (target.GetComponentInParent <Com.MyCompany.MyGame.EnemyHealth>().IsDead) { return(false); } // If we are near the payload or if the tank is near the player, go to next action (isDone true) if ((payload != null && (agent.transform.position - payload.transform.position).magnitude <= agentToPayloadShiftRange) || ((target.transform.position - target.GetComponentInParent <ZombieAgent>().LastTarget.position).magnitude <= tankToPlayerShiftRange)) { IsHidden = true; } return(true); }
public void OnGUI() { if (Selection.activeGameObject != null) { ZombieAgent zombieAgent = Selection.activeGameObject.GetComponent <ZombieAgent>(); if (zombieAgent) { GUILayout.Label("Current position: (" + zombieAgent.transform.position.x + ", " + zombieAgent.transform.position.y + ", " + zombieAgent.transform.position.z + ")."); GUILayout.Label("Is currently buffed: " + zombieAgent.IsBuffed); Dictionary <string, object> worldState = zombieAgent.getWorldState(); GUILayout.Label("Current World state:"); foreach (KeyValuePair <string, object> state in worldState) { GUILayout.Label("\t- " + state.Key + ": " + state.Value.ToString()); } } } }