private static void RecruitMercenaries(int count)
        {
            try
            {
                var cost = GetMercenaryCost();
                MobileParty.MainParty.AddElementToMemberRoster(PlayerEncounter.Settlement.Town.MercenaryData.TroopType, count,
                                                               false);
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, null, count * cost, true);
                CampaignEventDispatcher.Instance.OnUnitRecruited(PlayerEncounter.Settlement.Town.MercenaryData.TroopType, count);
                PlayerEncounter.Settlement.Town.MercenaryData.ChangeMercenaryCount(-count);

                if (count == 1)
                {
                    InformationManager.DisplayMessage(new InformationMessage(
                                                          $"You recruited one {PlayerEncounter.Settlement.Town.MercenaryData.TroopType.Name}."));
                }
                else
                {
                    InformationManager.DisplayMessage(new InformationMessage(
                                                          $"You recruited {count} {PlayerEncounter.Settlement.Town.MercenaryData.TroopType.Name}s."));
                }

                MBTextManager.SetTextVariable("GOLD_AMOUNT", count * cost, false);
                InformationManager.DisplayMessage(new InformationMessage(GameTexts.FindText("str_gold_removed_with_icon", null).ToString(), "event:/ui/notification/coins_negative"));
            }
            catch (Exception ex)
            {
                NativeMethods.MessageBox(IntPtr.Zero, ex.Message, "RecruitAllButton -- RecruitMercenaries", NativeMethods.MB_ICONERROR | NativeMethods.MB_OK);
            }
        }
        // Actual Hiring from Tavern
        private void HireCustomMercenariesInTavern(bool buyOne, bool pastPartyLimit = false)
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return;
            }
            CustomMercData customMercData = GetCustomMercDataOfPlayerEncounter();

            if (customMercData == null)
            {
                return;
            }

            int troopRecruitmentCost = this.troopRecruitmentCost(customMercData);
            int numberOfMercsToHire  = 0;

            if (buyOne)
            {
                numberOfMercsToHire = 1;
            }
            else
            {
                int numOfTroopSlotsOpen = PartyBase.MainParty.PartySizeLimit - PartyBase.MainParty.NumberOfAllMembers;
                while (Hero.MainHero.Gold > troopRecruitmentCost * (numberOfMercsToHire + 1) && customMercData.Number > numberOfMercsToHire && (pastPartyLimit || numOfTroopSlotsOpen > numberOfMercsToHire))
                {
                    numberOfMercsToHire++;
                }
            }
            customMercData.ChangeMercenaryCount(-numberOfMercsToHire);
            MobileParty.MainParty.AddElementToMemberRoster(customMercData.TroopInfoCharObject(), numberOfMercsToHire, false);
            int amount = numberOfMercsToHire * troopRecruitmentCost;

            GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, null, amount, false);
            CampaignEventDispatcher.Instance.OnUnitRecruited(customMercData.TroopInfoCharObject(), numberOfMercsToHire);
        }
        private void HireCustomMecenariesViaGameMenu(bool buyingOne, bool toPartyLimit)
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return;
            }
            CustomMercData customMercData = GetCustomMercDataOfPlayerEncounter();

            if (customMercData == null)
            {
                return;
            }
            int numOfTroopSlotsOpen  = PartyBase.MainParty.PartySizeLimit - PartyBase.MainParty.NumberOfAllMembers;
            int troopRecruitmentCost = this.troopRecruitmentCost(customMercData);

            if (customMercData.Number > 0 && Hero.MainHero.Gold >= troopRecruitmentCost && (!toPartyLimit || numOfTroopSlotsOpen > 0))
            {
                int numOfMercs = 1;
                if (!buyingOne)
                {
                    int numOfTroopPlayerCanBuy = (troopRecruitmentCost == 0) ? customMercData.Number : Hero.MainHero.Gold / troopRecruitmentCost;
                    numOfMercs = Math.Min(customMercData.Number, numOfTroopPlayerCanBuy);
                    if (toPartyLimit)
                    {
                        numOfMercs = Math.Min(numOfTroopSlotsOpen, numOfMercs);
                    }
                }
                MobileParty.MainParty.MemberRoster.AddToCounts(customMercData.TroopInfoCharObject(), numOfMercs, false, 0, 0, true, -1);
                GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, -(numOfMercs * troopRecruitmentCost), false);
                customMercData.ChangeMercenaryCount(-numOfMercs);
                GameMenu.SwitchToMenu("town_backstreet");
            }
        }
Esempio n. 4
0
        private static void AddExiledHero()
        {
            Hero            mainhero = Hero.MainHero;
            CharacterObject wanderer = (from x in CharacterObject.Templates
                                        where x.Occupation == Occupation.Wanderer && x.Culture.StringId == mainhero.Culture.StringId
                                        select x).GetRandomElementInefficiently <CharacterObject>();

            Equipment equipment = (from y in CharacterObject.All
                                   where y.Level > 20 && y.Culture.StringId == wanderer.Culture.StringId && !y.IsHero && y.Tier > 4
                                   select y).GetRandomElementInefficiently <CharacterObject>().Equipment;
            Equipment equipmentMC = (from z in CharacterObject.All
                                     where z.Tier == 4 && z.Culture.StringId == wanderer.Culture.StringId && !z.IsHero
                                     select z).GetRandomElementInefficiently <CharacterObject>().Equipment;
            Settlement randomElement = (from settlement in Settlement.All
                                        where settlement.Culture == wanderer.Culture && settlement.IsTown
                                        select settlement).GetRandomElementInefficiently <Settlement>();
            //wanderer.Equipment.FillFrom(equipment);
            Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, null, null, 33);

            Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, wanderer);
            GiveGoldAction.ApplyBetweenCharacters(null, hero, 4000, true);
            hero.BattleEquipment.FillFrom(equipment);
            mainhero.BattleEquipment.FillFrom(equipmentMC);
            hero.HasMet = true;
            hero.Clan   = randomElement.OwnerClan;
            hero.ChangeState(Hero.CharacterStates.Active);
            AddCompanionAction.Apply(Clan.PlayerClan, hero);
            AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
            CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
        }
Esempio n. 5
0
        internal void ConsequenceChangeCaptorGold(Companion companion, Hero hero)
        {
            if (!companion.MultipleRestrictedListOfConsequences.Contains(RestrictedListOfConsequences.ChangeCaptorGold))
            {
                return;
            }

            if (hero.PartyBelongedToAsPrisoner.LeaderHero == null)
            {
                return;
            }

            try
            {
                int level = 0;

                if (!string.IsNullOrEmpty(companion.GoldTotal))
                {
                    level = new CEVariablesLoader().GetIntFromXML(companion.GoldTotal);
                }
                else
                {
                    CECustomHandler.LogToFile("Missing GoldTotal");
                }

                GiveGoldAction.ApplyBetweenCharacters(null, hero.PartyBelongedToAsPrisoner.LeaderHero, level);
            }
            catch (Exception) { CECustomHandler.LogToFile("Invalid GoldTotal"); }
        }
Esempio n. 6
0
        private static void CSAddCompanion(int NoToAdd)
        {
            Hero mainhero = Hero.MainHero;

            for (int i = 0; i < NoToAdd; i++)
            {
                string          Locculture = CSCharCreationOption.CSOptionSettlement().Culture.StringId;
                CharacterObject wanderer   = (from x in CharacterObject.Templates
                                              where x.Occupation == Occupation.Wanderer && (x.Culture.StringId == mainhero.Culture.StringId || x.Culture.StringId == Locculture)
                                              select x).GetRandomElementInefficiently <CharacterObject>();
                Settlement randomElement = (from settlement in Settlement.All
                                            where settlement.Culture == wanderer.Culture && settlement.IsTown
                                            select settlement).GetRandomElementInefficiently <Settlement>();
                Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, null, null, 33);
                Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, wanderer);
                GiveGoldAction.ApplyBetweenCharacters(null, hero, 2000, true);
                CSSetEquip(hero, 4);
                hero.HasMet = true;
                hero.Clan   = randomElement.OwnerClan;
                hero.ChangeState(Hero.CharacterStates.Active);
                AddCompanionAction.Apply(Clan.PlayerClan, hero);
                AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
                CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
            }
        }
Esempio n. 7
0
        private void HealPlayerCharacter()
        {
            int price = PriceToHeal(Hero.MainHero);

            Hero.MainHero.HitPoints = Hero.MainHero.MaxHitPoints;
            GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, -price, false);
            GameMenu.SwitchToMenu("town_medical_district");
        }
 public override void CalculateClanExpenses(Clan clan, ref ExplainedNumber goldChange, bool applyWithdrawals = false)
 {
     foreach (MobileParty party in clan.Parties)
     {
         if (party.IsActive && (party.IsLordParty || party.IsGarrison || party.IsCaravan))
         {
             int partyWage = this.CalculatePartyWage(party, applyWithdrawals);
             int amount    = party.LeaderHero == null || party.LeaderHero == clan.Leader || (party.IsCaravan || party.LeaderHero.Gold > 10000) ? 0 : (party.LeaderHero.Gold < 5000 ? (int)((double)(5000 - party.LeaderHero.Gold) / 10.0) : 0);
             if (applyWithdrawals)
             {
                 float num = (float)clan.Gold + MathF.Abs(goldChange.ResultNumber);
                 int   paymentAmount;
                 if ((double)num > (double)(partyWage + amount))
                 {
                     paymentAmount = partyWage;
                     if (amount > 0)
                     {
                         GiveGoldAction.ApplyBetweenCharacters((Hero)null, party.LeaderHero, amount, true);
                     }
                 }
                 else
                 {
                     paymentAmount = (int)num > 0 ? (int)num : 0;
                     if (paymentAmount > partyWage)
                     {
                         paymentAmount = partyWage;
                     }
                 }
                 HardmodeClanFinanceModel.ApplyMoraleEffect(party, partyWage, paymentAmount);
             }
             TextObject desription1 = new TextObject("{=rhKxsdtz} {PARTY_NAME} wages", (Dictionary <string, TextObject>)null);
             desription1.SetTextVariable("PARTY_NAME", party.Name);
             goldChange.Add((float)-partyWage, desription1);
             if (party.LeaderHero != null && party.LeaderHero != clan.Leader && amount > 0)
             {
                 TextObject desription2 = new TextObject("{=tetGlwTx} {PARTY_NAME} finance help", (Dictionary <string, TextObject>)null);
                 desription2.SetTextVariable("PARTY_NAME", party.Name);
                 goldChange.Add((float)-amount, desription2);
             }
         }
     }
     if (clan.MapFaction == null || !clan.MapFaction.IsKingdomFaction || clan.Leader != clan.MapFaction.Leader)
     {
         return;
     }
     foreach (Clan clan1 in ((Kingdom)clan.MapFaction).Clans)
     {
         if (!clan1.IsUnderMercenaryService && clan1 != clan && clan1.Fortifications.Count == 0)
         {
             TextObject desription = new TextObject("{=*} King's support", (Dictionary <string, TextObject>)null);
             int        num1       = ((clan1 == Clan.PlayerClan ? 1 : 0) + clan1.CommanderHeroes.Count) * 100;
             int        num2       = clan.Leader.Gold > num1 ? num1 : clan.Leader.Gold;
             goldChange.Add((float)-num2, desription);
         }
     }
 }
Esempio n. 9
0
 private static void SpawnPartyAtPosition(Hero hero, Vec2 position)
 {
     if (hero.IsActive || !hero.IsAlive)
     {
         return;
     }
     hero.ChangeState(Hero.CharacterStates.Active);
     GiveGoldAction.ApplyBetweenCharacters((Hero)null, hero, 3000, true);
     MobilePartyHelper.SpawnLordParty(hero, position, 0.5f);
 }
Esempio n. 10
0
 public static void PayWarReparations(Kingdom kingdom, Kingdom otherKingdom, int goldCost)
 {
     if (goldCost >= kingdom.Leader.Gold)
     {
         GiveGoldAction.ApplyBetweenCharacters(kingdom.Leader, otherKingdom.Leader, kingdom.Leader.Gold);
     }
     else
     {
         GiveGoldAction.ApplyBetweenCharacters(kingdom.Leader, otherKingdom.Leader, goldCost);
     }
 }
        private static void ml_menu_bribe_guards_consequence(MenuCallbackArgs args)
        {
            int bribe = Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement);

            if (bribe == 0)
            {
                bribe = 500;
            }
            GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, null, bribe, false);
            GameMenu.ActivateGameMenu("ml_garrison_menu");
        }
Esempio n. 12
0
        private void ApplyAddRelation(Hero hero, Clan clan, int daysToNow)
        {
            var relation = GetExpectRelation(hero, clan, daysToNow);
            var cost     = GetExpectGoldCostOfRelation(clan, relation);

            if (Hero.MainHero.Gold > cost * 1.2 && CharacterRelationManager.GetHeroRelation(Hero.MainHero, clan.Leader) < 100)
            {
                ChangeRelationAction.ApplyPlayerRelation(clan.Leader, GetExpectRelation(hero, clan, daysToNow, false));
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, clan.Leader, cost);
            }
        }
        private static void TakeGoldFromHero(Hero hero, Clan captorClan, out string goldLossMessage)
        {
            var goldAmount = CalculateGoldLoss(hero.Gold, MaximumGoldPenalty);

            GiveGoldAction.ApplyBetweenCharacters(hero, captorClan.Leader, goldAmount, true);

            GameTexts.SetVariable("AMOUNT", goldAmount);

            goldLossMessage = GameTexts.FindText("str_you_have_lost_AMOUNT_denars", null).ToString();

            InformationManager.DisplayMessage(new InformationMessage(goldLossMessage));
        }
Esempio n. 14
0
        private void HealPartyCharacters(bool healplayer)
        {
            int numberTreated = 0;
            int price         = 0;

            CalculatePriceAndNumInjured(ref price, ref numberTreated, healplayer, true);
            if (numberTreated > 0)
            {
                GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, -price, false);
            }
            GameMenu.SwitchToMenu("town_medical_district");
        }
Esempio n. 15
0
        private void ExecuteSellBrothel(object identifier)
        {
            if (_brothel == null)
            {
                return;
            }
            GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, _brothel.Capital);
            CEBrothelBehavior.BrothelInteraction(_brothel.Settlement, false);

            Action onRefresh = _onRefresh;

            onRefresh?.Invoke();
        }
Esempio n. 16
0
        internal void ConsequenceGold(Companion companion, Hero hero)
        {
            if (!companion.MultipleRestrictedListOfConsequences.Contains(RestrictedListOfConsequences.GiveGold))
            {
                return;
            }

            int content      = _score.AttractivenessScore(hero);
            int currentValue = hero.GetSkillValue(CESkills.Prostitution);

            content += currentValue / 2;
            content *= companion.MultipleRestrictedListOfConsequences.Count(consequence => consequence == RestrictedListOfConsequences.GiveGold);
            GiveGoldAction.ApplyBetweenCharacters(null, hero, content);
        }
Esempio n. 17
0
        private void ExecuteToggleBrothel(object identifier)
        {
            if (_brothel == null)
            {
                return;
            }
            if (!_brothel.IsRunning)
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, null, _brothel.Expense);
            }
            _brothel.IsRunning = !_brothel.IsRunning;
            Action onRefresh = _onRefresh;

            onRefresh?.Invoke();
        }
 private void OnDailyTick()
 {
     if (Config.Value.ClanPartyGoldLimitToTakeFromTreasury <= 0)
     {
         return;
     }
     foreach (MobileParty warParty in Clan.PlayerClan.WarParties)
     {
         if (!warParty.IsGarrison && !warParty.IsMilitia && (!warParty.IsVillager && !warParty.IsCaravan) && !warParty.IsMainParty && (warParty?.LeaderHero != null && warParty.LeaderHero.Gold < Config.Value.ClanPartyGoldLimitToTakeFromTreasury))
         {
             GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, warParty.LeaderHero, Config.Value.ClanPartyGoldLimitToTakeFromTreasury);
             InformationManager.DisplayMessage(new InformationMessage(warParty.LeaderHero.Name?.ToString() + " is short on gold and gets " + Config.Value.ClanPartyGoldLimitToTakeFromTreasury.ToString() + " from the treasury.", Colors.Yellow));
         }
     }
 }
Esempio n. 19
0
 public override void ApplyCost()
 {
     if (_giver != null && _receiver != null)
     {
         GiveGoldAction.ApplyBetweenCharacters(_giver, _receiver, (int)Value);
     }
     else if (_giver != null)
     {
         _giver.ChangeHeroGold(-(int)Value);
     }
     else if (_receiver != null)
     {
         _receiver.ChangeHeroGold((int)Value);
     }
 }
Esempio n. 20
0
        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);
        }
        private static void RecruitAllAvailableTroops(MenuCallbackArgs args)
        {
            try
            {
                var minusMoney        = 0;
                var recruitedAnyTroop = false;
                foreach (var notable in Settlement.CurrentSettlement.Notables)
                {
                    for (var i = 0; i < 6; ++i)
                    {
                        if (notable.VolunteerTypes[i] == null ||
                            !HeroHelper.HeroCanRecruitFromHero(Hero.MainHero, notable, i))
                        {
                            continue;
                        }

                        var troop = notable.VolunteerTypes[i];
                        var cost  = Campaign.Current.Models.PartyWageModel.GetTroopRecruitmentCost(troop, Hero.MainHero, false);

                        if (cost > Hero.MainHero.Gold)
                        {
                            continue;
                        }
                        minusMoney       += cost;
                        recruitedAnyTroop = true;
                        GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, null, cost, true);
                        notable.VolunteerTypes[i] = null;
                        MobileParty.MainParty.MemberRoster.AddToCounts(troop, 1, false, 0, 0, true, -1);
                        CampaignEventDispatcher.Instance.OnUnitRecruited(troop, 1);

                        InformationManager.DisplayMessage(new InformationMessage($"You recruited one {troop.Name}."));
                    }
                }

                if (recruitedAnyTroop)
                {
                    MBTextManager.SetTextVariable("GOLD_AMOUNT", minusMoney, false);
                    InformationManager.DisplayMessage(new InformationMessage(GameTexts.FindText("str_gold_removed_with_icon", null).ToString(), "event:/ui/notification/coins_negative"));
                }
            }
            catch (Exception ex)
            {
                NativeMethods.MessageBox(IntPtr.Zero, ex.Message, "RecruitAllButton -- RecruitAllAvailableTroops", NativeMethods.MB_ICONERROR | NativeMethods.MB_OK);
            }
        }
 private void OnPlayerWinTournament()
 {
     if (Campaign.Current.GameMode != CampaignGameMode.Campaign)
     {
         return;
     }
     GainRenownAction.Apply(Hero.MainHero, this._tournamentGame.TournamentWinRenown, false);
     if (Hero.MainHero.MapFaction.IsKingdomFaction && Hero.MainHero.MapFaction.Leader != Hero.MainHero)
     {
         GainKingdomInfluenceAction.ApplyForDefault(Hero.MainHero, 1f);
     }
     Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(this._tournamentGame.Prize, 1, true);
     if (this.OverallExpectedDenars > 0)
     {
         GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.OverallExpectedDenars, false);
     }
     Campaign.Current.TournamentManager.OnPlayerWinTournament(this._tournamentGame.GetType());
 }
Esempio n. 23
0
        public static void NewClanAllocateForHero(Hero hero, Clan clan)
        {
            if (hero.Clan == Clan.PlayerClan)
            {
                DealApplyByFire(Hero.MainHero.Clan, hero);
                SetOccupationToLord(hero);
                hero.Clan        = clan;
                hero.CompanionOf = null;
                hero.ChangeState(Hero.CharacterStates.Active);
                hero.IsNoble = true;


                if (hero.Age >= Campaign.Current.Models.AgeModel.HeroComesOfAge && hero.PartyBelongedTo == null)
                {
                    MobileParty chilrenMobileParty = clan.CreateNewMobileParty(hero);
                    chilrenMobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                    chilrenMobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);
                }

                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, 2000, false);
            }
        }
Esempio n. 24
0
        private void conversation_tavernkeep_bought_drinks()
        {
            int _curDrinkPrice = CalculateDrinksPrice();

            GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, null, _curDrinkPrice, false);
            if (_curDrinkPrice >= 500 && _curDrinkPrice < 1000)
            {
                GainRenownAction.Apply(Hero.MainHero, MBRandom.RandomFloatRanged(1.0f, 2.0f));
                Hero.MainHero.AddSkillXp(DefaultSkills.Charm, MBRandom.RandomInt(2, 4));
            }
            else if (_curDrinkPrice >= 1000 && _curDrinkPrice < 1500)
            {
                GainRenownAction.Apply(Hero.MainHero, MBRandom.RandomFloatRanged(2.0f, 3.5f));
                Hero.MainHero.AddSkillXp(DefaultSkills.Charm, MBRandom.RandomInt(4, 8));
            }
            else if (_curDrinkPrice >= 1500)
            {
                GainRenownAction.Apply(Hero.MainHero, MBRandom.RandomFloatRanged(3.5f, 5.0f));
                Hero.MainHero.AddSkillXp(DefaultSkills.Charm, MBRandom.RandomInt(5, 10));
            }
            InformationManager.DisplayMessage(new InformationMessage("Gained some renown and charm for buying drinks."));
            _boughtDrinksIn.Add(MobileParty.MainParty.CurrentSettlement);
        }
Esempio n. 25
0
        public override void CalculateClanExpenses(Clan clan, ref ExplainedNumber goldChange, bool applyWithdrawals = false)
        {
            base.CalculateClanExpenses(clan, ref goldChange, applyWithdrawals);
            int total     = 0;
            int partyWage = 0;
            int payAmount = 0;

            foreach (MobileParty party in clan.Parties)
            {
                partyWage = 0;
                payAmount = 0;
                if (party.Name.Contains("Patrol"))
                {
                    partyWage = (int)(party.GetTotalWage() * Settings.Instance.DailyPatrolWageModifier);
                    total    += partyWage;
                    if (applyWithdrawals && party.LeaderHero != null)
                    {
                        float currentClanGold = (float)clan.Gold + goldChange.ResultNumber;
                        if (currentClanGold < partyWage)
                        {
                            payAmount = (int)currentClanGold;
                        }
                        else
                        {
                            GiveGoldAction.ApplyBetweenCharacters(null, party.LeaderHero, partyWage, true);
                            payAmount = partyWage;
                        }
                        ApplyMoraleEffect(party, partyWage, payAmount);
                    }
                }
            }
            if (total > 0)
            {
                TextObject textObject = new TextObject("Total patrol wages", null);
                goldChange.Add((float)(-(float)total), textObject);
            }
        }
Esempio n. 26
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);
        }
Esempio n. 27
0
        public void CreateVassal()
        {
            //Settlement settlement = GetCandidateSettlements().FirstOrDefault<Settlement>();
            if (targetSettlement == null)
            {
                return;
            }
            Hero hero = Hero.OneToOneConversationHero;

            if (hero == null)
            {
                return;
            }
            Kingdom kingdom = Hero.MainHero.MapFaction as Kingdom;

            if (kingdom == null)
            {
                return;
            }

            CultureObject culture  = targetSettlement.Culture;
            TextObject    clanName = NameGenerator.Current.GenerateClanName(culture, targetSettlement);
            string        str      = Guid.NewGuid().ToString().Replace("-", "");

            if (null == hero.LastSeenPlace)
            {
                hero.CacheLastSeenInformation(hero.HomeSettlement, true);
                hero.SyncLastSeenInformation();
            }
            //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, hero);
            //for  1.4.3 200815
            HeroOperation.DealApplyByFire(Hero.MainHero.Clan, hero);

            HeroOperation.SetOccupationToLord(hero);
            hero.ChangeState(Hero.CharacterStates.Active);
            Clan   clan   = TaleWorlds.ObjectSystem.MBObjectManager.Instance.CreateObject <Clan>("sue_clan_" + str);
            Banner banner = Banner.CreateRandomClanBanner(-1);

            clan.InitializeClan(clanName, clanName, culture, banner);
            clan.SetLeader(hero);

            //clan.Tier = 5; 修改家族等级
            FieldInfo fieldInfoId = clan.GetType().GetField("_tier", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            if (null != fieldInfoId)
            {
                fieldInfoId.SetValue(clan, selectClanTier);
            }
            //增加一些影响力
            clan.AddRenown(50 * selectClanTier, true);


            hero.Clan        = clan;
            hero.CompanionOf = null;
            hero.IsNoble     = true;
            hero.SetTraitLevel(DefaultTraits.Commander, 1);

            MobileParty mobileParty = clan.CreateNewMobileParty(hero);

            mobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
            mobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

            ChangeOwnerOfSettlementAction.ApplyByKingDecision(hero, targetSettlement);
            clan.UpdateHomeSettlement(targetSettlement);


            int takeMoney = TakeMoneyByTier(selectClanTier);

            if (targetSpouse != null)
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney / 2, false);
            }
            else
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney, false);
            }

            //关系处理
            //新晋家族关系增加
            int shipIncreate = ShipIncreateByTier(selectClanTier);

            ChangeRelationAction.ApplyPlayerRelation(hero, shipIncreate, true, true);
            if (targetSpouse != null)
            {
                ChangeRelationAction.ApplyPlayerRelation(targetSpouse, shipIncreate, true, true);
            }

            //以前家族关系减低,
            int     shipReduce = ShipReduceByTier(selectClanTier);
            Kingdom kindom     = Hero.MainHero.MapFaction as Kingdom;

            if (null != kindom && shipReduce > 0)
            {
                kindom.Clans.ToList().ForEach((obj) =>
                {
                    if (obj != Clan.PlayerClan)
                    {
                        ChangeRelationAction.ApplyPlayerRelation(obj.Leader, shipReduce * -1, true, true);
                    }
                }
                                              );
            }

            if (targetSpouse != null)
            {
                targetSpouse.Spouse = hero;
                InformationManager.AddQuickInformation(new TextObject($"{hero.Name} marry with {targetSpouse.Name}"), 0, null, "event:/ui/notification/quest_finished");

                HeroOperation.DealApplyByFire(Hero.MainHero.Clan, targetSpouse);
                //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, targetSpouse);

                targetSpouse.ChangeState(Hero.CharacterStates.Active);
                targetSpouse.IsNoble = true;
                HeroOperation.SetOccupationToLord(targetSpouse);
                targetSpouse.CompanionOf = null;
                targetSpouse.Clan        = clan;
                targetSpouse.SetTraitLevel(DefaultTraits.Commander, 1);
                //AddCompanionAction.Apply(clan, targetSpouse);

                MobileParty targetSpouseMobileParty = clan.CreateNewMobileParty(targetSpouse);

                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, targetSpouse, takeMoney / 2, false);
            }

            // 他们孩子处理
            if (isTogetherWithThireChildren)
            {
                DealTheirChildren(hero, clan);
            }


            //加入王国
            ChangeKingdomAction.ApplyByJoinToKingdom(clan, kingdom, true);
        }
        internal static bool GiveShareOfLootToPartyPre(ref object __instance, PartyBase partyToReceiveLoot, PartyBase winnerParty, float lootAmount)
        {
            //var ___LootedMembers= Traverse.Create<LootCollectorType>(__instance).Field("LootedMembers").GetValue()
            var ___LootedMembers      = LootCollectorType.GetProperty("LootedMembers", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as TroopRoster;
            var ___LootedPrisoners    = LootCollectorType.GetProperty("LootedPrisoners", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as TroopRoster;
            var ___CasualtiesInBattle = LootCollectorType.GetProperty("CasualtiesInBattle", BindingFlags.Public | BindingFlags.Instance).GetValue(__instance) as TroopRoster;
            var ___LootedItems        = LootCollectorType.GetProperty("LootedItems", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as ItemRoster;

            bool flag = winnerParty == PartyBase.MainParty;
            List <TroopRosterElement> troopRosterElements = new List <TroopRosterElement>();

            foreach (TroopRosterElement lootedMember in ___LootedMembers)
            {
                int             number    = lootedMember.Number;
                CharacterObject character = lootedMember.Character;
                for (int i = 0; i < number; i++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        TroopRosterElement troopRosterElement = new TroopRosterElement(character)
                        {
                            Number        = 1,
                            WoundedNumber = 1
                        };
                        troopRosterElements.Add(troopRosterElement);
                    }
                }
            }
            foreach (TroopRosterElement troopRosterElement1 in troopRosterElements)
            {
                ___LootedMembers.AddToCounts(troopRosterElement1.Character, -1, false, 0, 0, true, -1);
            }
            foreach (TroopRosterElement troopRosterElement2 in troopRosterElements)
            {
                if (!troopRosterElement2.Character.IsHero)
                {
                    partyToReceiveLoot.PrisonRoster.AddToCounts(troopRosterElement2.Character, troopRosterElement2.Number, false, 0, 0, true, -1);
                }
                else if (!partyToReceiveLoot.IsMobile)
                {
                    TakePrisonerAction.Apply(partyToReceiveLoot, troopRosterElement2.Character.HeroObject);
                }
                else
                {
                    TakePrisonerAction.Apply(partyToReceiveLoot, troopRosterElement2.Character.HeroObject);
                }
            }
            ICollection <ItemRosterElement> itemRosterElements = new List <ItemRosterElement>();

            for (int j = ___LootedItems.Count <ItemRosterElement>() - 1; j >= 0; j--)
            {
                ItemRosterElement elementCopyAtIndex = ___LootedItems.GetElementCopyAtIndex(j);
                int num = 0;
                EquipmentElement equipmentElement = elementCopyAtIndex.EquipmentElement;
                ItemObject       item             = equipmentElement.Item;
                equipmentElement = elementCopyAtIndex.EquipmentElement;
                ItemRosterElement itemRosterElement = new ItemRosterElement(item, 1, equipmentElement.ItemModifier);
                for (int k = 0; k < elementCopyAtIndex.Amount; k++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        itemRosterElements.Add(itemRosterElement);
                        num++;
                    }
                }
                ___LootedItems.AddToCounts(itemRosterElement.EquipmentElement, -num, true);
            }
            partyToReceiveLoot.ItemRoster.Add(itemRosterElements);
            for (int l = ___LootedPrisoners.Count <TroopRosterElement>() - 1; l >= 0; l--)
            {
                int             elementNumber    = ___LootedPrisoners.GetElementNumber(l);
                CharacterObject characterAtIndex = ___LootedPrisoners.GetCharacterAtIndex(l);
                int             num1             = 0;
                for (int m = 0; m < elementNumber; m++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        partyToReceiveLoot.MemberRoster.AddToCounts(characterAtIndex, 1, false, 0, 0, true, -1);
                        num1++;
                    }
                }
                ___LootedPrisoners.AddToCounts(characterAtIndex, -num1, false, 0, 0, true, -1);
            }
            ICollection <TroopRosterElement> troopRosterElements1 = new List <TroopRosterElement>();

            for (int n = ___CasualtiesInBattle.Count <TroopRosterElement>() - 1; n >= 0; n--)
            {
                int                elementNumber1      = ___CasualtiesInBattle.GetElementNumber(n);
                CharacterObject    characterObject     = ___CasualtiesInBattle.GetCharacterAtIndex(n);
                int                num2                = 0;
                TroopRosterElement troopRosterElement3 = new TroopRosterElement(characterObject);
                for (int o = 0; o < elementNumber1; o++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        troopRosterElements1.Add(troopRosterElement3);
                        num2++;
                    }
                }
                ___CasualtiesInBattle.AddToCounts(characterObject, -num2, false, 0, 0, true, -1);
            }
            ExplainedNumber explainedNumber = new ExplainedNumber(1f, null);

            if (winnerParty.MobileParty != null && winnerParty.MobileParty.Leader != null)
            {
                //Get the best looter
                if (winnerParty.MobileParty == MobileParty.MainParty)
                {
                    SkillHelper.AddSkillBonusForCharacter(DefaultSkills.Roguery, DefaultSkillEffects.RogueryLootBonus, BMHelpers.CharacterHelpers.GetCharacterWithHighestSkill(winnerParty, DefaultSkills.Roguery), ref explainedNumber, true);
                }
                else
                {
                    SkillHelper.AddSkillBonusForCharacter(DefaultSkills.Roguery, DefaultSkillEffects.RogueryLootBonus, winnerParty.MobileParty.Leader, ref explainedNumber, true);
                }
            }
            if (flag)
            {
                IEnumerable <ItemRosterElement> itemRosterElements1 = LootCasualties(troopRosterElements1, explainedNumber.ResultNumber, flag);
                partyToReceiveLoot.ItemRoster.Add(itemRosterElements1);
            }
            else if (partyToReceiveLoot.LeaderHero != null)
            {
                int gold = ConvertLootToGold(LootCasualties(troopRosterElements1, 0.5f));
                gold = MBMath.Round((float)gold * 0.5f * explainedNumber.ResultNumber);
                GiveGoldAction.ApplyBetweenCharacters(null, partyToReceiveLoot.LeaderHero, gold, false);
                return(false);
            }

            return(false);
        }
Esempio n. 29
0
        public virtual void OnSend()
        {
            int gold = CPSModule.PostalServiceModel.GetCourierFee(this.Sender, this.Recipient);

            GiveGoldAction.ApplyBetweenCharacters(this.Sender, null, gold, false);
        }
Esempio n. 30
0
        private void OnChangeClanLeader(float dt)
        {
            MobileParty leaderParty    = leader.PartyBelongedTo;
            MobileParty newLeaderParty = newLeader.PartyBelongedTo;

            Utils.Print($"[OnChangeClanLeader] current leader {leader.Name} new leader {newLeader.Name}");

            if (leader == null || newLeader == null || leaderParty == null || newLeaderParty == null)
            {
                return;
            }

            if (newLeader.GovernorOf != null)
            {
                ChangeGovernorAction.ApplyByGiveUpCurrent(newLeader);
            }
            if (leader.GovernorOf != null)
            {
                ChangeGovernorAction.ApplyByGiveUpCurrent(leader);
            }

            string evt;

            while ((evt = newLeader.GetHeroOccupiedEvents().FirstOrDefault()) != default)
            {
                newLeader.RemoveEventFromOccupiedHero(evt);
            }
            while ((evt = leader.GetHeroOccupiedEvents().FirstOrDefault()) != default)
            {
                leader.RemoveEventFromOccupiedHero(evt);
            }

            GiveGoldAction.ApplyBetweenCharacters(leader, newLeader, leader.Gold, true);

            leader.Clan.SetLeader(newLeader);

            Settlement currentSettlement = newLeaderParty.CurrentSettlement;

            ChangePlayerCharacterAction.Apply(newLeader);

            if (newLeaderParty != leaderParty)
            {
                if (newLeaderParty.CurrentSettlement == null)
                {
                    EnterSettlementAction.ApplyForParty(newLeaderParty, currentSettlement);
                }

                foreach (var troop in leaderParty.MemberRoster.GetTroopRoster())
                {
                    if (troop.Character == leader.CharacterObject)
                    {
                        continue;
                    }

                    leaderParty.MemberRoster.AddToCounts(troop.Character, -troop.Number);
                    newLeaderParty.MemberRoster.AddToCounts(troop.Character, troop.Number);
                }

                foreach (var troop in leaderParty.PrisonRoster.GetTroopRoster())
                {
                    if (troop.Character == leader.CharacterObject)
                    {
                        continue;
                    }

                    leaderParty.PrisonRoster.AddToCounts(troop.Character, -troop.Number);
                    newLeaderParty.PrisonRoster.AddToCounts(troop.Character, troop.Number);
                }

                ItemRosterElement i;
                while (leaderParty.ItemRoster.Count() > 0)
                {
                    i = leaderParty.ItemRoster.First();
                    leaderParty.ItemRoster.AddToCounts(i.EquipmentElement, -i.Amount);
                    newLeaderParty.ItemRoster.AddToCounts(i.EquipmentElement, i.Amount);
                }

                leaderParty.RemoveParty();
                AddHeroToPartyAction.Apply(leader, newLeaderParty);
            }
            else
            {
                leaderParty.Party.Owner = newLeader;
                var partyList = leaderParty.Party.MemberRoster;
                partyList.RemoveTroop(newLeader.CharacterObject);
                partyList.AddToCounts(newLeader.CharacterObject, 1, true);
                var newPartyName = new TextObject("{=shL0WElC}{TROOP.NAME}'s Party");
                newPartyName.SetCharacterProperties("TROOP", newLeader.CharacterObject);
                leaderParty.SetCustomName(newPartyName);
            }

            leader.HasMet = true;

            newLeader.Clan.Influence = Math.Max(0, newLeader.Clan.Influence - 100);

            HeroFixHelper.FixHeroStats(newLeader);
            HeroFixHelper.FixEquipment(newLeader);

            newLeaderParty.Party.Visuals.SetMapIconAsDirty();
            CampaignEventDispatcher.Instance.OnArmyOverlaySetDirty();

            newLeader = null;
            leader    = null;
            CampaignEvents.RemoveListeners(this);
            Utils.Print($"[OnChangeClanLeader] changed over");
        }