Esempio n. 1
0
        private static bool Prefix(TournamentBehavior __instance)
        {
            TournamentPrizePoolBehavior.TournamentReward = new TournamentReward(__instance.TournamentGame);
            typeof(TournamentBehavior).GetProperty("OverallExpectedDenars").SetValue(__instance, __instance.OverallExpectedDenars + TournamentXPSettings.Instance.BonusTournamentWinGold);

            return(true);
        }
Esempio n. 2
0
 static bool Prefix(TournamentBehavior __instance)
 {
     if (BannerlordTweaksSettings.Instance is { } settings)
     {
         typeof(TournamentBehavior).GetProperty("OverallExpectedDenars").SetValue(__instance, __instance.OverallExpectedDenars + settings.TournamentGoldRewardAmount);
     }
     return(true);
 }
 private void CreateTorunamentTreePostfixImpl(TournamentBehavior tournamentBehavior)
 {
     tournamentBehavior.Rounds[0] = BLTAdoptAHeroModule.TournamentConfig.Round1Type
                                    .GetRandomRound(tournamentBehavior.Rounds[0], tournamentBehavior.TournamentGame.Mode);
     tournamentBehavior.Rounds[1] = BLTAdoptAHeroModule.TournamentConfig.Round2Type
                                    .GetRandomRound(tournamentBehavior.Rounds[1], tournamentBehavior.TournamentGame.Mode);
     tournamentBehavior.Rounds[2] = BLTAdoptAHeroModule.TournamentConfig.Round3Type
                                    .GetRandomRound(tournamentBehavior.Rounds[2], tournamentBehavior.TournamentGame.Mode);
 }
Esempio n. 4
0
        private static void CalculateBet(ref TournamentBehavior __instance)
        {
            if (__instance.CurrentMatch == null || __instance.CurrentMatch.Teams == null || !TournamentSetting.Instance.BetGoldEnabled)
            {
                return;
            }
            var arr     = new int[__instance.CurrentMatch.Teams.Count()];
            var atIndex = -1;

            var num = 0;

            foreach (var team in __instance.CurrentMatch.Teams)
            {
                foreach (var participant in team.Participants)
                {
                    if (participant.Character == CharacterObject.PlayerCharacter)
                    {
                        atIndex = num;
                    }
                    arr[num] += participant.Character.Level;
                }
                num++;
            }

            var other = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                if (i != atIndex)
                {
                    other += arr[i];
                }
            }

            if (atIndex == -1)
            {
                return;
            }

            other /= (arr.Length - 1);

            var ratio = 2f * other / arr[atIndex];

            ratio *= 1 + (arr.Length - 2) * 0.2f;

            var odd = MathF.Clamp(ratio, 1.5f, 8f);

            Traverse.Create(__instance).Property("BetOdd").SetValue(odd);
        }
        private static bool Prefix(TournamentBehavior __instance)
        {
            var winners = (List <TournamentParticipant>)Traverse.Create(__instance.CurrentMatch).Method("GetWinners").GetValue();

            if (winners.Where(x => x.Character.HeroObject == Hero.MainHero).Count() > 0)
            {
                var tournamentInfo = TournamentsXPandedBehavior.GetTournamentInfo(__instance.TournamentGame.Town);

                if (__instance.CurrentRoundIndex > tournamentInfo.Rewards.LastPayoutIndex)
                {
                    tournamentInfo.Rewards.LastPayoutIndex = __instance.CurrentRoundIndex;
                    if (TournamentXPSettings.Instance.EnableRenownPerTroopTier)
                    {
                        var renownbonus = 0f;
                        foreach (var team in __instance.CurrentMatch.Teams)
                        {
                            var teambonus = 0f;
                            foreach (var p in team.Participants)
                            {
                                teambonus += TournamentXPSettings.Instance.GetRenownValue(p.Character);
                                if (p.Character.IsHero && p.Character.HeroObject == Hero.MainHero)
                                {
                                    teambonus = 0;
                                    break;
                                }
                            }
                            renownbonus += teambonus;
                        }
                        tournamentInfo.Rewards.BonusRenown += renownbonus;
                    }
                    if (TournamentXPSettings.Instance.BonusTournamentMatchGold > 0)
                    {
                        if (TournamentXPSettings.Instance.BonusTournamentMatchGoldImmediate)
                        {
                            GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, TournamentXPSettings.Instance.BonusTournamentMatchGold, false);
                        }
                        else
                        {
                            typeof(TournamentBehavior).GetProperty("OverallExpectedDenars").SetValue(__instance, __instance.OverallExpectedDenars + TournamentXPSettings.Instance.BonusTournamentMatchGold);
                        }
                    }
                }
            }

            return(true);
        }
 public void OpenBetting(TournamentBehavior tournamentBehavior)
 {
     if (BLTAdoptAHeroModule.TournamentConfig.EnableBetting &&
         tournamentBehavior.CurrentMatch != null &&
         (tournamentBehavior.CurrentRoundIndex == 3 || !BLTAdoptAHeroModule.TournamentConfig.BettingOnFinalOnly))
     {
         var    teams = TournamentHelpers.TeamNames.Take(tournamentBehavior.CurrentMatch.Teams.Count());
         string round = tournamentBehavior.CurrentRoundIndex < 3
             ? $"round {tournamentBehavior.CurrentRoundIndex + 1}"
             : "final";
         string msg = $"Betting is now OPEN for {round} match: {string.Join(" vs ", teams)}!";
         Log.LogFeedMessage(msg);
         ActionManager.SendChat(msg);
         activeBets          = new();
         CurrentBettingState = BettingState.open;
     }
     else
     {
         CurrentBettingState = BettingState.disabled;
     }
     TournamentHub.UpdateBets();
 }
Esempio n. 7
0
        //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);
        }
 static bool Prefix(TournamentBehavior __instance)
 {
     typeof(TournamentBehavior).GetProperty("OverallExpectedDenars").SetValue(__instance, __instance.OverallExpectedDenars + Settings.Instance.TournamentGoldRewardAmount);
     return(true);
 }
Esempio n. 9
0
        //public override MissionBehaviourType BehaviourType { get; }

        public TournamentXPandedMatchBehavior(TournamentBehavior behavior)
        {
            tournamentBehavior = behavior;
        }
Esempio n. 10
0
 public TournamentXPandedMatchListener(TournamentBehavior behavor)
 {
     tournamentBehavior = behavor;
 }
 static void Postfix(TournamentBehavior __instance)
 {
     betOddInfo?.SetValue(__instance, MathF.Max((float)betOddInfo.GetValue(__instance), Settings.Instance.MinimumBettingOdds, 0));
 }
        //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);
            }
            var tournamentInfo = TournamentsXPandedBehavior.GetTournamentInfo(__instance.TournamentGame.Town);
            var settlement     = __instance.Settlement;

            /* 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, tournamentInfo.Rewards.BonusInfluence);
            }
            /* Give Reputation */
            try
            {
                if (TournamentXPSettings.Instance.BonusReputationForTournamentWin > 0)
                {
                    List <Hero> heros = new List <Hero>();

                    foreach (var n in settlement.Notables)
                    {
                        if (!heros.Contains(n))
                        {
                            heros.Add(n);
                        }
                    }
                    foreach (var v in settlement.BoundVillages)
                    {
                        foreach (var n in v.Settlement.Notables)
                        {
                            if (!heros.Contains(n))
                            {
                                heros.Add(n);
                            }
                        }
                    }
                    if (settlement.OwnerClan.Heroes.Any <Hero>())
                    {
                        foreach (var n in settlement.OwnerClan.Heroes)
                        {
                            if (!heros.Contains(n))
                            {
                                heros.Add(n);
                            }
                        }
                    }
                    if (settlement.HeroesWithoutParty.Count > 0)
                    {
                        foreach (var n in settlement.HeroesWithoutParty)
                        {
                            if (!heros.Contains(n))
                            {
                                heros.Add(n);
                            }
                        }
                    }

                    foreach (var h in heros)
                    {
                        if (MBRandom.RandomFloat < .51f)
                        {
                            ChangeRelationAction.ApplyPlayerRelation(h, TournamentXPSettings.Instance.BonusReputationForTournamentWin, true, false);
                        }
                    }
                }

                MBTextManager.SetTextVariable("RELATION_VALUE", TournamentXPSettings.Instance.BonusReputationForTournamentWin, false);
                InformationManager.AddQuickInformation(new TextObject("{=o0qwDa0q}Your relation increased by {RELATION_VALUE} with nearby notables.", null), 0, null, "");
            }
            catch (Exception ex)
            {
                ErrorLog.Log("Error giving Reputation:\n" + ex.ToStringFull());
            }

            /* Give Item Prize */
            if (!TournamentXPSettings.Instance.EnableItemModifiersForPrizes)
            {
                if (!tournamentInfo.Rewards.PrizeGiven)
                {
                    try
                    {
                        Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true);
                        tournamentInfo.Rewards.PrizeGiven = true;
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.Log("Error assigning prize\n" + ex.ToStringFull());
                    }
                }
            }
            else
            {
                try
                {
                    if (!tournamentInfo.Rewards.PrizeGiven)
                    {
                        try
                        {
                            if (!String.IsNullOrWhiteSpace(tournamentInfo.SelectedPrizeStringId))
                            {
                                Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(tournamentInfo.SelectedPrizeItem.ToItemRosterElement().EquipmentElement, 1, true);
                                tournamentInfo.Rewards.PrizeGiven = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.Log("Error assigning prize\n" + ex.ToStringFull());
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLog.Log("ERROR: Tournament XPanded: OnPlayerWinTournament\nError Awarding Prize");
                    ErrorLog.Log("TournamentPrizePool:\n");
                    if (tournamentInfo != null)
                    {
                        ErrorLog.Log(Newtonsoft.Json.JsonConvert.SerializeObject(tournamentInfo));
                    }
                    ErrorLog.Log(ex.ToStringFull());
                }
            }

            if (!tournamentInfo.Rewards.PrizeGiven)
            {
                try
                {
                    Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true);
                    tournamentInfo.Rewards.PrizeGiven = true;
                }
                catch (Exception ex2)
                {
                    ErrorLog.Log("Error assigning prize\n" + ex2.ToStringFull());
                }
            }

            tournamentInfo.ReRollsUsed = 0;
            Campaign.Current.TournamentManager.OnPlayerWinTournament(__instance.TournamentGame.GetType());

            return(false);
        }
 public static void SkipMatchPrefix(TournamentBehavior __instance)
 {
     SafeCallStatic(() => Current?.CloseBetting());
 }
 public static void CreateTorunamentTreePostfix(TournamentBehavior __instance)
 {
     SafeCallStatic(() => Current?.CreateTorunamentTreePostfixImpl(__instance));
 }
 public static void AfterStartPostfix(TournamentBehavior __instance)
 {
     // Only called at the start of the tournament
     SafeCallStatic(() => Current?.OpenBetting(__instance));
 }