示例#1
0
        protected override void OnClick()
        {
            TroopRoster prisonRoster = MobileParty.MainParty.PrisonRoster;
            int         num          = 0;
            IRecruitPrisonersCampaignBehavior campaignBehavior = Campaign.Current.GetCampaignBehavior <IRecruitPrisonersCampaignBehavior>();
            CharacterObject bestPrisoner = null;

            while ((bestPrisoner = getBestRecruitablePrisoner()) != null)
            {
                if (MobileParty.MainParty.Party.PartySizeLimit <= MobileParty.MainParty.MemberRoster.TotalManCount)
                {
                    break;
                }

                int recruitableNumber = Campaign.Current.GetCampaignBehavior <IRecruitPrisonersCampaignBehavior>().GetRecruitableNumber(bestPrisoner);
                if (recruitableNumber > 0)
                {
                    int maxRecruitable = MobileParty.MainParty.Party.PartySizeLimit - MobileParty.MainParty.MemberRoster.TotalManCount;
                    recruitableNumber = Math.Min(recruitableNumber, maxRecruitable);
                    num += recruitableNumber;
                    PartyCommand command = new PartyCommand();
                    command.FillForRecruitTroop(PartyRosterSide.Right, TroopType.Prisoner, bestPrisoner, recruitableNumber);
                    _partyLogic.AddCommand(command);
                }
            }
            InformationManager.DisplayMessage(new InformationMessage("Recruited " + num.ToString() + " prisoners"));
        }
示例#2
0
        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);
            }
        }
示例#3
0
 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);
 }
        private void SendCommand(PartyCharacterVM character, int amount,
                                 int target)
        {
            var partyCommand = new PartyScreenLogic.PartyCommand();

            partyCommand.FillForUpgradeTroop(character.Side, character.Type, character.Character, amount, target);
            _partyVM.CurrentCharacter = character;
            _partyLogic.AddCommand(partyCommand);
        }
        private void RecruitPrisoner(PartyCharacterVM character, int remainingSize, ref int amount)
        {
            if (!_partyLogic.IsPrisonerRecruitable(character.Type, character.Character, character.Side))
            {
                return;
            }

            var number = Math.Min(character.NumOfRecruitablePrisoners, remainingSize);

            if (number > 0)
            {
                PartyScreenLogic.PartyCommand partyCommand = new PartyScreenLogic.PartyCommand();
                partyCommand.FillForRecruitTroop(character.Side, character.Type,
                                                 character.Character, number);

                _partyLogic.AddCommand(partyCommand);

                amount += number;
                character.UpdateRecruitable();
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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);
        }