Skip to content

Commit

Permalink
Spell: Add dyngo fake caster support
Browse files Browse the repository at this point in the history
Caster is dyngo, caster unit is dyngo owner in spell packet
  • Loading branch information
killerwife committed Jan 8, 2024
1 parent 5b7cb1a commit 0344077
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/game/Spells/Scripts/SpellScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class DynamicObject;

struct PeriodicTriggerData
{
WorldObject* trueCaster;
Unit* caster; Unit* target; WorldObject* targetObject;
SpellEntry const* spellInfo;
int32* basePoints;
PeriodicTriggerData(Unit* caster, Unit* target, WorldObject* targetObject, SpellEntry const* spellInfo, int32* basePoints) :
caster(caster), target(target), targetObject(targetObject), spellInfo(spellInfo), basePoints(basePoints) {}
PeriodicTriggerData(WorldObject* trueCaster, Unit* caster, Unit* target, WorldObject* targetObject, SpellEntry const* spellInfo, int32* basePoints) :
trueCaster(nullptr), caster(caster), target(target), targetObject(targetObject), spellInfo(spellInfo), basePoints(basePoints) {}
};

struct SpellScript
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3101,7 +3101,7 @@ SpellCastResult Spell::SpellStart(SpellCastTargets const* targets, Aura* trigger
SpellEvent* Event = new SpellEvent(this);
m_trueCaster->m_events.AddEvent(Event, m_trueCaster->m_events.CalculateTime(1));

if (!m_trueCaster->IsGameObject()) // gameobjects dont have a sense of already casting a spell
if (m_trueCaster->IsUnit()) // gameobjects dont have a sense of already casting a spell
{
// Prevent casting at cast another spell (ServerSide check)
if (m_caster->IsNonMeleeSpellCasted(false, true, true) && m_cast_count && !m_ignoreConcurrentCasts)
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/Spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ class Spell
void SetEventTarget(WorldObject* object) { m_eventTarget = object; }

// GO casting preparations
void SetFakeCaster(Unit* caster) { m_caster = caster; }
void SetFakeCaster(Unit* caster) { m_caster = caster; } // also used by dyngo caster emulation
WorldObject* GetTrueCaster() const { return m_trueCaster; }
Unit* GetAffectiveCasterOrOwner() const;

Expand Down
8 changes: 5 additions & 3 deletions src/game/Spells/SpellAuras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,9 +1025,11 @@ void Aura::PickTargetsForSpellTrigger(Unit*& triggerCaster, Unit*& triggerTarget

void Aura::CastTriggeredSpell(PeriodicTriggerData& data)
{
Spell* spell = new Spell(data.caster, data.spellInfo, TRIGGERED_OLD_TRIGGERED, data.caster->GetObjectGuid(), GetSpellProto());
Spell* spell = new Spell(data.trueCaster ? data.trueCaster : data.caster, data.spellInfo, TRIGGERED_OLD_TRIGGERED, data.trueCaster ? data.trueCaster->GetObjectGuid() : data.caster->GetObjectGuid(), GetSpellProto());
if (data.spellInfo->HasAttribute(SPELL_ATTR_EX2_RETAIN_ITEM_CAST)) // forward guid to at least spell go
spell->SetForwardedCastItem(GetCastItemGuid());
if (data.trueCaster && data.caster)
spell->SetFakeCaster(data.caster);
SpellCastTargets targets;
if (data.spellInfo->Targets & TARGET_FLAG_DEST_LOCATION)
{
Expand Down Expand Up @@ -2023,7 +2025,7 @@ void Aura::TriggerSpell()
}
}
int32 basePoints[] = { 0,0,0 };
PeriodicTriggerData data(triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints);
PeriodicTriggerData data(nullptr, triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints);
OnPeriodicTrigger(data);

// All ok cast by default case
Expand Down Expand Up @@ -2070,7 +2072,7 @@ void Aura::TriggerSpellWithValue()
WorldObject* triggerTargetObject = nullptr;
PickTargetsForSpellTrigger(triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo);

PeriodicTriggerData data(triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints);
PeriodicTriggerData data(nullptr, triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints);
OnPeriodicTrigger(data);

if (data.spellInfo)
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/SpellMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ uint32 GetSpellCastTime(SpellEntry const* spellInfo, WorldObject* caster, Spell*
if (!spellCastTimeEntry)
return 0;

int32 spellRank = caster && caster->GetTypeId() != TYPEID_GAMEOBJECT ? static_cast<Unit*>(caster)->GetSpellRank(spellInfo) : 0;
int32 spellRank = caster && caster->IsUnit() ? static_cast<Unit*>(caster)->GetSpellRank(spellInfo) : 0;
int32 castTime = spellCastTimeEntry->CastTime + spellCastTimeEntry->CastTimePerLevel * (spellRank / 5 - spellInfo->baseLevel);
castTime = std::max(castTime, spellCastTimeEntry->MinCastTime);

Expand Down

0 comments on commit 0344077

Please sign in to comment.