private void DealPatyTroop(TroopRoster battleTroopRoster) { TroopRoster troopRosters = MobileParty.MainParty.MemberRoster; ICollection <TroopRosterElement> needMoveTroop = troopRosters.RemoveIf(obj => !battleTroopRoster.Contains(obj.Character)); foreach (TroopRosterElement element in needMoveTroop) { if (element.Character.IsHero) { this._tempMobile.MemberRoster.AddToCounts(element.Character, 1); } else { this._tempMobile.MemberRoster.AddToCounts(element.Character, element.Number); } } }
private static void SortAnyParty(MBBindingList <PartyCharacterVM> toSort, PartyBase party, TroopRoster rosterToSort, PartySort sorter) { if (rosterToSort == null || rosterToSort.Count == 0 || toSort == null || toSort.IsEmpty()) { return; } CharacterObject leaderOfParty = party?.LeaderHero?.CharacterObject; // Sort the list, this is done for the visual unit cards to be properly positioned after the sort // This is not yet persisted to the actual roster, that is done after this. toSort.StableSort(sorter); // Sanity check to ensure the leader is *always* at the top of the party. if (leaderOfParty != null) { var index = toSort.FindIndex((character) => character.Character.Equals(leaderOfParty)); PartyCharacterVM leaderVm = toSort[index]; toSort.RemoveAt(index); toSort.Insert(0, leaderVm); } // Here we manually clear the roster while ignoring the party leader. // Don't use `rosterToSort.Clear()` as that seems to cause the party leader to get unset permanently afterward, which stops upgrades from working. rosterToSort.RemoveIf((item) => item.Character != leaderOfParty); // Re-add the correctly sorted troops to the roster. We need to do it in this janky way due to the fact that we can't easily sort // the underlying roster array. foreach (PartyCharacterVM character in toSort) { if (character.Character != leaderOfParty) { rosterToSort.AddToCounts( character.Troop.Character, character.Troop.Number, false, character.Troop.WoundedNumber, character.Troop.Xp); } } }