Skip to content

Commit

Permalink
small prog on area triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
hatersgit committed Nov 22, 2023
1 parent 6ba3846 commit 6d34591
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 97 deletions.
3 changes: 3 additions & 0 deletions modules/mod-Forge/src/ForgeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OUT

#include <string>
#include "AreaTriggerDataStore.h"
#include "ScriptMgr.h"
#include "Player.h"
#include "Config.h"
Expand Down Expand Up @@ -1040,6 +1041,8 @@ class ForgeCache : public DatabaseScript

LOG_INFO("server.load", "Loading npc sounds...");
sObjectMgr->LoadNpcSounds();

sAreaTriggerDataStore->LoadAreaTriggerTemplates();
}
catch (std::exception & ex) {
std::string error = ex.what();
Expand Down
98 changes: 1 addition & 97 deletions src/server/game/Globals/AreaTriggerDataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,58 +59,6 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
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
{
Field* verticeFields = vertices->Fetch();
uint32 areaTriggerId = verticeFields[0].Get<uint32>();

verticesByAreaTrigger[areaTriggerId].emplace_back(verticeFields[2].Get<float>(), verticeFields[3].Get<float>());

if (!verticeFields[4].IsNull() && !verticeFields[5].IsNull())
verticesTargetByAreaTrigger[areaTriggerId].emplace_back(verticeFields[4].Get<float>(), verticeFields[5].Get<float>());
else if (verticeFields[4].IsNull() != verticeFields[5].IsNull())
LOG_ERROR("sql.sql", "Table `areatrigger_template_polygon_vertices` has listed invalid target vertices (AreaTrigger: %u, Index: %u).", areaTriggerId, verticeFields[1].Get<uint32>());
} while (vertices->NextRow());
}
else
{
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
{
Field* splineFields = splines->Fetch();
uint32 spellMiscId = splineFields[0].Get<uint32>();
splinesBySpellMisc[spellMiscId].emplace_back(splineFields[1].Get<float>(), splineFields[2].Get<float>(), splineFields[3].Get<float>());
} while (splines->NextRow());
}
else
{
LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates splines. DB table `spell_areatrigger_splines` is empty.");
}

// 0 1 2 3 4 5 6
if (QueryResult rollpitchyaws = WorldDatabase.Query("SELECT SpellMiscId, X, Y, Z, TargetX, TargetY, TargetZ FROM `spell_areatrigger_rollpitchyaw` ORDER BY `SpellMiscId`"))
{
do
{
Field* rollpitchyawFields = rollpitchyaws->Fetch();
uint32 spellMiscId = rollpitchyawFields[0].Get<uint32>();
rollpitchyawBySpellMisc[spellMiscId].emplace_back(rollpitchyawFields[1].Get<float>(), rollpitchyawFields[2].Get<float>(), rollpitchyawFields[3].Get<float>());
rollpitchyawBySpellMisc[spellMiscId].emplace_back(rollpitchyawFields[4].Get<float>(), rollpitchyawFields[5].Get<float>(), rollpitchyawFields[6].Get<float>());
} while (rollpitchyaws->NextRow());
}
else
{
LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates Roll Pitch Yaw. DB table `spell_areatrigger_rollpitchyaw` 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`"))
{
Expand Down Expand Up @@ -145,7 +93,7 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
}

// 0 1 2 3 4 5 6 7 8 9 10
if (QueryResult areatriggerSpellMiscs = WorldDatabase.Query("SELECT SpellMiscId, AreaTriggerId, MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, TimeToTarget, TimeToTargetScale FROM `spell_areatrigger`"))
if (QueryResult areatriggerSpellMiscs = WorldDatabase.Query("SELECT SpellMiscId, AreaTriggerId, MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, TimeToTarget, TimeToTargetScale FROM `areatrigger_create_properties`"))
{
do
{
Expand Down Expand Up @@ -203,50 +151,6 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
LOG_INFO("server.loading", ">> Loaded 0 Spell AreaTrigger templates. DB table `spell_areatrigger` is empty.");
}

// 0 1 2 3 4 5 6 7
if (QueryResult circularMovementInfos = WorldDatabase.Query("SELECT SpellMiscId, StartDelay, CircleRadius, BlendFromRadius, InitialAngle, ZOffset, CounterClockwise, CanLoop FROM `spell_areatrigger_circular` ORDER BY `SpellMiscId`"))
{
do
{
Field* circularMovementInfoFields = circularMovementInfos->Fetch();
uint32 spellMiscId = circularMovementInfoFields[0].Get<uint32>();

auto atSpellMiscItr = _areaTriggerTemplateSpellMisc.find(spellMiscId);
if (atSpellMiscItr == _areaTriggerTemplateSpellMisc.end())
{
LOG_ERROR("sql.sql", "Table `spell_areatrigger_circular` reference invalid SpellMiscId %u", spellMiscId);
continue;
}

AreaTriggerOrbitInfo& orbitInfo = atSpellMiscItr->second.OrbitInfo;

orbitInfo.StartDelay = circularMovementInfoFields[1].Get<uint32>();

#define VALIDATE_AND_SET_FLOAT(Float, Value) \
orbitInfo.Float = Value; \
if (!std::isfinite(orbitInfo.Float)) \
{ \
LOG_ERROR("sql.sql", "Table `spell_areatrigger_circular` has listed areatrigger (MiscId: %u) with invalid " #Float " (%f), set to 0!", \
spellMiscId, orbitInfo.Float); \
orbitInfo.Float = 0.0f; \
}

VALIDATE_AND_SET_FLOAT(Radius, circularMovementInfoFields[2].Get<float>());
VALIDATE_AND_SET_FLOAT(BlendFromRadius, circularMovementInfoFields[3].Get<float>());
VALIDATE_AND_SET_FLOAT(InitialAngle, circularMovementInfoFields[4].Get<float>());
VALIDATE_AND_SET_FLOAT(ZOffset, circularMovementInfoFields[5].Get<float>());

#undef VALIDATE_AND_SET_FLOAT

orbitInfo.CounterClockwise = circularMovementInfoFields[6].Get<bool>();
orbitInfo.CanLoop = circularMovementInfoFields[7].Get<bool>();
} while (circularMovementInfos->NextRow());
}
else
{
LOG_INFO("server.loading", ">> Loaded 0 AreaTrigger templates circular movement infos. DB table `spell_areatrigger_circular` is empty.");
}

LOG_INFO("server.loading", ">> Loaded {} spell areatrigger templates in %u ms.", _areaTriggerTemplateStore.size(), GetMSTimeDiffToNow(oldMSTime));
}

Expand Down
1 change: 1 addition & 0 deletions src/server/game/Spells/Auras/SpellAuraDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ enum AuraType
SPELL_AURA_MOD_SPELL_POWER_OF_STAT_PERCENT = 330,
SPELL_AURA_MOD_SPELL_POWER_OF_RATING_PERCENT = 331,
SPELL_AURA_MOD_TRIGGER_SPELL_ON_POWER_PCT = 332,
SPELL_AURA_AREA_TRIGGER = 333,
TOTAL_AURAS
};

Expand Down
17 changes: 17 additions & 0 deletions src/server/game/Spells/Auras/SpellAuraEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ pAuraEffectHandler AuraEffectHandler[TOTAL_AURAS] =
&AuraEffect::HandleAuraModSpellPowerOfStatPercent, //330 SPELL_AURA_MOD_SPELL_POWER_OF_STAT_PERCENT
&AuraEffect::HandleAuraModSpellPowerOfCombatRatingPercent, //331 SPELL_AURA_MOD_SPELL_POWER_OF_RATING_PERCENT
&AuraEffect::HandleAuraModTriggerSpellPowerPercent, //332 SPELL_AURA_MOD_TRIGGER_SPELL_ON_POWER_PCT
&AuraEffect::HandleCreateAreaTrigger, //333 SPELL_AURA_AREA_TRIGGER
};

AuraEffect::AuraEffect(Aura* base, uint8 effIndex, int32* baseAmount, Unit* caster):
Expand Down Expand Up @@ -7246,3 +7247,19 @@ void AuraEffect::HandleAuraAddCharges(AuraApplication const* aurApp, uint8 mode,
}
}
}

void AuraEffect::HandleCreateAreaTrigger(AuraApplication const* aurApp, uint8 mode, bool apply) const
{
if (!(mode & AURA_EFFECT_HANDLE_REAL))
return;

Unit* target = aurApp->GetTarget();

if (Unit* caster = GetCaster())
{
if (apply)
AreaTrigger::CreateAreaTrigger(GetMiscValue(), caster, target, GetSpellInfo(), *target, GetBase()->GetDuration(), m_spellInfo->SpellVisual, ObjectGuid::Empty, this);
//else
// caster->RemoveAreaTrigger(this);
}
}
1 change: 1 addition & 0 deletions src/server/game/Spells/Auras/SpellAuraEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class AuraEffect
void HandleModTriggerSpellOnStacksSelf(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleModTriggerSpellOnStacksTarget(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleModToggleAuraCombatState(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleCreateAreaTrigger(AuraApplication const* aurApp, uint8 mode, bool apply) const;

// aura effect periodic tick handlers
void HandlePeriodicDummyAuraTick(Unit* target, Unit* caster) const;
Expand Down

0 comments on commit 6d34591

Please sign in to comment.