Пример #1
0
        public virtual PlanningSystem GetPlanningSystem(IWorld world)
        {
            var defaultPlan = GetResource("plans.yaml");
            var planning    = new PlanningSystem();

            if (defaultPlan != null)
            {
                try
                {
                    var blueprints  = Compiler.Instance.Deserializer.Deserialize <PlanBlueprint[]>(defaultPlan.Content);
                    var planFactory = new PlanFactory();

                    foreach (var blue in blueprints)
                    {
                        planning.Plans.Add(planFactory.Create(blue));
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Error deserializing " + defaultPlan.Location, e);
                }
            }

            return(planning);
        }
Пример #2
0
        private void RunNpcActions(ActionStack stack, IUserinterface ui)
        {
            //use ToArray because people might blow up rooms or kill one another
            foreach (var npc in Population.OfType <Npc>().OrderByDescending(NpcOrder).ToArray())
            {
                //if occupant was killed by a previous action
                if (!Population.Contains(npc))
                {
                    continue;
                }

                //if npc is in an explored(ish) location
                if (!ShouldRunActionsIn(npc.CurrentLocation))
                {
                    return;
                }

                //if the npc has a cunning plan (and isn't being coerced)!
                if (npc.NextAction == null)
                {
                    //give the Npc a chance to form a plan
                    PlanningSystem.Apply(new SystemArgs(this, ui, 0, null, npc, stack.Round));

                    //if the Npc has decided what to do
                    if (npc.Plan != null)
                    {
                        stack.RunStack(this, ui, npc.Plan, Population.SelectMany(p => p.GetFinalBehaviours()));
                        continue;
                    }
                }


                if (npc.Decide(ui, "Pick Action", null, out IAction chosen, npc.GetFinalActions().ToArray(), 0))
                {
                    stack.RunStack(this, ui, chosen, npc, Population.SelectMany(p => p.GetFinalBehaviours()));
                }
            }
        }