Example #1
0
        public Error Cancel(uint id)
        {
            ActiveAction activeAction;

            if (ActiveActions.TryGetValue(id, out activeAction) && !activeAction.IsDone)
            {
                var actionRequirements =
                    Ioc.Kernel.Get <ActionRequirementFactory>().GetActionRequirementRecord(activeAction.WorkerType);
                var actionRequirement = actionRequirements.List.FirstOrDefault(x => x.Index == activeAction.WorkerIndex);
                if (actionRequirement == null ||
                    (actionRequirement.Option & ActionOption.Uncancelable) == ActionOption.Uncancelable)
                {
                    return(Error.ActionUncancelable);
                }

                ThreadPool.QueueUserWorkItem(ActiveCancelCallback, activeAction);
                return(Error.Ok);
            }

            PassiveAction passiveAction;

            if (PassiveActions.TryGetValue(id, out passiveAction) && !passiveAction.IsDone)
            {
                if (!passiveAction.IsCancellable)
                {
                    return(Error.ActionUncancelable);
                }

                ThreadPool.QueueUserWorkItem(PassiveCancelCallback, passiveAction);
                return(Error.Ok);
            }

            return(Error.ActionNotFound);
        }
Example #2
0
        public bool Contains(GameAction action)
        {
            if (action is ActiveAction)
            {
                return(ActiveActions.ContainsKey(action.ActionId));
            }

            if (action is PassiveAction)
            {
                return(PassiveActions.ContainsKey(action.ActionId));
            }

            return(false);
        }