adding auto recast to keep fishing
This commit is contained in:
parent
cbd6a7c628
commit
a943ae6a59
@ -8,3 +8,7 @@ AutoFish.ScanRange = 30.0
|
|||||||
AutoFish.BobberEntries = 35591
|
AutoFish.BobberEntries = 35591
|
||||||
# Automatically loot fish
|
# Automatically loot fish
|
||||||
AutoFish.ServerAutoLoot = 1
|
AutoFish.ServerAutoLoot = 1
|
||||||
|
# Automatically Recast the fishing line
|
||||||
|
AutoFish.AutoRecast = 1
|
||||||
|
AutoFish.RecastDelayMs = 500
|
||||||
|
AutoFish.RecastSpell = 131474
|
||||||
|
|||||||
@ -9,15 +9,22 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
bool sEnabled = true;
|
bool sEnabled = true;
|
||||||
bool sServerAutoLoot = true;
|
bool sServerAutoLoot = true;
|
||||||
|
bool sAutoRecast = true;
|
||||||
uint32 sTickMs = 200;
|
uint32 sTickMs = 200;
|
||||||
float sScanRange = 30.0f;
|
float sScanRange = 30.0f;
|
||||||
|
uint32 sRecastDelayMs = 500;
|
||||||
|
uint32 sRecastSpell = 131474;
|
||||||
std::vector<uint32> sBobberEntries;
|
std::vector<uint32> sBobberEntries;
|
||||||
|
|
||||||
|
struct GuidHash { std::size_t operator()(ObjectGuid const& g) const noexcept { return std::hash<uint64>()(g.GetRawValue()); } };
|
||||||
|
std::unordered_map<ObjectGuid, uint32, GuidHash> sRecastTimers;
|
||||||
|
|
||||||
std::vector<uint32> ParseEntryList(std::string const& csv)
|
std::vector<uint32> ParseEntryList(std::string const& csv)
|
||||||
{
|
{
|
||||||
std::vector<uint32> out;
|
std::vector<uint32> out;
|
||||||
@ -33,6 +40,32 @@ namespace
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScheduleRecast(Player* plr)
|
||||||
|
{
|
||||||
|
if (!sAutoRecast || !plr || !plr->IsInWorld())
|
||||||
|
return;
|
||||||
|
sRecastTimers[plr->GetGUID()] = sRecastDelayMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TickRecast(uint32 diff)
|
||||||
|
{
|
||||||
|
for (auto it = sRecastTimers.begin(); it != sRecastTimers.end();)
|
||||||
|
{
|
||||||
|
if (it->second > diff)
|
||||||
|
{
|
||||||
|
it->second -= diff;
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Player* plr = ObjectAccessor::FindPlayer(it->first);
|
||||||
|
if (plr && plr->IsInWorld() && plr->IsAlive() && !plr->IsInCombat())
|
||||||
|
plr->CastSpell(plr, sRecastSpell, true);
|
||||||
|
it = sRecastTimers.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TryAutoFish(Player* plr)
|
void TryAutoFish(Player* plr)
|
||||||
{
|
{
|
||||||
if (!plr || !plr->IsInWorld())
|
if (!plr || !plr->IsInWorld())
|
||||||
@ -61,11 +94,11 @@ namespace
|
|||||||
InventoryResult msg = EQUIP_ERR_OK;
|
InventoryResult msg = EQUIP_ERR_OK;
|
||||||
plr->StoreLootItem(uint8(i), loot, msg);
|
plr->StoreLootItem(uint8(i), loot, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
plr->SendLootRelease(go->GetGUID());
|
plr->SendLootRelease(go->GetGUID());
|
||||||
go->SetLootState(GO_JUST_DEACTIVATED);
|
go->SetLootState(GO_JUST_DEACTIVATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScheduleRecast(plr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,8 +114,11 @@ public:
|
|||||||
{
|
{
|
||||||
sEnabled = sConfigMgr->GetOption<bool>("AutoFish.Enabled", true);
|
sEnabled = sConfigMgr->GetOption<bool>("AutoFish.Enabled", true);
|
||||||
sServerAutoLoot = sConfigMgr->GetOption<bool>("AutoFish.ServerAutoLoot", true);
|
sServerAutoLoot = sConfigMgr->GetOption<bool>("AutoFish.ServerAutoLoot", true);
|
||||||
|
sAutoRecast = sConfigMgr->GetOption<bool>("AutoFish.AutoRecast", true);
|
||||||
sTickMs = sConfigMgr->GetOption<uint32>("AutoFish.TickMs", 200u);
|
sTickMs = sConfigMgr->GetOption<uint32>("AutoFish.TickMs", 200u);
|
||||||
sScanRange = sConfigMgr->GetOption<float>("AutoFish.ScanRange", 30.0f);
|
sScanRange = sConfigMgr->GetOption<float>("AutoFish.ScanRange", 30.0f);
|
||||||
|
sRecastDelayMs = sConfigMgr->GetOption<uint32>("AutoFish.RecastDelayMs", 500u);
|
||||||
|
sRecastSpell = sConfigMgr->GetOption<uint32>("AutoFish.RecastSpell", 131474u);
|
||||||
sBobberEntries = ParseEntryList(sConfigMgr->GetOption<std::string>("AutoFish.BobberEntries", "35591"));
|
sBobberEntries = ParseEntryList(sConfigMgr->GetOption<std::string>("AutoFish.BobberEntries", "35591"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,18 +129,20 @@ public:
|
|||||||
|
|
||||||
static uint32 acc = 0;
|
static uint32 acc = 0;
|
||||||
acc += diff;
|
acc += diff;
|
||||||
if (acc < sTickMs)
|
if (acc >= sTickMs)
|
||||||
return;
|
|
||||||
acc = 0;
|
|
||||||
|
|
||||||
auto const& players = ObjectAccessor::GetPlayers();
|
|
||||||
for (auto const& kv : players)
|
|
||||||
{
|
{
|
||||||
Player* plr = kv.second;
|
acc = 0;
|
||||||
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
auto const& players = ObjectAccessor::GetPlayers();
|
||||||
continue;
|
for (auto const& kv : players)
|
||||||
TryAutoFish(plr);
|
{
|
||||||
|
Player* plr = kv.second;
|
||||||
|
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
||||||
|
continue;
|
||||||
|
TryAutoFish(plr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TickRecast(diff);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user