Example #1
0
        /// <inheritdoc/>
        public void RunRound(IUserinterface ui, IAction playerAction)
        {
            if (Player.Dead)
            {
                ui.ShowMessage("Dead", "Alas you are too dead to do that");
                return;
            }

            //get fresh round logs
            ui.Log.RoundResults.Clear();

            var stack     = new ActionStack();
            var actionRun = stack.RunStack(this, ui, playerAction, Player, GetAllBehaviours());

            if (actionRun)
            {
                RunNpcActions(stack, ui);

                foreach (IBehaviour b in GetAllBehaviours())
                {
                    b.OnRoundEnding(this, ui, stack.Round);
                }

                var results = GetPlayerVisibleLogResults(ui).ToArray();
                if (results.Any())
                {
                    ui.ShowMessage("Round Results", string.Join("\n", results));
                }
            }
        }
Example #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()));
                }
            }
        }