private void InitialzeStateManager() { _stateManager = new StateManager(_muffinAnimator); IdleState idle = new IdleState(_stateManager, transform); MoveState move = new MoveState(_stateManager, transform); TrapState trap = new TrapState(_stateManager, transform); DieState die = new DieState(_stateManager, transform); SpinState spin = new SpinState(_stateManager, transform); BlastState blast = new BlastState(_stateManager, transform); ChocoRushState chocoRush = new ChocoRushState(_stateManager, transform); PauseState pause = new PauseState(_stateManager, transform); _stateManager.AddCharacterState(idle); _stateManager.AddCharacterState(move); _stateManager.AddCharacterState(trap); _stateManager.AddCharacterState(die); _stateManager.AddCharacterState(spin); _stateManager.AddCharacterState(blast); _stateManager.AddCharacterState(chocoRush); _stateManager.AddCharacterState(pause); _stateManager.SetDefaultState("Pause"); }
public CloudSprite(Texture2D texture, Vector2 position, int rMod) : base(texture, position) { myRandom = rMod; myTexture = texture; myState = new IdleState(this); }
void Awake() { Hp = InitialLifes = ConfigReader.GetConfig().GetField("hero").GetField("InitialLifes").n; AttackDistance = ConfigReader.GetConfig().GetField("hero").GetField("AttackDistance").n; AttackReloadPeriod = ConfigReader.GetConfig().GetField("hero").GetField("AttackReloadPeriod").n; Velocity = ConfigReader.GetConfig().GetField("hero").GetField("Velocity").n; AttackReactionPeriod = ConfigReader.GetConfig().GetField("hero").GetField("AttackReactionPeriod").n; AttackReloadPeriod = ConfigReader.GetConfig().GetField("hero").GetField("AttackReloadPeriod").n; MovingToDragTargetVelocity = ConfigReader.GetConfig().GetField("hero").GetField("MovingToDragTargetVelocity").n; HpPercent = 100; IdleState idleState = new IdleState(this); ConductorMoveState moveState = new ConductorMoveState(this); ConductorDragState dragState = new ConductorDragState(this); AttackState attackState = new AttackState(this); AttackedState attackedState = new AttackedState(this); FrozenState frozenState = new FrozenState(this); Dictionary<int, State> stateMap = new Dictionary<int, State> { {(int) MovableCharacterStates.Idle, idleState}, {(int) MovableCharacterStates.Move, moveState}, {(int) MovableCharacterStates.Drag, dragState}, {(int) MovableCharacterStates.Attack, attackState}, {(int) MovableCharacterStates.Attacked, attackedState}, {(int) MovableCharacterStates.Frozen, frozenState} }; InitWithStates(stateMap, (int)MovableCharacterStates.Idle); }
void Awake () { wanderState = new WanderState (wanderTimeMin, wanderTimeMax, wanderSpeed, wanderRadius); idleState = new IdleState (idleTime); chaseState = new ChaseState (chaseTime, chaseSpeed); attackState = new AttackState (); deadState = new DeadState (); leaveAltarState = new LeaveAltarState (); }
void Awake() { attackState = new AttackState(this); chaseState = new ChaseState(this); idleState = new IdleState(this); patrolState = new PatrolState(this); playerBuddy = GameObject.FindGameObjectWithTag("Player").transform; buddyScript = playerBuddy.GetComponent<Movement>(); }
public LightningSprite(Texture2D texture, SoundEffect sound, Vector2 position, CloudSprite[] clouds, LightningGame game) : base(texture, position) { myGame = game; myTexture = texture; mySound = sound; myClouds = clouds; myState = new IdleState(this); }
void Awake() { mat = GetComponent<Renderer>().material; idleState = new IdleState(this); moveState = new MoveState(this); talkState = new TalkState(this); loveState = new LoveState(this); currentState = moveState; }
protected void Awake() { idleState = new IdleState(this); huntState = new HuntState(this); fearState = new FearState(this); engageState = new EngageState(this); counterState = new CounterState(this); nav = GetComponent<NavMeshAgent> (); }
// The NPC has 3 states: Idle and ChasingPlayer // If it's on the first state and SawPlayer transition is fired, it changes to ChasePlayer // If it's on ChasePlayerState and LostPlayer transition is fired, it returns to FollowPath protected void MakeFSM() { fsm = new FSMSystem (); IdleState idleState = new IdleState (detectionRange, initialPosition); idleState.AddTransition (Transition.PlayerDetected, StateID.ChasingPlayer); ChasingPlayerState chasingState = new ChasingPlayerState (this.detectionRange, this.attackRange); chasingState.AddTransition (Transition.PlayerConcealed, StateID.Idle); fsm.AddState (idleState); fsm.AddState (chasingState); }
public override StateMachine CreateMachine() { AbstractState idle = new IdleState((int)States.DEFAULT, this); AbstractState seek = new SeekState((int)States.SEEK, this); AbstractState pursuit = new PursuitState((int)States.PURSUIT, this); SeekStateMachine stateMachine = new SeekStateMachine(); stateMachine.AddDefaultState(idle); stateMachine.AddState(seek); stateMachine.AddState(pursuit); return stateMachine; }
public SpriteManager(Texture2D texture, Vector2 position, Vector2 screen, Game1 aGame, Asis anAsis, Laser aLaser, Enemy aEnemy, SoundEffect aLaserSoundEffect, SoundEffect aBackwardsLaserSoundEffect) : base(texture, position) { myPosition = position; myScreenSize = screen; myGame = aGame; Asis = anAsis; Laser = aLaser; redEnemy = aEnemy; LaserSoundEffect = aLaserSoundEffect; BackwardsLaserSoundEffect = aBackwardsLaserSoundEffect; myState = new IdleState(this); TimeStack = new Stack(); SetUpInput(); }
private void Awake() { wanderState = new WanderState (this); // huntStart = new HuntState (this); May replace with this idleState = new IdleState (this); // huntStart = new HuntState (this); May replace with this forageState = new ForageState (this); flightState = new FlightState (this); pursuitState = new PursuitState (this); exitState = new ExitState (this); enterState = new EnterState (this); navMeshAgent = GetComponent<NavMeshAgent>(); navMeshAgent.enabled = true; // navMeshObstacle.enabled = false; navMeshRadius = navMeshAgent.radius; navMeshAgent.avoidancePriority = Random.Range(0, 100); // Randomly set the avoidance priority }
public TimeTravelManager(Texture2D texture, Vector2 position, Vector2 screen, NebulaGame aGame, List<Sprite> aPositionsList, Hero anHero) : base(texture, position) { myTexture = texture; myPosition = position; myScale = new Vector2(1, 2); myGame = aGame; myScreenSize = screen; PositionsList = aPositionsList; myHero = anHero; TimeTravelSound = myGame.Content.Load<SoundEffect>("warp"); TimeTravelSoundInstance = TimeTravelSound.CreateInstance(); TimeTravelSoundInstance.IsLooped = true; myState = new IdleState(this); TimeStack = new Stack(); SetUpInput(); }
/// <summary> /// Constructor for sub-classes. /// </summary> /// <param name="state">the <see cref="IdleStateEvent"/> which triggered the event.</param> /// <param name="first"><c>true</c> if its the first idle event for the <see cref="IdleStateEvent"/>.</param> protected IdleStateEvent(IdleState state, bool first) { State = state; First = first; }
public new virtual bool CheckExpired(IdleState state, DateTime current) { return(base.CheckExpired(state, current)); }
/// <summary> /// Get the various Components. /// Create the possible States.</summary> public virtual void Awake() { // Get the necessary Components _navMeshAgent = GetComponent<NavMeshAgent>(); _inventory = GetComponent<Inventory>(); // Initialize necessary properties _enemies = new List<Character>(); _interactingCharacters = new List<Character>(); // Initialize the Stats Stats = Instantiate(_stats); Stats.Character = this; // Initialize the States _idleState = new IdleState(this); _alertState = new AlertState(this); _chaseState = new ChaseState(this); _attackState = new AttackState(this); _dyingState = new DyingState(this); _moveState = new MoveState(this); }
/// <summary> /// 获取状态 /// </summary> /// <param name="AIState"></param> /// <returns></returns> private StateBase GetState(AIStateType AIState) { if (this.m_StateDic.ContainsKey(AIState)) { return this.m_StateDic[AIState]; } StateBase state; switch (AIState) { case AIStateType.Attack: state = new AttackState(this.m_ActorBev,this.m_ActorAI); break; case AIStateType.Dead: state = new DeadState(this.m_ActorBev, this.m_ActorAI); break; case AIStateType.Hurt: state = new HurtState(this.m_ActorBev, this.m_ActorAI); break; case AIStateType.Idle: state = new IdleState(this.m_ActorBev, this.m_ActorAI); break; default: Debug.Log(AIState.ToString() + " not exsit "); return null; } this.m_StateDic.Add(AIState, state); return state; }
/// <summary> /// Initialize controlling state machine /// </summary> private void InitializeStateMachine() { Debug.Log("Init state machine"); // States IdleState idleState = new IdleState(); idleState.Parent = this; mStateMachine.AddState(idleState); SkiState skiState = new SkiState(); skiState.Parent = this; mStateMachine.AddState(skiState); CrouchState crouchState = new CrouchState(); crouchState.Parent = this; mStateMachine.AddState(crouchState); JumpState jumpState = new JumpState(); jumpState.Parent = this; mStateMachine.AddState(jumpState); InAirState inAirState = new InAirState(); inAirState.Parent = this; mStateMachine.AddState(inAirState); LandingState landState = new LandingState(); landState.Parent = this; mStateMachine.AddState(landState); FallDownState fallDownState = new FallDownState(); fallDownState.Parent = this; mStateMachine.AddState(fallDownState); // Transitions /////////////////// // Grounded states mStateMachine.AddTransition( CharacterEvents.To_Ski, idleState, skiState); mStateMachine.AddTransition( CharacterEvents.To_Idle, skiState, idleState); // Jump / Land states mStateMachine.AddTransition( CharacterEvents.To_Crouch, skiState, crouchState); mStateMachine.AddTransition( CharacterEvents.To_Jump, crouchState, jumpState); mStateMachine.AddTransition( CharacterEvents.To_InAir, jumpState, inAirState); mStateMachine.AddTransition( CharacterEvents.To_Landing, inAirState, landState); mStateMachine.AddTransition( CharacterEvents.To_Ski, landState, skiState); // Ramp states mStateMachine.AddTransition( CharacterEvents.To_InAir, skiState, inAirState); // for initialization mStateMachine.AddTransition( CharacterEvents.To_InAir, idleState, inAirState); // for fall down mStateMachine.AddTransition( CharacterEvents.To_FallDown, idleState, fallDownState); mStateMachine.AddTransition( CharacterEvents.To_FallDown, skiState, fallDownState); mStateMachine.AddTransition( CharacterEvents.To_FallDown, crouchState, fallDownState); // character starts in a spawn in state mStateMachine.StartState = idleState; mStateMachine.Activate(null); DeactivateRagdoll(); }
internal bool StartIdling() { if (SelectedFolder == null) { return(false); } switch (_idleState) { case IdleState.Off: //if (SelectedFolder.UidNext == 0) // SelectedFolder.Status(new[] { FolderStatusFields.UIdNext }); _lastIdleUId = SelectedFolder.UidNext; break; case IdleState.On: return(true); case IdleState.Paused: //if (SelectedFolder.UidNext == 0) // SelectedFolder.Status(new[] { FolderStatusFields.UIdNext }); _lastIdleUId = SelectedFolder.UidNext; break; } lock (_lock) { const string tmpl = "IMAPX{0} {1}"; _counter++; string text = string.Format(tmpl, _counter, "IDLE") + "\r\n"; byte[] bytes = Encoding.UTF8.GetBytes(text.ToCharArray()); if (IsDebug) { Debug.WriteLine(text); } _ioStream.Write(bytes, 0, bytes.Length); if (_ioStream.ReadByte() != '+') { return(false); } var line = _streamReader.ReadLine(); if (IsDebug && !string.IsNullOrEmpty(line)) { Debug.WriteLine(line); } } _idleState = IdleState.On; _idleLoopThread = new Thread(WaitForIdleServerEvents) { IsBackground = true }; _idleLoopThread.Start(); if (OnIdleStarted != null) { OnIdleStarted(SelectedFolder, new IdleEventArgs { Client = SelectedFolder.Client, Folder = SelectedFolder }); } return(true); }
private void WaitForIdleServerEvents() { if (_idleProcessThread == null) { _idleProcessThread = new Thread(ProcessIdleServerEvents) { IsBackground = true }; _idleProcessThread.Start(); } if (_idleNoopIssueThread == null) { _idleNoopIssueThread = new Thread(MaintainIdleConnection) { IsBackground = true }; _idleNoopIssueThread.Start(); } while (_idleState == IdleState.On) { if (_ioStream.ReadByte() != -1) { string tmp = _streamReader.ReadLine(); if (tmp == null) { continue; } if (IsDebug) { Debug.WriteLine(tmp); } if (tmp.ToUpper().Contains("OK")) { _idleState = IdleState.Off; return; } _idleEvents.Enqueue(tmp); if (_idleProcessThread == null) { _idleProcessThread = new Thread(ProcessIdleServerEvents) { IsBackground = true }; _idleProcessThread.Start(); } } } }
private void ConstructFSM() { IdleState idle = new IdleState(); idle.AddTransition(FSMTransitionType.CanBeMove, FSMStateType.Move); idle.AddTransition(FSMTransitionType.AttackWithSingleWield, FSMStateType.SingleWieldAttack); idle.AddTransition(FSMTransitionType.AttackWithDoubleHands, FSMStateType.DoubleHandsAttack); idle.AddTransition(FSMTransitionType.UsingRipple, FSMStateType.RippleAttack); idle.AddTransition(FSMTransitionType.UsingHeartAttack, FSMStateType.HeartAttack); idle.AddTransition(FSMTransitionType.UsingStygianDesolator, FSMStateType.StygianDesolator); idle.AddTransition(FSMTransitionType.UsingIceArrow, FSMStateType.IceArrow); idle.AddTransition(FSMTransitionType.UsingChoshimArrow, FSMStateType.ChoshimArrow); idle.AddTransition(FSMTransitionType.CanPickUp, FSMStateType.PickUp); idle.AddTransition(FSMTransitionType.UsingThunderBolt, FSMStateType.ThunderBolt); idle.AddTransition(FSMTransitionType.AttackWithSpear, FSMStateType.SpearAttack); idle.AddTransition(FSMTransitionType.CanDefend, FSMStateType.Defend); idle.AddTransition(FSMTransitionType.Falling, FSMStateType.Fall); MoveState move = new MoveState(); move.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); move.AddTransition(FSMTransitionType.AttackWithSingleWield, FSMStateType.SingleWieldAttack); move.AddTransition(FSMTransitionType.AttackWithDoubleHands, FSMStateType.DoubleHandsAttack); move.AddTransition(FSMTransitionType.AttackWithSpear, FSMStateType.SpearAttack); DefendState defend = new DefendState(); defend.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); SingleWieldAttackState singleWieldAttack = new SingleWieldAttackState(); singleWieldAttack.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); singleWieldAttack.AddTransition(FSMTransitionType.AttackWithSingleWield, FSMStateType.SingleWieldAttack); singleWieldAttack.AddTransition(FSMTransitionType.CanBeMove, FSMStateType.Move); DoubleHandsAttackState dualWieldAttack = new DoubleHandsAttackState(); dualWieldAttack.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); dualWieldAttack.AddTransition(FSMTransitionType.AttackWithDoubleHands, FSMStateType.DoubleHandsAttack); dualWieldAttack.AddTransition(FSMTransitionType.CanBeMove, FSMStateType.Move); SpearAttackState spearAttack = new SpearAttackState(); spearAttack.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); spearAttack.AddTransition(FSMTransitionType.CanBeMove, FSMStateType.Move); RippleAttackState rippleAttack = new RippleAttackState(); rippleAttack.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); HeartAttackState heartAttack = new HeartAttackState(); heartAttack.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); StygianDesolatorState stygianDesolator = new StygianDesolatorState(); stygianDesolator.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); IceArrowState iceArrow = new IceArrowState(); iceArrow.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); ChoshimArrowState choshimArrow = new ChoshimArrowState(); choshimArrow.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); ThunderBoltState thunderBolt = new ThunderBoltState(); thunderBolt.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); PickUpState pickUp = new PickUpState(); pickUp.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); FallState fall = new FallState(); fall.AddTransition(FSMTransitionType.IsIdle, FSMStateType.Idle); AddFSMState(idle); AddFSMState(move); AddFSMState(defend); AddFSMState(singleWieldAttack); AddFSMState(dualWieldAttack); AddFSMState(rippleAttack); AddFSMState(heartAttack); AddFSMState(stygianDesolator); AddFSMState(iceArrow); AddFSMState(choshimArrow); AddFSMState(thunderBolt); AddFSMState(pickUp); AddFSMState(spearAttack); AddFSMState(fall); }
protected virtual void FixedUpdate() { if (isPlayer) { KeyBinds.CheckKeysDown(this); } else { // AI hook goes here! } if (currentHorizontalState != null) { currentHorizontalState.Update(this); } if (currentVerticalState != null) { currentVerticalState.Update(this); } else if (currentHorizontalState == null) { // Both Horizontal and Vertical states are null -- move to default state. defaultState = (IdleState)ChangeState(null, defaultState); // This is merely a formality to make sure the OnStateEnter gets called. defaultState.Update(this); } if (currentEquipmentState != null) { currentEquipmentState.Update(this); } }
// Use this for initialization of variables that rely on other objects void Start () { //Initializing components anim = this.GetComponent<Animator>(); selfBody = this.GetComponent<Rigidbody2D>(); hitboxManager = this.GetComponent<CollisionboxManager>(); ActionFsm = new StateMachine<Player>(this); State<Player> startState = new IdleState(this, this.ActionFsm); ActionFsm.InitialState(startState); }
public CopyMachine(int pricePerDocument) { PricePerDocument = pricePerDocument; State = new IdleState(); MoneyCount = 0; }
public TcpClientConnection() { IdleState = new IdleState(); }
public DefaultIdleStateEvent(IdleState state, bool first) : base(state, first) { _representation = $"IdleStateEvent({state}{(first ? ", first" : "")})"; }
private void Awake() { singState = new SingState (this); idleState = new IdleState (this); audioSource = gameObject.GetComponent<AudioSource> (); audioSource.clip = song; }
public override void Begin() { base.Begin(); GameSystem.SetTimeMultiplier(GameSystem.GAMEPLAY, 1.0); IdleState idle = new IdleState(this.listenerId); MovingForwardState movingForward = new MovingForwardState(this.listenerId); MovingBackwardState movingBackward = new MovingBackwardState(this.listenerId); QuickStepForwardState quickStepForward = new QuickStepForwardState(this.listenerId); QuickStepBackwardState quickStepBackward = new QuickStepBackwardState(this.listenerId); DashChargingState dashCharging = new DashChargingState(this.listenerId); DashState dash = new DashState(this.listenerId); FeintState feint = new FeintState(this.listenerId); ChargingState charging = new ChargingState(this.listenerId); ChargeRecoveryState chargeRecovery = new ChargeRecoveryState(this.listenerId); DashRecoveryState dashRecovery = new DashRecoveryState(this.listenerId); //SpecialActivateState specialActivate = new SpecialActivateState(this.listenerId); //SpecialChargingState specialCharging = new SpecialChargingState(this.listenerId); CollisionWinCondition collisionWinCond = new CollisionWinCondition(this.listenerId); CollisionLossCondition collisionLossCond = new CollisionLossCondition(this.listenerId); CollisionWinState collisionWin = new CollisionWinState(this.listenerId); CollisionLossState collisionLoss = new CollisionLossState(this.listenerId); PlayerReadyState ready = new PlayerReadyState(this.listenerId); PlayerPlayingState playing = new PlayerPlayingState(this.listenerId); PlayerPausedState paused = new PlayerPausedState(this.listenerId); VictoryState victory = new VictoryState(this.listenerId); DefeatState defeat = new DefeatState(this.listenerId); //SpecialActivateCondition specialActivateCond = new SpecialActivateCondition(this.listenerId); DefeatCondition defeatCond = new DefeatCondition(this.listenerId); idle.AddStateChange("moveForward", movingForward); idle.AddStateChange("moveBackward", movingBackward); idle.AddStateChange("charge", charging); idle.AddStateChange("dashCharge", dashCharging); idle.AddStateChange("feint", feint); idle.AddStateChange("collisionWin", collisionWin); idle.AddStateChange("collisionLoss", collisionLoss); //idle.AddStateChange("specialActivate", specialActivate); idle.AddGameStateCondition(collisionWinCond); idle.AddGameStateCondition(collisionLossCond); //idle.AddGameStateCondition(specialActivateCond); movingForward.AddStateChange("stop", idle); movingForward.AddStateChange("quickStep", quickStepForward); movingForward.AddStateChange("moveBackward", movingBackward); movingForward.AddStateChange("charge", charging); movingForward.AddStateChange("dashCharge", dashCharging); movingForward.AddStateChange("feint", feint); movingForward.AddStateChange("collisionWin", collisionWin); movingForward.AddStateChange("collisionLoss", collisionLoss); //movingForward.AddStateChange("specialActivate", specialActivate); movingForward.AddGameStateCondition(collisionWinCond); movingForward.AddGameStateCondition(collisionLossCond); //movingForward.AddGameStateCondition(specialActivateCond); quickStepForward.AddStateChange("stop", idle); quickStepForward.AddStateChange("charge", charging); quickStepForward.AddStateChange("dashCharge", dashCharging); quickStepForward.AddStateChange("feint", feint); quickStepForward.AddStateChange("collisionWin", collisionWin); quickStepForward.AddStateChange("collisionLoss", collisionLoss); //quickStepForward.AddStateChange("specialActivate", specialActivate); quickStepForward.AddGameStateCondition(collisionWinCond); quickStepForward.AddGameStateCondition(collisionLossCond); //quickStepForward.AddGameStateCondition(specialActivateCond); movingBackward.AddStateChange("stop", idle); movingBackward.AddStateChange("quickStep", quickStepBackward); movingBackward.AddStateChange("moveForward", movingForward); movingBackward.AddStateChange("charge", charging); movingBackward.AddStateChange("dashCharge", dashCharging); movingBackward.AddStateChange("feint", feint); movingBackward.AddStateChange("collisionWin", collisionWin); movingBackward.AddStateChange("collisionLoss", collisionLoss); //movingBackward.AddStateChange("specialActivate", specialActivate); movingBackward.AddGameStateCondition(collisionWinCond); movingBackward.AddGameStateCondition(collisionLossCond); //movingBackward.AddGameStateCondition(specialActivateCond); quickStepBackward.AddStateChange("stop", idle); quickStepBackward.AddStateChange("charge", charging); quickStepBackward.AddStateChange("dashCharge", dashCharging); quickStepBackward.AddStateChange("feint", feint); quickStepBackward.AddStateChange("collisionWin", collisionWin); quickStepBackward.AddStateChange("collisionLoss", collisionLoss); //quickStepBackward.AddStateChange("specialActivate", specialActivate); quickStepBackward.AddGameStateCondition(collisionWinCond); quickStepBackward.AddGameStateCondition(collisionLossCond); //quickStepBackward.AddGameStateCondition(specialActivateCond); charging.AddStateChange("stop", chargeRecovery); charging.AddStateChange("collisionWin", collisionWin); charging.AddStateChange("collisionLoss", collisionLoss); charging.AddGameStateCondition(collisionWinCond); charging.AddGameStateCondition(collisionLossCond); dashCharging.AddStateChange("dash", dash); dashCharging.AddStateChange("collisionWin", collisionWin); dashCharging.AddStateChange("collisionLoss", collisionLoss); dashCharging.AddGameStateCondition(collisionWinCond); dashCharging.AddGameStateCondition(collisionLossCond); dash.AddStateChange("stop", dashRecovery); dash.AddStateChange("collisionWin", collisionWin); dash.AddStateChange("collisionLoss", collisionLoss); dash.AddGameStateCondition(collisionWinCond); dash.AddGameStateCondition(collisionLossCond); feint.AddStateChange("stop", idle); feint.AddStateChange("charge", charging); feint.AddStateChange("dashCharge", dashCharging); feint.AddStateChange("feint", feint); feint.AddStateChange("collisionWin", collisionWin); feint.AddStateChange("collisionLoss", collisionLoss); feint.AddGameStateCondition(collisionWinCond); feint.AddGameStateCondition(collisionLossCond); chargeRecovery.AddStateChange("recover", idle); chargeRecovery.AddStateChange("collisionWin", collisionWin); chargeRecovery.AddStateChange("collisionLoss", collisionLoss); chargeRecovery.AddGameStateCondition(collisionWinCond); chargeRecovery.AddGameStateCondition(collisionLossCond); dashRecovery.AddStateChange("recover", idle); dashRecovery.AddStateChange("collisionWin", collisionWin); dashRecovery.AddStateChange("collisionLoss", collisionLoss); dashRecovery.AddGameStateCondition(collisionWinCond); dashRecovery.AddGameStateCondition(collisionLossCond); /*specialActivate.AddStateChange("specialCharge", specialCharging); * specialActivate.AddStateChange("collisionWin", collisionWin); * specialActivate.AddStateChange("collisionLoss", collisionLoss); * specialActivate.AddGameStateCondition(collisionWinCond); * specialActivate.AddGameStateCondition(collisionLossCond); * specialCharging.AddStateChange("stop", idle); * specialCharging.AddStateChange("collisionWin", collisionWin); * specialCharging.AddStateChange("collisionLoss", collisionLoss); * specialCharging.AddGameStateCondition(collisionWinCond); * specialCharging.AddGameStateCondition(collisionLossCond);*/ collisionWin.AddStateChange("recover", idle); collisionLoss.AddStateChange("recover", idle); ready.AddStateChange("play", playing); playing.AddStateChange("pause", paused); playing.AddGameStateCondition(defeatCond); paused.AddStateChange("play", playing); playing.AddStateChange("victory", victory); playing.AddStateChange("defeat", defeat); this.input = new GameInputState(this.listenerId, 0); this.input.SetInputMapping(GameInputState.LEFT_STICK_LEFT_RIGHT, "moveStick"); this.input.SetInputMapping(GameInputState.D_PAD_LEFT_RIGHT, "moveStick"); this.input.SetInputMapping(GameInputState.A, "chargeButton"); this.input.SetInputMapping(GameInputState.B, "quickStepButton"); this.input.SetInputMapping(GameInputState.X, "dashButton"); this.input.SetInputMapping(GameInputState.Y, "feintButton"); this.input.SetInputMapping(GameInputState.START, "start"); this.AddCurrentState(this.input); this.AddCurrentState(idle); this.AddCurrentState(ready); }
void Awake() { idleState = new IdleState(this); chaseState = new ChaseState(this); }
/// <summary> /// Constructor for sub-classes. /// </summary> /// <param name="state">the <see cref="IdleStateEvent"/> which triggered the event.</param> /// <param name="first"><code>true</code> if its the first idle event for the <see cref="IdleStateEvent"/>.</param> protected IdleStateEvent(IdleState state, bool first) { this.State = state; this.First = first; }
public void UpdateAI() { var viewSize = new Vector2(200, 50); RectangleF viewArea = new RectangleF(Position - viewSize / 2, viewSize); if (viewArea.Contains(World.Player.Position)) { Target = World.Player; TargetTime = 200; } else { TargetTime--; if (TargetTime <= 0) { Target = null; } } if (Target != null) //Engaged { if (CurrentAction is ActionHit) { } else if (CurrentAction is ActionEnemyDeath) { } else if (CurrentAction is ActionJump) { } else if (CurrentAction is ActionClimb) { OnWall = false; } else { foreach (var weaponAI in GetWeaponAIs(Weapon)) { weaponAI.Update(this); } if (DifferenceVector.X < 0) { Owner.Facing = HorizontalFacing.Left; } else if (DifferenceVector.X > 0) { Owner.Facing = HorizontalFacing.Right; } float preferredDistanceMin = 20; float preferredDistanceMax = 30; if (Target.Invincibility > 0) { preferredDistanceMin = 30; preferredDistanceMax = 40; } if (Target.InAir) { preferredDistanceMin = 40; preferredDistanceMax = 50; } if (CurrentAction is ActionMove move) { move.WalkingLeft = false; move.WalkingRight = false; } if (Math.Abs(DifferenceVector.X) > preferredDistanceMax) { Owner.WalkConstrained(DifferenceVector.X); } if (Math.Abs(DifferenceVector.X) < preferredDistanceMin) { Owner.WalkConstrained(-DifferenceVector.X); } } AttackCooldown--; RangedCooldown--; } else //Idle { IdleTime--; switch (Idle) { case (IdleState.Wait): break; case (IdleState.MoveLeft): Owner.Facing = HorizontalFacing.Left; Owner.WalkConstrained(-1); break; case (IdleState.MoveRight): Owner.Facing = HorizontalFacing.Right; Owner.WalkConstrained(1); break; } if (OnWall) { if (Idle == IdleState.MoveLeft) { Idle = IdleState.MoveRight; } else if (Idle == IdleState.MoveRight) { Idle = IdleState.MoveLeft; } OnWall = false; IdleTime = 70; } if (IdleTime <= 0) { WeightedList <IdleState> nextState = new WeightedList <IdleState>(); nextState.Add(IdleState.Wait, 30); nextState.Add(IdleState.MoveLeft, 70); nextState.Add(IdleState.MoveRight, 70); IdleTime = Owner.Random.Next(50) + 20; Idle = nextState.GetWeighted(Owner.Random); } } }
void Awake() { idleState = new IdleState(this); chaseState = new ChaseState(this); attackState = new AttackState(this); }
private void Awake() { agent = GetComponent <NavMeshAgent>(); inventory = new Inventory(inventorySize); stateMachine = new StateMachine(); //states IdleState idleState = new IdleState(this); MoveToPointState moveToPoint = new MoveToPointState(this, agent); MoveToResourceState toResource = new MoveToResourceState(this, agent); MoveToBuildsite moveToBuild = new MoveToBuildsite(this, agent); HarvestResourceState harvestResource = new HarvestResourceState(this); FindStorageState findStorage = new FindStorageState(this); FindResourceState findResource = new FindResourceState(this, agent); MoveToStorageState toStorage = new MoveToStorageState(this, agent); StoreItemsState storeItems = new StoreItemsState(this); BuildState buildState = new BuildState(this); stateMachine.SetState(idleState); //transitions AddNewTransition(moveToPoint, idleState, Stuck()); AddNewTransition(idleState, toResource, HasRTarget()); AddNewTransition(idleState, moveToBuild, HasBuildTarget()); AddNewTransition(toResource, harvestResource, ReachedResource()); AddNewTransition(harvestResource, findStorage, InventoryFull()); AddNewTransition(harvestResource, findResource, ResourceIsEmpty()); AddNewTransition(findStorage, toStorage, HasStoreTarget()); AddNewTransition(toStorage, storeItems, ReachedStorage()); AddNewTransition(storeItems, findStorage, cantStore()); AddNewTransition(storeItems, toResource, GatherAndTarget()); AddNewTransition(storeItems, findResource, GatherAndNoTarget()); AddNewTransition(findResource, toResource, HasRTarget()); AddNewTransition(findResource, idleState, NoResourceNearbyEmpty()); AddNewTransition(findResource, findStorage, NoResourceNearbyNotEmpty()); AddNewTransition(moveToBuild, buildState, ReachedBuildsite()); AddNewTransition(buildState, idleState, () => buildTarget == null); stateMachine.AddAnyTransition(idleState, () => currentTask == unitTask.None); stateMachine.AddAnyTransition(moveToPoint, () => clickMove); AddNewTransition(moveToPoint, idleState, ReachedPoint()); void AddNewTransition(IState fromState, IState toState, Func <bool> condition) => stateMachine.AddTransition(fromState, toState, condition); //condition functions Func <bool> Stuck() => () => moveToPoint.stuckTime > 0.8f; Func <bool> HasRTarget() => () => resourceTarget != null; Func <bool> HasStoreTarget() => () => storeTarget != null; Func <bool> HasBuildTarget() => () => buildTarget != null; Func <bool> ReachedPoint() => () => Vector3.Distance(transform.position, clickTarget) < stopDistance; Func <bool> ReachedResource() => () => resourceTarget != null && Vector3.Distance(transform.position, resourceTarget.transform.position) < stopDistance; Func <bool> ReachedBuildsite() => () => buildTarget != null && Vector3.Distance(transform.position, buildTarget.transform.position) < stopDistance; Func <bool> ResourceIsEmpty() => () => resourceTarget == null; Func <bool> InventoryFull() => () => !inventory.CanAdd(resourceItem); Func <bool> ReachedStorage() => () => Vector3.Distance(transform.position, storeTarget.transform.position) < stopDistance; Func <bool> cantStore() => () => storeTarget == null && inventory.container.Count > 0; Func <bool> GatherAndTarget() => () => inventory.container.Count == 0 && resourceTarget != null; Func <bool> GatherAndNoTarget() => () => inventory.container.Count == 0 && resourceTarget == null && currentTask == unitTask.Gather; Func <bool> NoResourceNearbyEmpty() => () => inventory.container.Count == 0 && resourceTarget == null && nearbyRescources.Count == 0; Func <bool> NoResourceNearbyNotEmpty() => () => inventory.container.Count > 0 && resourceTarget == null; }
public void TestIdleKeepIdleCallback() { using (var session = Authenticate("IDLE")) { // SELECT server.EnqueueResponse("* FLAGS (\\Deleted \\Seen)\r\n" + "* 4 EXISTS\r\n" + "* 0 RECENT\r\n" + "* OK [UIDVALIDITY 1]\r\n" + "0002 OK SELECT completed\r\n"); Assert.IsTrue((bool)session.Select("INBOX")); Assert.AreEqual("0002 SELECT \"INBOX\"\r\n", server.DequeueRequest()); Assert.AreEqual(4, session.SelectedMailbox.ExistsMessage); // IDLE Assert.IsFalse(session.IsIdling); server.WaitForRequest = false; session.SendTimeout = 50; session.ReceiveTimeout = 50; session.TransactionTimeout = 50; var waitForIdleFinishEvent = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(delegate(object state) { var s = state as ImapPseudoServer; s.EnqueueResponse("* 2 EXPUNGE\r\n" + "* 3 EXISTS\r\n" + "+ idling\r\n"); Thread.Sleep(250); // ...time passes; another client expunges message 3... s.EnqueueResponse("* 3 EXPUNGE\r\n" + "* 2 EXISTS\r\n"); Thread.Sleep(250); // ...time passes; new mail arrives... s.EnqueueResponse("* 3 EXISTS\r\n"); waitForIdleFinishEvent.WaitOne(); Thread.Sleep(500); s.EnqueueResponse("0003 OK IDLE terminated\r\n"); }, server); var idleState = new IdleState(); idleState.Session = session; idleState.CurrentMessageCount = session.SelectedMailbox.ExistsMessage; Assert.IsTrue((bool)session.Idle(1000, idleState, delegate(object state, ImapUpdatedStatus updatedStatus) { var s = state as IdleState; if (updatedStatus.Expunge.HasValue) { s.CurrentMessageCount--; } else if (updatedStatus.Exists.HasValue) { if (s.CurrentMessageCount < updatedStatus.Exists.Value) { waitForIdleFinishEvent.Set(); return false; } else { s.CurrentMessageCount = updatedStatus.Exists.Value; } } return true; })); waitForIdleFinishEvent.Close(); Assert.AreEqual("0003 IDLE\r\n", server.DequeueRequest()); Assert.AreEqual("DONE\r\n", server.DequeueRequest()); Assert.AreEqual(3L, session.SelectedMailbox.ExistsMessage); CloseMailbox(session, "0004"); } }
public IdleStateEvent(IdleState state, bool first) { this.State = state; this.First = first; }
// Update is called once per frame void Update() { Debug.Log("当前状态为:" + state); switch (state) { case State.State_Idle: float newTime = Time.time; Debug.Log("当前子状态为:" + idleState); switch (idleState) { case IdleState.IdleState_stand: if (newTime - curTime > 4) { curTime = newTime; idleState = IdleState.IdleState_play_sword; spineAnimationState.SetAnimation(0, animation_idle2, true); } break; case IdleState.IdleState_play_sword: if (newTime - curTime > 4) { curTime = newTime; idleState = IdleState.IdleState_play_sheild; spineAnimationState.SetAnimation(0, animation_idle3, true); } break; case IdleState.IdleState_play_sheild: if (newTime - curTime > 4) { curTime = newTime; idleState = IdleState.IdleState_stand; spineAnimationState.SetAnimation(0, animation_idle1, true); } break; } if (getDistanceAbs(hero, this.gameObject) < 5.0f) { state = State.State_Follow; spineAnimationState.SetAnimation(0, animation_move, true); } break; case State.State_Follow: gotoObject(hero); if (getDistanceAbs(hero, this.gameObject) > 5.0f) { state = State.State_Back; } if (getDistanceAbs(hero, this.gameObject) < 1.0f) { state = State.State_Attack; spineAnimationState.SetAnimation(0, animation_attack, true); } break; case State.State_Back: gotoObject(birthPoint); if (getDistanceAbs(this.gameObject, birthPoint) < 0.1f) { state = State.State_Idle; spineAnimationState.SetAnimation(0, animation_idle1, true); } break; case State.State_Attack: if (getDistanceAbs(this.gameObject, hero) > 1.5f) { state = State.State_Follow; spineAnimationState.SetAnimation(0, animation_move, true); } break; } }
IdleStateEventArgs(bool first, IdleState state) { this.State = state; this.IsFirst = first; }
void Start() { anim = GetComponent <Animator>(); StateIDToActionID = new Dictionary <StateID, Action>() { { StateID.BattleFireBall, Action.FireBall }, { StateID.BattleFallingBall, Action.FallingBall } }; DragonHealth = 20; PeriodSufferDamge = 0; player = GameObject.FindGameObjectsWithTag("CurPlayer")[0]; GameObject controller_object = GameObject.FindGameObjectsWithTag("GameController")[0]; gamecontroller = controller_object.GetComponent <gamecontrol>(); DragonKnowledge = new KnowledgeSystem(); IdleState idle = new IdleState(player, gameObject); idle.AddTransition(Transition.SawPlayer, StateID.BattleRoar); idle.AddTransition(Transition.IdleEnd, StateID.RandomWalk); RandomWalkState walk = new RandomWalkState(player, gameObject); walk.AddTransition(Transition.SawPlayer, StateID.BattleRoar); walk.AddTransition(Transition.WalkEnd, StateID.Idle); BattleRoarState roar = new BattleRoarState(player, gameObject); roar.AddTransition(Transition.Falling, StateID.BattleFallingBall); roar.AddTransition(Transition.Beaten, StateID.BattleBeaten); roar.AddTransition(Transition.FireBall, StateID.BattleFireBall); roar.AddTransition(Transition.FarAway, StateID.BattleRun); BattleFireBallState fireball = new BattleFireBallState(player, gameObject); fireball.AddTransition(Transition.FireBall, StateID.BattleFireBall); fireball.AddTransition(Transition.FarAway, StateID.BattleRun); fireball.AddTransition(Transition.LowHealth, StateID.BattleRetreat); fireball.AddTransition(Transition.Beaten, StateID.BattleBeaten); fireball.AddTransition(Transition.Falling, StateID.BattleFallingBall); BattleRunState run = new BattleRunState(player, gameObject); run.AddTransition(Transition.FireBall, StateID.BattleFireBall); run.AddTransition(Transition.LowHealth, StateID.BattleRetreat); run.AddTransition(Transition.Falling, StateID.BattleFallingBall); BattleRetreatState retreat = new BattleRetreatState(player, gameObject); retreat.AddTransition(Transition.Beaten, StateID.BattleBeaten); BattleBeatenState beaten = new BattleBeatenState(player, gameObject); beaten.AddTransition(Transition.FireBall, StateID.BattleFireBall); beaten.AddTransition(Transition.LowHealth, StateID.BattleRetreat); beaten.AddTransition(Transition.FlyBack, StateID.BattleFlyBack); BattleFlyBackState flyback = new BattleFlyBackState(player, gameObject); flyback.AddTransition(Transition.FireBall, StateID.BattleFireBall); flyback.AddTransition(Transition.Falling, StateID.BattleFallingBall); flyback.AddTransition(Transition.FarAway, StateID.BattleRun); flyback.AddTransition(Transition.Beaten, StateID.BattleBeaten); BattleFallingBall fallingball = new BattleFallingBall(player, gameObject); fallingball.AddTransition(Transition.FireBall, StateID.BattleFireBall); fallingball.AddTransition(Transition.FarAway, StateID.BattleRun); fallingball.AddTransition(Transition.LowHealth, StateID.BattleRetreat); fallingball.AddTransition(Transition.Beaten, StateID.BattleBeaten); fallingball.AddTransition(Transition.Falling, StateID.BattleFallingBall); fsm = new FSMSystem(); fsm.AddState(idle); fsm.AddState(walk); fsm.AddState(roar); fsm.AddState(fireball); fsm.AddState(run); fsm.AddState(retreat); fsm.AddState(beaten); fsm.AddState(flyback); fsm.AddState(fallingball); }
public MyStateMachine() { ChaseState = new IdleState(this); IdleState = new ChaseState(this); AttackState = new AttackState(this); }
//-----------------------New States------------------------ private IdleState NewIdle() { idle = new IdleState(idleTimer, IdleCallback); return(idle); }
/// <summary> /// Initialize controlling state machine /// </summary> private void InitializeStateMachine() { //states IdleState idleState = new IdleState(); idleState.Parent = this; mStateMachine.AddState(idleState); WalkState walkState = new WalkState(); walkState.Parent = this; mStateMachine.AddState(walkState); /* RunState runState = new RunState(); runState.Parent = this; mStateMachine.AddState(runState); */ GetWalkTarget getWalkTargetState = new GetWalkTarget(); getWalkTargetState.Parent = this; mStateMachine.AddState(getWalkTargetState); SpawnInState spawnInState = new SpawnInState(); spawnInState.Parent = this; mStateMachine.AddState(spawnInState); SpawnOutState spawnOutState = new SpawnOutState(); spawnOutState.Parent = this; mStateMachine.AddState(spawnOutState); DeadState deadState = new DeadState(); deadState.Parent = this; mStateMachine.AddState(deadState); EatCarrotState eatCarrotState = new EatCarrotState(); eatCarrotState.Parent = this; mStateMachine.AddState(eatCarrotState); EatFlowerState eatFlowerState = new EatFlowerState(); eatFlowerState.Parent = this; mStateMachine.AddState(eatFlowerState); WinDanceState winDanceState = new WinDanceState(); winDanceState.Parent = this; mStateMachine.AddState(winDanceState); LostState lostState = new LostState(); lostState.Parent = this; mStateMachine.AddState(lostState); //transitions mStateMachine.AddTransition((int)CharacterEvents.To_Walk, idleState, walkState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, idleState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_Idle, walkState, idleState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, walkState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_Walk, getWalkTargetState, walkState); mStateMachine.AddTransition((int)CharacterEvents.To_Idle, getWalkTargetState, idleState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, spawnInState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_SpawnOut, getWalkTargetState, spawnOutState); mStateMachine.AddTransition((int)CharacterEvents.To_EatCarrot, getWalkTargetState, eatCarrotState); mStateMachine.AddTransition((int)CharacterEvents.To_EatFlower, getWalkTargetState, eatFlowerState); mStateMachine.AddTransition((int)CharacterEvents.To_Dead, spawnOutState, deadState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatCarrotState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatFlowerState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, getWalkTargetState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, idleState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, walkState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnInState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnOutState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatFlowerState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatCarrotState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, idleState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, walkState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, getWalkTargetState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnInState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnOutState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatFlowerState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatCarrotState, lostState); #if (WINDOWS_PHONE && !SILVERLIGHT) mStateMachine.AddTransition((int)CharacterEvents.To_SpawnIn, deadState, spawnInState); #endif //mStateMachine.AddTransition((int)CharacterEvents.To_Run, walkState, runState); //mStateMachine.AddTransition((int)CharacterEvents.TimerElapsed, runState, walkState); // character starts in a spawn in state #if (WINDOWS_PHONE && !SILVERLIGHT) mStateMachine.StartState = deadState; #else mStateMachine.StartState = spawnInState; #endif }
// Update is called once per frame void Update() { switch (state) { case State.State_idle: float newTime = Time.time; switch (idleState) { case IdleState.IdleState_idle1: playAnimation(idleAnimationName); if (Time.time - cutTime > 4) { idleState = IdleState.IdleState_idle2; cutTime = newTime; } break; case IdleState.IdleState_idle2: playAnimation(idleAnimationName2); if (Time.time - cutTime > 4) { idleState = IdleState.IdleState_idle3; cutTime = newTime; } break; case IdleState.IdleState_idle3: playAnimation(idleAnimationName3); if (Time.time - cutTime > 4) { idleState = IdleState.IdleState_idle1; cutTime = newTime; } break; } if (getDistance(this.gameObject, hero) < range) { setState(State.State_follow); } break; case State.State_follow: playAnimation(moveAnimation); moveTo(hero); if (getDistance(this.gameObject, hero) > range) { setState(State.State_back); } if (getDistance(this.gameObject, hero) < attackRange) { setState(State.State_attack); } break; case State.State_attack: playAnimation(attackAnimationName); if (getDistance(this.gameObject, hero) > attackRange) { setState(State.State_follow); } break; case State.State_back: playAnimation(moveAnimation); moveTo(birthPoint); if (getDistance(this.gameObject, birthPoint) < 0.2) { setState(State.State_idle); } break; case State.State_patrol: break; } }
protected AbstractDistributed() { IdleState = new IdleState(); }
public string Reply() { switch (State) { case IdleState.Initialize: break; case IdleState.StartDelay: if (Stats.IsInGame || Stats.IsLoadingWorld) { State = IdleState.CheckIdle; } else if (General.DateSubtract(StartDelay) > 0) { if (FailedStartDelay > 3 && General.DateSubtract(TimeFailedStartDelay) > 600) { State = IdleState.Terminate; break; } Logger.Instance.Write(Parent, "Demonbuddy:{0}: Delayed start failed! ({1} seconds overtime)", Parent.Demonbuddy.Proc.Id, General.DateSubtract(StartDelay)); TimeFailedStartDelay = DateTime.Now; FailedStartDelay++; return "Restart"; } break; case IdleState.CheckIdle: _lastIdleAction = DateTime.Now; // Update Last Idle action time return IdleAction; case IdleState.Busy: if (Stats.IsRunning && !Stats.IsPaused && Stats.IsInGame) { Reset(); } else if (General.DateSubtract(_lastIdleAction) > 10) { if (Failed >= 3) State = IdleState.Terminate; Failed++; Reset(); } break; case IdleState.UserStop: if (Stats.IsRunning) State = IdleState.CheckIdle; ResetCoinage(); break; case IdleState.UserPause: if(!Stats.IsPaused) State = IdleState.CheckIdle; break; case IdleState.NewProfile: State = IdleState.CheckIdle; return "LoadProfile " + Parent.ProfileSchedule.GetProfile; case IdleState.Terminate: Parent.Restart(); break; } return "Roger!"; }
public void SetIdleState(IdleState idleState) { switch (idleState) { case IdleState.InUse: Type = PresenceType.available; Mode = PresenceMode.available; Priority = 2; break; case IdleState.Idle: Type = PresenceType.available; Mode = PresenceMode.away; Priority = 0; break; case IdleState.ExtendedIdle: Type = PresenceType.available; Mode = PresenceMode.xa; Priority = 0; break; } }
/// <summary> /// Initialize controlling state machine /// </summary> private void InitializeStateMachine() { //states IdleState idleState = new IdleState(); idleState.Parent = this; mStateMachine.AddState(idleState); WalkState walkState = new WalkState(); walkState.Parent = this; mStateMachine.AddState(walkState); /* * RunState runState = new RunState(); * runState.Parent = this; * mStateMachine.AddState(runState); */ GetWalkTarget getWalkTargetState = new GetWalkTarget(); getWalkTargetState.Parent = this; mStateMachine.AddState(getWalkTargetState); SpawnInState spawnInState = new SpawnInState(); spawnInState.Parent = this; mStateMachine.AddState(spawnInState); SpawnOutState spawnOutState = new SpawnOutState(); spawnOutState.Parent = this; mStateMachine.AddState(spawnOutState); DeadState deadState = new DeadState(); deadState.Parent = this; mStateMachine.AddState(deadState); EatCarrotState eatCarrotState = new EatCarrotState(); eatCarrotState.Parent = this; mStateMachine.AddState(eatCarrotState); EatFlowerState eatFlowerState = new EatFlowerState(); eatFlowerState.Parent = this; mStateMachine.AddState(eatFlowerState); WinDanceState winDanceState = new WinDanceState(); winDanceState.Parent = this; mStateMachine.AddState(winDanceState); LostState lostState = new LostState(); lostState.Parent = this; mStateMachine.AddState(lostState); //transitions mStateMachine.AddTransition((int)CharacterEvents.To_Walk, idleState, walkState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, idleState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_Idle, walkState, idleState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, walkState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_Walk, getWalkTargetState, walkState); mStateMachine.AddTransition((int)CharacterEvents.To_Idle, getWalkTargetState, idleState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, spawnInState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_SpawnOut, getWalkTargetState, spawnOutState); mStateMachine.AddTransition((int)CharacterEvents.To_EatCarrot, getWalkTargetState, eatCarrotState); mStateMachine.AddTransition((int)CharacterEvents.To_EatFlower, getWalkTargetState, eatFlowerState); mStateMachine.AddTransition((int)CharacterEvents.To_Dead, spawnOutState, deadState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatCarrotState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatFlowerState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, getWalkTargetState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, idleState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, walkState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnInState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnOutState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatFlowerState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatCarrotState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, idleState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, walkState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, getWalkTargetState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnInState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnOutState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatFlowerState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatCarrotState, lostState); #if (WINDOWS_PHONE && !SILVERLIGHT) mStateMachine.AddTransition((int)CharacterEvents.To_SpawnIn, deadState, spawnInState); #endif //mStateMachine.AddTransition((int)CharacterEvents.To_Run, walkState, runState); //mStateMachine.AddTransition((int)CharacterEvents.TimerElapsed, runState, walkState); // character starts in a spawn in state #if (WINDOWS_PHONE && !SILVERLIGHT) mStateMachine.StartState = deadState; #else mStateMachine.StartState = spawnInState; #endif }
void Start() { IdleState idleState = new IdleState(StateMgr, this); StateMgr.SwitchTo(idleState); }
//Pet bobs around a point. void Idle() { switch (_currentIdleState) { case IdleState.NONE: break; case IdleState.RECORDING_POSITON: lastLocation = transform.position; _currentIdleState = IdleState.DOIN_MY_THANG; break; case IdleState.DOIN_MY_THANG: transform.position = new Vector3(transform.position.x,lastLocation.y + ((float)Math.Sin(Time.time) / floatingStrength),transform.position.z); idleTimeLeft -= Time.deltaTime; if (idleTimeLeft < 0f) _currentAIState = AIStates.DECIDING; break; } //Currently Only Moves Up and Down. }
public string Reply() { if (Program.Pause) { return("Roger!"); } switch (State) { case IdleState.Initialize: break; case IdleState.StartDelay: if (Stats.IsInGame || Stats.IsLoadingWorld) { State = IdleState.CheckIdle; } else if (General.DateSubtract(StartDelay) > 0) { if (FailedStartDelay > 5 || (FailedStartDelay > 3 && General.DateSubtract(TimeFailedStartDelay) > 600)) { State = IdleState.Terminate; return("Shutdown"); //break; } Logger.Instance.Write(Parent, "Demonbuddy:{0}: Delayed start failed! ({1} seconds overtime)", Parent.Demonbuddy.Proc.Id, General.DateSubtract(StartDelay)); TimeFailedStartDelay = DateTime.Now; FailedStartDelay++; return("Restart"); } break; case IdleState.CheckIdle: { _lastIdleAction = DateTime.Now; // Update Last Idle action time string idleAction = IdleAction; if (idleAction != "Roger!") { Logger.Instance.Write("Idle action: {0}", idleAction); } return(idleAction); } case IdleState.Busy: if (Stats.IsRunning && !Stats.IsPaused && Stats.IsInGame) { Reset(); } else if (General.DateSubtract(_lastIdleAction) > 10) { if (Failed >= 3) { State = IdleState.Terminate; } Failed++; Reset(); } break; case IdleState.UserStop: if (Stats.IsRunning) { State = IdleState.CheckIdle; } ResetCoinage(); break; case IdleState.UserPause: if (!Stats.IsPaused) { Reset(); State = IdleState.CheckIdle; } break; case IdleState.NewProfile: State = IdleState.CheckIdle; return("LoadProfile " + Parent.ProfileSchedule.GetProfile); case IdleState.Terminate: Parent.Restart(); return("Shutdown"); //break; } return("Roger!"); }
void Start() { playerModelDefaultRotation = playerModel.transform.localRotation; playerModelClimbRotation = Quaternion.identity; playerModelTauntRotation.SetLookRotation(new Vector3(0, 0, -1), new Vector3(0, 1, 0)); attackCollider.enabled = false; lightningGenerator.SetActive(false); // temp dashAttackCollider.enabled = false; shieldCollider.enabled = false; ShowShield(false); ShowHorn(false); playerAnimator = GetComponent <Animator>(); GameObject.FindGameObjectWithTag("GameSession").GetComponent <SavePlayerState>().RecoverPlayerStatusValues(this); staminaRecovery = 0.0f; fullStaminaRecovery = false; GameObject guiObject = GameObject.Find("GUI"); if (guiObject) { guiManager = guiObject.GetComponent <GUIManager>(); } activeRespawnPoint = initialPosition; cameraFade = GameObject.Find("PlayerCamera").GetComponent <CameraFade>(); attack = new AttackState(CalculateFramesFromTime(attackDuration)); cast = new CastState(CalculateFramesFromTime(castDuration)); climb = new ClimbState(); dash = new DashState(CalculateFramesFromTime(dashDuration)); dead = new DeadState(CalculateFramesFromTime(deadDuration)); defense = new DefenseState(); drink = new DrinkState(CalculateFramesFromTime(drinkDuration)); fall = new FallState(); fallcloud = new FallCloudState(CalculateFramesFromTime(fallCloudDuration)); hit = new HitState(CalculateFramesFromTime(hitDuration)); idle = new IdleState(); jump = new JumpState(CalculateFramesFromTime(GetComponent <PlayerMove>().timeToJumpApex)); refill = new RefillState(CalculateFramesFromTime(refillDuration)); taunt = new TauntState(CalculateFramesFromTime(tauntDuration)); walk = new WalkState(); SetState(idle); facingRight = true; jumpAvailable = true; climbLadderAvailable = false; beerRefillAvailable = false; justHit = false; jumpFrames = 0; framesInDelayCount = 0; camFollow = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraFollow>(); colliderSize = GetComponent <BoxCollider>().size; godMode = false; }
protected IdleStateEvent(IdleState _state, bool first) { this._state = _state; this.first = first; }
internal bool StartIdling() { if (SelectedFolder == null) { return false; } switch (_idleState) { case IdleState.Off: _lastIdleUId = SelectedFolder.UidNext; break; case IdleState.On: return true; case IdleState.Paused: _lastIdleUId = SelectedFolder.UidNext; break; } lock (_lock) { const string tmpl = "IMAP{0} {1}"; _counter++; string text = string.Format(tmpl, _counter, "IDLE") + "\r\n"; byte[] bytes = Encoding.UTF8.GetBytes(text.ToCharArray()); if (IsDebug) { Debug.WriteLine(text); } _ioStream.Write(bytes, 0, bytes.Length); string line = ""; if (_ioStream.ReadByte() != '+') { return false; } else { line = _streamReader.ReadLine(); } if (IsDebug) { Debug.WriteLine(line); } } _idleState = IdleState.On; _idleLoopThread = new Thread(WaitForIdleServerEvents) { IsBackground = true }; _idleLoopThread.Start(); if (OnIdleStarted != null) OnIdleStarted(SelectedFolder, new IdleEventArgs { Client = SelectedFolder.Client, Folder = SelectedFolder }); return true; }
private void Start() { //Agarro el model _model = GetComponent <Model>(); //Creo la FSM _fsm = new FSM <string>(); //Creo los estados IdleState <string> idle = new IdleState <string>(this); PatrolState <string> patrol = new PatrolState <string>(Waypoints, transform, this); ShootState <string> shoot = new ShootState <string>(this); AlertState <string> alert = new AlertState <string>(this, Sight, ExclamationMark); SearchState <string> search = new SearchState <string>(this); //Creo las transiciones idle.AddTransition(_patrolKey, patrol); idle.AddTransition(_shootKey, shoot); idle.AddTransition(_alertKey, alert); idle.AddTransition(_searchKey, search); idle.AddTransition(_idleKey, idle); //se tienen a si mismos por si llega a tener que volverse a ejecutar con el random patrol.AddTransition(_idleKey, idle); patrol.AddTransition(_shootKey, shoot); patrol.AddTransition(_alertKey, alert); patrol.AddTransition(_searchKey, search); alert.AddTransition(_idleKey, idle); alert.AddTransition(_shootKey, shoot); alert.AddTransition(_patrolKey, patrol); alert.AddTransition(_alertKey, alert); alert.AddTransition(_searchKey, search); search.AddTransition(_searchKey, search); search.AddTransition(_idleKey, idle); search.AddTransition(_shootKey, shoot); search.AddTransition(_patrolKey, patrol); search.AddTransition(_alertKey, alert); //diccionario de todos los estados de idle para la roulette _statesRoulette = new Dictionary <string, int>(); _statesRoulette.Add(_idleKey, 30); _statesRoulette.Add(_patrolKey, 70); _statesRoulette.Add(_searchKey, 50); //inicializo la FSM _fsm.SetInitialState(idle); //Inicializo los nodos del Desicion Tree ActionNode _shootActionNode = new ActionNode(ChangeToShootState); //Aca pasarle función ActionNode _alertActionNode = new ActionNode(ChangeToAlertState); ActionNode _randomStateActionNode = new ActionNode(ChangeToRandomState); _isFirstTimeQuestionNode = new QuestionNode(Sight.SawTargetOnce, _shootActionNode, _alertActionNode); _isSeeingPlayerQuestionNode = new QuestionNode(Sight.IsSeeingTarget, _isFirstTimeQuestionNode, _randomStateActionNode); Sight.SawTarget.AddListener(ExecuteTree); // Roulette _actionRoulette = new Roulette <string>(); }
void Start() { // originalPos.transform. this.originalPos.transform.parent = null; fromAttr = GetComponent <BasicObjectAttr>(); NavMeshAgent agent = GetComponent <NavMeshAgent>(); FSMManager manager = GetComponent <FSMManager>(); IdleState idle = new IdleState(); idle.isInfinite = true; InvestigateState investigateState = new InvestigateState(); manager.setCurrentState(idle); manager.GetBasicState().configure("Player", (o) => { investigateState.setTargetPos(o.transform.position).SetDoWhenArrive((s) => { Collider[] coll = Physics.OverlapSphere(gameObject.transform.position, fromAttr.dangerViewAreaRadius); foreach (Collider c in coll) { if (c.tag.Equals("Player")) { var go = Camera.main.GetComponent <GameOverCameraControl>(); go.showDeadEffect = true; return(null); } } idle.time = fromAttr.investigateWaitTime; idle.isInfinite = false; idle.onComplete((s1) => { investigateState.setTargetPos(this.originalPos.transform.position); investigateState.SetDoWhenArrive((s2) => { idle.isInfinite = true; transform.rotation = this.originalPos.transform.rotation; agent.destination = this.transform.position; return(idle); }); return(investigateState); }); return(idle); }); return(investigateState); }, (o) => { investigateState.setTargetPos(o.transform.position); investigateState.SetDoWhenArrive((s) => { Collider[] coll = Physics.OverlapSphere(gameObject.transform.position, fromAttr.dangerViewAreaRadius); foreach (Collider c in coll) { if (c.tag.Equals("Player")) { var go = Camera.main.GetComponent <GameOverCameraControl>(); go.showDeadEffect = true; return(null); } } idle.time = fromAttr.investigateWaitTime; idle.isInfinite = false; idle.onComplete((s1) => { investigateState.setTargetPos(this.originalPos.transform.position); investigateState.SetDoWhenArrive((s2) => { idle.isInfinite = true; transform.rotation = this.originalPos.transform.rotation; agent.destination = this.transform.position; return(idle); }); return(investigateState); }); return(idle); }); return(investigateState); }); }
public void Reset(bool all = false, bool freshstart = false) { State = IdleState.CheckIdle; Stats.Reset(); ResetCoinage(); if (all) { IsInitialized = false; InitTime = DateTime.Now; State = IdleState.Initialize; Failed = 0; FailedStartDelay = 0; } if (freshstart) { FixAttempts = 0; } }
static void IdleLoop(object state) { IdleState idle = (IdleState)state; lock (idle.Client.SyncRoot) { // Note: since the IMAP server will drop the connection after 30 minutes, we must loop sending IDLE commands that // last ~29 minutes or until the user has requested that they do not want to IDLE anymore. // // For GMail, we use a 9 minute interval because they do not seem to keep the connection alive for more than ~10 minutes. while (!idle.IsCancellationRequested) { using (var timeout = new CancellationTokenSource(new TimeSpan(0, 9, 0))) { try { // We set the timeout source so that if the idle.DoneToken is cancelled, it can cancel the timeout idle.SetTimeoutSource(timeout); if (idle.Client.Capabilities.HasFlag(ImapCapabilities.Idle)) { // The Idle() method will not return until the timeout has elapsed or idle.CancellationToken is cancelled idle.Client.Idle(timeout.Token, idle.CancellationToken); } else { // The IMAP server does not support IDLE, so send a NOOP command instead idle.Client.NoOp(idle.CancellationToken); // Wait for the timeout to elapse or the cancellation token to be cancelled WaitHandle.WaitAny(new[] { timeout.Token.WaitHandle, idle.CancellationToken.WaitHandle }); } } catch (OperationCanceledException) { // This means that idle.CancellationToken was cancelled, not the DoneToken nor the timeout. break; } catch (ImapProtocolException) { // The IMAP server sent garbage in a response and the ImapClient was unable to deal with it. // This should never happen in practice, but it's probably still a good idea to handle it. // // Note: an ImapProtocolException almost always results in the ImapClient getting disconnected. break; } catch (ImapCommandException) { // The IMAP server responded with "NO" or "BAD" to either the IDLE command or the NOOP command. // This should never happen... but again, we're catching it for the sake of completeness. break; } finally { // We're about to Dispose() the timeout source, so set it to null. idle.SetTimeoutSource(null); } } } } }
void Deciding() { ResetAIStates(); if (IsOutOfPlayerLimits()) { _currentAIState = AIStates.RETURNING; if (_currentReturningState == ReturningState.NONE) _currentReturningState = ReturningState.LOOKING_FOR_TARGET; } else { if (Random.value < 0.5f) { _currentAIState = AIStates.IDLING; if (_currentIdleState == IdleState.NONE) _currentIdleState = IdleState.DOIN_MY_THANG; } else { _currentAIState = AIStates.ROAMING; if (_currentRoamingState == RoamingState.NONE) _currentRoamingState = RoamingState.LOOKING_FOR_TARGET; } } }
protected override void Update() { if (currentState.AllowJumping() && Input.GetAxis("Jump") > 0.1) { float jumpForce = Mathf.Sqrt(2 * -gravity * jumpHeight); velocity.y = jumpForce; SetState(JumpingState.Instance()); } if (!onGround && velocity.y < 0) { SetState(FallingState.Instance()); } float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); float strafe = 0f; bool applyGroundFriction = true; if (Math.Abs(horizontal) > AXIS_DEADZONE) { if (currentState.AllowRunning()) { strafe = horizontal; SetState(RunningState.Instance()); velocity.x = horizontalSpeed * strafe; applyGroundFriction = false; } else if (currentState.AllowAirControl()) { strafe = horizontal; velocity.x += strafe * airControlHorizontalAcceleration * Time.deltaTime * 1.0f / 0.999f /*counter-drag*/; } } if (Math.Abs(velocity.x) > horizontalSpeed) { velocity.x = horizontalSpeed * Math.Sign(velocity.x); } if (currentState.AllowCrouching() && vertical < -AXIS_DEADZONE) { SetState(CrouchingState.Instance()); } else if (onGround) { if (strafe == 0f) { SetState(IdleState.Instance()); } else { SetState(RunningState.Instance()); } } if (applyGroundFriction) { if (onGround) { velocity.x *= 0.85f; } else { velocity.x *= 0.999f; } } currentState.Update(gameObject, this); base.Update(); }
void ResetAIStates() { idleTimeLeft = Random.Range(5, 10); _currentReturningState = ReturningState.NONE; _currentIdleState = IdleState.NONE; _currentRoamingState = RoamingState.NONE; _currentPlayingState = PlayingState.NONE; }
internal void PauseIdling() { if (_idleState != IdleState.On) { return; } StopIdling(true); _idleState = IdleState.Paused; if (OnIdlePaused != null) OnIdlePaused(SelectedFolder, new IdleEventArgs { Client = SelectedFolder.Client, Folder = SelectedFolder }); }