Skip to content

Commit

Permalink
add area trigger spell; needs visual
Browse files Browse the repository at this point in the history
  • Loading branch information
hatersgit committed Nov 26, 2023
1 parent 61007a4 commit d00929e
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 29 deletions.
30 changes: 16 additions & 14 deletions src/server/game/Entities/AreaTrigger/AreaTrigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ _previousCheckOrientation(std::numeric_limits<float>::infinity()),
_isBeingRemoved(false), _isRemoved(false), _reachedDestination(false), _lastSplineIndex(0), _movementTime(0),
_areaTriggerTemplate(nullptr), _areaTriggerMiscTemplate(nullptr), _spawnId(0), _guidScriptId(0), _ai(), m_areaTriggerData(new AreaTriggerDataState())
{
m_objectType |= TYPEMASK_GAMEOBJECT;
m_objectType |= TYPEMASK_AREATRIGGER;
m_objectTypeId = TYPEID_AREATRIGGER;

m_valuesCount = DYNAMICOBJECT_END;

m_updateFlag = UPDATEFLAG_STATIONARY_POSITION | UPDATEFLAG_AREATRIGGER;
}

AreaTrigger::~AreaTrigger()
Expand Down Expand Up @@ -90,7 +92,7 @@ bool AreaTrigger::Create(uint32 spellMiscId, Unit* caster, Unit* target, SpellIn

_areaTriggerTemplate = _areaTriggerMiscTemplate->Template;
auto templateId = GetTemplate() ? GetTemplate()->Id : 0;
Object::_Create(ObjectGuid::Create<HighGuid::DynamicObject>(templateId, caster->GetMap()->GenerateLowGuid<HighGuid::DynamicObject>()));
Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(templateId, caster->GetMap()->GenerateLowGuid<HighGuid::AreaTrigger>()));

UpdatePositionData();

Expand Down Expand Up @@ -176,20 +178,20 @@ bool AreaTrigger::Create(uint32 spellMiscId, Unit* caster, Unit* target, SpellIn
if (HasOrbit())
Relocate(CalculateOrbitPosition());

//if (IsWorldObject())
// setActive(true); //must before add to map to be put in world container
if (IsWorldObject())
setActive(true); //must before add to map to be put in world container

////if (!GetMap()->AddToMap(this, true))
////{
//// // Returning false will cause the object to be deleted - remove from transport
//// if (transport)
//// transport->RemovePassenger(this);
//// return false;
////}
if (!GetMap()->AddATToMap(this))
{
// Returning false will cause the object to be deleted - remove from transport
if (transport)
transport->RemovePassenger(this);
return false;
}

//caster->_RegisterAreaTrigger(this);

//_ai->OnCreate();
_ai->OnCreate();

return true;
}
Expand Down Expand Up @@ -935,14 +937,14 @@ void AreaTrigger::DebugVisualizePosition()
}

void AreaTrigger::AI_Initialize()
{/*
{
AI_Destroy();
AreaTriggerAI* ai = sScriptMgr->GetAreaTriggerAI(this);
if (!ai)
ai = new NullAreaTriggerAI(this);

_ai.reset(ai);
_ai->OnInitialize();*/
_ai->OnInitialize();
}

void AreaTrigger::AI_Destroy()
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/AreaTrigger/AreaTrigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class AreaTrigger : public WorldObject, public GridObject<AreaTrigger>, public M
AreaTriggerAI* AI() { return _ai.get(); }

private:
bool AddToMap(AreaTrigger* obj);
bool Create(uint32 spellMiscId, Unit* caster, Unit* target, SpellInfo const* spell, Position const& pos, int32 duration, std::array<uint32, 2> spellVisual, ObjectGuid const& castId, AuraEffect const* aurEff, AreaTriggerOrbitInfo* customOrbitInfo = nullptr);
public:
static AreaTrigger* CreateAreaTrigger(uint32 spellMiscId, Unit* caster, Unit* target, SpellInfo const* spell, Position const& pos, int32 duration, std::array<uint32, 2> spellVisual, ObjectGuid const& castId = ObjectGuid::Empty, AuraEffect const* aurEff = nullptr);
Expand Down
14 changes: 9 additions & 5 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c
if (flags & UPDATEFLAG_STATIONARY_POSITION)
{
// UPDATETYPE_CREATE_OBJECT2 dynamic objects, corpses...
if (isType(TYPEMASK_DYNAMICOBJECT) || isType(TYPEMASK_CORPSE) || isType(TYPEMASK_PLAYER))
if (isType(TYPEMASK_DYNAMICOBJECT) || isType(TYPEMASK_CORPSE) || isType(TYPEMASK_PLAYER) || isType(TYPEMASK_AREATRIGGER))
updatetype = UPDATETYPE_CREATE_OBJECT2;

// UPDATETYPE_CREATE_OBJECT2 for pets...
Expand Down Expand Up @@ -448,6 +448,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
case TYPEID_GAMEOBJECT:
case TYPEID_DYNAMICOBJECT:
case TYPEID_CORPSE:
case TYPEID_AREATRIGGER:
*data << uint32(GetGUID().GetCounter());
break;
//! Unit, Player and default here are sending wrong values.
Expand All @@ -470,10 +471,12 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
// 0x4
if (flags & UPDATEFLAG_HAS_TARGET)
{
if (Unit* victim = unit->GetVictim())
*data << victim->GetPackGUID();
else
*data << uint8(0);
if (unit) {
if (Unit* victim = unit->GetVictim())
*data << victim->GetPackGUID();
else
*data << uint8(0);
}
}

// 0x2
Expand Down Expand Up @@ -603,6 +606,7 @@ uint32 Object::GetUpdateFieldData(Player const* target, uint32*& flags) const
visibleFlag |= UF_FLAG_OWNER;
break;
case TYPEID_DYNAMICOBJECT:
case TYPEID_AREATRIGGER:
flags = DynamicObjectUpdateFieldFlags;
if (((DynamicObject*)this)->GetCasterGUID() == target->GetGUID())
visibleFlag |= UF_FLAG_OWNER;
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Entities/Object/ObjectGuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum TypeMask
TYPEMASK_GAMEOBJECT = 0x0020,
TYPEMASK_DYNAMICOBJECT = 0x0040,
TYPEMASK_CORPSE = 0x0080,
TYPEMASK_AREATRIGGER = 0x0100,
TYPEMASK_SEER = TYPEMASK_PLAYER | TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT
};

Expand All @@ -72,6 +73,7 @@ enum class HighGuid
Mo_Transport = 0x1FC0, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT)
Instance = 0x1F40, // blizz 1F40
Group = 0x1F50,
AreaTrigger = 0xff00,
};

template<HighGuid high>
Expand Down Expand Up @@ -107,6 +109,7 @@ GUID_TRAIT_MAP_SPECIFIC(HighGuid::Pet)
GUID_TRAIT_MAP_SPECIFIC(HighGuid::GameObject)
GUID_TRAIT_MAP_SPECIFIC(HighGuid::DynamicObject)
GUID_TRAIT_MAP_SPECIFIC(HighGuid::Corpse)
GUID_TRAIT_MAP_SPECIFIC(HighGuid::AreaTrigger)

class ObjectGuid;
class PackedGuid;
Expand Down Expand Up @@ -195,6 +198,7 @@ class ObjectGuid
case HighGuid::Corpse: return TYPEID_CORPSE;
case HighGuid::Mo_Transport: return TYPEID_GAMEOBJECT;
case HighGuid::Vehicle: return TYPEID_UNIT;
case HighGuid::AreaTrigger: return TYPEID_AREATRIGGER;
// unknown
case HighGuid::Instance:
case HighGuid::Group:
Expand Down Expand Up @@ -227,6 +231,7 @@ class ObjectGuid
case HighGuid::Mo_Transport:
case HighGuid::Instance:
case HighGuid::Group:
case HighGuid::AreaTrigger:
return false;
case HighGuid::GameObject:
case HighGuid::Transport:
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Entities/Object/Updates/UpdateData.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ enum OBJECT_UPDATE_FLAGS
UPDATEFLAG_STATIONARY_POSITION = 0x0040,
UPDATEFLAG_VEHICLE = 0x0080,
UPDATEFLAG_POSITION = 0x0100,
UPDATEFLAG_ROTATION = 0x0200
UPDATEFLAG_ROTATION = 0x0200,
UPDATEFLAG_AREATRIGGER = 0x0400
};

class UpdateData
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Globals/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ struct CellObjectGuids
{
CellGuidSet creatures;
CellGuidSet gameobjects;
CellGuidSet areatriggers;
};

typedef std::unordered_map<uint32/*cell_id*/, CellObjectGuids> CellObjectGuidsMap;
Expand Down
10 changes: 7 additions & 3 deletions src/server/game/Grids/GridDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DynamicObject;
class GameObject;
class Pet;
class Player;
class AreaTrigger;
class ObjectGuid;

#define MAX_NUMBER_OF_CELLS 8
Expand All @@ -55,14 +56,16 @@ class ObjectGuid;

// Creature used instead pet to simplify *::Visit templates (not required duplicate code for Creature->Pet case)
typedef TYPELIST_5(GameObject, Player, Creature/*pets*/, Corpse/*resurrectable*/, DynamicObject/*farsight target*/) AllWorldObjectTypes;
typedef TYPELIST_4(GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/) AllGridObjectTypes;
typedef TYPELIST_5(Creature, GameObject, DynamicObject, Pet, Corpse) AllMapStoredObjectTypes;
typedef TYPELIST_5(GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/, AreaTrigger) AllGridObjectTypes;
typedef TYPELIST_6(Creature, GameObject, DynamicObject, Pet, Corpse, AreaTrigger) AllMapStoredObjectTypes;

typedef GridRefMgr<Corpse> CorpseMapType;
typedef GridRefMgr<Creature> CreatureMapType;
typedef GridRefMgr<DynamicObject> DynamicObjectMapType;
typedef GridRefMgr<GameObject> GameObjectMapType;
typedef GridRefMgr<Player> PlayerMapType;
typedef GridRefMgr<GameObject> GameObjectMapType;
typedef GridRefMgr<AreaTrigger> AreaTriggerMapType;

enum GridMapTypeMask
{
Expand All @@ -71,7 +74,8 @@ enum GridMapTypeMask
GRID_MAP_TYPE_MASK_DYNAMICOBJECT = 0x04,
GRID_MAP_TYPE_MASK_GAMEOBJECT = 0x08,
GRID_MAP_TYPE_MASK_PLAYER = 0x10,
GRID_MAP_TYPE_MASK_ALL = 0x1F
GRID_MAP_TYPE_MASK_AREATRIGGER = 0x20,
GRID_MAP_TYPE_MASK_ALL = 0x3f
};

typedef Grid<Player, AllWorldObjectTypes, AllGridObjectTypes> GridType;
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Grids/Notifiers/GridNotifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,4 @@ bool AnyDeadUnitSpellTargetInRangeCheck::operator()(Creature* u)
template void ObjectUpdater::Visit<Creature>(CreatureMapType&);
template void ObjectUpdater::Visit<GameObject>(GameObjectMapType&);
template void ObjectUpdater::Visit<DynamicObject>(DynamicObjectMapType&);
template void ObjectUpdater::Visit<AreaTrigger>(AreaTriggerMapType&);
13 changes: 12 additions & 1 deletion src/server/game/Grids/ObjectGridLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CellImpl.h"
#include "Corpse.h"
#include "GridNotifiers.h"
#include "AreaTriggerDataStore.h"
#include "Creature.h"
#include "DynamicObject.h"
#include "GameObject.h"
Expand Down Expand Up @@ -189,6 +190,13 @@ void ObjectGridLoader::Visit(CreatureMapType& m)
LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map);
}

void ObjectGridLoader::Visit(AreaTriggerMapType& m)
{
CellCoord cellCoord = i_cell.GetCellCoord();
CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetDifficulty(), cellCoord.GetId());
LoadHelper(cell_guids.areatriggers, cellCoord, m, i_areaTriggers, i_map);
}

void ObjectWorldLoader::Visit(CorpseMapType& /*m*/)
{
CellCoord cellCoord = i_cell.GetCellCoord();
Expand All @@ -213,6 +221,7 @@ void ObjectGridLoader::LoadN(void)
i_gameObjects = 0;
i_creatures = 0;
i_corpses = 0;
i_areaTriggers = 0;
i_cell.data.Part.cell_y = 0;
for (uint32 x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
{
Expand All @@ -235,7 +244,7 @@ void ObjectGridLoader::LoadN(void)
}
}
}
LOG_DEBUG("maps", "{} GameObjects, {} Creatures, and {} Corpses/Bones loaded for grid {} on map {}", i_gameObjects, i_creatures, i_corpses, i_grid.GetGridId(), i_map->GetId());
LOG_DEBUG("maps", "{} GameObjects, {} Creatures, {} Corpses/Bones, and {} areatriggers loaded for grid {} on map {}", i_gameObjects, i_creatures, i_corpses, i_areaTriggers, i_grid.GetGridId(), i_map->GetId());
}

template<class T>
Expand Down Expand Up @@ -278,8 +287,10 @@ void ObjectGridCleaner::Visit(GridRefMgr<T>& m)
template void ObjectGridUnloader::Visit(CreatureMapType&);
template void ObjectGridUnloader::Visit(GameObjectMapType&);
template void ObjectGridUnloader::Visit(DynamicObjectMapType&);
template void ObjectGridUnloader::Visit(AreaTriggerMapType&);

template void ObjectGridCleaner::Visit(CreatureMapType&);
template void ObjectGridCleaner::Visit<GameObject>(GameObjectMapType&);
template void ObjectGridCleaner::Visit<DynamicObject>(DynamicObjectMapType&);
template void ObjectGridCleaner::Visit<Corpse>(CorpseMapType&);
template void ObjectGridCleaner::Visit<AreaTrigger>(AreaTriggerMapType&);
4 changes: 3 additions & 1 deletion src/server/game/Grids/ObjectGridLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class ObjectGridLoader

public:
ObjectGridLoader(NGridType& grid, Map* map, const Cell& cell)
: i_cell(cell), i_grid(grid), i_map(map), i_gameObjects(0), i_creatures(0), i_corpses (0)
: i_cell(cell), i_grid(grid), i_map(map), i_gameObjects(0), i_creatures(0), i_corpses(0), i_areaTriggers(0)
{}

void Visit(GameObjectMapType& m);
void Visit(CreatureMapType& m);
void Visit(CorpseMapType&) const {}
void Visit(DynamicObjectMapType&) const {}
void Visit(AreaTriggerMapType& m);

void LoadN(void);

Expand All @@ -51,6 +52,7 @@ class ObjectGridLoader
uint32 i_gameObjects;
uint32 i_creatures;
uint32 i_corpses;
uint32 i_areaTriggers;
};

//Stop the creatures before unloading the NGrid
Expand Down
57 changes: 57 additions & 0 deletions src/server/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ void Map::AddToGrid(DynamicObject* obj, Cell const& cell)
obj->SetCurrentCell(cell);
}

template<>
void Map::AddToGrid(AreaTrigger* obj, Cell const& cell)
{
NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
grid->GetGridType(cell.CellX(), cell.CellY()).AddGridObject(obj);

obj->SetCurrentCell(cell);
}

template<>
void Map::AddToGrid(Corpse* obj, Cell const& cell)
{
Expand Down Expand Up @@ -720,6 +729,51 @@ bool Map::AddToMap(MotionTransport* obj, bool /*checkTransport*/)
return true;
}

bool Map::AddATToMap(AreaTrigger* at) {
//TODO: Needs clean up. An object should not be added to map twice.
if (at->IsInWorld())
{
ASSERT(at->IsInGrid());
at->UpdateObjectVisibility(true);
return true;
}

CellCoord cellCoord = Acore::ComputeCellCoord(at->GetPositionX(), at->GetPositionY());
//It will create many problems (including crashes) if an object is not added to grid after creation
//The correct way to fix it is to make AddToMap return false and delete the object if it is not added to grid
//But now AddToMap is used in too many places, I will just see how many ASSERT failures it will cause
ASSERT(cellCoord.IsCoordValid());
if (!cellCoord.IsCoordValid())
{
LOG_ERROR("maps", "Map::AddToMap: Object {} has invalid coordinates X:{} Y:{} grid cell [{}:{}]",
at->GetGUID().ToString(), at->GetPositionX(), at->GetPositionY(), cellCoord.x_coord, cellCoord.y_coord);
return false; //Should delete object
}

Cell cell(cellCoord);
if (at->isActiveObject())
EnsureGridLoadedForActiveObject(cell, at);
else
EnsureGridCreated(GridCoord(cell.GridX(), cell.GridY()));

AddToGrid(at, cell);
LOG_DEBUG("maps", "Object {} enters grid[{}, {}]", at->GetGUID().ToString(), cell.GridX(), cell.GridY());

//Must already be set before AddToMap. Usually during obj->Create.
at->SetMap(this);
at->AddToWorld();

InitializeObject(at);

if (at->isActiveObject())
AddToActive(at);

//something, such as vehicle, needs to be update immediately
//also, trigger needs to cast spell, if not update, cannot see visual
at->UpdateObjectVisibility(true);
return true;
}

bool Map::IsGridLoaded(const GridCoord& p) const
{
NGridType* grid = getNGrid(p.x_coord, p.y_coord);
Expand Down Expand Up @@ -3157,6 +3211,9 @@ void Map::RemoveAllObjectsInRemoveList()
case TYPEID_DYNAMICOBJECT:
RemoveFromMap((DynamicObject*)obj, true);
break;
case TYPEID_AREATRIGGER:
RemoveFromMap((AreaTrigger*)obj, true);
break;
case TYPEID_GAMEOBJECT:
{
GameObject* go = obj->ToGameObject();
Expand Down
3 changes: 3 additions & 0 deletions src/server/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Transport;
class StaticTransport;
class MotionTransport;
class PathGenerator;
class AreaTrigger;

enum WeatherState : uint32;

Expand Down Expand Up @@ -337,6 +338,8 @@ class Map : public GridRefMgr<NGridType>
template<class T> bool AddToMap(T*, bool checkTransport = false);
template<class T> void RemoveFromMap(T*, bool);

bool AddATToMap(AreaTrigger* at);

void VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Acore::ObjectUpdater, GridTypeMapContainer>& gridVisitor,
TypeContainerVisitor<Acore::ObjectUpdater, WorldTypeMapContainer>& worldVisitor);

Expand Down
Loading

0 comments on commit d00929e

Please sign in to comment.