/// <summary> /// Called when [before executed]. /// </summary> /// <typeparam name="T1"> The type of the 1. </typeparam> /// <param name="preExecuteEvent"> The pre execute event. </param> /// <param name="preExecuteEventConfigurationAction"> The pre execute event configuration action. </param> /// <returns> </returns> public IStateEventConfiguration OnBeforeExecuted <T1> (T1 preExecuteEvent, Action <T1> preExecuteEventConfigurationAction) where T1 : IStateEvent { _preExecuteEvent = preExecuteEvent; preExecuteEventConfigurationAction(preExecuteEvent); return(this); }
protected void GotoState(IState nextState, IStateEvent evt) { curState.Leave(evt); preState = curState; curState = nextState; curState.Enter(evt); }
/// <summary> /// Called when [after executed]. /// </summary> /// <typeparam name="T1"> The type of the 1. </typeparam> /// <param name="postExecuteEvent"> The post execute event. </param> /// <param name="postExecuteEventConfigurationAction"> The post execute event configuration action. </param> /// <returns> </returns> public IStateEventConfiguration OnAfterExecuted <T1> (T1 postExecuteEvent, Action <T1> postExecuteEventConfigurationAction) where T1 : IStateEvent { _postExecuteEvent = postExecuteEvent; postExecuteEventConfigurationAction(postExecuteEvent); return(this); }
public override bool OnMessage(NpcActor owner, IStateEvent t) { switch (t.EventType) { case StateEventType.BossCome: owner.ShowBoom(true); return(true); case StateEventType.BossLeave: owner.ShowBoom(false); return(true); case StateEventType.BossHit: EventDispatcher.TriggerEvent(BattleEvent.BossAngry); owner.StateMachine.ChangeState(new NpcStateScare()); return(true); case StateEventType.BossAbuse: EventDispatcher.TriggerEvent(BattleEvent.BossAngry); owner.ShowWater(); owner.RefreshWorkSate(WorkState.HitToWork); owner.StateMachine.ChangeState(new NpcStateWork()); return(true); } return(false); }
public StateCommand(string name, string status, IStateEvent expectedEvent = null) { ExpectedEvent = expectedEvent; Status = status; Name = name; Notes = ""; }
/// <summary> /// Called when [stop]. /// </summary> /// <typeparam name="T"> </typeparam> /// <param name="stopEvent"> The stop event. </param> /// <param name="stopEventConfigurationAction"> The stop event configuration action. </param> /// <returns> </returns> IStateMachineConfiguration IStateMachineConfiguration.OnStop <T> (T stopEvent, Action <T> stopEventConfigurationAction) { StopEvent = stopEvent; stopEventConfigurationAction(stopEvent); return(this); }
/// <summary> /// 注册事件 /// </summary> /// <param name="e">事件接口</param> public void RegisterEvent(IStateEvent e) { if (e == null || _stateEvent.Contains(e)) { return; } _stateEvent.Add(e); }
public override EventResult HandleEvent(IStateEvent happening) { if (happening is CombatFinishedEvent) { combatFinished = true; return(EventResult.EventHandled); } return(EventResult.EventNotHandled); }
public override EventResult HandleEvent(IStateEvent happening) { if (happening is PositionReachedEvent) { positionReached = true; return(EventResult.EventHandled); } return(EventResult.EventNotHandled); }
public static IStateEvent MockStateEvent <T>( IStateEvent mockEvent, string stateKey, int age = 0) where T : class, IStateContent { mockEvent.StateKey = stateKey; mockEvent.UnsignedData.Age = age; return(mockEvent); }
public void RaiseEvent(IStateEvent ev) { if (activeState != null && !activeState.MachineTerminated) { var result = activeState.HandleEvent(ev); if (result == EventResult.EventNotHandled) { logger.Log("Unhandled event in statemachine", LogLevel.Warning); } } }
public override bool OnMessage(NpcActor owner, IStateEvent t) { switch (t.EventType) { case StateEventType.BossCome: owner.StateMachine.ChangeState(new NpcStateWork()); owner.RefreshWorkSate(WorkState.HitToWork); return(true); } return(false); }
public bool CanLeave(IState enterState, IStateEvent evt) { bool canLeave = true; StateLeaveTransitDelegate leaveDel = null; if (stateLeaveTransitDic != null) { stateLeaveTransitDic.TryGetValue(enterState, out leaveDel); if (leaveDel != null) { canLeave = leaveDel(enterState, evt); } } return(canLeave); }
public override EventResult HandleEvent(IStateEvent happening) { if (happening is PlayerReachedGoalEvent) { goalReached = true; Debug.Log("Hurrah"); return(EventResult.EventHandled); } if (happening is PlayerDiedEvent) { playerDied = true; Debug.Log("Boho"); return(EventResult.EventHandled); } return(EventResult.EventNotHandled); }
//发送消息到当前的状态 public bool HandleMessage(IStateEvent msg) { //the message if (m_pCurrentState != null && m_pCurrentState.OnMessage(m_pOwner, msg)) { return(true); } // message to the global state if (m_pGlobalState != null && m_pGlobalState.OnMessage(m_pOwner, msg)) { return(true); } return(false); }
/// <summary> /// Adds the state event. /// </summary> /// <param name="stateEvent"> The state event. </param> /// <param name="executionMethod"> The execution method. </param> public void AddStateEvent(IStateEvent stateEvent, EventExecutionMethod executionMethod) { switch (executionMethod) { case EventExecutionMethod.Parallel: _parallelEvents.Enqueue(stateEvent); break; case EventExecutionMethod.Default: case EventExecutionMethod.Serial: _serializedEvents.Enqueue(stateEvent); break; default: throw new ArgumentOutOfRangeException("executionMethod"); } }
public bool CanEnter(IState leaveState, IStateEvent evt) { bool canEnter = false;//还是默认不能进入,如果默认可以进入,那么在不加状态之间的切换链接情况下,可以默认退出可以默认进入,那么切换链接就没有意义了 StateEnterTransitDelegate enterDel = null; if (stateEnterTransitDic != null) { stateEnterTransitDic.TryGetValue(leaveState, out enterDel); if (enterDel != null) { canEnter = enterDel(leaveState, evt); } } if (allStateEnterTransit != null) { canEnter |= allStateEnterTransit(leaveState, evt); } return(canEnter); }
/// <summary> /// Called when [after executed]. /// </summary> /// <typeparam name="T1"> The type of the 1. </typeparam> /// <param name="configureAction"> The configure action. </param> /// <returns> </returns> public IStateEventConfiguration OnAfterExecuted <T1> (Func <T1> configureAction) where T1 : class, IStateEvent { _postExecuteEvent = configureAction( ); return(this); }
public StateEventInfo(int processId, IStateEvent state) : base(processId, state) { State = state; }
/// <summary> /// 该状态接收到某个消息,子类具体实现 /// </summary> /// <param name="actorType"></param> /// <param name="t"></param> /// <returns></returns> public virtual bool OnMessage(Actor_type owner, IStateEvent t) { return(false); }
protected bool TryTransitState(IState curState, IState nextState, IStateEvent evt) { return(curState.CanLeave(nextState, evt) && nextState.CanEnter(curState, evt)); }
protected bool TryTransitState(IState nextState, IStateEvent evt) { return(TryTransitState(curState, nextState, evt)); }
/// <summary> /// Called when [start]. /// </summary> /// <param name="startEvent"> The start event. </param> /// <returns> </returns> IStateMachineConfiguration IStateMachineConfiguration.OnStart(IStateEvent startEvent) { StartEvent = startEvent; return(this); }
/// <summary> /// Called when [stop]. /// </summary> /// <typeparam name="T"> </typeparam> /// <param name="stopEvent"> The stop event. </param> /// <returns> </returns> IStateMachineConfiguration IStateMachineConfiguration.OnStop <T> (T stopEvent) { StopEvent = stopEvent; return(this); }
public StateEventInfo(int processId, string name, string status, string notes, IStateCommand expectedCommand) : base(processId, new StateEvent(name, status, notes, expectedCommand)) { State = new StateEvent(name, status, notes, expectedCommand); }
/// <summary> /// Called when [after executed]. /// </summary> /// <typeparam name="T1"> The type of the 1. </typeparam> /// <param name="postExecuteEvent"> The post execute event. </param> /// <returns> </returns> public IStateEventConfiguration OnAfterExecuted <T1> (T1 postExecuteEvent) where T1 : IStateEvent { _postExecuteEvent = postExecuteEvent; return(this); }
/// <summary> /// Called when [before executed]. /// </summary> /// <typeparam name="T1"> The type of the 1. </typeparam> /// <param name="preExecuteEvent"> The pre execute event. </param> /// <returns> </returns> public IStateEventConfiguration OnBeforeExecuted <T1> (T1 preExecuteEvent) where T1 : IStateEvent { _preExecuteEvent = preExecuteEvent; return(this); }
/// <summary> /// Called when configuring the behavior that is executed after to the current <see cref="IStateEvent" /> /// </summary> /// <param name="postExecuteEvent"> The post execute event. </param> /// <returns> /// the modified <see cref="IStateEventConfiguration" /> instance. /// </returns> public IStateEventConfiguration OnAfterExecuted(IStateEvent postExecuteEvent) { _postExecuteEvent = postExecuteEvent; return(this); }
/// <summary> /// Called when configuring the behavior that is executed prior to the current <see cref="IStateEvent" /> /// </summary> /// <param name="preExecuteEvent"> The pre execute event. </param> /// <returns> /// the modified <see cref="IStateEventConfiguration" /> instance. /// </returns> public IStateEventConfiguration OnBeforeExecuted(IStateEvent preExecuteEvent) { _preExecuteEvent = preExecuteEvent; return(this); }
/// <summary> /// Called when [stop]. /// </summary> /// <typeparam name="T"> </typeparam> /// <returns> </returns> IStateMachineConfiguration IStateMachineConfiguration.OnStop <T> (Func <T> configureAction) { StopEvent = _stateContainer.GetInstance <T> ( ); return(this); }