private void RemoveTroops() { MobileParty heroParty = MobileParty.MainParty; TroopRoster troops = heroParty.MemberRoster; TroopRosterElement troopElement; CharacterObject troop; int troopTypeCount; int numOfTroopsToTake; TroopRoster tempTroopRoster; for (int i = 0; i < troops.Count; i++) { tempTroopRoster = new TroopRoster(); troop = troops.GetCharacterAtIndex(i); troopElement = troops.GetElementCopyAtIndex(i); Debug.WriteLine("troopElement " + i + ": " + troopElement.Character.Name); troopTypeCount = troops.GetTroopCount(troop); Debug.WriteLine("cons2 Troop " + i + ": " + troop.Name + ", count:" + troopTypeCount); if (numOfTroopNeeded > 0) { numOfTroopsToTake = getNumTroopNeeded(troop, troopTypeCount); int numOfTroopsToRemove = troopTypeCount - numOfTroopsToTake; Debug.WriteLine("take Troop " + troop.Name + ", num to take: " + numOfTroopsToTake + ", num to remove: " + numOfTroopsToRemove); numOfTroopNeeded -= numOfTroopsToTake; if (numOfTroopsToRemove > 0) { Debug.WriteLine("remove Troop1 " + troop.Name + ", num: " + numOfTroopsToRemove); CharacterObject tempTroop = troopElement.Character; tempTroopRoster.FillMembersOfRoster(numOfTroopsToTake, troop); troopRosterRemovedTroops.Add(tempTroopRoster); Debug.WriteLine("troopRoosterRemovedTroops count" + troopRosterRemovedTroops.Count()); troops.RemoveTroop(troop, numOfTroopsToRemove); i--; } } else { Debug.WriteLine("remove Troop2 " + troop.Name + ", num: " + troopTypeCount + ", troopCound: " + troopTypeCount); CharacterObject tempTroop = troopElement.Character; tempTroopRoster.FillMembersOfRoster(troopTypeCount, troop); Debug.WriteLine("output temp roster: "); outputRoster(troopRosterRemovedTroops); troopRosterRemovedTroops.Add(tempTroopRoster); Debug.WriteLine("output roster: "); outputRoster(troopRosterRemovedTroops); Debug.WriteLine("troopRoosterRemovedTroops count" + troopRosterRemovedTroops.Count() + ", troopRoster tootalCount: " + troopRosterRemovedTroops.TotalManCount); troops.RemoveTroop(troop, troopTypeCount); i--; } } Debug.WriteLine("end of remove troops"); }
private void RevoltLogic(SettlementInfo info, Settlement settlement) { TextObject revoltNotification = GameTexts.FindText("str_GM_RevoltNotification"); revoltNotification.SetTextVariable("SETTLEMENT", settlement.Name.ToString()); InformationManager.DisplayMessage(new InformationMessage(revoltNotification.ToString())); Hero selectedHero = null; TextObject revolutionaryMob = GameTexts.FindText("str_GM_RevolutionaryMob"); MobileParty mob = MobileParty.Create(revolutionaryMob.ToString()); TroopRoster roster = new TroopRoster(); TroopRoster infantry = new TroopRoster(); infantry.FillMembersOfRoster(300, settlement.Culture.MeleeMilitiaTroop); roster.Add(infantry); TroopRoster archers = new TroopRoster(); archers.FillMembersOfRoster(200, settlement.Culture.RangedMilitiaTroop); roster.Add(archers); TroopRoster prisonRoster = new TroopRoster(); prisonRoster.IsPrisonRoster = true; if (info.CurrentFaction.IsAtWarWith(info.OriginalFaction)) { Clan chosenClan = null; int leastSettlements = 100; foreach (var noble in info.OriginalFaction.Nobles) { int currentSettlements = noble.Clan.Settlements.Count(); if (currentSettlements >= leastSettlements) { continue; } leastSettlements = currentSettlements; chosenClan = noble.Clan; } selectedHero = chosenClan != null?chosenClan.Nobles.GetRandomElement() : info.OriginalFaction.Leader; } else { var clan = CreateRebellionClan(info); clan.AddRenown(500); DeclareWarAction.Apply(clan, info.CurrentFaction); selectedHero = clan.Leader; mob.IsLordParty = true; } mob.ChangePartyLeader(selectedHero.CharacterObject); mob.Party.Owner = selectedHero; if (!info.CurrentFaction.IsAtWarWith(info.OriginalFaction)) { mob.MemberRoster.AddToCounts(mob.Party.Owner.CharacterObject, 1, false, 0, 0, true, -1); } mob.InitializeMobileParty(new TextObject(revolutionaryMob.ToString(), null), roster, prisonRoster, settlement.GatePosition, 2.0f, 2.0f); Revolutionaries.Add(new Tuple <PartyBase, SettlementInfo>(mob.Party, info)); MobileParty garrison = settlement.Parties.FirstOrDefault(party => party.IsGarrison); if (garrison == null) { foreach (var party in settlement.Parties.Where(party => party.IsMilitia || party.MapFaction.StringId == settlement.OwnerClan.MapFaction.StringId)) { garrison = party; break; } } if (garrison == null) { ChangeOwnerOfSettlementAction.ApplyByRevolt(selectedHero, settlement); GetFactionInformation(info.CurrentFaction).CityRevoltedSuccess(settlement); } else { Campaign.Current.MapEventManager.StartSiegeOutsideMapEvent(mob.Party, garrison.Party); } info.RevoltProgress = 0; }