public override void ConsumeConsumables()
        {
            if (_wrapper == null)
            {
                return;
            }
            var bp = GetCurrentConsumablesBreakpoint();

            if (bp == null)
            {
                return;
            }
            if (bp.Time != _currentConsumablesBreakpoint.Time)
            {
                _didConsumeConsumables = false;
            }

            if (_didConsumeConsumables)
            {
                return;
            }
            _didConsumeConsumables        = true;
            _currentConsumablesBreakpoint = bp;
            ConsumablesManager.EatConsumables(bp.Consumables, bp.Time, bp.Quantity);
        }
        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();
            }
        }
        private ConsumablesBreakpoint GetCurrentConsumablesBreakpoint()
        {
            var bps = _wrapper?.Breakpoints?.ConsumablesBreakpoints;

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

                    return(b);
                }
            }

            _currentConsumablesBreakpoint = null;
            return(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();
                }
            }
        }