mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 08:55:32 +01:00
Core/Phases: more work on corpse phasing
- moved all sql queries to prepared statements - implemented corpse phases saving, loading, cleaning
This commit is contained in:
@@ -4,5 +4,7 @@ DROP TABLE IF EXISTS `corpse_phases`;
|
||||
CREATE TABLE `corpse_phases` (
|
||||
`Guid` int(10) unsigned NOT NULL,
|
||||
`PhaseId` int(10) unsigned NOT NULL,
|
||||
`Time` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
`CorpseType` tinyint(3) unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`Guid`,`PhaseId`)
|
||||
);
|
||||
|
||||
@@ -92,6 +92,9 @@ bool Corpse::Create(uint32 guidlow, Player* owner)
|
||||
|
||||
_gridCoord = Trinity::ComputeGridCoord(GetPositionX(), GetPositionY());
|
||||
|
||||
for (auto itr : owner->GetPhases())
|
||||
SetInPhase(itr, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -121,6 +124,17 @@ void Corpse::SaveToDB()
|
||||
stmt->setUInt32(index++, GetInstanceId()); // instanceId
|
||||
trans->Append(stmt);
|
||||
|
||||
for (auto phaseId : GetPhases())
|
||||
{
|
||||
index = 0;
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CORPSE_PHASES);
|
||||
stmt->setUInt32(index++, GetGUIDLow()); // Guid (corpse's)
|
||||
stmt->setUInt32(index++, phaseId); // PhaseId
|
||||
stmt->setUInt32(index++, uint32(m_time)); // Time
|
||||
stmt->setUInt8(index++, GetType()); // CorpseType
|
||||
trans->Append(stmt);
|
||||
}
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
}
|
||||
|
||||
@@ -146,14 +160,25 @@ void Corpse::DeleteFromDB(SQLTransaction& trans)
|
||||
// Only specific bones
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CORPSE);
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
trans->Append(stmt);
|
||||
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CORPSE_PHASES);
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
trans->Append(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
// all corpses (not bones)
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_CORPSES);
|
||||
stmt->setUInt32(0, GetOwnerGUID().GetCounter());
|
||||
trans->Append(stmt);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_CORPSES_PHASES);
|
||||
stmt->setUInt32(0, GetOwnerGUID().GetCounter());
|
||||
trans->Append(stmt);
|
||||
}
|
||||
trans->Append(stmt);
|
||||
|
||||
}
|
||||
|
||||
bool Corpse::LoadCorpseFromDB(uint32 guid, Field* fields)
|
||||
|
||||
@@ -6928,8 +6928,9 @@ void ObjectMgr::LoadCorpses()
|
||||
|
||||
std::unordered_map<uint32, std::list<uint32>> phases;
|
||||
|
||||
// 0 1
|
||||
QueryResult phaseResult = WorldDatabase.Query("SELECT `Guid`, `PhaseId` FROM corpse_phases");
|
||||
// 0 1
|
||||
// SELECT Guid, PhaseId FROM corpse_phases
|
||||
PreparedQueryResult phaseResult = CharacterDatabase.Query(CharacterDatabase.GetPreparedStatement(CHAR_SEL_CORPSE_PHASES));
|
||||
if (phaseResult)
|
||||
{
|
||||
do
|
||||
|
||||
@@ -1384,6 +1384,10 @@ void World::SetInitialWorldSettings()
|
||||
stmt->setUInt32(0, 3 * DAY);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_OLD_CORPSE_PHASES);
|
||||
stmt->setUInt32(0, 3 * DAY);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
///- Load the DBC files
|
||||
TC_LOG_INFO("server.loading", "Initialize data stores...");
|
||||
LoadDBCStores(m_dataPath);
|
||||
|
||||
@@ -337,6 +337,11 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PrepareStatement(CHAR_DEL_CORPSE, "DELETE FROM corpse WHERE corpseGuid = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_DEL_PLAYER_CORPSES, "DELETE FROM corpse WHERE guid = ? AND corpseType <> 0", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_DEL_OLD_CORPSES, "DELETE FROM corpse WHERE corpseType = 0 OR time < (UNIX_TIMESTAMP(NOW()) - ?)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_CORPSE_PHASES, "SELECT Guid, PhaseId FROM corpse_phases", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_DEL_CORPSE_PHASES, "DELETE FROM corpse_phases WHERE Guid = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_DEL_PLAYER_CORPSES_PHASES, "DELETE FROM corpse_phases WHERE Guid = ? AND CorpseType <> 0", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_DEL_OLD_CORPSE_PHASES, "DELETE FROM corpse_phases WHERE CorpseType = 0 OR Time < (UNIX_TIMESTAMP(NOW()) - ?)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_INS_CORPSE_PHASES, "INSERT INTO corpse_phases (Guid, PhaseId, Time, CorpseType) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC);
|
||||
|
||||
// Creature respawn
|
||||
PrepareStatement(CHAR_SEL_CREATURE_RESPAWNS, "SELECT guid, respawnTime FROM creature_respawn WHERE mapId = ? AND instanceId = ?", CONNECTION_SYNCH);
|
||||
|
||||
@@ -297,6 +297,11 @@ enum CharacterDatabaseStatements
|
||||
CHAR_DEL_CORPSE,
|
||||
CHAR_DEL_PLAYER_CORPSES,
|
||||
CHAR_DEL_OLD_CORPSES,
|
||||
CHAR_SEL_CORPSE_PHASES,
|
||||
CHAR_DEL_CORPSE_PHASES,
|
||||
CHAR_DEL_PLAYER_CORPSES_PHASES,
|
||||
CHAR_DEL_OLD_CORPSE_PHASES,
|
||||
CHAR_INS_CORPSE_PHASES,
|
||||
|
||||
CHAR_SEL_CREATURE_RESPAWNS,
|
||||
CHAR_REP_CREATURE_RESPAWN,
|
||||
|
||||
Reference in New Issue
Block a user