Quote:
Originally Posted by lesderid
Depending on your connection to the server, sending it, receiving the error and sending it again might take longer than simply finding the sweet spot (which is indeed probably around 1100 ms) and sending it once. Using potions as soon as possible can be quite crucial to keeping a character alive, so I would go for that solution.
|
For that reason I believe that timers are not reliable, so I tried doing this:
Code:
bool busy = false;
byte SlotHP; // its value is set by UseHP
private void HandleHPUpdate(Packet packet)
{
if (CurrentPercentHP <= ConfiguredPercentHP && !busy)
{
busy = true; // prevent concurrent operations
UseHP(); // use potion now
}
}
private void HandleItemUsed(Packet packet)
{
if (response != 1) // failed to use item
{
// busy is never set back to false
// because I have no idea which slot
// it was trying to use
return;
}
if (ItemSlotUsed == SlotHP && busy)
{
if (CurrentPercentHP <= ConfiguredPercentHP) // hp is still low
{
UseHP(1000); //use potion after 1000ms
}
else // hp is higher than configured, stop using potions
{
busy = false;
SlotHP = 255;
}
}
}
This works well, until it reaches a point where it tries to use a potion too fast (how is that even possible ?) the server then responds with "Still have time to reuse item" and obviously the flag "busy" is never set back to false, so the whole thing is stuck.