예제 #1
0
        private void ChainNotify(GameAction action, ActionState state)
        {
            chainState = state;
            ChainCallback currentChain = chainCallback;

            ISchedule scheduledAction = action as ISchedule;

            switch (state)
            {
            case ActionState.Fired:
            case ActionState.Started:
            case ActionState.Rescheduled:
                DbPersistance.Current.Save(action);
                if (scheduledAction != null)
                {
                    Scheduler.Current.Put(scheduledAction);
                }

                DbPersistance.Current.Save(this);

                Scheduler.Current.Put(new ChainExecuter(currentChain, state));
                return;

            case ActionState.Completed:
            case ActionState.Failed:
                ActionIdGenerator.Release(action.ActionId);
                DbPersistance.Current.Delete(action);
                break;

            default:
                throw new Exception("Unexpected state " + state);
            }

            //current action is completed by either success or failure
            if (scheduledAction != null)
            {
                Scheduler.Current.Remove(scheduledAction);
            }

            action.IsDone    = true;
            action.OnNotify -= ChainNotify;
            Current          = null;
            DbPersistance.Current.Save(this);

            Scheduler.Current.Put(new ChainExecuter(currentChain, state));
        }
예제 #2
0
        protected void ExecuteChainAndWait(PassiveAction chainable, ChainCallback routeCallback)
        {
            if (Current != null)
            {
                throw new Exception("Previous chain action has not yet completed");
            }

            chainable.IsChain   = true;
            chainable.OnNotify += ChainNotify;
            chainCallback       = routeCallback;

            Current = chainable;
            Current.WorkerObject      = WorkerObject;
            Current.ActionId          = ActionIdGenerator.GetNext();
            Current.ActionIdGenerator = ActionIdGenerator;
            Current.Location          = Location;

            DbPersistance.Current.Save(this);
            chainable.StateChange(chainable.Execute() == Error.Ok ? ActionState.Started : ActionState.Failed);

            StateChange(ActionState.Rescheduled);
        }