diff --git a/src/game/Handlers/PetHandler.cpp b/src/game/Handlers/PetHandler.cpp index 4346d7771..c686cf7bf 100644 --- a/src/game/Handlers/PetHandler.cpp +++ b/src/game/Handlers/PetHandler.cpp @@ -220,9 +220,9 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data) case ACT_PASSIVE: // 0x01 case ACT_ENABLED: // 0xC1 spell { - Unit* unit_target = nullptr; + Unit* pUnitTarget = nullptr; if (targetGuid) - unit_target = _player->GetMap()->GetUnit(targetGuid); + pUnitTarget = _player->GetMap()->GetUnit(targetGuid); // do not cast unknown spells SpellEntry const* spellInfo = sSpellMgr.GetSpellEntry(spellid); @@ -233,88 +233,56 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data) } if (!pCharmedUnit->IsSpellReady(*spellInfo)) - return; - - // Why is this here? - for (uint32 i : spellInfo->EffectImplicitTargetA) { - if (i == TARGET_ENUM_UNITS_ENEMY_AOE_AT_SRC_LOC || i == TARGET_ENUM_UNITS_ENEMY_AOE_AT_DEST_LOC || i == TARGET_ENUM_UNITS_ENEMY_AOE_AT_DYNOBJ_LOC) - return; + pCharmedUnit->SendPetCastFail(spellid, SPELL_FAILED_NOT_READY); + return; } // do not cast not learned spells if (!pCharmedUnit->HasSpell(spellid) || spellInfo->IsPassiveSpell()) + { + pCharmedUnit->SendPetCastFail(spellid, SPELL_FAILED_NOT_KNOWN); return; + } + + bool const explicitlySelectedTarget = Spells::IsExplicitlySelectedUnitTarget(spellInfo->EffectImplicitTargetA[0]); + + if (!pUnitTarget && explicitlySelectedTarget) + { + pCharmedUnit->SendPetCastFail(spellid, SPELL_FAILED_BAD_IMPLICIT_TARGETS); + return; + } + + if (pUnitTarget == pCharmedUnit && + // Cannot cast negative spells on yourself. Handle it here since casting negative + // spells on yourself is frequently used within the core itself for certain mechanics. + ((explicitlySelectedTarget && !spellInfo->IsPositiveSpell(pCharmedUnit, pUnitTarget)) || + // spells not castable on self like Fire Shield + spellInfo->HasAttribute(SPELL_ATTR_EX_CANT_TARGET_SELF))) + { + pCharmedUnit->SendPetCastFail(spellid, SPELL_FAILED_BAD_TARGETS); + return; + } + + // remove not needed target + if (pUnitTarget && pUnitTarget != pCharmedUnit && !explicitlySelectedTarget) + pUnitTarget = nullptr; + + // make sure pet is facing target + if (pUnitTarget && pUnitTarget != pCharmedUnit && !pUnitTarget->HasUnitState(UNIT_STAT_CAN_NOT_REACT) && + spellInfo->IsNeedFaceTarget() && !pCharmedUnit->IsFacingTarget(pUnitTarget)) + { + float orientation = pCharmedUnit->GetAngle(pUnitTarget); + pCharmedUnit->SetFacingTo(orientation); + pCharmedUnit->SetOrientation(orientation); + } pCharmedUnit->ClearUnitState(UNIT_STAT_MOVING); - - Spell* spell = new Spell(pCharmedUnit, spellInfo, false); - - SpellCastResult result = spell->CheckPetCast(unit_target); - - // auto turn to target unless possessed - if (result == SPELL_FAILED_UNIT_NOT_INFRONT && !pCharmedUnit->HasAuraType(SPELL_AURA_MOD_POSSESS)) - { - if (unit_target) - { - pCharmedUnit->SetInFront(unit_target); - if (unit_target->GetTypeId() == TYPEID_PLAYER) - pCharmedUnit->SendCreateUpdateToPlayer((Player*)unit_target); - } - else if (Unit* unit_target2 = spell->m_targets.getUnitTarget()) - { - pCharmedUnit->SetInFront(unit_target2); - if (unit_target2->GetTypeId() == TYPEID_PLAYER) - pCharmedUnit->SendCreateUpdateToPlayer((Player*)unit_target2); - } - if (Unit* powner = pCharmedUnit->GetCharmerOrOwner()) - if (powner->GetTypeId() == TYPEID_PLAYER) - pCharmedUnit->SendCreateUpdateToPlayer((Player*)powner); - result = SPELL_CAST_OK; - } - - if (result == SPELL_CAST_OK) - { - if (((Creature*)pCharmedUnit)->IsPet()) - ((Pet*)pCharmedUnit)->CheckLearning(spellid); - - unit_target = spell->m_targets.getUnitTarget(); - - // 10% chance to play special pet attack talk, else growl - // actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell - if (((Creature*)pCharmedUnit)->IsPet() && (((Pet*)pCharmedUnit)->getPetType() == SUMMON_PET) && (pCharmedUnit != unit_target) && (urand(0, 100) < 10)) - pCharmedUnit->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL); - else - pCharmedUnit->SendPetAIReaction(); - - if (unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pCharmedUnit->HasAuraType(SPELL_AURA_MOD_POSSESS)) - { - // This is true if pet has no target or has target but targets differs. - if (pCharmedUnit->GetVictim() != unit_target) - { - if (pCharmedUnit->GetVictim()) - pCharmedUnit->AttackStop(); - pCharmedUnit->GetMotionMaster()->Clear(); - if (((Creature*)pCharmedUnit)->AI()) - ((Creature*)pCharmedUnit)->AI()->AttackStart(unit_target); - } - } - - spell->prepare(); - } - else - { - if (pCharmedUnit->HasAuraType(SPELL_AURA_MOD_POSSESS)) - Spell::SendCastResult(GetPlayer(), spellInfo, result); - else - pCharmedUnit->SendPetCastFail(spellid, result); - - if (((Creature*)pCharmedUnit)->IsSpellReady(*spellInfo)) - GetPlayer()->SendClearCooldown(spellid, ((Creature*)pCharmedUnit)); - - spell->finish(false); - spell->Delete(); - } + auto result = pCharmedUnit->CastSpell(pUnitTarget, spellInfo, false); + if (result != SPELL_CAST_OK) + pCharmedUnit->SendPetCastFail(spellid, result); + else if (((Creature*)pCharmedUnit)->IsPet()) + ((Pet*)pCharmedUnit)->CheckLearning(spellid); break; } default: diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp index f692f84d4..509bdbb49 100644 --- a/src/game/Objects/Object.cpp +++ b/src/game/Objects/Object.cpp @@ -1827,24 +1827,9 @@ bool WorldObject::HasInArc(WorldObject const* target, float const arcangle, floa return ((angle >= lborder) && (angle <= rborder)); } -bool WorldObject::isInFrontInMap(WorldObject const* target, float distance, float arc) const +bool WorldObject::IsFacingTarget(WorldObject const* target) const { - return IsWithinDistInMap(target, distance) && HasInArc(target, arc); -} - -bool WorldObject::isInBackInMap(WorldObject const* target, float distance, float arc) const -{ - return IsWithinDistInMap(target, distance) && !HasInArc(target, 2 * M_PI_F - arc); -} - -bool WorldObject::isInFront(WorldObject const* target, float distance, float arc) const -{ - return IsWithinDist(target, distance) && HasInArc(target, arc); -} - -bool WorldObject::isInBack(WorldObject const* target, float distance, float arc) const -{ - return IsWithinDist(target, distance) && !HasInArc(target, 2 * M_PI_F - arc); + return (GetDistance2dToCenter(target) < NO_FACING_CHECKS_DISTANCE) || HasInArc(target); } bool WorldObject::GetRandomPoint(float x, float y, float z, float distance, float &rand_x, float &rand_y, float &rand_z) const diff --git a/src/game/Objects/Object.h b/src/game/Objects/Object.h index 628bd0696..c7e52d829 100644 --- a/src/game/Objects/Object.h +++ b/src/game/Objects/Object.h @@ -737,10 +737,7 @@ class WorldObject : public Object float GetAngle(float const x, float const y) const; bool HasInArc(WorldObject const* target, float const arcangle = M_PI, float offset = 0.0f) const; bool HasInArc(float const arcangle, float const x, float const y) const; - bool isInFrontInMap(WorldObject const* target,float distance, float arc = M_PI) const; - bool isInBackInMap(WorldObject const* target, float distance, float arc = M_PI) const; - bool isInFront(WorldObject const* target,float distance, float arc = M_PI) const; - bool isInBack(WorldObject const* target, float distance, float arc = M_PI) const; + bool IsFacingTarget(WorldObject const* target) const; bool CanReachWithMeleeSpellAttack(WorldObject const* pVictim, float flat_mod = 0.0f) const; float GetLeewayBonusRange(Unit const* target, bool ability) const; diff --git a/src/game/Objects/Pet.cpp b/src/game/Objects/Pet.cpp index 479fbb2dd..5dc394650 100644 --- a/src/game/Objects/Pet.cpp +++ b/src/game/Objects/Pet.cpp @@ -2331,6 +2331,14 @@ void Pet::CastPetAura(PetAura const* aura) CastSpell(this, auraId, true); } +void Pet::RemoveAllCooldowns(bool sendOnly) +{ + SpellCaster::RemoveAllCooldowns(sendOnly); + + if (Player const* pOwner = GetCharmerOrOwnerPlayerOrPlayerItself()) + pOwner->SendClearAllCooldowns(this); +} + void Pet::SynchronizeLevelWithOwner() { Unit* owner = GetOwner(); diff --git a/src/game/Objects/Pet.h b/src/game/Objects/Pet.h index 852ff0e1a..992dfe8b3 100644 --- a/src/game/Objects/Pet.h +++ b/src/game/Objects/Pet.h @@ -222,6 +222,8 @@ class Pet : public Creature void CastPetAuras(bool current); void CastPetAura(PetAura const* aura); + virtual void RemoveAllCooldowns(bool sendOnly = false) override; + void _LoadSpellCooldowns(); void _SaveSpellCooldowns(); void _LoadAuras(uint32 timediff); diff --git a/src/game/Objects/Player.h b/src/game/Objects/Player.h index d51edf275..2fa423d65 100644 --- a/src/game/Objects/Player.h +++ b/src/game/Objects/Player.h @@ -1495,7 +1495,7 @@ class Player final: public Unit virtual void AddCooldown(SpellEntry const& spellEntry, ItemPrototype const* itemProto = nullptr, bool permanent = false, uint32 forcedDuration = 0) override; virtual void RemoveSpellCooldown(SpellEntry const& spellEntry, bool updateClient = true) override; virtual void RemoveSpellCategoryCooldown(uint32 category, bool updateClient = true) override; - virtual void RemoveAllCooldowns(bool sendOnly = false); + virtual void RemoveAllCooldowns(bool sendOnly = false) override; virtual void LockOutSpells(SpellSchoolMask schoolMask, uint32 duration) override; void RemoveSpellLockout(SpellSchoolMask spellSchoolMask, std::set* spellAlreadySent = nullptr); void SendClearCooldown(uint32 spellId, Unit* target) const; diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index 9c1a54a81..51783491a 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -2406,7 +2406,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& } case TARGET_ENUM_UNITS_ENEMY_AOE_AT_SRC_LOC: { - FillAreaTargets(targetUnitMap, radius, PUSH_DEST_CENTER, SPELL_TARGETS_AOE_DAMAGE); + FillAreaTargets(targetUnitMap, radius, PUSH_SRC_CENTER, SPELL_TARGETS_AOE_DAMAGE); float minDist = -1; #if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4 @@ -2449,7 +2449,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& // fill real target list if no spell script target defined FillAreaTargets(bounds.first != bounds.second ? tempTargetUnitMap : targetUnitMap, - radius, PUSH_DEST_CENTER, SPELL_TARGETS_ALL); + radius, PUSH_SRC_CENTER, SPELL_TARGETS_ALL); if (!tempTargetUnitMap.empty()) { @@ -2636,7 +2636,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& break; case TARGET_ENUM_UNITS_FRIEND_AOE_AT_SRC_LOC: // selected friendly units (for casting objects) around casting object - FillAreaTargets(targetUnitMap, radius, PUSH_SELF_CENTER, SPELL_TARGETS_FRIENDLY, GetCastingObject()); + FillAreaTargets(targetUnitMap, radius, PUSH_SRC_CENTER, SPELL_TARGETS_FRIENDLY, GetCastingObject()); break; case TARGET_ENUM_UNITS_FRIEND_AOE_AT_DEST_LOC: FillAreaTargets(targetUnitMap, radius, PUSH_DEST_CENTER, SPELL_TARGETS_FRIENDLY); @@ -6136,8 +6136,7 @@ SpellCastResult Spell::CheckCast(bool strict) // hart version required facing if (m_targets.getUnitTarget() && !m_caster->IsFriendlyTo(m_targets.getUnitTarget()) && - (m_caster->GetDistance2dToCenter(m_targets.getUnitTarget()) > NO_FACING_CHECKS_DISTANCE) && - !m_caster->HasInArc(m_targets.getUnitTarget())) + !m_caster->IsFacingTarget(m_targets.getUnitTarget())) return SPELL_FAILED_UNIT_NOT_INFRONT; } else if (m_spellInfo->Id == 13278) // Gnomish Death Ray @@ -7276,8 +7275,7 @@ SpellCastResult Spell::CheckRange(bool strict) return SPELL_CAST_OK; // Requires target forward for these spells - if ((m_caster->GetDistance2dToCenter(target) > NO_FACING_CHECKS_DISTANCE) && - !m_caster->HasInArc(target)) + if (!m_caster->IsFacingTarget(target)) return SPELL_FAILED_UNIT_NOT_INFRONT; float range_mod = 1.0f; @@ -7330,8 +7328,7 @@ SpellCastResult Spell::CheckRange(bool strict) return SPELL_FAILED_TOO_CLOSE; if (m_caster->IsPlayer() && (m_spellInfo->Custom & SPELL_CUSTOM_FACE_TARGET) && - (m_caster->GetDistance2dToCenter(target) > NO_FACING_CHECKS_DISTANCE) && - !m_caster->HasInArc(target)) + !m_caster->IsFacingTarget(target)) return SPELL_FAILED_UNIT_NOT_INFRONT; } @@ -8406,6 +8403,10 @@ public: i_centerY = i_castingObject->GetPositionY(); } break; + case PUSH_SRC_CENTER: + i_centerX = i_spell.m_targets.m_srcX; + i_centerY = i_spell.m_targets.m_srcY; + break; case PUSH_DEST_CENTER: i_centerX = i_spell.m_targets.m_destX; i_centerY = i_spell.m_targets.m_destY; @@ -8507,25 +8508,29 @@ public: switch (i_push_type) { case PUSH_IN_FRONT: - if (i_castingObject->isInFront(unit, i_radius, 2 * M_PI_F / 3)) + if (i_castingObject->IsWithinDist(unit, i_radius) && i_castingObject->HasInArc(unit, 2 * M_PI_F / 3)) i_data->push_back(unit); break; case PUSH_IN_FRONT_90: - if (i_castingObject->isInFront(unit, i_radius, M_PI_F / 2)) + if (i_castingObject->IsWithinDist(unit, i_radius) && i_castingObject->HasInArc(unit, M_PI_F / 2)) i_data->push_back(unit); break; case PUSH_IN_FRONT_15: - if (i_castingObject->isInFront(unit, i_radius, M_PI_F / 12)) + if (i_castingObject->IsWithinDist(unit, i_radius) && i_castingObject->HasInArc(unit, M_PI_F / 12)) i_data->push_back(unit); break; case PUSH_IN_BACK: // 75 - if (i_castingObject->isInBack(unit, i_radius, 5 * M_PI_F / 12)) + if (i_castingObject->IsWithinDist(unit, i_radius) && !i_castingObject->HasInArc(unit, 2 * M_PI_F - 5 * M_PI_F / 12)) i_data->push_back(unit); break; case PUSH_SELF_CENTER: if (i_castingObject->IsWithinDist(unit, i_radius)) i_data->push_back(unit); break; + case PUSH_SRC_CENTER: + if (itr->getSource()->IsWithinDist3d(i_spell.m_targets.m_srcX, i_spell.m_targets.m_srcY, i_spell.m_targets.m_srcZ, i_radius)) + i_data->push_back(unit); + break; case PUSH_DEST_CENTER: if (itr->getSource()->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ, i_radius)) i_data->push_back(unit); diff --git a/src/game/Spells/Spell.h b/src/game/Spells/Spell.h index e5c766c87..6fd4a5f7e 100644 --- a/src/game/Spells/Spell.h +++ b/src/game/Spells/Spell.h @@ -68,6 +68,7 @@ enum SpellNotifyPushType PUSH_IN_FRONT_15, PUSH_IN_BACK, PUSH_SELF_CENTER, + PUSH_SRC_CENTER, PUSH_DEST_CENTER, PUSH_TARGET_CENTER }; diff --git a/src/game/Spells/SpellEntry.h b/src/game/Spells/SpellEntry.h index cd855b221..a6a110415 100644 --- a/src/game/Spells/SpellEntry.h +++ b/src/game/Spells/SpellEntry.h @@ -234,10 +234,11 @@ namespace Spells case TARGET_UNIT_ENEMY: case TARGET_UNIT_FRIEND: case TARGET_UNIT: + case TARGET_UNIT_PARTY: case TARGET_UNIT_FRIEND_CHAIN_HEAL: case TARGET_LOCATION_CASTER_TARGET_POSITION : case TARGET_UNIT_RAID: - //case TARGET_UNIT_RAID_AND_CLASS: + case TARGET_UNIT_RAID_AND_CLASS: return true; } return false; @@ -890,6 +891,11 @@ class SpellEntry return false; } + inline bool IsNeedFaceTarget() const + { + return ((Custom & SPELL_CUSTOM_FACE_TARGET) || (rangeIndex == SPELL_RANGE_IDX_COMBAT)); + } + inline bool IsNeedCastSpellAtFormApply(ShapeshiftForm form) const { if (!(Attributes & (SPELL_ATTR_PASSIVE | SPELL_ATTR_HIDDEN_CLIENTSIDE)) || !form) diff --git a/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp b/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp index 48ebbf5c9..7cc1077bf 100644 --- a/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp +++ b/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp @@ -773,7 +773,7 @@ struct npc_residual_montruosityAI : public ScriptedAI { if (itr != m_creature) { - if (!itr->isInFrontInMap(m_creature, 45.0f, M_PI_F)) + if (!(itr->IsWithinDistInMap(m_creature, 45.0f) && itr->HasInArc(m_creature))) { float distance = m_creature->GetDistance(itr); if (distance < closestbefore)