Example #1
0
        public void Load()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            if (isf.FileExists("PlayerData.dat"))
            {
                IsolatedStorageFileStream stream = isf.OpenFile("PlayerData.dat", System.IO.FileMode.Open);
                XmlReader reader = XmlReader.Create(stream);
                reader.ReadToFollowing("IsStored");
                IsStored = reader.ReadElementContentAsBoolean();
                if (IsStored)
                {
                    reader.ReadToFollowing("OGI");
                    OGI = reader.ReadElementContentAsString();
                    reader.ReadToFollowing("Hash");
                    Hash = reader.ReadElementContentAsString();
                }
                reader.ReadToFollowing("Difficulty");
                Difficulty = (Difficulty)Enum.Parse(typeof(Difficulty), reader.ReadElementContentAsString(), true);
                reader.ReadToFollowing("Points");
                Points = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("DeviceRegistered");
                DeviceRegistered = reader.ReadElementContentAsBoolean();
                reader.ReadToFollowing("ReportingEnabled");
                ReportingEnabled = reader.ReadElementContentAsBoolean();
                reader.ReadToFollowing("GameUsage");
                while (reader.Read())
                {
                    if (reader.IsStartElement("GameStat"))
                    {
                        VelesConflictReporting.GameUsageStastics statics = new VelesConflictReporting.GameUsageStastics();
                        reader.ReadToFollowing("Actions");
                        statics.Actions = reader.ReadElementContentAsInt();
                        reader.ReadToFollowing("Map");
                        statics.Map = reader.ReadElementContentAsString();
                        reader.ReadToFollowing("Difficulty");
                        statics.Difficulty = reader.ReadElementContentAsInt();
                        reader.ReadToFollowing("Winner");
                        statics.Winner = reader.ReadElementContentAsInt();
                        reader.ReadToFollowing("TimeSpent");
                        statics.TimeSpent = new TimeSpan(reader.ReadElementContentAsLong());
                        statics.DeviceID = GameBase.DeviceID;
                        GameBase.GameUsage.Add(statics);
                    }
                    else if (reader.Name == "GameUsage")
                    {
                        break;
                    }

                }
                reader.ReadToFollowing("MenuUsage");
                while (reader.Read())
                {
                    if (reader.IsStartElement("MenuStat"))
                    {
                        VelesConflictReporting.MenuUsageStatistic statics = new VelesConflictReporting.MenuUsageStatistic();
                        reader.ReadToFollowing("Actions");
                        statics.Actions = reader.ReadElementContentAsInt();
                        reader.ReadToFollowing("Menu");
                        statics.Menu = reader.ReadElementContentAsString();
                        reader.ReadToFollowing("TimeSpent");
                        statics.TimeSpent = new TimeSpan(reader.ReadElementContentAsLong());
                        statics.DeviceID = GameBase.DeviceID;
                        GameBase.MenuUsage.Add(statics);
                    }
                    else if (reader.Name == "MenuUsage")
                        break;
                }
                reader.ReadToFollowing("Research");
                reader.ReadToFollowing("Attack");
                Research["Attack"] = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("Defense");
                Research["Defense"] = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("Speed");
                Research["Speed"] = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("Growth");
                Research["Growth"] = reader.ReadElementContentAsInt();

                while (reader.Read())
                {
                    if (reader.IsStartElement("ProgressEntry"))
                    {
                        reader.ReadToFollowing("Campaing");
                        string campaing = reader.ReadElementContentAsString();
                        reader.ReadToFollowing("Progress");
                        int progress = reader.ReadElementContentAsInt();
                        Progress.Add(campaing, progress);
                    }
                }
                stream.Flush();
                stream.Dispose();
            }
            else
                FirstLoad = true;
            isf.Dispose();
        }
Example #2
0
        void OnGameEnd()
        {
            if (playerData.ReportingEnabled)
            {
                VelesConflictReporting.GameUsageStastics gus = new VelesConflictReporting.GameUsageStastics();
                gus.Actions = GameActions;
                gus.Map = selectedMission.Map;
                gus.TimeSpent = GameTimeSpent;
                gus.Difficulty = (int)playerData.Difficulty;
                gus.DeviceID = DeviceID;
                gus.Winner = GameManager.GetLooser() == PlayerType.Player2 ? 1 : 2;
                lock (GameUsage)
                    GameUsage.Add(gus);
            }
            GameActions = 0;
            GameTimeSpent = TimeSpan.Zero;
            Manager.Enabled = true;
            MainMenuContract.Enabled = true;
            SinglePlayerContract.Enabled = false;
            GameScript.Dispose();
            GameScript = null;
            GameState = GameState.Menu;
            LevelContentManager.Unload();
            LevelContentManager.Dispose();

            textSettings.Scale = 1;
            textSettings.Origin = Vector2.Zero;
            textSettings.Width = 200;
            textSettings.Offset = new Vector2(545, 50);
            textSettings.Depth = 0.49f;
            //Select the next mission
            if (GameManager.GetLooser() == PlayerType.Player2)
            {
                Control LastControl = Manager.Menues["Mission"].Controls.Last(control => control.Tag == selectedMission);
                LastControl.Color = Color.White;
                int Index = Manager.Menues["Mission"].Controls.LastIndexOf(LastControl) + 1;
                int Offset = Manager.Menues["Mission"].Controls.IndexOf(Manager.Menues["Mission"].Controls.First(control => control.Tag is Mission));
                int Progress = EpisodeProgressCounter + selectedEpisode.Missions.IndexOf(selectedMission) + 2;
                if (Progress > playerData.GetProgress(selectedCampaing.InternalName))
                {
                    playerData.Points += selectedMission.PointsGain;
                    playerData.SetProgress(selectedCampaing.InternalName, Progress);
                }
                Mission oldMission = selectedMission;
                if (Index >= Manager.Menues["Mission"].Controls.Count)
                {
                    //Switch episodes
                    HexControl hexControl = (HexControl)Manager.Menues["Strategic"].Controls.First(c => c is HexControl);
                    foreach (int cell in selectedEpisode.Cells)
                    {
                        hexControl[cell].Color = new Color(53, 234, 28) * 0.7f;
                    }
                    hexControl[selectedEpisode.Position].Color = new Color(53, 234, 28) * 0.7f;
                    Index = selectedCampaing.Episodes.IndexOf(selectedEpisode) + 1;

                    if (Index >= selectedCampaing.Episodes.Count)
                    {
                        textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                        textManager.Parse();

                        //Last episode
                        Manager.ClearHistory();
                        Manager.InjectMenu(Manager.Menues["Main"]);
                        if (!string.IsNullOrWhiteSpace(oldMission.Popup))
                        {
                            PopupTextManager.Text = oldMission.Popup;
                            PopupTextManager.Parse();
                            ShowEpilogueAfter = true;
                            PopupMB.Show(true);

                        }
                        else
                        {
                            (Manager.Menues["Epilogue"] as EpilogueMenu).Prepare(selectedCampaing);
                            Manager.SetMenu("Epilogue");
                        }
                    }
                    else
                    {

                        selectedEpisode = selectedCampaing.Episodes[Index];
                        hexControl[selectedEpisode.Position].Color = Color.Yellow * 0.5f;
                        EpisodeProgressCounter = 0;
                        foreach (Episode ep in selectedCampaing.Episodes)
                        {
                            if (ep != selectedEpisode)
                                EpisodeProgressCounter += ep.Missions.Count;
                            else
                                break;
                        }
                        //Trigget menu change event to rebuild the mission
                        //Manager_OnBeginMenuChange(this, new MenuChangeEventArgs() { Menu = Manager.Menues["Mission"] });
                        if (!string.IsNullOrWhiteSpace(oldMission.Popup))
                        {
                            ShowStrategicAfter = true;
                            textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                            textManager.Parse();
                            PopupTextManager.Text = oldMission.Popup;
                            PopupTextManager.Parse();
                            PopupMB.Show(true);
                        }
                        else
                        {
                            Manager.SetMenu("Strategic");
                            Manager.ClearHistory();
                            Manager.InjectMenu(Manager.Menues["Main"]);
                            Manager.InjectMenu(Manager.Menues["Campaing"]);
                            Manager.InjectMenu(Manager.Menues["Base"]);
                        }
                    }
                }
                else
                {
                    LastControl = Manager.Menues["Mission"].Controls[Index];
                    LastControl.Color = Color.Gray;
                    LastControl.Enabled = true;
                    if (!string.IsNullOrWhiteSpace(selectedMission.Popup))
                    {
                        PopupTextManager.Text = selectedMission.Popup;
                        PopupTextManager.Parse();
                        PopupMB.Show(true);
                    }
                    selectedMission = LastControl.Tag as Mission;

                    textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                    textManager.Parse();
                }
            }
            else
            {
                textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                textManager.Parse();
                PopupTextManager.Text = LocalizationData.GG;
                PopupTextManager.Parse();
                PopupMB.Show(true);
            }
            playerData.Save();
            GameManager = null;
        }