public static bool Prefix(MobileParty __instance, PartyTemplateObject pt, int troopNumberLimit) { if (__instance.IsBandit) // TaleWorlds hardcoding strikes again { double num1 = 0.4 + 0.8 * MiscHelper.GetGameProcess(); int num2 = MBRandom.RandomInt(2); double num3 = num2 == 0 ? MBRandom.RandomFloat : (MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * 4.0); double num4 = num2 == 0 ? (num3 * 0.8 + 0.2) : 1 + num3; foreach (PartyTemplateStack stack in pt.Stacks) { int numTroopsToAdd = MBRandom.RoundRandomized((float)(stack.MinValue + num1 * num4 * MBRandom.RandomFloat * (stack.MaxValue - stack.MinValue))); __instance.AddElementToMemberRoster(stack.Character, numTroopsToAdd); } } else if (__instance.IsVillager) { int index = MBRandom.RandomInt(pt.Stacks.Count); for (int troopCount = 0; troopCount < troopNumberLimit; troopCount++) { __instance.AddElementToMemberRoster(pt.Stacks[index].Character, 1); index = MBRandom.RandomInt(pt.Stacks.Count); } } else // everything else looks fine; hand stack filling to original method { return(true); } return(false); }
// Makes a party depending on town prosperity public MobileParty generateParty(Town town, string[] troopIDs, int type) { MobileParty party = new MobileParty(); int troopProspModifier = 0; // Militia if (type == 0) { TextObject text = new TextObject("Basilisk Mercenaries"); party.Name = text; } // Nobles else { TextObject text = new TextObject("Basilisk Noble Mercenaries"); party.Name = text; } troopProspModifier = (int)Math.Floor(town.Prosperity / 100 + Clan.PlayerClan.Renown * 0.05); int troopAmount = 0; CharacterObject unit; CharacterObject unitf; foreach (string id in troopIDs) { unit = CharacterObject.Find(id); string f_id = ""; genderPairs.TryGetValue(unit.StringId, out f_id); unitf = CharacterObject.Find(f_id); if (unit.Level > 21) { continue; } troopAmount = (int)Math.Floor((double)troopProspModifier / unit.Level); troopAmount = balanceTroops(unit.Level, troopAmount); if (troopAmount >= 1) { troopAmount = rand.Next((int)Math.Ceiling((double)troopAmount / 2), troopAmount + 1); while (troopAmount > 0) { party.AddElementToMemberRoster(randomGender(unit, unitf), 1, true); troopAmount--; } } } return(party); }
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; } } }
public static bool Prefix(ref MobileParty __instance, PartyTemplateObject pt, MobileParty.PartyTypeEnum partyType, int troopNumberLimit = -1) { bool result = true; if (partyType == MobileParty.PartyTypeEnum.Bandit) { int num = 0; for (int i = 0; i < pt.Stacks.Count; i++) { num = Support.Random(pt.Stacks[i].MinValue, pt.Stacks[i].MaxValue); if (num > 0 && pt.Stacks[i].Character != null) { __instance.AddElementToMemberRoster(pt.Stacks[i].Character, num); } } result = false; } return(result); }
public static bool Prefix(ref MobileParty __result, Hero hero, Vec2 position, float spawnRadius, Settlement spawnSettlement) { MobileParty spawnedParty = MBObjectManager.Instance.CreateObject <MobileParty>(hero.CharacterObject.StringId + "_" + (object)hero.NumberOfCreatedParties); ++hero.NumberOfCreatedParties; spawnedParty.AddElementToMemberRoster(hero.CharacterObject, 1, true); int troopNumberLimit = hero == Hero.MainHero || hero.Clan == Clan.PlayerClan ? SubModule.Settings.Strategy_ModifyRespawnParty_PlayerPartySizeOnRespawn : SubModule.Settings.Strategy_ModifyRespawnParty_AILordPartySizeOnRespawn; if (!Campaign.Current.GameStarted) { float num = (float)(1.0 - (double)MBRandom.RandomFloat * (double)MBRandom.RandomFloat); troopNumberLimit = (int)((double)spawnedParty.Party.PartySizeLimit * (double)num); } TextObject partyName = MobilePartyHelper.GeneratePartyName((BasicCharacterObject)hero.CharacterObject); spawnedParty.InitializeMobileParty(partyName, hero.Clan.DefaultPartyTemplate, position, spawnRadius, 0.0f, MobileParty.PartyTypeEnum.Lord, troopNumberLimit); spawnedParty.Party.Owner = hero; spawnedParty.IsLordParty = true; spawnedParty.Party.Visuals.SetMapIconAsDirty(); if (spawnSettlement != null) { spawnedParty.SetMoveGoToSettlement(spawnSettlement); } spawnedParty.Aggressiveness = (float)(0.899999976158142 + 0.100000001490116 * (double)hero.GetTraitLevel(DefaultTraits.Valor) - 0.0500000007450581 * (double)hero.GetTraitLevel(DefaultTraits.Mercy)); hero.PassedTimeAtHomeSettlement = (float)(int)((double)MBRandom.RandomFloat * 100.0); if (spawnSettlement != null) { spawnedParty.Ai.SetAIState(AIState.VisitingNearbyTown, (PartyBase)null); spawnedParty.SetMoveGoToSettlement(spawnSettlement); } // CampaignEventDispatcher.Instance.OnLordPartySpawned(spawnedParty); object[] parametersArray = new object[] { spawnedParty }; OnLordPartySpawnedMI.Invoke(CampaignEventDispatcher.Instance, parametersArray); __result = spawnedParty; return(false); }
public static void AddRandomCultureUnits(MobileParty party, int numberToAdd, CultureObject overrideCulture = null) { // Get culture CultureObject partyCultureObject = null; if (overrideCulture != null) { partyCultureObject = overrideCulture; } else { partyCultureObject = party.Party.Culture; } // Get possible units to create List <CharacterObject> characterObjectList = null; if (partyCultureObject.IsBandit) { characterObjectList = GetBanditCharacters(partyCultureObject); } else { characterObjectList = GetMainCultureCharacters(partyCultureObject); } // Split spawn based on number to add int[] spawnNumbers = new int[characterObjectList.Count]; int currentSpawned = 0; while (currentSpawned < numberToAdd) { int randomInt = MBRandom.RandomInt(0, spawnNumbers.Length); spawnNumbers[randomInt]++; currentSpawned++; } for (int i = 0; i < characterObjectList.Count; i++) { CharacterObject characterObject = (CharacterObject)characterObjectList[i]; party.AddElementToMemberRoster(characterObject, spawnNumbers[i]); } }
private void partyFuncTest() { party.SetMoveEngageParty(MainParty); party.AddElementToMemberRoster(CharacterObject.PlayerCharacter, 10); }