Example #1
0
 private IEnumerable <SpeechNode> AskAQuestion()
 {
     yield return(new SpeechNode()
     {
         Text = "Ask...",
         Actions = new List <SpeechNode.SpeechAction>()
         {
             new SpeechNode.SpeechAction()
             {
                 Text = "What do you think of us?",
                 Action = WhatDoYouThink
             },
             new SpeechNode.SpeechAction()
             {
                 Text = "What's the news?",
                 Action = WhatsTheNews
             },
             new SpeechNode.SpeechAction()
             {
                 Text = "What goods do you want?",
                 Action = WhatGoods
             },
             new SpeechNode.SpeechAction()
             {
                 Text = "Nevermind",
                 Action = () => SpeechNode.Echo(DialougeTree)
             }
         }
     });
 }
Example #2
0
        private IEnumerable <SpeechNode> WhatDoYouThink()
        {
            Diplomacy.Politics p            = World.ComponentManager.Diplomacy.GetPolitics(Faction, PlayerFation);
            Relationship       r            = p.GetCurrentRelationship();
            string             relationship = "So far, our relationship has been " + r;

            if (p.RecentEvents.Count > 0)
            {
                relationship += ", because ";
                List <string> events = p.RecentEvents.Select(e => e.Description).ToList();
                relationship += TextGenerator.GetListString(events);
            }

            relationship += ".";
            yield return(new SpeechNode()
            {
                Text = relationship,
                Actions = new List <SpeechNode.SpeechAction>()
                {
                    new SpeechNode.SpeechAction()
                    {
                        Text = "Interesting",
                        Action = () => SpeechNode.Echo(DialougeTree)
                    }
                }
            });
        }
Example #3
0
        private IEnumerable <SpeechNode> CommonGoods()
        {
            string goods = "We already have a lot of ";

            List <string> goodList = Faction.Race.CommonResources.Select(tags => tags.ToString()).ToList();

            goods += TextGenerator.GetListString(goodList);
            goods += " things";

            goods   += ". We don't have many ";
            goodList = Faction.Race.RareResources.Select(tags => tags.ToString()).ToList();
            goods   += TextGenerator.GetListString(goodList);
            goods   += " goods";
            goods   += ".";

            yield return(new SpeechNode()
            {
                Text = goods,
                Actions = new List <SpeechNode.SpeechAction>()
                {
                    new SpeechNode.SpeechAction()
                    {
                        Text = "OK",
                        Action = () => SpeechNode.Echo(DialougeTree)
                    }
                }
            });
        }
Example #4
0
        private IEnumerable <SpeechNode> WhatGoods()
        {
            string goods = "We desire ";

            List <string> goodList = Faction.Race.LikedResources.Select(tags => tags.ToString()).ToList();

            goods += TextGenerator.GetListString(goodList);
            goods += " items";

            if (Faction.Race.HatedResources.Any())
            {
                goods   += ". But we find ";
                goodList = Faction.Race.HatedResources.Select(tags => tags.ToString()).ToList();
                goods   += TextGenerator.GetListString(goodList);
                goods   += " items offensive";
            }
            goods += ".";

            yield return(new SpeechNode()
            {
                Text = goods,
                Actions = new List <SpeechNode.SpeechAction>()
                {
                    new SpeechNode.SpeechAction()
                    {
                        Text = "Interesting",
                        Action = () => SpeechNode.Echo(DialougeTree)
                    }
                }
            });
        }
Example #5
0
 public void Transition(SpeechNode node)
 {
     CurrentNode = node;
     Talker.Say(node.Text);
     DialougeSelector.ClearItems();
     foreach (SpeechNode.SpeechAction action in node.Actions)
     {
         DialougeSelector.AddItem(action.Text);
     }
 }
Example #6
0
 private IEnumerable <SpeechNode> WhatsTheNews()
 {
     yield return(new SpeechNode()
     {
         Text = "The world is the same as ever.",
         Actions = new List <SpeechNode.SpeechAction>()
         {
             new SpeechNode.SpeechAction()
             {
                 Text = "Interesting",
                 Action = () => SpeechNode.Echo(DialougeTree)
             }
         }
     });
 }
Example #7
0
        public override void Update(DwarfTime gameTime)
        {
            CompositeLibrary.Update();
            MainWindow.LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2);
            Input.Update();
            GUI.Update(gameTime);

            if (CurrentAction != null)
            {
                if (CurrentCoroutine == null)
                {
                    CurrentCoroutine  = CurrentAction.Action();
                    CurrentEnumerator = CurrentCoroutine.GetEnumerator();
                }

                if (CurrentCoroutine != null)
                {
                    SpeechNode node = CurrentEnumerator.Current;

                    if (node != null)
                    {
                        Transition(node);
                        CurrentCoroutine = null;
                        CurrentAction    = null;
                    }
                    else
                    {
                        if (!CurrentEnumerator.MoveNext())
                        {
                            CurrentCoroutine  = null;
                            CurrentAction     = null;
                            CurrentEnumerator = null;
                            Transition(DialougeTree);
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
Example #8
0
        void Initialize()
        {
            Envoy.TradeMoney = Faction.TradeMoney + MathFunctions.Rand(-100.0f, 100.0f);
            Envoy.TradeMoney = Math.Max(Envoy.TradeMoney, 0.0f);
            TalkerName       = TextGenerator.GenerateRandom(Datastructures.SelectRandom(Faction.Race.NameTemplates).ToArray());
            Tabs             = new Dictionary <string, GUIComponent>();
            GUI = new DwarfGUI(Game, Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Default),
                               Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Title),
                               Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Small), Input)
            {
                DebugDraw = false
            };
            IsInitialized = true;
            MainWindow    = new GUIComponent(GUI, GUI.RootComponent)
            {
                LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2)
            };

            Layout = new GridLayout(GUI, MainWindow, 11, 4);
            Layout.UpdateSizes();

            Talker = new SpeakerComponent(GUI, Layout, new Animation(Faction.Race.TalkAnimation));
            Layout.SetComponentPosition(Talker, 0, 0, 4, 4);

            DialougeSelector = new ListSelector(GUI, Layout)
            {
                Mode        = ListItem.SelectionMode.ButtonList,
                DrawButtons = true,
                DrawPanel   = false,
                Label       = "",
                ItemHeight  = 35,
                Padding     = 5
            };
            DialougeSelector.OnItemSelected += DialougeSelector_OnItemSelected;
            Layout.SetComponentPosition(DialougeSelector, 2, 3, 1, 8);

            BackButton = new Button(GUI, Layout, "Back", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.LeftArrow));
            Layout.SetComponentPosition(BackButton, 2, 10, 1, 1);
            BackButton.OnClicked += back_OnClicked;
            BackButton.IsVisible  = false;
            DialougeTree          = new SpeechNode()
            {
                Text    = GetGreeting(),
                Actions = new List <SpeechNode.SpeechAction>()
                {
                    new SpeechNode.SpeechAction()
                    {
                        Text   = "Trade...",
                        Action = WaitForTrade
                    },
                    new SpeechNode.SpeechAction()
                    {
                        Text   = "Ask a question...",
                        Action = AskAQuestion
                    },
                    new SpeechNode.SpeechAction()
                    {
                        Text   = "Declare war!",
                        Action = DeclareWar
                    },
                    new SpeechNode.SpeechAction()
                    {
                        Text   = "Leave",
                        Action = () =>
                        {
                            BackButton.IsVisible = true;
                            if (Envoy != null)
                            {
                                Diplomacy.RecallEnvoy(Envoy);
                            }
                            return(SpeechNode.Echo(new SpeechNode()
                            {
                                Text = GetFarewell(),
                                Actions = new List <SpeechNode.SpeechAction>()
                            }));
                        }
                    }
                }
            };


            if (Politics.WasAtWar)
            {
                PreeTree = new SpeechNode()
                {
                    Text    = Datastructures.SelectRandom(Faction.Race.Speech.PeaceDeclarations),
                    Actions = new List <SpeechNode.SpeechAction>()
                    {
                        new SpeechNode.SpeechAction()
                        {
                            Text   = "Make peace with " + Faction.Name,
                            Action = () =>
                            {
                                if (!Politics.HasEvent("you made peace with us"))
                                {
                                    Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                                    {
                                        Change      = 0.4f,
                                        Description = "you made peace with us",
                                        Duration    = new TimeSpan(4, 0, 0, 0),
                                        Time        = World.Time.CurrentDate
                                    });
                                }
                                return(SpeechNode.Echo(DialougeTree));
                            }
                        },
                        new SpeechNode.SpeechAction()
                        {
                            Text   = "Continue the war with " + Faction.Name,
                            Action = DeclareWar
                        }
                    }
                };
                Transition(PreeTree);
                Politics.WasAtWar = false;
            }
            else
            {
                Transition(DialougeTree);
            }


            if (!Politics.HasMet)
            {
                Politics.HasMet = true;

                Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                {
                    Change      = 0.0f,
                    Description = "we just met",
                    Duration    = new TimeSpan(1, 0, 0, 0),
                    Time        = World.Time.CurrentDate
                });
            }

            Layout.UpdateSizes();
            Talker.TweenIn(Drawer2D.Alignment.Top, 0.25f);
            DialougeSelector.TweenIn(Drawer2D.Alignment.Right, 0.25f);
        }
Example #9
0
        IEnumerable <SpeechNode> WaitForTrade()
        {
            TradeDialog dialog = TradeDialog.Popup(GUI, GUI.RootComponent, Faction, Resources);

            LastEvent        = null;
            dialog.OnTraded += dialog_OnClicked;



            while (LastEvent == null && dialog.IsVisible)
            {
                yield return(null);
            }

            if (LastEvent != null)
            {
                TradeEvent.Profit profit = LastEvent.GetProfit();

                if (LastEvent.IsHate() && !Politics.HasEvent("you tried to give us something offensive"))
                {
                    Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                    {
                        Change      = -0.25f,
                        Description = "you tried to give us something offensive",
                        Duration    = new TimeSpan(4, 0, 0, 0),
                        Time        = World.Time.CurrentDate
                    });
                }
                else if ((!LastEvent.IsHate() && LastEvent.IsLike()) && !Politics.HasEvent("you gave us something we liked"))
                {
                    Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                    {
                        Change      = 0.25f,
                        Description = "you gave us something we liked",
                        Duration    = new TimeSpan(4, 0, 0, 0),
                        Time        = World.Time.CurrentDate
                    });
                }

                if (profit.PercentProfit > 0.25f && !LastEvent.IsHate())
                {
                    DoTrade(LastEvent);

                    if (!Politics.HasEvent("we had profitable trade"))
                    {
                        Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                        {
                            Change      = 0.25f,
                            Description = "we had profitable trade",
                            Duration    = new TimeSpan(2, 0, 0, 0),
                            Time        = World.Time.CurrentDate
                        });
                    }

                    yield return(new SpeechNode()
                    {
                        Text = GetGoodTradeText(),
                        Actions = new List <SpeechNode.SpeechAction>()
                        {
                            new SpeechNode.SpeechAction()
                            {
                                Text = "Ok",
                                Action = () => SpeechNode.Echo(DialougeTree)
                            }
                        }
                    });
                }
                else
                {
                    yield return(new SpeechNode()
                    {
                        Text = GetBadTradeText(),
                        Actions = new List <SpeechNode.SpeechAction>()
                        {
                            new SpeechNode.SpeechAction()
                            {
                                Text = "Sorry.",
                                Action = () => SpeechNode.Echo(DialougeTree)
                            }
                        }
                    });
                }
                yield break;
            }
            else
            {
                yield return(DialougeTree);
            }
            yield break;
        }
Example #10
0
        public static IEnumerable <SpeechNode> Echo(SpeechNode other)
        {
            yield return(other);

            yield break;
        }
Example #11
0
 public static IEnumerable<SpeechNode> Echo(SpeechNode other)
 {
     yield return other;
     yield break;
 }
Example #12
0
        void Initialize()
        {
            TalkerName = TextGenerator.GenerateRandom(Datastructures.SelectRandom(Faction.Race.NameTemplates).ToArray());
            Tabs = new Dictionary<string, GUIComponent>();
            GUI = new DwarfGUI(Game, Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Default),
                Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Title),
                Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Small), Input)
            {
                DebugDraw = false
            };
            IsInitialized = true;
            Drawer = new Drawer2D(Game.Content, Game.GraphicsDevice);
            MainWindow = new Panel(GUI, GUI.RootComponent)
            {
                LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2)
            };

            Layout = new GridLayout(GUI, MainWindow, 11, 4);
            Layout.UpdateSizes();

            Talker = new SpeakerComponent(GUI, Layout, new Animation(Faction.Race.TalkAnimation));
            Layout.SetComponentPosition(Talker, 0, 0, 4, 4);

            DialougeSelector = new ListSelector(GUI, Layout)
            {
                Mode = ListItem.SelectionMode.ButtonList,
                DrawPanel = false,
                Label = ""
            };
            DialougeSelector.OnItemSelected += DialougeSelector_OnItemSelected;
            Layout.SetComponentPosition(DialougeSelector, 2, 2, 2, 10);

            Button back = new Button(GUI, Layout, "Back", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.LeftArrow));
            Layout.SetComponentPosition(back, 0, 10, 1, 1);
            back.OnClicked += back_OnClicked;

            DialougeTree = new SpeechNode()
            {
                Text = GetGreeting(),
                Actions = new List<SpeechNode.SpeechAction>()
                {
                    new SpeechNode.SpeechAction()
                    {
                        Text = "Let's trade.",
                        Action = WaitForTrade
                    },
                    new SpeechNode.SpeechAction()
                    {
                        Text = "Goodbye.",
                        Action = () => SpeechNode.Echo(new SpeechNode()
                        {
                            Text = GetFarewell(),
                            Actions = new List<SpeechNode.SpeechAction>()
                        })
                    }
                }
            };

            Transition(DialougeTree);
            Politics.HasMet = true;

            PlayerFation.AddResources(new ResourceAmount(ResourceLibrary.ResourceType.Mana, 64));
        }
Example #13
0
 public void Transition(SpeechNode node)
 {
     CurrentNode = node;
     Talker.Say(node.Text);
     DialougeSelector.ClearItems();
     foreach (SpeechNode.SpeechAction action in node.Actions)
     {
         DialougeSelector.AddItem("- " + action.Text);
     }
 }