public TradeEnvoy SendTradeEnvoy() { if (!World.EnumerateZones().Any(room => room is BalloonPort && room.IsBuilt)) { World.MakeAnnouncement(String.Format("Trade envoy from {0} left: No balloon port!", ParentFaction.Name)); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f); return(null); } TradeEnvoy envoy = null; var creatures = World.MonsterSpawner.Spawn(World.MonsterSpawner.GenerateSpawnEvent(this, World.PlayerFaction, MathFunctions.Random.Next(4) + 1, false)); envoy = new TradeEnvoy(World.Time.CurrentDate) { Creatures = creatures, OtherFaction = World.PlayerFaction, ShouldRemove = false, OwnerFaction = this, TradeGoods = Race.GenerateTradeItems(World), TradeMoney = new DwarfBux((decimal)MathFunctions.Rand(150.0f, 550.0f)) }; if (Race.IsNative) { if (Economy == null) { Economy = new Company(this, 1000.0m, new CompanyInformation() { Name = ParentFaction.Name }); } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, Economy.Information)); } } else { GameComponent balloon = null; var rooms = World.EnumerateZones().Where(room => room.Type.Name == "Balloon Port").ToList(); if (rooms.Count != 0) { Vector3 pos = rooms.First().GetBoundingBox().Center(); balloon = Balloon.CreateBalloon(pos + new Vector3(0, 1000, 0), pos + Vector3.UnitY * 15, World.ComponentManager, this); } if (balloon != null) { foreach (CreatureAI creature in creatures) { Matrix tf = creature.Physics.LocalTransform; tf.Translation = balloon.LocalTransform.Translation; creature.Physics.LocalTransform = tf; } } else { if (Economy == null) { Economy = new Company(this, 1000.0m, new CompanyInformation() { Name = ParentFaction.Name }); } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, Economy.Information)); } } } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); } envoy.DistributeGoods(); TradeEnvoys.Add(envoy); World.MakeAnnouncement(new DwarfCorp.Gui.Widgets.QueuedAnnouncement { Text = String.Format("Trade envoy from {0} has arrived!", ParentFaction.Name), ClickAction = (gui, sender) => { if (envoy.Creatures.Count > 0) { envoy.Creatures.First().ZoomToMe(); World.UserInterface.MakeWorldPopup(String.Format("Traders from {0} ({1}) have entered our territory.\nThey will try to get to our balloon port to trade with us.", ParentFaction.Name, Race.Name), envoy.Creatures.First().Physics, -10); } }, ShouldKeep = () => { return(envoy.ExpiditionState == Expedition.State.Arriving); } }); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_positive_generic, 0.15f); World.Tutorial("trade"); if (!String.IsNullOrEmpty(Race.TradeMusic)) { SoundManager.PlayMusic(Race.TradeMusic); } return(envoy); }
public TradeEnvoy SendTradeEnvoy(Faction natives, WorldManager world) { if (!world.PlayerFaction.GetRooms().Any(room => room is BalloonPort && room.IsBuilt)) { world.MakeAnnouncement(String.Format("Trade envoy from {0} left. No balloon port!", natives.Name)); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f); return(null); } TradeEnvoy envoy = null; List <CreatureAI> creatures = world.MonsterSpawner.Spawn(world.MonsterSpawner.GenerateSpawnEvent(natives, world.PlayerFaction, MathFunctions.Random.Next(4) + 1, false)); if (natives.TradeMoney < 100m) { natives.TradeMoney += MathFunctions.Rand(250.0f, 5000.0f); } envoy = new TradeEnvoy(world.Time.CurrentDate) { Creatures = creatures, OtherFaction = world.PlayerFaction, ShouldRemove = false, OwnerFaction = natives, TradeGoods = natives.Race.GenerateResources(world), TradeMoney = natives.TradeMoney }; if (natives.Race.IsNative) { if (natives.Economy == null) { natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation() { Name = natives.Name }); } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); if (natives.Economy == null) { natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation() { Name = natives.Name }); } creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, natives.Economy.Company.Information)); } } else { Body balloon = world.PlayerFaction.DispatchBalloon(); foreach (CreatureAI creature in creatures) { Matrix tf = creature.Physics.LocalTransform; tf.Translation = balloon.LocalTransform.Translation; creature.Physics.LocalTransform = tf; } } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); } envoy.DistributeGoods(); natives.TradeEnvoys.Add(envoy); world.MakeAnnouncement(new DwarfCorp.Gui.Widgets.QueuedAnnouncement { Text = String.Format("Trade envoy from {0} has arrived!", natives.Name), ClickAction = (gui, sender) => { if (envoy.Creatures.Count > 0) { envoy.Creatures.First().ZoomToMe(); World.MakeWorldPopup(String.Format("Traders from {0} ({1}) have entered our territory. They will try to get to our balloon port to trade with us.", natives.Name, natives.Race.Name), envoy.Creatures.First().Physics, -10); } }, ShouldKeep = () => { return(envoy.ExpiditionState == Expedition.State.Arriving); } }); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_positive_generic, 0.15f); world.Tutorial("trade"); if (!String.IsNullOrEmpty(natives.Race.TradeMusic)) { SoundManager.PlayMusic(natives.Race.TradeMusic); } return(envoy); }