Exemple #1
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);
        }
Exemple #2
0
        public override ActivityStep ResolveStep(GameEntity entity)
        {
            ActivityStep stepFromSubActivity = _subactivity.CheckAndResolveStep(entity);

            if (stepFromSubActivity.State == ActivityState.FinishedSuccess)
            {
                if (_activityEnumerator.MoveNext())
                {
                    _subactivity = _activityEnumerator.Current;

                    return(new ActivityStep
                    {
                        State = ActivityState.InProgress,
                        GameAction = stepFromSubActivity.GameAction
                    });
                }
            }

            return(stepFromSubActivity);
        }
Exemple #3
0
        public override ActivityStep ResolveStep(GameEntity entity)
        {
            if (_itemToTake.held.ParentEntity != Guid.Empty)
            {
                return(Fail(entity));
            }

            if (entity.position.Position != _itemToTake.position.Position)
            {
                return(_goToActivity.CheckAndResolveStep(entity));
            }

            IGameAction pickUpAction = _actionFactory.CreatePickUpAction(_itemToTake, entity);

            return(new ActivityStep
            {
                State = ActivityState.FinishedSuccess,
                GameAction = pickUpAction
            });
        }
        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);
        }
Exemple #5
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);
        }