Skip to content

Commit

Permalink
Spell: SPELL_EFFECT_OPEN_LOCK should work on vehicle
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jan 11, 2025
1 parent 4ac23c5 commit e3752ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
20 changes: 14 additions & 6 deletions src/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6469,7 +6469,10 @@ SpellCastResult Spell::CheckCast(bool strict)
}
case SPELL_EFFECT_OPEN_LOCK:
{
if (m_caster->GetTypeId() != TYPEID_PLAYER) // only players can open locks, gather etc.
Player const* affectedCaster = dynamic_cast<Player*>(m_caster);
if (!affectedCaster && m_caster->IsUnit())
affectedCaster = static_cast<Unit*>(m_trueCaster)->GetControllingPlayer();
if (!affectedCaster) // only players can open locks, gather etc. (can be on vehicle)
return SPELL_FAILED_BAD_TARGETS;

// we need a go target in case of TARGET_GAMEOBJECT (for other targets acceptable GO and items)
Expand All @@ -6484,8 +6487,8 @@ SpellCastResult Spell::CheckCast(bool strict)
if (GameObject* go = m_targets.getGOTarget())
{
// In BattleGround players can use only flags and banners
if (((Player*)m_caster)->InBattleGround() &&
!((Player*)m_caster)->CanUseBattleGroundObject())
if (((Player*)affectedCaster)->InBattleGround() &&
!((Player*)affectedCaster)->CanUseBattleGroundObject())
return SPELL_FAILED_TRY_AGAIN;

lockId = go->GetGOInfo()->GetLockId();
Expand All @@ -6500,13 +6503,13 @@ SpellCastResult Spell::CheckCast(bool strict)
return SPELL_FAILED_CHEST_IN_USE;

// done in client but we need to recheck anyway
if (go->GetGOInfo()->CannotBeUsedUnderImmunity() && m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE))
if (go->GetGOInfo()->CannotBeUsedUnderImmunity() && affectedCaster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE))
return SPELL_FAILED_DAMAGE_IMMUNE;
}
else if (Item* item = m_targets.getItemTarget())
{
// not own (trade?)
if (item->GetOwner() != m_caster)
if (item->GetOwner() != affectedCaster)
return SPELL_FAILED_ITEM_GONE;

lockId = item->GetProto()->LockID;
Expand Down Expand Up @@ -7466,8 +7469,13 @@ SpellCastResult Spell::CheckRange(bool strict)
}

if (GameObject* goTarget = m_targets.getGOTarget())
if (!goTarget->IsAtInteractDistance(dynamic_cast<Player*>(m_trueCaster), maxRange)) // only player casts these
{
Player const* player = dynamic_cast<Player*>(m_trueCaster);
if (!player && m_trueCaster->IsUnit())
player = static_cast<Unit*>(m_trueCaster)->GetControllingPlayer();
if (!goTarget->IsAtInteractDistance(player, maxRange)) // only player or vehicle casts these
return SPELL_FAILED_OUT_OF_RANGE;
}

if (m_targets.m_targetMask == TARGET_FLAG_DEST_LOCATION)
{
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 @@ -909,7 +909,7 @@ class Spell
MaNGOS::unique_weak_ptr<Spell> GetWeakPtr() const;

protected:
void SendLoot(ObjectGuid guid, LootType loottype, LockType lockType);
void SendLoot(ObjectGuid guid, LootType loottype, LockType lockType, Player* player);
bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data
void UpdateOriginalCasterPointer();

Expand Down
15 changes: 8 additions & 7 deletions src/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5553,7 +5553,7 @@ void Spell::EffectEnergisePct(SpellEffectIndex eff_idx)
m_caster->EnergizeBySpell(unitTarget, m_spellInfo, gain, power);
}

void Spell::SendLoot(ObjectGuid guid, LootType loottype, LockType lockType)
void Spell::SendLoot(ObjectGuid guid, LootType loottype, LockType lockType, Player* player)
{
switch (guid.GetHigh())
{
Expand All @@ -5573,7 +5573,7 @@ void Spell::SendLoot(ObjectGuid guid, LootType loottype, LockType lockType)
return;

case GAMEOBJECT_TYPE_CHEST:
gameObjTarget->Use(m_caster);
gameObjTarget->Use(player);
// Don't return, let loots been taken
break;

Expand Down Expand Up @@ -5631,14 +5631,15 @@ void Spell::SendLoot(ObjectGuid guid, LootType loottype, LockType lockType)

void Spell::EffectOpenLock(SpellEffectIndex eff_idx)
{
if (!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
Player* player = dynamic_cast<Player*>(m_trueCaster);
if (!player && m_trueCaster->IsUnit())
player = const_cast<Player*>(static_cast<Unit*>(m_trueCaster)->GetControllingPlayer());
if (!player)
{
DEBUG_LOG("WORLD: Open Lock - No Player Caster!");
return;
}

Player* player = (Player*)m_caster;

uint32 lockId;

// Get lockId
Expand Down Expand Up @@ -5687,13 +5688,13 @@ void Spell::EffectOpenLock(SpellEffectIndex eff_idx)
// only send loot if owner is player, else client sends release anyway
if (itemTarget->GetOwnerGuid() == m_caster->GetObjectGuid())
{
SendLoot(itemTarget->GetObjectGuid(), LOOT_SKINNING, LockType(m_spellInfo->EffectMiscValue[eff_idx]));
SendLoot(itemTarget->GetObjectGuid(), LOOT_SKINNING, LockType(m_spellInfo->EffectMiscValue[eff_idx]), player);
m_spellLog.AddLog(uint32(SPELL_EFFECT_OPEN_LOCK), itemTarget->GetPackGUID());
}
}
else
{
SendLoot(gameObjTarget->GetObjectGuid(), LOOT_SKINNING, LockType(m_spellInfo->EffectMiscValue[eff_idx]));
SendLoot(gameObjTarget->GetObjectGuid(), LOOT_SKINNING, LockType(m_spellInfo->EffectMiscValue[eff_idx]), player);
m_spellLog.AddLog(uint32(SPELL_EFFECT_OPEN_LOCK), gameObjTarget->GetPackGUID());
}
}
Expand Down

0 comments on commit e3752ec

Please sign in to comment.