Beispiel #1
0
        private void ExecuteTransferWounded()
        {
            try
            {
                var enumerator = new PartyCharacterVM[_mainPartyList.Count];
                _mainPartyList?.CopyTo(enumerator, 0);

                foreach (PartyCharacterVM character in enumerator)
                {
                    if (character?.WoundedCount > 0)
                    {
                        if (character.IsTroopTransferrable)
                        {
                            int wounded = Math.Min(character.WoundedCount, character.Number);
                            character.OnTransfer(character, -1, wounded, character.Side);
                            character.InitializeUpgrades();
                        }
                    }
                }

                _partyVm?.ExecuteRemoveZeroCounts();
                _parent.RefreshValues();
            }
            catch (Exception e)
            {
                Logging.Log(Logging.Levels.ERROR, $"Transfer Wounded Troops: {e}");
                Utilities.DisplayMessage($"PSE Transfer Wounded Exception: {e}");
            }
        }
Beispiel #2
0
        public void TransferPrisoners(bool fromLeft)
        {
            try
            {
                List <PartyCharacterVM> prisoners;

                if (fromLeft)
                {
                    prisoners = _partyVM.OtherPartyPrisoners.ToList();
                }
                else
                {
                    prisoners = _partyVM.MainPartyPrisoners.ToList();
                }

                if (_partyLogic.PrisonerTransferState == PartyScreenLogic.TransferState.TransferableWithTrade && PartyManagerSettings.Settings.RansomPrisonersUseWhitelist)
                {
                    prisoners = prisoners.Where(x => PartyManagerSettings.Settings.RansomPrisonerBlackWhiteList
                                                .Contains(x.Character.Name.ToString())).ToList();
                }
                else if (_partyLogic.PrisonerTransferState == PartyScreenLogic.TransferState.TransferableWithTrade)
                {
                    prisoners = prisoners.Where(x => !PartyManagerSettings.Settings.RansomPrisonerBlackWhiteList
                                                .Contains(x.Character.Name.ToString())).ToList();
                }
                else if (PartyManagerSettings.Settings.TransferPrisonersUseWhitelist)
                {
                    prisoners = prisoners.Where(x => PartyManagerSettings.Settings.TransferPrisonerBlackWhiteList
                                                .Contains(x.Character.Name.ToString())).ToList();
                }
                else
                {
                    prisoners = prisoners.Where(x => !PartyManagerSettings.Settings.TransferPrisonerBlackWhiteList
                                                .Contains(x.Character.Name.ToString())).ToList();
                }


                foreach (var prisoner in prisoners)
                {
                    TransferUnit(prisoner, fromLeft);
                }
                _partyVM.ExecuteRemoveZeroCounts();
            }
            catch (Exception e)
            {
                GenericHelpers.LogException("TransferPrisonersLeft", e);
            }
        }
        public bool TransferUnits(PartyCharacterVM troop, PMTransferType transferType)
        {
            try
            {
                if (troop == null || troop.Number == 0)
                {
                    return(true);
                }

                int unitCount = 0;

                switch (transferType)
                {
                case PMTransferType.All:
                    unitCount = troop.Number;
                    break;

                case PMTransferType.Half:
                    unitCount = (int)Math.Round(troop.Number / 2f, MidpointRounding.AwayFromZero);
                    break;

                case PMTransferType.Custom:
                    unitCount = Math.Min(troop.Number, PartyManagerSettings.Settings.CustomShiftTransferCount);
                    break;
                }

                if (unitCount == 0 || unitCount < 0)
                {
                    return(true);
                }

                troop.OnTransfer(troop, -1, unitCount, troop.Side);
                PartyVM.ExecuteRemoveZeroCounts();
                return(false);
            }
            catch (Exception e)
            {
                GenericHelpers.LogException("TransferUnits", e);
            }


            return(true);
        }
        public void UpgradeAllTroopsPath(int shouldUseOnlyDictInt)
        {
            var totalUpgrades     = 0;
            var toUpgrade         = new Dictionary <PartyCharacterVM, UpgradeTarget>();
            var shouldUseOnlyDict = shouldUseOnlyDictInt == 1;

            try
            {
                foreach (PartyCharacterVM character in _mainPartyList)
                {
                    if (character == null || character.Upgrades.Count == 0)
                    {
                        continue;
                    }

                    if (PartyScreenConfig.PathsToUpgrade.TryGetValue(character.Character.StringId, out var upgradePath))
                    {
                        if (upgradePath != -1)
                        {
                            toUpgrade.Add(character, new SpecificUpgradeTarget(upgradePath));
                        }
                    }
                    else if (!shouldUseOnlyDict)
                    {
                        if (character.Upgrades.Count >= 2)
                        {
                            if (PartyScreenConfig.ExtraSettings.EqualUpgrades)
                            {
                                toUpgrade.Add(character, new EqualDistributionTarget());
                            }
                        }
                        else if (character.Upgrades[0].IsAvailable)
                        {
                            toUpgrade.Add(character, new SpecificUpgradeTarget(0));
                        }
                    }
                }

                foreach (var keyValuePair in toUpgrade)
                {
                    totalUpgrades += Upgrade(keyValuePair.Key, keyValuePair.Value);
                }

                _parent.RefreshValues();
                _partyVM.ExecuteRemoveZeroCounts();

                if (PartyScreenConfig.ExtraSettings.ShowGeneralLogMessage)
                {
                    InformationManager.DisplayMessage(new InformationMessage($"Upgraded {totalUpgrades} troops!"));
                }
            }
            catch (Exception e)
            {
                Utilities.DisplayMessage($"PSE UpgradeTroops exception: {e}");
                Logging.Log(Logging.Levels.ERROR, $"Upgrade All Troops: {e}");

                foreach (var upgradeTarget in toUpgrade)
                {
                    Logging.Log(Logging.Levels.DEBUG, $"Key: {upgradeTarget.Key.Name} - Value: {upgradeTarget.Value}");
                }
            }
        }