示例#1
0
        internal void ReloadAllocation()
        {
            if (File.Exists(_allocationPath))
            {
                try
                {
                    var text        = File.ReadAllText(_allocationPath);
                    var parsed      = JSON.Parse(text);
                    var breakpoints = parsed["Breakpoints"];
                    _wrapper = new BreakpointWrapper {
                        Breakpoints = new Breakpoints()
                    };
                    _wrapper.Breakpoints.Magic = breakpoints["Magic"].Children.Select(bp => new AllocationBreakPoint {
                        Time = bp["Time"].AsInt, Priorities = bp["Priorities"].AsArray.Children.Select(x => x.Value.ToUpper()).Where(x => _validMagicPriorities.Any(x.StartsWith)).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();
                    _wrapper.Breakpoints.Energy = breakpoints["Energy"].Children.Select(bp => new AllocationBreakPoint {
                        Time = bp["Time"].AsInt, Priorities = bp["Priorities"].AsArray.Children.Select(x => x.Value.ToUpper()).Where(x => _validEnergyPriorities.Any(x.StartsWith)).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();
                    _wrapper.Breakpoints.R3 = breakpoints["R3"].Children.Select(bp => new AllocationBreakPoint {
                        Time = bp["Time"].AsInt, Priorities = bp["Priorities"].AsArray.Children.Select(x => x.Value.ToUpper()).Where(x => _validR3Priorities.Any(x.StartsWith)).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();
                    _wrapper.Breakpoints.Gear = breakpoints["Gear"].Children.Select(bp => new GearBreakpoint {
                        Time = bp["Time"].AsInt, Gear = bp["ID"].AsArray.Children.Select(x => x.AsInt).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();
                    _wrapper.Breakpoints.Diggers = breakpoints["Diggers"].Children.Select(bp => new DiggerBreakpoint {
                        Time = bp["Time"].AsInt, Diggers = bp["List"].AsArray.Children.Select(x => x.AsInt).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();
                    _wrapper.Breakpoints.Wandoos = breakpoints["Wandoos"].Children.Select(bp => new WandoosBreakpoint {
                        Time = bp["Time"].AsInt, OS = bp["OS"].AsInt
                    }).OrderByDescending(x => x.Time).ToArray();
                    _wrapper.Breakpoints.RebirthTime = breakpoints["RebirthTime"].AsInt;

                    if (_wrapper.Breakpoints.RebirthTime < 180 && _wrapper.Breakpoints.RebirthTime != -1)
                    {
                        _wrapper.Breakpoints.RebirthTime = -1;
                        Main.Log("Invalid rebirth time in allocation. Rebirth disabled");
                    }

                    if (_wrapper.Breakpoints.RebirthTime > 0)
                    {
                        Main.Log($"Loaded custom allocation:\n{_wrapper.Breakpoints.Energy.Length} energy breakpoints\n{_wrapper.Breakpoints.Magic.Length} magic breakpoints\n{_wrapper.Breakpoints.R3.Length} R3 breakpoints\n{_wrapper.Breakpoints.Gear.Length} gear breakpoints\n{_wrapper.Breakpoints.Diggers.Length} digger breakpoints,\n{_wrapper.Breakpoints.Wandoos.Length} wandoos OS breakpoints. \nRebirth at {_wrapper.Breakpoints.RebirthTime}");
                    }
                    else
                    {
                        Main.Log($"Loaded custom allocation:\n{_wrapper.Breakpoints.Energy.Length} energy breakpoints\n{_wrapper.Breakpoints.Magic.Length} magic breakpoints\n{_wrapper.Breakpoints.R3.Length} R3 breakpoints\n{_wrapper.Breakpoints.Gear.Length} gear breakpoints\n{_wrapper.Breakpoints.Diggers.Length} digger breakpoints.\n{_wrapper.Breakpoints.Wandoos.Length} wandoos OS breakpoints. \nNo rebirth time specified");
                    }

                    _currentDiggerBreakpoint  = null;
                    _currentEnergyBreakpoint  = null;
                    _currentGearBreakpoint    = null;
                    _currentWandoosBreakpoint = null;
                    _currentMagicBreakpoint   = null;
                    _currentR3Breakpoint      = null;

                    if (Main.Settings.ManageEnergy)
                    {
                        _character.removeMostEnergy();
                    }

                    if (Main.Settings.ManageR3)
                    {
                        _character.removeAllRes3();
                    }

                    if (Main.Settings.ManageMagic)
                    {
                        _character.removeMostMagic();
                    }

                    if (Main.Settings.ManageGear)
                    {
                        EquipGear();
                    }
                    if (Main.Settings.ManageEnergy)
                    {
                        AllocateEnergy();
                    }
                    if (Main.Settings.ManageMagic)
                    {
                        AllocateMagic();
                    }
                    if (Main.Settings.ManageDiggers && Main.Character.buttons.diggers.interactable)
                    {
                        EquipDiggers();
                    }
                    if (Main.Settings.ManageR3 && Main.Character.buttons.hacks.interactable)
                    {
                        AllocateR3();
                    }
                }
                catch (Exception e)
                {
                    Main.Log(e.Message);
                    Main.Log(e.StackTrace);
                }
            }
            else
            {
                var emptyAllocation = @"{
    ""Breakpoints"": {
      ""Magic"": [
        {
          ""Time"": 0,
          ""Priorities"": []
        }
      ],
      ""Energy"": [
        {
          ""Time"": 0,
          ""Priorities"": []
        }
      ],
    ""R3"": [
        {
          ""Time"": 0,
          ""Priorities"": []
        }
      ],
      ""Gear"": [
        {
          ""Time"": 0,
          ""ID"": []
        }
      ],
      ""Wandoos"": [
        {
          ""Time"": 0,
          ""OS"": 0
        }
      ],
      ""Diggers"": [
        {
          ""Time"": 0,
          ""List"": []
        }
      ],
      ""RebirthTime"": -1
    }
  }
        ";

                Main.Log("Created empty allocation profile. Please update allocation.json");
                using (var writer = new StreamWriter(File.Open(_allocationPath, FileMode.CreateNew)))
                {
                    writer.WriteLine(emptyAllocation);
                    writer.Flush();
                }
            }
        }