public void Reset() { myState = AIState.Idle; stuckPlayer = null; crate = null; chasePlayer = null; hasBombPlayer = null; myLSB = null; theirLSB = null; movementFrozen = false; lastNode = null; //bools for timers wasMovingRight = false; wasMovingLeft = false; justJumped = false; justThrew = false; //timers for firing events freezeTimer = new AITimer(45); throwTimer = new AITimer(40); jumpTimer = new AITimer(20); playerChaseTimer = new AITimer(60); confusedTimer = new AITimer(30); directionSwitchedCount = 0; }
void Idle() { crate = GameObject.FindObjectOfType <StickyCrate> (); if (crate == null) { //wait it hasnt spawned yet } else { //go get that crate! myState = AIState.CrateAvailable; } }
void GoToCrate() { crate = GameObject.FindObjectOfType <StickyCrate> (); if (crate == null) { if (GetComponent <PlayerController>().hasStickyBomb) { //i have the bomb, switch states myState = AIState.IHaveBomb; //find a target based off of distance away chasePlayer = FindClosestPlayer(); if (chasePlayer == null) { Debug.LogError("There is no player that is closest to this AI."); } } else { //well now we know someone else has the bomb. so lets switch states myState = AIState.SomeoneElseHasBomb; PlayerController hbp = PlayerController.GetPlayerWithBomb(); if (hbp.playerID != myPlayer.playerID) { hasBombPlayer = hbp; } } } else { //go get that crate! MoveTowards(crate.gameObject); } }
void Confused() { int maxFloor = AIP.MaxFloor(); if (confusedState == AIState.BombOnGround) { myLSB = GameObject.FindObjectOfType <LocalStickyBomb> (); if (myLSB == null) { if (myPlayer.hasStickyBomb) { //i have the bomb again, switch states myState = AIState.IHaveBomb; //find a target based off of distance away chasePlayer = FindClosestPlayer(); if (chasePlayer == null) { Debug.LogError("There is no player that is closest to this AI."); } } else { //either someone else picked it up, or it exploded. crate = GameObject.FindObjectOfType <StickyCrate> (); if (crate != null) { //it exploded because a new crate spawned. myState = AIState.CrateAvailable; } else { //no new crate - someone else picked it up myState = AIState.SomeoneElseHasBomb; PlayerController hbp = PlayerController.GetPlayerWithBomb(); if (hbp.playerID != myPlayer.playerID) { hasBombPlayer = hbp; } } } } else { AIP cM = AIP.FindClosestMaster(maxFloor, myLSB.transform.position); MoveTowards(cM.gameObject); //PopText.Create("Master", Color.gray, 50, cM.transform.position); if (Vector3.Distance(cM.transform.position, this.transform.position) < .5f) { //our work here is done. myState = AIState.BombOnGround; } } } else if (confusedState == AIState.IHaveBomb) { playerChaseTimer.Decrement(); if (playerChaseTimer.Count() == 0) { //ree-evaluate closest player chasePlayer = FindClosestPlayer(); playerChaseTimer.Reset(); } //go to the max floor and figure it out from there. if (chasePlayer != null) { AIP cM = AIP.FindClosestMaster(maxFloor, chasePlayer.transform.position); MoveTowards(cM.gameObject); //PopText.Create("Master", Color.red, 50, cM.transform.position); } } else if (confusedState == AIState.SomeoneElseHasBomb) { //go to the max floor and figure it out from there. if (hasBombPlayer != null) { AIP cM = AIP.FindClosestMaster(maxFloor, hasBombPlayer.transform.position); MoveTowards(cM.gameObject); } } else if (confusedState == AIState.CrateAvailable) { myState = AIState.Idle; } }
void GoToBomb() { myLSB = GameObject.FindObjectOfType <LocalStickyBomb> (); if (myLSB == null) { if (myPlayer.hasStickyBomb) { //i have the bomb again, switch states myState = AIState.IHaveBomb; //find a target based off of distance away chasePlayer = FindClosestPlayer(); if (chasePlayer == null) { Debug.LogError("There is no player that is closest to this AI."); } } else { //either someone else picked it up, or it exploded. crate = GameObject.FindObjectOfType <StickyCrate> (); if (crate != null) { //it exploded because a new crate spawned. myState = AIState.CrateAvailable; } else { //no new crate - someone else picked it up myState = AIState.SomeoneElseHasBomb; PlayerController hbp = PlayerController.GetPlayerWithBomb(); if (hbp.playerID != myPlayer.playerID) { hasBombPlayer = hbp; } } } } else { AIP pointNearBomb = AIP.PointNear(myLSB.transform.position); //PopText.Create("Bomb", Color.blue, 50, myLSB.transform.position); //PopText.Create("Point", Color.green, 50, pointNearBomb.transform.position); int floorGuess = 1; if (myLSB.transform.position.y - this.transform.position.y > 4) { floorGuess = 2; } if (pointNearBomb != null && lastNode != null && pointNearBomb.FLOOR > lastNode.FLOOR) { //move to master node of player floor MoveTowards(AIP.FindClosestMaster(pointNearBomb.FLOOR, myLSB.transform.position).gameObject); //PopText.Create("Master", Color.red, 50, AIP.FindClosestMaster(pointNearBomb.FLOOR, myLSB.transform.position).gameObject.transform.position); //PopText.Create("Moving to top floor.", Color.white, 120,this.transform.position); } else if (pointNearBomb != null && lastNode != null && floorGuess == 2) { MoveTowards(AIP.FindClosestMaster(2, myLSB.transform.position).gameObject); //PopText.Create("Master", Color.red, 50, AIP.FindClosestMaster(2, myLSB.transform.position).gameObject.transform.position); } else if (pointNearBomb != null && lastNode != null && pointNearBomb.FLOOR < lastNode.FLOOR) { //move to master node of player floor MoveTowards(AIP.FindClosestMaster(pointNearBomb.FLOOR, myLSB.transform.position).gameObject); //PopText.Create("Moving to bottom floor.", Color.white, 120,this.transform.position); //PopText.Create("Master", Color.red, 50, AIP.FindClosestMaster(pointNearBomb.FLOOR, myLSB.transform.position).gameObject.transform.position); } else { MoveTowards(myLSB.gameObject); } } }