2025-11-01 16:58:41 -07:00
|
|
|
#include "ScriptMgr.h"
|
|
|
|
|
#include "Player.h"
|
|
|
|
|
#include "GameObject.h"
|
2025-11-01 17:13:37 -07:00
|
|
|
#include "WorldSession.h"
|
2025-11-01 16:58:41 -07:00
|
|
|
#include "ObjectAccessor.h"
|
|
|
|
|
#include "CellImpl.h"
|
2025-11-01 17:13:37 -07:00
|
|
|
#include "GridNotifiers.h"
|
|
|
|
|
#include "GridNotifiersImpl.h"
|
|
|
|
|
#include "LootMgr.h"
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
class mod_autofish_PlayerScript : public PlayerScript
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:13:37 -07:00
|
|
|
public:
|
|
|
|
|
mod_autofish_PlayerScript() : PlayerScript("mod_autofish_PlayerScript") {}
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
void OnUpdate(Player* player, uint32) override
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:13:37 -07:00
|
|
|
if (!player->IsAlive() || player->IsInCombat() || player->GetMap()->IsBattlegroundOrArena())
|
|
|
|
|
return;
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
Acore::GameObjectInRangeCheck check(player, player, 10.0f);
|
|
|
|
|
Acore::GameObjectSearcher<Acore::GameObjectInRangeCheck> searcher(player, foundBobber, check);
|
|
|
|
|
player->VisitNearbyGridObject(10.0f, searcher);
|
|
|
|
|
|
|
|
|
|
if (!foundBobber)
|
2025-11-01 16:58:41 -07:00
|
|
|
return;
|
|
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
GameObject* go = foundBobber;
|
|
|
|
|
if (go->GetOwnerGUID() != player->GetGUID())
|
|
|
|
|
{
|
|
|
|
|
foundBobber = nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
if (go->GetGoState() != GO_STATE_READY)
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:13:37 -07:00
|
|
|
foundBobber = nullptr;
|
|
|
|
|
return;
|
2025-11-01 16:58:41 -07:00
|
|
|
}
|
2025-11-01 17:13:37 -07:00
|
|
|
|
|
|
|
|
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;
|
2025-11-01 16:58:41 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
private:
|
|
|
|
|
static GameObject* foundBobber;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GameObject* mod_autofish_PlayerScript::foundBobber = nullptr;
|
|
|
|
|
|
|
|
|
|
class mod_autofish_WorldScript : public WorldScript
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
|
|
|
|
public:
|
2025-11-01 17:13:37 -07:00
|
|
|
mod_autofish_WorldScript() : WorldScript("mod_autofish_WorldScript") {}
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
void OnGameObjectCreate(GameObject* go) override
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:13:37 -07:00
|
|
|
if (go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
|
|
|
|
|
lastBobber = go;
|
2025-11-01 16:58:41 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
static GameObject* GetLastBobber() { return lastBobber; }
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
private:
|
|
|
|
|
static GameObject* lastBobber;
|
|
|
|
|
};
|
2025-11-01 16:58:41 -07:00
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
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) {}
|
2025-11-01 16:58:41 -07:00
|
|
|
};
|
|
|
|
|
|
2025-11-01 17:13:37 -07:00
|
|
|
void Addmod_autofishScripts()
|
2025-11-01 16:58:41 -07:00
|
|
|
{
|
2025-11-01 17:13:37 -07:00
|
|
|
new mod_autofish_PlayerScript();
|
|
|
|
|
new mod_autofish_WorldScript();
|
2025-11-01 16:58:41 -07:00
|
|
|
}
|