rsa
06.10.2010, 14:57
Продолжая процесс переноса обновляемых таблиц в базу characters, решил попробовать сделать базу mangos полностью ридонли.
Для этого пришлось вынести в characters "продолжения" таблиц gameobject и creatures, что за компанию позволяет иметь у нескольких реалмов одну базу mangos и разную расстановку НПЦ/ГО в разных реалмах.
Патч позволяет также заменять ГО и НПС в мире не изменяя при этом оригинальную базу (при загрузке объекты с одинаковым гуидом заменятся на те что изменены в конкретно этом реалме).
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index e7ef2ef..24f6a90 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1016,9 +1016,9 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
data.spawnMask = spawnMask;
// updated in DB
- WorldDatabase.BeginTransaction();
+ CharacterDatabase.BeginTransaction();
- WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid);
+ CharacterDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid);
std::ostringstream ss;
ss << "INSERT INTO creature VALUES ("
@@ -1041,9 +1041,9 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
<< (m_isDeadByDefault ? 1 : 0) << "," //is_dead
<< GetDefaultMovementType() << ")"; //default movement generator type
- WorldDatabase.PExecuteLog("%s", ss.str().c_str());
+ CharacterDatabase.PExecuteLog("%s", ss.str().c_str());
- WorldDatabase.CommitTransaction();
+ CharacterDatabase.CommitTransaction();
}
void Creature::SelectLevel(const CreatureInfo *cinfo, float percentHealth, float percentMana)
diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp
index 2f9318c..3a76073 100644
--- a/src/game/GameObject.cpp
+++ b/src/game/GameObject.cpp
@@ -557,10 +557,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
<< uint32(GetGoAnimProgress()) << ", "
<< uint32(GetGoState()) << ")";
- WorldDatabase.BeginTransaction();
- WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
- WorldDatabase.PExecuteLog("%s", ss.str().c_str());
- WorldDatabase.CommitTransaction();
+ CharacterDatabase.BeginTransaction();
+ CharacterDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
+ CharacterDatabase.PExecuteLog("%s", ss.str().c_str());
+ CharacterDatabase.CommitTransaction();
}
bool GameObject::LoadFromDB(uint32 guid, Map *map)
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index 50be622..2be8d89 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -1186,17 +1186,31 @@ void ObjectMgr::LoadCreatureModelRace()
sLog.outString( ">> Loaded %u creature_model_race entries", count);
}
-void ObjectMgr::LoadCreatures()
+void ObjectMgr::LoadCreatures(bool currentRealm)
{
uint32 count = 0;
+ QueryResult *result;
+ if (!currentRealm)
+ {
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid,"
+ result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid,"
// 4 5 6 7 8 9 10 11
"equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
// 12 13 14 15 16 17 18 19
"curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, event, pool_entry "
"FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid "
"LEFT OUTER JOIN pool_creature ON creature.guid = pool_creature.guid");
+ }
+ else
+ {
+ // 0 1 2 3
+ result = CharacterDatabase.Query("SELECT creature.guid, id, map, modelid,"
+ // 4 5 6 7 8 9 10 11
+ "equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
+ // 12 13 14 15 16 17 18 19
+ "curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, 0, 0 "
+ "FROM creature");
+ }
if(!result)
{
@@ -1393,16 +1407,26 @@ void ObjectMgr::RemoveCreatureFromGrid(uint32 guid, CreatureData const* data)
}
}
-void ObjectMgr::LoadGameobjects()
+void ObjectMgr::LoadGameobjects(bool currentRealm)
{
uint32 count = 0;
-
+ QueryResult *result;
+ if (!currentRealm)
+ {
// 0 1 2 3 4 5 6
- QueryResult *result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
+ result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
// 7 8 9 10 11 12 13 14 15 16 17
"rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event, pool_entry "
"FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid "
"LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid");
+ }
+ else
+ {
+ result = CharacterDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
+ // 7 8 9 10 11 12 13 14 15 16 17
+ "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, 0, 0 "
+ "FROM gameobject");
+ }
if(!result)
{
diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h
index 1452682..11d3dee 100644
--- a/src/game/ObjectMgr.h
+++ b/src/game/ObjectMgr.h
@@ -960,14 +960,14 @@ class ObjectMgr
void LoadDbScriptStrings();
void LoadCreatureLocales();
void LoadCreatureTemplates();
- void LoadCreatures();
+ void LoadCreatures(bool currentRealm = false);
void LoadCreatureRespawnTimes();
void LoadCreatureAddons();
void LoadCreatureModelInfo();
void LoadCreatureModelRace();
void LoadEquipmentTemplates();
void LoadGameObjectLocales();
- void LoadGameobjects();
+ void LoadGameobjects(bool currentRealm = false);
void LoadGameobjectRespawnTimes();
void LoadItemPrototypes();
void LoadItemRequiredTarget();
diff --git a/src/game/World.cpp b/src/game/World.cpp
index 9b38fb4..59d0e3d 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1056,6 +1056,9 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading Creature Data..." );
sObjectMgr.LoadCreatures();
+ sLog.outString( "Loading Creature Data from character DB..." );
+ sObjectMgr.LoadCreatures(true);
+
sLog.outString( "Loading pet levelup spells..." );
sSpellMgr.LoadPetLevelupSpellMap();
@@ -1074,6 +1077,9 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading Gameobject Data..." );
sObjectMgr.LoadGameobjects();
+ sLog.outString( "Loading Gameobject Data from character DB..." );
+ sObjectMgr.LoadGameobjects(true);
+
sLog.outString( "Loading Gameobject Respawn Data..." ); // must be after PackInstances()
sObjectMgr.LoadGameobjectRespawnTimes();
--
Внимание! Патч написан за 10 минут и серьезно не тестировался. Не решены проблемы с вейпойнтами, эвентами и пулами (хотя я не уверен что их вообще надо решать). Будут проблемы - пишите, подумаем.
PS да, и не забудьте создать в базе characters таблицы gameobject и creature, можно скулем для создания базы mangos
Для этого пришлось вынести в characters "продолжения" таблиц gameobject и creatures, что за компанию позволяет иметь у нескольких реалмов одну базу mangos и разную расстановку НПЦ/ГО в разных реалмах.
Патч позволяет также заменять ГО и НПС в мире не изменяя при этом оригинальную базу (при загрузке объекты с одинаковым гуидом заменятся на те что изменены в конкретно этом реалме).
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index e7ef2ef..24f6a90 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1016,9 +1016,9 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
data.spawnMask = spawnMask;
// updated in DB
- WorldDatabase.BeginTransaction();
+ CharacterDatabase.BeginTransaction();
- WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid);
+ CharacterDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid);
std::ostringstream ss;
ss << "INSERT INTO creature VALUES ("
@@ -1041,9 +1041,9 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
<< (m_isDeadByDefault ? 1 : 0) << "," //is_dead
<< GetDefaultMovementType() << ")"; //default movement generator type
- WorldDatabase.PExecuteLog("%s", ss.str().c_str());
+ CharacterDatabase.PExecuteLog("%s", ss.str().c_str());
- WorldDatabase.CommitTransaction();
+ CharacterDatabase.CommitTransaction();
}
void Creature::SelectLevel(const CreatureInfo *cinfo, float percentHealth, float percentMana)
diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp
index 2f9318c..3a76073 100644
--- a/src/game/GameObject.cpp
+++ b/src/game/GameObject.cpp
@@ -557,10 +557,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
<< uint32(GetGoAnimProgress()) << ", "
<< uint32(GetGoState()) << ")";
- WorldDatabase.BeginTransaction();
- WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
- WorldDatabase.PExecuteLog("%s", ss.str().c_str());
- WorldDatabase.CommitTransaction();
+ CharacterDatabase.BeginTransaction();
+ CharacterDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
+ CharacterDatabase.PExecuteLog("%s", ss.str().c_str());
+ CharacterDatabase.CommitTransaction();
}
bool GameObject::LoadFromDB(uint32 guid, Map *map)
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index 50be622..2be8d89 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -1186,17 +1186,31 @@ void ObjectMgr::LoadCreatureModelRace()
sLog.outString( ">> Loaded %u creature_model_race entries", count);
}
-void ObjectMgr::LoadCreatures()
+void ObjectMgr::LoadCreatures(bool currentRealm)
{
uint32 count = 0;
+ QueryResult *result;
+ if (!currentRealm)
+ {
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid,"
+ result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid,"
// 4 5 6 7 8 9 10 11
"equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
// 12 13 14 15 16 17 18 19
"curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, event, pool_entry "
"FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid "
"LEFT OUTER JOIN pool_creature ON creature.guid = pool_creature.guid");
+ }
+ else
+ {
+ // 0 1 2 3
+ result = CharacterDatabase.Query("SELECT creature.guid, id, map, modelid,"
+ // 4 5 6 7 8 9 10 11
+ "equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
+ // 12 13 14 15 16 17 18 19
+ "curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, 0, 0 "
+ "FROM creature");
+ }
if(!result)
{
@@ -1393,16 +1407,26 @@ void ObjectMgr::RemoveCreatureFromGrid(uint32 guid, CreatureData const* data)
}
}
-void ObjectMgr::LoadGameobjects()
+void ObjectMgr::LoadGameobjects(bool currentRealm)
{
uint32 count = 0;
-
+ QueryResult *result;
+ if (!currentRealm)
+ {
// 0 1 2 3 4 5 6
- QueryResult *result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
+ result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
// 7 8 9 10 11 12 13 14 15 16 17
"rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event, pool_entry "
"FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid "
"LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid");
+ }
+ else
+ {
+ result = CharacterDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
+ // 7 8 9 10 11 12 13 14 15 16 17
+ "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, 0, 0 "
+ "FROM gameobject");
+ }
if(!result)
{
diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h
index 1452682..11d3dee 100644
--- a/src/game/ObjectMgr.h
+++ b/src/game/ObjectMgr.h
@@ -960,14 +960,14 @@ class ObjectMgr
void LoadDbScriptStrings();
void LoadCreatureLocales();
void LoadCreatureTemplates();
- void LoadCreatures();
+ void LoadCreatures(bool currentRealm = false);
void LoadCreatureRespawnTimes();
void LoadCreatureAddons();
void LoadCreatureModelInfo();
void LoadCreatureModelRace();
void LoadEquipmentTemplates();
void LoadGameObjectLocales();
- void LoadGameobjects();
+ void LoadGameobjects(bool currentRealm = false);
void LoadGameobjectRespawnTimes();
void LoadItemPrototypes();
void LoadItemRequiredTarget();
diff --git a/src/game/World.cpp b/src/game/World.cpp
index 9b38fb4..59d0e3d 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1056,6 +1056,9 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading Creature Data..." );
sObjectMgr.LoadCreatures();
+ sLog.outString( "Loading Creature Data from character DB..." );
+ sObjectMgr.LoadCreatures(true);
+
sLog.outString( "Loading pet levelup spells..." );
sSpellMgr.LoadPetLevelupSpellMap();
@@ -1074,6 +1077,9 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading Gameobject Data..." );
sObjectMgr.LoadGameobjects();
+ sLog.outString( "Loading Gameobject Data from character DB..." );
+ sObjectMgr.LoadGameobjects(true);
+
sLog.outString( "Loading Gameobject Respawn Data..." ); // must be after PackInstances()
sObjectMgr.LoadGameobjectRespawnTimes();
--
Внимание! Патч написан за 10 минут и серьезно не тестировался. Не решены проблемы с вейпойнтами, эвентами и пулами (хотя я не уверен что их вообще надо решать). Будут проблемы - пишите, подумаем.
PS да, и не забудьте создать в базе characters таблицы gameobject и creature, можно скулем для создания базы mangos