reworking looting to fully auto loot
This commit is contained in:
parent
41b2cfb9a8
commit
f4e1def666
@ -1,98 +1,86 @@
|
|||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "GameObject.h"
|
#include "GameObject.h"
|
||||||
|
#include "WorldSession.h"
|
||||||
#include "ObjectAccessor.h"
|
#include "ObjectAccessor.h"
|
||||||
#include "GridNotifiers.h"
|
|
||||||
#include "CellImpl.h"
|
#include "CellImpl.h"
|
||||||
#include "Config.h"
|
#include "GridNotifiers.h"
|
||||||
|
#include "GridNotifiersImpl.h"
|
||||||
|
#include "LootMgr.h"
|
||||||
|
|
||||||
namespace
|
class mod_autofish_PlayerScript : public PlayerScript
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
public:
|
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);
|
if (!player->IsAlive() || player->IsInCombat() || player->GetMap()->IsBattlegroundOrArena())
|
||||||
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;
|
return;
|
||||||
|
|
||||||
static uint32 acc = 0;
|
Acore::GameObjectInRangeCheck check(player, player, 10.0f);
|
||||||
acc += diff;
|
Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck> searcher(player, foundBobber, check);
|
||||||
if (acc < sTickMs)
|
player->VisitNearbyGridObject(10.0f, searcher);
|
||||||
return;
|
|
||||||
acc = 0;
|
|
||||||
|
|
||||||
auto const& players = ObjectAccessor::GetPlayers();
|
if (!foundBobber)
|
||||||
for (auto const& kv : players)
|
return;
|
||||||
|
|
||||||
|
GameObject* go = foundBobber;
|
||||||
|
if (go->GetOwnerGUID() != player->GetGUID())
|
||||||
{
|
{
|
||||||
Player* plr = kv.second;
|
foundBobber = nullptr;
|
||||||
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
return;
|
||||||
continue;
|
|
||||||
TryAutoLootNearbyBobber(plr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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