Пример #1
0
        public static MBBindingList <string> GetSelectableSortOrderStrings()
        {
            var sortTypes = new MBBindingList <string>();

            try
            {
                foreach (var sort in Enum.GetValues(typeof(CustomSortOrder)))
                {
                    if ((int)sort >= 0)
                    {
                        sortTypes.Add(sort.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                GenericHelpers.LogException("PartyManagerSettings.GetSelectableSortOrders", ex);
            }

            return(sortTypes);
        }
Пример #2
0
        public PartyManagerSettings Clone()
        {
            try
            {
                //I feel dirty
                PartyManagerSettings clone;
                using (MemoryStream ms = new MemoryStream())
                {
                    Serializer.Serialize(ms, this);

                    ms.Seek(0, SeekOrigin.Begin);
                    clone = Serializer.Deserialize(ms) as PartyManagerSettings;
                }

                return(clone);
            }
            catch (Exception ex)
            {
                GenericHelpers.LogException("PartyManagerSettings.Clone", ex);
            }

            return(null);
        }
Пример #3
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);
            }
        }
Пример #4
0
 public PartyController()
 {
     GenericHelpers.LogDebug("PartyController.Constructor", "Party Controller Generated");
 }
Пример #5
0
 public static MethodInfo GetInitializeTroopListsMethod(this PartyVM partyVM)
 {
     return(GenericHelpers.GetPrivateMethod("InitializeTroopLists", partyVM));
 }
Пример #6
0
 public static MethodInfo GetRefreshPartyInformationMethod(this PartyVM partyVM)
 {
     return(GenericHelpers.GetPrivateMethod("RefreshPartyInformation", partyVM));
 }
Пример #7
0
 //PartyVM calls
 public static PartyScreenLogic GetPartyScreenLogic(this PartyVM partyVM)
 {
     return(GenericHelpers.GetPrivateField <PartyScreenLogic, PartyVM>(partyVM, "_partyScreenLogic"));
 }
Пример #8
0
 public static GauntletLayer GetGauntletLayer(this GauntletPartyScreen partyScreen)
 {
     return(GenericHelpers.GetPrivateField <GauntletLayer, GauntletPartyScreen>(partyScreen, "_gauntletLayer"));
 }
Пример #9
0
 public static PartyVM GetPartyVM(this GauntletPartyScreen partyScreen)
 {
     return(GenericHelpers.GetPrivateField <PartyVM, GauntletPartyScreen>(partyScreen, "_dataSource"));
 }
Пример #10
0
        private static PartyManagerSettings CreateUpdateFile(PartyManagerSettings settings = null)
        {
            try
            {
                var newFileGenerated = false;
                if (settings == null)
                {
                    settings         = new PartyManagerSettings();
                    newFileGenerated = true;
                }
                else
                {
                    for (int i = settings.Version.Value; i < version; i++)
                    {
                        switch (i)
                        {
                        case 1:
                            settings.EnableHotkey   = true;
                            settings.EnableAutoSort = true;
                            break;

                        case 2:
                            settings.EnableSortTypeCycleHotkey      = true;
                            settings.EnableRecruitUpgradeSortHotkey = true;
                            break;

                        case 3:
                            settings.CavalryAboveFootmen = true;
                            settings.MeleeAboveArchers   = true;
                            break;
                        }
                    }

                    settings.Version = version;
                }


                var saveDirectory = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }


                using (var fs = new FileStream(filePath, FileMode.Create))
                {
                    Serializer.Serialize(fs, settings);
                }

                if (newFileGenerated)
                {
                    var fullPath = Path.GetFullPath(filePath);
                    settings.NewFileMessage = $"PartyManager config generated at {fullPath}";
                }
            }
            catch (Exception ex)
            {
                GenericHelpers.LogException("PartyManagerSettings.CreateUpdateFile", ex);
            }

            return(settings);
        }
Пример #11
0
 public void SaveSettings()
 {
     CreateUpdateFile(this);
     GenericHelpers.LogDebug("PartyManagerSettings", "Settings Saved");
 }
Пример #12
0
 public static void ReloadSettings()
 {
     _settings = LoadSettings();
     GenericHelpers.LogMessage("Settings Reloaded");
 }