예제 #1
0
        public override void OnGameInitializationFinished(Game game)
        {
            if (!disabled)
            {
                if (game.GameType is Campaign)
                {
                    ApplyPatches(game, typeof(TournamentsXPandedSubModule));
                    //Setup Custom Items.
                    string customfile = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetConfigsPath(), ModuleFolderName, "CustomPrizeItems.json");
                    if (File.Exists(customfile))
                    {
                        var configtxt   = File.ReadAllText(customfile);
                        var customItems = JsonConvert.DeserializeObject <List <string> >(configtxt);
                        //InitCustomItems(customItems);
                        InitItemsList(customItems, out TournamentPrizePoolBehavior._customItems);
                    }

                    //Setup Legacy Items
                    List <string> strArray = new List <string>()
                    {
                        "winds_fury_sword_t3", "bone_crusher_mace_t3", "tyrhung_sword_t3", "pernach_mace_t3", "early_retirement_2hsword_t3", "black_heart_2haxe_t3", "knights_fall_mace_t3", "the_scalpel_sword_t3", "judgement_mace_t3", "dawnbreaker_sword_t3", "ambassador_sword_t3", "heavy_nasalhelm_over_imperial_mail", "closed_desert_helmet", "sturgian_helmet_closed", "full_helm_over_laced_coif", "desert_mail_coif", "heavy_nasalhelm_over_imperial_mail", "plumed_nomad_helmet", "eastern_studded_shoulders", "ridged_northernhelm", "armored_bearskin", "noble_horse_southern", "noble_horse_imperial", "noble_horse_western", "noble_horse_eastern", "noble_horse_battania", "noble_horse_northern", "special_camel"
                    };
                    InitItemsList(strArray, out TournamentPrizePoolBehavior._legacyItems);

                    if (TournamentXPSettings.Instance.DebugMode)
                    {
                        try
                        {
                            CreateDiagnostics();
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.Log("ERROR CREATING DIAGNOSTICS\n" + ex.ToStringFull());
                        }
                    }

                    TournamentManager tournamentManager = Campaign.Current.TournamentManager as TournamentManager;
                    foreach (var s in Campaign.Current.Settlements)
                    {
                        try
                        {
                            if (s.HasTournament)
                            {
                                TournamentGame tg = tournamentManager.GetTournamentGame(s.Town);
                                if (tg is Fight2TournamentGame)
                                {
                                    ((List <TournamentGame>)Traverse.Create(tournamentManager).Field("_activeTournaments").GetValue()).Remove(tg);
                                    tg = null;
                                    tg = new FightTournamentGame(s.Town);
                                    tournamentManager.AddTournament(tg);
                                    InformationManager.DisplayMessage(new InformationMessage("Repaired Tournament in: " + s.Town.Name.ToString(), Colors.Red));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.Log("Error resetting Tournament\n" + ex.ToStringFull());
                        }
                    }

                    //Try to repair

                    /*
                     * foreach (var settlement in Settlement.All)
                     * {
                     *  if (settlement.HasTournament)
                     *  {
                     *      var tournament = Campaign.Current.TournamentManager.GetTournamentGame(settlement.Town) as Fight2TournamentGame;
                     *      try
                     *      {
                     *          if (tournament != null)
                     *          {
                     *              tournament.SetFightMode(Fight2TournamentGame.FightMode.Mixed);
                     *          }
                     *      }
                     *      catch (Exception ex)
                     *      {
                     *          ErrorLog.Log("Error repairing tournament: " + settlement.Town.StringId);
                     *          ErrorLog.Log(ex.ToStringFull());
                     *      }
                     *  }
                     * }
                     */
                }
            }
            else
            {
                if (MessageBox.Show("Tournament XPanded disabled. Would you like to reset all Tournaments to stock?", "TournamentsXPanded Disabled", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        List <TournamentPrizePool> prizePools = new List <TournamentPrizePool>();
                        MBObjectManager.Instance.GetAllInstancesOfObjectType <TournamentPrizePool>(ref prizePools);
                        foreach (var pp in prizePools)
                        {
                            MBObjectManager.Instance.UnregisterObject(pp);
                        }
                        InformationManager.DisplayMessage(new InformationMessage("TournamentXPanded prize pools de-registered.", Colors.Red));

                        TournamentManager tournamentManager = Campaign.Current.TournamentManager as TournamentManager;
                        foreach (var s in Campaign.Current.Settlements)
                        {
                            if (s.HasTournament)
                            {
                                TournamentGame tg = tournamentManager.GetTournamentGame(s.Town);
                                if (tg is Fight2TournamentGame)
                                {
                                    ((List <TournamentGame>)Traverse.Create(tournamentManager).Field("_activeTournaments").GetValue()).Remove(tg);
                                }
                            }
                        }
                        InformationManager.DisplayMessage(new InformationMessage("TournamentXPanded tournaments reset.", Colors.Red));
                        InformationManager.DisplayMessage(new InformationMessage("TournamentXPanded can now be saved in clean state.", Colors.Red));
                    }
                    catch
                    {
                        // InformationManager.DisplayMessage(new InformationMessage("TournamentXPanded can now be saved in clean state.", Colors.Red));
                    }
                }
            }
        }