public IEnumerator KillTroop(float waitTime) { if (Health <= 0 & this.troopState == TroopState.Alive) { Debug.Log(this.gameObject); yield return(new WaitForSeconds(waitTime)); troopState = TroopState.Dead; //set troop to dead if (this.gameObject.tag != "King") { Debug.Log("HI"); gameManager.KillPlayer(this.gameObject, this.team); //kill the player } else if (this.gameObject.tag == "King") { //end the game Debug.Log("hey"); anim.win(); yield return(new WaitForSeconds(4f)); UI.EndGameScreen(this.gameObject); } } }
protected void Start() { myAnimator = GetComponentInChildren <Animator>(); troopState = TroopState.INIT; VelocityEnhance(FindVelocityTower()); //Mira si existeix torre de velocitat, i aplica la millora team = tag; troopObjective = DetectClosestEnemy(); currNode = findClosestNode(); pathRequest = new GraphPathfinder(); StartCoroutine(Attack()); }
public void ChangeState(TroopState state) { if (troopState != null) { previousTroopState = troopState; troopState.Exit(); } troopState = state; troopState.Enter(); }
/// <summary> /// Handler when an event switches state. This is how we know to remove a stub from the assignment once it joins the battle. /// </summary> /// <param name="stub"></param> /// <param name="newState"></param> private void StubOnStateSwitched(ITroopStub stub, TroopState newState) { lock (assignmentLock) { switch (newState) { case TroopState.Battle: RemoveStub(stub); break; } } }
public Vector2 gNextStep(Vector2 _currentCoordinates) //if step is made return true, else return false { nextStep = gameField.getNextStep(gameField.getNodeByCoordinates(_currentCoordinates)); if (nextStep == null) { mState = TroopState.STAND; return(_currentCoordinates); } else { mState = TroopState.MOVE; return(nextStep.getNodeCoordinates()); } }
public void checkState() { Vector2 nextStep = gNextStep(pos); switch (mState) { case TroopState.STAND: gNextStep(pos); mState = TroopState.MOVE; break; case TroopState.MOVE: makeNextStep(nextStep); break; } }
public virtual bool TroopStubCreate(out ITroopStub troopStub, ICity city, ISimpleStub stub, TroopState initialState = TroopState.Idle) { if (!city.DefaultTroop.RemoveFromFormation(FormationType.Normal, stub)) { troopStub = null; return(false); } troopStub = city.CreateTroopStub(); troopStub.BeginUpdate(); troopStub.Add(stub); troopStub.State = initialState; troopStub.EndUpdate(); return(true); }
//刷新训练队列 public void RefreshTrolls(object obj = null) { InitSLots(); int num = meditor.GetCurTroopCount(); for (int i = 0; i < num; i++) { TroopState state = meditor.GetTroopState(i); int queueIndex = meditor.GetTroopQueueIndex(i); troopSprites[queueIndex].spriteName = meditor.GetTroopIcon(i); Transform trans = buildSlot [queueIndex].transform; trans.FindChild("Img_None").gameObject.SetActive(false); trans.FindChild("Btn_Delete").gameObject.SetActive(true); trans.FindChild("Img_Soldier").gameObject.SetActive(true); Transform timeTrans = trans.FindChild("Time_Pro"); Transform labTime = timeTrans.FindChild("Lab_Time"); Transform progressbar = timeTrans.FindChild("ProgressBar"); //训练队列中 正在训练中 训练满 if (state == TroopState.NeedTrain) { // timeTrans.gameObject.SetActive (true); // labTime.gameObject.SetActive (false); // progressbar.gameObject.SetActive (false); //临时处理 timeTrans.gameObject.SetActive(false); labTime.gameObject.SetActive(false); progressbar.gameObject.SetActive(false); Transform labDone = trans.FindChild("Lab_Done"); labDone.gameObject.SetActive(true); labDone.GetComponent <UILabel> ().text = "等待训练"; buildTimes [i].state = TroopState.NeedTrain; } else if (state == TroopState.Training) { // timeTrans.gameObject.SetActive (true); // labTime.gameObject.SetActive (true); // progressbar.gameObject.SetActive (true); // UILabel timeLabel = labTime.GetComponent<UILabel> (); // UIProgressBar progress = timeTrans.FindChild ("ProgressBar").GetComponent<UIProgressBar>(); // var trainData = meditor.GetCurTrainData (meditor.curBuildingGuid, queueIndex); // buildTimes [i].endTime = trainData.endTime; //临时处理 timeTrans.gameObject.SetActive(false); labTime.gameObject.SetActive(false); progressbar.gameObject.SetActive(false); Transform labDone = trans.FindChild("Lab_Done"); labDone.gameObject.SetActive(true); labDone.GetComponent <UILabel> ().text = "训练中"; buildTimes [i].state = TroopState.Training; } else if (state == TroopState.TrainFull) { timeTrans.gameObject.SetActive(false); labTime.gameObject.SetActive(false); progressbar.gameObject.SetActive(false); Transform labDone = trans.FindChild("Lab_Done"); labDone.gameObject.SetActive(true); labDone.GetComponent <UILabel> ().text = "训练完成"; buildTimes [i].state = TroopState.TrainFull; } } }
public TroopStateController(TroopOnField troop) { //Declare all states and put them in List<TroopState> Standby s = new Standby(); March m = new March(); //Declare all possible transitions T_S_M t_s_m = new T_S_M(s, m); T_M_S t_m_s = new T_M_S(m, s); //Create transition list for each state List<Transition> transition_s = new List<Transition>(); transition_s.Add(t_s_m); List<Transition> transition_m = new List<Transition>(); transition_m.Add(t_m_s); //Put relevant transitions in each of the state s.initialize(troop, transition_s); m.initialize(troop, transition_m); //Set up the first state activeState = s; }
public Troop(Field _field) { gameField = _field; mState = TroopState.STAND; pos = transform.position; }
void Update() { troopObjective = DetectClosestEnemy(); switch (troopState) { case TroopState.INIT: if (pathRequest.findPath(currNode, towerToMove) && !StillInRange(troopObjective)) { troopState = TroopState.MOVING; myAnimator.SetBool("Running", true); myAnimator.SetBool("Attack", false); } else if (troopObjective != null) { if (StillInRange(troopObjective)) { troopState = TroopState.ATTACKING; myAnimator.SetBool("Running", false); myAnimator.SetBool("Attack", true); //StartCoroutine(Attack()); } } break; case TroopState.MOVING: if (!AmIAlive()) { isMoving = false; troopState = TroopState.DYING; } else if (StillInRange(troopObjective)) { isMoving = false; troopState = TroopState.ATTACKING; myAnimator.SetBool("Attack", true); myAnimator.SetBool("Running", false); targetIndex = 0; //StartCoroutine(Attack()); } else { isMoving = true; if (tag == "AllyTroop" && towerToMove.tag == "AllyTower") { pathRequest.findPath(currNode, towerToMove); DetectClosestTower(); } pathRequest.findPath(currNode, towerToMove); FollowPath(); } break; case TroopState.ATTACKING: if (!AmIAlive()) { isAttacking = false; //StopCoroutine(Attack()); troopState = TroopState.DYING; } else if (!StillInRange(troopObjective) && pathRequest.findPath(currNode, towerToMove)) { //StopCoroutine(Attack()); isAttacking = false; myAnimator.SetBool("Running", true); myAnimator.SetBool("Attack", false); troopState = TroopState.MOVING; } break; case TroopState.DYING: StopAllCoroutines(); if (this.tag == "EnemyTroop") { GameObject.Find("AllyEconomy").GetComponent <PlayerController>().SumMoney(stats.dropedCoins); } else { GameObject.Find("EnemyEconomy").GetComponent <PlayerController>().SumMoney(stats.dropedCoins); } Destroy(this.gameObject); break; } currNode = findClosestNode(); }
public void Update() { bool validTransition = false; foreach(Transition t in activeState.transitions) { if (t.isValid()) { Debug.Log("changing state"); activeState.onExit(); activeState = t.nextState; activeState.onEnter(); validTransition = true; break; } } if (!validTransition) activeState.Update(); }
public T_S_M(TroopState f, TroopState t) : base(f,t) { }
public T_M_S(TroopState f, TroopState t) : base(f, t) { }
//public abstract void onTransition(); public Transition(TroopState from, TroopState next) { fromState = from; nextState = next; }
// Update is called once per frame public void Update() { if (this.gameObject.tag == "King" && setKing == false) { troopState = TroopState.Alive; setKing = true; } Anim.SetFloat("Health", this.Health); Curx = gameObject.transform.position.x; Cury = gameObject.transform.position.z; TroopRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(TroopRay, out TroopHit, 100)) { if (TroopHit.transform.gameObject == this.gameObject) { sprite.SetActive(true); } else { sprite.SetActive(false); } } switch (gameManager.state) { case (State.TroopPlacement): //if troop placement state //if troop is in blue team if (this.team == Team.Blue) { //if the troop hasn't been placed on board if (gameManager.turn == Turn.Blue && this.troopState == TroopState.NotPlaced) { canDrag = true; //allow player to move } else { canDrag = false; //player cant move } } //if troop is in red team if (this.team == Team.Red) { //if the troop hasn't been placed on board if (gameManager.turn == Turn.Red && this.troopState == TroopState.NotPlaced) { canDrag = true; //allow player to move } else { canDrag = false; //player cant move } } break; case (State.Gameplay): //if gameplay state if (troopState == TroopState.Alive) { //if troop is in blue team if (this.team == Team.Blue) { if (this.troopState == TroopState.Alive) { var check = gameManager.SearchList(gameManager.deadBlueTeam, this.tag.ToString()); if (check != null) { gameManager.deadBlueTeam.Remove(this.gameObject); } } //if blue teams turn if (gameManager.turn == Turn.Blue) { if (gameManager.BlueCurPiece != null) { if (this.tag == "King") { canDrag = true; } //if this troops turn to move else if (this.tag == gameManager.BlueCurPiece.tag) { canDrag = true; //allow player to move } else { canDrag = false; //player cant move } } } //if not blue teams turn else { canDrag = false; //player cant move } } //if troop is in red team else if (this.team == Team.Red) { if (this.troopState == TroopState.Alive) { var check = gameManager.SearchList(gameManager.deadRedTeam, this.tag.ToString()); if (check != null) { gameManager.deadRedTeam.Remove(this.gameObject); } } //if red teams turn if (gameManager.turn == Turn.Red) { if (gameManager.RedCurPiece != null) { //if this troops turn to move if (this.tag == gameManager.RedCurPiece.tag) { canDrag = true; //allow player to move } else { canDrag = false; //player cant move } } } //if not red teams turn else { canDrag = false; //player cant move } } } break; default: break; } }
private void StationTroopInStronghold(ITroopObject troopObject, IStronghold stronghold, TroopState stubState = TroopState.Stationed) { procedure.TroopObjectStation(troopObject, stronghold); if (troopObject.Stub.State != stubState) { troopObject.Stub.BeginUpdate(); troopObject.Stub.State = stubState; troopObject.Stub.EndUpdate(); } StateChange(ActionState.Completed); }
public void ChangeToPreviousState() { troopState = previousTroopState; troopState.Enter(); }