Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #3
0
        public void LoadFromDatabase(uint id,
                                     string chainCallback,
                                     PassiveAction current,
                                     ActionState chainState,
                                     bool isVisible)
        {
            ActionId        = id;
            this.chainState = chainState;
            Current         = current;
            IsVisible       = isVisible;

            //set the chain callback through reflection. The chain callback method should always exist in this class
            if (chainCallback != string.Empty)
            {
                this.chainCallback =
                    (ChainCallback)Delegate.CreateDelegate(typeof(ChainCallback), this, chainCallback, true);
            }

            switch (chainState)
            {
            case ActionState.Completed:
            case ActionState.Failed:
                Scheduler.Current.Put(new ChainExecuter(this.chainCallback, chainState));
                break;

            default:
                current.IsChain   = true;
                current.OnNotify += ChainNotify;

                ScheduledPassiveAction scheduledPassiveAction = current as ScheduledPassiveAction;
                if (scheduledPassiveAction != null)
                {
                    Scheduler.Current.Put(scheduledPassiveAction);
                }

                break;
            }
        }