Esempio n. 1
0
        public void Notice(GameEntity noticedEntity, StimulusDefinition stimulus, GameEntity entity, bool noticingEnemy)
        {
            HashSet <Guid> entitiesSeen = entity.vision.EntitiesNoticed;

            entitiesSeen.Add(noticedEntity.id.Id);
            entity.ReplaceVision(entity.vision.VisionRange, entity.vision.PerceptionRange, entitiesSeen);

            if (noticingEnemy && entity.hasAware)
            {
                entity.ReplaceAware(int.MaxValue);
            }

            IActivity activityFromReaction = _activityResolver.ResolveNewActivityForActorIfApplicable(stimulus, noticedEntity, entity);

            if (activityFromReaction == null)
            {
                return;
            }

            if (entity.hasActivity)
            {
                _activityInterruptor.FailAndReplace(entity, entity.activity.Activity, activityFromReaction);
            }
            else
            {
                entity.AddActivity(activityFromReaction);
            }
        }
Esempio n. 2
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);
        }