public override void MissionLogic()
        {
            base.MissionLogic();

            if (ObjectiveIndex > 2 &&
                ObjectiveIndex <= 6 &&
                !Game.player.HyperspeedOn)
            {
                if (Vector2.Distance(Game.player.position, rebelShips[1].position) > 500)
                {
                    PopupHandler.DisplayPortraitMessage(PortraitID.RebelPilot, "Hey! Where are you going? The freighter will be here any minute now.");
                    Game.player.BounceBack();
                }

                if (ControlManager.CheckPress(RebindableKeys.Pause) &&
                    GameStateManager.currentState.Equals("OverworldState"))
                {
                    PopupHandler.DisplaySelectionMenu("Do you want to skip waiting?",
                                                      new List <string>()
                    {
                        "Yes", "No"
                    },
                                                      new List <System.Action>()
                    {
                        delegate
                        {
                            SkipForward();
                        },
                        delegate {}
                    });
                }
            }
        }
        protected override void SetupObjectives()
        {
            objectives.Clear();

            Objectives.Add(new TimedMessageObjective(Game, this, ObjectiveDescriptions[0],
                                                     3000, 3000, PortraitID.Sair, GetEvent((int)EventID.TravelingToAsteroids).Text));

            Objectives.Add(new CloseInOnLocationObjective(Game, this, ObjectiveDescriptions[0],
                                                          250, new EventTextCapsule(GetEvent((int)EventID.TalkWithCaptain1), null, EventTextCanvas.MessageBox,
                                                                                    new List <PortraitID>()
            {
                PortraitID.AllianceCaptain, PortraitID.Sair, PortraitID.AllianceCaptain
            },
                                                                                    new List <int> {
                2, 3
            })));

            CloseInOnLocationObjective talkToCaptainObjective = new CloseInOnLocationObjective(Game, this, ObjectiveDescriptions[0], 100,
                                                                                               new EventTextCapsule(GetEvent((int)EventID.TalkWithCaptain2), null, EventTextCanvas.MessageBox, PortraitID.AllianceCaptain));

            Objectives.Add(talkToCaptainObjective);

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               delegate
            {
                ReplaceObjectiveText(TextType.Event, ActionKeyID,
                                     "'" + ControlManager.GetKeyName(RebindableKeys.Action1) + "'-key", (int)EventID.InLevel2);
            },
                                               delegate { },
                                               delegate { return(true); },
                                               delegate { return(false); }));

            ShootingLevelObjective shootingLevelObjective = new ShootingLevelObjective(Game, this, ObjectiveDescriptions[0],
                                                                                       "RebelsInTheMeteors", LevelStartCondition.Immediately,
                                                                                       new EventTextCapsule(GetEvent((int)EventID.AfterCombat),
                                                                                                            null,
                                                                                                            EventTextCanvas.MessageBox,
                                                                                                            PortraitID.AllianceCaptain));

            shootingLevelObjective.SetFailLogic(
                delegate
            {
                Game.player.position  = Game.stateManager.overworldState.GetMiningOutpost.GetGameObject("mining asteroids").position;
                Game.camera.cameraPos = Game.player.position;
                PopupHandler.DisplayPortraitMessage(PortraitID.AllianceCaptain, "Too bad. Talk to me to try again.");
                talkToCaptainObjective.Reset();
                shootingLevelObjective.Reset();
                ObjectiveIndex = 2;
            }
                );

            Objectives.Add(shootingLevelObjective);

            Objectives.Add(new TimedMessageObjective(Game, this, ObjectiveDescriptions[1],
                                                     3000, 3000, PortraitID.Sair, GetEvent((int)EventID.TravelingBack).Text));

            objectives.Add(new ArriveAtLocationObjective(Game, this, ObjectiveDescriptions[1]));
        }
 //The function called when the class is activated.
 //For events inheriting from the "PointLevelEvent"-class
 //this is all that is executed before the event is removed.
 //Check "Swarm"-class to see how lasting events can look.
 public override void Run(GameTime gameTime)
 {
     if (portrait != PortraitID.None)
     {
         PopupHandler.DisplayPortraitMessage(portrait, message);
     }
     else
     {
         PopupHandler.DisplayMessage(message);
     }
     TriggerStatus = Trigger.Completed;
 }
 private void SkipForward()
 {
     game.player.position  = Destination.position;
     game.camera.cameraPos = game.player.position;
     PopupHandler.SkipRealTimeMessages();
     ships[0].HasArrived = true;
     for (int i = 0; i < portraits.Count; i++)
     {
         PopupHandler.DisplayPortraitMessage(portraits[0], portraitTriggers[0], timedMessages.Keys.First());
         portraits.RemoveAt(0);
         portraitTriggers.RemoveAt(0);
         timedMessages.Remove(timedMessages.Keys.First());
     }
     skip = true;
 }
        private void StartEnemyLevel(int enemyIndex, string level)
        {
            game.stateManager.shooterState.BeginLevel(level);
            game.stateManager.shooterState.CurrentLevel.SetFreighterMaxHP(shipToDefendMaxHP);
            game.stateManager.shooterState.CurrentLevel.SetFreighterHP(shipToDefendMaxHP);
            enemies.RemoveAt(enemyIndex);

            if (enemyMessages.Count > 0)
            {
                if (enemyPortraits[0] != PortraitID.None)
                {
                    PopupHandler.DisplayPortraitMessage(enemyPortraits[0], enemyMessages[0]);
                }
                else
                {
                    PopupHandler.DisplayMessage(enemyMessages[0]);
                }
                enemyMessages.RemoveAt(0);
                enemyPortraits.RemoveAt(0);
            }
        }
        public override void MissionLogic()
        {
            base.MissionLogic();

            if (StatsManager.gameMode != GameMode.Develop &&
                !CollisionDetection.IsPointInsideCircle(Game.player.position, MissionArea, MissionAreaRadius) &&
                !Game.player.HyperspeedOn)
            {
                PopupHandler.DisplayPortraitMessage(PortraitID.Berr, "Where are you going? Follow the blinking gold dot on you radar to get to the mining station.");
                Game.player.BounceBack();
            }

            if (downedShips == -1 &&
                Game.stateManager.shooterState.GetLevel("RebelsInTheMeteors").IsMapCompleted)
            {
                downedShips = Game.stateManager.shooterState.GetLevel("RebelsInTheMeteors").enemiesKilledByPlayer;
                int bonus = downedShips * DownedShipsMultiplier;
                ReplaceObjectiveText(TextType.Completed, MoneyID, MoneyReward);
                ReplaceObjectiveText(TextType.Completed, BonusID, bonus);
                moneyReward += bonus;
            }
        }
Beispiel #7
0
        public virtual void OnCompleted()
        {
            isOnCompletedCalled = true;

            if (objectiveCompletedEventText != null && objectiveCompletedEventText.Text != "")
            {
                if (eventTextCanvas.Equals(EventTextCanvas.BaseState))
                {
                    mission.MissionHelper.ShowEvent(objectiveCompletedEventText);
                }
                else if (eventTextCanvas.Equals(EventTextCanvas.MessageBox))
                {
                    if (usePortraits)
                    {
                        if (portraits != null &&
                            portraits.Count > 0)
                        {
                            PopupHandler.DisplayPortraitMessage(portraits, portraitTriggers, objectiveCompletedEventText.Text);
                        }
                        else
                        {
                            PopupHandler.DisplayPortraitMessage(portraits[0], objectiveCompletedEventText.Text);
                        }
                    }
                    else
                    {
                        PopupHandler.DisplayMessage(objectiveCompletedEventText.Text);
                    }
                }
            }

            if (completedLogic != null)
            {
                completedLogic.Invoke();
            }
        }
        private void UpdateTutorialMessages(GameTime gameTime)
        {
            if (!hasEnteredStation && GameStateManager.currentState.Equals("StationState") &&
                game.stateManager.stationState.SubStateManager.ButtonControl == ButtonControl.Menu)
            {
                hasEnteredStation = true;
                DisplayTutorialMessage("You can disable tutorial messages in the options menu.", TutorialImage.MenuControls);
            }

            if (!hasEnteredOverworld && GameStateManager.currentState.Equals("OverworldState"))
            {
                tempTimer -= gameTime.ElapsedGameTime.Milliseconds;

                if (tempTimer < 0)
                {
                    tempTimer           = 50;
                    hasEnteredOverworld = true;

                    DisplayTutorialImage(TutorialImage.OverworldControls);
                }
            }

            else if (!coordinatesDisplayed &&
                     hasEnteredOverworld &&
                     PopupHandler.TextBufferEmpty)
            {
                coordinatesDisplayed = true;

                DisplayTutorialMessage("Your current objective is to go to coordinates (2450, 700). To find that location, follow the blinking dot on your radar. Main missions are represented by gold-colored dots and secondary missions by silver-colored dots.",
                                       TutorialImage.Radar);
            }

            Vector2 highfenceBeaconPosition = game.stateManager.overworldState.GetBeacon("Highfence Beacon").position;

            if (!hasEnteredHighfenceBeaconArea &&
                Vector2.Distance(game.player.position, highfenceBeaconPosition) < BeaconTutorialActivationRadius)
            {
                hasEnteredHighfenceBeaconArea = true;
                DisplayTutorialMessage("This is a 'beacon'. Beacons are used for traveling quickly between planets, but they need to be activated before use. Activate a beacon by flying close to it!");
            }

            if (!hasEnteredVerticalShooter && GameStateManager.currentState.Equals("ShooterState"))
            {
                tempTimer2 -= gameTime.ElapsedGameTime.Milliseconds;

                if (tempTimer2 < 0)
                {
                    tempTimer2 = 500;

                    hasEnteredVerticalShooter = true;
                    DisplayTutorialMessage(new List <String> {
                        "You can rebind the keys in the options menu.",
                        "Down at the bottom-left you can find information about the current level objective, your active weapons and on your ship's health, energy and shields."
                    },
                                           new List <TutorialImage> {
                        TutorialImage.CombatControls, TutorialImage.CombatBars
                    },
                                           new List <int> {
                        1
                    });
                }
            }

            if (!hasEnteredShooterWithShield && !(ShipInventoryManager.equippedShield is EmptyShield) &&
                GameStateManager.currentState.Equals("ShooterState"))
            {
                tempTimer2 -= gameTime.ElapsedGameTime.Milliseconds;

                if (tempTimer2 < 0)
                {
                    tempTimer2 = 500;

                    hasEnteredShooterWithShield = true;
                    DisplayTutorialMessage("You now have a shield to protect your ship's hull! If you take a hit, the shield will absorb the damage if it has enough power.");
                }
            }

            if (equipShieldTutorial &&
                !equipShieldTutorialFinished)
            {
                game.stateManager.stationState.SubStateManager.ShopMenuState.DisplayBuyAndEquip = false;
                switch (equipShieldProgress)
                {
                case 0:
                    if (GameStateManager.currentState.Equals("StationState") &&
                        game.stateManager.stationState.Station.name.Equals("Highfence Shop"))
                    {
                        string message = "[Alliance Pilot] \"Start by selecting 'Buy/Sell' and pressing 'Enter'.";

                        if (!hasRecievedTutorialMoney)
                        {
                            message += " Here is two hundred Crebits, it should cover the cost for the shield.\"";
                        }

                        PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, message);

                        if (!hasRecievedTutorialMoney)
                        {
                            StatsManager.Crebits += 200;
                            PopupHandler.DisplayMessage("You recieved 200 Crebits.");
                            hasRecievedTutorialMoney = true;
                        }

                        equipShieldProgress = 1;
                    }
                    break;

                case 1:
                    if (GameStateManager.currentState.Equals("StationState") &&
                        game.stateManager.stationState.Station.name.Equals("Highfence Shop") &&
                        game.stateManager.stationState.SubStateManager.ActiveMenuState.Equals(game.stateManager.stationState.SubStateManager.ShopMenuState))
                    {
                        PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, "[Alliance Pilot] \"Select the 'Basic shield' in the column to the right and select 'Buy'.\"");
                        equipShieldProgress = 2;
                    }
                    break;

                case 2:
                    if (GameStateManager.currentState.Equals("StationState") &&
                        game.stateManager.stationState.Station.name.Equals("Highfence Shop") &&
                        game.stateManager.stationState.SubStateManager.ActiveMenuState.Equals(game.stateManager.stationState.SubStateManager.ShopMenuState) &&
                        ShipInventoryManager.ownedShields.Count > 0)
                    {
                        PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, "[Alliance Pilot] \"Good! Now exit the shop by selecting and pressing 'Go Back' and return to the overworld!\"");
                        equipShieldProgress = 3;
                    }
                    break;

                case 3:
                    if (GameStateManager.currentState.Equals("OverworldState"))
                    {
                        PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, "[Alliance Pilot] \"Now, press 'I' to access your inventory.\"");
                        equipShieldProgress = 4;
                    }
                    break;

                case 4:
                    if (GameStateManager.currentState.Equals("ShipManagerState"))
                    {
                        PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, "[Alliance Pilot] \"To equip your shield, select the shield slot and press 'Enter' to select from your list of available shields.\"");
                        equipShieldProgress = 5;
                    }
                    break;

                case 5:
                    if (GameStateManager.currentState.Equals("ShipManagerState") &&
                        game.stateManager.shipManagerState.IsShieldSlotSelected)
                    {
                        PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, "[Alliance Pilot] \"Now, press 'Enter' again to equip the selected shield.\"");
                        equipShieldProgress = 6;
                    }
                    break;

                case 6:
                    if (!(ShipInventoryManager.equippedShield is EmptyShield))
                    {
                        PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, "[Alliance Pilot] \"Good! Now your shield is equipped! What parts you have equipped is crucial for your success. Come back here often and try different combinations of ship parts.\"#\"Now, exit the inventory by pressing 'Escape' and return to me!\"");
                        equipShieldTutorialFinished = true;
                    }
                    break;
                }

                if (equipShieldProgress < 2 &&
                    ShipInventoryManager.OwnedShields.Count > 0)
                {
                    PopupHandler.DisplayPortraitMessage(PortraitID.AlliancePilot, "You already bought a shield? Okay, let me tell you how to equip it! Start by pressing 'I' to access your inventory.");
                    equipShieldProgress = 4;
                }
            }

            if (equipShieldTutorialFinished &&
                game.stateManager.stationState.SubStateManager.ShopMenuState.DisplayBuyAndEquip == false)
            {
                game.stateManager.stationState.SubStateManager.ShopMenuState.DisplayBuyAndEquip = true;
            }

            if (ShipInventoryManager.HasItemOfKind("LongShot") &&
                MissionManager.GetMission(MissionID.Main3_DefendColony).MissionState.Equals(StateOfMission.Unavailable) &&
                GameStateManager.currentState.Equals("OverworldState") && !longShotTutorialActivated)
            {
                tempTimer3 -= gameTime.ElapsedGameTime.Milliseconds;

                if (tempTimer3 <= 0)
                {
                    tempTimer3 = 1000;
                    longShotTutorialActivated = true;
                    DisplayTutorialMessage(new List <string>()
                    {
                        String.Format("You have recieved your first long-range weapon: 'LongShot'. You can have two weapons equipped at a time, and you can toggle between them in combat using '{0}'.", ControlManager.GetKeyName(RebindableKeys.Action2)),
                        "Try accessing your inventory with 'I' and equip LongShot on one slot and SpreadBullet on the other. Then you can vary your strategy in combat depending on which enemies you encounter."
                    });
                }
            }

            if (ShipInventoryManager.OwnedSecondary.Count > 0 && GameStateManager.currentState.Equals("OverworldState") &&
                !secondaryWeaponTutorialDisplayed)
            {
                tempTimer3 -= gameTime.ElapsedGameTime.Milliseconds;

                if (tempTimer3 <= 0)
                {
                    tempTimer3 = 1000;
                    secondaryWeaponTutorialDisplayed = true;
                    DisplayTutorialMessage("You have acquired your first secondary weapon! Don't forget to equip it if you havn't done so already. Secondary weapons are fired automatically and don't use energy, so they are very handy!");
                }
            }

            if (isAMissionFailed && GameStateManager.currentState.Equals("OverworldState") &&
                !hasDisplayedSkipMessage)
            {
                tempTimer2 -= gameTime.ElapsedGameTime.Milliseconds;

                if (tempTimer2 < 0)
                {
                    tempTimer2 = 500;

                    hasDisplayedSkipMessage = true;
                    DisplayTutorialMessage("When you fail a mission, you can replay most of them by going back to where they started. Press 'Escape' to skip dialogs and mission events you have already seen.");
                }
            }
        }
Beispiel #9
0
        protected override void SetupObjectives()
        {
            objectives.Clear();

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               delegate { SetupAllyShips(allyShips1, destinations[0].position, destinations[1]); },
                                               delegate { },
                                               delegate { return(true); },
                                               delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               new EventTextCapsule(GetEvent((int)EventID.OutsideRebelStation1), null, EventTextCanvas.MessageBox, PortraitID.Sair),
                                               delegate { },
                                               delegate { },
                                               delegate { return(GameStateManager.currentState.ToLower().Equals("overworldstate")); },
                                               delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               new EventTextCapsule(GetEvent((int)EventID.AtRebelRendezvous), null, EventTextCanvas.MessageBox, PortraitID.RebelTroopLeader),
                                               delegate
            {
                readyToLeave      = false;
                allyShipRectangle = new Rectangle(
                    (int)allyShips1[0].position.X - AllyShipRectOffset,
                    (int)allyShips1[0].position.Y - AllyShipRectOffset,
                    AllyShipRectWidth, AllyShipRectHeight);

                PopupHandler.DisplayPortraitMessage(PortraitID.Rok, "[Rok] \"Talk to the ships waiting nearby our base when you're ready to leave.\"");
            },
                                               delegate
            {
                if (CollisionDetection.IsRectInRect(Game.player.Bounds, allyShipRectangle) &&
                    (ControlManager.CheckPress(RebindableKeys.Action1) ||
                     ControlManager.CheckKeyPress(Keys.Enter)) &&
                    GameStateManager.currentState.Equals("OverworldState"))
                {
                    PopupHandler.DisplaySelectionMenu("[Rebel Pilot] Ready to go?",
                                                      new List <string>()
                    {
                        "Yes", "No"
                    },
                                                      new List <System.Action>()
                    {
                        delegate { readyToLeave = true; },
                        delegate { readyToLeave = false; }
                    });
                }
            },
                                               delegate { return(readyToLeave); },
                                               delegate { return(false); }));

            //objectives.Add(new CloseInOnLocationObjective(Game, this, ObjectiveDescriptions[0],
            //    200, new EventTextCapsule(GetEvent((int)EventID.AtRebelRendezvous), null, EventTextCanvas.MessageBox, PortraitID.RebelTroopLeader)));

            AutoPilotObjective autoPilotObjective = new AutoPilotObjective(Game, this, ObjectiveDescriptions[0], AutoPilotSpeed,
                                                                           allyShips1, destinations[3].position,
                                                                           new EventTextCapsule(GetEvent((int)EventID.ArriveAtScienceStation),
                                                                                                null,
                                                                                                EventTextCanvas.MessageBox, PortraitID.RebelTroopLeader), false);

            autoPilotObjective.Initialize();
            autoPilotObjective.SetTimedMessages(new Dictionary <string, List <float> >
            {
                { GetEvent((int)EventID.TravelToScienceStation1).Text, new List <float> {
                      5000, 3000
                  } },
                { GetEvent((int)EventID.TravelToScienceStation2).Text, new List <float> {
                      1000, 3000
                  } },
                { GetEvent((int)EventID.TravelToScienceStation3).Text, new List <float> {
                      13000, 3000
                  } }
            }
                                                , new List <List <PortraitID> >()
            {
                new List <PortraitID> {
                    PortraitID.Ai
                },
                new List <PortraitID> {
                    PortraitID.Sair
                },
                new List <PortraitID> {
                    PortraitID.Ai
                }
            }
                                                , new List <List <int> > {
                new List <int> {
                }, new List <int> {
                }, new List <int> {
                }
            });

            objectives.Add(autoPilotObjective);

            objectives.Add(new ShootingLevelObjective(Game, this, ObjectiveDescriptions[0],
                                                      "Itnos_1", LevelStartCondition.TextCleared,
                                                      new EventTextCapsule(GetEvent((int)EventID.AfterLevel1),
                                                                           null, EventTextCanvas.MessageBox, PortraitID.RebelTroopLeader)));

            objectives.Add(new ArriveAtLocationObjective(Game, this, ObjectiveDescriptions[0],
                                                         new EventTextCapsule(GetEvent((int)EventID.InsideScienceStation1), null, EventTextCanvas.MessageBox, PortraitID.Sair)));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               new EventTextCapsule(GetEvent((int)EventID.InsideScienceStation2), null, EventTextCanvas.MessageBox),
                                               delegate { }, delegate { }, delegate { return(true); }, delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               new EventTextCapsule(GetEvent((int)EventID.InsideScienceStation3), null, EventTextCanvas.MessageBox, PortraitID.Ente),
                                               delegate { }, delegate { }, delegate { return(true); }, delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[1],
                                               new EventTextCapsule(GetEvent((int)EventID.OutsideScienceStation), null, EventTextCanvas.MessageBox, PortraitID.Sair),
                                               delegate
            {
                RemoveShips();
            }, delegate { },
                                               delegate
            {
                return(GameStateManager.currentState == "OverworldState");
            },
                                               delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[1],
                                               new EventTextCapsule(GetEvent((int)EventID.BreakThroughLevel), null, EventTextCanvas.MessageBox, PortraitID.Sair),
                                               delegate
            {
                hangarAttackTime = StatsManager.PlayTime.GetFutureOverworldTime(2000);
            },
                                               delegate { },
                                               delegate
            {
                return(StatsManager.PlayTime.HasOverworldTimePassed(hangarAttackTime));
            },
                                               delegate { return(false); }));

            objectives.Add(new ShootingLevelObjective(Game, this, ObjectiveDescriptions[1],
                                                      "Itnos_2", LevelStartCondition.TextCleared,
                                                      new EventTextCapsule(GetEvent((int)EventID.AfterLevel2), null, EventTextCanvas.MessageBox, PortraitID.RebelTroopLeader)));

            objectives.Add(new CloseInOnLocationObjective(Game, this, ObjectiveDescriptions[1], 200,
                                                          new EventTextCapsule(GetEvent((int)EventID.OutsideRebelStation2), null, EventTextCanvas.MessageBox, PortraitID.Ente)));

            objectives.Add(new ArriveAtLocationObjective(Game, this, ObjectiveDescriptions[1]));
        }
Beispiel #10
0
        public override void OnFailed()
        {
            base.OnFailed();

            PopupHandler.DisplayPortraitMessage(PortraitID.RebelTroopLeader, "[Mineral researcher] Too bad. Fly back to Lavis Station and talk to me to try again.");
        }
        protected override void SetupObjectives()
        {
            float time = 0;

            objectives.Clear();

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               delegate { SetupAllyShips(allyShips1, fortrunStation.position, newNorrland); },
                                               delegate { },
                                               delegate { return(true); },
                                               delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               new EventTextCapsule(GetEvent((int)EventID.OutsideFortrun1), null, EventTextCanvas.MessageBox, PortraitID.Sair),
                                               delegate
            {
                time = StatsManager.PlayTime.GetFutureOverworldTime(500);
            },
                                               delegate { },
                                               delegate { return(StatsManager.PlayTime.HasOverworldTimePassed(time)); },
                                               delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               new EventTextCapsule(GetEvent((int)EventID.OutsideFortrun2), null, EventTextCanvas.MessageBox, PortraitID.Ai),
                                               delegate
            {
                readyToLeave      = false;
                allyShipRectangle = new Rectangle(
                    (int)allyShips1[0].position.X - AllyShipRectOffset,
                    (int)allyShips1[0].position.Y - AllyShipRectOffset,
                    AllyShipRectWidth, AllyShipRectHeight);

                PopupHandler.DisplayPortraitMessage(PortraitID.Ai, "[Ai] \"Talk to the alliance ships waiting outside Fortrun when you're ready to leave.\"#\"Don't forget to stop by the shop and upgrade your equipment if you have not done so already!\"");
            },
                                               delegate
            {
                if (CollisionDetection.IsRectInRect(Game.player.Bounds, allyShipRectangle) &&
                    (ControlManager.CheckPress(RebindableKeys.Action1) ||
                     ControlManager.CheckKeyPress(Keys.Enter)) &&
                    GameStateManager.currentState.Equals("OverworldState"))
                {
                    PopupHandler.DisplaySelectionMenu("[Ai] Ready to go?",
                                                      new List <string>()
                    {
                        "Yes", "No"
                    },
                                                      new List <System.Action>()
                    {
                        delegate { readyToLeave = true; },
                        delegate { readyToLeave = false; }
                    });
                }
            },
                                               delegate { return(readyToLeave); },
                                               delegate { return(false); }));

            AutoPilotObjective autoPilotObjective1 = new AutoPilotObjective(Game, this, ObjectiveDescriptions[1], AutoPilotSpeed,
                                                                            allyShips1, fortrunStation.position,
                                                                            new EventTextCapsule(GetEvent((int)EventID.OutsideNewNorrland), null, EventTextCanvas.MessageBox, PortraitID.Ai));

            autoPilotObjective1.Initialize();
            autoPilotObjective1.SetTimedMessages(new Dictionary <string, List <float> >
            {
                { GetEvent((int)EventID.ToNewNorrland1).Text, new List <float> {
                      3000, 3000
                  } },
                { GetEvent((int)EventID.ToNewNorrland2).Text, new List <float> {
                      20000, 3000
                  } }
            },
                                                 null, null);

            objectives.Add(autoPilotObjective1);

            objectives.Add(new ShootingLevelObjective(Game, this, ObjectiveDescriptions[1],
                                                      "DefendColonyBreak", LevelStartCondition.TextCleared));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[0],
                                               new EventTextCapsule(GetEvent((int)EventID.FirstLevelCompleted), null, EventTextCanvas.MessageBox, PortraitID.Ai),
                                               delegate
            {
                Game.stateManager.GotoPlanetSubScreen("New Norrland", "Overview");
            },
                                               delegate { },
                                               delegate { return(true); },
                                               delegate { return(false); }));

            objectives.Add(new ShootingLevelObjective(Game, this, ObjectiveDescriptions[1],
                                                      "DefendColonyHold", LevelStartCondition.TextCleared,
                                                      new EventTextCapsule(GetEvent((int)EventID.SecondLevelCompleted), null, EventTextCanvas.MessageBox, PortraitID.Ai)));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[1],
                                               delegate
            {
                RemoveShips(allyShips1);
                SetupAllyShips(allyShips2,
                               new Vector2(newNorrland.position.X + 0, newNorrland.position.Y - 625),
                               fortrunStation);
            },
                                               delegate { },
                                               delegate { return(true); },
                                               delegate { return(false); }));

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[2],
                                               new EventTextCapsule(new EventText("[Ai] \"Let's go\""), null, EventTextCanvas.MessageBox, PortraitID.Ai),
                                               delegate
            {
                allyShipRectangle = new Rectangle(
                    (int)allyShips2[0].position.X - AllyShipRectOffset,
                    (int)allyShips2[0].position.Y - AllyShipRectOffset,
                    AllyShipRectWidth, AllyShipRectHeight);
                readyToLeave = false;

                PopupHandler.DisplayPortraitMessage(PortraitID.Ai, "[Ai] \"Talk to the alliance ships waiting outside New Norrland when you're ready to leave.\"");
            },
                                               delegate
            {
                if (CollisionDetection.IsRectInRect(Game.player.Bounds, allyShipRectangle) &&
                    (ControlManager.CheckPress(RebindableKeys.Action1) ||
                     ControlManager.CheckKeyPress(Keys.Enter)) &&
                    GameStateManager.currentState.Equals("OverworldState"))
                {
                    PopupHandler.DisplaySelectionMenu("[Ai] Ready to head back?",
                                                      new List <string>()
                    {
                        "Yes", "No"
                    },
                                                      new List <System.Action>()
                    {
                        delegate { readyToLeave = true; },
                        delegate { readyToLeave = false; }
                    });
                }
            },
                                               delegate { return(readyToLeave); },
                                               delegate { return(false); }));

            AutoPilotObjective autoPilotObjective = new AutoPilotObjective(Game, this, ObjectiveDescriptions[3], AutoPilotSpeed2,
                                                                           allyShips2, newNorrland.position, false);

            autoPilotObjective.Initialize();
            autoPilotObjective.SetActivateRealTimeIndex(2);
            autoPilotObjective.SetTimedMessages(
                new Dictionary <string, List <float> >
            {
                { GetEvent((int)EventID.ToFortrun1).Text, new List <float> {
                      7000, 3000
                  } },
                { GetEvent((int)EventID.ToFortrun2).Text, new List <float> {
                      1000, 3000
                  } },
                { GetEvent((int)EventID.ToFortrun3).Text, new List <float> {
                      4000, 3000
                  } },
            },
                new List <List <PortraitID> >()
            {
                new List <PortraitID> {
                    PortraitID.Sair, PortraitID.CommonCitizen
                },
                new List <PortraitID> {
                    PortraitID.Ai
                },
                new List <PortraitID> {
                    PortraitID.Sair
                }
            },
                new List <List <int> > {
                new List <int> {
                    1
                }, new List <int> {
                }, new List <int> {
                }
            });

            objectives.Add(autoPilotObjective);

            objectives.Add(new CustomObjective(Game, this, ObjectiveDescriptions[3],
                                               delegate
            {
                RemoveShips(allyShips2);
                Game.stateManager.GotoStationSubScreen("Fortrun Station", "Mission");
            },
                                               delegate { },
                                               delegate { return(true); },
                                               delegate { return(false); }));

            objectives.Add(new ArriveAtLocationObjective(Game, this, ObjectiveDescriptions[3]));
        }
        public override void OnFailed()
        {
            base.OnFailed();

            PopupHandler.DisplayPortraitMessage(PortraitID.Ente, "[Crazy scientist] \"Haha! Oh, I mean, sorry. Look what a mess you are. Of course you weren't able to make it through the level. But you are welcome to try again. If you do, maybe you too will be a legend one day.\"");
        }
        public override void Update(PlayTime playTime)
        {
            base.Update(playTime);

            if (autofollow && started)
            {
                if (!escortDataCapsule.ShipToDefend.HasArrived)
                {
                    game.player.Direction.SetDirection(new Vector2(
                        escortDataCapsule.ShipToDefend.destination.X - game.player.position.X,
                        escortDataCapsule.ShipToDefend.destination.Y - game.player.position.Y));
                }

                game.player.speed = escortDataCapsule.ShipToDefend.speed;

                if (ControlManager.CheckPress(RebindableKeys.Pause)
                    && GameStateManager.currentState.Equals("OverworldState"))
                {
                    PopupHandler.DisplaySelectionMenu("Do you want to skip travel?",
                        new List<string>() { "Yes", "No" },
                        new List<System.Action>(){
                            delegate 
                            {
                                SkipForward();
                            },
                            delegate {}
                        });
                }
            }

            if (timedMessageCount >= 0
                && timedMessageCount < timedMessages.Count
                && StatsManager.PlayTime.HasOverworldTimePassed(timedMessageTimes[timedMessageCount]))
            {
                if (timedMessagePortraits[timedMessageCount] != PortraitID.None)
                {
                    PopupHandler.DisplayRealtimePortraitMessage(3000, new [] {timedMessagePortraits[timedMessageCount]},
                        new List<int>(), timedMessages[timedMessageCount]);
                }
                else
                {
                    PopupHandler.DisplayRealtimeMessage(3000, timedMessages[timedMessageCount]);
                }
                timedMessageCount++;
            }

            // Player talks to freighter to begin escort
            if (!started
                && GameStateManager.currentState.Equals("OverworldState")
                && CollisionDetection.IsRectInRect(game.player.Bounds, escortDataCapsule.ShipToDefend.Bounds)
                && ((ControlManager.CheckPress(RebindableKeys.Action1) || ControlManager.CheckKeyPress(Keys.Enter))))
            {
                if (showInventoryTutorial
                    && ShipInventoryManager.equippedShield is EmptyShield)
                {
                    PopupHandler.DisplayPortraitMessage(introductionPortrait, "[Alliance Pilot] \"You need to equip a shield before we leave. Go to the shop next to Highfence and I will tell you what to do.");
                    game.tutorialManager.EnableEquipTutorial();
                }

                else
                {
                    if (introductionPortrait != PortraitID.None)
                    {
                        PopupHandler.DisplayPortraitMessage(introductionPortrait, introductionText);
                    }
                    else
                    {
                        PopupHandler.DisplayMessage(introductionText);
                    }

                    ((FreighterShip)escortDataCapsule.ShipToDefend).Start();
                    escortDataCapsule.ShipToDefend.speed = escortDataCapsule.FreighterSpeed;

                    started = true;

                    if (autofollow)
                    {
                        game.player.DisableControls();
                    }

                    this.Description = descriptions[0];

                    enemyAttackStartTime = StatsManager.PlayTime.GetFutureOverworldTime(escortDataCapsule.EnemyAttackStartTime);

                    for (int i = 0; i < timedMessages.Count; i++)
                    {
                        timedMessageTimes.Add(StatsManager.PlayTime.GetFutureOverworldTime(escortDataCapsule.TimedMessageTriggers[i]));
                    }
                    timedMessageCount = 0;
                }
            }

            // Escort mission begins
            if (started 
                && GameStateManager.currentState.Equals("OverworldState") &&
                numberOfEnemyShips > 0 &&
                StatsManager.PlayTime.HasOverworldTimePassed(enemyAttackStartTime))
            {
                // Ready to spawn a new enemy ship
                if (StatsManager.PlayTime.HasOverworldTimePassed(enemyNextWaveTime))
                {
                    int i = startingNumberOfEnemyShips - numberOfEnemyShips;

                    if (descriptions.Count > 0)
                    {
                        if (descriptions.Count > 1)
                        {
                            descriptions.RemoveAt(0);
                        }

                        this.Description = descriptions[0];
                    }

                    if (attackStartPortraits[i] != PortraitID.None)
                    {
                        PopupHandler.DisplayPortraitMessage(attackStartPortraits[i], attackStartText[i]);
                    }
                    else
                    {
                        PopupHandler.DisplayMessage(attackStartText[i]);
                    }

                    game.stateManager.overworldState.GetSectorX.shipSpawner.AddOverworldShip(
                        enemies[0],
                        escortDataCapsule.ShipToDefend.position +
                        (650 * escortDataCapsule.ShipToDefend.Direction.GetDirectionAsVector()),
                        levels[levelIndex], escortDataCapsule.ShipToDefend);

                    numberOfEnemyShips--;

                    if (numberOfEnemyShips > 0)
                    {
                        enemyNextWaveTime = StatsManager.PlayTime.GetFutureOverworldTime(escortDataCapsule.EnemyAttackFrequency);
                    }
                }
            }
            
            // Transfers freigter hp between levels
            for (int i = 0; i < levels.Count; i++)
            {
                if (GameStateManager.currentState.Equals("ShooterState")
                    && game.stateManager.shooterState.CurrentLevel.Identifier.Equals(levels[i])
                    && game.stateManager.shooterState.GetLevel(levels[i]).IsObjectiveCompleted)
                {
                    shipToDefendHP = game.stateManager.shooterState.CurrentLevel.GetFreighterHP();

                    levelCompleted = true;
                    levelCompletedIndex = i;
                    levelIndex = i + 1;
                }
            }

            if (GameStateManager.currentState.Equals("OverworldState"))
            {
                if (levelCompleted
                && levelCompletedIndex > lastLevelCompletedIndex)
                {
                    levelCompleted = false;
                    lastLevelCompletedIndex = levelCompletedIndex;

                    if (afterAttackPortraits[levelCompletedIndex] != PortraitID.None)
                    {
                        PopupHandler.DisplayPortraitMessage(afterAttackPortraits[levelCompletedIndex],
                            afterAttackMessages[levelCompletedIndex]);
                    }
                    else
                    {
                        PopupHandler.DisplayMessage(afterAttackMessages[levelCompletedIndex]);
                    }
                }
                else
                {
                    levelCompleted = false;
                }
            }

            Collision();
        }
        public override void Update(PlayTime playTime)
        {
            base.Update(playTime);

            // Updates player direction and speed
            if (!HasAnyShipArrived())
            {
                game.player.Direction.SetDirection(new Vector2(
                                                       Destination.position.X - game.player.position.X,
                                                       Destination.position.Y - game.player.position.Y));

                if (ControlManager.CheckPress(RebindableKeys.Pause) &&
                    GameStateManager.currentState.Equals("OverworldState"))
                {
                    PopupHandler.DisplaySelectionMenu("Do you want to skip travel?",
                                                      new List <string>()
                    {
                        "Yes", "No"
                    },
                                                      new List <System.Action>()
                    {
                        delegate
                        {
                            SkipForward();
                        },
                        delegate {}
                    });
                }
            }
            game.player.speed = speed;

            // Displays timed messages
            if (timedMessages.Keys.Count > 0 &&
                StatsManager.PlayTime.HasOverworldTimePassed(nextMessageTime))
            {
                if (portraits.Count > 0)
                {
                    if (realTime)
                    {
                        PopupHandler.DisplayRealtimePortraitMessage(GetNextMessageDuration(), portraits[0].ToArray(),
                                                                    portraitTriggers[0], timedMessages.Keys.First());
                    }
                    else
                    {
                        realTimeSwitchIndex++;
                        PopupHandler.DisplayPortraitMessage(portraits[0], portraitTriggers[0], timedMessages.Keys.First());
                        if (useRealTimeSwitch &&
                            realTimeSwitchIndex >= activateRealTimeSwitchIndex)
                        {
                            realTime = true;
                        }
                    }

                    portraits.RemoveAt(0);
                    portraitTriggers.RemoveAt(0);
                }
                else
                {
                    if (realTime)
                    {
                        PopupHandler.DisplayRealtimeMessage(GetNextMessageDuration(), timedMessages.Keys.First());
                    }
                    else
                    {
                        realTimeSwitchIndex++;
                        PopupHandler.DisplayMessage(timedMessages.Keys.First());
                        if (useRealTimeSwitch &&
                            realTimeSwitchIndex >= activateRealTimeSwitchIndex)
                        {
                            realTime = true;
                        }
                    }
                }

                timedMessages.Remove(timedMessages.Keys.First());

                if (timedMessages.Keys.Count > 0)
                {
                    nextMessageTime = GetNextMessageStartTime();
                }
            }
        }