*Implemented gameobjects and creatures grouping (pools of them)
*Groups (called pools) can be also member of any game event Author: Neo2003 --HG-- branch : trunk
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE `pool_creature` (
|
||||
`guid` int(10) unsigned NOT NULL default '0',
|
||||
`pool_entry` mediumint(8) unsigned NOT NULL default '0',
|
||||
`chance` float unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`pool_entry`,`guid`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `pool_gameobject` (
|
||||
`guid` int(10) unsigned NOT NULL default '0',
|
||||
`pool_entry` mediumint(8) unsigned NOT NULL default '0',
|
||||
`chance` float unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`guid`,`pool_entry`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `pool_template` (
|
||||
`entry` mediumint(8) unsigned NOT NULL default '0' COMMENT 'Pool entry',
|
||||
`max_limit` int(10) unsigned NOT NULL default '0' COMMENT 'Max number of objects (0) is no limit',
|
||||
PRIMARY KEY (`entry`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `game_event_pool` (
|
||||
`pool_entry` mediumint(8) unsigned NOT NULL default '0' COMMENT 'Id of the pool',
|
||||
`event` smallint(6) NOT NULL default '0' COMMENT 'Put negatives values to remove during event',
|
||||
PRIMARY KEY (`pool_entry`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "QuestDef.h"
|
||||
#include "GossipDef.h"
|
||||
#include "Player.h"
|
||||
#include "PoolHandler.h"
|
||||
#include "Opcodes.h"
|
||||
#include "Log.h"
|
||||
#include "LootMgr.h"
|
||||
@@ -423,7 +424,11 @@ void Creature::Update(uint32 diff)
|
||||
//Call AI respawn virtual function
|
||||
i_AI->JustRespawned();
|
||||
|
||||
GetMap()->Add(this);
|
||||
uint16 poolid = poolhandler.IsPartOfAPool(GetGUIDLow(), GetTypeId());
|
||||
if (poolid)
|
||||
poolhandler.UpdatePool(poolid, GetGUIDLow(), GetTypeId());
|
||||
else
|
||||
GetMap()->Add(this);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "GameEvent.h"
|
||||
#include "World.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "PoolHandler.h"
|
||||
#include "ProgressBar.h"
|
||||
#include "Language.h"
|
||||
#include "Log.h"
|
||||
@@ -916,6 +917,61 @@ void GameEvent::LoadFromDB()
|
||||
|
||||
delete result;
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// GameEventPool
|
||||
////////////////////////
|
||||
|
||||
mGameEventPoolIds.resize(mGameEvent.size()*2-1);
|
||||
// 1 2
|
||||
result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.event "
|
||||
"FROM pool_template JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry");
|
||||
|
||||
count = 0;
|
||||
if( !result )
|
||||
{
|
||||
barGoLink bar2(1);
|
||||
bar2.step();
|
||||
|
||||
sLog.outString();
|
||||
sLog.outString(">> Loaded %u pools in game events", count );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
barGoLink bar2( result->GetRowCount() );
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
|
||||
bar2.step();
|
||||
|
||||
uint32 entry = fields[0].GetUInt16();
|
||||
int16 event_id = fields[1].GetInt16();
|
||||
|
||||
int32 internal_event_id = mGameEvent.size() + event_id - 1;
|
||||
|
||||
if(internal_event_id < 0 || internal_event_id >= mGameEventPoolIds.size())
|
||||
{
|
||||
sLog.outErrorDb("`game_event_pool` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!poolhandler.CheckPool(entry))
|
||||
{
|
||||
sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
++count;
|
||||
IdList& poollist = mGameEventPoolIds[internal_event_id];
|
||||
poollist.push_back(entry);
|
||||
|
||||
} while( result->NextRow() );
|
||||
sLog.outString();
|
||||
sLog.outString( ">> Loaded %u pools in game events", count );
|
||||
delete result;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 GameEvent::GetNPCFlag(Creature * cr)
|
||||
@@ -1188,6 +1244,17 @@ void GameEvent::GameEventSpawn(int16 event_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(internal_event_id < 0 || internal_event_id >= mGameEventPoolIds.size())
|
||||
{
|
||||
sLog.outError("GameEvent::GameEventSpawn attempt access to out of range mGameEventPoolIds element %i (size: %u)",internal_event_id,mGameEventPoolIds.size());
|
||||
return;
|
||||
}
|
||||
|
||||
for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
|
||||
{
|
||||
poolhandler.SpawnPool(*itr);
|
||||
}
|
||||
}
|
||||
|
||||
void GameEvent::GameEventUnspawn(int16 event_id)
|
||||
@@ -1238,6 +1305,16 @@ void GameEvent::GameEventUnspawn(int16 event_id)
|
||||
pGameobject->AddObjectToRemoveList();
|
||||
}
|
||||
}
|
||||
if(internal_event_id < 0 || internal_event_id >= mGameEventPoolIds.size())
|
||||
{
|
||||
sLog.outError("GameEvent::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %i (size: %u)",internal_event_id,mGameEventPoolIds.size());
|
||||
return;
|
||||
}
|
||||
|
||||
for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
|
||||
{
|
||||
poolhandler.DespawnPool(*itr);
|
||||
}
|
||||
}
|
||||
|
||||
void GameEvent::ChangeEquipOrModel(int16 event_id, bool activate)
|
||||
|
||||
@@ -127,7 +127,9 @@ class GameEvent
|
||||
bool hasGameObjectActiveEventExcept(uint32 go_guid, uint16 event_id);
|
||||
protected:
|
||||
typedef std::list<uint32> GuidList;
|
||||
typedef std::list<uint16> IdList;
|
||||
typedef std::vector<GuidList> GameEventGuidMap;
|
||||
typedef std::vector<IdList> GameEventIdMap;
|
||||
typedef std::pair<uint32, ModelEquip> ModelEquipPair;
|
||||
typedef std::list<ModelEquipPair> ModelEquipList;
|
||||
typedef std::vector<ModelEquipList> GameEventModelEquipMap;
|
||||
@@ -149,6 +151,7 @@ class GameEvent
|
||||
GameEventModelEquipMap mGameEventModelEquip;
|
||||
GameEventGuidMap mGameEventCreatureGuids;
|
||||
GameEventGuidMap mGameEventGameobjectGuids;
|
||||
GameEventIdMap mGameEventPoolIds;
|
||||
GameEventDataMap mGameEvent;
|
||||
GameEventBitmask mGameEventBattleGroundHolidays;
|
||||
QuestIdToEventConditionMap mQuestToEventConditions;
|
||||
|
||||
+12
-3
@@ -22,6 +22,7 @@
|
||||
#include "QuestDef.h"
|
||||
#include "GameObject.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "PoolHandler.h"
|
||||
#include "SpellMgr.h"
|
||||
#include "Spell.h"
|
||||
#include "UpdateMask.h"
|
||||
@@ -66,7 +67,7 @@ GameObject::~GameObject()
|
||||
{
|
||||
if(m_uint32Values) // field array can be not exist if GameOBject not loaded
|
||||
{
|
||||
// crash possible at access to deleted GO in Unit::m_gameobj
|
||||
// Possible crash at access to deleted GO in Unit::m_gameobj
|
||||
uint64 owner_guid = GetOwnerGUID();
|
||||
if(owner_guid)
|
||||
{
|
||||
@@ -281,7 +282,11 @@ void GameObject::Update(uint32 /*p_time*/)
|
||||
return;
|
||||
}
|
||||
// respawn timer
|
||||
GetMap()->Add(this);
|
||||
uint16 poolid = poolhandler.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
|
||||
if (poolid)
|
||||
poolhandler.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
|
||||
else
|
||||
GetMap()->Add(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -484,7 +489,11 @@ void GameObject::Delete()
|
||||
SetGoState(1);
|
||||
SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags);
|
||||
|
||||
AddObjectToRemoveList();
|
||||
uint16 poolid = poolhandler.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
|
||||
if (poolid)
|
||||
poolhandler.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
|
||||
else
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
void GameObject::getFishLoot(Loot *fishloot, Player* loot_owner)
|
||||
|
||||
+28
-9
@@ -35,6 +35,7 @@
|
||||
#include "World.h"
|
||||
#include "GameEvent.h"
|
||||
#include "SpellMgr.h"
|
||||
#include "PoolHandler.h"
|
||||
#include "AccountMgr.h"
|
||||
//#include "GMTicketMgr.h"
|
||||
#include "WaypointManager.h"
|
||||
@@ -204,7 +205,7 @@ bool ChatHandler::HandleTargetObjectCommand(const char* args)
|
||||
|
||||
result = WorldDatabase.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, "
|
||||
"(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
|
||||
"LEFT OUTER JOIN game_event_gameobject on gameobject.guid=game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 1",
|
||||
"LEFT OUTER JOIN game_event_gameobject on gameobject.guid=game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10",
|
||||
m_session->GetPlayer()->GetPositionX(), m_session->GetPlayer()->GetPositionY(), m_session->GetPlayer()->GetPositionZ(), m_session->GetPlayer()->GetMapId(),eventFilter.str().c_str());
|
||||
}
|
||||
|
||||
@@ -214,16 +215,34 @@ bool ChatHandler::HandleTargetObjectCommand(const char* args)
|
||||
return true;
|
||||
}
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
uint32 lowguid = fields[0].GetUInt32();
|
||||
uint32 id = fields[1].GetUInt32();
|
||||
float x = fields[2].GetFloat();
|
||||
float y = fields[3].GetFloat();
|
||||
float z = fields[4].GetFloat();
|
||||
float o = fields[5].GetFloat();
|
||||
int mapid = fields[6].GetUInt16();
|
||||
bool found = false;
|
||||
float x, y, z, o;
|
||||
uint32 lowguid, id;
|
||||
uint16 mapid, pool_id;
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
lowguid = fields[0].GetUInt32();
|
||||
id = fields[1].GetUInt32();
|
||||
x = fields[2].GetFloat();
|
||||
y = fields[3].GetFloat();
|
||||
z = fields[4].GetFloat();
|
||||
o = fields[5].GetFloat();
|
||||
mapid = fields[6].GetUInt16();
|
||||
pool_id = poolhandler.IsPartOfAPool(lowguid, TYPEID_GAMEOBJECT);
|
||||
if (!pool_id || (pool_id && poolhandler.IsSpawnedObject(pool_id, lowguid, TYPEID_GAMEOBJECT)))
|
||||
found = true;
|
||||
} while( result->NextRow() && (!found) );
|
||||
|
||||
delete result;
|
||||
|
||||
if (!found)
|
||||
{
|
||||
PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameObjectInfo const* goI = objmgr.GetGameObjectInfo(id);
|
||||
|
||||
if (!goI)
|
||||
|
||||
@@ -227,6 +227,8 @@ libmangosgame_a_SOURCES = \
|
||||
PossessedAI.h \
|
||||
PointMovementGenerator.cpp \
|
||||
PointMovementGenerator.h \
|
||||
PoolHandler.cpp \
|
||||
PoolHandler.h \
|
||||
QueryHandler.cpp \
|
||||
QuestDef.cpp \
|
||||
QuestDef.h \
|
||||
|
||||
+32
-26
@@ -939,9 +939,10 @@ void ObjectMgr::LoadCreatures()
|
||||
QueryResult *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
|
||||
"curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, event "
|
||||
"FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid");
|
||||
// 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");
|
||||
|
||||
if(!result)
|
||||
{
|
||||
@@ -968,11 +969,19 @@ void ObjectMgr::LoadCreatures()
|
||||
Field *fields = result->Fetch();
|
||||
bar.step();
|
||||
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
uint32 guid = fields[ 0].GetUInt32();
|
||||
uint32 entry = fields[ 1].GetUInt32();
|
||||
|
||||
CreatureInfo const* cInfo = GetCreatureTemplate(entry);
|
||||
if(!cInfo)
|
||||
{
|
||||
sLog.outErrorDb("Table `creature` has creature (GUID: %u) with non existing creature entry %u, skipped.", guid, entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
CreatureData& data = mCreatureDataMap[guid];
|
||||
|
||||
data.id = fields[ 1].GetUInt32();
|
||||
data.id = entry;
|
||||
data.mapid = fields[ 2].GetUInt32();
|
||||
data.displayid = fields[ 3].GetUInt32();
|
||||
data.equipmentId = fields[ 4].GetUInt32();
|
||||
@@ -990,13 +999,7 @@ void ObjectMgr::LoadCreatures()
|
||||
data.spawnMask = fields[16].GetUInt8();
|
||||
data.phaseMask = fields[17].GetUInt16();
|
||||
int16 gameEvent = fields[18].GetInt16();
|
||||
|
||||
CreatureInfo const* cInfo = GetCreatureTemplate(data.id);
|
||||
if(!cInfo)
|
||||
{
|
||||
sLog.outErrorDb("Table `creature` have creature (GUID: %u) with not existed creature entry %u, skipped.",guid,data.id );
|
||||
continue;
|
||||
}
|
||||
int16 PoolId = fields[19].GetInt16();
|
||||
|
||||
if(heroicCreatures.find(data.id)!=heroicCreatures.end())
|
||||
{
|
||||
@@ -1081,7 +1084,7 @@ void ObjectMgr::LoadCreatures()
|
||||
}
|
||||
}
|
||||
|
||||
if (gameEvent==0) // if not this is to be managed by GameEvent System
|
||||
if (gameEvent==0 && PoolId==0) // if not this is to be managed by GameEvent System or Pool system
|
||||
AddCreatureToGrid(guid, &data);
|
||||
++count;
|
||||
|
||||
@@ -1131,9 +1134,10 @@ void ObjectMgr::LoadGameobjects()
|
||||
|
||||
// 0 1 2 3 4 5 6
|
||||
QueryResult *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
|
||||
"rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event "
|
||||
"FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid");
|
||||
// 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");
|
||||
|
||||
if(!result)
|
||||
{
|
||||
@@ -1153,11 +1157,19 @@ void ObjectMgr::LoadGameobjects()
|
||||
Field *fields = result->Fetch();
|
||||
bar.step();
|
||||
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
uint32 guid = fields[ 0].GetUInt32();
|
||||
uint32 entry = fields[ 1].GetUInt32();
|
||||
|
||||
GameObjectInfo const* gInfo = GetGameObjectInfo(entry);
|
||||
if(!gInfo)
|
||||
{
|
||||
sLog.outErrorDb("Table `gameobject` has gameobject (GUID: %u) with non existing gameobject entry %u, skipped.", guid, entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
GameObjectData& data = mGameObjectDataMap[guid];
|
||||
|
||||
data.id = fields[ 1].GetUInt32();
|
||||
data.id = entry;
|
||||
data.mapid = fields[ 2].GetUInt32();
|
||||
data.posX = fields[ 3].GetFloat();
|
||||
data.posY = fields[ 4].GetFloat();
|
||||
@@ -1174,13 +1186,7 @@ void ObjectMgr::LoadGameobjects()
|
||||
data.spawnMask = fields[14].GetUInt8();
|
||||
data.phaseMask = fields[15].GetUInt16();
|
||||
int16 gameEvent = fields[16].GetInt16();
|
||||
|
||||
GameObjectInfo const* gInfo = GetGameObjectInfo(data.id);
|
||||
if(!gInfo)
|
||||
{
|
||||
sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u) with not existed gameobject entry %u, skipped.",guid,data.id );
|
||||
continue;
|
||||
}
|
||||
int16 PoolId = fields[17].GetInt16();
|
||||
|
||||
if(data.phaseMask==0)
|
||||
{
|
||||
@@ -1188,7 +1194,7 @@ void ObjectMgr::LoadGameobjects()
|
||||
data.phaseMask = 1;
|
||||
}
|
||||
|
||||
if (gameEvent==0) // if not this is to be managed by GameEvent System
|
||||
if (gameEvent==0 && PoolId==0) // if not this is to be managed by GameEvent System or Pool system
|
||||
AddGameobjectToGrid(guid, &data);
|
||||
++count;
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include "VMapFactory.h"
|
||||
#include "GlobalEvents.h"
|
||||
#include "GameEvent.h"
|
||||
#include "PoolHandler.h"
|
||||
#include "Database/DatabaseImpl.h"
|
||||
#include "GridNotifiersImpl.h"
|
||||
#include "CellImpl.h"
|
||||
@@ -1220,6 +1221,9 @@ void World::SetInitialWorldSettings()
|
||||
sLog.outString( "Loading Gameobject Respawn Data..." ); // must be after PackInstances()
|
||||
objmgr.LoadGameobjectRespawnTimes();
|
||||
|
||||
sLog.outString( "Loading Objects Pooling Data...");
|
||||
poolhandler.LoadFromDB();
|
||||
|
||||
sLog.outString( "Loading Game Event Data...");
|
||||
sLog.outString();
|
||||
gameeventmgr.LoadFromDB();
|
||||
@@ -1455,6 +1459,9 @@ void World::SetInitialWorldSettings()
|
||||
sLog.outString("Calculate next daily quest reset time..." );
|
||||
InitDailyQuestResetTime();
|
||||
|
||||
sLog.outString("Starting objects Pooling system..." );
|
||||
poolhandler.Initialize();
|
||||
|
||||
sLog.outString("Starting Game Event system..." );
|
||||
uint32 nextGameEvent = gameeventmgr.Initialize();
|
||||
m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent); //depend on next event
|
||||
|
||||
@@ -475,6 +475,12 @@
|
||||
<File
|
||||
RelativePath="..\..\src\game\PetitionsHandler.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\PoolHandler.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\PoolHandler.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\QueryHandler.cpp">
|
||||
</File>
|
||||
|
||||
@@ -773,6 +773,14 @@
|
||||
RelativePath="..\..\src\game\PetitionsHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\PoolHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\PoolHandler.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\QueryHandler.cpp"
|
||||
>
|
||||
|
||||
@@ -756,6 +756,14 @@
|
||||
RelativePath="..\..\src\game\PetitionsHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\PoolHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\PoolHandler.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\QueryHandler.cpp"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user