public void LifeCheck(GameServer.PlayerLifeManaChange lifeMana) { int LifeThreshold = LifeCheck_LifeThreshold; int ManaThreshold = LifeCheck_ManaThreshold; int DrinkDelay = LifeCheck_DrinkDelay; TimeSpan span = new TimeSpan(DateTime.Now.Ticks - this.LastDrink.Ticks); if (span.TotalMilliseconds > DrinkDelay && (this.Player.Life <= LifeThreshold || this.Player.Mana <= ManaThreshold)) { // This is what we'll compare each acceptable find to Potion bestPotSoFar = new Potion(); // We'll set this to the best slot we find int bestPotSlot = -1; // First check for rejuv, then for health pot with highest potency for (int i = 0; i < 4; i++) { // if this slot isn't empty if (this.Player.Belt[i].Count > 0) { Potion tempPot = (Potion)this.Player.Belt[i].Peek(); // Make sure pot being used is for correct threshhold if (tempPot.Type != PotionType.Rejuvination) { // If life is below threshhold, but mana isn't, only drink a health if (this.Player.Life <= LifeThreshold && this.Player.Mana >= ManaThreshold) if (tempPot.Type != PotionType.Health) { continue; } // If mana is below threshhold, but life isn't, only drink a mana if (this.Player.Mana <= ManaThreshold && this.Player.Life >= LifeThreshold) if (tempPot.Type != PotionType.Mana) { continue; } } if (tempPot.Potency > bestPotSoFar.Potency) { bestPotSoFar = tempPot; bestPotSlot = i; } } } if (bestPotSlot < 0) { // Ran out of pots OnDebugOutput(new DebugOutput("No potions left!?")); } else { Action drink = new Action(ActionPriority.High); drink.OnActionExecute += delegate { Potion pot = this.Player.Belt[bestPotSlot].Peek() as Potion; GameClient.UseBeltItem p = new GameClient.UseBeltItem(pot.UID, false); GameClient.UseBeltItem p2 = new GameClient.UseBeltItem(p.PacketData); if (p.ItemUID != p2.ItemUID || p.ToMerc != p2.ToMerc || p.Unknown9 != p2.Unknown9) { throw new Exception("Bad packet building result, drinking potion."); } this.SendPacket(p.PacketData); }; OnDebugOutput(new DebugOutput("Enqueued to drink: " + bestPotSlot.ToString())); // Drink this slot this.EnqueuePriority(drink); } } }