public static UpgradeResults UpgradeTroops(PartyVM partyVm, PartyScreenLogic partyScreenLogic) { UpgradeResults results = new UpgradeResults(); List <PartyCharacterVM> upgradableTroops = GetUpgradeableTroops(partyVm); if (upgradableTroops.IsEmpty()) { Global.Helpers.Message("No troops available to upgrade"); return(results); } List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> > commands = PrepareUpgradeCommands(upgradableTroops, partyScreenLogic, ref results); if (results.UpgradedTotal == 0) { Global.Helpers.Message(results.MultiPathSkipped > 0 ? $"No troops upgraded. {results.MultiPathSkipped} troop types with multi-path upgrades were skipped. To prevent any skipping enable split upgrades and disable player decision in the settings" : "No troops upgraded"); } else { ExecuteCommands(commands, partyVm, partyScreenLogic); } return(results); }
public void RecruitAllPrisoners(bool ignorePartyLimit) { var currentlyRecruitingPrisoner = ""; try { var recruits = PartyVM?.MainPartyPrisoners? .Where(x => !x.IsHero && x.IsRecruitablePrisoner && x.NumOfRecruitablePrisoners > 0).ToList(); if (PartyManagerSettings.Settings.RecruitPrisonersUseWhitelist) { recruits = recruits.Where(x => PartyManagerSettings.Settings.RecruitPrisonerBlackWhiteList.Contains(x.Name)).ToList(); } else { recruits = recruits.Where(x => !PartyManagerSettings.Settings.RecruitPrisonerBlackWhiteList.Contains(x.Name)).ToList(); } if (recruits?.Count > 0) { var freeUnitSlots = PartyScreenLogic.RightOwnerParty.PartySizeLimit - PartyScreenLogic.RightOwnerParty.NumberOfAllMembers; var recruitCount = 0; foreach (var troop in recruits) { currentlyRecruitingPrisoner = troop?.Name?.ToString(); if (freeUnitSlots > 0 || ignorePartyLimit) { var toBeRecruited = ignorePartyLimit ? troop.NumOfRecruitablePrisoners : Math.Min(freeUnitSlots, troop.NumOfRecruitablePrisoners); for (int i = 0; i < toBeRecruited; i++) { PartyScreenLogic.PartyCommand command = new PartyScreenLogic.PartyCommand(); command.FillForRecruitTroop(PartyScreenLogic.PartyRosterSide.Right, troop.Type, troop.Character, 1); PartyScreenLogic.AddCommand(command); } GenericHelpers.LogDebug("RecruitAll", $"Recruited {toBeRecruited} {troop.Character.Name}"); recruitCount += toBeRecruited; freeUnitSlots -= toBeRecruited; } } ButtonClickRefresh(true, true); } else { GenericHelpers.LogMessage("No prisoners found to recruit"); } } catch (Exception ex) { GenericHelpers.LogException($"RecruitAllPrisoners UnitType({currentlyRecruitingPrisoner})", ex); } }
public static void ProcessCommand(this PartyScreenLogic instance, PartyScreenLogic.PartyCommand command) { Traverse.Create(instance).Method("ProcessCommand", new Type[1] { typeof(PartyScreenLogic.PartyCommand) }).GetValue(command); }
public static void SortPartyScreen(PartyScreenLogic partyScreen, bool right, bool left, bool troops, bool prisoners) { try { if (left) { if (troops) { SortUnits(partyScreen.MemberRosters[0]); } if (prisoners) { SortUnits(partyScreen.PrisonerRosters[0]); } } if (right) { if (troops) { SortUnits(partyScreen.MemberRosters[1]); } if (prisoners) { SortUnits(partyScreen.PrisonerRosters[1]); } } } catch (Exception ex) { InformationManager.DisplayMessage(new InformationMessage("Error in SortParty: " + ex.Message)); } }
public static void ExecuteRecruitAll(this PartyVM partyVM) { PartyScreenLogic partyScreenLogic = GetPartyScreenLogic(partyVM); int num = partyScreenLogic.RightOwnerParty.PartySizeLimit - partyScreenLogic.MemberRosters[1].TotalManCount; int num2 = 0; int num3 = 0; foreach (PartyCharacterVM item in partyVM.MainPartyPrisoners.OrderByDescending((PartyCharacterVM o) => o.Character.Tier).ToList()) { if (num <= 0) { break; } if (!item.IsHero && item.NumOfRecruitablePrisoners > 0) { int num4 = Math.Min(item.NumOfRecruitablePrisoners, num); num2++; num -= num4; num3 += num4; PartyScreenLogic.PartyCommand partyCommand = new PartyScreenLogic.PartyCommand(); partyCommand.FillForRecruitTroop(item.Side, item.Type, item.Character, num4); partyVM.CurrentCharacter = item; ProcessCommand(partyScreenLogic, partyCommand); } } RefreshPartyScreen(partyVM); if (num2 > 0) { InformationManager.DisplayMessage(new InformationMessage($"招募 {num3} 兵 ({num2})")); } if (num <= 0) { InformationManager.DisplayMessage(new InformationMessage("队伍成员达到上限.")); } }
private static bool OpenAdoptedHeroScreen() { if (!PartyScreenAllowed) { return(false); } if (ScreenManager.TopScreen is not MapScreen) { Game.Current.GameStateManager.PopState(); } var _partyScreenLogic = new PartyScreenLogic(); AccessTools.Field(typeof(PartyScreenManager), "_partyScreenLogic").SetValue(PartyScreenManager.Instance, _partyScreenLogic); AccessTools.Field(typeof(PartyScreenManager), "_currentMode").SetValue(PartyScreenManager.Instance, PartyScreenMode.Normal); var heroRoster = new TroopRoster(null); foreach (var hero in BLTAdoptAHeroCampaignBehavior.GetAllAdoptedHeroes().OrderBy(h => h.Name.Raw().ToLower())) { heroRoster.AddToCounts(hero.CharacterObject, 1); } _partyScreenLogic.Initialize(heroRoster, new(null), MobileParty.MainParty, false, new("Viewers"), 0, (_, _, _, _, _, _, _, _, _) => true, new("BLT Viewer Heroes"), false); _partyScreenLogic.InitializeTrade(PartyScreenLogic.TransferState.NotTransferable, PartyScreenLogic.TransferState.NotTransferable, PartyScreenLogic.TransferState.NotTransferable); _partyScreenLogic.SetTroopTransferableDelegate((_, _, _, _) => false); var partyState = Game.Current.GameStateManager.CreateState <PartyState>(); partyState.InitializeLogic(_partyScreenLogic); Game.Current.GameStateManager.PushState(partyState); return(true); }
public SortAllTroopsVM(PartyVM partyVm, PartyScreenLogic logic) { _partyVM = partyVm; _partyLogic = logic; _mainPartyList = _partyVM.MainPartyTroops; _mainPartyPrisoners = _partyVM.MainPartyPrisoners; _sortHint = new HintViewModel(new TextObject("Sort Troops\nCtrl Click to sort just main party")); }
public RecruitPrisonerVM(PartyEnhancementsVM parent, PartyVM partyVm, PartyScreenLogic logic) { _parent = parent; _partyVM = partyVm; _partyLogic = logic; _mainPartyPrisoners = _partyVM.MainPartyPrisoners; _recruitHint = new HintViewModel(new TextObject("Recruit All Prisoners.\nClick with CTRL pressed to ignore party size limits")); }
public override void OnFinalize() { base.OnFinalize(); _mainPartyPrisoners = null; _mainPartyList = null; _partyLogic = null; _partyVM = null; }
private void UpgradeUnit(PartyCharacterVM troop, bool path1) { PartyScreenLogic.PartyCommand command = new PartyScreenLogic.PartyCommand(); command.FillForUpgradeTroop(PartyScreenLogic.PartyRosterSide.Right, troop.Type, troop.Character, path1 ? troop.NumOfTarget1UpgradesAvailable : troop.NumOfTarget2UpgradesAvailable, path1 ? PartyScreenLogic.PartyCommand.UpgradeTargetType.UpgradeTarget1 : PartyScreenLogic.PartyCommand.UpgradeTargetType.UpgradeTarget2); PartyScreenLogic.AddCommand(command); }
public RecruitAllPrisonersWidget(UIContext context) : base(context) { if (ScreenManager.TopScreen is GauntletPartyScreen) { this._partyVM = (PartyVM)((GauntletPartyScreen)ScreenManager.TopScreen).GetField("_dataSource"); this._partyLogic = (PartyScreenLogic)this._partyVM.GetField("_partyScreenLogic"); this._mainPartyList = this._partyVM.MainPartyTroops; } }
public UpgradeAllTroopsVM(PartyEnhancementsVM parent, PartyVM partyVm, PartyScreenLogic logic) { _parent = parent; _partyVM = partyVm; _partyLogic = logic; _mainPartyList = _partyVM.MainPartyTroops; _upgradeHint = new HintViewModel(new TextObject("Upgrade All Troops\nRight click to upgrade only paths set by you")); }
public override void OnFinalize() { base.OnFinalize(); _logic.UpdateDelegate = Delegate.Remove(_logic.UpdateDelegate, new PartyScreenLogic.PresentationUpdate(RefreshDelegate)) as PartyScreenLogic.PresentationUpdate; PartyScreenConfig.ExtraSettings.PropertyChanged -= OnEnableChange; _mainPartyList = null; _otherPartyList = null; _logic = null; }
public static void OrderParty(this PartyVM partyVM) { PartyScreenLogic partyScreenLogic = GetPartyScreenLogic(partyVM); var own = partyScreenLogic.MemberRosters[1]; List <TroopRosterElement> list = own.ToList(); List <FlattenedTroopRosterElement> elementList = CreateFlattenedRoster(own, partyVM); for (int i = 0; i < list.Count; i++) { if (!list[i].Character.IsHero) { own.RemoveTroop(list[i].Character, list[i].Number); } } own.Add(elementList); }
public static bool Prefix(PartyScreenLogic __instance, ItemCategory itemCategory, int numOfItemsLeftToRemove) { ItemCategory itemCategory1; int numItemsRequired = numOfItemsLeftToRemove; ItemRosterElement[] copyOfAllElements = __instance.RightOwnerParty.ItemRoster.GetCopyOfAllElements(); int totalItemCount = __instance.RightOwnerParty.ItemRoster.Count; ItemRosterElement[] cleanItemRoster = new ItemRosterElement[totalItemCount]; Array.Copy(copyOfAllElements, 0, cleanItemRoster, 0, totalItemCount); Array.Sort <ItemRosterElement>(cleanItemRoster, (ItemRosterElement left, ItemRosterElement right) => { EquipmentElement equipmentElement = left.EquipmentElement; int itemValue = equipmentElement.ItemValue; equipmentElement = right.EquipmentElement; return(itemValue.CompareTo(equipmentElement.ItemValue)); }); ItemRosterElement[] itemRosterElementArray = cleanItemRoster; for (int i = 0; i < itemRosterElementArray.Length; i++) { ItemRosterElement rosterElement = itemRosterElementArray[i]; ItemObject item = rosterElement.EquipmentElement.Item; if (item != null) { itemCategory1 = item.ItemCategory; } else { itemCategory1 = null; } if (itemCategory1 == itemCategory) { int amountToRemove = Math.Min(numItemsRequired, rosterElement.Amount); __instance.RightOwnerParty.ItemRoster.AddToCounts(rosterElement.EquipmentElement, -amountToRemove, true); numItemsRequired -= amountToRemove; if (numItemsRequired == 0) { break; } } } return(false); }
public PartyEnhancementsVM(PartyVM partyVM, PartyScreenLogic partyScreenLogic, GauntletPartyScreen parentScreen) { _partyVM = partyVM; _partyScreenLogic = partyScreenLogic; _parentScreen = parentScreen; _settingsHint = new HintViewModel(new TextObject("PSE Settings")); _sortTroopsVM = new SortAllTroopsVM(_partyVM, _partyScreenLogic); _upgradeTroopsVM = new UpgradeAllTroopsVM(this, _partyVM, _partyScreenLogic); _recruitPrisonerVm = new RecruitPrisonerVM(this, _partyVM, _partyScreenLogic); _unitTallyVm = new UnitTallyVM(partyVM.MainPartyTroops, partyVM.OtherPartyTroops, partyScreenLogic, _partyScreenLogic?.LeftOwnerParty?.MobileParty?.IsGarrison ?? false); _transferWounded = new TransferWoundedTroopsVM(this, partyVM, _partyScreenLogic?.LeftOwnerParty?.MobileParty?.IsGarrison ?? false); _partyScreenLogic.AfterReset += AfterReset; _partyScreenLogic.Update += UpdateLabel; PartyScreenConfig.ExtraSettings.PropertyChanged += OnEnableChange; RefreshValues(); UpdateLabel(null); }
public static RecruitmentResults RecruitPrisoners(PartyVM partyVm, PartyScreenLogic partyScreenLogic) { RecruitmentResults results = new RecruitmentResults(); List <PartyCharacterVM> recruitablePrisoners = GetRecruitablePrisoners(partyVm); if (recruitablePrisoners.IsEmpty()) { Global.Helpers.Message("No prisoners available to recruit"); return(results); } int partySpace = partyScreenLogic.RightOwnerParty.PartySizeLimit - partyScreenLogic.MemberRosters[1].TotalManCount; partySpace = partySpace < 0 ? 0 : partySpace; if (partySpace == 0) { if (States.HotkeyControl) { Global.Helpers.Message("Party limit reached! Limit overriden, proceeding..."); } else { Global.Helpers.Message("Party limit reached! Cannot recruit prisoners. (Hold control to override)"); return(results); } } List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> > commands = PrepareRecruitmentCommands(recruitablePrisoners, partySpace, ref results, partyVm); if (commands.Count == 0) { Global.Helpers.Message("No prisoners recruited"); } else { ExecuteCommands(commands, partyVm, partyScreenLogic); } return(results); }
public UnitTallyVM(MBBindingList <PartyCharacterVM> mainPartyList, MBBindingList <PartyCharacterVM> otherParty, PartyScreenLogic logic, bool shouldShowGarrison) { PartyScreenConfig.ExtraSettings.PropertyChanged += OnEnableChange; InfantryLabel = "Infantry: NaN"; ArchersLabel = "Archers: NaN"; CavalryLabel = "Cavalry: NaN"; HorseArcherLabel = "Horse Archers: NaN"; InfantryGarrisonLabel = "Infantry: NaN"; ArchersGarrisonLabel = "Archers: NaN"; CavalryGarrisonLabel = "Cavalry: NaN"; _horseArcherGarrisonLabel = "Horse Archers: NaN"; _mainPartyList = mainPartyList; _otherPartyList = otherParty; IsEnabled = PartyScreenConfig.ExtraSettings.DisplayCategoryNumbers; ShouldShowGarrison = shouldShowGarrison; _logic = logic; _logic.UpdateDelegate = Delegate.Combine(_logic.UpdateDelegate, new PartyScreenLogic.PresentationUpdate(RefreshDelegate)) as PartyScreenLogic.PresentationUpdate; }
public TransferVM(PartyScreenLogic partyLogic, PartyVM partyVm) { this._partyLogic = partyLogic; this._partyVM = partyVm; LeftTroopTransferHidden = true; LeftPrisonerTransferHidden = true; RightTroopTransferHidden = true; RightPrisonerTransferHidden = true; LeftTroopTransferTooltip = new HintViewModel("Transfer Troops to Party Limit"); LeftPrisonerTransferTooltip = new HintViewModel("Transfer Prisoners to Prisoner Limit"); RightTroopTransferTooltip = new HintViewModel("Transfer Troops to Party Limit"); RightPrisonerTransferTooltip = new HintViewModel("Transfer Prisoners to Prisoner Limit"); if (partyLogic.PrisonerTransferState == PartyScreenLogic.TransferState.TransferableWithTrade) { LeftPrisonerTransferHidden = false; LeftPrisonerTransferTooltip = new HintViewModel("Ransom black/white listed prisoners"); } //else if (partyLogic.PrisonerTransferState == PartyScreenLogic.TransferState.Transferable && // partyLogic.MemberTransferState == PartyScreenLogic.TransferState.Transferable) //{ // RightPrisonerTransferHidden = false; // RightTroopTransferHidden = false; //} //else if (partyLogic.PrisonerTransferState == PartyScreenLogic.TransferState.Transferable) //{ // RightPrisonerTransferHidden = false; //} //else if (partyLogic.MemberTransferState == PartyScreenLogic.TransferState.Transferable) //{ // RightTroopTransferHidden = false; //} }
public static void SortPartyLogic(PartyScreenLogic PartyScreenLogic, PartyVM PartyVM, SortType sortType, bool rightTroops, bool rightPrisoners, bool leftTroops, bool leftPrisoners) { var left = (int)PartyScreenLogic.PartyRosterSide.Left; var right = (int)PartyScreenLogic.PartyRosterSide.Right; //Left Side if (leftTroops) { SortPartyHelpers.SortUnits(PartyScreenLogic.MemberRosters[left], sortType, PartyVM?.OtherPartyTroops); } if (leftPrisoners) { SortUnits(PartyScreenLogic.PrisonerRosters[left], sortType, PartyVM?.OtherPartyPrisoners); } //Right Side if (rightTroops) { SortUnits(PartyScreenLogic.MemberRosters[right], sortType, PartyVM?.MainPartyTroops, true); } if (rightPrisoners) { SortPartyHelpers.SortUnits(PartyScreenLogic.PrisonerRosters[right], sortType, PartyVM?.MainPartyPrisoners); } }
public void AfterReset(PartyScreenLogic logic, bool fromCancel) { RefreshValues(); }
public static void ExecuteUpgradeAll(this PartyVM partyVM) { var hasTwoUpgrade = new List <PartyCharacterVM>(); PartyScreenLogic partyScreenLogic = GetPartyScreenLogic(partyVM); int troopNum = 0; int troopNumTotal = 0; var party = partyVM.MainPartyTroops.OrderByDescending((PartyCharacterVM o) => o.Character.Tier).ToList(); foreach (PartyCharacterVM partyCharacterVM in party) { if (!partyCharacterVM.IsHero && partyCharacterVM.IsUpgrade1Available && !partyCharacterVM.IsUpgrade2Exists && partyCharacterVM.NumOfTarget1UpgradesAvailable > 0 && !partyCharacterVM.IsUpgrade1Insufficient) { int numOfTarget1UpgradesAvailable = partyCharacterVM.NumOfTarget1UpgradesAvailable; troopNum++; troopNumTotal += numOfTarget1UpgradesAvailable; PartyScreenLogic.PartyCommand partyCommand = new PartyScreenLogic.PartyCommand(); partyCommand.FillForUpgradeTroop(partyCharacterVM.Side, partyCharacterVM.Type, partyCharacterVM.Character, numOfTarget1UpgradesAvailable, PartyScreenLogic.PartyCommand.UpgradeTargetType.UpgradeTarget1); partyVM.CurrentCharacter = partyCharacterVM; ProcessCommand(partyScreenLogic, partyCommand); } if (!partyCharacterVM.IsHero && partyCharacterVM.IsUpgrade1Exists && partyCharacterVM.IsUpgrade1Available && partyCharacterVM.IsUpgrade2Exists && partyCharacterVM.IsUpgrade2Available) { hasTwoUpgrade.Add(partyCharacterVM); } } foreach (var partyCharacterVM in hasTwoUpgrade) { if (UpgradeSetting.Instance.IsEnabled && partyCharacterVM.IsUpgrade1Exists && partyCharacterVM.IsUpgrade2Exists && partyCharacterVM.IsUpgrade1Available && partyCharacterVM.IsUpgrade2Available && !partyCharacterVM.IsUpgrade1Insufficient && !partyCharacterVM.IsUpgrade2Insufficient) { var upgradeSide = UpgradeSetting.Instance.FindUpgradeTopInSetting(partyCharacterVM.Character); if (upgradeSide > -1 && upgradeSide < 2) { var upgradeNum = upgradeSide == 0 ? partyCharacterVM.NumOfTarget1UpgradesAvailable : partyCharacterVM.NumOfTarget2UpgradesAvailable; troopNum++; troopNumTotal += upgradeNum; PartyScreenLogic.PartyCommand partyCommand = new PartyScreenLogic.PartyCommand(); partyCommand.FillForUpgradeTroop(partyCharacterVM.Side, partyCharacterVM.Type, partyCharacterVM.Character, upgradeNum, (PartyScreenLogic.PartyCommand.UpgradeTargetType)upgradeSide); partyVM.CurrentCharacter = partyCharacterVM; ProcessCommand(partyScreenLogic, partyCommand); continue; } } partyVM.MainPartyTroops.Remove(partyCharacterVM); partyVM.MainPartyTroops.Insert(1, partyCharacterVM); } RefreshPartyScreen(partyVM); if (troopNum > 0) { InformationManager.DisplayMessage(new InformationMessage($"升级 {troopNumTotal} 部队 ({troopNum})")); } }
public static void SortPartyScreen(PartyScreenLogic partyScreen) { SortPartyScreen(partyScreen, right: true, left: true, troops: true, prisoners: true); }
private static int CalculateCountOfTroopsThatCanBeUpgraded(AvailableResources availableResources, PartyCharacterVM troops, PartyScreenLogic partyScreenLogic, (int maxUpgradableTroops, PartyScreenLogic.PartyCommand.UpgradeTargetType upgradeTargetType) upgradesPerTargetType)
// Something wrong with upgrade private static List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> > PrepareUpgradeCommands(IEnumerable <PartyCharacterVM> upgradableTroops, PartyScreenLogic partyScreenLogic, ref UpgradeResults upgradeResults) { List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> > commands = new List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> >(); AvailableResources availableResources = new AvailableResources(); foreach (PartyCharacterVM troops in upgradableTroops) { List <(int, PartyScreenLogic.PartyCommand.UpgradeTargetType)> upgradesPerTypes = new List <(int maxUpgradableTroops, PartyScreenLogic.PartyCommand.UpgradeTargetType upgradeTargetType)> { (int.MaxValue, PartyScreenLogic.PartyCommand.UpgradeTargetType.UpgradeTarget1) }; if (HasTwoUpgradePaths(troops) && !YapoSettings.Instance.PlayerDecision && !MultipathUpgradeLogic.TryGetUpgradePaths(troops, out upgradesPerTypes)) { upgradeResults.MultiPathSkipped++; continue; } foreach ((int maxUpgradableTroops, PartyScreenLogic.PartyCommand.UpgradeTargetType upgradeTargetType)upgradesPerType in upgradesPerTypes) { int troopsToUpgrade = CalculateCountOfTroopsThatCanBeUpgraded(availableResources, troops, partyScreenLogic, upgradesPerType); if (troopsToUpgrade == 0) { continue; } upgradeResults.UpgradedTypes++; upgradeResults.UpgradedTotal += troopsToUpgrade; PartyScreenLogic.PartyCommand upgradeCommand = new PartyScreenLogic.PartyCommand(); upgradeCommand.FillForUpgradeTroop(troops.Side, troops.Type, troops.Character, troopsToUpgrade, upgradesPerType.upgradeTargetType); commands.Add(new Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand>(troops, upgradeCommand)); availableResources.UpdateAvailableResources(troops, troopsToUpgrade, (int)upgradesPerType.upgradeTargetType); } } return(commands); }
private static bool TransferAllCharacters(PartyVM __instance, ref PartyScreenLogic ____partyScreenLogic, ref PartyCharacterVM ____currentCharacter, PartyScreenLogic.PartyRosterSide rosterSide, PartyScreenLogic.TroopType type) { MBBindingList <PartyCharacterVM> list; if (type == PartyScreenLogic.TroopType.Member) { if (rosterSide == PartyScreenLogic.PartyRosterSide.Left) { list = __instance.OtherPartyTroops; } else { list = __instance.MainPartyTroops; } } else { if (rosterSide == PartyScreenLogic.PartyRosterSide.Left) { list = __instance.OtherPartyPrisoners; } else { list = __instance.MainPartyPrisoners; } } var newList = list; var lack = 10000; var prisionerSetting = PrisonerSetting.Instance; if (prisionerSetting.IsEnabled && rosterSide == PartyScreenLogic.PartyRosterSide.Left && PartyScreenLogic.TroopType.Prisoner == type) { var limit = MobileParty.MainParty.Party.PrisonerSizeLimit; lack = limit - __instance.MainPartyPrisoners.Sum(a => a.Number); var fixeds = new List <PartyCharacterVM>(); var order1 = new List <PartyCharacterVM>(); var order2 = new List <PartyCharacterVM>(); var order3 = new List <PartyCharacterVM>(); var order4 = new List <PartyCharacterVM>(); var other = new List <PartyCharacterVM>(); foreach (var item in newList) { if (prisionerSetting.IsFixTroop(item.Character) > 0) { fixeds.Add(item); } else if (prisionerSetting.OrderTroop(item.Character, prisionerSetting.Order1, prisionerSetting.Order1MinTier) > 0) { order1.Add(item); } else if (prisionerSetting.OrderTroop(item.Character, prisionerSetting.Order2, prisionerSetting.Order2MinTier) > 0) { order2.Add(item); } else if (prisionerSetting.OrderTroop(item.Character, prisionerSetting.Order3, prisionerSetting.Order3MinTier) > 0) { order3.Add(item); } else if (prisionerSetting.OrderTroop(item.Character, prisionerSetting.Order4, prisionerSetting.Order4MinTier) > 0) { order4.Add(item); } else if (!prisionerSetting.EnableFilter) { other.Add(item); } } //var orderList = newList // .OrderBy(a => // { // return prisionerSetting.IsFixTroop(a.Character); // }) // .ThenBy(a => { return prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order1, prisionerSetting.Order1MinTier); }) // .ThenBy(a => { return prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order2, prisionerSetting.Order2MinTier); }) // .ThenBy(a => { return prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order3, prisionerSetting.Order3MinTier); }) // .ThenBy(a => { return prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order4, prisionerSetting.Order4MinTier); }) // .ToList(); newList = new MBBindingList <PartyCharacterVM>(); foreach (var item in other.OrderBy(a => a.Character.Tier)) { newList.Add(item); } foreach (var item in order4.OrderBy(a => { return(prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order4, prisionerSetting.Order4MinTier)); })) { newList.Add(item); } foreach (var item in order3.OrderBy(a => { return(prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order3, prisionerSetting.Order3MinTier)); })) { newList.Add(item); } foreach (var item in order2.OrderBy(a => { return(prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order2, prisionerSetting.Order2MinTier)); })) { newList.Add(item); } foreach (var item in order1.OrderBy(a => { return(prisionerSetting.OrderTroop(a.Character, prisionerSetting.Order1, prisionerSetting.Order1MinTier)); })) { newList.Add(item); } foreach (var item in fixeds.OrderBy(a => { return(prisionerSetting.IsFixTroop(a.Character)); })) { newList.Add(item); } } int tranfer = 0; for (int i = newList.Count - 1; i >= 0; i--) { if (lack <= tranfer) { break; } if (____partyScreenLogic.IsTroopTransferrable(type, newList[i].Character, (int)newList[i].Side)) { PartyScreenLogic.PartyCommand partyCommand = new PartyScreenLogic.PartyCommand(); PartyCharacterVM partyCharacterVM = newList[i]; ____currentCharacter = partyCharacterVM; if (partyCharacterVM.Type == PartyScreenLogic.TroopType.AttachedGroups) { partyCommand.FillForTransferPartyLeaderTroop(partyCharacterVM.Side, __instance.CurrentCharacter.Type, partyCharacterVM.Character, partyCharacterVM.Troop.Number); } else if (partyCharacterVM.Side == PartyScreenLogic.PartyRosterSide.Right) { if (PartyScreenLogic.TroopType.Prisoner == type && prisionerSetting.IsEnabled && prisionerSetting.IsFixTroop(partyCharacterVM.Character) > 0) { continue; } partyCommand.FillForTransferTroop(partyCharacterVM.Side, partyCharacterVM.Type, partyCharacterVM.Character, partyCharacterVM.Troop.Number, partyCharacterVM.Troop.WoundedNumber, -1); } else { var tranferNumber = partyCharacterVM.Troop.Number; var tranferWoundedNumber = partyCharacterVM.Troop.WoundedNumber; if (rosterSide == PartyScreenLogic.PartyRosterSide.Left && PartyScreenLogic.TroopType.Prisoner == type) { if (lack - tranfer <= partyCharacterVM.Troop.Number) { tranferNumber = lack - tranfer; var heath = partyCharacterVM.Troop.Number - partyCharacterVM.Troop.WoundedNumber; if (tranferNumber < heath) { tranferWoundedNumber = 0; } else { tranferWoundedNumber = tranferNumber - heath; } } tranfer += tranferNumber; } partyCommand.FillForTransferTroop(partyCharacterVM.Side, partyCharacterVM.Type, partyCharacterVM.Character, tranferNumber, tranferWoundedNumber, -1); } ____partyScreenLogic.AddCommand(partyCommand); } } return(false); }
public void UpgradeAllTroops(bool customOnly = false) { var currentlyUpgradingUnit = ""; try { var upgrades = PartyVM?.MainPartyTroops? .Where(x => !x.IsHero && ((x.IsUpgrade1Available && !x.IsUpgrade1Insufficient) || (x.IsUpgrade2Available && !x.IsUpgrade2Insufficient))).ToList(); var upgradesCount = 0; if (!PartyManagerSettings.Settings.DisableCustomUpgradePaths) { var splitTroops = PartyManagerSettings.Settings.SavedTroopUpgradePaths.Where(x => x.EvenSplit).Select(x => x.UnitName).ToList(); var customTroops = PartyManagerSettings.Settings.SavedTroopUpgradePaths.Where(x => !x.EvenSplit).Select(x => x.UnitName).ToList(); var splitUpgrades = upgrades.Where(x => splitTroops.Contains(x.Name.ToString())).ToList(); var customUpgrades = upgrades.Where(x => customTroops.Contains(x.Name.ToString())).ToList(); upgrades = upgrades.Where(x => !splitTroops.Contains(x.Name.ToString()) && !customTroops.Contains(x.Name.ToString())).ToList(); foreach (var troop in splitUpgrades) { currentlyUpgradingUnit = troop?.Character?.Name?.ToString(); var unitUpgrades = Math.Min(troop.NumOfTarget1UpgradesAvailable, troop.NumOfTarget2UpgradesAvailable) / 2; GenericHelpers.LogDebug("UpgradeAllTroops", $"Split {troop.Name.ToString()}: {unitUpgrades}"); var unitsUpgraded = false; for (int i = 0; i < unitUpgrades; i++) { if (troop.IsUpgrade1Insufficient || troop.IsUpgrade2Insufficient || !troop.IsUpgrade1Available || !troop.IsUpgrade2Available) { break; } PartyScreenLogic.PartyCommand command1 = new PartyScreenLogic.PartyCommand(); PartyScreenLogic.PartyCommand command2 = new PartyScreenLogic.PartyCommand(); command1.FillForUpgradeTroop(PartyScreenLogic.PartyRosterSide.Right, troop.Type, troop.Character, 1, PartyScreenLogic.PartyCommand.UpgradeTargetType.UpgradeTarget1); var c1Valid = PartyScreenLogic.ValidateCommand(command1); PartyScreenLogic.AddCommand(command1); if (troop.IsUpgrade2Insufficient) { GenericHelpers.LogDebug("UpgradeAllTroops", $"Upgrade2 Insufficient"); break; } command2.FillForUpgradeTroop(PartyScreenLogic.PartyRosterSide.Right, troop.Type, troop.Character, 1, PartyScreenLogic.PartyCommand.UpgradeTargetType.UpgradeTarget2); var c2Valid = PartyScreenLogic.ValidateCommand(command1); PartyScreenLogic.AddCommand(command2); unitsUpgraded = true; } if (unitsUpgraded) { upgradesCount++; } } foreach (var troop in customUpgrades) { currentlyUpgradingUnit = troop?.Character?.Name?.ToString(); var upgradePath = PartyManagerSettings.Settings.SavedTroopUpgradePaths .Where(x => x.UnitName == troop.Name.ToString())?.Select(x => x.TargetUpgrade).FirstOrDefault(); if (upgradePath == 0 && !troop.IsUpgrade1Insufficient) { UpgradeUnit(troop, true); upgradesCount++; } else if (upgradePath == 1 && !troop.IsUpgrade2Insufficient) { UpgradeUnit(troop, false); upgradesCount++; } } } if (!customOnly) { //single upgrade units var singleUpgrades = upgrades.Where(x => !(x.IsUpgrade1Exists && x.IsUpgrade2Exists)).ToList(); if (PartyManagerSettings.Settings.UpgradeTroopsUseWhitelist) { singleUpgrades = singleUpgrades.Where(x => PartyManagerSettings.Settings.UpgradeTroopsBlackWhiteList.Contains(x.Name)).ToList(); } else { singleUpgrades = singleUpgrades.Where(x => !PartyManagerSettings.Settings.UpgradeTroopsBlackWhiteList.Contains(x.Name)).ToList(); } foreach (var troop in singleUpgrades) { currentlyUpgradingUnit = troop?.Character?.Name?.ToString(); PartyScreenLogic.PartyCommand command = new PartyScreenLogic.PartyCommand(); if (troop.NumOfTarget1UpgradesAvailable > 0) { UpgradeUnit(troop, true); } else { UpgradeUnit(troop, false); } upgradesCount++; } } if (upgradesCount > 0) { GenericHelpers.LogDebug("UpgradeAllTroops", $"{upgradesCount} troops upgraded"); ButtonClickRefresh(true, false); } else { GenericHelpers.LogMessage("No troops found to upgrade"); } } catch (Exception ex) { GenericHelpers.LogException($"UpgradeAllTroops unittype({currentlyUpgradingUnit})", ex); } }
private static void Postfix(PartyScreenLogic __instance, PartyBase leftParty, MobileParty ownerParty, bool isDismissMode, TextObject leftPartyName, int lefPartySizeLimit, TextObject header = null) { SortPartyHelpers.SortPartyScreen(__instance); }