public static void RerollConsequence(MenuCallbackArgs args) { try { TournamentPrizePool settings = GetTournamentPrizePool(Settlement.CurrentSettlement); TournamentGame tournamentGame = Campaign.Current.TournamentManager.GetTournamentGame(Settlement.CurrentSettlement.Town); //Clear old prizes settings.SelectedPrizeStringId = null; settings.Prizes = new ItemRoster(); settings.RemainingRerolls--; //Generate New Prize var prize = GenerateTournamentPrize(tournamentGame, settings, false); SetTournamentSelectedPrize(tournamentGame, prize); try { GameMenu.SwitchToMenu("town_arena"); } catch (Exception ex) { ErrorLog.Log("ERROR: BMTournamentXP: Re-roll: Refreshing Arena Menu:"); ErrorLog.Log(ex.ToStringFull()); } } catch (Exception ex) { ErrorLog.Log("Re-roll Prize Pool"); ErrorLog.Log(ex.ToStringFull()); } }
private static void OnSelectPrize(List <InquiryElement> prizeSelections) { if (prizeSelections.Count > 0) { try { TournamentGame tournamentGame = Campaign.Current.TournamentManager.GetTournamentGame(Settlement.CurrentSettlement.Town); TournamentPrizePool currentPool = GetTournamentPrizePool(Settlement.CurrentSettlement); currentPool.SelectedPrizeStringId = prizeSelections.First().Identifier.ToString(); var prize = Game.Current.ObjectManager.GetObject <ItemObject>(prizeSelections.First().Identifier.ToString()); SetTournamentSelectedPrize(tournamentGame, prize); } catch (Exception ex) { ErrorLog.Log("ERROR: BMTournamentXP: OnSelectPrize: Error setting Town Prize"); ErrorLog.Log(ex.ToStringFull()); } try { GameMenu.SwitchToMenu("town_arena"); } catch (Exception ex) { ErrorLog.Log("ERROR: BMTournamentXP: OnSelectPrize: Refresh Arena Menu"); ErrorLog.Log(ex.ToStringFull()); } } }
public static TournamentPrizePool GetTournamentPrizePool(Settlement settlement, ItemObject prize = null) { Town component = settlement.Town; TournamentPrizePool obj = MBObjectManager.Instance.GetObject <TournamentPrizePool>((TournamentPrizePool x) => x.Town == component); if (obj == null) { obj = MBObjectManager.Instance.CreateObject <TournamentPrizePool>(); obj.Town = component; } if (prize != null) { obj.Prizes = new ItemRoster(); obj.Prizes.Add(new ItemRosterElement(prize, 1)); obj.SelectedPrizeStringId = prize.StringId; } else { if (settlement.HasTournament) { var townPrize = Campaign.Current.TournamentManager.GetTournamentGame(settlement.Town).Prize; if (townPrize.StringId != obj.SelectedPrizeStringId) { obj.Prizes = new ItemRoster(); obj.Prizes.Add(new ItemRosterElement(townPrize, 1)); obj.SelectedPrizeStringId = townPrize.StringId; obj.RemainingRerolls = TournamentXPSettings.Instance.MaxNumberOfRerollsPerTournament; } } } return(obj); }
private static bool RerollCondition(MenuCallbackArgs args) { if (TournamentXPSettings.Instance.MaxNumberOfRerollsPerTournament == 0) { return(false); } bool flag; TextObject textObject; TournamentPrizePool settings = GetTournamentPrizePool(Settlement.CurrentSettlement); bool flag1 = Campaign.Current.Models.SettlementAccessModel.CanMainHeroDoSettlementAction(Settlement.CurrentSettlement, SettlementAccessModel.SettlementAction.JoinTournament, out flag, out textObject); if (settings.RemainingRerolls <= 0) { flag = true; flag1 = false; textObject = new TextObject("{=tourn004}Re-roll Attempts Exceeded"); } args.optionLeaveType = GameMenuOption.LeaveType.HostileAction; return(MenuHelper.SetOptionProperties(args, flag1, flag, textObject)); }
//REVISIT - convert to transpiler patch to just change our prize payment // All we really need to change is instead of giving an ItemObject - which has no ItemModifers, we give them an ItemRosterEquipement, which can have ItemModifiers private static bool Prefix(ref TournamentBehavior __instance) { //Override Standard behavior if (Campaign.Current.GameMode != CampaignGameMode.Campaign) { return(false); } /* Give Gold, Influence, Renown */ if (__instance.OverallExpectedDenars > 0) { GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, __instance.OverallExpectedDenars, false); } GainRenownAction.Apply(Hero.MainHero, __instance.TournamentGame.TournamentWinRenown, false); if (Hero.MainHero.MapFaction.IsKingdomFaction && Hero.MainHero.MapFaction.Leader != Hero.MainHero) { GainKingdomInfluenceAction.ApplyForDefault(Hero.MainHero, TournamentPrizePoolBehavior.TournamentReward.BonusInfluence); } /* Give Item Prize */ if (!TournamentXPSettings.Instance.EnableItemModifiersForPrizes) { if (!TournamentPrizePoolBehavior.TournamentReward.PrizeGiven) { Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true); TournamentPrizePoolBehavior.TournamentReward.PrizeGiven = true; } } else { TournamentPrizePool currentPool = null; string prizeStringId = ""; try { if (!TournamentPrizePoolBehavior.TournamentReward.PrizeGiven) { currentPool = TournamentPrizePoolBehavior.GetTournamentPrizePool(__instance.Settlement); prizeStringId = __instance.TournamentGame.Prize.StringId; //Beta1.2 #if VERSION120 Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(currentPool.Prizes.Where(x => x.EquipmentElement.Item.StringId == prizeStringId).First().EquipmentElement, 1, true); #endif //Release1.1.1 #if VERSION111 Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(currentPool.Prizes.Where(x => x.EquipmentElement.Item.StringId == prizeStringId).First(), 1, true); #endif TournamentPrizePoolBehavior.TournamentReward.PrizeGiven = true; } } catch (Exception ex) { ErrorLog.Log("ERROR: Tournament XPanded: OnPlayerWinTournament\nError Awarding Prize"); ErrorLog.Log("TournamentPrizePool:\n"); if (currentPool != null) { ErrorLog.Log(Newtonsoft.Json.JsonConvert.SerializeObject(currentPool)); } ErrorLog.Log(ex.ToStringFull()); if (!TournamentPrizePoolBehavior.TournamentReward.PrizeGiven) { Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true); TournamentPrizePoolBehavior.TournamentReward.PrizeGiven = true; } } } Campaign.Current.TournamentManager.OnPlayerWinTournament(__instance.TournamentGame.GetType()); return(false); }
public static void PrizeSelectConsequence(MenuCallbackArgs args) { try { List <InquiryElement> prizeElements = new List <InquiryElement>(); TournamentGame tournamentGame = Campaign.Current.TournamentManager.GetTournamentGame(Settlement.CurrentSettlement.Town); TournamentPrizePool currentPool = GetTournamentPrizePool(Settlement.CurrentSettlement); if (currentPool.Prizes.Count < TournamentXPSettings.Instance.NumberOfPrizeOptions) { ItemObject prize = GenerateTournamentPrize(tournamentGame, currentPool, true); } // InformationManager.Clear(); foreach (ItemRosterElement ire in currentPool.Prizes) { var p = ire.EquipmentElement; try { var ii = new ImageIdentifier(p.Item.StringId, ImageIdentifierType.Item, p.GetModifiedItemName().ToString()); // prizeElements.Add(new InquiryElement(p.Item.StringId, ii, true, p.Item.ToToolTipTextObject().ToString())); prizeElements.Add(new InquiryElement( p.Item.StringId, p.GetModifiedItemName().ToString(), ii, true, p.ToToolTipTextObject().ToString() )); } catch (Exception ex) { ErrorLog.Log("ERROR: Tournament Prize System\nFailed to add prize element to display" + p.Item.StringId); ErrorLog.Log(ex.ToStringFull()); } } if (prizeElements.Count > 0) { string info = "{=tourn012}You can choose an item from the list below as your reward if you win the tournament!"; TextObject descr = new TextObject(info); if (TournamentXPSettings.Instance.DebugMode) { info = "Town:{TOWN}\nMin:{MIN}\nMax:{MAX}\nProsperity:{PROSPERITY}\nTypes:{TYPES}"; descr = new TextObject(info); descr.SetTextVariable("TOWN", currentPool.Town.Name); descr.SetTextVariable("MIN", TournamentPrizePoolBehavior.GetMinPrizeValue().ToString()); descr.SetTextVariable("MAX", TournamentPrizePoolBehavior.GetMaxPrizeValue().ToString()); descr.SetTextVariable("PROSPERITY", currentPool.Town.GetProsperityLevel().ToString()); var types = ""; foreach (var t in TournamentPrizePoolBehavior.GetActivePrizeTypes()) { types += t.ToString() + ", "; } types = types.Substring(0, types.Length - 2); descr.SetTextVariable("TYPES", types); } InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData( new TextObject("{=tourn005}Tournament Prize Selection").ToString(), descr.ToString(), prizeElements, true, true, new TextObject("{=tourn006}OK").ToString(), new TextObject("{=tourn007}Cancel").ToString(), new Action <List <InquiryElement> >(OnSelectPrize), new Action <List <InquiryElement> >(OnDeSelectPrize)), true); try { GameMenu.SwitchToMenu("town_arena"); } catch (Exception ex) { ErrorLog.Log("ERROR: BMTournamentXP: Select Prize: Refresh Menu"); ErrorLog.Log(ex.ToStringFull()); } } else { InformationManager.ShowInquiry(new InquiryData("Tournament Prize Selection", "You should not be seeing this. Something went wrong generating the prize list. Your item restrictions may be set too narrow.", true, false, "OK", "", null, null)); } } catch (Exception ex) { ErrorLog.Log("ERROR: BMTournamentXP: Tournament Prize Selection"); ErrorLog.Log(ex.ToStringFull()); } }
public static ItemObject GenerateTournamentPrize(TournamentGame tournamentGame, TournamentPrizePool currentPool = null, bool keepTownPrize = true) { var numItemsToGet = TournamentXPSettings.Instance.NumberOfPrizeOptions; bool bRegenAllPrizes = false; if (currentPool == null) { bRegenAllPrizes = true; currentPool = GetTournamentPrizePool(tournamentGame.Town.Settlement); } var allitems = GetItemStringsRevised(tournamentGame, TournamentPrizePoolBehavior.GetActivePrizeTypes()); if (allitems.Count == 0) { MessageBox.Show("TournamentsXPanded Error:\nAlert, your prize generation filters have resulted in no valid prizes. Consider widening your prize value range and if you are using a custom list make sure it's loaded correctly."); return(null); } //Add any existing items if we are filling in missing ones from an already generated pool var pickeditems = new List <string>(); if (keepTownPrize && !string.IsNullOrWhiteSpace((tournamentGame.Prize.StringId))) { pickeditems.Add(tournamentGame.Prize.StringId); currentPool.SelectedPrizeStringId = tournamentGame.Prize.StringId; } try { if (!bRegenAllPrizes) { foreach (ItemRosterElement existingPrize in currentPool.Prizes) { if (!pickeditems.Contains(existingPrize.EquipmentElement.Item.StringId)) { pickeditems.Add(existingPrize.EquipmentElement.Item.StringId); } if (allitems.Contains(existingPrize.EquipmentElement.Item.StringId)) { allitems.Remove(existingPrize.EquipmentElement.Item.StringId); } } } } catch (Exception ex) { ErrorLog.Log("ERROR: GetTournamentPrize existingprizes\n" + ex.ToStringFull()); } //If the totoal pool of unique items is less than our desired number, reduce our pool size. if (allitems.Count() < numItemsToGet) { numItemsToGet = allitems.Count(); } while (pickeditems.Count < numItemsToGet && allitems.Count() > 0) { var randomId = allitems.GetRandomElement <string>(); if (!pickeditems.Contains(randomId)) { pickeditems.Add(randomId); allitems.Remove(randomId); } } currentPool.Prizes = new ItemRoster(); foreach (var id in pickeditems) { ItemModifier itemModifier = null; ItemObject pickedPrize = null; try { pickedPrize = Game.Current.ObjectManager.GetObject <ItemObject>(id); } catch (Exception ex) { ErrorLog.Log("Error getting object StringId: " + id + "\n" + ex.ToStringFull()); } if (pickedPrize != null) { #if VERSION120 || VERSION130 if (TournamentXPSettings.Instance.EnableItemModifiersForPrizes && pickedPrize.ItemType != ItemObject.ItemTypeEnum.Thrown && pickedPrize.ItemType != ItemObject.ItemTypeEnum.Arrows) { try { if (MBRandom.RandomFloatRanged(100f) < 50f) { var ee = GetEquipmentWithModifier(pickedPrize, TournamentPrizePoolBehavior.GetProsperityModifier(tournamentGame.Town.Settlement)); itemModifier = ee.ItemModifier; } } catch (Exception ex) { ErrorLog.Log("Error in GetEquipmentWithModifier\nItem:" + pickedPrize.StringId + "\n" + ex.ToStringFull()); } } #endif try { currentPool.Prizes.Add(new ItemRosterElement(pickedPrize, 1, itemModifier)); } catch (Exception ex) { ErrorLog.Log("Error adding equipment to prizepool.\n" + ex.ToStringFull()); } } else { MessageBox.Show("Invalid Item detected. Please remove: " + id + " from your list of custom items. Ignoring this item and continuing."); } } if (!keepTownPrize) { var selected = currentPool.Prizes.GetRandomElement <ItemRosterElement>(); currentPool.SelectedPrizeStringId = selected.EquipmentElement.Item.StringId; SetTournamentSelectedPrize(tournamentGame, selected.EquipmentElement.Item); } return(currentPool.SelectPrizeItemRosterElement.EquipmentElement.Item); }
public static ItemObject GenerateTournamentPrize(TournamentGame tournamentGame, TournamentPrizePool currentPool = null, bool keepTownPrize = true) { var numItemsToGet = TournamentXPSettings.Instance.NumberOfPrizeOptions; bool bRegenAllPrizes = false; if (currentPool == null) { bRegenAllPrizes = true; currentPool = GetTournamentPrizePool(tournamentGame.Town.Settlement); } var allitems = GetItemStringsRevised(tournamentGame, TournamentPrizePoolBehavior.GetActivePrizeTypes()); //Add any existing items if we are filling in missing ones from an already generated pool var pickeditems = new List <string>(); if (keepTownPrize && !string.IsNullOrWhiteSpace((tournamentGame.Prize.StringId))) { pickeditems.Add(tournamentGame.Prize.StringId); currentPool.SelectedPrizeStringId = tournamentGame.Prize.StringId; } try { if (!bRegenAllPrizes) { foreach (ItemRosterElement existingPrize in currentPool.Prizes) { if (!pickeditems.Contains(existingPrize.EquipmentElement.Item.StringId)) { pickeditems.Add(existingPrize.EquipmentElement.Item.StringId); } if (allitems.Contains(existingPrize.EquipmentElement.Item.StringId)) { allitems.Remove(existingPrize.EquipmentElement.Item.StringId); } } } } catch (Exception ex) { ErrorLog.Log("ERROR: GetTournamentPrize existingprizes\n" + ex.ToStringFull()); } //If the totoal pool of unique items is less than our desired number, reduce our pool size. if (allitems.Count() < numItemsToGet) { numItemsToGet = allitems.Count(); } while (pickeditems.Count < numItemsToGet && allitems.Count() > 0) { var randomId = allitems.GetRandomElement <string>(); if (!pickeditems.Contains(randomId)) { pickeditems.Add(randomId); allitems.Remove(randomId); } } currentPool.Prizes = new ItemRoster(); foreach (var id in pickeditems) { ItemModifier itemModifier = null; var pickedPrize = Game.Current.ObjectManager.GetObject <ItemObject>(id); #if VERSION120 if (TournamentXPSettings.Instance.EnableItemModifiersForPrizes) { //var ee = GetEquipmentWithModifier(pickedPrize, TournamentPrizePoolBehavior.GetProsperityModifier(tournamentGame.Town.Settlement)); if (MBRandom.RandomFloatRanged(100f) < 50f) { var ee = GetEquipmentWithModifier(pickedPrize, 1.3f); itemModifier = ee.ItemModifier; } } #endif currentPool.Prizes.Add(new ItemRosterElement(pickedPrize, 1, itemModifier)); // currentPool.Prizes.Add(new ItemRosterElement(pickedPrize, 1, null)); //Turn off random item mods for now; } if (!keepTownPrize) { var selected = currentPool.Prizes.GetRandomElement <ItemRosterElement>(); currentPool.SelectedPrizeStringId = selected.EquipmentElement.Item.StringId; SetTournamentSelectedPrize(tournamentGame, selected.EquipmentElement.Item); } return(currentPool.SelectPrizeItemRosterElement.EquipmentElement.Item); }