public void Update(DwarfTime time) { Minions.RemoveAll(m => m.IsDead); if (HandleThreatsTimer == null) { HandleThreatsTimer = new Timer(1.0f, false, Timer.TimerMode.Real); } HandleThreatsTimer.Update(time); if (HandleThreatsTimer.HasTriggered) { HandleThreats(); } if (World.ComponentManager.NumComponents() > 0) { OwnedObjects.RemoveAll(obj => obj.IsDead || obj.Parent == null || !obj.Manager.HasComponent(obj.GlobalID)); } #region Update Expeditions foreach (TradeEnvoy envoy in TradeEnvoys) { envoy.Update(World); } var hadFactions = TradeEnvoys.Count > 0; TradeEnvoys.RemoveAll(t => t == null || t.ShouldRemove); if (hadFactions && TradeEnvoys.Count == 0) { var music = World.Time.IsDay() ? "main_theme_day" : "main_theme_night"; SoundManager.PlayMusic(music); } foreach (var party in WarParties) { party.Update(World); } WarParties.RemoveAll(w => w.ShouldRemove); #endregion }
public void UpdateTradeEnvoys(Faction faction) { foreach (TradeEnvoy envoy in faction.TradeEnvoys) { if (envoy.ExpiditionState == Expedition.State.Trading) { if (envoy.UpdateWaitTimer(World.Time.CurrentDate)) { World.MakeAnnouncement(String.Format("The envoy from {0} is leaving.", envoy.OwnerFaction.Name)); RecallEnvoy(envoy); } } envoy.Creatures.RemoveAll(creature => creature.IsDead); if (envoy.DeathTimer.Update(faction.World.Time.CurrentDate)) { envoy.Creatures.ForEach((creature) => creature.GetRoot().Die()); } Diplomacy.Politics politics = faction.World.Diplomacy.GetPolitics(faction, envoy.OtherFaction); if (politics.GetCurrentRelationship() == Relationship.Hateful) { World.MakeAnnouncement(String.Format("The envoy from {0} is leaving.", envoy.OwnerFaction.Name)); RecallEnvoy(envoy); } else { if (envoy.Creatures.Any( // TODO (mklingen) why do I need this null check? creature => creature.Creature != null && envoy.OtherFaction.Designations.IsDesignation(creature.Physics, DesignationType.Attack))) { if (!politics.HasEvent("You attacked our trade delegates")) { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = -1.0f, Description = "You attacked our trade delegates", Duration = new TimeSpan(1, 0, 0, 0), Time = faction.World.Time.CurrentDate }); } else { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = -2.0f, Description = "You attacked our trade delegates more than once", Duration = new TimeSpan(1, 0, 0, 0), Time = faction.World.Time.CurrentDate }); } } } if (!envoy.ShouldRemove && envoy.ExpiditionState == Expedition.State.Arriving) { foreach (CreatureAI creature in envoy.Creatures) { Room tradePort = envoy.OtherFaction.GetNearestRoomOfType(BalloonPort.BalloonPortName, creature.Position); if (tradePort == null) { World.MakeAnnouncement("We need a balloon trade port to trade.", null, () => { return(envoy.OtherFaction.GetNearestRoomOfType(BalloonPort.BalloonPortName, creature.Position) == null); }); World.Tutorial("trade"); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.5f); RecallEnvoy(envoy); break; } if (creature.Tasks.Count == 0) { TradeEnvoy envoy1 = envoy; creature.Tasks.Add(new TradeTask(tradePort, envoy1)); } if (!tradePort.IsRestingOnZone(creature.Position)) { continue; } if (envoy.ExpiditionState != Expedition.State.Trading || !envoy.IsTradeWidgetValid()) { envoy.MakeTradeWidget(World); } envoy.ExpiditionState = Expedition.State.Trading; break; } } else if (envoy.ExpiditionState == Expedition.State.Leaving) { BoundingBox worldBBox = faction.World.ChunkManager.Bounds; foreach (CreatureAI creature in envoy.Creatures) { if (creature.Tasks.Count == 0) { creature.LeaveWorld(); } } foreach (CreatureAI creature in envoy.Creatures) { if (MathFunctions.Dist2D(worldBBox, creature.Position) < 2.0f) { creature.GetRoot().Delete(); } } } else { if (!envoy.IsTradeWidgetValid()) { envoy.MakeTradeWidget(World); } } if (envoy.Creatures.All(creature => creature.IsDead)) { envoy.ShouldRemove = true; World.GoalManager.OnGameEvent(new Goals.Triggers.TradeEnvoyKilled { PlayerFaction = envoy.OtherFaction, OtherFaction = envoy.OwnerFaction }); } } bool hadFactions = faction.TradeEnvoys.Count > 0; faction.TradeEnvoys.RemoveAll(t => t == null || t.ShouldRemove); if (hadFactions && faction.TradeEnvoys.Count == 0) { var music = World.Time.IsDay() ? "main_theme_day" : "main_theme_night"; SoundManager.PlayMusic(music); } }
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); }