예제 #1
0
        public Error DoActive(int workerType, IGameObject workerObject, ActiveAction action, IHasEffect effects)
        {
            if (workerObject.IsBlocked > 0)
            {
                return(Error.ObjectNotFound);
            }

            uint actionId = actionIdGen.GetNext();

            ActionRequirementFactory.ActionRecord record =
                Ioc.Kernel.Get <ActionRequirementFactory>().GetActionRequirementRecord(workerType);

            if (record == null)
            {
                return(Error.ActionNotFound);
            }

            foreach (var actionReq in record.List.Where(x => x.Type == action.Type))
            {
                var error = action.Validate(actionReq.Parms);

                if (error != Error.Ok)
                {
                    if (error != Error.ActionInvalid)
                    {
                        return(error);
                    }

                    continue;
                }

                if (!CanDoActiveAction(action, actionReq, workerObject))
                {
                    return(Error.ActionTotalMaxReached);
                }

                error =
                    Ioc.Kernel.Get <EffectRequirementFactory>()
                    .GetEffectRequirementContainer(actionReq.EffectReqId)
                    .Validate(workerObject, effects.GetAllEffects(actionReq.EffectReqInherit), requirementFormula);

                if (error != Error.Ok)
                {
                    return(error);
                }

                SetActiveActionParams(action);

                action.ActionId     = actionId;
                action.WorkerIndex  = actionReq.Index;
                action.WorkerType   = workerType;
                action.WorkerObject = workerObject;
                active.Add(action.ActionId, action);

                Error ret = action.Execute();

                if (ret != Error.Ok)
                {
                    action.StateChange(ActionState.Failed);
                    active.Remove(action.ActionId);
                    actionIdGen.Release(action.ActionId);
                }
                else
                {
                    action.StateChange(ActionState.Started);
                }

                return(ret);
            }

            return(Error.ActionInvalid);
        }