Exemple #1
0
        public Outcome Compile(int maxTime)
        {
            if (compiled != null)
            {
                return(compiled);
            }

            compiled = new Outcome();

            IfEvent checkTime = new IfEvent();

            compiled.outcomeEvents.Add(checkTime);

            ConditionOutcome tooSoon = new ConditionOutcome();

            checkTime.outcomes.Add(tooSoon);

            ResourceCondition condition = new ResourceCondition();

            condition.resource   = Resource.Time;
            condition.comparison = Comparison.LessThan;
            condition.value      = maxTime;
            tooSoon.condition1   = condition;

            TextEvent sayTooSoon = new TextEvent();

            sayTooSoon.text = "The day isn't over yet. Come back to sleep when it's night time.";
            tooSoon.outcomeEvents.Add(sayTooSoon);

            EndScenarioEvent end = new EndScenarioEvent();

            tooSoon.outcomeEvents.Add(end);

            TextChoiceEvent choice = new TextChoiceEvent();

            choice.prompt = "Sleep?";
            if (cost != 0)
            {
                choice.prompt += " (" + cost + " $dollars per night)";
            }
            compiled.outcomeEvents.Add(choice);

            Choice yes = new Choice();

            yes.text = "Yes";
            choice.choices.Add(yes);

            Choice no = new Choice();

            no.text = "No";
            choice.choices.Add(no);

            SleepEvent sleep = new SleepEvent();

            sleep.decision = false;
            sleep.cost     = cost;
            yes.outcomeEvents.Add(sleep);

            return(compiled);
        }
Exemple #2
0
        public Outcome Compile()
        {
            if (compiled != null)
            {
                return(compiled);
            }

            List <StoryEvent> events = new List <StoryEvent>();

            TextEvent prompt = new TextEvent();

            prompt.text          = intro;
            prompt.speaker.Value = speaker;
            events.Add(prompt);

            List <StoryEvent> buyEvents  = new List <StoryEvent>();
            List <StoryEvent> sellEvents = new List <StoryEvent>();

            buyEvents.Add(compileTrades(buying, true, prompt));
            sellEvents.Add(compileTrades(selling, false, prompt));

            if (buying.Count == 0)
            {
                events.AddRange(sellEvents);
            }
            else if (selling.Count == 0)
            {
                events.AddRange(buyEvents);
            }
            else
            {
                TextChoiceEvent buyOrSell = new TextChoiceEvent();
                buyOrSell.prompt = "What would you like to do?";
                events.Add(buyOrSell);

                Choice buy = new Choice();
                buy.text = "I'd like to buy.";
                buy.outcomeEvents.AddRange(buyEvents);
                buy.meetAllConditions = false;
                buy.conditions.AddRange(buying.Select(trade => trade.MakeCondition(true)));
                buyOrSell.choices.Add(buy);

                Choice sell = new Choice();
                sell.text = "I'd like to sell.";
                sell.outcomeEvents.AddRange(sellEvents);
                sell.meetAllConditions = false;
                sell.conditions.AddRange(buying.Select(trade => trade.MakeCondition(false)));
                buyOrSell.choices.Add(sell);

                Choice back = new Choice();
                back.text = "Nevermind.";
                buyOrSell.choices.Add(back);
            }


            return(compiled = new ShopOutcome(events));
        }
Exemple #3
0
        private StoryEvent compileTrades(List <Trade> trades, bool buying, StoryEvent restart)
        {
            TextChoiceEvent choiceEvent = new TextChoiceEvent();

            choiceEvent.prompt = "What would you like to " + (buying ? "buy" : "sell") + "?";

            foreach (Trade trade in trades)
            {
                Choice choice = new Choice();
                choice.text = trade.MakeChoice(buying);
                choice.conditions.Add(trade.MakeCondition(buying));
                choiceEvent.choices.Add(choice);

                IfEvent checkQuantity = new IfEvent();
                choice.outcomeEvents.Add(checkQuantity);

                ConditionOutcome limitReachedOutcome = new ConditionOutcome();
                limitReachedOutcome.condition1      = new CanTradeCondition(trade, true);
                limitReachedOutcome.nextEvent.Value = choiceEvent;
                checkQuantity.outcomes.Add(limitReachedOutcome);

                TextEvent soldOut = new TextEvent();
                soldOut.speaker.Value = speaker;
                soldOut.text          = buying ? "I'm sorry, I'm all sold out of that." : "I'm sorry, I think I have enough of that.";
                if (trades.Count > 1)
                {
                    soldOut.text += " Maybe something else?";
                }
                limitReachedOutcome.outcomeEvents.Add(soldOut);

                ConditionOutcome enoughOutcome = new ConditionOutcome();
                enoughOutcome.condition1 = new CanTradeCondition(trade, false);
                checkQuantity.outcomes.Add(enoughOutcome);

                TextChoiceEvent tradeChoice = new TextChoiceEvent();
                tradeChoice.prompt = trade.prompt;
                enoughOutcome.outcomeEvents.Add(tradeChoice);

                Choice accept = new Choice();
                accept.text = trade.acceptResponse;
                tradeChoice.choices.Add(accept);

                accept.outcomeEvents.AddRange(trade.MakeOutcomes(buying));
                if (!String.IsNullOrEmpty(thanks))
                {
                    TextEvent acceptMessage = new TextEvent();
                    acceptMessage.text          = thanks;
                    acceptMessage.speaker.Value = speaker;
                    accept.outcomeEvents.Add(acceptMessage);
                }
                accept.nextEvent.Value = choiceEvent;

                Choice decline = new Choice();
                decline.text = trade.declineResponse;
                tradeChoice.choices.Add(decline);

                Choice backToTrade = new Choice();
                backToTrade.text            = "Maybe another item...";
                backToTrade.nextEvent.Value = choiceEvent;
                tradeChoice.choices.Add(backToTrade);
            }

            Choice back = new Choice();

            back.text = "On second thought, nevermind.";
            choiceEvent.choices.Add(back);

            return(choiceEvent);
        }