#include "ScriptMgr.h" #include "Player.h" #include "GameObject.h" #include "WorldSession.h" #include "ObjectAccessor.h" #include "CellImpl.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "LootMgr.h" class mod_autofish_PlayerScript : public PlayerScript { public: mod_autofish_PlayerScript() : PlayerScript("mod_autofish_PlayerScript") {} void OnUpdate(Player* player, uint32) override { if (!player->IsAlive() || player->IsInCombat() || player->GetMap()->IsBattlegroundOrArena()) return; Acore::GameObjectInRangeCheck check(player, player, 10.0f); Acore::GameObjectSearcher searcher(player, foundBobber, check); player->VisitNearbyGridObject(10.0f, searcher); if (!foundBobber) return; GameObject* go = foundBobber; if (go->GetOwnerGUID() != player->GetGUID()) { 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; }; 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) lastBobber = go; } static GameObject* GetLastBobber() { return lastBobber; } private: static GameObject* lastBobber; }; GameObject* mod_autofish_WorldScript::lastBobber = nullptr; class mod_autofish_GridNotifier : public Acore::GameObjectSearcher { public: mod_autofish_GridNotifier(Player* p, GameObject*& result, Acore::GameObjectInRangeCheck const& check) : Acore::GameObjectSearcher(p, result, check) {} }; void Addmod_autofishScripts() { new mod_autofish_PlayerScript(); new mod_autofish_WorldScript(); }