public void exitState() { // change to check for health and ammo. enemy = null; enemySighted = false; if (Health < 50) { activeState.enabled = false; cs.enabled = true; activeState = cs; return; } else if (AmmoAmount <= 0) { activeState.enabled = false; ams.enabled = true; activeState = ams; return; } else { activeState.enabled = false; rs.enabled = true; activeState = rs; } }
public virtual void stateSwitcher() { if (Health <= 50 && Health > 0) // Collect Health State { activeState.enabled = false; activeState = csCollectHealth; activeState.enabled = true; } else if (Ammo <= 0) // Collect Ammo State { activeState.enabled = false; activeState = caCollectAmmo; activeState.enabled = true; } else if (EnemyInRange) // Shoot State. { activeState.enabled = false; activeState = sShootState; activeState.enabled = true; } else if (Health > 50 || Ammo > 0 || !EnemyInRange) // Roam State. { activeState.enabled = false; activeState = rStateRoam; activeState.enabled = true; } if (Health <= 0) // Death. { this.gameObject.SetActive(false); GameManager2.Instance.UpdateDeaths(this.gameObject); Sender.SendMessage("IncreaseKillCount"); } }
private void stateSwitcher() { if (Health <= 50 && Health > 0) { activeState.enabled = false; activeState = csCollectHealth; activeState.enabled = true; } else if (Ammo <= 0) { // Set Collect Ammo Active. activeState.enabled = false; activeState = rStateRoam; activeState.enabled = true; } else if (EnemyInRange) { activeState.enabled = false; activeState = sShootState; activeState.enabled = true; } else if (Health > 50 || Ammo > 0 || !EnemyInRange) { activeState.enabled = false; activeState = rStateRoam; activeState.enabled = true; } else if (Health < 0) { } }
public bool onWall = false; //是否在墙上 private void Start() { playerRigidbody = GetComponent <Rigidbody2D>(); normalGravity = playerRigidbody.gravityScale; playerRigidbody.velocity = Vector2.zero; state = new MoveState(this); }
/// <summary> /// Callback from WPF to tell us that one of the dependency properties has been changed. /// For the dependency properties that are registered here, this method updates the Elipse from the current values of the known dp objects /// </summary> protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { if (e.Property == PartBaseStateProperty) { lastPartBaseState = (IBaseState)e.NewValue; } else if (e.Property == ActionInfoProperty) { lastActionInfo = (IActionInfo)e.NewValue; } else if (e.Property == HighlightColorProperty) { lastHighlightColor = (Color)e.NewValue; } else if (e.Property == IncludeConnectionStateProperty) { lastIncludeConnectionState = (bool)e.NewValue; } else if (e.Property == BorderBrushProperty) { lastBorderBrush = (Brush)e.NewValue; } Update(); base.OnPropertyChanged(e); }
void Awake() { rStateRoam = gameObject.GetComponent <Roam>(); sShootState = gameObject.GetComponent <Shoot>(); csCollectHealth = gameObject.GetComponent <CollectHealth>(); activeState = rStateRoam; activeState.enabled = true; }
public static void ChangeGameState(GameStates state) { if (currentState == null) { currentState = new GameState(); } currentState.Enter(state); }
// Use this for initialization void Start() { // Set intitial state. activeState = rs; // Set random colour MeshRenderer mySkin = this.transform.GetComponent <MeshRenderer>(); mySkin.material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)); }
/// <summary> /// A call to transition to the nextState passed in. /// </summary> /// <param name="nextState"> the desired state to transition to. </param> public void TransitionToState(StateTypes nextState) { IBaseState battleState = GetNextState(nextState); currentState.OnExit(); currentState = battleState; currentState.OnEnter(); }
void Awake() { // state references. rsState = GetComponent <RoamState>(); chState = GetComponent <CollectHealthState>(); sState = GetComponent <ShootState>(); caState = GetComponent <CollectAmmoState>(); // initialize states. rsState.enabled = true; activeState = rsState; }
/// <summary> /// Validates the transition from the current state to the nextBattleState passed in. /// </summary> /// <param name="nextBattleState"> The desired next battle state. </param> /// <returns> Returns the next state or null depending on the validity of the state transition requested. </returns> private IBaseState ValidateStateTransition(StateTypes nextBattleState) { IBaseState nextState = null; StateTransition transition = new StateTransition(currentState.StateType, nextBattleState); if (!transitions.TryGetValue(transition, out nextState)) { UnityEngine.Debug.LogError("Invalid Transition"); } return(nextState); }
public void StartState(Type stateType) { IBaseState state = GetState(stateType); if (state == null) { throw new Exception($"can not state '{stateType.FullName}' which is not exist."); } _currentState = state; _currentStateTime = 0; _currentState.OnEnter(); }
void Awake() { // state references. rs = GetComponent <RoamState>(); cs = GetComponent <CollectHealthState>(); ss = GetComponent <ShootState>(); ams = GetComponent <CollectAmmoState>(); // initialize states. rs.enabled = true; cs.enabled = false; activeState = rs; }
// Update is called once per frame void Update() { // needs sorting out // need to see if roam state and then get closest enemy. // Run state specific code if (activeState != null) { activeState.StateUpdate(); } // try changeing this to a list in a game manger class that keeps track of bots // bots can notify game manager of death. // need a way for each bot to register a kill. // maybe by accessing the health variable of the hit collider in shoot. foreach (GameObject go in GameManager.Instance.botsList) { if (go != null && AmmoAmount > 0) { // Check distance to enemy. if (Vector3.Distance(transform.position, go.transform.position) < 50.0f) { // Check angle to enemy. //Debug.DrawLine(transform.position, go.transform.position, Color.red, 0.5f); Vector3 targetDir = go.transform.position - transform.position; Vector3 forward = transform.forward; float angle = Vector3.Angle(targetDir, forward); if (angle < 20.0F) { //Debug.Log("Enemy Sighted " + this.name); enemySighted = true; enemy = go.transform; activeState.enabled = false; ss.enabled = true; activeState = ss; } } } } if (enemy != null) { if (enemy.gameObject.activeSelf == false) { enemySighted = false; activeState.enabled = false; rs.enabled = true; activeState = rs; } } }
public IBaseState GetState(Type stateType) { if (stateType == null) { throw new Exception("State type is invalid."); } IBaseState state = null; if (m_States.TryGetValue(stateType, out state)) { return(state); } return(null); }
/// <summary> /// Provides overriden implementation for Main Loop Service method. Reflects associated IPort ConnState changes into this object. /// Services the underlying port read and port write actions to implement the basic functionality of this object. /// </summary> protected override void PerformMainLoopService() { System.Threading.Thread.Sleep(1); IBaseState portBaseState = portBaseStateObserver.Object; if (portBaseStateObserver.IsUpdateNeeded) { portBaseStateObserver.Update(); IBaseState updatedBaseState = portBaseStateObserver.Object; if (updatedBaseState.ConnState != BaseState.ConnState) { SetBaseState(updatedBaseState.ConnState, "Port ConnState changed", true); } portBaseState = updatedBaseState; } if (portBaseState.IsConnected) { if (portRdAction.ActionState.IsComplete && portRdActionParam.ActionResultEnum != ActionResultEnum.None) { if (portRdActionParam.BytesRead > 0 && portWrAction.ActionState.CanStart) { portRdActionParam.ActionResultEnum = ActionResultEnum.None; portWrActionParam.BytesToWrite = portRdActionParam.BytesRead; portWrAction.Start(); } } else if (portWrAction.ActionState.IsComplete && portWrActionParam.ActionResultEnum != ActionResultEnum.None) { portWrActionParam.ActionResultEnum = ActionResultEnum.None; portRdAction.Start(); } else if (portRdAction.ActionState.CanStart && portWrAction.ActionState.CanStart) { portWrActionParam.Reset(); portRdAction.Start(); } } }
public void ChangeState(Type stateType) { if (stateType == _currentState.GetType()) { Debug.Log($"state '{stateType.FullName}' is running."); return; } IBaseState state = GetState(stateType); if (state == null) { throw new Exception($"can not state '{stateType.FullName}' which is not exist."); } _currentState.OnLeave(); _currentState = state; _currentStateTime = 0; _currentState.OnEnter(); }
// State Switcher private void stateSwitcher() { float result = 0; //result = fLogic.getValues(Health, Ammo, Range); Debug.Log(result); if (result <= -2) { activeState.enabled = false; chState.enabled = true; activeState = chState; Debug.Log(this.name + result); } else if (result < 0 && result > -2) { activeState.enabled = false; caState.enabled = true; activeState = caState; Debug.Log(this.name + result); } else if (result > 0 && result < 1) { activeState.enabled = false; rsState.enabled = true; activeState = rsState; Debug.Log(this.name + result); } else if (result >= 1) { activeState.enabled = false; sState.enabled = true; activeState = sState; Debug.Log(this.name + result); } }
public IBaseState PlaystyleStatic() { Debug.Log("PlaystyleStatic"); if (Mathf.Abs(m_PlayerController.collider.bounds.center.x - m_EnemyController.collider.bounds.center.x) > m_DistanceToPlayer) { m_NextState = new AIBattlePursue(m_Character); } else { m_NextState = GetActionFromString(m_EnemyController.attackSequence[m_EnemyController.attackSequenceIndex]); if (m_EnemyController.attackSequence.Length - 1 > m_EnemyController.attackSequenceIndex) { m_EnemyController.attackSequenceIndex++; } else { m_EnemyController.attackSequenceIndex = 0; } } return(m_NextState); }
public IBaseState PlaystyleStatic() { Debug.Log("PlaystyleStatic"); if (Mathf.Abs(m_PlayerController.collider.bounds.center.x - m_EnemyController.collider.bounds.center.x) > m_DistanceToPlayer) { m_NextState = new AIBattlePursue(m_Character); } else { m_NextState = GetActionFromString(m_EnemyController.attackSequence[m_EnemyController.attackSequenceIndex]); if (m_EnemyController.attackSequence.Length-1 > m_EnemyController.attackSequenceIndex) m_EnemyController.attackSequenceIndex++; else m_EnemyController.attackSequenceIndex = 0; } return m_NextState; }
public IBaseState PlaystyleDynamic() { Debug.Log("PlaystyleDynamic"); if (Mathf.Abs(m_PlayerController.collider.bounds.center.x - m_EnemyController.collider.bounds.center.x) > m_DistanceToPlayer) { m_NextState = new AIBattlePursue(m_Character); } else { m_PredictionTimer = 0.0f; string predictedAction = string.Empty; predictedAction = m_EnemyController.nGramPredictor.GetMostLikely(m_PlayerController.predictionSequence); Debug.Log("Prediction: " + predictedAction); if (predictedAction != string.Empty) { if (predictedAction == "AIBattleHeavyAttackUp") { m_NextState = new AIBattleBlockUp(m_Character); } else if (predictedAction == "AIBattleHeavyAttackDown") { m_NextState = new AIBattleBlockDown(m_Character); } else if (predictedAction == "AIBattleLightAttackUp") { m_NextState = new AIBattleBlockUp(m_Character); } else if (predictedAction == "AIBattleLightAttackDown") { m_NextState = new AIBattleBlockDown(m_Character); } else if (predictedAction == "AIBattleParryUp") { m_NextState = new AIBattleLightAttackDown(m_Character); } else if (predictedAction == "AIBattleParryDown") { m_NextState = new AIBattleLightAttackUp(m_Character); } else if (predictedAction == "AIBattleBlockUp") { m_NextState = new AIBattleHeavyAttackDown(m_Character); } else if (predictedAction == "AIBattleBlockDown") { m_NextState = new AIBattleHeavyAttackUp(m_Character); } } else { m_NextState = new AIBattleLightAttackDown(m_Character); } } return m_NextState; }
/// <summary> /// 尝试获取BuffState对象 /// </summary> /// <param name="iBaseState">接口对象</param> /// <param name="fieldName">字段名</param> /// <param name="buffState">要返回的对象</param> /// <returns>是否取到了BuffState对象</returns> private bool TryGetBuff(IBaseState iBaseState, string fieldName, out BuffState buffState) { if (!GetBuffStateByNameDic.ContainsKey(fieldName)) { if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Chaofeng)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Chaofeng); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Hunluan)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Hunluan); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Jiangzhi)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Jiangzhi); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Kongju)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Kongju); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Meihuo)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Meihuo); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Xuanyun)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Xuanyun); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Zhimang)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Zhimang); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Jingu)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Jingu); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Jinmo)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Jinmo); } else if (fieldName == GameState.Instance.GetFieldName <ISpecialState, BuffState>(temp => temp.Mabi)) { GetBuffStateByNameDic.Add(fieldName, temp => ((ISpecialState)temp).Mabi); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.Huoli)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).Huoli); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.Jiasu)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).Jiasu); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.Jinghua)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).Jinghua); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.Minjie)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).Minjie); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.Qiangli)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).Qiangli); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.Qusan)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).Qusan); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.Ruizhi)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).Ruizhi); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.XixueWuli)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).XixueWuli); } else if (fieldName == GameState.Instance.GetFieldName <IBuffState, BuffState>(temp => temp.XixueMofa)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IBuffState)temp).XixueMofa); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Bingdong)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Bingdong); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Chidun)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Chidun); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Dianran)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Dianran); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Diaoling)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Diaoling); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Jiansu)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Jiansu); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Mihuo)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Mihuo); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Wuli)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Wuli); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Xuruo)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Xuruo); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Zhongdu)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Zhongdu); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.Zuzhou)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).Zuzhou); } else if (fieldName == GameState.Instance.GetFieldName <IDebuffState, BuffState>(temp => temp.LiuXue)) { GetBuffStateByNameDic.Add(fieldName, temp => ((IDebuffState)temp).LiuXue); } } if (GetBuffStateByNameDic.ContainsKey(fieldName)) { buffState = GetBuffStateByNameDic[fieldName](iBaseState); return(true); } buffState = default(BuffState); return(false); }
public Context() { _state = null; }
/// <summary> /// Default Constructor /// </summary> /// <param name="startingState"> The starting state of the state machine. </param> public StateMachine(IBaseState startingState) { currentState = startingState; InitializeTransitions(); }
public void SetState(IBaseState state) { _state = state; }
public IBaseState PlaystyleDynamic() { Debug.Log("PlaystyleDynamic"); if (Mathf.Abs(m_PlayerController.collider.bounds.center.x - m_EnemyController.collider.bounds.center.x) > m_DistanceToPlayer) { m_NextState = new AIBattlePursue(m_Character); } else { m_PredictionTimer = 0.0f; string predictedAction = string.Empty; predictedAction = m_EnemyController.nGramPredictor.GetMostLikely(m_PlayerController.predictionSequence); Debug.Log("Prediction: " + predictedAction); if (predictedAction != string.Empty) { if (predictedAction == "AIBattleHeavyAttackUp") { m_NextState = new AIBattleBlockUp(m_Character); } else if (predictedAction == "AIBattleHeavyAttackDown") { m_NextState = new AIBattleBlockDown(m_Character); } else if (predictedAction == "AIBattleLightAttackUp") { m_NextState = new AIBattleBlockUp(m_Character); } else if (predictedAction == "AIBattleLightAttackDown") { m_NextState = new AIBattleBlockDown(m_Character); } else if (predictedAction == "AIBattleParryUp") { m_NextState = new AIBattleLightAttackDown(m_Character); } else if (predictedAction == "AIBattleParryDown") { m_NextState = new AIBattleLightAttackUp(m_Character); } else if (predictedAction == "AIBattleBlockUp") { m_NextState = new AIBattleHeavyAttackDown(m_Character); } else if (predictedAction == "AIBattleBlockDown") { m_NextState = new AIBattleHeavyAttackUp(m_Character); } } else { m_NextState = new AIBattleLightAttackDown(m_Character); } } return(m_NextState); }
public void SetState(States newState) { currentState = currentState.SetState(newState); }
public WorkItem() { currentState = new Open(); }
public void SetPlayerState(IBaseState newState) { state.Finish(); state = newState; state.Enter(); }
// Start is called before the first frame update private void Start() { IActiveState = new StartState(this); }
public void SwitchState(IBaseState nextState) { IActiveState = nextState; }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var behavior = (parameter != null) ? ((parameter is PartBaseStateDenyReasonSetConverterBehavior) ? (PartBaseStateDenyReasonSetConverterBehavior)parameter : ValueContainer.CreateFromObject(parameter).GetValue <PartBaseStateDenyReasonSetConverterBehavior>(rethrow: false)) : default(PartBaseStateDenyReasonSetConverterBehavior); IBaseState baseState = (value as IBaseState).MapDefaultTo(BaseState.None); UseState useState = baseState.UseState; ConnState connState = baseState.ConnState; bool useStateIsBusy = (useState == UseState.OnlineBusy || useState == UseState.AttemptOnline); bool connStateIsBusy = (connState == ConnState.Connecting); bool connStateIsApplicable = (connState != ConnState.NotApplicable && connState != ConnState.Undefined); BaseState.ToStringSelect toStringSelect = BaseState.ToStringSelect.UseStateNoPrefix | BaseState.ToStringSelect.ConnState | ((useState == UseState.OnlineBusy) ? BaseState.ToStringSelect.ActionName : BaseState.ToStringSelect.Reason); switch (behavior) { case PartBaseStateDenyReasonSetConverterBehavior.IsFullyOnlineAndIdle: if (useStateIsBusy) { return("Part '{0}' is not idle: {1}".CheckedFormat(baseState.PartID, baseState.ToString(toStringSelect))); } else if (!useState.IsOnline(acceptAttemptOnline: false, acceptUninitialized: false, acceptOnlineFailure: false, acceptAttemptOnlineFailed: false)) { return("Part '{0}' is not online: {1}".CheckedFormat(baseState.PartID, baseState.ToString(toStringSelect))); } else if (!connState.IsConnected() && connStateIsApplicable) { return("Part '{0}' is not connected: {1}".CheckedFormat(baseState.PartID, baseState.ToString(toStringSelect))); } break; case PartBaseStateDenyReasonSetConverterBehavior.IsOnlineAndIdle: if (useStateIsBusy) { return("Part '{0}' is not idle: {1}".CheckedFormat(baseState.PartID, baseState.ToString(toStringSelect))); } else if (!useState.IsOnline(acceptAttemptOnline: false, acceptUninitialized: true, acceptOnlineFailure: true, acceptAttemptOnlineFailed: false)) { return("Part '{0}' is not online: {1}".CheckedFormat(baseState.PartID, baseState.ToString(toStringSelect))); } else if (!connState.IsConnected() && connStateIsApplicable) { return("Part '{0}' is not connected: {1}".CheckedFormat(baseState.PartID, baseState.ToString(toStringSelect))); } break; case PartBaseStateDenyReasonSetConverterBehavior.IsOnline: if (!useState.IsOnline(acceptAttemptOnline: true, acceptUninitialized: true, acceptOnlineFailure: true, acceptAttemptOnlineFailed: false)) { return("Part '{0}' is not online: {1}".CheckedFormat(baseState.PartID, baseState.ToString(toStringSelect))); } break; case PartBaseStateDenyReasonSetConverterBehavior.IsNotBusy: if (useStateIsBusy) { return("Part '{0}' is not idle: {1}".CheckedFormat(baseState.PartID, baseState.ToString(BaseState.ToStringSelect.AllForPart))); } break; default: return("Invalid requested conversion beahvior [{0}]".CheckedFormat(behavior)); } return(EmptyArrayFactory <string> .Instance); }