Core/Pools: Implemented quest pooling

Core/DBLayer: Added GetNumRows() method to PreparedResultSet

--HG--
branch : trunk
This commit is contained in:
Shauren
2010-09-14 13:56:27 +02:00
parent cdd8f446fa
commit 102e51d620
10 changed files with 515 additions and 59 deletions
+21 -13
View File
@@ -48,6 +48,7 @@
#include "DisableMgr.h"
#include "ScriptMgr.h"
#include "SpellScript.h"
#include "PoolMgr.h"
ScriptMapMap sQuestEndScripts;
ScriptMapMap sQuestStartScripts;
@@ -7331,13 +7332,13 @@ void ObjectMgr::DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_
cell_guids.corpses.erase(player_guid);
}
void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map,char const* table)
void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map, std::string table, bool starter, bool go)
{
map.clear(); // need for reload case
uint32 count = 0;
QueryResult result = WorldDatabase.PQuery("SELECT id,quest FROM %s",table);
QueryResult result = WorldDatabase.PQuery("SELECT id, quest, pool_entry FROM %s qr LEFT JOIN pool_quest pq ON qr.quest = pq.entry", table.c_str());
if (!result)
{
@@ -7346,38 +7347,45 @@ void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map,char const* table)
bar.step();
sLog.outString();
sLog.outErrorDb(">> Loaded 0 quest relations from %s. DB table `%s` is empty.",table,table);
sLog.outErrorDb(">> Loaded 0 quest relations from %s, table is empty.", table.c_str());
return;
}
barGoLink bar(result->GetRowCount());
PooledQuestRelation* poolRelationMap = go ? &sPoolMgr.mQuestGORelation : &sPoolMgr.mQuestCreatureRelation;
if (starter)
poolRelationMap->clear();
do
{
Field *fields = result->Fetch();
bar.step();
uint32 id = fields[0].GetUInt32();
uint32 quest = fields[1].GetUInt32();
uint32 id = result->Fetch()[0].GetUInt32();
uint32 quest = result->Fetch()[1].GetUInt32();
uint32 poolId = result->Fetch()[2].GetUInt32();
if (mQuestTemplates.find(quest) == mQuestTemplates.end())
{
sLog.outErrorDb("Table `%s: Quest %u listed for entry %u does not exist.",table,quest,id);
sLog.outErrorDb("Table `%s: Quest %u listed for entry %u does not exist.", table.c_str(), quest, id);
continue;
}
map.insert(QuestRelations::value_type(id,quest));
if (!poolId || !starter)
map.insert(QuestRelations::value_type(id, quest));
else if (starter)
poolRelationMap->insert(PooledQuestRelation::value_type(quest, id));
++count;
} while (result->NextRow());
sLog.outString();
sLog.outString(">> Loaded %u quest relations from %s", count,table);
sLog.outString(">> Loaded %u quest relations from %s", count, table.c_str());
}
void ObjectMgr::LoadGameobjectQuestRelations()
{
LoadQuestRelationsHelper(mGOQuestRelations,"gameobject_questrelation");
LoadQuestRelationsHelper(mGOQuestRelations, "gameobject_questrelation", true, true);
for (QuestRelations::iterator itr = mGOQuestRelations.begin(); itr != mGOQuestRelations.end(); ++itr)
{
@@ -7391,7 +7399,7 @@ void ObjectMgr::LoadGameobjectQuestRelations()
void ObjectMgr::LoadGameobjectInvolvedRelations()
{
LoadQuestRelationsHelper(mGOQuestInvolvedRelations,"gameobject_involvedrelation");
LoadQuestRelationsHelper(mGOQuestInvolvedRelations, "gameobject_involvedrelation", false, true);
for (QuestRelations::iterator itr = mGOQuestInvolvedRelations.begin(); itr != mGOQuestInvolvedRelations.end(); ++itr)
{
@@ -7405,7 +7413,7 @@ void ObjectMgr::LoadGameobjectInvolvedRelations()
void ObjectMgr::LoadCreatureQuestRelations()
{
LoadQuestRelationsHelper(mCreatureQuestRelations,"creature_questrelation");
LoadQuestRelationsHelper(mCreatureQuestRelations, "creature_questrelation", true, false);
for (QuestRelations::iterator itr = mCreatureQuestRelations.begin(); itr != mCreatureQuestRelations.end(); ++itr)
{
@@ -7419,7 +7427,7 @@ void ObjectMgr::LoadCreatureQuestRelations()
void ObjectMgr::LoadCreatureInvolvedRelations()
{
LoadQuestRelationsHelper(mCreatureQuestInvolvedRelations,"creature_involvedrelation");
LoadQuestRelationsHelper(mCreatureQuestInvolvedRelations, "creature_involvedrelation", false, false);
for (QuestRelations::iterator itr = mCreatureQuestInvolvedRelations.begin(); itr != mCreatureQuestInvolvedRelations.end(); ++itr)
{
+1 -1
View File
@@ -1086,7 +1086,7 @@ class ObjectMgr
void CheckScripts(ScriptsType type, std::set<int32>& ids);
void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment);
void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
void LoadQuestRelationsHelper(QuestRelations& map, std::string table, bool starter, bool go);
void PlayerCreateInfoAddItemHelper(uint32 race_, uint32 class_, uint32 itemId, int32 count);
MailLevelRewardMap m_mailLevelRewardMap;
+366 -27
View File
@@ -23,59 +23,73 @@
#include "MapManager.h"
////////////////////////////////////////////////////////////
// template class SpawnedPoolData
// template class ActivePoolData
// Method that tell amount spawned objects/subpools
uint32 SpawnedPoolData::GetSpawnedObjects(uint32 pool_id) const
uint32 ActivePoolData::GetActiveObjectCount(uint32 pool_id) const
{
SpawnedPoolPools::const_iterator itr = mSpawnedPools.find(pool_id);
ActivePoolPools::const_iterator itr = mSpawnedPools.find(pool_id);
return itr != mSpawnedPools.end() ? itr->second : 0;
}
// Method that tell if a creature is spawned currently
template<>
bool SpawnedPoolData::IsSpawnedObject<Creature>(uint32 db_guid) const
bool ActivePoolData::IsActiveObject<Creature>(uint32 db_guid) const
{
return mSpawnedCreatures.find(db_guid) != mSpawnedCreatures.end();
}
// Method that tell if a gameobject is spawned currently
template<>
bool SpawnedPoolData::IsSpawnedObject<GameObject>(uint32 db_guid) const
bool ActivePoolData::IsActiveObject<GameObject>(uint32 db_guid) const
{
return mSpawnedGameobjects.find(db_guid) != mSpawnedGameobjects.end();
}
// Method that tell if a quest can be started
template<>
bool ActivePoolData::IsActiveObject<Quest>(uint32 quest_id) const
{
return mActiveQuests.find(quest_id) != mActiveQuests.end();
}
// Method that tell if a pool is spawned currently
template<>
bool SpawnedPoolData::IsSpawnedObject<Pool>(uint32 sub_pool_id) const
bool ActivePoolData::IsActiveObject<Pool>(uint32 sub_pool_id) const
{
return mSpawnedPools.find(sub_pool_id) != mSpawnedPools.end();
}
template<>
void SpawnedPoolData::AddSpawn<Creature>(uint32 db_guid, uint32 pool_id)
void ActivePoolData::ActivateObject<Creature>(uint32 db_guid, uint32 pool_id)
{
mSpawnedCreatures.insert(db_guid);
++mSpawnedPools[pool_id];
}
template<>
void SpawnedPoolData::AddSpawn<GameObject>(uint32 db_guid, uint32 pool_id)
void ActivePoolData::ActivateObject<GameObject>(uint32 db_guid, uint32 pool_id)
{
mSpawnedGameobjects.insert(db_guid);
++mSpawnedPools[pool_id];
}
template<>
void SpawnedPoolData::AddSpawn<Pool>(uint32 sub_pool_id, uint32 pool_id)
void ActivePoolData::ActivateObject<Quest>(uint32 quest_id, uint32 pool_id)
{
mActiveQuests.insert(quest_id);
++mSpawnedPools[pool_id];
}
template<>
void ActivePoolData::ActivateObject<Pool>(uint32 sub_pool_id, uint32 pool_id)
{
mSpawnedPools[sub_pool_id] = 0;
++mSpawnedPools[pool_id];
}
template<>
void SpawnedPoolData::RemoveSpawn<Creature>(uint32 db_guid, uint32 pool_id)
void ActivePoolData::RemoveObject<Creature>(uint32 db_guid, uint32 pool_id)
{
mSpawnedCreatures.erase(db_guid);
uint32& val = mSpawnedPools[pool_id];
@@ -84,7 +98,7 @@ void SpawnedPoolData::RemoveSpawn<Creature>(uint32 db_guid, uint32 pool_id)
}
template<>
void SpawnedPoolData::RemoveSpawn<GameObject>(uint32 db_guid, uint32 pool_id)
void ActivePoolData::RemoveObject<GameObject>(uint32 db_guid, uint32 pool_id)
{
mSpawnedGameobjects.erase(db_guid);
uint32& val = mSpawnedPools[pool_id];
@@ -93,7 +107,16 @@ void SpawnedPoolData::RemoveSpawn<GameObject>(uint32 db_guid, uint32 pool_id)
}
template<>
void SpawnedPoolData::RemoveSpawn<Pool>(uint32 sub_pool_id, uint32 pool_id)
void ActivePoolData::RemoveObject<Quest>(uint32 quest_id, uint32 pool_id)
{
mActiveQuests.erase(quest_id);
uint32& val = mSpawnedPools[pool_id];
if (val > 0)
--val;
}
template<>
void ActivePoolData::RemoveObject<Pool>(uint32 sub_pool_id, uint32 pool_id)
{
mSpawnedPools.erase(sub_pool_id);
uint32& val = mSpawnedPools[pool_id];
@@ -130,18 +153,18 @@ bool PoolGroup<T>::CheckPool() const
}
template <class T>
PoolObject* PoolGroup<T>::RollOne(SpawnedPoolData& spawns, uint32 triggerFrom)
PoolObject* PoolGroup<T>::RollOne(ActivePoolData& spawns, uint32 triggerFrom)
{
if (!ExplicitlyChanced.empty())
{
float roll = (float)rand_chance();
for (uint32 i=0; i<ExplicitlyChanced.size(); ++i)
for (uint32 i = 0; i < ExplicitlyChanced.size(); ++i)
{
roll -= ExplicitlyChanced[i].chance;
// Triggering object is marked as spawned at this time and can be also rolled (respawn case)
// so this need explicit check for this case
if (roll < 0 && (ExplicitlyChanced[i].guid == triggerFrom || !spawns.IsSpawnedObject<T>(ExplicitlyChanced[i].guid)))
if (roll < 0 && (ExplicitlyChanced[i].guid == triggerFrom || !spawns.IsActiveObject<T>(ExplicitlyChanced[i].guid)))
return &ExplicitlyChanced[i];
}
}
@@ -150,7 +173,7 @@ PoolObject* PoolGroup<T>::RollOne(SpawnedPoolData& spawns, uint32 triggerFrom)
int32 index = irand(0, EqualChanced.size()-1);
// Triggering object is marked as spawned at this time and can be also rolled (respawn case)
// so this need explicit check for this case
if (EqualChanced[index].guid == triggerFrom || !spawns.IsSpawnedObject<T>(EqualChanced[index].guid))
if (EqualChanced[index].guid == triggerFrom || !spawns.IsActiveObject<T>(EqualChanced[index].guid))
return &EqualChanced[index];
}
@@ -161,17 +184,17 @@ PoolObject* PoolGroup<T>::RollOne(SpawnedPoolData& spawns, uint32 triggerFrom)
// If no guid is passed, the pool is just removed (event end case)
// If guid is filled, cache will be used and no removal will occur, it just fill the cache
template<class T>
void PoolGroup<T>::DespawnObject(SpawnedPoolData& spawns, uint32 guid)
void PoolGroup<T>::DespawnObject(ActivePoolData& spawns, uint32 guid)
{
for (size_t i=0; i<EqualChanced.size(); ++i)
for (size_t i=0; i < EqualChanced.size(); ++i)
{
// if spawned
if (spawns.IsSpawnedObject<T>(EqualChanced[i].guid))
if (spawns.IsActiveObject<T>(EqualChanced[i].guid))
{
if (!guid || EqualChanced[i].guid == guid)
{
Despawn1Object(EqualChanced[i].guid);
spawns.RemoveSpawn<T>(EqualChanced[i].guid,poolId);
spawns.RemoveObject<T>(EqualChanced[i].guid,poolId);
}
}
}
@@ -179,12 +202,12 @@ void PoolGroup<T>::DespawnObject(SpawnedPoolData& spawns, uint32 guid)
for (size_t i = 0; i < ExplicitlyChanced.size(); ++i)
{
// spawned
if (spawns.IsSpawnedObject<T>(ExplicitlyChanced[i].guid))
if (spawns.IsActiveObject<T>(ExplicitlyChanced[i].guid))
{
if (!guid || ExplicitlyChanced[i].guid == guid)
{
Despawn1Object(ExplicitlyChanced[i].guid);
spawns.RemoveSpawn<T>(ExplicitlyChanced[i].guid,poolId);
spawns.RemoveObject<T>(ExplicitlyChanced[i].guid,poolId);
}
}
}
@@ -216,6 +239,49 @@ void PoolGroup<GameObject>::Despawn1Object(uint32 guid)
}
}
// Same on one quest
template<>
void PoolGroup<Quest>::Despawn1Object(uint32 quest_id)
{
// Creatures
QuestRelations* questMap = sObjectMgr.GetCreatureQuestRelationMap();
PooledQuestRelationBoundsNC qr = sPoolMgr.mQuestCreatureRelation.equal_range(quest_id);
for (PooledQuestRelation::iterator itr = qr.first; itr != qr.second; ++itr)
{
QuestRelations::iterator qitr = questMap->find(itr->second);
if (qitr == questMap->end())
continue;
QuestRelations::iterator lastElement = questMap->upper_bound(itr->second);
for (; qitr != lastElement; ++qitr)
{
if (qitr->first == itr->second)
{
questMap->erase(qitr); // iterator is now no more valid
break; // but we can exit loop since the element is found
}
}
}
// Gameobjects
questMap = sObjectMgr.GetGOQuestRelationMap();
qr = sPoolMgr.mQuestGORelation.equal_range(quest_id);
for (PooledQuestRelation::iterator itr = qr.first; itr != qr.second; ++itr)
{
QuestRelations::iterator qitr = questMap->find(itr->second);
if (qitr == questMap->end())
continue;
QuestRelations::iterator lastElement = questMap->upper_bound(itr->second);
for (; qitr != lastElement; ++qitr)
{
if (qitr->first == itr->second)
{
questMap->erase(qitr); // iterator is now no more valid
break; // but we can exit loop since the element is found
}
}
}
}
// Same on one pool
template<>
void PoolGroup<Pool>::Despawn1Object(uint32 child_pool_id)
@@ -246,10 +312,10 @@ void PoolGroup<Pool>::RemoveOneRelation(uint32 child_pool_id)
}
template <class T>
void PoolGroup<T>::SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 triggerFrom)
void PoolGroup<T>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom)
{
uint32 lastDespawned = 0;
int count = limit - spawns.GetSpawnedObjects(poolId);
int count = limit - spawns.GetActiveObjectCount(poolId);
// If triggered from some object respawn this object is still marked as spawned
// and also counted into m_SpawnedPoolAmount so we need increase count to be
@@ -260,7 +326,7 @@ void PoolGroup<T>::SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 tri
// This will try to spawn the rest of pool, not guaranteed
for (int i = 0; i < count; ++i)
{
PoolObject* obj = RollOne(spawns,triggerFrom);
PoolObject* obj = RollOne(spawns, triggerFrom);
if (!obj)
continue;
if (obj->guid == lastDespawned)
@@ -272,7 +338,7 @@ void PoolGroup<T>::SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 tri
triggerFrom = 0;
continue;
}
spawns.AddSpawn<T>(obj->guid,poolId);
spawns.ActivateObject<T>(obj->guid, poolId);
Spawn1Object(obj);
if (triggerFrom)
@@ -285,6 +351,73 @@ void PoolGroup<T>::SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 tri
}
}
template <>
void PoolGroup<Quest>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom)
{
sLog.outDebug("PoolGroup<Quest>: Spawning pool %u", poolId);
// load state from db
if (!triggerFrom)
{
QueryResult result = CharacterDatabase.PQuery("SELECT quest_id FROM pool_quest_save WHERE pool_id = %u", poolId);
if (result)
{
do
{
uint32 questId = result->Fetch()[0].GetUInt32();
spawns.ActivateObject<Quest>(questId, poolId);
PoolObject tempObj(questId, 0.0f);
Spawn1Object(&tempObj);
--limit;
} while (result->NextRow() && limit);
return;
}
}
uint32 lastDespawned = 0;
ActivePoolObjects currentQuests = spawns.GetActiveQuests();
ActivePoolObjects newQuests;
// always try to select different quests
for (PoolObjectList::iterator itr = EqualChanced.begin(); itr != EqualChanced.end(); ++itr)
{
if (spawns.IsActiveObject<Quest>(itr->guid))
continue;
newQuests.insert(itr->guid);
}
// clear the pool
DespawnObject(spawns);
// recycle minimal amount of quests if possible count is lower than limit
if (limit > newQuests.size() && !currentQuests.empty())
{
do
{
ActivePoolObjects::iterator itr = currentQuests.begin();
std::advance(itr, urand(0, currentQuests.size()-1));
newQuests.insert(*itr);
} while (newQuests.size() < limit);
}
if (newQuests.empty())
return;
// activate <limit> random quests
do
{
ActivePoolObjects::iterator itr = newQuests.begin();
std::advance(itr, urand(0, newQuests.size()-1));
spawns.ActivateObject<Quest>(*itr, poolId);
PoolObject tempObj(*itr, 0.0f);
Spawn1Object(&tempObj);
newQuests.erase(itr);
--limit;
} while (limit && newQuests.size());
// if we are here it means the pool is initialized at startup and did not have previous saved state
if (!triggerFrom)
sPoolMgr.SaveQuestsToDB();
}
// Method that is actualy doing the spawn job on 1 creature
template <>
void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
@@ -340,6 +473,29 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
}
}
// Same for 1 quest
template<>
void PoolGroup<Quest>::Spawn1Object(PoolObject* obj)
{
// Creatures
QuestRelations* questMap = sObjectMgr.GetCreatureQuestRelationMap();
PooledQuestRelationBoundsNC qr = sPoolMgr.mQuestCreatureRelation.equal_range(obj->guid);
for (PooledQuestRelation::iterator itr = qr.first; itr != qr.second; ++itr)
{
sLog.outDebug("PoolGroup<Quest>: Adding quest %u to creature %u", itr->first, itr->second);
questMap->insert(QuestRelations::value_type(itr->second, itr->first));
}
// Gameobjects
questMap = sObjectMgr.GetGOQuestRelationMap();
qr = sPoolMgr.mQuestGORelation.equal_range(obj->guid);
for (PooledQuestRelation::iterator itr = qr.first; itr != qr.second; ++itr)
{
sLog.outDebug("PoolGroup<Quest>: Adding quest %u to GO %u", itr->first, itr->second);
questMap->insert(QuestRelations::value_type(itr->second, itr->first));
}
}
// Same for 1 pool
template <>
void PoolGroup<Pool>::Spawn1Object(PoolObject* obj)
@@ -365,6 +521,12 @@ void PoolGroup<GameObject>::ReSpawn1Object(PoolObject* obj)
pGameobject->GetMap()->Add(pGameobject);
}
// Nothing to do for a quest
template <>
void PoolGroup<Quest>::ReSpawn1Object(PoolObject* /*obj*/)
{
}
// Nothing to do for a child Pool
template <>
void PoolGroup<Pool>::ReSpawn1Object(PoolObject* /*obj*/)
@@ -653,6 +815,98 @@ void PoolMgr::LoadFromDB()
}
}
void PoolMgr::LoadQuestPools()
{
QueryResult result = WorldDatabase.Query("SELECT entry, pool_entry FROM pool_quest");
mQuestSearchMap.clear();
mPoolQuestGroups.resize(max_pool_id + 1);
uint32 count = 0;
if (!result)
{
barGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString(">> Loaded 0 quests in pools");
return;
}
barGoLink bar(result->GetRowCount());
PooledQuestRelationBounds creBounds;
PooledQuestRelationBounds goBounds;
enum eQuestTypes
{
QUEST_NONE = 0,
QUEST_DAILY = 1,
QUEST_WEEKLY = 2
} pooledType = QUEST_NONE;
do
{
Field* fields = result->Fetch();
bar.step();
uint32 entry = fields[0].GetUInt32();
uint32 pool_id = fields[1].GetUInt32();
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
if (!pQuest)
{
sLog.outErrorDb("`pool_quest` has a non existing quest template (Entry: %u) defined for pool id (%u), skipped.", entry, pool_id);
continue;
}
if (pool_id > max_pool_id)
{
sLog.outErrorDb("`pool_quest` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id);
continue;
}
if (!pQuest->IsDailyOrWeekly())
{
sLog.outErrorDb("`pool_quest` has an quest (%u) which is not daily or weekly in pool id (%u), use ExclusiveGroup instead, skipped.", entry, pool_id);
continue;
}
if (!pooledType)
pooledType = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY;
eQuestTypes currType = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY;
if (pooledType != currType)
{
sLog.outErrorDb("`pool_quest` quest %u is %s but pool (%u) is specified for %s, mixing not allowed, skipped.", entry, currType == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY", pool_id, pooledType == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY");
continue;
}
creBounds = mQuestCreatureRelation.equal_range(entry);
goBounds = mQuestGORelation.equal_range(entry);
if (creBounds.first == creBounds.second && goBounds.first == goBounds.second)
{
sLog.outErrorDb("`pool_quest` lists entry (%u) as member of pool (%u) but is not started anywhere, skipped.", entry, pool_id);
continue;
}
PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id];
++count;
PoolObject plObject = PoolObject(entry, 0.0f);
PoolGroup<Quest>& questgroup = mPoolQuestGroups[pool_id];
questgroup.SetPoolId(pool_id);
questgroup.AddEntry(plObject, pPoolTemplate->MaxLimit);
SearchPair p(entry, pool_id);
mQuestSearchMap.insert(p);
} while (result->NextRow());
sLog.outString();
sLog.outString(">> Loaded %u quests in pools", count);
}
// The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks
void PoolMgr::Initialize()
{
@@ -680,7 +934,7 @@ void PoolMgr::Initialize()
// Don't spawn child pools, they are spawned recursively by their parent pools
if (!pool_pool_id)
{
SpawnPool(pool_entry);;
SpawnPool(pool_entry);
count++;
}
} while (result->NextRow());
@@ -689,6 +943,77 @@ void PoolMgr::Initialize()
sLog.outBasic("Pool handling system initialized, %u pools spawned.", count);
}
void PoolMgr::SaveQuestsToDB()
{
SQLTransaction trans = CharacterDatabase.BeginTransaction();
std::ostringstream query;
query << "DELETE FROM pool_quest_save WHERE pool_id IN (";
bool first = true;
for (PoolGroupQuestMap::iterator itr = mPoolQuestGroups.begin(); itr != mPoolQuestGroups.end(); ++itr)
{
if (!first)
query << ",";
first = false;
query << itr->GetPoolId();
}
if (!first)
{
query << ")";
trans->Append(query.str().c_str());
}
first = true;
query.rdbuf()->str("");
query << "INSERT INTO pool_quest_save (pool_id, quest_id) VALUES ";
for (SearchMap::iterator itr = mQuestSearchMap.begin(); itr != mQuestSearchMap.end(); ++itr)
{
if (IsSpawnedObject<Quest>(itr->first))
{
if (!first)
query << ",";
first = false;
query << "(" << itr->second << "," << itr->first << ")";
}
}
if (!first)
trans->Append(query.str().c_str());
CharacterDatabase.CommitTransaction(trans);
}
void PoolMgr::ChangeDailyQuests()
{
for (PoolGroupQuestMap::iterator itr = mPoolQuestGroups.begin(); itr != mPoolQuestGroups.end(); ++itr)
{
if (Quest const* pQuest = sObjectMgr.GetQuestTemplate(itr->GetFirstEqualChancedObjectId()))
{
if (pQuest->IsWeekly())
continue;
UpdatePool<Quest>(itr->GetPoolId(), 1); // anything non-zero means don't load from db
}
}
SaveQuestsToDB();
}
void PoolMgr::ChangeWeeklyQuests()
{
for (PoolGroupQuestMap::iterator itr = mPoolQuestGroups.begin(); itr != mPoolQuestGroups.end(); ++itr)
{
if (Quest const* pQuest = sObjectMgr.GetQuestTemplate(itr->GetFirstEqualChancedObjectId()))
{
if (pQuest->IsDaily())
continue;
UpdatePool<Quest>(itr->GetPoolId(), 1);
}
}
SaveQuestsToDB();
}
// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different
// If it's same, the creature is respawned only (added back to map)
template<>
@@ -707,6 +1032,14 @@ void PoolMgr::SpawnPool<GameObject>(uint32 pool_id, uint32 db_guid)
mPoolGameobjectGroups[pool_id].SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, db_guid);
}
// Call to spawn a pool
template<>
void PoolMgr::SpawnPool<Quest>(uint32 pool_id, uint32 quest_id)
{
if (!mPoolQuestGroups[pool_id].isEmpty())
mPoolQuestGroups[pool_id].SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, quest_id);
}
// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different
// If it's same, the pool is respawned only
template<>
@@ -721,6 +1054,7 @@ void PoolMgr::SpawnPool(uint32 pool_id)
SpawnPool<Pool>(pool_id, 0);
SpawnPool<GameObject>(pool_id, 0);
SpawnPool<Creature>(pool_id, 0);
SpawnPool<Quest>(pool_id, 0);
}
// Call to despawn a pool, all gameobjects/creatures in this pool are removed
@@ -732,6 +1066,9 @@ void PoolMgr::DespawnPool(uint32 pool_id)
if (!mPoolGameobjectGroups[pool_id].isEmpty())
mPoolGameobjectGroups[pool_id].DespawnObject(mSpawnedData);
if (!mPoolQuestGroups[pool_id].isEmpty())
mPoolQuestGroups[pool_id].DespawnObject(mSpawnedData);
if (!mPoolPoolGroups[pool_id].isEmpty())
mPoolPoolGroups[pool_id].DespawnObject(mSpawnedData);
}
@@ -742,6 +1079,7 @@ bool PoolMgr::CheckPool(uint32 pool_id) const
return pool_id <= max_pool_id &&
mPoolGameobjectGroups[pool_id].CheckPool() &&
mPoolCreatureGroups[pool_id].CheckPool() &&
mPoolQuestGroups[pool_id].CheckPool() &&
mPoolPoolGroups[pool_id].CheckPool();
}
@@ -760,3 +1098,4 @@ void PoolMgr::UpdatePool(uint32 pool_id, uint32 db_guid_or_pool_id)
template void PoolMgr::UpdatePool<Pool>(uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<GameObject>(uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<Creature>(uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<Quest>(uint32 pool_id, uint32 db_guid_or_pool_id);
+52 -15
View File
@@ -23,6 +23,7 @@
#include <ace/Singleton.h>
#include "Creature.h"
#include "GameObject.h"
#include "QuestDef.h"
struct PoolTemplateData
{
@@ -40,26 +41,29 @@ class Pool // for Pool of Pool
{
};
typedef std::set<uint32> SpawnedPoolObjects;
typedef std::map<uint32,uint32> SpawnedPoolPools;
typedef std::set<uint32> ActivePoolObjects;
typedef std::map<uint32,uint32> ActivePoolPools;
class SpawnedPoolData
class ActivePoolData
{
public:
template<typename T>
bool IsSpawnedObject(uint32 db_guid_or_pool_id) const;
bool IsActiveObject(uint32 db_guid_or_pool_id) const;
uint32 GetSpawnedObjects(uint32 pool_id) const;
uint32 GetActiveObjectCount(uint32 pool_id) const;
template<typename T>
void AddSpawn(uint32 db_guid_or_pool_id, uint32 pool_id);
void ActivateObject(uint32 db_guid_or_pool_id, uint32 pool_id);
template<typename T>
void RemoveSpawn(uint32 db_guid_or_pool_id, uint32 pool_id);
void RemoveObject(uint32 db_guid_or_pool_id, uint32 pool_id);
ActivePoolObjects GetActiveQuests() { return mActiveQuests; } // a copy of the set
private:
SpawnedPoolObjects mSpawnedCreatures;
SpawnedPoolObjects mSpawnedGameobjects;
SpawnedPoolPools mSpawnedPools;
ActivePoolObjects mSpawnedCreatures;
ActivePoolObjects mSpawnedGameobjects;
ActivePoolObjects mActiveQuests;
ActivePoolPools mSpawnedPools;
};
template <class T>
@@ -73,20 +77,31 @@ class PoolGroup
bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
void AddEntry(PoolObject& poolitem, uint32 maxentries);
bool CheckPool() const;
PoolObject* RollOne(SpawnedPoolData& spawns, uint32 triggerFrom);
void DespawnObject(SpawnedPoolData& spawns, uint32 guid=0);
PoolObject* RollOne(ActivePoolData& spawns, uint32 triggerFrom);
void DespawnObject(ActivePoolData& spawns, uint32 guid=0);
void Despawn1Object(uint32 guid);
void SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 triggerFrom);
void SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom);
void Spawn1Object(PoolObject* obj);
void ReSpawn1Object(PoolObject* obj);
void RemoveOneRelation(uint32 child_pool_id);
uint32 GetFirstEqualChancedObjectId()
{
if (EqualChanced.empty())
return 0;
return EqualChanced.front().guid;
}
uint32 GetPoolId() const { return poolId; }
private:
uint32 poolId;
PoolObjectList ExplicitlyChanced;
PoolObjectList EqualChanced;
};
typedef std::multimap<uint32, uint32> PooledQuestRelation;
typedef std::pair<PooledQuestRelation::const_iterator, PooledQuestRelation::const_iterator> PooledQuestRelationBounds;
typedef std::pair<PooledQuestRelation::iterator, PooledQuestRelation::iterator> PooledQuestRelationBoundsNC;
class PoolMgr
{
friend class ACE_Singleton<PoolMgr, ACE_Null_Mutex>;
@@ -95,13 +110,16 @@ class PoolMgr
public:
void LoadFromDB();
void LoadQuestPools();
void SaveQuestsToDB();
void Initialize();
template<typename T>
uint32 IsPartOfAPool(uint32 db_guid_or_pool_id) const;
template<typename T>
bool IsSpawnedObject(uint32 db_guid_or_pool_id) const { return mSpawnedData.IsSpawnedObject<T>(db_guid_or_pool_id); }
bool IsSpawnedObject(uint32 db_guid_or_pool_id) const { return mSpawnedData.IsActiveObject<T>(db_guid_or_pool_id); }
bool CheckPool(uint32 pool_id) const;
@@ -111,6 +129,11 @@ class PoolMgr
template<typename T>
void UpdatePool(uint32 pool_id, uint32 db_guid_or_pool_id);
void ChangeDailyQuests();
void ChangeWeeklyQuests();
PooledQuestRelation mQuestCreatureRelation;
PooledQuestRelation mQuestGORelation;
protected:
template<typename T>
void SpawnPool(uint32 pool_id, uint32 db_guid_or_pool_id);
@@ -120,6 +143,7 @@ class PoolMgr
typedef std::vector<PoolGroup<Creature> > PoolGroupCreatureMap;
typedef std::vector<PoolGroup<GameObject> > PoolGroupGameObjectMap;
typedef std::vector<PoolGroup<Pool> > PoolGroupPoolMap;
typedef std::vector<PoolGroup<Quest> > PoolGroupQuestMap;
typedef std::pair<uint32, uint32> SearchPair;
typedef std::map<uint32, uint32> SearchMap;
@@ -127,12 +151,14 @@ class PoolMgr
PoolGroupCreatureMap mPoolCreatureGroups;
PoolGroupGameObjectMap mPoolGameobjectGroups;
PoolGroupPoolMap mPoolPoolGroups;
PoolGroupQuestMap mPoolQuestGroups;
SearchMap mCreatureSearchMap;
SearchMap mGameobjectSearchMap;
SearchMap mPoolSearchMap;
SearchMap mQuestSearchMap;
// dynamic data
SpawnedPoolData mSpawnedData;
ActivePoolData mSpawnedData;
};
#define sPoolMgr (*ACE_Singleton<PoolMgr, ACE_Null_Mutex>::instance())
@@ -159,6 +185,17 @@ inline uint32 PoolMgr::IsPartOfAPool<GameObject>(uint32 db_guid) const
return 0;
}
// Method that tell if the quest is part of another pool and return the pool id if yes
template<>
inline uint32 PoolMgr::IsPartOfAPool<Quest>(uint32 pool_id) const
{
SearchMap::const_iterator itr = mQuestSearchMap.find(pool_id);
if (itr != mQuestSearchMap.end())
return itr->second;
return 0;
}
// Method that tell if the pool is part of another pool and return the pool id if yes
template<>
inline uint32 PoolMgr::IsPartOfAPool<Pool>(uint32 pool_id) const
+12 -3
View File
@@ -1437,6 +1437,9 @@ void World::SetInitialWorldSettings()
sLog.outString("Loading Quests Relations...");
sObjectMgr.LoadQuestRelations(); // must be after quest load
sLog.outString("Loading Quest Pooling Data...");
sPoolMgr.LoadQuestPools();
sLog.outString("Loading Dungeon boss data...");
sLFGMgr.LoadDungeonEncounters();
@@ -1720,6 +1723,9 @@ void World::SetInitialWorldSettings()
sLog.outString("Deleting expired bans...");
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
sLog.outString("Starting objects Pooling system...");
sPoolMgr.Initialize();
sLog.outString("Calculate next daily quest reset time...");
InitDailyQuestResetTime();
@@ -1729,9 +1735,6 @@ void World::SetInitialWorldSettings()
sLog.outString("Calculate random battleground reset time..." );
InitRandomBGResetTime();
sLog.outString("Starting objects Pooling system...");
sPoolMgr.Initialize();
// possibly enable db logging; avoid massive startup spam by doing it here.
if (sLog.GetLogDBLater())
{
@@ -2597,6 +2600,9 @@ void World::ResetDailyQuests()
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
if (itr->second->GetPlayer())
itr->second->GetPlayer()->ResetDailyQuestStatus();
// change available dailies
sPoolMgr.ChangeDailyQuests();
}
void World::LoadDBAllowedSecurityLevel()
@@ -2624,6 +2630,9 @@ void World::ResetWeeklyQuests()
m_NextWeeklyQuestReset = time_t(m_NextWeeklyQuestReset + WEEK);
sWorld.setWorldState(WS_WEEKLY_QUEST_RESET_TIME, uint64(m_NextWeeklyQuestReset));
// change available weeklies
sPoolMgr.ChangeWeeklyQuests();
}
void World::ResetRandomBG()
+1
View File
@@ -208,6 +208,7 @@ class PreparedResultSet
const char* GetCString(uint32 index);
bool NextRow();
uint64 GetRowCount() const { return num_rows; }
private:
bool CheckFieldIndex(uint32 index) const