reworking looting to fully auto loot
This commit is contained in:
parent
41b2cfb9a8
commit
f4e1def666
@ -1,98 +1,86 @@
|
||||
#include "ScriptMgr.h"
|
||||
#include "Player.h"
|
||||
#include "GameObject.h"
|
||||
#include "WorldSession.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "GridNotifiers.h"
|
||||
#include "CellImpl.h"
|
||||
#include "Config.h"
|
||||
#include "GridNotifiers.h"
|
||||
#include "GridNotifiersImpl.h"
|
||||
#include "LootMgr.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::VisitObjects(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
|
||||
class mod_autofish_PlayerScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
AutoFish_WorldUpdate() : WorldScript("AutoFish_WorldUpdate") {}
|
||||
mod_autofish_PlayerScript() : PlayerScript("mod_autofish_PlayerScript") {}
|
||||
|
||||
void OnAfterConfigLoad(bool) override
|
||||
void OnUpdate(Player* player, uint32) 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)
|
||||
if (!player->IsAlive() || player->IsInCombat() || player->GetMap()->IsBattlegroundOrArena())
|
||||
return;
|
||||
|
||||
static uint32 acc = 0;
|
||||
acc += diff;
|
||||
if (acc < sTickMs)
|
||||
return;
|
||||
acc = 0;
|
||||
Acore::GameObjectInRangeCheck check(player, player, 10.0f);
|
||||
Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck> searcher(player, foundBobber, check);
|
||||
player->VisitNearbyGridObject(10.0f, searcher);
|
||||
|
||||
auto const& players = ObjectAccessor::GetPlayers();
|
||||
for (auto const& kv : players)
|
||||
if (!foundBobber)
|
||||
return;
|
||||
|
||||
GameObject* go = foundBobber;
|
||||
if (go->GetOwnerGUID() != player->GetGUID())
|
||||
{
|
||||
Player* plr = kv.second;
|
||||
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
||||
continue;
|
||||
TryAutoLootNearbyBobber(plr);
|
||||
foundBobber = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (go->GetGoState() != GO_STATE_READY)
|
||||
{
|
||||
foundBobber = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
player->SendLoot(go->GetGUID(), LOOT_FISHING);
|
||||
Loot* loot = &go->loot;
|
||||
for (uint32 i = 0; i < loot->items.size(); ++i)
|
||||
player->StoreLootItem(i, loot);
|
||||
player->SendLootRelease(go->GetGUID());
|
||||
|
||||
foundBobber = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
static GameObject* foundBobber;
|
||||
};
|
||||
|
||||
void AddSC_autofish_world()
|
||||
GameObject* mod_autofish_PlayerScript::foundBobber = nullptr;
|
||||
|
||||
class mod_autofish_WorldScript : public WorldScript
|
||||
{
|
||||
new AutoFish_WorldUpdate();
|
||||
public:
|
||||
mod_autofish_WorldScript() : WorldScript("mod_autofish_WorldScript") {}
|
||||
|
||||
void OnGameObjectCreate(GameObject* go) override
|
||||
{
|
||||
if (go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
|
||||
lastBobber = go;
|
||||
}
|
||||
|
||||
static GameObject* GetLastBobber() { return lastBobber; }
|
||||
|
||||
private:
|
||||
static GameObject* lastBobber;
|
||||
};
|
||||
|
||||
GameObject* mod_autofish_WorldScript::lastBobber = nullptr;
|
||||
|
||||
class mod_autofish_GridNotifier : public Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck>
|
||||
{
|
||||
public:
|
||||
mod_autofish_GridNotifier(Player* p, GameObject*& result, Acore::GameObjectInRangeCheck const& check)
|
||||
: Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck>(p, result, check) {}
|
||||
};
|
||||
|
||||
void Addmod_autofishScripts()
|
||||
{
|
||||
new mod_autofish_PlayerScript();
|
||||
new mod_autofish_WorldScript();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user