Initial Commit
This commit is contained in:
parent
28d0342f4f
commit
7de504c0af
8
conf/mod_autofish.conf.dist
Normal file
8
conf/mod_autofish.conf.dist
Normal file
@ -0,0 +1,8 @@
|
||||
# AutoFish module
|
||||
AutoFish.Enabled = 1
|
||||
# How often to scan (ms). 150–250ms feels instant without being spammy.
|
||||
AutoFish.TickMs = 200
|
||||
# Max distance to look for your own bobber
|
||||
AutoFish.ScanRange = 30.0
|
||||
# Bobber entries to watch (comma-separated). Default covers classic/WotLK.
|
||||
AutoFish.BobberEntries = 35591
|
||||
6
src/loader.cpp
Normal file
6
src/loader.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
void AddSC_autofish_world();
|
||||
|
||||
void Addmod_autofishScripts()
|
||||
{
|
||||
AddSC_autofish_world();
|
||||
}
|
||||
98
src/mod_autofish.cpp
Normal file
98
src/mod_autofish.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
#include "ScriptMgr.h"
|
||||
#include "Player.h"
|
||||
#include "GameObject.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "GridNotifiers.h"
|
||||
#include "CellImpl.h"
|
||||
#include "Config.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
std::vector<uint32> sBobberEntries;
|
||||
bool sEnabled = true;
|
||||
uint32 sTickMs = 200;
|
||||
float sScanRange = 30.0f;
|
||||
|
||||
std::vector<uint32> ParseEntryList(std::string const& csv)
|
||||
{
|
||||
std::vector<uint32> out;
|
||||
std::stringstream ss(csv);
|
||||
std::string item;
|
||||
while (std::getline(ss, item, ','))
|
||||
{
|
||||
auto trim = [](std::string& s)
|
||||
{
|
||||
s.erase(0, s.find_first_not_of(" \t\r\n"));
|
||||
s.erase(s.find_last_not_of(" \t\r\n") + 1);
|
||||
};
|
||||
trim(item);
|
||||
if (!item.empty())
|
||||
out.push_back(static_cast<uint32>(std::stoul(item)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void TryAutoLootNearbyBobber(Player* plr)
|
||||
{
|
||||
if (!plr || !plr->IsInWorld())
|
||||
return;
|
||||
|
||||
std::list<GameObject*> goList;
|
||||
Acore::AllGameObjectsMatchingOneEntryInRange check(plr, sBobberEntries, sScanRange);
|
||||
Acore::GameObjectListSearcher<Acore::AllGameObjectsMatchingOneEntryInRange> searcher(plr, goList, check);
|
||||
Cell::VisitGridObjects(plr, searcher, sScanRange);
|
||||
|
||||
for (GameObject* go : goList)
|
||||
{
|
||||
if (!go)
|
||||
continue;
|
||||
if (go->GetOwnerGUID() != plr->GetGUID())
|
||||
continue;
|
||||
if (go->getLootState() == GO_READY)
|
||||
{
|
||||
plr->SendLoot(go->GetGUID(), LOOT_FISHING);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AutoFish_WorldUpdate : public WorldScript
|
||||
{
|
||||
public:
|
||||
AutoFish_WorldUpdate() : WorldScript("AutoFish_WorldUpdate") {}
|
||||
|
||||
void OnAfterConfigLoad(bool) override
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
void OnUpdate(uint32 diff) override
|
||||
{
|
||||
if (!sEnabled)
|
||||
return;
|
||||
|
||||
static uint32 acc = 0;
|
||||
acc += diff;
|
||||
if (acc < sTickMs)
|
||||
return;
|
||||
acc = 0;
|
||||
|
||||
auto const& players = ObjectAccessor::GetPlayers();
|
||||
for (auto const& kv : players)
|
||||
{
|
||||
Player* plr = kv.second;
|
||||
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
||||
continue;
|
||||
TryAutoLootNearbyBobber(plr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_autofish_world()
|
||||
{
|
||||
new AutoFish_WorldUpdate();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user