trying another method from mod-aoe-loot
This commit is contained in:
parent
ff4d63ef39
commit
d86112823b
@ -131,121 +131,129 @@ namespace
|
||||
{
|
||||
Loot *loot = &lootGo->loot;
|
||||
|
||||
// 1) Normal items
|
||||
for (uint32 slot = 0; slot < loot->items.size(); ++slot)
|
||||
for (uint8 slot = 0; slot < loot->items.size(); ++slot)
|
||||
{
|
||||
LootItem &li = loot->items[slot];
|
||||
if (li.is_looted)
|
||||
continue;
|
||||
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(uint8(slot), loot, msg);
|
||||
|
||||
if (!loot->quest_items.empty())
|
||||
{
|
||||
uint32 baseSlot = loot->items.size();
|
||||
for (uint32 q = 0; q < loot->quest_items.size(); ++q)
|
||||
{
|
||||
QuestItem &qi = loot->quest_items[q];
|
||||
if (qi.is_looted)
|
||||
continue;
|
||||
|
||||
uint8 slot = uint8(baseSlot + q);
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(slot, loot, msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (loot->gold > 0)
|
||||
{
|
||||
plr->ModifyMoney(loot->gold);
|
||||
loot->gold = 0;
|
||||
}
|
||||
|
||||
plr->SendLootRelease(lootGuid);
|
||||
|
||||
if (lootGo->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
|
||||
lootGo->SetLootState(GO_JUST_DEACTIVATED);
|
||||
plr->StoreLootItem(slot, loot, msg);
|
||||
}
|
||||
|
||||
const QuestItemMap &questItems = loot->GetPlayerQuestItems();
|
||||
if (!questItems.empty())
|
||||
{
|
||||
uint8 baseSlot = static_cast<uint8>(loot->items.size());
|
||||
for (uint8 i = 0; i < questItems.size(); ++i)
|
||||
{
|
||||
uint8 slot = baseSlot + i;
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(slot, loot, msg);
|
||||
}
|
||||
}
|
||||
|
||||
const QuestItemMap &ffaItems = loot->GetPlayerFFAItems();
|
||||
if (!ffaItems.empty())
|
||||
{
|
||||
for (uint8 i = 0; i < ffaItems.size(); ++i)
|
||||
{
|
||||
uint8 slot = i;
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(slot, loot, msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (loot->gold > 0)
|
||||
{
|
||||
plr->ModifyMoney(loot->gold);
|
||||
loot->gold = 0;
|
||||
}
|
||||
|
||||
plr->SendLootRelease(lootGuid);
|
||||
|
||||
if (lootGo->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
|
||||
lootGo->SetLootState(GO_JUST_DEACTIVATED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it = sLootTimers.erase(it);
|
||||
it = sLootTimers.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void TryAutoFish(Player *plr)
|
||||
{
|
||||
if (!plr || !plr->IsInWorld() || !RequirementMet(plr))
|
||||
return;
|
||||
|
||||
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 && go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
|
||||
{
|
||||
go->Use(plr);
|
||||
if (sServerAutoLoot)
|
||||
ScheduleAutoLoot(plr);
|
||||
ScheduleRecast(plr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TryAutoFish(Player * plr)
|
||||
class AutoFish_WorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AutoFish_WorldScript() : WorldScript("AutoFish_WorldScript") {}
|
||||
|
||||
void OnAfterConfigLoad(bool) override
|
||||
{
|
||||
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", 18248u);
|
||||
sAutoLootDelayMs = sConfigMgr->GetOption<uint32>("AutoFish.AutoLootDelayMs", 120u);
|
||||
sRequiredItemId = sConfigMgr->GetOption<uint32>("AutoFish.RequiredItemId", 0u);
|
||||
sRequiredEquipId = sConfigMgr->GetOption<uint32>("AutoFish.RequiredEquipId", 0u);
|
||||
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)
|
||||
{
|
||||
if (!plr || !plr->IsInWorld() || !RequirementMet(plr))
|
||||
return;
|
||||
|
||||
std::list<GameObject *> nearList;
|
||||
for (auto entry : sBobberEntries)
|
||||
plr->GetGameObjectListWithEntryInGrid(nearList, entry, sScanRange);
|
||||
|
||||
for (GameObject *go : nearList)
|
||||
acc = 0;
|
||||
auto const &players = ObjectAccessor::GetPlayers();
|
||||
for (auto const &kv : players)
|
||||
{
|
||||
if (!go || go->GetOwnerGUID() != plr->GetGUID())
|
||||
Player *plr = kv.second;
|
||||
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
||||
continue;
|
||||
|
||||
if (go->getLootState() == GO_READY && go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
|
||||
{
|
||||
go->Use(plr);
|
||||
if (sServerAutoLoot)
|
||||
ScheduleAutoLoot(plr);
|
||||
ScheduleRecast(plr);
|
||||
return;
|
||||
}
|
||||
TryAutoFish(plr);
|
||||
}
|
||||
}
|
||||
|
||||
TickAutoLoot(diff);
|
||||
TickRecast(diff);
|
||||
}
|
||||
};
|
||||
|
||||
class AutoFish_WorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AutoFish_WorldScript() : WorldScript("AutoFish_WorldScript") {}
|
||||
|
||||
void OnAfterConfigLoad(bool) override
|
||||
{
|
||||
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", 18248u);
|
||||
sAutoLootDelayMs = sConfigMgr->GetOption<uint32>("AutoFish.AutoLootDelayMs", 120u);
|
||||
sRequiredItemId = sConfigMgr->GetOption<uint32>("AutoFish.RequiredItemId", 0u);
|
||||
sRequiredEquipId = sConfigMgr->GetOption<uint32>("AutoFish.RequiredEquipId", 0u);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
TickAutoLoot(diff);
|
||||
TickRecast(diff);
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_autofish_world()
|
||||
{
|
||||
new AutoFish_WorldScript();
|
||||
}
|
||||
void AddSC_autofish_world()
|
||||
{
|
||||
new AutoFish_WorldScript();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user