private void UpdateLineItemText(Widget LineItem, ResourceAmount Resource) { var resourceInfo = ResourceLibrary.GetResourceByName(Resource.ResourceType); LineItem.GetChild(1).Text = resourceInfo.ShortName ?? resourceInfo.ResourceName; LineItem.GetChild(1).Invalidate(); LineItem.GetChild(2).Text = String.Format("{0}", ValueSourceEntity.ComputeValue(Resource.ResourceType)); var counter = LineItem.GetChild(0).Children.Last(); counter.Text = Resource.NumResources.ToString(); counter.Invalidate(); LineItem.GetChild(0).Invalidate(); LineItem.Tooltip = resourceInfo.ResourceName + "\n" + resourceInfo.Description; for (int i = 0; i < 3; i++) { if (i > 0) { LineItem.GetChild(i).TextColor = Resource.NumResources > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f); } LineItem.GetChild(i).BackgroundColor = Resource.NumResources > 0 ? resourceInfo.Tint.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f); LineItem.GetChild(i).Tooltip = resourceInfo.ResourceName + "\n" + resourceInfo.Description; LineItem.GetChild(i).Invalidate(); } }
private Widget CreateLineItem(ResourceAmount Resource) { var r = Root.ConstructWidget(new Gum.Widget { MinimumSize = new Point(1, 32), MaximumSize = new Point(1, 32) }); var resourceInfo = ResourceLibrary.GetResourceByName(Resource.ResourceType); r.AddChild(new Gum.Widget { MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Background = new TileReference("resources", resourceInfo.NewGuiSprite), AutoLayout = AutoLayout.DockLeft, BackgroundColor = resourceInfo.Tint.ToVector4() }); r.AddChild(new Gum.Widget { AutoLayout = AutoLayout.DockFill, //Text = String.Format("{0} at ${1}e", Resource.NumResources, resourceInfo.MoneyValue), //Font = "outline-font", //TextColor = new Vector4(1,1,1,1), TextVerticalAlign = VerticalAlign.Center }); UpdateLineItemText(r, Resource); return(r); }
// Aggregates resources by tags so that there aren't as many to display. private List <AggregatedResource> AggregateResources(IEnumerable <KeyValuePair <string, Pair <ResourceAmount> > > resources) { List <AggregatedResource> aggregated = new List <AggregatedResource>(); foreach (var pair in resources) { var resource = ResourceLibrary.GetResourceByName(pair.Value.First.ResourceType); var existing = aggregated.FirstOrDefault(existingResource => AreListsEqual(ResourceLibrary.GetResourceByName(existingResource.Amount.First.ResourceType).Tags, resource.Tags)); if (existing != null) { existing.Amount.First.NumResources += pair.Value.First.NumResources; existing.Amount.Second.NumResources += pair.Value.Second.NumResources; existing.Members.Add(String.Format("{0}x {1}", pair.Value.First.NumResources, pair.Value.First.ResourceType)); } else { aggregated.Add(new AggregatedResource() { Amount = pair.Value, Members = new List <string>() { String.Format("{0}x {1}", pair.Value.First.NumResources, pair.Value.First.ResourceType) } }); } } return(aggregated); }
private void MoveRandomValue(IEnumerable <ResourceAmount> source, List <ResourceAmount> destination, ITradeEntity trader) { foreach (var amount in source) { Resource r = ResourceLibrary.GetResourceByName(amount.ResourceType); if (trader.TraderRace.HatedResources.Any(tag => r.Tags.Contains(tag))) { continue; } if (amount.NumResources == 0) { continue; } ResourceAmount destAmount = destination.FirstOrDefault(resource => resource.ResourceType == amount.ResourceType); if (destAmount == null) { destAmount = new ResourceAmount(amount.ResourceType, 0); destination.Add(destAmount); } int numToMove = MathFunctions.RandInt(1, amount.NumResources + 1); amount.NumResources -= numToMove; destAmount.NumResources += numToMove; break; } }
public override void Construct() { Font = "font16"; OnUpdate = (sender, time) => { var builder = new StringBuilder(); builder.AppendFormat("Liquid assets: ${0}\n", Faction.Treasurys.Select(t => t.Money.Value).Sum()); var resources = Faction.ListResourcesInStockpilesPlusMinions(); builder.AppendFormat("Material assets: {0} resources valued at ${1}\n", resources.Values.Select(r => r.First.NumResources + r.Second.NumResources).Sum(), resources.Values.Select(r => { var value = ResourceLibrary.GetResourceByName(r.First.ResourceType).MoneyValue.Value; return((r.First.NumResources * value) + (r.Second.NumResources * value)); }).Sum()); builder.AppendFormat("{0} employees at ${1} per day.\n", Faction.Minions.Count, Faction.Minions.Select(m => m.Stats.CurrentLevel.Pay.Value).Sum()); var freeStockPile = Faction.ComputeRemainingStockpileSpace(); var totalStockPile = Faction.ComputeTotalStockpileSpace(); builder.AppendFormat("Stockpile space: {0} used of {1} ({2:00.00}%)\n", totalStockPile - freeStockPile, totalStockPile, (float)(totalStockPile - freeStockPile) / (float)totalStockPile * 100.0f); Text = builder.ToString(); }; Root.RegisterForUpdate(this); }
private Widget CreateLineItem(ResourceAmount Resource) { var r = Root.ConstructWidget(new Gui.Widget { MinimumSize = new Point(1, 32), Background = new TileReference("basic", 0) }); var resourceInfo = ResourceLibrary.GetResourceByName(Resource.ResourceType); var icon = r.AddChild(new ResourceIcon() { MinimumSize = new Point(32 + 16, 32 + 16), MaximumSize = new Point(32 + 16, 32 + 16), Layers = resourceInfo.GuiLayers, AutoLayout = AutoLayout.DockLeft, BackgroundColor = Resource.NumResources > 0 ? resourceInfo.Tint.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f), TextColor = Color.White.ToVector4(), TextHorizontalAlign = HorizontalAlign.Right, TextVerticalAlign = VerticalAlign.Bottom }); r.AddChild(new Gui.Widget { AutoLayout = AutoLayout.DockLeft, MinimumSize = new Point(128 / GameSettings.Default.GuiScale, 0), MaximumSize = new Point(128 / GameSettings.Default.GuiScale, 32), TextColor = Resource.NumResources > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f), TextVerticalAlign = VerticalAlign.Center, TextHorizontalAlign = HorizontalAlign.Left, HoverTextColor = GameSettings.Default.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(), Font = GameSettings.Default.GuiScale == 1 ? "font10" : "font8", ChangeColorOnHover = true, WrapText = true }); r.AddChild(new Gui.Widget { AutoLayout = AutoLayout.DockRight, //Text = String.Format("{0} at ${1}e", Resource.NumResources, resourceInfo.MoneyValue), //Font = "font18-outline", //TextColor = new Vector4(1,1,1,1), TextColor = Resource.NumResources > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f), TextVerticalAlign = VerticalAlign.Center, HoverTextColor = GameSettings.Default.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(), Font = GameSettings.Default.GuiScale == 1 ? "font10" : "font8", ChangeColorOnHover = true, }); r.Layout(); UpdateLineItemText(r, Resource); return(r); }
public void Eat(DateTime time) { bool outOfFood = false; foreach (var creature in Party) { var resource = Resources.FirstOrDefault(r => r.NumResources > 0 && ResourceLibrary.GetResourceByName(r.ResourceType).Tags.Contains(Resource.ResourceTags.Edible)); if (resource != null) { resource.NumResources--; } else if (MathFunctions.RandEvent(0.5f)) { outOfFood = true; creature.Creature.Hp -= MathFunctions.Rand(1, 10); var thoughts = creature.Creature.GetComponent <DwarfThoughts>(); if (thoughts != null) { thoughts.AddThought(Thought.ThoughtType.FeltHungry); } } } var numDied = Party.Count(p => p.Creature.Hp <= 0); foreach (var creature in Party.Where(p => p.Creature.Hp <= 0)) { creature.Delete(); } if (outOfFood) { if (numDied == 0) { LastEvent = "The adventuring party ran out of food!"; } else { LastEvent = String.Format("The adventuring party ran out of food! {0} starved to death.", numDied); } } Party.RemoveAll(p => p.Creature.Hp <= 0); if (Party.Count == 0) { AdventureState = State.Done; LastEvent = "All of the members of the adventuring party starved to death."; Resources.Clear(); Money = 0; } HourOfLastEating = time.Hour; }
public DwarfBux ComputeValue(ResourceLibrary.ResourceType Resource) { var resource = ResourceLibrary.GetResourceByName(Resource); if (SourceEnvoy.OwnerFaction.Race.CommonResources.Any(r => resource.Tags.Contains(r))) { return(resource.MoneyValue * 0.75m); } if (SourceEnvoy.OwnerFaction.Race.RareResources.Any(r => resource.Tags.Contains(r))) { return(resource.MoneyValue * 1.25m); } return(resource.MoneyValue); }
public override void OnAction(WorldManager world) { var owner = world.Factions.Factions[OwnerFaction]; var des = world.Factions.Factions[DestinationFaction]; var charisma = Party.Max(p => p.Stats.BuffedChar); float tradeGoodness = charisma - MathFunctions.Rand(0, 10.0f); var politics = world.Diplomacy.GetPolitics(owner, des); if (Resources.Any(r => ResourceLibrary.GetResourceByName(r.ResourceType).Tags.Any(t => des.Race.HatedResources.Contains(t)))) { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Description = "You gave us something we hate!", Change = -5, Duration = new TimeSpan(4, 0, 0, 0), Time = world.Time.CurrentDate }); LastEvent = String.Format("The {0} of {1} were offended by our peace offering. They captured the envoy.", des.Race.Plural, des.Name); Party.Clear(); Resources.Clear(); Money = 0; AdventureState = State.Done; return; } decimal tradeValue = (Resources.Sum(r => GetValue(ResourceLibrary.GetResourceByName(r.ResourceType), des) * r.NumResources) + (decimal)Money) * (decimal)charisma; if (MathFunctions.Rand(0, 500) < (float)tradeValue) { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Description = "You sent a peace envoy.", Change = 10, Duration = new TimeSpan(8, 0, 0, 0), Time = world.Time.CurrentDate }); politics.HasMet = true; politics.WasAtWar = false; LastEvent = String.Format("The adventuring party made peace with the {0} of {1}!", des.Race.Plural, des.Name); Money = 0; Resources.Clear(); AdventureState = State.ComingBack; } base.OnAction(world); }
private void UpdateLineItemText(Widget LineItem, ResourceAmount Resource) { var resourceInfo = ResourceLibrary.GetResourceByName(Resource.ResourceType); var font = LineItem.Root.GetTileSheet("font10"); var label = resourceInfo.ShortName ?? resourceInfo.Name; if (font != null) { Point measurements = font.MeasureString(resourceInfo.ShortName ?? resourceInfo.Name); label = font.WordWrapString(label, 1.0f, 128 / GameSettings.Default.GuiScale, LineItem.WrapWithinWords); if (128 / GameSettings.Default.GuiScale < measurements.X) { LineItem.MinimumSize.Y = font.TileHeight * label.Split('\n').Length; } } LineItem.GetChild(1).Text = label; LineItem.GetChild(1).Invalidate(); LineItem.GetChild(2).Text = String.Format("{0}", ValueSourceEntity.ComputeValue(Resource.ResourceType)); var counter = LineItem.GetChild(0).Children.Last(); counter.Text = Resource.NumResources.ToString(); counter.Invalidate(); LineItem.GetChild(0).Invalidate(); LineItem.Tooltip = resourceInfo.Name + "\n" + resourceInfo.Description; for (int i = 0; i < 3; i++) { if (i > 0) { LineItem.GetChild(i).TextColor = Resource.NumResources > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f); } LineItem.GetChild(i).BackgroundColor = Resource.NumResources > 0 ? resourceInfo.Tint.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f); LineItem.GetChild(i).Tooltip = resourceInfo.Name + "\n" + resourceInfo.Description; LineItem.GetChild(i).Invalidate(); } }
private static void _wait_for_trade(YarnEngine State, List <Ancora.AstNode> Arguments, Yarn.MemoryVariableStore Memory) { var envoy = Memory.GetValue("$envoy").AsObject as TradeEnvoy; var playerFaction = Memory.GetValue("$player_faction").AsObject as Faction; var world = Memory.GetValue("$world").AsObject as WorldManager; State.Pause(); State.PlayerInterface.WaitForTrade((tradeResult, transaction) => { if (tradeResult == Gui.Widgets.TradeDialogResult.Cancel) { Memory.SetValue("$trade_result", new Yarn.Value("cancelled")); } else if (tradeResult == Gui.Widgets.TradeDialogResult.RejectProfit) { Memory.SetValue("$trade_result", new Yarn.Value("unprofitable")); } else if (transaction.PlayerItems.Select(i => ResourceLibrary.GetResourceByName(i.ResourceType)) .SelectMany(i => i.Tags) .Any(tag => envoy.OwnerFaction.Race.HatedResources.Contains(tag))) { Memory.SetValue("$trade_result", new Yarn.Value("hated")); } else if (transaction.PlayerItems.Select(i => ResourceLibrary.GetResourceByName(i.ResourceType)) .SelectMany(i => i.Tags) .Any(tag => envoy.OwnerFaction.Race.LikedResources.Contains(tag))) { Memory.SetValue("$trade_result", new Yarn.Value("liked")); } else { Memory.SetValue("$trade_result", new Yarn.Value("acceptable")); } Memory.SetValue("$trade_transaction", new Yarn.Value(transaction)); State.CancelSpeech(); State.Unpause(); }); }
public DwarfBux ComputeValue(ResourceType Resource) { return(ResourceLibrary.GetResourceByName(Resource).MoneyValue); }
public string GetStatusString(WorldManager world) { return(String.Format("Food supply {0}, {1}", Resources.Sum(r => ResourceLibrary.GetResourceByName(r.ResourceType).Tags.Contains(Resource.ResourceTags.Edible) ? r.NumResources : 0), GetETAString(world))); }
public void SetTradeItems(List <ResourceAmount> leftResources, List <ResourceAmount> rightResources, DwarfBux leftMoney, DwarfBux rightMoney) { Update(); LeftItems.Clear(); RightItems.Clear(); var left = GetTopResources(leftResources).ToList(); int leftCount = left.Count + (leftMoney > 0.0m ? 1 : 0); int k = 0; foreach (var resource in left) { var resourceType = ResourceLibrary.GetResourceByName(resource.ResourceType); LeftItems.AddChild(new ResourceIcon() { Layers = resourceType.GuiLayers, MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(LeftWidget.Rect.X + 16 + k * 4 - leftCount * 2, LeftWidget.Rect.Y + 5, 32, 32) }); k++; } if (leftMoney > 0.0m) { LeftItems.AddChild(new Widget() { Background = new TileReference("coins", 1), MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(LeftWidget.Rect.X + 16 + k * 4 - leftCount * 2, LeftWidget.Rect.Y + 5, 32, 32) }); } var right = GetTopResources(rightResources).ToList(); int rightCount = right.Count + (rightMoney > 0.0m ? 1 : 0); k = 0; foreach (var resource in GetTopResources(rightResources)) { var resourceType = ResourceLibrary.GetResourceByName(resource.ResourceType); RightItems.AddChild(new ResourceIcon() { Layers = resourceType.GuiLayers, MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(RightWidget.Rect.X + 16 + k * 4 - rightCount * 2, RightWidget.Rect.Y + 5, 32, 32) }); k++; } if (rightMoney > 0.0m) { RightItems.AddChild(new Widget() { Background = new TileReference("coins", 1), MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Rect = new Rectangle(RightWidget.Rect.X + 16 + k * 4 - rightCount * 2, RightWidget.Rect.Y + 5, 32, 32) }); } LeftItems.Invalidate(); RightItems.Invalidate(); }
public override void OnAction(WorldManager world) { if (Resources.Count == 0) { LastEvent = String.Format("The trade party didn't have anything to trade, so they're coming home."); return; } var owner = world.Factions.Factions[OwnerFaction]; var dest = world.Factions.Factions[DestinationFaction]; var charisma = Party.Max(p => p.Stats.BuffedChar); float tradeGoodness = charisma - MathFunctions.Rand(0, 10.0f); var politics = world.Diplomacy.GetPolitics(owner, dest); List <ResourceAmount> destGoods = dest.Race.GenerateResources(world); List <ResourceAmount> tradeGoods = new List <ResourceAmount>(); bool wasBadTrade = false; int randIters = 100; for (int iter = 0; iter < randIters; iter++) { var resourceType = Datastructures.SelectRandom(Resources); if (resourceType.NumResources == 0) { continue; } var resource = ResourceLibrary.GetResourceByName(resourceType.ResourceType); bool liked = resource.Tags.Any(t => dest.Race.LikedResources.Contains(t)); bool hated = resource.Tags.Any(t => dest.Race.HatedResources.Contains(t)); if (tradeGoodness < 0 && liked) { LastEvent = String.Format("{0} gave the {1} {2}, which made them very angry!", Datastructures.SelectRandom(Party).Stats.FullName, dest.Race.Name, resourceType.ResourceType); string badTrade = "You gave us something we hate."; if (!politics.RecentEvents.Any(ev => ev.Description == badTrade)) { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Description = badTrade, Change = -5, Duration = new TimeSpan(4, 0, 0, 0), Time = world.Time.CurrentDate }); } wasBadTrade = true; break; } else if (tradeGoodness > 0 && liked) { string goodTrade = "You gave us something we like."; if (!politics.RecentEvents.Any(ev => ev.Description == goodTrade)) { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Description = goodTrade, Change = 5, Duration = new TimeSpan(4, 0, 0, 0), Time = world.Time.CurrentDate }); } } var resourceValue = GetValue(resource, dest); // Now find a resource of equal or greater value and trade for it. int randIter2 = 0; while (randIter2 < 100) { var randGood = Datastructures.SelectRandom(destGoods); if (randGood.NumResources == 0) { randIter2++; continue; } var good = ResourceLibrary.GetResourceByName(randGood.ResourceType); var randGoodValue = GetValue(good, dest); // Trade the most of this resource we possibly can. If we want to // trade an item of lesser value, try to trade 1 good for as much of it as possible. if (randGoodValue <= resourceValue) { int numToTrade = Math.Min((int)(resourceValue / randGoodValue), randGood.NumResources); if (numToTrade * randGoodValue >= 0.75f * resourceValue) { randGood.NumResources -= numToTrade; resourceType.NumResources--; tradeGoods.Add(new ResourceAmount(good, numToTrade)); break; } } // If we're trading upwards, try trading as much of our resource as possible for the valuable item. else { int numToTrade = Math.Min((int)(randGoodValue / resourceValue), resourceType.NumResources); if (numToTrade * resourceValue >= 0.75f * randGoodValue) { randGood.NumResources--; resourceType.NumResources -= numToTrade; tradeGoods.Add(new ResourceAmount(good, 1)); break; } } randIter2++; } // We failed to find a good of equal value, so let's just trade money. if (randIter2 == 100) { resourceType.NumResources--; Money += resourceValue; } } Resources.AddRange(tradeGoods); if (!wasBadTrade) { LastEvent = String.Format("The trade party is returning home with {0} goods, and {1}.", Resources.Sum(r => r.NumResources), Money); } base.OnAction(world); }
public override void Construct() { Border = "border-one"; Font = "font10"; TextColor = new Vector4(0, 0, 0, 1); OnShown += (sender) => { Clear(); ResourceCombos.Clear(); //Parent.OnClick = null; var titleBar = AddChild(new Gui.Widget() { AutoLayout = Gui.AutoLayout.DockTop, MinimumSize = new Point(0, 34), }); int k = 0; foreach (var ingredient in Data.RequiredResources) { var resource = ResourceLibrary.GetAverageWithTag(ingredient.ResourceType); titleBar.AddChild(new Gui.Widget { MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Background = resource.GuiLayers[0], AutoLayout = AutoLayout.DockLeft, Text = ingredient.NumResources.ToString(), TextHorizontalAlign = HorizontalAlign.Right, TextVerticalAlign = VerticalAlign.Bottom, Font = "font10-outline-numsonly", TextColor = Color.White.ToVector4(), Tooltip = ingredient.ResourceType.ToString() }); if (k < Data.RequiredResources.Count - 1) { titleBar.AddChild(new Gui.Widget { MinimumSize = new Point(16, 32), MaximumSize = new Point(16, 32), AutoLayout = AutoLayout.DockLeft, Text = "+", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Bottom, Font = "font10" }); } else { titleBar.AddChild(new Gui.Widget { MinimumSize = new Point(16, 32), MaximumSize = new Point(16, 32), AutoLayout = AutoLayout.DockLeft, Text = ">>", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Bottom, Font = "font10" }); } k++; } titleBar.AddChild(new Gui.Widget { MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Background = Data.Icon, AutoLayout = Gui.AutoLayout.DockLeft, Text = Data.CraftedResultsCount.ToString(), Font = "font10-outline-numsonly", TextHorizontalAlign = HorizontalAlign.Right, TextVerticalAlign = VerticalAlign.Bottom, TextColor = Color.White.ToVector4() }); titleBar.AddChild(new Gui.Widget { Text = " " + Data.Name, Font = "font16", AutoLayout = Gui.AutoLayout.DockLeft, TextVerticalAlign = VerticalAlign.Center, MinimumSize = new Point(0, 34), Padding = new Margin(0, 0, 16, 0) }); AddChild(new Gui.Widget { Text = Data.Description + "\n", AutoLayout = Gui.AutoLayout.DockTop, AutoResizeToTextHeight = true }); var minion = World.PlayerFaction.Minions.FirstOrDefault(m => Data.IsMagical ? m.Stats.IsTaskAllowed(Task.TaskCategory.Research) : m.Stats.IsTaskAllowed(Task.TaskCategory.BuildObject)); var nearestBuildLocation = World.PlayerFaction.FindNearestItemWithTags(Data.CraftLocation, Vector3.Zero, false, null); if (minion == null) { AddChild(new Gui.Widget { Text = String.Format("Needs {0} to {1}!", Data.IsMagical ? "Wizard" : "CraftsDwarf", Data.Verb), TextColor = new Vector4(1, 0, 0, 1), AutoLayout = Gui.AutoLayout.DockBottom }); } else if (!String.IsNullOrEmpty(Data.CraftLocation) && Data.Type == CraftItem.CraftType.Resource && nearestBuildLocation == null) { AddChild(new Gui.Widget { Text = String.Format("Needs {0} to {1}!", Data.CraftLocation, Data.Verb), TextColor = new Vector4(1, 0, 0, 1), AutoLayout = Gui.AutoLayout.DockBottom }); } else { foreach (var resourceAmount in Data.RequiredResources) { var child = AddChild(new Widget() { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(200, 18) }); child.AddChild(new Gui.Widget() { Font = "font8", Text = String.Format("{0} {1}: ", resourceAmount.NumResources, resourceAmount.ResourceType), AutoLayout = AutoLayout.DockLeft }); child.Layout(); var resourceSelector = child.AddChild(new Gui.Widgets.ComboBox { Font = "font8", Items = Master.Faction.ListResourcesWithTag(resourceAmount.ResourceType).Where(r => r.NumResources >= resourceAmount.NumResources).Select(r => r.ResourceType.ToString()).OrderBy(p => p).ToList(), AutoLayout = AutoLayout.DockLeft, MinimumSize = new Point(200, 18), Tooltip = String.Format("Type of {0} to use.", resourceAmount.ResourceType) }) as Gui.Widgets.ComboBox; if (AllowWildcard) { resourceSelector.Items.Insert(0, "Any"); } if (resourceSelector.Items.Count == 0) { resourceSelector.Items.Add("<Not enough!>"); } resourceSelector.SelectedIndex = 0; ResourceCombos.Add(resourceSelector); } if (Data.Type == CraftItem.CraftType.Resource) { var child2 = AddChild(new Widget() { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(100, 18) }); child2.AddChild(new Gui.Widget() { Font = "font8", Text = "Repeat ", AutoLayout = AutoLayout.DockLeft }); NumCombo = child2.AddChild(new Gui.Widgets.ComboBox { Font = "font8", Items = new List <string>() { "1x", "5x", "10x", "100x" }, AutoLayout = AutoLayout.DockLeft, MinimumSize = new Point(64, 18), MaximumSize = new Point(64, 18), Tooltip = "Craft this many objects." }) as Gui.Widgets.ComboBox; NumCombo.SelectedIndex = 0; } var bottomBar = AddChild(new Widget() { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(256, 32) }); bool hasExisting = false; if (BuildAction != null) { if (Data.Type == CraftItem.CraftType.Object && PlaceAction != null) { hasExisting = true; var resources = Master.Faction.ListResources(); if (resources.Any(resource => ResourceLibrary.GetResourceByName(resource.Key).CraftInfo.CraftItemType == Data.Name)) { bottomBar.AddChild(new Button() { Text = "Place Existing", OnClick = (widget, args) => { PlaceAction(this, args); }, AutoLayout = AutoLayout.DockLeftCentered, MinimumSize = new Point(64, 28), Tooltip = String.Format("Place an existing {0} from our stockpiles.", Data.Name) }); } } var buildButton = bottomBar.AddChild(new Button() { Text = hasExisting ? String.Format("{0} New", Data.Verb): Data.Verb, OnClick = (widget, args) => { BuildAction(this, args); //sender.Hidden = true; //sender.Invalidate(); }, AutoLayout = AutoLayout.DockLeftCentered, MinimumSize = new Point(64, 28), Tooltip = String.Format("{1} a new {0} using the selected resources.", Data.Name, Data.Verb) }); //Parent.OnClick = (parent, args) => buildButton.OnClick(buildButton, args); } } Layout(); }; }
public override void Construct() { ItemSize = new Point(32, 64); Root.RegisterForUpdate(this); Background = new TileReference("basic", 0); BackgroundColor = new Vector4(0, 0, 0, 0.5f); OnUpdate = (sender, time) => { var existingResourceEntries = new List <Widget>(Children); Children.Clear(); var aggregated = AggregateResources( Master.Faction.ListResourcesInStockpilesPlusMinions().Where(p => p.Value.First.NumResources > 0 || p.Value.Second.NumResources > 0)); foreach (var resource in aggregated) { var resourceTemplate = ResourceLibrary.GetResourceByName(resource.Amount.First.ResourceType); // Don't display resources with no value (a hack, yes!). This is to prevent "special" resources from getting traded. if (resourceTemplate.MoneyValue == 0.0m) { continue; } var icon = existingResourceEntries.FirstOrDefault(w => w is ResourceIcon && (w as ResourceIcon).EqualsLayers(resourceTemplate.GuiLayers)); StringBuilder label = new StringBuilder(); foreach (var aggregates in resource.Members) { label.Append(aggregates); label.Append("\n"); } label.Append(resourceTemplate.Description); if (icon == null) { icon = AddChild(new ResourceIcon() { Layers = resourceTemplate.GuiLayers, Tooltip = label.ToString(), }); } else { icon.Tooltip = label.ToString(); if (!Children.Contains(icon)) { AddChild(icon); } } string text = "S" + resource.Amount.First.NumResources.ToString(); text += "\n"; if (resource.Amount.Second.NumResources > 0) { text += "I" + resource.Amount.Second.NumResources.ToString(); } icon.Text = text; icon.Invalidate(); } var width = Root.RenderData.VirtualScreen.Width - ItemSpacing.X; var itemsThatFit = width / (ItemSize.X + ItemSpacing.X); var sensibleWidth = (Math.Min(Children.Count, itemsThatFit) * (ItemSize.X + ItemSpacing.X)) + ItemSpacing.X; Rect = new Rectangle((Root.RenderData.VirtualScreen.Width / 2 - sensibleWidth / 2), 0, sensibleWidth, 32); Layout(); }; }
public float ComputeValue(ResourceLibrary.ResourceType Resource) { // Todo: Account for rare or common items. return(ResourceLibrary.GetResourceByName(Resource).MoneyValue); }
public float ComputeValue(ResourceLibrary.ResourceType Resource) { return(ResourceLibrary.GetResourceByName(Resource).MoneyValue); }
public override void Construct() { AutoSizeColumns = true; IsRootTray = true; ItemSource = new Gui.Widget[] { new HorizontalMenuTray.MenuItem { Text = "CHEAT MODE", }, new HorizontalMenuTray.MenuItem { Text = "DEBUG", ExpansionChild = new HorizontalMenuTray.Tray { ItemSize = new Point(200, 20), ItemSource = Debugger.EnumerateSwitches().Select(s => new HorizontalMenuTray.CheckboxMenuItem { Text = Debugger.GetNicelyFormattedName(s.Name), InitialState = s.State, SetCallback = s.Set }) } }, new HorizontalMenuTray.MenuItem { Text = "DEBUG SAVE", OnClick = (sender, args) => { // Turn off binary compressed saves and save a nice straight json save for debugging purposes. // Todo: Why isn't World managing this paused state itself? bool paused = Master.World.Paused; var previousSetting = DwarfGame.COMPRESSED_BINARY_SAVES; DwarfGame.COMPRESSED_BINARY_SAVES = false; Master.World.Save( String.Format("{0}_{1}_DEBUG", Overworld.Name, Master.World.GameID), (success, exception) => { Master.World.MakeAnnouncement(success ? "Debug save created.": "Debug save failed - " + exception.Message); DwarfGame.COMPRESSED_BINARY_SAVES = previousSetting; Master.World.Paused = paused; }); } }, new HorizontalMenuTray.MenuItem { Text = "BUILD", ExpansionChild = new HorizontalMenuTray.Tray { ItemSource = RoomLibrary.GetRoomTypes().Select(r => new HorizontalMenuTray.MenuItem { Text = r, OnClick = (sender, args) => ActivateGodTool("Build/" + r) }) } }, new HorizontalMenuTray.MenuItem { Text = "SPAWN", ExpansionChild = new HorizontalMenuTray.Tray { Columns = 5, ItemSource = EntityFactory.EnumerateEntityTypes().Where(s => !s.Contains("Resource") || !ResourceLibrary.GetResourceByName(s.Substring(0, s.Length - " Resource".Length)).Generated).OrderBy(s => s).Select(s => new HorizontalMenuTray.MenuItem { Text = s, OnClick = (sender, args) => ActivateGodTool("Spawn/" + s) }) } }, new HorizontalMenuTray.MenuItem { Text = "PLACE BLOCK", ExpansionChild = new HorizontalMenuTray.Tray { Columns = 3, ItemSource = VoxelLibrary.PrimitiveMap.Keys .Where(t => t.Name != "empty" && t.Name != "water") .OrderBy(s => s.Name) .Select(s => new HorizontalMenuTray.MenuItem { Text = s.Name, OnClick = (sender, args) => ActivateGodTool("Place/" + s.Name) }) } }, new HorizontalMenuTray.MenuItem { Text = "DELETE BLOCK", OnClick = (sender, args) => ActivateGodTool("Delete Block") }, new HorizontalMenuTray.MenuItem { Text = "KILL BLOCK", OnClick = (sender, args) => ActivateGodTool("Kill Block") }, new HorizontalMenuTray.MenuItem { Text = "PLACE GRASS", ExpansionChild = new HorizontalMenuTray.Tray { Columns = 3, ItemSource = GrassLibrary.TypeList .OrderBy(s => s.Name) .Select(s => new HorizontalMenuTray.MenuItem { Text = s.Name, OnClick = (sender, args) => ActivateGodTool("Grass/" + s.Name) }) } }, new HorizontalMenuTray.MenuItem { Text = "PLACE DECAL", ExpansionChild = new HorizontalMenuTray.Tray { Columns = 3, ItemSource = DecalLibrary.TypeList .OrderBy(s => s.Name) .Select(s => new HorizontalMenuTray.MenuItem { Text = s.Name, OnClick = (sender, args) => ActivateGodTool("Decal/" + s.Name) }) } }, new HorizontalMenuTray.MenuItem { Text = "PLACE RAIL", ExpansionChild = new HorizontalMenuTray.Tray { Columns = 1, ItemSource = new HorizontalMenuTray.MenuItem[] { new HorizontalMenuTray.MenuItem { Text = "RAW PIECES", ExpansionChild = new HorizontalMenuTray.Tray { Columns = 2, ItemSize = new Point(200, 20), ItemSource = Rail.RailLibrary.EnumeratePieces().Select(p => new HorizontalMenuTray.MenuItem { Text = p.Name, OnClick = (sender, args) => ActivateGodTool("Rail/" + p.Name) }) } }, new HorizontalMenuTray.MenuItem { Text = "USING PATTERNS", ExpansionChild = new HorizontalMenuTray.Tray { Columns = 1, ItemSource = Rail.RailLibrary.EnumeratePatterns().Select(p => new HorizontalMenuTray.MenuItem { Text = p.Name, OnClick = (sender, args) => { var railTool = Master.Tools[GameMaster.ToolMode.BuildRail] as Rail.BuildRailTool; railTool.Pattern = p; Master.ChangeTool(GameMaster.ToolMode.BuildRail); railTool.GodModeSwitch = true; } }) } }, new HorizontalMenuTray.MenuItem { Text = "PAINT", OnClick = (sender, args) => { var railTool = Master.Tools[GameMaster.ToolMode.PaintRail] as Rail.PaintRailTool; railTool.SelectedResources = new List <ResourceAmount>(new ResourceAmount[] { new ResourceAmount("Rail", 1) }); Master.ChangeTool(GameMaster.ToolMode.PaintRail); railTool.GodModeSwitch = true; } } } } }, new HorizontalMenuTray.MenuItem { Text = "KILL THINGS", OnClick = (sender, args) => ActivateGodTool("Kill Things") }, new HorizontalMenuTray.MenuItem { Text = "TRAILER", ExpansionChild = new HorizontalMenuTray.Tray { ItemSource = new List <HorizontalMenuTray.MenuItem>() { new HorizontalMenuTray.MenuItem { Text = "SPIN +", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Zero, 2.0f, 0.0f), }, new HorizontalMenuTray.MenuItem { Text = "SPIN -", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Zero, -2.0f, 0.0f), }, new HorizontalMenuTray.MenuItem { Text = "ZOOM -", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Zero, 0.0f, 2.5f), }, new HorizontalMenuTray.MenuItem { Text = "ZOOM +", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Zero, 0.0f, -2.5f), }, new HorizontalMenuTray.MenuItem { Text = "FWD", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Forward * 5, 0.0f, 0.0f), }, new HorizontalMenuTray.MenuItem { Text = "BACK", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Backward * 5, 0.0f, 0.0f), }, new HorizontalMenuTray.MenuItem { Text = "LEFT", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Left * 5, 0.0f, 0.0f), }, new HorizontalMenuTray.MenuItem { Text = "RIGHT", OnClick = (sender, args) => this.Master.World.Camera.Trailer(Vector3.Right * 5, 0.0f, 0.0f), }, } } }, new HorizontalMenuTray.MenuItem { Text = "FILL WATER", OnClick = (sender, args) => ActivateGodTool("Fill Water") }, new HorizontalMenuTray.MenuItem { Text = "FILL LAVA", OnClick = (sender, args) => ActivateGodTool("Fill Lava") }, new HorizontalMenuTray.MenuItem { Text = "TRADE ENVOY", ExpansionChild = new HorizontalMenuTray.Tray { ItemSource = Master.World.Factions.Factions.Values.Where(f => f.Race.IsIntelligent && f != Master.Faction).Select(s => { return(new HorizontalMenuTray.MenuItem { Text = s.Name, OnClick = (sender, args) => Master.World.Diplomacy.SendTradeEnvoy(s, Master.World) }); }), } }, new HorizontalMenuTray.MenuItem { Text = "EVENT", ExpansionChild = new HorizontalMenuTray.Tray { ItemSource = Master.World.GoalManager.EventScheduler.Events.Events.Select(e => { return(new HorizontalMenuTray.MenuItem { Text = e.Name, OnClick = (sender, args) => Master.World.GoalManager.EventScheduler.ActivateEvent(Master.World, e) }); }), } }, new HorizontalMenuTray.MenuItem { Text = "WAR PARTY", ExpansionChild = new HorizontalMenuTray.Tray { ItemSource = Master.World.Factions.Factions.Values.Where(f => f.Race.IsIntelligent && f != Master.Faction).Select(s => { return(new HorizontalMenuTray.MenuItem { Text = s.Name, OnClick = (sender, args) => Master.World.Diplomacy.SendWarParty(s) }); }), } }, new HorizontalMenuTray.MenuItem { Text = "DWARF BUX", OnClick = (sender, args) => Master.Faction.AddMoney(100m) }, new HorizontalMenuTray.MenuItem { Text = "MINIONS", ExpansionChild = new HorizontalMenuTray.Tray { ItemSource = new HorizontalMenuTray.MenuItem[] { new HorizontalMenuTray.MenuItem { Text = "PAY", OnClick = (sender, args) => Master.PayEmployees() }, new HorizontalMenuTray.MenuItem { Text = "STARVE", OnClick = (sender, args) => { foreach (var minion in Master.Faction.Minions) { minion.Status.Hunger.CurrentValue = 0; } } }, new HorizontalMenuTray.MenuItem { Text = "XP", OnClick = (sender, args) => { foreach (var minion in Master.Faction.Minions) { minion.AddXP(100); } } }, new HorizontalMenuTray.MenuItem { Text = "DISEASE", OnClick = (sender, args) => ActivateGodTool("Disease") }, new HorizontalMenuTray.MenuItem { Text = "HAPPY", OnClick = (sender, args) => { foreach (var minion in Master.Faction.Minions) { var thoughts = minion.GetRoot().GetComponent <DwarfThoughts>(); if (thoughts != null) { thoughts.AddThought(Thought.ThoughtType.CheatedHappy); } } } }, new HorizontalMenuTray.MenuItem { Text = "PISSED", OnClick = (sender, args) => { foreach (var minion in Master.Faction.Minions) { var thoughts = minion.GetRoot().GetComponent <DwarfThoughts>(); if (thoughts != null) { thoughts.AddThought(Thought.ThoughtType.CheatedPissed); } } } }, new HorizontalMenuTray.MenuItem { Text = "GAMBLE", OnClick = (sender, args) => { foreach (var employee in Master.Faction.Minions) { employee.AssignTask(new Scripting.GambleTask() { Priority = Task.PriorityType.High }); } } }, new HorizontalMenuTray.MenuItem { Text = "PASS OUT", OnClick = (sender, args) => { var employee = Datastructures.SelectRandom(Master.Faction.Minions); if (employee != null) { employee.Creature.Heal(-employee.Status.Health.CurrentValue * employee.Creature.MaxHealth + 1); } } } } } }, new HorizontalMenuTray.MenuItem { Text = "SPAWN TEST", OnClick = (sender, args) => { // Copy is required because spawning some types results in the creation of new types. EG, snakes create snake meat. var keys = EntityFactory.EnumerateEntityTypes().ToList(); int num = keys.Count(); float gridSize = (float)Math.Ceiling(Math.Sqrt((double)num)); Vector3 gridCenter = Master.World.CursorLightPos; int i = 0; for (float dx = -gridSize / 2; dx <= gridSize / 2; dx++) { for (float dz = -gridSize / 2; dz <= gridSize / 2; dz++) { if (i >= num) { continue; } Vector3 pos = MathFunctions.Clamp(gridCenter + new Vector3(dx, VoxelConstants.ChunkSizeY, dz), Master.World.ChunkManager.Bounds); VoxelHandle handle = VoxelHelpers.FindFirstVisibleVoxelOnRay(Master.World.ChunkManager.ChunkData, pos, pos + Vector3.Down * 100); if (handle.IsValid) { EntityFactory.CreateEntity <GameComponent>(keys[i], handle.WorldPosition + Vector3.Up); } i++; } } } }, new HorizontalMenuTray.MenuItem { Text = "SPAWN CRAFTS", OnClick = (sender, args) => { // Copy is required because spawning some types results in the creation of new types. EG, snakes create snake meat. var itemTypes = CraftLibrary.EnumerateCraftables().Where(craft => craft.Type == CraftItem.CraftType.Object).ToList(); int num = itemTypes.Count(); float gridSize = (float)Math.Ceiling(Math.Sqrt((double)num)); Vector3 gridCenter = Master.World.CursorLightPos; int i = 0; for (float dx = -gridSize / 2; dx <= gridSize / 2; dx++) { for (float dz = -gridSize / 2; dz <= gridSize / 2; dz++) { if (i < num) { var item = itemTypes[i]; if (item.Name != "Explosive") { Vector3 pos = MathFunctions.Clamp(gridCenter + new Vector3(dx, VoxelConstants.ChunkSizeY, dz), Master.World.ChunkManager.Bounds); VoxelHandle handle = VoxelHelpers.FindFirstVisibleVoxelOnRay(Master.World.ChunkManager.ChunkData, pos, pos + Vector3.Down * 100); if (handle.IsValid) { var blackboard = new Blackboard(); List <ResourceAmount> resources = item.RequiredResources.Select(r => new ResourceAmount(ResourceLibrary.GetResourcesByTag(r.ResourceType).First(), r.NumResources)).ToList(); blackboard.SetData <List <ResourceAmount> >("Resources", resources); blackboard.SetData <string>("CraftType", item.Name); var entity = EntityFactory.CreateEntity <GameComponent>(item.EntityName, handle.WorldPosition + Vector3.Up + item.SpawnOffset, blackboard); if (entity != null) { if (item.AddToOwnedPool) { Master.Faction.OwnedObjects.Add(entity as Body); } if (item.Moveable) { entity.Tags.Add("Moveable"); } if (item.Deconstructable) { entity.Tags.Add("Deconstructable"); } } } } } i++; } } } }, new HorizontalMenuTray.MenuItem { Text = "+1 HOUR", OnClick = (sender, args) => { Master.World.Time.CurrentDate += new TimeSpan(1, 0, 0); } }, new HorizontalMenuTray.MenuItem { Text = "FORCE REBUILD", OnClick = (sender, args) => { foreach (var chunk in Master.World.ChunkManager.ChunkData.ChunkMap) { for (int Y = 0; Y < VoxelConstants.ChunkSizeY; ++Y) { chunk.InvalidateSlice(Y); } } } }, new HorizontalMenuTray.MenuItem { Text = "REPULSE", OnClick = (sender, args) => ActivateGodTool("Repulse") }, new HorizontalMenuTray.MenuItem { Text = "SLOWMO", OnClick = (sender, args) => GameSettings.Default.EnableSlowMotion = !GameSettings.Default.EnableSlowMotion }, new HorizontalMenuTray.MenuItem { Text = "LET IT SNOW", OnClick = (sender, args) => { var storm = Weather.CreateStorm(Vector3.One, 100.0f, Master.World); storm.TypeofStorm = StormType.SnowStorm; storm.Start(); } } }; base.Construct(); }
public override void Construct() { Font = "font10"; Title = AddChild(new Widget() { Font = "font16", Text = "Finance", AutoLayout = AutoLayout.DockTop }); InfoWidget = AddChild(new Widget() { Font = "font10", Text = "", MinimumSize = new Point(640, 300), AutoLayout = AutoLayout.DockTop }); OnUpdate = (sender, time) => { numrows = 0; InfoWidget.Clear(); AddRow("Liquid assets:", Faction.Economy.CurrentMoney.ToString()); var resources = Faction.ListResourcesInStockpilesPlusMinions(); AddRow("Material assets:", String.Format("{0} goods valued at ${1}", resources.Values.Select(r => r.First.NumResources + r.Second.NumResources).Sum(), resources.Values.Select(r => { var value = ResourceLibrary.GetResourceByName(r.First.ResourceType).MoneyValue.Value; return((r.First.NumResources * value) + (r.Second.NumResources * value)); }).Sum())); var payPerDay = (DwarfBux)Faction.Minions.Select(m => m.Stats.CurrentLevel.Pay.Value).Sum(); AddRow("Employees:", String.Format("{0} at {1} per day.", Faction.Minions.Count, payPerDay)); AddRow("Runway:", String.Format("{0} day(s).\n", (int)(Faction.Economy.CurrentMoney / Math.Max(payPerDay, (decimal)0.01)))); var freeStockPile = Faction.ComputeRemainingStockpileSpace(); var totalStockPile = Math.Max(Faction.ComputeTotalStockpileSpace(), 1); AddRow("Stockpile space:", String.Format("{0} used of {1} ({2:00.00}%)\n", totalStockPile - freeStockPile, totalStockPile, (float)(totalStockPile - freeStockPile) / (float)totalStockPile * 100.0f)); var freeTreasury = Faction.ComputeRemainingTreasurySpace(); var totalTreasury = Math.Max(Faction.ComputeTotalTreasurySpace(), 1.0m); AddRow("Treasury space:", String.Format("{0} used of {1} ({2:00.00}%)\n", Faction.Economy.CurrentMoney, (DwarfBux)totalTreasury, 100.0f * (1.0f - ((float)(decimal)(totalTreasury - Faction.Economy.CurrentMoney) / (float)totalTreasury)))); AddRow("Average dwarf happiness:", String.Format("{0}%", (int)(float)Faction.Minions.Sum(m => m.Status.Happiness.Percentage) / Math.Max(Faction.Minions.Count, 1))); InfoWidget.Layout(); }; var selector = AddChild(new ComboBox() { Items = Faction.World.Stats.GameStats.Keys.ToList(), AutoLayout = AutoLayout.DockTop }) as ComboBox; var graph = AddChild(new Graph() { AutoLayout = AutoLayout.DockFill, GraphStyle = Graph.Style.LineChart }) as Graph; graph.SetFont("font10"); graph.Values = Faction.World.Stats.GameStats["Money"].Values.Select(v => v.Value).ToList(); selector.OnSelectedIndexChanged = (sender) => { var values = Faction.World.Stats.GameStats[selector.SelectedItem].Values; graph.Values = Faction.World.Stats.GameStats[selector.SelectedItem].Values.Select(v => v.Value).ToList(); if (values.Count > 0) { graph.XLabelMin = "\n" + TextGenerator.AgeToString(Faction.World.Time.CurrentDate - values.First().Date); graph.XLabelMax = "\nNow"; } graph.Invalidate(); }; selector.OnSelectedIndexChanged.Invoke(selector); Layout(); Root.RegisterForUpdate(this); }
public bool CanBuild() { foreach (var resource in Master.Faction.ListResourcesInStockpilesPlusMinions().Where(r => Data.CanBuildWith(ResourceLibrary.GetResourceByName(r.Key)))) { if (resource.Value.First.NumResources > 0 || resource.Value.Second.NumResources > 0) { return(true); } } return(false); }
public static void ProcessTrade(DialogueContext Context) { if (Context.TradePanel.Result == Gui.Widgets.TradeDialogResult.Propose) { var containsHatedItem = Context.TradePanel.Transaction.PlayerItems .Select(item => ResourceLibrary.GetResourceByName(item.ResourceType)) .SelectMany(item => item.Tags) .Any(tag => Context.Envoy.OwnerFaction.Race.HatedResources.Contains(tag)); var containsLikedItem = Context.TradePanel.Transaction.PlayerItems .Select(item => ResourceLibrary.GetResourceByName(item.ResourceType)) .SelectMany(item => item.Tags) .Any(tag => Context.Envoy.OwnerFaction.Race.LikedResources.Contains(tag)); if (containsHatedItem) { Context.Envoy.OwnerFaction.Race.Speech.Language.SayBoo(); Context.NumOffensiveTrades++; var phrase = Datastructures.SelectRandom(Context.Envoy.OwnerFaction.Race.Speech.OffensiveTrades); var action = Context.NumOffensiveTrades >= 3 ? GoodbyeWithPrompt(phrase) : RootWithPrompt(phrase); Context.Transition(action); if (!Context.Politics.HasEvent("you tried to give us something offensive")) { Context.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 = Context.World.Time.CurrentDate }); } } else { if (containsLikedItem) { if (!Context.Politics.HasEvent("you gave us something we liked")) { Context.Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = 0.25f, Description = "you gave us something we liked", Duration = new TimeSpan(4, 0, 0, 0), Time = Context.World.Time.CurrentDate }); } } Context.TradePanel.Transaction.Apply(Context.World); Context.Transition(RootWithPrompt(Datastructures.SelectRandom(Context.Envoy.OwnerFaction.Race.Speech.GoodTrades))); Context.World.GoalManager.OnGameEvent(new Goals.Events.Trade { PlayerFaction = Context.PlayerFaction, PlayerGold = Context.TradePanel.Transaction.PlayerMoney, PlayerGoods = Context.TradePanel.Transaction.PlayerItems, OtherFaction = Context.Envoy.OwnerFaction, OtherGold = Context.TradePanel.Transaction.EnvoyMoney, OtherGoods = Context.TradePanel.Transaction.EnvoyItems }); if (!Context.Politics.HasEvent("we had profitable trade")) { Context.Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = 0.25f, Description = "we had profitable trade", Duration = new TimeSpan(2, 0, 0, 0), Time = Context.World.Time.CurrentDate }); } Context.Envoy.OwnerFaction.Race.Speech.Language.SayYay(); } } else if (Context.TradePanel.Result == Gui.Widgets.TradeDialogResult.RejectOffense || Context.TradePanel.Result == Gui.Widgets.TradeDialogResult.RejectProfit) { Context.Envoy.OwnerFaction.Race.Speech.Language.SayBoo(); Context.Transition(RootWithPrompt(Datastructures.SelectRandom(Context.Envoy.OwnerFaction.Race.Speech.BadTrades))); } else { Context.Transition(RootWithPrompt("Changed your mind?")); } }