Skip to content

Commit d537671

Browse files
killerwiferobinsch
andcommitted
GameObject: Add rest of CanUseNow for GO checks
Co-Authored-By: robinsch <robinsch@users.noreply.github.com>
1 parent 241c5fe commit d537671

3 files changed

Lines changed: 53 additions & 18 deletions

File tree

src/game/Entities/GameObject.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,40 @@ bool GameObject::CanUseNow(Player const* player) const
15121512
}
15131513
}
15141514

1515+
if (!GetGOInfo()->GetLockId())
1516+
{
1517+
// ignore for remote control state
1518+
if (!player->IsSelfMover())
1519+
{
1520+
// check player on vehicle
1521+
if (!player->GetTransportInfo() || !player->GetTransportInfo()->IsOnVehicle() || !GetGOInfo()->IsUsableMounted())
1522+
return false;
1523+
}
1524+
1525+
// We can't interact with anyone while being shapeshifted, unless form flags allow us to do so
1526+
if (player->IsShapeShifted())
1527+
{
1528+
if (SpellShapeshiftFormEntry const* formEntry = sSpellShapeshiftFormStore.LookupEntry(player->GetShapeshiftForm()))
1529+
{
1530+
if (!(formEntry->flags1 & SHAPESHIFT_FLAG_CAN_NPC_INTERACT) && player->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_TAXI_FLIGHT)) // meant to have an can unshift check here
1531+
return false;
1532+
}
1533+
else
1534+
return false;
1535+
}
1536+
}
1537+
1538+
// client checks this but needs recheck
1539+
if (GetGOInfo()->IsUsableInCombat() && player->IsInCombat())
1540+
return false;
1541+
1542+
// client checks this but needs recheck
1543+
if (GetGOInfo()->CannotBeUsedUnderImmunity() && player->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE))
1544+
return false;
1545+
1546+
if (HasFlag(GAMEOBJECT_FLAGS, GO_FLAG_LOCKED) && !GetSpellForLock(player)) // we should not allow use of a locked GO
1547+
return false;
1548+
15151549
return true;
15161550
}
15171551

@@ -2947,10 +2981,17 @@ SpellEntry const* GameObject::GetSpellForLock(Player const* player) const
29472981

29482982
for (auto&& playerSpell : player->GetSpellMap())
29492983
if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(playerSpell.first))
2950-
for (uint32 i = 0; i < MAX_EFFECT_INDEX; ++i)
2951-
if (spellInfo->Effect[i] == SPELL_EFFECT_OPEN_LOCK && ((uint32)spellInfo->EffectMiscValue[i]) == lock->Index[i])
2952-
if (player->CalculateSpellEffectValue(nullptr, spellInfo, SpellEffectIndex(i), nullptr) >= int32(lock->Skill[i]))
2984+
for (uint32 effIdx = 0; effIdx < MAX_EFFECT_INDEX; ++effIdx)
2985+
if (spellInfo->Effect[effIdx] == SPELL_EFFECT_OPEN_LOCK && ((uint32)spellInfo->EffectMiscValue[effIdx]) == lock->Index[i])
2986+
{
2987+
uint32 minRequiredSkill;
2988+
if (lock->Skill[i])
2989+
minRequiredSkill = lock->Skill[i];
2990+
else
2991+
minRequiredSkill = GetLevel() * 5;
2992+
if (player->CalculateSpellEffectValue(nullptr, spellInfo, SpellEffectIndex(effIdx), nullptr) >= int32(minRequiredSkill))
29532993
return spellInfo;
2994+
}
29542995
}
29552996

29562997
return nullptr;

src/game/Entities/GameObject.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,15 @@ struct GameObjectInfo
587587
}
588588
}
589589

590+
bool IsUsableInCombat() const
591+
{
592+
switch (type)
593+
{
594+
case GAMEOBJECT_TYPE_CHEST: return chest.notInCombat == 0;
595+
default: return true;
596+
}
597+
}
598+
590599
bool IsInfiniteGameObject() const
591600
{
592601
switch (type)

src/game/Spells/SpellHandler.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,24 +321,13 @@ void WorldSession::HandleGameObjectUseOpcode(WorldPacket& recv_data)
321321
return;
322322
}
323323

324-
// ignore for remote control state
325-
if (!_player->IsSelfMover())
326-
{
327-
// check player on vehicle
328-
if (!_player->GetTransportInfo() || !_player->GetTransportInfo()->IsOnVehicle() || !obj->GetGOInfo()->IsUsableMounted())
329-
return;
330-
}
331-
332324
// Never expect this opcode for some type GO's
333325
if (obj->GetGoType() == GAMEOBJECT_TYPE_GENERIC)
334326
{
335327
sLog.outError("HandleGameObjectUseOpcode: CMSG_GAMEOBJ_USE for not allowed GameObject type %u (Entry %u), didn't expect this to happen.", obj->GetGoType(), obj->GetEntry());
336328
return;
337329
}
338330

339-
if (obj->HasFlag(GAMEOBJECT_FLAGS, GO_FLAG_LOCKED)) // we should not allow use of a locked GO
340-
return;
341-
342331
if (obj->HasFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE))
343332
return;
344333

@@ -349,10 +338,6 @@ void WorldSession::HandleGameObjectUseOpcode(WorldPacket& recv_data)
349338
return;
350339
}
351340

352-
// client checks this but needs recheck
353-
if (obj->GetGOInfo()->CannotBeUsedUnderImmunity() && _player->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE))
354-
return;
355-
356341
if (!obj->CanUseNow(_player))
357342
return;
358343

0 commit comments

Comments
 (0)