Esempio n. 1
0
        public void UpdateTradeEnvoys()
        {
            foreach (TradeEnvoy envoy in TradeEnvoys)
            {
                Diplomacy.Politics politics = PlayState.Diplomacy.GetPolitics(this, envoy.OtherFaction);
                if (politics.GetCurrentRelationship() == Relationship.Hateful)
                {
                    RecallEnvoy(envoy);
                }
                else
                {
                    if (!envoy.Creatures.Any(creature => envoy.OtherFaction.AttackDesignations.Contains(creature.Physics)))
                    {
                        continue;
                    }

                    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        = PlayState.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        = PlayState.Time.CurrentDate
                        });
                    }
                }

                if (envoy.Creatures.All(creature => creature.IsDead))
                {
                    envoy.ShouldRemove = true;
                }
            }

            TradeEnvoys.RemoveAll(t => t.ShouldRemove);
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public void UpdateTradeEnvoys(Faction faction)
        {
            foreach (Faction.TradeEnvoy envoy in faction.TradeEnvoys)
            {
                if (envoy.DeathTimer.Update(PlayState.Time.CurrentDate))
                {
                    envoy.Creatures.ForEach((creature) => creature.GetRootComponent().Die());
                }

                Diplomacy.Politics politics = PlayState.ComponentManager.Diplomacy.GetPolitics(faction, envoy.OtherFaction);
                if (politics.GetCurrentRelationship() == Relationship.Hateful)
                {
                    RecallEnvoy(envoy);
                }
                else
                {
                    if (envoy.Creatures.Any(
                            creature => envoy.OtherFaction.AttackDesignations.Contains(creature.Physics)))
                    {
                        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        = PlayState.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        = PlayState.Time.CurrentDate
                            });
                        }
                    }
                }

                if (!envoy.ShouldRemove && envoy.ExpiditionState == Faction.Expidition.State.Arriving)
                {
                    foreach (CreatureAI creature in envoy.Creatures)
                    {
                        Room tradePort = envoy.OtherFaction.GetNearestRoomOfType(BalloonPort.BalloonPortName,
                                                                                 creature.Position);

                        if (creature.Tasks.Count == 0)
                        {
                            creature.Tasks.Add(new ActWrapperTask(new GoToZoneAct(creature, tradePort))
                            {
                                Name = "Go to trade port.", Priority = Task.PriorityType.Urgent
                            });
                        }

                        if (!tradePort.IsRestingOnZone(creature.Position))
                        {
                            continue;
                        }

                        envoy.ExpiditionState = Faction.Expidition.State.Trading;
                        if (GameState.Game.StateManager.States.ContainsKey("DiplomacyState_" + faction.Name))
                        {
                            DiplomacyState state = GameState.Game.StateManager.States["DiplomacyState_" + faction.Name] as DiplomacyState;
                            if (state != null)
                            {
                                state.Envoy     = envoy;
                                state.Resources = envoy.TradeGoods;
                            }
                            GameState.Game.StateManager.PushState("DiplomacyState_" + faction.Name);
                        }
                        else
                        {
                            GameState.Game.StateManager.PushState(new DiplomacyState(GameState.Game,
                                                                                     GameState.Game.StateManager,
                                                                                     (PlayState)GameState.Game.StateManager.GetState <PlayState>("PlayState"), envoy)
                            {
                                Name  = "DiplomacyState_" + faction.Name,
                                Envoy = envoy
                            });
                        }
                        break;
                    }
                }
                else if (envoy.ExpiditionState == Faction.Expidition.State.Leaving)
                {
                    BoundingBox worldBBox = PlayState.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.GetRootComponent().Delete();
                            creature.IsDead = true;
                        }
                    }
                }

                if (envoy.Creatures.All(creature => creature.IsDead))
                {
                    envoy.ShouldRemove = true;
                }
            }

            faction.TradeEnvoys.RemoveAll(t => t.ShouldRemove);
        }