adding delay before autoloot
This commit is contained in:
parent
353dcac81f
commit
8417de8b0f
@ -12,3 +12,4 @@ AutoFish.ServerAutoLoot = 1
|
||||
AutoFish.AutoRecast = 1
|
||||
AutoFish.RecastDelayMs = 500
|
||||
AutoFish.RecastSpell = 18248
|
||||
AutoFish.AutoLootDelayMs = 120
|
||||
|
||||
@ -19,12 +19,17 @@ namespace
|
||||
uint32 sTickMs = 200;
|
||||
float sScanRange = 30.0f;
|
||||
uint32 sRecastDelayMs = 500;
|
||||
uint32 sRecastSpell = 131474;
|
||||
uint32 sRecastSpell = 18248;
|
||||
uint32 sAutoLootDelayMs = 120;
|
||||
std::vector<uint32> sBobberEntries;
|
||||
|
||||
struct GuidHash { std::size_t operator()(ObjectGuid const& g) const noexcept { return std::hash<uint64>()(g.GetRawValue()); } };
|
||||
|
||||
std::unordered_map<ObjectGuid, uint32, GuidHash> sRecastTimers;
|
||||
|
||||
struct PendingLoot { ObjectGuid bobber; uint32 timer; };
|
||||
std::unordered_map<ObjectGuid, PendingLoot, GuidHash> sLootTimers;
|
||||
|
||||
std::vector<uint32> ParseEntryList(std::string const& csv)
|
||||
{
|
||||
std::vector<uint32> out;
|
||||
@ -47,6 +52,13 @@ namespace
|
||||
sRecastTimers[plr->GetGUID()] = sRecastDelayMs;
|
||||
}
|
||||
|
||||
void ScheduleAutoLoot(Player* plr, GameObject* bobber)
|
||||
{
|
||||
if (!sServerAutoLoot || !plr || !bobber)
|
||||
return;
|
||||
sLootTimers[plr->GetGUID()] = PendingLoot{ bobber->GetGUID(), sAutoLootDelayMs };
|
||||
}
|
||||
|
||||
void TickRecast(uint32 diff)
|
||||
{
|
||||
for (auto it = sRecastTimers.begin(); it != sRecastTimers.end();)
|
||||
@ -66,6 +78,38 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void TickAutoLoot(uint32 diff)
|
||||
{
|
||||
for (auto it = sLootTimers.begin(); it != sLootTimers.end();)
|
||||
{
|
||||
if (it->second.timer > diff)
|
||||
{
|
||||
it->second.timer -= diff;
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
Player* plr = ObjectAccessor::FindPlayer(it->first);
|
||||
GameObject* bobber = it->second.bobber ? ObjectAccessor::GetGameObject(*plr, it->second.bobber) : nullptr;
|
||||
|
||||
if (plr && bobber && plr->IsInWorld() && bobber->IsInWorld())
|
||||
{
|
||||
Loot* loot = &bobber->loot;
|
||||
for (uint32 i = 0; i < loot->items.size(); ++i)
|
||||
{
|
||||
if (loot->items[i].is_looted)
|
||||
continue;
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(uint8(i), loot, msg);
|
||||
}
|
||||
plr->SendLootRelease(bobber->GetGUID());
|
||||
bobber->SetLootState(GO_JUST_DEACTIVATED);
|
||||
}
|
||||
|
||||
it = sLootTimers.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void TryAutoFish(Player* plr)
|
||||
{
|
||||
if (!plr || !plr->IsInWorld())
|
||||
@ -85,18 +129,7 @@ namespace
|
||||
go->Use(plr);
|
||||
|
||||
if (sServerAutoLoot)
|
||||
{
|
||||
Loot* loot = &go->loot;
|
||||
for (uint32 i = 0; i < loot->items.size(); ++i)
|
||||
{
|
||||
if (loot->items[i].is_looted)
|
||||
continue;
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(uint8(i), loot, msg);
|
||||
}
|
||||
plr->SendLootRelease(go->GetGUID());
|
||||
go->SetLootState(GO_JUST_DEACTIVATED);
|
||||
}
|
||||
ScheduleAutoLoot(plr, go);
|
||||
|
||||
ScheduleRecast(plr);
|
||||
return;
|
||||
@ -119,6 +152,7 @@ public:
|
||||
sScanRange = sConfigMgr->GetOption<float>("AutoFish.ScanRange", 30.0f);
|
||||
sRecastDelayMs = sConfigMgr->GetOption<uint32>("AutoFish.RecastDelayMs", 500u);
|
||||
sRecastSpell = sConfigMgr->GetOption<uint32>("AutoFish.RecastSpell", 18248u);
|
||||
sAutoLootDelayMs = sConfigMgr->GetOption<uint32>("AutoFish.AutoLootDelayMs", 120u);
|
||||
sBobberEntries = ParseEntryList(sConfigMgr->GetOption<std::string>("AutoFish.BobberEntries", "35591"));
|
||||
}
|
||||
|
||||
@ -142,6 +176,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
TickAutoLoot(diff);
|
||||
TickRecast(diff);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user