public override void EquipGear()
        {
            if (_wrapper == null)
            {
                return;
            }
            var bp = GetCurrentGearBreakpoint();

            if (bp == null)
            {
                return;
            }

            if (bp.Time != _currentGearBreakpoint.Time)
            {
                _hasGearSwapped = false;
            }

            if (_hasGearSwapped)
            {
                return;
            }

            if (!LoadoutManager.CanSwap())
            {
                return;
            }
            _hasGearSwapped        = true;
            _currentGearBreakpoint = bp;
            LoadoutManager.ChangeGear(bp.Gear);
            Main.Controller.assignCurrentEquipToLoadout(0);
        }
        private GearBreakpoint GetCurrentGearBreakpoint()
        {
            var bps = _wrapper?.Breakpoints?.Gear;

            if (bps == null)
            {
                return(null);
            }
            foreach (var b in bps)
            {
                if (_character.rebirthTime.totalseconds > b.Time)
                {
                    if (_currentGearBreakpoint == null)
                    {
                        _hasGearSwapped        = false;
                        _currentGearBreakpoint = b;
                    }

                    return(b);
                }
            }

            _currentGearBreakpoint = null;
            return(null);
        }
        public void DoRebirth()
        {
            if (_wrapper == null)
            {
                return;
            }

            if (_wrapper.Breakpoints.Rebirth.RebirthAvailable())
            {
                if (_character.bossController.isFighting || _character.bossController.nukeBoss)
                {
                    Main.Log("Delaying rebirth while boss fight is in progress");
                    return;
                }
            }
            else
            {
                return;
            }

            if (_wrapper.Breakpoints.Rebirth.DoRebirth())
            {
                _currentDiggerBreakpoint      = null;
                _currentEnergyBreakpoint      = null;
                _currentGearBreakpoint        = null;
                _currentWandoosBreakpoint     = null;
                _currentMagicBreakpoint       = null;
                _currentR3Breakpoint          = null;
                _currentNguBreakpoint         = null;
                _currentConsumablesBreakpoint = null;
                ConsumablesManager.resetLastConsumables();
            }
        }
Beispiel #4
0
        public void DoRebirth()
        {
            if (_wrapper == null)
            {
                return;
            }

            if (_wrapper.Breakpoints.RebirthTime < 0)
            {
                return;
            }

            if (_character.rebirthTime.totalseconds < _wrapper.Breakpoints.RebirthTime)
            {
                return;
            }

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

            Main.Log("Rebirth time hit, performing rebirth");
            var controller = Main.Character.rebirth;

            typeof(Rebirth).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
            .Single(x => x.Name == "engage" && x.GetParameters().Length == 0).Invoke(controller, null);
        }
        public void DoRebirth()
        {
            if (_wrapper == null)
            {
                return;
            }

            if (_wrapper.Breakpoints.RebirthTime < 0)
            {
                return;
            }

            if (_character.rebirthTime.totalseconds < _wrapper.Breakpoints.RebirthTime)
            {
                return;
            }

            if (Main.Settings.SwapYggdrasilLoadouts && Main.Settings.YggdrasilLoadout.Length > 0)
            {
                if (!LoadoutManager.TryYggdrasilSwap() || !DiggerManager.TryYggSwap())
                {
                    Main.Log("Delaying rebirth to wait for ygg loadout/diggers");
                    return;
                }

                YggdrasilManager.HarvestAll();
                LoadoutManager.RestoreGear();
                LoadoutManager.ReleaseLock();
                DiggerManager.RestoreDiggers();
                DiggerManager.ReleaseLock();
            }

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

            Main.Log("Rebirth time hit, performing rebirth");
            var controller = Main.Character.rebirth;

            typeof(Rebirth).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
            .Single(x => x.Name == "engage" && x.GetParameters().Length == 0).Invoke(controller, null);
        }
        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()
                    };
                    var rb     = breakpoints["Rebirth"];
                    var rbtime = breakpoints["RebirthTime"];
                    if (rb == null)
                    {
                        _wrapper.Breakpoints.Rebirth = rbtime == null ? new NoRebirth() : BaseRebirth.CreateRebirth(ParseTime(rbtime), "time", new string[0]);
                    }
                    else
                    {
                        if (rb["Type"] == null || rb["Target"] == null)
                        {
                            _wrapper.Breakpoints.Rebirth = new NoRebirth();
                        }

                        var type   = rb["Type"].Value.ToUpper();
                        var target = type == "TIME" ? ParseTime(rb["Target"]) : rb["Target"].AsDouble;
                        _wrapper.Breakpoints.Rebirth = BaseRebirth.CreateRebirth(target, type, rb["Challenges"].AsArray.Children.Select(x => x.Value.ToUpper()).ToArray());
                    }

                    _wrapper.Breakpoints.ConsumablesBreakpoints = breakpoints["Consumables"].Children.Select(bp => new ConsumablesBreakpoint {
                        Time        = ParseTime(bp["Time"]),
                        Consumables = ParseConsumableItemNames(bp["Items"].AsArray.Children.Select(x => x.Value.ToUpper()).ToArray()),
                        Quantity    = GetConsumablesQuantities(bp["Items"].AsArray.Children.Select(x => x.Value.ToUpper()).ToArray())
                    }).OrderByDescending(x => x.Time).ToArray();


                    _wrapper.Breakpoints.Magic = breakpoints["Magic"].Children.Select(bp => new AllocationBreakPoint
                    {
                        Time       = ParseTime(bp["Time"]),
                        Priorities = BaseBreakpoint.ParseBreakpointArray(bp["Priorities"].AsArray.Children.Select(x => x.Value.ToUpper())
                                                                         .ToArray(), ResourceType.Magic, rbtime).Where(x => x != null).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();

                    _wrapper.Breakpoints.Energy = breakpoints["Energy"].Children.Select(bp => new AllocationBreakPoint
                    {
                        Time       = ParseTime(bp["Time"]),
                        Priorities = BaseBreakpoint.ParseBreakpointArray(bp["Priorities"].AsArray.Children.Select(x => x.Value.ToUpper())
                                                                         .ToArray(), ResourceType.Energy, rbtime).Where(x => x != null).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();

                    _wrapper.Breakpoints.R3 = breakpoints["R3"].Children.Select(bp => new AllocationBreakPoint
                    {
                        Time       = ParseTime(bp["Time"]),
                        Priorities = BaseBreakpoint.ParseBreakpointArray(bp["Priorities"].AsArray.Children.Select(x => x.Value.ToUpper())
                                                                         .ToArray(), ResourceType.R3, rbtime).Where(x => x != null).ToArray()
                    }).OrderByDescending(x => x.Time).ToArray();

                    _wrapper.Breakpoints.Gear = breakpoints["Gear"].Children
                                                .Select(bp => new GearBreakpoint
                    {
                        Time = ParseTime(bp["Time"]),
                        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    = ParseTime(bp["Time"]),
                        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 = ParseTime(bp["Time"]), OS = bp["OS"].AsInt
                    })
                                                   .OrderByDescending(x => x.Time).ToArray();

                    _wrapper.Breakpoints.NGUBreakpoints = breakpoints["NGUDiff"].Children
                                                          .Select(bp => new NGUDiffBreakpoint {
                        Time = ParseTime(bp["Time"]), Diff = bp["Diff"].AsInt
                    })
                                                          .Where(x => x.Diff <= 2).OrderByDescending(x => x.Time).ToArray();

                    Main.Log(BuildAllocationString());

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

                    this.DoAllocations();
                }
                catch (Exception e)
                {
                    Main.Log("Failed to load allocation file. Resave to reload");
                    Main.Log(e.Message);
                    Main.Log(e.StackTrace);
                    _wrapper = new BreakpointWrapper
                    {
                        Breakpoints =
                        {
                            Rebirth                = new NoRebirth(),          R3      = new AllocationBreakPoint[0],
                            Diggers                = new DiggerBreakpoint[0],  Energy  = new AllocationBreakPoint[0],
                            Gear                   = new GearBreakpoint[0],    Magic   = new AllocationBreakPoint[0],
                            NGUBreakpoints         = new NGUDiffBreakpoint[0], Wandoos = new WandoosBreakpoint[0],
                            ConsumablesBreakpoints = new ConsumablesBreakpoint[0]
                        }
                    };

                    _currentDiggerBreakpoint      = null;
                    _currentEnergyBreakpoint      = null;
                    _currentGearBreakpoint        = null;
                    _currentWandoosBreakpoint     = null;
                    _currentMagicBreakpoint       = null;
                    _currentR3Breakpoint          = null;
                    _currentNguBreakpoint         = null;
                    _currentConsumablesBreakpoint = null;
                }
            }
            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"": []
        }
      ],
      ""NGUDiff"": [
        {
          ""Time"": 0,
          ""Diff"": 0
        }
      ],
      ""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();
                }
            }
        }
Beispiel #7
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 && Main.Character.buttons.bloodMagic.interactable)
                    {
                        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();
                }
            }
        }