Added catches for quest and money loot
This commit is contained in:
parent
4886019ca0
commit
ff4d63ef39
@ -25,14 +25,20 @@ namespace
|
||||
uint32 sRequiredEquipId = 0;
|
||||
std::vector<uint32> sBobberEntries;
|
||||
|
||||
struct GuidHash { std::size_t operator()(ObjectGuid const& g) const noexcept { return std::hash<uint64>()(g.GetRawValue()); } };
|
||||
struct GuidHash
|
||||
{
|
||||
std::size_t operator()(ObjectGuid const &g) const noexcept { return std::hash<uint64>()(g.GetRawValue()); }
|
||||
};
|
||||
|
||||
std::unordered_map<ObjectGuid, uint32, GuidHash> sRecastTimers;
|
||||
|
||||
struct PendingLoot { uint32 timer; };
|
||||
struct PendingLoot
|
||||
{
|
||||
uint32 timer;
|
||||
};
|
||||
std::unordered_map<ObjectGuid, PendingLoot, GuidHash> sLootTimers;
|
||||
|
||||
std::vector<uint32> ParseEntryList(std::string const& csv)
|
||||
std::vector<uint32> ParseEntryList(std::string const &csv)
|
||||
{
|
||||
std::vector<uint32> out;
|
||||
std::stringstream ss(csv);
|
||||
@ -47,21 +53,23 @@ namespace
|
||||
return out;
|
||||
}
|
||||
|
||||
bool HasEquippedItem(Player* plr, uint32 entry)
|
||||
bool HasEquippedItem(Player *plr, uint32 entry)
|
||||
{
|
||||
if (!entry) return true;
|
||||
if (!entry)
|
||||
return true;
|
||||
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
|
||||
{
|
||||
if (Item* it = plr->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
|
||||
if (Item *it = plr->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
|
||||
if (it->GetEntry() == entry)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RequirementMet(Player* plr)
|
||||
bool RequirementMet(Player *plr)
|
||||
{
|
||||
if (!plr) return false;
|
||||
if (!plr)
|
||||
return false;
|
||||
if (sRequiredItemId && !plr->HasItemCount(sRequiredItemId, 1, false))
|
||||
return false;
|
||||
if (sRequiredEquipId && !HasEquippedItem(plr, sRequiredEquipId))
|
||||
@ -69,18 +77,18 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScheduleRecast(Player* plr)
|
||||
void ScheduleRecast(Player *plr)
|
||||
{
|
||||
if (!sAutoRecast || !plr || !plr->IsInWorld())
|
||||
return;
|
||||
sRecastTimers[plr->GetGUID()] = sRecastDelayMs;
|
||||
}
|
||||
|
||||
void ScheduleAutoLoot(Player* plr)
|
||||
void ScheduleAutoLoot(Player *plr)
|
||||
{
|
||||
if (!sServerAutoLoot || !plr)
|
||||
return;
|
||||
sLootTimers[plr->GetGUID()] = PendingLoot{ sAutoLootDelayMs };
|
||||
sLootTimers[plr->GetGUID()] = PendingLoot{sAutoLootDelayMs};
|
||||
}
|
||||
|
||||
void TickRecast(uint32 diff)
|
||||
@ -94,7 +102,7 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
Player* plr = ObjectAccessor::FindPlayer(it->first);
|
||||
Player *plr = ObjectAccessor::FindPlayer(it->first);
|
||||
if (plr && plr->IsInWorld() && plr->IsAlive() && !plr->IsInCombat() && RequirementMet(plr))
|
||||
plr->CastSpell(plr, sRecastSpell, true);
|
||||
it = sRecastTimers.erase(it);
|
||||
@ -113,23 +121,49 @@ namespace
|
||||
continue;
|
||||
}
|
||||
|
||||
Player* plr = ObjectAccessor::FindPlayer(it->first);
|
||||
Player *plr = ObjectAccessor::FindPlayer(it->first);
|
||||
if (plr && plr->IsInWorld() && RequirementMet(plr))
|
||||
{
|
||||
ObjectGuid lootGuid = plr->GetLootGUID();
|
||||
if (lootGuid.IsGameObject())
|
||||
{
|
||||
if (GameObject* lootGo = ObjectAccessor::GetGameObject(*plr, lootGuid))
|
||||
if (GameObject *lootGo = ObjectAccessor::GetGameObject(*plr, lootGuid))
|
||||
{
|
||||
Loot* loot = &lootGo->loot;
|
||||
for (uint32 i = 0; i < loot->items.size(); ++i)
|
||||
Loot *loot = &lootGo->loot;
|
||||
|
||||
// 1) Normal items
|
||||
for (uint32 slot = 0; slot < loot->items.size(); ++slot)
|
||||
{
|
||||
if (loot->items[i].is_looted)
|
||||
LootItem &li = loot->items[slot];
|
||||
if (li.is_looted)
|
||||
continue;
|
||||
|
||||
InventoryResult msg = EQUIP_ERR_OK;
|
||||
plr->StoreLootItem(uint8(i), loot, msg);
|
||||
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);
|
||||
}
|
||||
@ -140,16 +174,16 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void TryAutoFish(Player* plr)
|
||||
void TryAutoFish(Player * plr)
|
||||
{
|
||||
if (!plr || !plr->IsInWorld() || !RequirementMet(plr))
|
||||
return;
|
||||
|
||||
std::list<GameObject*> nearList;
|
||||
std::list<GameObject *> nearList;
|
||||
for (auto entry : sBobberEntries)
|
||||
plr->GetGameObjectListWithEntryInGrid(nearList, entry, sScanRange);
|
||||
|
||||
for (GameObject* go : nearList)
|
||||
for (GameObject *go : nearList)
|
||||
{
|
||||
if (!go || go->GetOwnerGUID() != plr->GetGUID())
|
||||
continue;
|
||||
@ -164,11 +198,11 @@ namespace
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AutoFish_WorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
class AutoFish_WorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AutoFish_WorldScript() : WorldScript("AutoFish_WorldScript") {}
|
||||
|
||||
void OnAfterConfigLoad(bool) override
|
||||
@ -196,10 +230,10 @@ public:
|
||||
if (acc >= sTickMs)
|
||||
{
|
||||
acc = 0;
|
||||
auto const& players = ObjectAccessor::GetPlayers();
|
||||
for (auto const& kv : players)
|
||||
auto const &players = ObjectAccessor::GetPlayers();
|
||||
for (auto const &kv : players)
|
||||
{
|
||||
Player* plr = kv.second;
|
||||
Player *plr = kv.second;
|
||||
if (!plr || !plr->IsInWorld() || plr->IsGameMaster())
|
||||
continue;
|
||||
TryAutoFish(plr);
|
||||
@ -209,9 +243,9 @@ public:
|
||||
TickAutoLoot(diff);
|
||||
TickRecast(diff);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
void AddSC_autofish_world()
|
||||
{
|
||||
void AddSC_autofish_world()
|
||||
{
|
||||
new AutoFish_WorldScript();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user