private void addXpToGarrison(Settlement settle) { var town = settle.Town; if (town == null) { return; } if (town.GarrisonChange > 1 && (town.GarrisonParty == null || !town.GarrisonParty.IsActive)) { town.Owner.Settlement.AddGarrisonParty(); } if (town.GarrisonParty != null && town.GarrisonParty.IsActive && town.GarrisonParty.MapEvent == null && town.GarrisonParty.CurrentSettlement != null) { int bonusXp = Campaign.Current.Models.DailyTroopXpBonusModel.CalculateDailyTroopXpBonus(town); float xpMultiplier = Campaign.Current.Models.DailyTroopXpBonusModel.CalculateGarrisonXpBonusMultiplier(town); if (bonusXp > 0) { for (int i = 0; i < town.GarrisonParty.MemberRoster.Count; i++) { TroopRosterElement troopElement = town.GarrisonParty.MemberRoster.GetElementCopyAtIndex(i); int totalTroopXp = TaleWorlds.Library.MathF.Round((float)(bonusXp * xpMultiplier * troopElement.Number * ConfigLoader.Instance.Config.GarrisonTrainingXpMultiplier) - (bonusXp * xpMultiplier)); town.GarrisonParty.MemberRoster.AddXpToTroopAtIndex(totalTroopXp, i); } } } }
public override void StartEvent() { MobileParty.MainParty.RecentEventsMorale += moraleGain; MobileParty.MainParty.MoraleExplained.Add(moraleGain, new TaleWorlds.Localization.TextObject("Random Event")); for (int i = 0; i < PartyBase.MainParty.MemberRoster.Count; i++) { TroopRosterElement elementCopyAtIndex = PartyBase.MainParty.MemberRoster.GetElementCopyAtIndex(i); if (elementCopyAtIndex.Character.IsHero) { elementCopyAtIndex.Character.HeroObject.Heal(PartyBase.MainParty, 100, false); } else { MobileParty.MainParty.Party.AddToMemberRosterElementAtIndex(i, 0, -PartyBase.MainParty.MemberRoster.GetElementWoundedNumber(i)); } } InformationManager.ShowInquiry( new InquiryData("The Hot Springs", $"You stumble upon some beautiful hot springs. After bathing with your soldiers you feel fantastic!", true, false, "Done", null, null, null ), true); StopEvent(); }
public static void DesertTroopsFromParty(MobileParty party, int stackNo, int numberOfDeserters, ref TroopRoster desertedTroopList) { TroopRosterElement rosterSlot = party.MemberRoster.GetElementCopyAtIndex(stackNo); party.MemberRoster.AddToCounts(rosterSlot.Character, -numberOfDeserters, false, 0, 0, true, -1); if (desertedTroopList == (TroopRoster)null) { desertedTroopList = new TroopRoster(); } desertedTroopList.AddToCounts(rosterSlot.Character, numberOfDeserters, false, 0, 0, true, -1); }
public SpousesSelectTroopsItemVM(TroopRosterElement troop, Action <SpousesSelectTroopsItemVM> onAdd, Action <SpousesSelectTroopsItemVM> onRemove) { this._onAdd = onAdd; this._onRemove = onRemove; this.Troop = troop; this.MaxAmount = this.Troop.Number - this.Troop.WoundedNumber; this.Visual = new ImageIdentifierVM(CampaignUIHelper.GetCharacterCode(troop.Character, false)); this.Name = troop.Character.Name.ToString(); this.TierIconData = CampaignUIHelper.GetCharacterTierData(this.Troop.Character, false); this.TypeIconData = CampaignUIHelper.GetCharacterTypeData(this.Troop.Character, false); }
private void addXp(MobileParty party) { if (!party.IsActive) { return; } bool hasCombatTips = party.HasPerk(DefaultPerks.Leadership.CombatTips); bool hasRaiseTheMeek = party.HasPerk(DefaultPerks.Leadership.RaiseTheMeek); if (!hasCombatTips && !hasRaiseTheMeek) { return; } for (int i = 0; i < party.MemberRoster.Count; i++) { TroopRosterElement troopElement = party.MemberRoster.GetElementCopyAtIndex(i); int troopMultiplier = troopElement.Number; int totalTroopXp = 0; // If we scaleByReadyToUpgrade, ignore the amount of units ready to upgrade if (ConfigLoader.Instance.Config.ScaleByReadyToUpgrade) { troopMultiplier -= troopElement.NumberReadyToUpgrade; } if (hasCombatTips) { // Add combatTips xp totalTroopXp += ConfigLoader.Instance.Config.CombatTipsXpAmount * troopMultiplier; // Remove the default added xp totalTroopXp -= Campaign.Current.Models.PartyTrainingModel.GetPerkExperiencesForTroops(DefaultPerks.Leadership.CombatTips); } if (hasRaiseTheMeek && troopElement.Character.Tier < 4) { // Add raiseTheMeek xp totalTroopXp += ConfigLoader.Instance.Config.RaiseTheMeekXpAmount * troopMultiplier; // Remove the default added xp only if we haven't removed it for CombatTips, native doesn't support both // even if its technically possible as party can have multiple leaders. It only applies CombatTips instead. if (!hasCombatTips) { totalTroopXp -= Campaign.Current.Models.PartyTrainingModel.GetPerkExperiencesForTroops(DefaultPerks.Leadership.RaiseTheMeek); } } // Add xp to the troop party.Party.MemberRoster.AddXpToTroopAtIndex(totalTroopXp, i); } }
private void FindDuplicateParties() { try { HashSet <Hero> heroSet1 = new HashSet <Hero>(5); HashSet <Hero> heroSet2 = new HashSet <Hero>(5); for (int index = 0; index < MobileParty.MainParty.MemberRoster.Count; ++index) { TroopRosterElement elementCopyAtIndex = MobileParty.MainParty.MemberRoster.GetElementCopyAtIndex(index); if (elementCopyAtIndex.Character.IsHero && elementCopyAtIndex.Character != Hero.MainHero.CharacterObject) { if (elementCopyAtIndex.Number > 1) { int num = (int)MessageBox.Show("Party AI Overhaul and Commands: Found duplicate companion: " + elementCopyAtIndex.Character.Name?.ToString() + "\nThis was most likely caused by a bug, the duplicate will now be deleted. You can continue playing.\nIf you have good reason to believe this was not a duplicate, please report so on nexusmods."); MobileParty.MainParty.MemberRoster.AddToCountsAtIndex(index, -(elementCopyAtIndex.Number - 1)); } heroSet1.Add(elementCopyAtIndex.Character.HeroObject); } } for (int index = 0; index < Campaign.Current.MobileParties.Count; ++index) { MobileParty mobileParty = Campaign.Current.MobileParties[index]; if (mobileParty?.Party?.Owner != null && mobileParty.IsLordParty) { if (mobileParty.LeaderHero == null) { int num = (int)MessageBox.Show("Party AI Overhaul and Commands: Found duplicate party: " + mobileParty.Name?.ToString() + "\nThis was most likely caused by a bug, the duplicate will now be deleted. You can continue playing.\nIf you have good reason to believe this was not a duplicate, please report so on nexusmods."); mobileParty.RemoveParty(); } else if (heroSet1.Contains(mobileParty.LeaderHero)) { int num = (int)MessageBox.Show("Party AI Overhaul and Commands: Found duplicate companion and party: " + mobileParty.Name?.ToString() + "\nThis was most likely caused by a bug, the duplicate companion in your party will now be deleted. You can continue playing.\nIf you have good reason to believe this was not a duplicate, please report so on nexusmods."); MobileParty.MainParty.MemberRoster.RemoveTroop(mobileParty.Leader); heroSet2.Add(mobileParty.LeaderHero); } else if (heroSet2.Contains(mobileParty.LeaderHero) && mobileParty.LeaderHero.Clan == Clan.PlayerClan) { int num = (int)MessageBox.Show("Party AI Overhaul and Commands: Found duplicate party: " + mobileParty.Name?.ToString() + "\nThis was most likely caused by a bug, the duplicate will now be deleted. You can continue playing.\nIf you have good reason to believe this was not a duplicate, please report so on nexusmods."); mobileParty.RemoveParty(); } else { heroSet2.Add(mobileParty.LeaderHero); } } } } catch (Exception ex) { int num = (int)MessageBox.Show(ex.FlattenException()); } }
//If performance is an issue let's memoize this, reason I haven't done that off the bat is //there is no readily safe identifier I can use to link the same troop types. //and honestly I think its over-optimising anyways to even consider it, memory is enough of a problem. private static double getTroopXpDivisor(TroopRoster roster, FlattenedTroopRosterElement item) { int indexOfTroop = roster.FindIndexOfTroop(item.Troop); if (indexOfTroop == -1) { return(1); } TroopRosterElement element = roster.GetElementCopyAtIndex(indexOfTroop); if (element.NumberReadyToUpgrade == 0 || element.Number == 0) { return(1); } return((double)element.Number / (double)element.NumberReadyToUpgrade); }
private void addXp(MobileParty party) { Boolean hasBoth = false; if (party.IsActive && party.HasPerk(DefaultPerks.Leadership.CombatTips) && party.HasPerk(DefaultPerks.Leadership.CombatTips)) { hasBoth = true; } if (party.IsActive && party.HasPerk(DefaultPerks.Leadership.CombatTips)) { for (int i = 0; i < party.MemberRoster.Count; i++) { TroopRosterElement troopElement = party.MemberRoster.GetElementCopyAtIndex(i); int troopMultiplier = troopElement.Number; if (ConfigLoader.Instance.Config.ScaleByReadyToUpgrade) { troopMultiplier -= troopElement.NumberReadyToUpgrade; } int totalTroopXp = ConfigLoader.Instance.Config.CombatTipsXpAmount * troopMultiplier; //Remove the default added xp totalTroopXp -= Campaign.Current.Models.PartyTrainingModel.GetTroopPerksXp(DefaultPerks.Leadership.CombatTips); party.Party.MemberRoster.AddXpToTroopAtIndex(totalTroopXp, i); } } if (party.IsActive && party.HasPerk(DefaultPerks.Leadership.RaiseTheMeek)) { for (int i = 0; i < party.MemberRoster.Count; i++) { TroopRosterElement troopElement2 = party.MemberRoster.GetElementCopyAtIndex(i); if (troopElement2.Character.Tier < 4) { int defaultSingleTroopPerksXp2 = Campaign.Current.Models.PartyTrainingModel.GetTroopPerksXp(DefaultPerks.Leadership.RaiseTheMeek); int totalTroopXp2 = ConfigLoader.Instance.Config.RaiseTheMeekXpAmount * troopElement2.Number; if (!hasBoth) { //Remove the default added xp only if we haven't removed it for CombatTips, native doesn't support both //even if its technically possible as party can have multiple leaders. It only applies CombatTips instead. totalTroopXp2 -= Campaign.Current.Models.PartyTrainingModel.GetTroopPerksXp(DefaultPerks.Leadership.RaiseTheMeek); } party.Party.MemberRoster.AddXpToTroopAtIndex(totalTroopXp2, i); } } } }
private PartyState GetPartyState(PartyBase party) { if (!PartyStates.TryGetValue(party.Id, out PartyState partyState)) { partyState = new PartyState(this, party.Side == BattleSideEnum.Attacker); PartyStates[party.Id] = partyState; for (int index = 0; index < party.MemberRoster.Count; ++index) { TroopRosterElement elementCopyAtIndex = party.MemberRoster.GetElementCopyAtIndex(index); CharacterObject troop = elementCopyAtIndex.Character; if (troop != null) { partyState.RegisterTroops(troop, (elementCopyAtIndex.Number - elementCopyAtIndex.WoundedNumber)); } } } return(partyState); }
private void DoPrisonerTransfer(MobileParty prisonerParty) { var rosterAsList = MobileParty.MainParty.PrisonRoster.GetTroopRoster(); for (int i = 0; i < rosterAsList.Count; i++) { TroopRosterElement element = rosterAsList[i]; if (!element.Character.IsHero) { prisonerParty.AddElementToMemberRoster(element.Character, element.Number); MobileParty.MainParty.PrisonRoster.RemoveTroop(element.Character, element.Number); } else { heroInPrisonerRoster = true; } } }
private void CheckForTroopDesertionEffectiveMorale(MobileParty party, int stackNo, int desertIfMoraleIsLessThanValue, out int numberOfDeserters) { int regularDeserters = 0; float morale = party.Morale; if (party.IsActive && party.MemberRoster.Count > 0) { TroopRosterElement troopStack = party.MemberRoster.GetElementCopyAtIndex(stackNo); double desertChance = Math.Pow((double)troopStack.Character.Level / 100.0, 0.100000001490116 * (((double)desertIfMoraleIsLessThanValue - (double)morale) / (double)desertIfMoraleIsLessThanValue)); for (int index = 0; index < troopStack.Number; ++index) { if (desertChance < (double)MBRandom.RandomFloat) { ++regularDeserters; } } } numberOfDeserters = regularDeserters; }
private static void SplitRosters(TroopRoster troops1, TroopRoster troops2, TroopRosterElement rosterElement) { // toss a coin (to your Witcher) if (rosterElement.Number == 1) { if (Rng.Next(0, 2) == 0) { troops1.AddToCounts(rosterElement.Character, 1); } else { troops2.AddToCounts(rosterElement.Character, 1); } } else { var half = Math.Max(1, rosterElement.Number / 2); troops1.AddToCounts(rosterElement.Character, half); var remainder = rosterElement.Number % 2; troops2.AddToCounts(rosterElement.Character, Math.Max(1, half + remainder)); } }
public void OnSettlementEntered(MobileParty mobileParty, Settlement settlement, Hero hero) { if (mobileParty != null && mobileParty.IsActive && mobileParty.Name.Contains("Patrol")) { //InformationManager.DisplayMessage(new InformationMessage(new TextObject("Patrol entered " + settlement.Name, null).ToString())); if (settlement.IsTown || settlement.IsCastle) { for (int i = 0; i < mobileParty.PrisonRoster.Count; i++) { TroopRosterElement prisoner = mobileParty.PrisonRoster.GetElementCopyAtIndex(i); int woundedNumber = prisoner.WoundedNumber; if (prisoner.Character.IsHero) { EnterSettlementAction.ApplyForPrisoner(prisoner.Character.HeroObject, settlement); } settlement.Party.PrisonRoster.AddToCounts(prisoner.Character, prisoner.Number, false, woundedNumber, 0, true, -1); mobileParty.PrisonRoster.RemoveTroop(prisoner.Character, prisoner.Number, default(UniqueTroopDescriptor), 0); } mobileParty.SetMoveGoToPoint(mobileParty.HomeSettlement.GatePosition); } } }
private static void SacrificeTroopsWithRatio( MobileParty mobileParty, float sacrifaceRatio) { int num1 = MBRandom.RoundRandomized((float)mobileParty.Party.NumberOfRegularMembers * sacrifaceRatio); for (int index = 0; index < num1; ++index) { float num2 = 100f; TroopRosterElement troopRosterElement1 = mobileParty.Party.MemberRoster.First <TroopRosterElement>(); foreach (TroopRosterElement troopRosterElement2 in mobileParty.Party.MemberRoster) { float num3 = (float)((double)troopRosterElement2.Character.Level - (troopRosterElement2.WoundedNumber > 0 ? 0.5 : 0.0) - (double)MBRandom.RandomFloat * 0.5); if (!troopRosterElement2.Character.IsHero && (double)num3 < (double)num2 && troopRosterElement2.Number > 0) { num2 = num3; troopRosterElement1 = troopRosterElement2; } } mobileParty.MemberRoster.AddToCounts(troopRosterElement1.Character, -1, false, troopRosterElement1.WoundedNumber > 0 ? -1 : 0, 0, true, -1); } }
private static void SortRoster(SorterConfiguration configuration, TroopRoster troopRoster, ICollection <PartyCharacterVM> partyList, Action <MBBindingList <PartyCharacterVM> > apply) { FieldInfo troopRosterDataField = troopRoster.GetType().GetField("data", BindingFlags.NonPublic | BindingFlags.Instance); TroopRosterElement[] originalTroops = (TroopRosterElement[])troopRosterDataField?.GetValue(troopRoster); if (originalTroops == null || originalTroops.All(x => x.Character == null)) { return; } List <TroopRosterElement> originalTroopList = originalTroops.Where(x => x.Character != null).ToList(); List <TroopRosterElement> sortedTroops = originalTroopList.Where(x => !x.Character.IsHero).ToList(); List <TroopRosterElement> heroTroops = originalTroopList.Where(x => x.Character.IsHero && !x.Character.IsPlayerCharacter).ToList(); TroopRosterElement player = originalTroopList.FirstOrDefault(x => x.Character.IsPlayerCharacter); TroopSorterService.Sort(ref sortedTroops, ref heroTroops, configuration); if (heroTroops.Count > 0) { sortedTroops.InsertRange(0, heroTroops); } if (player.Character != null) { sortedTroops.Insert(0, player); } troopRosterDataField.SetValue(troopRoster, sortedTroops.ToArray()); List <PartyCharacterVM> tempTroopList = partyList.ToList(); MBBindingList <PartyCharacterVM> newTroopList = new MBBindingList <PartyCharacterVM>(); partyList.Clear(); foreach (PartyCharacterVM troop in sortedTroops.Select(sortedTroop => tempTroopList.FirstOrDefault(x => x.Troop.Character.ToString() == sortedTroop.Character.ToString()))) { newTroopList.Add(troop); } apply(newTroopList); }
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); }
public static bool HasHigherTierToUpgradeTo(this TroopRosterElement element) { return(!element.Character.IsHero && element.Character.UpgradeTargets != null && element.Character.UpgradeTargets.Length != 0); }
internal void CECaptorHuntPrisoners(MenuCallbackArgs args, int amount = 20) { CEPersistence.animationPlayEvent = false; TroopRoster releasedPrisoners = TroopRoster.CreateDummyTroopRoster(); if (CESettings.Instance != null) { amount = CESettings.Instance.AmountOfTroopsForHunt; } try { for (int i = 0; i < amount; i++) { TroopRosterElement test = MobileParty.MainParty.PrisonRoster.GetTroopRoster().Where(troop => !troop.Character.IsHero).GetRandomElementInefficiently(); if (test.Character == null) { continue; } MobileParty.MainParty.PrisonRoster.RemoveTroop(test.Character); releasedPrisoners.AddToCounts(test.Character, 1, true); } } catch (Exception) { CECustomHandler.LogToFile("Couldn't find anymore prisoners."); } if (!releasedPrisoners.GetTroopRoster().IsEmpty()) { CECaptorContinue(args); try { Clan clan = Clan.BanditFactions.First(clanLooters => clanLooters.StringId == "looters"); clan.Banner.SetBannerVisual(Banner.CreateRandomBanner().BannerVisual); Settlement nearest = SettlementHelper.FindNearestSettlement(settlement => { return(true); }); MobileParty prisonerParty = BanditPartyComponent.CreateBanditParty("CustomPartyCE_Hunt_" + MBRandom.RandomInt(int.MaxValue), clan, nearest.Hideout, false); PartyTemplateObject defaultPartyTemplate = clan.DefaultPartyTemplate; prisonerParty.InitializeMobileParty(defaultPartyTemplate, MobileParty.MainParty.Position2D, 0.5f, 0.1f, -1); prisonerParty.SetCustomName(new TextObject("{=CEEVENTS1107}Escaped Captives")); prisonerParty.MemberRoster.Clear(); prisonerParty.MemberRoster.Add(releasedPrisoners.ToFlattenedRoster()); prisonerParty.RecentEventsMorale = -100; prisonerParty.IsActive = true; prisonerParty.ActualClan = clan; prisonerParty.Party.Owner = clan.Leader; prisonerParty.Party.Visuals.SetMapIconAsDirty(); prisonerParty.HomeSettlement = nearest; prisonerParty.InitializePartyTrade(0); Hero.MainHero.HitPoints += 40; CECustomHandler.LogToFile(prisonerParty.Leader.Name.ToString()); PlayerEncounter.RestartPlayerEncounter(prisonerParty.Party, MobileParty.MainParty.Party, true); StartBattleAction.Apply(MobileParty.MainParty.Party, prisonerParty.Party); PlayerEncounter.Update(); CEPersistence.huntState = CEPersistence.HuntState.StartHunt; CampaignMission.OpenBattleMission(PlayerEncounter.GetBattleSceneForMapPosition(MobileParty.MainParty.Position2D)); } catch (Exception) { CECaptorKillPrisoners(args, amount); } } else { CECaptorContinue(args); } }
internal void CECaptorPrisonerRebel(MenuCallbackArgs args) { CEPersistence.animationPlayEvent = false; TroopRoster releasedPrisoners = TroopRoster.CreateDummyTroopRoster(); try { foreach (TroopRosterElement element in MobileParty.MainParty.PrisonRoster.GetTroopRoster()) { if (element.Character.IsHero) { element.Character.HeroObject.ChangeState(Hero.CharacterStates.Active); } } releasedPrisoners.Add(MobileParty.MainParty.PrisonRoster.ToFlattenedRoster()); MobileParty.MainParty.PrisonRoster.Clear(); } catch (Exception) { CECustomHandler.LogToFile("Couldn't find anymore prisoners."); } if (!releasedPrisoners.GetTroopRoster().IsEmpty()) { try { TroopRosterElement leader = releasedPrisoners.GetTroopRoster().FirstOrDefault(hasHero => hasHero.Character.IsHero); Clan clan = null; Settlement nearest = null; MobileParty prisonerParty = null; if (leader.Character != null) { clan = leader.Character.HeroObject.Clan; nearest = SettlementHelper.FindNearestSettlement(settlement => settlement.OwnerClan == clan) ?? SettlementHelper.FindNearestSettlement(settlement => true); prisonerParty = LordPartyComponent.CreateLordParty("CustomPartyCE_" + MBRandom.RandomInt(int.MaxValue), leader.Character.HeroObject, MobileParty.MainParty.Position2D, 0.5f, nearest); } else { clan = Clan.BanditFactions.First(clanLooters => clanLooters.StringId == "looters"); clan.Banner.SetBannerVisual(Banner.CreateRandomBanner().BannerVisual); nearest = SettlementHelper.FindNearestSettlement(settlement => true); prisonerParty = BanditPartyComponent.CreateBanditParty("CustomPartyCE_" + MBRandom.RandomInt(int.MaxValue), clan, nearest.Hideout, false); } PartyTemplateObject defaultPartyTemplate = clan.DefaultPartyTemplate; prisonerParty.InitializeMobileParty(defaultPartyTemplate, MobileParty.MainParty.Position2D, 0.5f, 0.1f, -1); prisonerParty.SetCustomName(new TextObject("{=CEEVENTS1107}Escaped Captives")); prisonerParty.MemberRoster.Clear(); prisonerParty.ActualClan = clan; prisonerParty.MemberRoster.Add(releasedPrisoners.ToFlattenedRoster()); prisonerParty.IsActive = true; prisonerParty.HomeSettlement = nearest; prisonerParty.SetMovePatrolAroundPoint(nearest.IsTown ? nearest.GatePosition : nearest.Position2D); if (leader.Character != null) { prisonerParty.Party.Owner = leader.Character.HeroObject; #if BETA prisonerParty.ChangePartyLeader(leader.Character); #else prisonerParty.ChangePartyLeader(leader.Character, true); #endif } else { prisonerParty.Party.Owner = clan.Leader; } prisonerParty.RecentEventsMorale = -100; prisonerParty.Aggressiveness = 0.2f; prisonerParty.InitializePartyTrade(0); Hero.MainHero.HitPoints += 40; CECustomHandler.LogToFile(prisonerParty.Leader.Name.ToString()); PlayerEncounter.RestartPlayerEncounter(MobileParty.MainParty.Party, prisonerParty.Party); GameMenu.SwitchToMenu("encounter"); } catch (Exception) { CECaptorContinue(args); } } else { CECaptorContinue(args); } }
internal void GiveShareOfLootToParty(PartyBase partyToReceiveLoot, PartyBase winnerParty, float lootAmount) { bool flag = winnerParty == PartyBase.MainParty; List <TroopRosterElement> troopRosterElements = new List <TroopRosterElement>(); foreach (TroopRosterElement lootedMember in this.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) { this.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 = this.LootedItems.Count <ItemRosterElement>() - 1; j >= 0; j--) { ItemRosterElement elementCopyAtIndex = this.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++; } } this.LootedItems.AddToCounts(itemRosterElement, -num, true); } partyToReceiveLoot.ItemRoster.Add(itemRosterElements); for (int l = this.LootedPrisoners.Count <TroopRosterElement>() - 1; l >= 0; l--) { int elementNumber = this.LootedPrisoners.GetElementNumber(l); CharacterObject characterAtIndex = this.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++; } } this.LootedPrisoners.AddToCounts(characterAtIndex, -num1, false, 0, 0, true, -1); } ICollection <TroopRosterElement> troopRosterElements1 = new List <TroopRosterElement>(); for (int n = this.CasualtiesInBattle.Count <TroopRosterElement>() - 1; n >= 0; n--) { int elementNumber1 = this.CasualtiesInBattle.GetElementNumber(n); CharacterObject characterObject = this.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++; } } this.CasualtiesInBattle.AddToCounts(characterObject, -num2, false, 0, 0, true, -1); } ExplainedNumber explainedNumber = new ExplainedNumber(1f, null); if (winnerParty.MobileParty != null && winnerParty.MobileParty.Leader != null) { SkillHelper.AddSkillBonusForCharacter(DefaultSkills.Roguery, DefaultSkillEffects.RogueryLootBonus, winnerParty.MobileParty.Leader, ref explainedNumber, true); } if (flag) { IEnumerable <ItemRosterElement> itemRosterElements1 = this.LootCasualties(troopRosterElements1, explainedNumber.ResultNumber); partyToReceiveLoot.ItemRoster.Add(itemRosterElements1); } else if (partyToReceiveLoot.LeaderHero != null) { int gold = LootCollector.ConvertLootToGold(this.LootCasualties(troopRosterElements1, 0.5f)); gold = MBMath.Round((float)gold * 0.5f * explainedNumber.ResultNumber); GiveGoldAction.ApplyBetweenCharacters(null, partyToReceiveLoot.LeaderHero, gold, false); return; } }
public static string FireSpecificEventPartyLeader(string specificEvent, out CEEvent ceEvent, bool force = false, string heroname = null) { List <string> eventNames = new List <string>(); string flag = "$FAILEDTOFIND"; ceEvent = null; if (CEPersistence.CEEventList == null || CEPersistence.CEEventList.Count <= 0) { return(flag); } specificEvent = specificEvent.ToLower(); CEEvent foundevent = CEPersistence.CEEventList.FirstOrDefault(ceevent => ceevent.Name.ToLower() == specificEvent); if (foundevent != null) { if (heroname == null) { foreach (TroopRosterElement troopRosterElement in PartyBase.MainParty.PrisonRoster.GetTroopRoster()) { if (troopRosterElement.Character != null) { if (foundevent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.Captor)) { string result = new CEEventChecker(foundevent).FlagsDoMatchEventConditions(troopRosterElement.Character, PartyBase.MainParty); if (force || result == null) { foundevent.Captive = troopRosterElement.Character; ceEvent = foundevent; return(foundevent.Name); } flag = "$" + result; } } } } else { TroopRosterElement specificTroopRosterElement = PartyBase.MainParty.PrisonRoster.GetTroopRoster().FirstOrDefault(troopRosterElement => troopRosterElement.Character != null && troopRosterElement.Character.Name.ToString() == heroname); if (specificTroopRosterElement.Character == null) { return("$FAILTOFINDHERO"); } CharacterObject specificCaptive = specificTroopRosterElement.Character; if (!foundevent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.Captor)) { return(flag); } string result = new CEEventChecker(foundevent).FlagsDoMatchEventConditions(specificCaptive, PartyBase.MainParty); if (force || result == null) { foundevent.Captive = specificCaptive; return(foundevent.Name); } flag = "$" + result; } } else { flag = "$EVENTNOTFOUND"; } return(flag); }
private void addXp(MobileParty party) { //Only train troops in main hero party to alleviate CPU load if (party.IsMainParty) { int leaderLeadership = Hero.MainHero.GetSkillValue(DefaultSkills.Leadership); int totalXPEarned = 0; Dictionary <string, int> troopsReadyToUpgrade = new Dictionary <string, int>(); for (int i = 0; i < party.MemberRoster.Count; i++) { //IMPORTANT: bear in mind we only get a COPY. So after any changes to the troop, info will be inconsistent. TroopRosterElement troop = party.MemberRoster.GetElementCopyAtIndex(i); //Only gain XP if character LVL is lower than the leader's LVL AND the troop can be upgraded if (troop.Character.Level < Hero.MainHero.Level && !troop.Character.UpgradeTargets.IsEmpty()) { int lvlDifference = Hero.MainHero.Level - troop.Character.Level; //Get the least xp this troop needs to lvl up (seems it could have different troops to level up to and need different xp for each one) int minXPForUpgrade = troop.Character.GetUpgradeXpCost(party.Party, 0); int targetIndex = 1; while (targetIndex < troop.Character.UpgradeTargets.Length) { minXPForUpgrade = System.Math.Min(minXPForUpgrade, troop.Character.GetUpgradeXpCost(party.Party, targetIndex)); targetIndex++; } int trainableTroopCount = troop.Number - troop.Xp / minXPForUpgrade; //Perform the math int xpEarned = (leaderLeadership * TrainTroopsSettings.Instance.TroopXPMultiplier + lvlDifference * TrainTroopsSettings.Instance.LevelDifferenceMultiplier) * trainableTroopCount; party.Party.MemberRoster.AddXpToTroopAtIndex(xpEarned, i); int troopsReadyToUpgradeCount = (troop.Xp + xpEarned) / minXPForUpgrade; //Report troops ready to upgrade if (troopsReadyToUpgradeCount != 0) { //Will update the party button notification so that the red icon is shown (?) //PlayerUpdateTracker.Current.GetPartyNotificationText(); //PlayerUpdateTracker.Current.UpdatePartyNotification(); //TODO: get the troop name, for now it only gets it in english string troopName = troop.Character.ToString(); //Count how many troops of each type are ready to upgrade //If a troop with the same name has already been counted, add it if (troopsReadyToUpgrade.ContainsKey(troopName)) { troopsReadyToUpgrade[troopName] += troopsReadyToUpgradeCount; } //Else add it anew else { troopsReadyToUpgrade.Add(troopName, troopsReadyToUpgradeCount); } } totalXPEarned += xpEarned; } } InformationManager.DisplayMessage(new InformationMessage("Total training XP for the day: " + totalXPEarned + "." + getTroopsReadyToUpgradeMessage(troopsReadyToUpgrade))); } }