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
|
||||
# Automatically loot fish
|
||||
AutoFish.ServerAutoLoot = 1
|
||||
# Automatically Recast the fishing line
|
||||
AutoFish.AutoRecast = 1
|
||||
AutoFish.RecastDelayMs = 500
|
||||
AutoFish.RecastSpell = 131474
|
||||
|
||||
@ -9,15 +9,22 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool sEnabled = true;
|
||||
bool sServerAutoLoot = true;
|
||||
bool sAutoRecast = true;
|
||||
uint32 sTickMs = 200;
|
||||
float sScanRange = 30.0f;
|
||||
uint32 sRecastDelayMs = 500;
|
||||
uint32 sRecastSpell = 131474;
|
||||
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> out;
|
||||
@ -33,6 +40,32 @@ namespace
|
||||
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)
|
||||
{
|
||||
if (!plr || !plr->IsInWorld())
|
||||
@ -61,11 +94,11 @@ namespace
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(uint8(i), loot, msg);
|
||||
}
|
||||
|
||||
plr->SendLootRelease(go->GetGUID());
|
||||
go->SetLootState(GO_JUST_DEACTIVATED);
|
||||
}
|
||||
|
||||
ScheduleRecast(plr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -81,8 +114,11 @@ public:
|
||||
{
|
||||
sEnabled = sConfigMgr->GetOption<bool>("AutoFish.Enabled", true);
|
||||
sServerAutoLoot = sConfigMgr->GetOption<bool>("AutoFish.ServerAutoLoot", true);
|
||||
sAutoRecast = sConfigMgr->GetOption<bool>("AutoFish.AutoRecast", true);
|
||||
sTickMs = sConfigMgr->GetOption<uint32>("AutoFish.TickMs", 200u);
|
||||
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"));
|
||||
}
|
||||
|
||||
@ -93,10 +129,9 @@ public:
|
||||
|
||||
static uint32 acc = 0;
|
||||
acc += diff;
|
||||
if (acc < sTickMs)
|
||||
return;
|
||||
if (acc >= sTickMs)
|
||||
{
|
||||
acc = 0;
|
||||
|
||||
auto const& players = ObjectAccessor::GetPlayers();
|
||||
for (auto const& kv : players)
|
||||
{
|
||||
@ -106,6 +141,9 @@ public:
|
||||
TryAutoFish(plr);
|
||||
}
|
||||
}
|
||||
|
||||
TickRecast(diff);
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_autofish_world()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user