2025-11-01 16:58:41 -07:00
|
|
|
#include "ScriptMgr.h"
|
|
|
|
|
#include "Player.h"
|
|
|
|
|
#include "GameObject.h"
|
|
|
|
|
#include "ObjectAccessor.h"
|
2025-11-01 17:15:03 -07:00
|
|
|
#include "Config.h"
|
2025-11-01 17:13:37 -07:00
|
|
|
#include "LootMgr.h"
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
namespace
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:15:03 -07:00
|
|
|
bool sEnabled = true;
|
|
|
|
|
uint32 sTickMs = 200;
|
|
|
|
|
float sScanRange = 30.0f;
|
|
|
|
|
std::vector<uint32> sBobberEntries;
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
std::vector<uint32> ParseEntryList(std::string const& csv)
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:15:03 -07:00
|
|
|
std::vector<uint32> out;
|
|
|
|
|
std::stringstream ss(csv);
|
|
|
|
|
std::string item;
|
|
|
|
|
while (std::getline(ss, item, ','))
|
2025-11-01 17:13:37 -07:00
|
|
|
{
|
2025-11-01 17:15:03 -07:00
|
|
|
item.erase(0, item.find_first_not_of(" \t\r\n"));
|
|
|
|
|
item.erase(item.find_last_not_of(" \t\r\n") + 1);
|
|
|
|
|
if (!item.empty())
|
|
|
|
|
out.push_back(uint32(std::stoul(item)));
|
2025-11-01 17:13:37 -07:00
|
|
|
}
|
2025-11-01 17:15:03 -07:00
|
|
|
return out;
|
|
|
|
|
}
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
void TryAutoFish(Player* plr)
|
|
|
|
|
{
|
|
|
|
|
if (!plr || !plr->IsInWorld())
|
2025-11-01 17:13:37 -07:00
|
|
|
return;
|
|
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
std::list<GameObject*> nearList;
|
|
|
|
|
for (auto entry : sBobberEntries)
|
|
|
|
|
plr->GetGameObjectListWithEntryInGrid(nearList, entry, sScanRange);
|
2025-11-01 17:13:37 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
for (GameObject* go : nearList)
|
|
|
|
|
{
|
|
|
|
|
if (!go || go->GetOwnerGUID() != plr->GetGUID())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (go->getLootState() == GO_READY)
|
|
|
|
|
{
|
|
|
|
|
plr->SendLoot(go->GetGUID(), LOOT_FISHING);
|
|
|
|
|
|
|
|
|
|
Loot* loot = &go->loot;
|
|
|
|
|
for (uint32 i = 0; i < loot->items.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (LootItem* li = loot->LootItemInSlot(i, plr))
|
|
|
|
|
plr->AutoStoreLootItem(i, loot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plr->SendLootRelease(go->GetGUID());
|
|
|
|
|
go->SetLootState(GO_JUST_DEACTIVATED);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-01 16:58:41 -07:00
|
|
|
}
|
2025-11-01 17:15:03 -07:00
|
|
|
}
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
class AutoFish_WorldScript : public WorldScript
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
|
|
|
|
public:
|
2025-11-01 17:15:03 -07:00
|
|
|
AutoFish_WorldScript() : WorldScript("AutoFish_WorldScript") {}
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
void OnAfterConfigLoad(bool) override
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:15:03 -07:00
|
|
|
sEnabled = sConfigMgr->GetOption<bool>("AutoFish.Enabled", true);
|
|
|
|
|
sTickMs = sConfigMgr->GetOption<uint32>("AutoFish.TickMs", 200u);
|
|
|
|
|
sScanRange = sConfigMgr->GetOption<float>("AutoFish.ScanRange", 30.0f);
|
|
|
|
|
sBobberEntries = ParseEntryList(sConfigMgr->GetOption<std::string>("AutoFish.BobberEntries", "35591"));
|
2025-11-01 16:58:41 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
void OnUpdate(uint32 diff) override
|
|
|
|
|
{
|
|
|
|
|
if (!sEnabled)
|
|
|
|
|
return;
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
static uint32 acc = 0;
|
|
|
|
|
acc += diff;
|
|
|
|
|
if (acc < sTickMs)
|
|
|
|
|
return;
|
|
|
|
|
acc = 0;
|
2025-11-01 17:13:37 -07:00
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
auto const& players = ObjectAccessor::GetPlayers();
|
|
|
|
|
for (auto const& kv : players)
|
|
|
|
|
{
|
|
|
|
|
Player* plr = kv.second;
|
|
|
|
|
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
|
|
|
|
continue;
|
|
|
|
|
TryAutoFish(plr);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-01 16:58:41 -07:00
|
|
|
};
|
|
|
|
|
|
2025-11-01 17:15:03 -07:00
|
|
|
void AddSC_autofish_world()
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:15:03 -07:00
|
|
|
new AutoFish_WorldScript();
|
2025-11-01 16:58:41 -07:00
|
|
|
}
|