Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Server/Phasing: Update Phasing and add SAI example for phasing for fi…
Browse files Browse the repository at this point in the history
…rst quest in gilneas.

Signed-off-by: AriDEV <aridev666@gmail.com>
  • Loading branch information
AriDEV committed Oct 31, 2019
1 parent e63e061 commit 7fad4e5
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 90 deletions.
4 changes: 4 additions & 0 deletions sql/updates/world/2019_10_30_00_world.sql
Original file line number Diff line number Diff line change
@@ -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');
307 changes: 280 additions & 27 deletions src/server/collision/Management/MMapManager.cpp

Large diffs are not rendered by default.

111 changes: 76 additions & 35 deletions src/server/collision/Management/MMapManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand All @@ -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;
};
}

Expand Down
12 changes: 10 additions & 2 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,9 @@ struct SmartAction

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

struct
{
Expand Down
3 changes: 3 additions & 0 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
14 changes: 7 additions & 7 deletions src/server/game/Entities/Pet/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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))
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Entities/Pet/Pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15904,6 +15904,8 @@ void Player::AddQuest(Quest const* quest, Object* questGiver)
UpdateForQuestWorldObjects();
UpdatePhasing();

UpdateObjectVisibility();

if (questGiver) // script managment for every quest
{
switch (questGiver->GetTypeId())
Expand Down Expand Up @@ -28366,7 +28368,7 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy

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;
Expand Down Expand Up @@ -29325,9 +29327,8 @@ void Player::SendDeclineGuildInvitation(std::string declinerName, bool autoDecli

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

RebuildTerrainSwaps(); // to set default map swaps

Expand Down
3 changes: 3 additions & 0 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13639,6 +13639,9 @@ bool Unit::InitTamedPet(Pet* pet, uint8 level, uint32 spell_id)
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();
Expand Down
12 changes: 12 additions & 0 deletions src/server/game/Globals/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Movement/PathGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 23 additions & 1 deletion src/server/scripts/Commands/cs_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit 7fad4e5

Please sign in to comment.