Changing interaction behavior to use(player)

This commit is contained in:
Flerp 2025-11-01 17:31:42 -07:00
parent 12475ef9c2
commit 2d9736d6df

View File

@ -2,16 +2,19 @@
#include "Player.h"
#include "GameObject.h"
#include "ObjectAccessor.h"
#include "GridNotifiers.h"
#include "CellImpl.h"
#include "Config.h"
#include "WorldSession.h"
#include <sstream>
#include <vector>
#include <list>
#include <string>
namespace
{
std::vector<uint32> sBobberEntries;
bool sEnabled = true;
uint32 sTickMs = 200;
float sScanRange = 30.0f;
std::vector<uint32> sBobberEntries;
std::vector<uint32> ParseEntryList(std::string const& csv)
{
@ -20,47 +23,41 @@ namespace
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);
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(static_cast<uint32>(std::stoul(item)));
out.push_back(uint32(std::stoul(item)));
}
return out;
}
void TryAutoLootNearbyBobber(Player* plr)
void TryAutoFish(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::VisitObjects(plr, searcher, sScanRange);
std::list<GameObject*> nearList;
for (auto entry : sBobberEntries)
plr->GetGameObjectListWithEntryInGrid(nearList, entry, sScanRange);
for (GameObject* go : goList)
for (GameObject* go : nearList)
{
if (!go)
if (!go || go->GetOwnerGUID() != plr->GetGUID())
continue;
if (go->GetOwnerGUID() != plr->GetGUID())
continue;
if (go->getLootState() == GO_READY)
if (go->getLootState() == GO_READY && go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
{
plr->SendLoot(go->GetGUID(), LOOT_FISHING);
go->Use(plr);
return;
}
}
}
}
class AutoFish_WorldUpdate : public WorldScript
class AutoFish_WorldScript : public WorldScript
{
public:
AutoFish_WorldUpdate() : WorldScript("AutoFish_WorldUpdate") {}
AutoFish_WorldScript() : WorldScript("AutoFish_WorldScript") {}
void OnAfterConfigLoad(bool) override
{
@ -87,12 +84,12 @@ public:
Player* plr = kv.second;
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
continue;
TryAutoLootNearbyBobber(plr);
TryAutoFish(plr);
}
}
};
void AddSC_autofish_world()
{
new AutoFish_WorldUpdate();
new AutoFish_WorldScript();
}