From 8417de8b0f9e32dca9f8137343398edff88c8acf Mon Sep 17 00:00:00 2001 From: Flerp Date: Sat, 1 Nov 2025 18:35:44 -0700 Subject: [PATCH] adding delay before autoloot --- conf/mod_autofish.conf.dist | 1 + src/mod_autofish.cpp | 61 +++++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/conf/mod_autofish.conf.dist b/conf/mod_autofish.conf.dist index 1bc0007..c934eab 100644 --- a/conf/mod_autofish.conf.dist +++ b/conf/mod_autofish.conf.dist @@ -12,3 +12,4 @@ AutoFish.ServerAutoLoot = 1 AutoFish.AutoRecast = 1 AutoFish.RecastDelayMs = 500 AutoFish.RecastSpell = 18248 +AutoFish.AutoLootDelayMs = 120 diff --git a/src/mod_autofish.cpp b/src/mod_autofish.cpp index 8801c1b..6dc8e79 100644 --- a/src/mod_autofish.cpp +++ b/src/mod_autofish.cpp @@ -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 sBobberEntries; struct GuidHash { std::size_t operator()(ObjectGuid const& g) const noexcept { return std::hash()(g.GetRawValue()); } }; + std::unordered_map sRecastTimers; + struct PendingLoot { ObjectGuid bobber; uint32 timer; }; + std::unordered_map sLootTimers; + std::vector ParseEntryList(std::string const& csv) { std::vector 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("AutoFish.ScanRange", 30.0f); sRecastDelayMs = sConfigMgr->GetOption("AutoFish.RecastDelayMs", 500u); sRecastSpell = sConfigMgr->GetOption("AutoFish.RecastSpell", 18248u); + sAutoLootDelayMs = sConfigMgr->GetOption("AutoFish.AutoLootDelayMs", 120u); sBobberEntries = ParseEntryList(sConfigMgr->GetOption("AutoFish.BobberEntries", "35591")); } @@ -142,6 +176,7 @@ public: } } + TickAutoLoot(diff); TickRecast(diff); } };