Exemplo n.º 1
0
 public static void RegisterEvent(string appCode, EventStep step, ActivityStep type, Func <IWorkflowContext, IActivity, bool> predicate)
 {
     if (predicate != null)
     {
         string key = KeyTemplate.FormatTo(step.ToString(), type.ToString());
         EntityEventList.Add(key, predicate);
     }
 }
Exemplo n.º 2
0
        private ACL_Data_Contract.ActivityData GetTestScriptStep(ObservableList <ActivityIdentifiers> stepList)
        {
            ActivityData ad      = new ActivityData();
            int          orderID = 0;

            foreach (ActivityIdentifiers actIden in stepList)
            {
                ActivityStep activityStep = new ActivityStep();
                if (!string.IsNullOrEmpty(actIden.ExternalID))
                {
                    try
                    {
                        long rqmID = Convert.ToInt64(GetExportedIDString(actIden.ExternalID, "RQMID"));
                        //getExportID(actIden.ExternalID);
                        if (rqmID != 0)
                        {
                            activityStep.ExportedID    = rqmID;
                            activityStep.ShouldUpdated = true;
                        }
                    }
                    catch (Exception e)
                    {
                        activityStep.ShouldUpdated = false;
                        Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}");
                    }
                }

                if (actIden == null || actIden.IdentifiedActivity == null)
                {
                    Reporter.ToLog(eLogLevel.ERROR, "Error: When Exporting to RQM, ActivityIdentifiers object or actIden.IdentifiedActivity is null and cannot export to RQM");
                    break;
                }

                activityStep.EntityName = actIden.ActivityName;
                string description = actIden.ActivityDescription == null ? string.Empty : actIden.ActivityDescription;
                activityStep.StepExpResults = actIden.IdentifiedActivity.Expected;
                activityStep.StepOrderId    = orderID;
                orderID++;
                activityStep.EntityId = 0;

                foreach (GingerCore.Variables.VariableBase variable in actIden.IdentifiedActivity.Variables)
                {
                    ActivityParam param = new ActivityParam();
                    param.EntityName   = variable.FileName;
                    param.DefaultValue = variable.Value;
                    //param. //Add automation status to param
                    ad.ActivityParamsColl.Add(param);
                    description = description + GetVariableWithSigns(variable.FileName, variable.Value);
                }
                activityStep.EntityDesc = description;
                ad.ActivityStepsColl.Add(activityStep);
            }
            return(ad);
        }
Exemplo n.º 3
0
        public static ActivityStep GetBitOr()
        {
            var          steps  = Enum.GetValues(typeof(ActivityStep)) as ActivityStep[];
            ActivityStep result = ActivityStep.None;

            foreach (var step in steps)
            {
                result |= step;
            }
            return(result);
        }
Exemplo n.º 4
0
        public override bool CanBuildStep(ActivityStep activityStep)
        {
            switch (activityStep)
            {
            case ActivityStep.StationPlanning:
                return(false);

            default:
                return(true);
            }
        }
Exemplo n.º 5
0
        public virtual bool CanBuildStep(ActivityStep activityStep)
        {
            switch (activityStep)
            {
            case ActivityStep.FreqPlanning:
            case ActivityStep.StationPlanning:
                return(false);

            default:
                return(true);
            }
        }
        private bool GetUI(ActivityStep step)
        {
            var uiFactory = Utility.GetUIFactory();

            if (uiFactory != null)
            {
                var uiBuilder = uiFactory.GetUIBuilder(RiasPortal.ModuleContainer.Activity.ActivityType);
                if (uiBuilder.CanBuildStep(step))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        public IGameAction GetAction(GameEntity entity)
        {
            // todo: remove this and use BlockedUntil. But for sure? Maybe this check is better?
            // now it causes problems when an animating actor is leaving sight (animation doesn't finish -> infinite loop)
            if (entity.view.Controller.Animator.IsAnimating)
            {
                return(null);
            }

            if (entity.hasPreparedAction)
            {
                IGameAction actionToReturn = entity.preparedAction.Action;
                entity.RemovePreparedAction();
                return(actionToReturn);
            }

            if (!entity.hasActivity)
            {
                float score;
                Skill skill = _utilityAi.ResolveSkillWhenIdle(out score, entity);

                Activity newActivity;
                try
                {
                    newActivity = skill.ActivityCreator.CreateActivity(_activityCreationContext, score, null, entity);
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message + ", stack trace: " + e.StackTrace);
                    newActivity = new WaitActivity(_actionFactory, 2, "Wait");
                }
                entity.AddActivity(newActivity);
                newActivity.OnStart(entity);
            }

            IActivity    activity     = entity.activity.Activity;
            ActivityStep activityStep = activity.CheckAndResolveStep(entity);

            if (activityStep.State == ActivityState.FinishedSuccess || activityStep.State == ActivityState.FinishedFailure)
            {
                entity.RemoveActivity();
            }

            IGameAction actionFromActivity = activityStep.GameAction;

            return(actionFromActivity);
        }
Exemplo n.º 8
0
        private static Job CreateJob(int column = 2, int row = 2)
        {
            var steps = new ActivityStep[1] {
                new DigStep(column, row)
            };
            var activities = new Activity[1] {
                new Activity(steps)
            };
            var job = new Job(
                JobManager.Medium,
                activities,
                0,
                JobState.Pending
                );

            return(job);
        }
Exemplo n.º 9
0
        public static bool RaiseEvent(EventStep step, ActivityStep type, IWorkflowContext context, IActivity activity)
        {
            string key = KeyTemplate.FormatTo(step.ToString(), type.ToString());

            if (EntityEventList.ContainsKey(key))
            {
                Logger.GetLogger("Workflow").Info("{0}:Raise WorkflowEvent:{1}".FormatTo(context.FlowInstance.Id, key));
                try
                {
                    return(EntityEventList[key](context, activity));
                }
                catch (Exception ex)
                {
                    Logger.GetLogger("Workflow").Info("{0}:Raise WorkflowEvent:{1} Error:{2},{3}".FormatTo(context.FlowInstance.Id, key, ex.Message, ex.StackTrace));
                }
            }
            return(true);
        }
Exemplo n.º 10
0
        private void StartPathing(IMap map, Job job, IJobFit[] fits)
        {
#if DEBUG
            Debug.WriteLine("JobManager:StartPathing");
#endif

            if (fits.Length > _foundRoutes.Length)
            {
                _foundRoutes = new Route[fits.Length];
                _fitness     = new int[fits.Length];
            }
            _pendingRoutes = fits.Length;

            for (int i = 0; i < fits.Length; i++)
            {
                IJobFit      fit      = fits[i];
                Activity     activity = job.Activities[0];
                ActivityStep step     = activity.Steps[0];
                ref MapCell  location = ref map.GetCell(fit.LocationColumn, fit.LocationRow);
                ref MapCell  target   = ref map.GetCell(step.Column, step.Row);
Exemplo n.º 11
0
        public override ActivityStep ResolveStep(GameEntity entity)
        {
            if (_followStepsActivity != null)
            {
                ActivityStep goToResult = _followStepsActivity.CheckAndResolveStep(entity);
                if (goToResult.State != ActivityState.FinishedFailure)
                {
                    return(goToResult);
                }
            }

            int escapeFloodRange = entity.vision.VisionRange;
            int allowedDelay     = 3;

            IFloodArea enemyFlood = _calculatedAreaAccessor.FetchWalkableFlood(_floodSource, escapeFloodRange);

            Position startingPosition       = entity.position.Position;
            bool     standingOutsideOfFlood = enemyFlood.GetValueAtPosition(startingPosition) == int.MaxValue;

            if (standingOutsideOfFlood)
            {
                return(new ActivityStep
                {
                    GameAction = _actionFactory.CreatePassAction(entity),
                    State = ActivityState.InProgress
                });
            }
            Position         targetPosition;
            var              predecessors = FindBestPositionInFloodToFleeTo(entity, startingPosition, allowedDelay, enemyFlood, out targetPosition);
            Stack <Position> steps        = new Stack <Position>();

            CreateStepsStack(targetPosition, steps, predecessors);
            if (!steps.Any())
            {
                Debug.LogError($"can't find best flood position starting at {startingPosition}.");
            }

            _followStepsActivity = new FollowStepsActivity(_actionFactory, steps, "Run away — steps");

            return(_followStepsActivity.CheckAndResolveStep(entity));
        }
Exemplo n.º 12
0
 private void VoidExecute(ActivityStep step, Action <IWorkflowContext> action, IWorkflowContext context, IActivity activity)
 {
     WorkflowEventManager.RaiseEvent(EventStep.Before, step, context, activity);
     action(context);
     WorkflowEventManager.RaiseEvent(EventStep.After, step, context, activity);
 }
Exemplo n.º 13
0
 public virtual bool CanBuildStep(ActivityStep activityStep)
 {
     return(activityStep != ActivityStep.None);
 }
Exemplo n.º 14
0
        public IGameAction GetAction(GameEntity entity)
        {
            // todo: remove this and use BlockedUntil. But for sure? Maybe this check is better?
            // now it may cause problems when an animating actor is leaving sight (animation doesn't finish -> infinite loop)
            if (entity.view.Controller.Animator.IsAnimating)
            {
                return(null);
            }

            if (entity.hasPreparedAction)
            {
                IGameAction actionToReturn = entity.preparedAction.Action;
                entity.RemovePreparedAction();
                return(actionToReturn);
            }

            (Skill skill, float score)newSkillAndScore = default;
            if (entity.hasActivity && entity.hasSkills && entity.hasStimuli)
            {
                List <Stimulus> stimuliReceived = entity.stimuli.Stimuli.ToList();

                newSkillAndScore = _activityResolver.ResolveNewSkillIfApplicable(entity, stimuliReceived);
            }
            else if (!entity.hasActivity)
            {
                newSkillAndScore = _utilityAi.ResolveSkillWhenIdle(entity);
            }

            if (newSkillAndScore.skill != null)
            {
                Activity newActivity;
                try
                {
                    newActivity = newSkillAndScore.skill.ActivityCreator.CreateActivity(_activityCreationContext, newSkillAndScore.score, null, entity);
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message + ", stack trace: " + e.StackTrace);
                    newActivity = new WaitActivity(_actionFactory, 2, "Wait");
                }

                if (entity.hasActivity)
                {
                    entity.activity.Activity.OnFailure(entity);
                }
                entity.ReplaceActivity(newActivity);
                newActivity.OnStart(entity);
            }

            IActivity    activity     = entity.activity.Activity;
            ActivityStep activityStep = activity.CheckAndResolveStep(entity);

            if (activityStep.State == ActivityState.FinishedSuccess || activityStep.State == ActivityState.FinishedFailure)
            {
                entity.RemoveActivity();
            }

            IGameAction actionFromActivity = activityStep.GameAction;

            return(actionFromActivity);
        }
Exemplo n.º 15
0
        public IGameAction GetAction(GameEntity entity)
        {
            IGameAction gameActionToReturn = null;

            IActivity activity = entity.hasActivity ? entity.activity.Activity : null;

            if (activity != null)
            {
                ActivityStep activityStep = activity.CheckAndResolveStep(entity);

                if (activityStep.State == ActivityState.FinishedSuccess)
                {
                }
                else if (activityStep.State == ActivityState.FinishedFailure)
                {
                    _activityInterruptor.FailAndReplace(entity, null);
                }
                return(activityStep.GameAction);
            }

            Decision decision = _context.playerDecision.Decision;

            if (decision == Decision.None)
            {
                return(null);
            }

            if (decision == Decision.PickUp)
            {
                gameActionToReturn = ResolveForPickUp(entity);
            }
            else if (decision == Decision.Drop)
            {
                gameActionToReturn = ResolveForDrop(entity);
            }
            else if (decision == Decision.Eat)
            {
                gameActionToReturn = ResolveForEat(entity);
            }
            else if (decision == Decision.Pass)
            {
                gameActionToReturn = _actionFactory.CreatePassAction(entity);
            }
            // todo clean this up

            /*else if (decision == Decision.TakeItem1)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 0);
             * }
             * else if (decision == Decision.TakeItem2)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 1);
             * }
             * else if (decision == Decision.TakeItem3)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 2);
             * }
             * else if (decision == Decision.TakeItem4)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 3);
             * }
             * else if (decision == Decision.TakeItem5)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 4);
             * }
             * else if (decision == Decision.TakeItem6)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 5);
             * }
             * else if (decision == Decision.TakeItem7)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 6);
             * }
             * else if (decision == Decision.TakeItem8)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 7);
             * }
             * else if (decision == Decision.TakeItem9)
             * {
             *      gameActionToReturn = CreateTakeFromInventoryActionIfPossible(entity, 8);
             * }*/
            else if (_moveInputs.Contains(decision))
            {
                gameActionToReturn = ResolveForMove(entity, decision);
            }
            else if (decision == Decision.Custom0)
            {
                gameActionToReturn = _actionFactory.CreateLambdaAction(
                    targetEntity =>
                {
                    targetEntity.ReplaceIntegrity(targetEntity.integrity.MaxIntegrity, targetEntity.integrity.MaxIntegrity);
                    return(Enumerable.Empty <IActionEffect>());
                }, entity);
            }
            else if (decision == Decision.Custom1)
            {
                gameActionToReturn = _actionFactory.CreateLambdaAction(actionEntity =>
                {
                    throw new Exception("test pawła 2");
                }, entity);
            }
            else if (decision == Decision.Custom2)
            {
                gameActionToReturn = ResolveForAlphaNumber(2, entity);
            }
            else if (decision == Decision.Custom3)
            {
                gameActionToReturn = ResolveForAlphaNumber(3, entity);
            }
            else if (decision == Decision.Custom4)
            {
                gameActionToReturn = ResolveForAlphaNumber(4, entity);
            }
            else if (decision == Decision.Custom5)
            {
                gameActionToReturn = ResolveForAlphaNumber(5, entity);
            }

            if (gameActionToReturn != null)
            {
                _context.ReplacePlayerDecision(Decision.None, Position.Zero, Position.MinValue);
            }

            return(gameActionToReturn);
        }