Attempting to fix autofishing from pools

This commit is contained in:
Flerp 2025-11-01 18:42:12 -07:00
parent 8417de8b0f
commit 1650bdc9a9

View File

@ -19,15 +19,15 @@ namespace
uint32 sTickMs = 200; uint32 sTickMs = 200;
float sScanRange = 30.0f; float sScanRange = 30.0f;
uint32 sRecastDelayMs = 500; uint32 sRecastDelayMs = 500;
uint32 sRecastSpell = 18248; uint32 sRecastSpell = 18248; // your corrected spell
uint32 sAutoLootDelayMs = 120; uint32 sAutoLootDelayMs = 120; // small delay so pools populate loot
std::vector<uint32> sBobberEntries; std::vector<uint32> sBobberEntries;
struct GuidHash { std::size_t operator()(ObjectGuid const& g) const noexcept { return std::hash<uint64>()(g.GetRawValue()); } }; struct GuidHash { std::size_t operator()(ObjectGuid const& g) const noexcept { return std::hash<uint64>()(g.GetRawValue()); } };
std::unordered_map<ObjectGuid, uint32, GuidHash> sRecastTimers; std::unordered_map<ObjectGuid, uint32, GuidHash> sRecastTimers;
struct PendingLoot { ObjectGuid bobber; uint32 timer; }; struct PendingLoot { uint32 timer; };
std::unordered_map<ObjectGuid, PendingLoot, GuidHash> sLootTimers; std::unordered_map<ObjectGuid, PendingLoot, GuidHash> sLootTimers;
std::vector<uint32> ParseEntryList(std::string const& csv) std::vector<uint32> ParseEntryList(std::string const& csv)
@ -52,11 +52,11 @@ namespace
sRecastTimers[plr->GetGUID()] = sRecastDelayMs; sRecastTimers[plr->GetGUID()] = sRecastDelayMs;
} }
void ScheduleAutoLoot(Player* plr, GameObject* bobber) void ScheduleAutoLoot(Player* plr)
{ {
if (!sServerAutoLoot || !plr || !bobber) if (!sServerAutoLoot || !plr)
return; return;
sLootTimers[plr->GetGUID()] = PendingLoot{ bobber->GetGUID(), sAutoLootDelayMs }; sLootTimers[plr->GetGUID()] = PendingLoot{ sAutoLootDelayMs };
} }
void TickRecast(uint32 diff) void TickRecast(uint32 diff)
@ -90,11 +90,14 @@ namespace
} }
Player* plr = ObjectAccessor::FindPlayer(it->first); Player* plr = ObjectAccessor::FindPlayer(it->first);
GameObject* bobber = it->second.bobber ? ObjectAccessor::GetGameObject(*plr, it->second.bobber) : nullptr; if (plr && plr->IsInWorld())
if (plr && bobber && plr->IsInWorld() && bobber->IsInWorld())
{ {
Loot* loot = &bobber->loot; ObjectGuid lootGuid = plr->GetLootGUID(); // bobber for open water OR the pool GO for schools
if (lootGuid.IsGameObject())
{
if (GameObject* lootGo = ObjectAccessor::GetGameObject(*plr, lootGuid))
{
Loot* loot = &lootGo->loot;
for (uint32 i = 0; i < loot->items.size(); ++i) for (uint32 i = 0; i < loot->items.size(); ++i)
{ {
if (loot->items[i].is_looted) if (loot->items[i].is_looted)
@ -102,8 +105,11 @@ namespace
InventoryResult msg = EQUIP_ERR_OK; InventoryResult msg = EQUIP_ERR_OK;
plr->StoreLootItem(uint8(i), loot, msg); plr->StoreLootItem(uint8(i), loot, msg);
} }
plr->SendLootRelease(bobber->GetGUID()); plr->SendLootRelease(lootGuid);
bobber->SetLootState(GO_JUST_DEACTIVATED); if (lootGo->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
lootGo->SetLootState(GO_JUST_DEACTIVATED);
}
}
} }
it = sLootTimers.erase(it); it = sLootTimers.erase(it);
@ -126,11 +132,9 @@ namespace
if (go->getLootState() == GO_READY && go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE) if (go->getLootState() == GO_READY && go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
{ {
go->Use(plr); go->Use(plr); // fires skillups/achievements and opens the correct loot source
if (sServerAutoLoot) if (sServerAutoLoot)
ScheduleAutoLoot(plr, go); ScheduleAutoLoot(plr); // loot whatever the server opened (bobber or pool GO)
ScheduleRecast(plr); ScheduleRecast(plr);
return; return;
} }