Skip to content
Permalink
Browse files

Server/Phasing: Update Phasing and add SAI example for phasing for fi…

…rst quest in gilneas.

Signed-off-by: AriDEV <aridev666@gmail.com>
  • Loading branch information...
AriDEV committed Oct 31, 2019
1 parent e63e061 commit 7fad4e56163a3534dcc62085bbd14317fce2bdbe
@@ -0,0 +1,4 @@
UPDATE creature_template SET AIName='SmartAI' WHERE entry=34863;
DELETE FROM smart_scripts WHERE entryorguid=34863;
INSERT INTO smart_scripts (entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o, comment) VALUES
(34863, 0, 0, 0, 20, 0, 100, 0, 14078, 0, 0, 0, 44, 170, 1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 'Lieutenant Walden: On quest reward - set player phaseId 170');

Large diffs are not rendered by default.

@@ -20,36 +20,69 @@
#ifndef _MMAP_MANAGER_H
#define _MMAP_MANAGER_H

#include "UnorderedMap.h"
#include "Define.h"
#include "DetourAlloc.h"
#include "DetourNavMesh.h"
#include "DetourNavMeshQuery.h"
#include "World.h"
#include <string>
#include <unordered_map>
#include <set>

// move map related classes
// move map related classes
namespace MMAP
{
typedef UNORDERED_MAP<uint32, dtTileRef> MMapTileSet;
typedef UNORDERED_MAP<uint32, dtNavMeshQuery*> NavMeshQuerySet;

// dummy struct to hold map's mmap data
struct MMapData
{
MMapData(dtNavMesh* mesh) : navMesh(mesh) { }
~MMapData()
{
for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i)
dtFreeNavMeshQuery(i->second);

if (navMesh)
dtFreeNavMesh(navMesh);
}
typedef std::set<uint32> TerrainSet;

struct NavMeshHolder
{
// Pre-built navMesh
dtNavMesh* navMesh;

// List of terrain swap map ids used to build the navMesh
TerrainSet terrainIds;

MMapTileSet loadedTileRefs;
};

struct PhasedTile
{
unsigned char* data;
MmapTileHeader fileHeader;
int32 dataSize;
};

typedef UNORDERED_MAP<uint32, PhasedTile*> PhaseTileContainer;
typedef UNORDERED_MAP<uint32, PhaseTileContainer> PhaseTileMap;


typedef UNORDERED_MAP<uint32, TerrainSet> TerrainSetMap;

class MMapData
{
public:
MMapData(dtNavMesh* mesh, uint32 mapId);
~MMapData();

dtNavMesh* GetNavMesh(TerrainSet swaps);

// we have to use single dtNavMeshQuery for every instance, since those are not thread safe
NavMeshQuerySet navMeshQueries; // instanceId to query
MMapTileSet mmapLoadedTiles; // maps [map grid coords] to [dtTile]

dtNavMesh* navMesh;
MMapTileSet loadedTileRefs;
TerrainSetMap loadedPhasedTiles;

private:
uint32 _mapId;
PhaseTileContainer _baseTiles;
std::set<uint32> _activeSwaps;
void RemoveSwap(PhasedTile* ptile, uint32 swap, uint32 packedXY);
void AddSwap(PhasedTile* tile, uint32 swap, uint32 packedXY);
};


@@ -59,27 +92,35 @@ namespace MMAP
// holds all all access to mmap loading unloading and meshes
class MMapManager
{
public:
MMapManager() : loadedTiles(0) { }
~MMapManager();

bool loadMap(const std::string& basePath, uint32 mapId, int32 x, int32 y);
bool unloadMap(uint32 mapId, int32 x, int32 y);
bool unloadMap(uint32 mapId);
bool unloadMapInstance(uint32 mapId, uint32 instanceId);

// the returned [dtNavMeshQuery const*] is NOT threadsafe
dtNavMeshQuery const* GetNavMeshQuery(uint32 mapId, uint32 instanceId);
dtNavMesh const* GetNavMesh(uint32 mapId);

uint32 getLoadedTilesCount() const { return loadedTiles; }
uint32 getLoadedMapsCount() const { return loadedMMaps.size(); }
private:
bool loadMapData(uint32 mapId);
uint32 packTileID(int32 x, int32 y);

MMapDataSet loadedMMaps;
uint32 loadedTiles;
public:
MMapManager() : loadedTiles(0) { }
~MMapManager();

bool loadMap(const std::string& basePath, uint32 mapId, int32 x, int32 y);
bool unloadMap(uint32 mapId, int32 x, int32 y);
bool unloadMap(uint32 mapId);
bool unloadMapInstance(uint32 mapId, uint32 instanceId);

// the returned [dtNavMeshQuery const*] is NOT threadsafe
dtNavMeshQuery const* GetNavMeshQuery(uint32 mapId, uint32 instanceId, TerrainSet swaps);
dtNavMesh const* GetNavMesh(uint32 mapId, TerrainSet swaps);

uint32 getLoadedTilesCount() const { return loadedTiles; }
uint32 getLoadedMapsCount() const { return loadedMMaps.size(); }

void LoadPhaseTiles(uint32 mapId, int32 x, int32 y);
void UnloadPhaseTile(uint32 mapId, int32 x, int32 y);
PhaseTileContainer GetPhaseTileContainer(uint32 mapId) { return _phaseTiles[mapId]; }

private:
bool loadMapData(uint32 mapId);
uint32 packTileID(int32 x, int32 y);

MMapDataSet loadedMMaps;
uint32 loadedTiles;

PhasedTile* LoadTile(uint32 mapId, int32 x, int32 y);
PhaseTileMap _phaseTiles;
};
}

@@ -1023,8 +1023,16 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_SET_INGAME_PHASE_MASK:
{
if (GetBaseObject())
GetBaseObject()->SetPhaseMask(e.action.ingamePhaseMask.mask, true);
//break;
ObjectList* targets = GetTargets(e, unit);

if (!targets)
break;

for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
(*itr)->ToUnit()->SetPhased(e.action.ingamePhaseId.id, true, e.action.ingamePhaseId.apply);

delete targets;
break;
}
case SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL:
@@ -710,8 +710,9 @@ struct SmartAction

struct
{
uint32 mask;
} ingamePhaseMask;
uint32 id;
uint32 apply;
} ingamePhaseId;

struct
{
@@ -3286,6 +3286,9 @@ bool WorldObject::IsPhased(WorldObject const* obj) const
if (obj->GetPhases().empty() && IsPhased(169))
return true;

if (GetTypeId() == TYPEID_PLAYER && ToPlayer()->IsGameMaster())
return true;

return Skyfire::Containers::Intersects(_phases.begin(), _phases.end(), obj->GetPhases().begin(), obj->GetPhases().end());
}

@@ -177,7 +177,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool c

Map* map = owner->GetMap();
uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_PET);
if (!Create(guid, map, owner->GetPhaseMask(), petEntry, petId))
if (!Create(guid, map, /*owner->GetPhaseMask(),*/ petEntry, petId))
return false;

float px, py, pz;
@@ -715,7 +715,7 @@ bool Pet::CreateBaseAtCreature(Creature* creature)
{
ASSERT(creature);

if (!CreateBaseAtTamed(creature->GetCreatureTemplate(), creature->GetMap(), creature->GetPhaseMask()))
if (!CreateBaseAtTamed(creature->GetCreatureTemplate(), creature->GetMap()/*, creature->GetPhaseMask()*/))
return false;

Relocate(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation());
@@ -746,7 +746,7 @@ bool Pet::CreateBaseAtCreature(Creature* creature)

bool Pet::CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner)
{
if (!CreateBaseAtTamed(cinfo, owner->GetMap(), owner->GetPhaseMask()))
if (!CreateBaseAtTamed(cinfo, owner->GetMap()/*, owner->GetPhaseMask()*/))
return false;

if (CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family))
@@ -757,12 +757,12 @@ bool Pet::CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner)
return true;
}

bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phaseMask)
bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map/*, uint32 phaseMask*/)
{
SF_LOG_DEBUG("entities.pet", "Pet::CreateBaseForTamed");
uint32 guid=sObjectMgr->GenerateLowGuid(HIGHGUID_PET);
uint32 petId = sObjectMgr->GeneratePetNumber();
if (!Create(guid, map, phaseMask, cinfo->Entry, petId))
if (!Create(guid, map, /*phaseMask,*/ cinfo->Entry, petId))
return false;

setPowerType(POWER_FOCUS);
@@ -1865,12 +1865,12 @@ bool Pet::IsPermanentPetFor(Player* owner) const
}
}

bool Pet::Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 petId)
bool Pet::Create(uint32 guidlow, Map* map, /*uint32 phaseMask,*/ uint32 Entry, uint32 petId)
{
ASSERT(map);
SetMap(map);

SetPhaseMask(phaseMask, false);
//SetPhaseMask(phaseMask, false);
Object::_Create(guidlow, petId, HIGHGUID_PET);

m_DBTableGuid = guidlow;
@@ -56,10 +56,10 @@ class Pet : public Guardian

bool IsPermanentPetFor(Player* owner) const; // pet have tab in character windows and set UNIT_FIELD_PET_NUMBER

bool Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number);
bool Create(uint32 guidlow, Map* map, /*uint32 phaseMask,*/ uint32 Entry, uint32 pet_number);
bool CreateBaseAtCreature(Creature* creature);
bool CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner);
bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phaseMask);
bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map/*, uint32 phaseMask*/);
bool LoadPetFromDB(Player* owner, uint32 petentry = 0, uint32 petnumber = 0, bool current = false);
bool isBeingLoaded() const { return m_loading;}
void SavePetToDB(PetSaveMode mode);
UpdateForQuestWorldObjects();
UpdatePhasing();

UpdateObjectVisibility();

if (questGiver) // script managment for every quest
{
switch (questGiver->GetTypeId())

Map* map = GetMap();
uint32 pet_number = sObjectMgr->GeneratePetNumber();
if (!pet->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_PET), map, GetPhaseMask(), entry, pet_number))
if (!pet->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_PET), map, /*GetPhaseMask(),*/ entry, pet_number))
{
SF_LOG_ERROR("misc", "no such creature entry %u", entry);
delete pet;

void Player::UpdatePhasing()
{
std::set<uint32> phaseIds;
std::set<uint32> terrainswaps;
std::set<uint32> worldAreaSwaps;
if (!IsInWorld())
return;

RebuildTerrainSwaps(); // to set default map swaps

return false;
}

for (auto phase : GetPhases())
pet->SetPhased(phase, false, true);

pet->GetCharmInfo()->SetPetNumber(sObjectMgr->GeneratePetNumber(), true);
// this enables pet details window (Shift+P)
pet->InitPetCreateSpells();
@@ -1709,6 +1709,12 @@ void ObjectMgr::LoadCreatures()
}
}

if (data.phaseGroup && GetPhasesForGroup(data.phaseGroup).empty())
{
SF_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with non-existing `phasegroup` (%u) set, `phasegroup` set to 0", guid, data.id, data.phaseGroup);
data.phaseGroup = 0;
}

if (data.phaseGroup && data.phaseid)
{
SF_LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u Entry: %u) with both `phaseid` and `phasegroup` set, `phasegroup` set to 0", guid, data.id);
@@ -2000,6 +2006,12 @@ void ObjectMgr::LoadGameobjects()
int16 gameEvent = fields[17].GetInt8();
uint32 PoolId = fields[18].GetUInt32();

if (data.phaseGroup && GetPhasesForGroup(data.phaseGroup).empty())
{
SF_LOG_ERROR("sql.sql", "Table `gameobject` has gameobject (GUID: %u Entry: %u) with non-existing `phasegroup` (%u) set, `phasegroup` set to 0", guid, data.id, data.phaseGroup);
data.phaseGroup = 0;
}

if (data.phaseGroup && data.phaseid)
{
SF_LOG_ERROR("sql.sql", "Table `gameobject` have gameobject (GUID: %u Entry: %u) with both `phaseid` and `phasegroup` set, `phasegroup` set to 0", guid, data.id);
@@ -41,8 +41,8 @@ PathGenerator::PathGenerator(const Unit* owner) :
if (MMAP::MMapFactory::IsPathfindingEnabled(mapId))
{
MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
_navMesh = mmap->GetNavMesh(mapId);
_navMeshQuery = mmap->GetNavMeshQuery(mapId, _sourceUnit->GetInstanceId());
_navMesh = mmap->GetNavMesh(mapId, _sourceUnit->GetTerrainSwaps());
_navMeshQuery = mmap->GetNavMeshQuery(mapId, _sourceUnit->GetInstanceId(), _sourceUnit->GetTerrainSwaps());
}

CreateFilter();
@@ -187,7 +187,7 @@ class misc_commandscript : public CommandScript

uint32 haveMap = Map::ExistMap(mapId, gridX, gridY) ? 1 : 0;
uint32 haveVMap = Map::ExistVMap(mapId, gridX, gridY) ? 1 : 0;
uint32 haveMMap = (MMAP::MMapFactory::IsPathfindingEnabled(mapId) && MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId())) ? 1 : 0;
uint32 haveMMap = (MMAP::MMapFactory::IsPathfindingEnabled(mapId) && MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps())) ? 1 : 0;

if (haveVMap)
{
@@ -214,6 +214,28 @@ class misc_commandscript : public CommandScript
if (status)
handler->PSendSysMessage(LANG_LIQUID_STATUS, liquidStatus.level, liquidStatus.depth_level, liquidStatus.entry, liquidStatus.type_flags, status);

if (!object->GetPhases().empty())
{
std::stringstream ss;
for (uint32 swap : object->GetPhases())
ss << swap << " ";
handler->PSendSysMessage("Target's active phase swaps: %s", ss.str().c_str());
}
if (!object->GetTerrainSwaps().empty())
{
std::stringstream ss;
for (uint32 swap : object->GetTerrainSwaps())
ss << swap << " ";
handler->PSendSysMessage("Target's active terrain swaps: %s", ss.str().c_str());
}
if (!object->GetWorldMapSwaps().empty())
{
std::stringstream ss;
for (uint32 swap : object->GetWorldMapSwaps())
ss << swap << " ";
handler->PSendSysMessage("Target's active world map area swaps: %s", ss.str().c_str());
}

return true;
}

0 comments on commit 7fad4e5

Please sign in to comment.
You can’t perform that action at this time.