moving onupdate to worldscript
This commit is contained in:
parent
f4e1def666
commit
b0cb8dbb1f
@ -1,86 +1,101 @@
|
|||||||
#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 "CellImpl.h"
|
#include "Config.h"
|
||||||
#include "GridNotifiers.h"
|
|
||||||
#include "GridNotifiersImpl.h"
|
|
||||||
#include "LootMgr.h"
|
#include "LootMgr.h"
|
||||||
|
|
||||||
class mod_autofish_PlayerScript : public PlayerScript
|
namespace
|
||||||
{
|
{
|
||||||
public:
|
bool sEnabled = true;
|
||||||
mod_autofish_PlayerScript() : PlayerScript("mod_autofish_PlayerScript") {}
|
uint32 sTickMs = 200;
|
||||||
|
float sScanRange = 30.0f;
|
||||||
|
std::vector<uint32> sBobberEntries;
|
||||||
|
|
||||||
void OnUpdate(Player* player, uint32) override
|
std::vector<uint32> ParseEntryList(std::string const& csv)
|
||||||
{
|
{
|
||||||
if (!player->IsAlive() || player->IsInCombat() || player->GetMap()->IsBattlegroundOrArena())
|
std::vector<uint32> out;
|
||||||
return;
|
std::stringstream ss(csv);
|
||||||
|
std::string item;
|
||||||
Acore::GameObjectInRangeCheck check(player, player, 10.0f);
|
while (std::getline(ss, item, ','))
|
||||||
Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck> searcher(player, foundBobber, check);
|
|
||||||
player->VisitNearbyGridObject(10.0f, searcher);
|
|
||||||
|
|
||||||
if (!foundBobber)
|
|
||||||
return;
|
|
||||||
|
|
||||||
GameObject* go = foundBobber;
|
|
||||||
if (go->GetOwnerGUID() != player->GetGUID())
|
|
||||||
{
|
{
|
||||||
foundBobber = nullptr;
|
item.erase(0, item.find_first_not_of(" \t\r\n"));
|
||||||
return;
|
item.erase(item.find_last_not_of(" \t\r\n") + 1);
|
||||||
|
if (!item.empty())
|
||||||
|
out.push_back(uint32(std::stoul(item)));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (go->GetGoState() != GO_STATE_READY)
|
void TryAutoFish(Player* plr)
|
||||||
{
|
{
|
||||||
foundBobber = nullptr;
|
if (!plr || !plr->IsInWorld())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
player->SendLoot(go->GetGUID(), LOOT_FISHING);
|
std::list<GameObject*> nearList;
|
||||||
|
for (auto entry : sBobberEntries)
|
||||||
|
plr->GetGameObjectListWithEntryInGrid(nearList, entry, sScanRange);
|
||||||
|
|
||||||
|
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;
|
Loot* loot = &go->loot;
|
||||||
for (uint32 i = 0; i < loot->items.size(); ++i)
|
for (uint32 i = 0; i < loot->items.size(); ++i)
|
||||||
player->StoreLootItem(i, loot);
|
|
||||||
player->SendLootRelease(go->GetGUID());
|
|
||||||
|
|
||||||
foundBobber = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static GameObject* foundBobber;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameObject* mod_autofish_PlayerScript::foundBobber = nullptr;
|
|
||||||
|
|
||||||
class mod_autofish_WorldScript : public WorldScript
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
mod_autofish_WorldScript() : WorldScript("mod_autofish_WorldScript") {}
|
|
||||||
|
|
||||||
void OnGameObjectCreate(GameObject* go) override
|
|
||||||
{
|
{
|
||||||
if (go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
|
if (LootItem* li = loot->LootItemInSlot(i, plr))
|
||||||
lastBobber = go;
|
plr->AutoStoreLootItem(i, loot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GameObject* GetLastBobber() { return lastBobber; }
|
plr->SendLootRelease(go->GetGUID());
|
||||||
|
go->SetLootState(GO_JUST_DEACTIVATED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
class AutoFish_WorldScript : public WorldScript
|
||||||
static GameObject* lastBobber;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameObject* mod_autofish_WorldScript::lastBobber = nullptr;
|
|
||||||
|
|
||||||
class mod_autofish_GridNotifier : public Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
mod_autofish_GridNotifier(Player* p, GameObject*& result, Acore::GameObjectInRangeCheck const& check)
|
AutoFish_WorldScript() : WorldScript("AutoFish_WorldScript") {}
|
||||||
: Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck>(p, result, check) {}
|
|
||||||
|
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;
|
||||||
|
TryAutoFish(plr);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void Addmod_autofishScripts()
|
void AddSC_autofish_world()
|
||||||
{
|
{
|
||||||
new mod_autofish_PlayerScript();
|
new AutoFish_WorldScript();
|
||||||
new mod_autofish_WorldScript();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user