예제 #1
0
        private static void OnSelectTournamentStyle(List <InquiryElement> selectedTypes)
        {
            if (selectedTypes.Count > 0)
            {
                var town = Settlement.CurrentSettlement.Town;
                TournamentManager tournamentManager = Campaign.Current.TournamentManager as TournamentManager;
                TournamentGame    tournamentGame;
                TournamentGame    currentGame = tournamentManager.GetTournamentGame(town);

                switch (selectedTypes.First().Identifier.ToString())
                {
                case "melee":
                    tournamentGame = new FightTournamentGame(town);
                    TournamentPrizePoolBehavior.TournamentReward = new TournamentReward(tournamentGame);
                    break;

                case "melee2":
                    tournamentGame = new Fight2TournamentGame(town);
                    TournamentPrizePoolBehavior.TournamentReward = new TournamentReward(tournamentGame);
                    break;

                //case "melee3":
                //    tournamentGame = new BattleRoyalTournamentGame(town);
                //    TournamentPrizePoolBehavior.TournamentReward = new TournamentReward(tournamentGame);
                //    break;

                case "archery":
                    tournamentGame = new ArcheryTournamentGame(town);
                    break;

                case "joust":
                    tournamentGame = new JoustingTournamentGame(town);
                    break;

                case "race":
                    tournamentGame = new HorseRaceTournamentGame(town);
                    break;

                default:
                    tournamentGame = new FightTournamentGame(town);
                    break;
                }

                if (tournamentGame.GetType() != currentGame.GetType())
                {
                    ((List <TournamentGame>)Traverse.Create(tournamentManager).Field("_activeTournaments").GetValue()).Remove(currentGame);
                    tournamentManager.AddTournament(tournamentGame);
                }

                try
                {
                    GameMenu.SwitchToMenu("town_arena");
                }
                catch (Exception ex)
                {
                    ErrorLog.Log("ERROR: BMTournamentXP: Refreshing Arena Screen:");
                    ErrorLog.Log(ex.ToStringFull());
                }
            }
        }
예제 #2
0
        public override void SyncData(IDataStore dataStore)
        {
            if (dataStore.IsSaving && TournamentXPSettings.Instance.EnableCleanSave)
            {
                List <TournamentPrizePool> prizePools = new List <TournamentPrizePool>();
                MBObjectManager.Instance.GetAllInstancesOfObjectType <TournamentPrizePool>(ref prizePools);
                foreach (var pp in prizePools)
                {
                    MBObjectManager.Instance.UnregisterObject(pp);
                }

                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 saved in clean state.", Colors.Red));
            }
        }
예제 #3
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));
                    }
                }
            }
        }