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 IThrewBomb() { //i just threw the bomb. wait until it either hits someone or hits the ground before deciding what to do. if (myLSB != null) { if (myLSB.GetComponent <StickyBomb>().ownerID == myPlayer.playerID) { //its ur bomb //check to see if it landed on the ground or stuck someone if (myLSB.GetComponent <StickyBomb>().hitGround) { //it hit the ground myState = AIState.BombOnGround; //PopText.Create("MY BOMB ON GROUND", Color.white, 120,this.transform.position); } else if (myLSB.GetComponent <StickyBomb>().stuckID > 0) { myState = AIState.SomeoneElseStuck; stuckPlayer = PlayerController.GetByPlayerID(myLSB.GetComponent <StickyBomb>().stuckID); //PopText.Create("SOMEONE ELSE STUCK", Color.white, 120,this.transform.position); } } else { //its not ur bomb. see if ur bomb even ecists LocalStickyBomb[] allbombs = GameObject.FindObjectsOfType <LocalStickyBomb> (); bool myBombExists = false; foreach (var b in allbombs) { if (b.GetComponent <StickyBomb>().ownerID == myPlayer.playerID) { //we are good myBombExists = true; myLSB = b; } } if (!myBombExists) { //what happened to my bomb?? } } } else { myLSB = GameObject.FindObjectOfType <LocalStickyBomb> (); if (myLSB == null) { //what happened to my bomb?? } } }
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); } } }
void AvoidBombMidAir() { //someone just threw the bomb. wait until it either hits someone or hits the ground before deciding what to do. if (theirLSB != null) { if (theirLSB.GetComponent <StickyBomb>().ownerID == hasBombPlayer.playerID) { //its their bomb //check to see if it landed on the ground or stuck someone if (theirLSB.GetComponent <StickyBomb>().hitGround) { //it hit the ground myState = AIState.BombOnGround; //PopText.Create("MY BOMB ON GROUND", Color.white, 120,this.transform.position); } else if (theirLSB.GetComponent <StickyBomb>().stuckID > 0) { if (theirLSB.GetComponent <StickyBomb>().stuckID != myPlayer.playerID) { myState = AIState.SomeoneElseStuck; stuckPlayer = PlayerController.GetByPlayerID(theirLSB.GetComponent <StickyBomb>().stuckID); //PopText.Create("SOMEONE ELSE STUCK", Color.white, 120,this.transform.position); } } else if (Vector3.Distance(theirLSB.transform.position, this.transform.position) < 2.5f) //if its getting close to us { //try and jump away if (myPlayer.IsGrounded() && !justJumped) { myPlayer.COMMAND_Jump(); justJumped = true; } } } else { //its not their bomb. see if their bomb even ecists LocalStickyBomb[] allbombs = GameObject.FindObjectsOfType <LocalStickyBomb> (); bool theirBombExists = false; foreach (var b in allbombs) { if (b.GetComponent <StickyBomb>().ownerID == hasBombPlayer.playerID) { //we are good theirBombExists = true; theirLSB = b; } } if (!theirBombExists) { //what happened to my bomb?? } } } else { theirLSB = GameObject.FindObjectOfType <LocalStickyBomb> (); if (theirLSB == null) { //what happened to my bomb?? } } }
public bool ShouldISprint() { float juice = myPlayer.SprintRatio(); int stickyTime = 10; bool grounded = false; if (GameObject.FindObjectOfType <LocalStickyBomb>() != null) { LocalStickyBomb sb = GameObject.FindObjectOfType <LocalStickyBomb>(); stickyTime = sb.GetTimerInSeconds(false); grounded = sb.GetComponent <StickyBomb>().hitGround; } if (stickyTime <= 2) { return(true); } else if (stickyTime <= 4) { if (myState == AIState.IAmStuck || myState == AIState.SomeoneElseStuck) { return(true); } else { if (juice > .5f) { return(true); } else { return(false); } } } else if (stickyTime <= 7) { if (myState == AIState.IAmStuck || myState == AIState.SomeoneElseStuck) { if (juice > .8f) { return(true); } return(false); } return(false); } if (grounded) { if (juice > .5f) { return(true); } else { return(false); } } if (stickyTime == 10) { if (myState == AIState.IHaveBomb || myState == AIState.SomeoneElseHasBomb || myState == AIState.SomeoneElseThrewBomb) { if (juice > .7f) { return(true); } } } return(false); }