Esempio n. 1
0
        public override void Initialize(EntityProperties properties, JsonObject aiconfig)
        {
            if (!(entity is EntityAgent))
            {
                entity.World.Logger.Error("The goal ai currently only works on entities inheriting from EntityAgent. Will ignore loading goals for entity {0} ", entity.Code);
                return;
            }

            PathTraverser = new StraightLineTraverser(entity as EntityAgent);

            JsonObject[] goals = aiconfig["aigoals"]?.AsArray();
            if (goals == null)
            {
                return;
            }

            foreach (JsonObject goalConfig in goals)
            {
                string goalCode = goalConfig["code"]?.AsString();
                Type   goalType = null;
                if (!AiGoalRegistry.GoalTypes.TryGetValue(goalCode, out goalType))
                {
                    entity.World.Logger.Error("Goal with code {0} for entity {1} does not exist. Ignoring.", goalCode, entity.Code);
                    continue;
                }

                AiGoalBase goal = (AiGoalBase)Activator.CreateInstance(goalType, (EntityAgent)entity);
                goal.LoadConfig(goalConfig, aiconfig);

                goalManager.AddGoal(goal);
            }
        }
Esempio n. 2
0
        public override void Initialize(EntityProperties properties, JsonObject aiconfig)
        {
            if (!(entity is EntityAgent))
            {
                entity.World.Logger.Error("The task ai currently only works on entities inheriting from EntityAgent. Will ignore loading tasks for entity {0} ", entity.Code);
                return;
            }

            //PathTraverser = new StraightLineTraverser(entity as EntityAgent);
            PathTraverser = new WaypointsTraverser(entity as EntityAgent);

            JsonObject[] tasks = aiconfig["aitasks"]?.AsArray();
            if (tasks == null)
            {
                return;
            }

            foreach (JsonObject taskConfig in tasks)
            {
                string taskCode = taskConfig["code"]?.AsString();
                Type   taskType = null;
                if (!AiTaskRegistry.TaskTypes.TryGetValue(taskCode, out taskType))
                {
                    entity.World.Logger.Error("Task with code {0} for entity {1} does not exist. Ignoring.", taskCode, entity.Code);
                    continue;
                }

                IAiTask task = (IAiTask)Activator.CreateInstance(taskType, (EntityAgent)entity);
                task.LoadConfig(taskConfig, aiconfig);

                taskManager.AddTask(task);
            }
        }
        public AiActionBase(EntityAgent entity)
        {
            this.entity = entity;
            this.world  = entity.World;
            rand        = new Random((int)entity.EntityId);

            this.pathTraverser = entity.GetBehavior <EntityBehaviorTaskAI>().PathTraverser;
        }
Esempio n. 4
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            base.Initialize(properties, api, InChunkIndex3d);

            pathTraverser = new StraightLinePathTraverser(this);
        }