Skip to content

Commit

Permalink
Renamed areatrigger_template_auras to areatrigger_template_actions
Browse files Browse the repository at this point in the history
  • Loading branch information
joschiwald committed Jan 28, 2017
1 parent 00d393c commit d3b957c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 96 deletions.
10 changes: 5 additions & 5 deletions sql/updates/world/master/2017_01_29_00_world.sql
Expand Up @@ -26,13 +26,13 @@ CREATE TABLE `areatrigger_template_polygon_vertices` (
PRIMARY KEY (`AreaTriggerId`,`Idx`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `areatrigger_template_auras`;
CREATE TABLE `areatrigger_template_auras` (
DROP TABLE IF EXISTS `areatrigger_template_actions`;
CREATE TABLE `areatrigger_template_actions` (
`AreaTriggerId` int(10) unsigned NOT NULL,
`AuraId` int(10) unsigned NOT NULL,
`ActionType` int(10) unsigned NOT NULL,
`ActionParam` int(10) unsigned NOT NULL,
`TargetType` int(10) unsigned NOT NULL DEFAULT '0',
`CastType` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`AreaTriggerId`, `AuraId`)
PRIMARY KEY (`AreaTriggerId`, `ActionType`, `ActionParam`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `spell_areatrigger`;
Expand Down
80 changes: 45 additions & 35 deletions src/server/game/Entities/AreaTrigger/AreaTrigger.cpp
Expand Up @@ -352,7 +352,7 @@ void AreaTrigger::HandleUnitEnterExit(std::list<Unit*> const& newTargetList)
if (player->isDebugAreaTriggers)
ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_ENTERED, GetTemplate()->Id);

AddAuras(unit);
DoActions(unit);
sScriptMgr->OnAreaTriggerEntityUnitEnter(this, unit);
}

Expand All @@ -364,7 +364,7 @@ void AreaTrigger::HandleUnitEnterExit(std::list<Unit*> const& newTargetList)
if (player->isDebugAreaTriggers)
ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_LEFT, GetTemplate()->Id);

RemoveAuras(leavingUnit);
UndoActions(leavingUnit);
sScriptMgr->OnAreaTriggerEntityUnitExit(this, leavingUnit);
}
}
Expand Down Expand Up @@ -492,62 +492,72 @@ void AreaTrigger::UpdateShape()
UpdatePolygonOrientation();
}

void AreaTrigger::AddAuras(Unit* unit)
{
if (Unit* caster = GetCaster())
{
for (AreaTriggerAuras const& aura : GetTemplate()->Auras)
{
if (UnitFitToAuraRequirement(unit, caster, aura.TargetType))
{
if (aura.CastType == AREATRIGGER_AURA_CASTTYPE_CAST)
caster->CastSpell(unit, aura.AuraId, true);
else
caster->AddAura(aura.AuraId, unit);
}
}
}
}

void AreaTrigger::RemoveAuras(Unit* unit)
{
for (AreaTriggerAuras const& aura : GetTemplate()->Auras)
unit->RemoveAurasDueToSpell(aura.AuraId, GetCasterGuid());
}

bool AreaTrigger::UnitFitToAuraRequirement(Unit* unit, Unit* caster, AreaTriggerAuraTypes targetType) const
bool UnitFitToActionRequirement(Unit* unit, Unit* caster, AreaTriggerActionUserTypes targetType)
{
switch (targetType)
{
case AREATRIGGER_AURA_USER_FRIEND:
case AREATRIGGER_ACTION_USER_FRIEND:
{
return caster->IsFriendlyTo(unit);
}
case AREATRIGGER_AURA_USER_ENEMY:
case AREATRIGGER_ACTION_USER_ENEMY:
{
return !caster->IsFriendlyTo(unit);
}
case AREATRIGGER_AURA_USER_RAID:
case AREATRIGGER_ACTION_USER_RAID:
{
return caster->IsInRaidWith(unit);
}
case AREATRIGGER_AURA_USER_PARTY:
case AREATRIGGER_ACTION_USER_PARTY:
{
return caster->IsInPartyWith(unit);
}
case AREATRIGGER_AURA_USER_CASTER:
case AREATRIGGER_ACTION_USER_CASTER:
{
return unit->GetGUID() == GetCasterGuid();
return unit->GetGUID() == caster->GetGUID();
}
case AREATRIGGER_AURA_USER_ANY:
case AREATRIGGER_ACTION_USER_ANY:
default:
break;
}

return true;
}

void AreaTrigger::InitSplineOffsets(::Movement::PointsArray splinePoints, uint32 timeToTarget)
void AreaTrigger::DoActions(Unit* unit)
{
if (Unit* caster = GetCaster())
{
for (AreaTriggerAction const& action : GetTemplate()->Actions)
{
if (UnitFitToActionRequirement(unit, caster, action.TargetType))
{
switch (action.ActionType)
{
case AREATRIGGER_ACTION_CAST:
caster->CastSpell(unit, action.Param, true);
break;
case AREATRIGGER_ACTION_ADDAURA:
caster->AddAura(action.Param, unit);
break;
default:
break;
}
}
}
}
}

void AreaTrigger::UndoActions(Unit* unit)
{
for (AreaTriggerAction const& action : GetTemplate()->Actions)
{
if (action.ActionType == AREATRIGGER_ACTION_CAST || action.ActionType == AREATRIGGER_ACTION_ADDAURA)
unit->RemoveAurasDueToSpell(action.Param, GetCasterGuid());
}
}

void AreaTrigger::InitSplineOffsets(std::vector<G3D::Vector3> splinePoints, uint32 timeToTarget)
{
float angleSin = std::sin(GetOrientation());
float angleCos = std::cos(GetOrientation());
Expand All @@ -568,7 +578,7 @@ void AreaTrigger::InitSplineOffsets(::Movement::PointsArray splinePoints, uint32
InitSplines(splinePoints, timeToTarget);
}

void AreaTrigger::InitSplines(::Movement::PointsArray const& splinePoints, uint32 timeToTarget)
void AreaTrigger::InitSplines(std::vector<G3D::Vector3> const& splinePoints, uint32 timeToTarget)
{
if (splinePoints.size() < 2)
return;
Expand Down
10 changes: 4 additions & 6 deletions src/server/game/Entities/AreaTrigger/AreaTrigger.h
Expand Up @@ -18,7 +18,6 @@
#ifndef TRINITYCORE_AREATRIGGER_H
#define TRINITYCORE_AREATRIGGER_H

#include "MoveSplineInitArgs.h"
#include "Object.h"
#include "Position.h"
#include "Spline.h"
Expand Down Expand Up @@ -63,8 +62,8 @@ class TC_GAME_API AreaTrigger : public WorldObject, public GridObject<AreaTrigge

G3D::Vector3 const& GetRollPitchYaw() const { return _rollPitchYaw; }
G3D::Vector3 const& GetTargetRollPitchYaw() const { return _targetRollPitchYaw; }
void InitSplineOffsets(::Movement::PointsArray splinePoints, uint32 timeToTarget);
void InitSplines(::Movement::PointsArray const& splinePoints, uint32 timeToTarget);
void InitSplineOffsets(std::vector<G3D::Vector3> splinePoints, uint32 timeToTarget);
void InitSplines(std::vector<G3D::Vector3> const& splinePoints, uint32 timeToTarget);
bool HasSplines() const { return !_spline.empty(); }
::Movement::Spline<int32> const& GetSpline() const { return _spline; }
uint32 GetElapsedTimeForMovement() const { return GetTimeSinceCreated(); } /// @todo: research the right value, in sniffs both timers are nearly identical
Expand All @@ -83,9 +82,8 @@ class TC_GAME_API AreaTrigger : public WorldObject, public GridObject<AreaTrigge
bool CheckIsInPolygon2D(Position const* pos) const;
void HandleUnitEnterExit(std::list<Unit*> const& targetList);

void AddAuras(Unit* unit);
void RemoveAuras(Unit* unit);
bool UnitFitToAuraRequirement(Unit* unit, Unit* caster, AreaTriggerAuraTypes targetType) const;
void DoActions(Unit* unit);
void UndoActions(Unit* unit);

void UpdatePolygonOrientation();
void UpdateSplinePosition(uint32 diff);
Expand Down
33 changes: 23 additions & 10 deletions src/server/game/Entities/AreaTrigger/AreaTriggerTemplate.h
Expand Up @@ -18,13 +18,8 @@
#ifndef TRINITYCORE_AREATRIGGER_TEMPLATE_H
#define TRINITYCORE_AREATRIGGER_TEMPLATE_H

#include "Object.h"
#include "Spline.h"
#include <G3D/Vector3.h>

class Unit;
class SpellInfo;

#define MAX_AREATRIGGER_ENTITY_DATA 6

enum AreaTriggerFlags
Expand Down Expand Up @@ -52,11 +47,29 @@ enum AreaTriggerTypes
AREATRIGGER_TYPE_MAX = 5
};

struct AreaTriggerAuras
enum AreaTriggerActionTypes
{
AREATRIGGER_ACTION_CAST = 0,
AREATRIGGER_ACTION_ADDAURA = 1,
AREATRIGGER_ACTION_MAX = 2
};

enum AreaTriggerActionUserTypes
{
AREATRIGGER_ACTION_USER_ANY = 0,
AREATRIGGER_ACTION_USER_FRIEND = 1,
AREATRIGGER_ACTION_USER_ENEMY = 2,
AREATRIGGER_ACTION_USER_RAID = 3,
AREATRIGGER_ACTION_USER_PARTY = 4,
AREATRIGGER_ACTION_USER_CASTER = 5,
AREATRIGGER_ACTION_USER_MAX = 6
};

struct AreaTriggerAction
{
uint32 AuraId;
AreaTriggerAuraTypes TargetType;
AreaTriggerAuraCastTypes CastType;
uint32 Param;
AreaTriggerActionTypes ActionType;
AreaTriggerActionUserTypes TargetType;
};

class AreaTriggerTemplate
Expand Down Expand Up @@ -88,7 +101,7 @@ class AreaTriggerTemplate
float MaxSearchRadius;
std::vector<G3D::Vector2> PolygonVertices;
std::vector<G3D::Vector2> PolygonVerticesTarget;
std::vector<AreaTriggerAuras> Auras;
std::vector<AreaTriggerAction> Actions;

union
{
Expand Down
51 changes: 29 additions & 22 deletions src/server/game/Globals/AreaTriggerDataStore.cpp
Expand Up @@ -34,44 +34,46 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
std::unordered_map<uint32, std::vector<G3D::Vector2>> verticesByAreaTrigger;
std::unordered_map<uint32, std::vector<G3D::Vector2>> verticesTargetByAreaTrigger;
std::unordered_map<uint32, std::vector<G3D::Vector3>> splinesBySpellMisc;
std::unordered_map<uint32, std::vector<AreaTriggerAuras>> aurasByAreaTrigger;
std::unordered_map<uint32, std::vector<AreaTriggerAction>> actionsByAreaTrigger;

if (QueryResult templateAuras = WorldDatabase.Query("SELECT AreaTriggerId, AuraId, TargetType, CastType FROM `areatrigger_template_auras`"))
// 0 1 2 3
if (QueryResult templateActions = WorldDatabase.Query("SELECT AreaTriggerId, ActionType, ActionParam, TargetType FROM `areatrigger_template_actions`"))
{
do
{
Field* templateAurasFields = templateAuras->Fetch();
uint32 areaTriggerId = templateAurasFields[0].GetUInt32();
Field* templateActionFields = templateActions->Fetch();
uint32 areaTriggerId = templateActionFields[0].GetUInt32();

AreaTriggerAuras aura;
aura.AuraId = templateAurasFields[1].GetUInt32();
uint32 targetType = templateAurasFields[2].GetUInt32();
uint32 castType = templateAurasFields[3].GetUInt32();
AreaTriggerAction action;
action.Param = templateActionFields[2].GetUInt32();
uint32 actionType = templateActionFields[1].GetUInt32();
uint32 targetType = templateActionFields[3].GetUInt32();

if (targetType >= AREATRIGGER_AURA_USER_MAX)
if (actionType >= AREATRIGGER_ACTION_MAX)
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_auras` has invalid TargetType (%u) for AreaTriggerId %u and AuraId %u", targetType, areaTriggerId, aura.AuraId);
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid ActionType (%u) for AreaTriggerId %u and Param %u", actionType, areaTriggerId, action.Param);
continue;
}

if (castType >= AREATRIGGER_AURA_CASTTYPE_MAX)
if (targetType >= AREATRIGGER_ACTION_USER_MAX)
{
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_auras` has invalid CastType (%u) for AreaTriggerId %u and AuraId %u", castType, areaTriggerId, aura.AuraId);
TC_LOG_ERROR("sql.sql", "Table `areatrigger_template_actions` has invalid TargetType (%u) for AreaTriggerId %u and Param %u", targetType, areaTriggerId, action.Param);
continue;
}

aura.TargetType = AreaTriggerAuraTypes(targetType);
aura.CastType = AreaTriggerAuraCastTypes(castType);
action.TargetType = AreaTriggerActionUserTypes(targetType);
action.ActionType = AreaTriggerActionTypes(actionType);

aurasByAreaTrigger[areaTriggerId].push_back(aura);
actionsByAreaTrigger[areaTriggerId].push_back(action);
}
while (templateAuras->NextRow());
while (templateActions->NextRow());
}
else
{
TC_LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates auras. DB table `areatrigger_template_auras` is empty.");
TC_LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates actions. DB table `areatrigger_template_actions` is empty.");
}

// 0 1 2 3 4 5
if (QueryResult vertices = WorldDatabase.Query("SELECT AreaTriggerId, Idx, VerticeX, VerticeY, VerticeTargetX, VerticeTargetY FROM `areatrigger_template_polygon_vertices` ORDER BY `AreaTriggerId`, `Idx`"))
{
do
Expand All @@ -93,6 +95,7 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
TC_LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates polygon vertices. DB table `areatrigger_template_polygon_vertices` is empty.");
}

// 0 1 2 3
if (QueryResult splines = WorldDatabase.Query("SELECT SpellMiscId, X, Y, Z FROM `spell_areatrigger_splines` ORDER BY `SpellMiscId`, `Idx`"))
{
do
Expand All @@ -106,13 +109,15 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
spline.z = splineFields[3].GetFloat();

splinesBySpellMisc[spellMiscId].push_back(spline);
} while (splines->NextRow());
}
while (splines->NextRow());
}
else
{
TC_LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates splines. DB table `spell_areatrigger_splines` is empty.");
}

// 0 1 2 3 4 5 6 7 8 9
if (QueryResult templates = WorldDatabase.Query("SELECT Id, Type, Flags, Data0, Data1, Data2, Data3, Data4, Data5, ScriptName FROM `areatrigger_template`"))
{
do
Expand All @@ -138,14 +143,15 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
areaTriggerTemplate.ScriptId = sObjectMgr->GetScriptId(fields[9].GetString());
areaTriggerTemplate.PolygonVertices = std::move(verticesByAreaTrigger[areaTriggerTemplate.Id]);
areaTriggerTemplate.PolygonVerticesTarget = std::move(verticesTargetByAreaTrigger[areaTriggerTemplate.Id]);
areaTriggerTemplate.Auras = std::move(aurasByAreaTrigger[areaTriggerTemplate.Id]);
areaTriggerTemplate.Actions = std::move(actionsByAreaTrigger[areaTriggerTemplate.Id]);

areaTriggerTemplate.InitMaxSearchRadius();
_areaTriggerTemplateStore[areaTriggerTemplate.Id] = areaTriggerTemplate;

} while (templates->NextRow());
}
while (templates->NextRow());
}

// 0 1 2 3 4 5 6 7 8
if (QueryResult areatriggerSpellMiscs = WorldDatabase.Query("SELECT SpellMiscId, AreaTriggerId, MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, DecalPropertiesId, TimeToTarget, TimeToTargetScale FROM `spell_areatrigger`"))
{
do
Expand Down Expand Up @@ -188,7 +194,8 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
miscTemplate.SplinePoints = splinesBySpellMisc[miscTemplate.MiscId];

_areaTriggerTemplateSpellMisc[miscTemplate.MiscId] = miscTemplate;
} while (areatriggerSpellMiscs->NextRow());
}
while (areatriggerSpellMiscs->NextRow());
}
else
{
Expand Down
18 changes: 0 additions & 18 deletions src/server/game/Miscellaneous/SharedDefines.h
Expand Up @@ -5100,24 +5100,6 @@ enum ResetFailedReason : uint8
INSTANCE_RESET_FAILED_OFFLINE = 2 // "Cannot reset %s. There are players offline in your party."
};

enum AreaTriggerAuraTypes
{
AREATRIGGER_AURA_USER_ANY = 0,
AREATRIGGER_AURA_USER_FRIEND = 1,
AREATRIGGER_AURA_USER_ENEMY = 2,
AREATRIGGER_AURA_USER_RAID = 3,
AREATRIGGER_AURA_USER_PARTY = 4,
AREATRIGGER_AURA_USER_CASTER = 5,
AREATRIGGER_AURA_USER_MAX = 6
};

enum AreaTriggerAuraCastTypes
{
AREATRIGGER_AURA_CASTTYPE_CAST = 0,
AREATRIGGER_AURA_CASTTYPE_ADDAURA = 1,
AREATRIGGER_AURA_CASTTYPE_MAX = 2
};

enum class GameError : uint32
{
ERR_SYSTEM = 0,
Expand Down

0 comments on commit d3b957c

Please sign in to comment.