diff --git a/sql/migrations/20231105013729_world.sql b/sql/migrations/20231105013729_world.sql new file mode 100644 index 000000000..921bf0db3 --- /dev/null +++ b/sql/migrations/20231105013729_world.sql @@ -0,0 +1,21 @@ +DROP PROCEDURE IF EXISTS add_migration; +delimiter ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20231105013729'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20231105013729'); +-- Add your query below. + + +-- Remove custom change to icon of Consecration. +DELETE FROM `spell_mod` WHERE `Id` IN (20116, 20922, 20923, 20924, 26573); + + +-- End of migration. +END IF; +END?? +delimiter ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/Maps/GridNotifiersImpl.h b/src/game/Maps/GridNotifiersImpl.h index 0180a7724..9cd51a14d 100644 --- a/src/game/Maps/GridNotifiersImpl.h +++ b/src/game/Maps/GridNotifiersImpl.h @@ -127,33 +127,27 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target) if (!target->CanSeeInWorld(i_check)) return; - if (!target->IsAlive() || target->IsTaxiFlying()) - return; - - if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->IsImmuneToAoe()) - return; - if (!i_dynobject.IsWithinDistInMap(target, i_dynobject.GetRadius())) return; - //Check targets for not_selectable unit flag and remove - if (target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SPAWNING | UNIT_FLAG_NOT_SELECTABLE)) - return; + if (target->IsCreature()) + { + if (((Creature*)target)->IsImmuneToAoe()) + return; - if (i_dynobject.GetCasterGuid().IsPlayer() && target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER)) - return; - - // Evade target - if (target->GetTypeId()==TYPEID_UNIT && ((Creature*)target)->IsInEvadeMode()) - return; - - //Check player targets and remove if in GM mode or GM invisibility (for not self casting case) - if (target->GetTypeId() == TYPEID_PLAYER && target != i_check && (((Player*)target)->IsGameMaster() || ((Player*)target)->GetVisibility() == VISIBILITY_OFF)) - return; + if (((Creature*)target)->IsInEvadeMode()) + return; + } + else + { + //Check player targets and remove if in GM mode or GM invisibility (for not self casting case) + if (target != i_check && (((Player*)target)->IsGameMaster() || ((Player*)target)->GetVisibility() == VISIBILITY_OFF)) + return; + } if (!i_positive && !i_check->IsValidAttackTarget(target)) return; - if (i_positive && !i_check->IsFriendlyTo(target)) + if (i_positive && !i_check->IsValidHelpfulTarget(target)) return; // Must check LoS with the target to prevent casting through objects by targeting @@ -166,14 +160,19 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target) Unit* pUnit = i_check->ToUnit(); - // Negative AoE from non flagged players cannot target other players + // World of Warcraft Client Patch 1.7.0 (2005-09-13) + // - Consecration and other similar spells can no longer be used by + // non-PvP flagged players to damage PvP flagged enemies. +#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_6_1 if (!i_positive) { + // Negative AoE from non flagged players cannot target other players if (Player* attackerPlayer = pUnit ? pUnit->GetCharmerOrOwnerPlayerOrPlayerItself() : nullptr) if (Player* attackedPlayer = target->GetCharmerOrOwnerPlayerOrPlayerItself()) if (!attackerPlayer->IsPvP() && !(attackerPlayer->IsFFAPvP() && attackedPlayer->IsFFAPvP()) && !attackerPlayer->IsInDuelWith(attackedPlayer)) return; } +#endif SpellEntry const* spellInfo = sSpellMgr.GetSpellEntry(i_dynobject.GetSpellId()); SpellEffectIndex eff_index = i_dynobject.GetEffIndex(); diff --git a/src/game/Objects/DynamicObject.cpp b/src/game/Objects/DynamicObject.cpp index b5fb1b7c5..871cccbb8 100644 --- a/src/game/Objects/DynamicObject.cpp +++ b/src/game/Objects/DynamicObject.cpp @@ -158,6 +158,11 @@ Unit* DynamicObject::GetUnitCaster() const return nullptr; } +Player* DynamicObject::GetAffectingPlayer() const +{ + return ::ToPlayer(GetUnitCaster()); +} + uint32 DynamicObject::GetFactionTemplateId() const { return GetCaster()->GetFactionTemplateId(); diff --git a/src/game/Objects/DynamicObject.h b/src/game/Objects/DynamicObject.h index d5ad0805a..e9a54dc65 100644 --- a/src/game/Objects/DynamicObject.h +++ b/src/game/Objects/DynamicObject.h @@ -52,6 +52,8 @@ class DynamicObject : public WorldObject ObjectGuid const& GetCasterGuid() const { return GetGuidValue(DYNAMICOBJECT_CASTER); } SpellCaster* GetCaster() const; Unit* GetUnitCaster() const; + Player* GetAffectingPlayer() const final; + bool IsCharmerOrOwnerPlayerOrPlayerItself() const final { return GetCasterGuid().IsPlayer(); } float GetRadius() const { return m_radius; } DynamicObjectType GetType() const { return (DynamicObjectType)GetByteValue(DYNAMICOBJECT_BYTES,0); } bool NeedsRefresh(Unit* unit) const; diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp index 285bb1669..b2ef2ed31 100644 --- a/src/game/Objects/Object.cpp +++ b/src/game/Objects/Object.cpp @@ -3653,3 +3653,45 @@ bool WorldObject::IsValidAttackTarget(Unit const* target, bool checkAlive) const } return true; } + +bool WorldObject::IsValidHelpfulTarget(Unit const* target, bool checkAlive) const +{ + ASSERT(target); + + // this unit flag prevents casting on friendly or self too + if (target == this) + return !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE_2); + + if (FindMap() != target->FindMap()) + return false; + + if (!target->IsTargetableBy(this, false, checkAlive, true)) + return false; + + if (GetReactionTo(target) < REP_UNFRIENDLY || + target->GetReactionTo(this) < REP_UNFRIENDLY) + return false; + + Player const* playerAffectingAttacker = GetAffectingPlayer(); + Player const* playerAffectingTarget = target->GetAffectingPlayer(); + + // PvP checks + if (playerAffectingAttacker && playerAffectingTarget) + { + // pet and owner + if (playerAffectingAttacker == playerAffectingTarget) + return true; + + // cannot help others in duels + if (playerAffectingAttacker->duel && playerAffectingAttacker->duel->startTime != 0 || + playerAffectingTarget->duel && playerAffectingTarget->duel->startTime != 0) + return false; + + // group forces friendly relations in ffa pvp + if (playerAffectingAttacker->IsFFAPvP() && playerAffectingTarget->IsFFAPvP() && + !playerAffectingAttacker->IsInSameRaidWith(playerAffectingTarget)) + return false; + } + + return true; +} diff --git a/src/game/Objects/Object.h b/src/game/Objects/Object.h index 4d42613bf..e7a19574a 100644 --- a/src/game/Objects/Object.h +++ b/src/game/Objects/Object.h @@ -906,6 +906,7 @@ class WorldObject : public Object virtual ReputationRank GetReactionTo(WorldObject const* target) const; ReputationRank static GetFactionReactionTo(FactionTemplateEntry const* factionTemplateEntry, WorldObject const* target); bool IsValidAttackTarget(Unit const* target, bool checkAlive = true) const; + bool IsValidHelpfulTarget(Unit const* target, bool checkAlive = true) const; virtual void SaveRespawnTime() {} void AddObjectToRemoveList(); diff --git a/src/game/Objects/Unit.cpp b/src/game/Objects/Unit.cpp index 5a8cce359..af0c65c2d 100644 --- a/src/game/Objects/Unit.cpp +++ b/src/game/Objects/Unit.cpp @@ -6119,7 +6119,6 @@ void Unit::SetInCombatWithVictim(Unit* pVictim, bool touchOnly/* = false*/, uint } } - void Unit::ClearInCombat() { m_combatTimer = 0; @@ -6133,37 +6132,45 @@ void Unit::ClearInCombat() } } -bool Unit::IsTargetableBy(WorldObject const* pAttacker, bool forAoE, bool checkAlive) const +bool Unit::IsTargetableBy(WorldObject const* pCaster, bool forAoE, bool checkAlive, bool helpful) const { - if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE)) + // applies to both harmful and helpful + if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE_2)) return false; if (checkAlive && !IsAlive()) return false; - if (Player const* pPlayer = ToPlayer()) + if (!helpful) { - if (pPlayer->IsGameMaster() || pPlayer->GetCurrentCinematicEntry() != 0) - return false; - } - - if (pAttacker) - { - if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SPAWNING | UNIT_FLAG_TAXI_FLIGHT | UNIT_FLAG_NOT_ATTACKABLE_1 | UNIT_FLAG_NON_ATTACKABLE_2)) + if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SPAWNING | UNIT_FLAG_TAXI_FLIGHT | UNIT_FLAG_NOT_ATTACKABLE_1 | UNIT_FLAG_NOT_SELECTABLE)) return false; - if (IsTaxiFlying()) - return false; + if (Player const* pPlayer = ToPlayer()) + { + if (pPlayer->IsGameMaster()) + return false; + + if (pPlayer->GetCurrentCinematicEntry() != 0) + return false; + + if (IsTaxiFlying()) + return false; + } if (!forAoE && !CanBeDetected()) return false; + } - if (pAttacker->IsCharmerOrOwnerPlayerOrPlayerItself()) + if (pCaster) + { + if (pCaster->IsCharmerOrOwnerPlayerOrPlayerItself()) { + // applies to both harmful and helpful if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER)) return false; } - else // non player attacker + else if (!helpful) // non player attacker { if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC)) return false; @@ -6173,16 +6180,16 @@ bool Unit::IsTargetableBy(WorldObject const* pAttacker, bool forAoE, bool checkA } // attacker flags prevent attacking victim too - if (pAttacker->IsUnit()) + if (!helpful && pCaster->IsUnit()) { if (IsCharmerOrOwnerPlayerOrPlayerItself()) { - if (pAttacker->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER)) + if (pCaster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER)) return false; } else // non player victim { - if (pAttacker->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC)) + if (pCaster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC)) return false; } } diff --git a/src/game/Objects/Unit.h b/src/game/Objects/Unit.h index af0a92f80..09ea7e5c3 100644 --- a/src/game/Objects/Unit.h +++ b/src/game/Objects/Unit.h @@ -1014,7 +1014,7 @@ class Unit : public SpellCaster void AddExtraAttackOnUpdate() { m_doExtraAttacks = true; }; bool CanAttack(Unit const* target, bool force = false) const; - bool IsTargetableBy(WorldObject const* pAttacker, bool forAoE = false, bool checkAlive = true) const; + bool IsTargetableBy(WorldObject const* pCaster, bool forAoE = false, bool checkAlive = true, bool helpful = false) const; bool CanReachWithMeleeAutoAttack(Unit const* pVictim, float flat_mod = 0.0f) const; bool CanReachWithMeleeAutoAttackAtPosition(Unit const* pVictim, float x, float y, float z, float flat_mod = 0.0f) const; diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index 083733ede..f5a0277f4 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -2751,7 +2751,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& // remove not targetable units if spell has no script targets for (UnitList::iterator itr = targetUnitMap.begin(); itr != targetUnitMap.end();) { - if (!(*itr)->IsTargetableBy(m_caster, true, false) || !m_spellInfo->CanTargetAliveState((*itr)->IsAlive())) + if (!(*itr)->IsTargetableBy(m_caster, true, false, m_spellInfo->IsPositiveSpell(m_caster, *itr)) || !m_spellInfo->CanTargetAliveState((*itr)->IsAlive())) targetUnitMap.erase(itr++); else ++itr; @@ -5956,20 +5956,6 @@ SpellCastResult Spell::CheckCast(bool strict) if (strict && m_spellInfo->HasAttribute(SPELL_ATTR_EX3_ONLY_ON_PLAYER) && target->GetTypeId() != TYPEID_PLAYER && !m_spellInfo->IsAreaOfEffectSpell()) return SPELL_FAILED_BAD_TARGETS; } - // Can't help a friend in duel | sorry, not enough time to figure out why this is necessary - if (m_spellInfo->IsPositiveSpell() && m_spellInfo->Id != 28697) - { - Player* casterOwner = m_casterUnit ? m_casterUnit->GetCharmerOrOwnerPlayerOrPlayerItself() : nullptr; - Player* targetOwner = target->GetCharmerOrOwnerPlayerOrPlayerItself(); - - if (m_spellInfo->Id == 7266 && targetOwner && targetOwner->duel && casterOwner && !casterOwner->IsInDuelWith(targetOwner)) - { - return SPELL_FAILED_TARGET_DUELING; - } - - if (targetOwner && casterOwner != targetOwner && targetOwner->duel && targetOwner->duel->startTime && casterOwner && !casterOwner->IsInDuelWith(targetOwner)) - return SPELL_FAILED_TARGET_DUELING; - } } else if (m_caster == target) { @@ -6048,7 +6034,6 @@ SpellCastResult Spell::CheckCast(bool strict) // simple cases bool explicit_target_mode = false; - bool target_hostile = false; bool target_hostile_checked = false; bool target_friendly_checked = false; for (uint32 k : m_spellInfo->EffectImplicitTargetA) @@ -6058,12 +6043,9 @@ SpellCastResult Spell::CheckCast(bool strict) if (!target_hostile_checked) { target_hostile_checked = true; - target_hostile = m_caster->IsHostileTo(target); + if (!m_caster->IsValidHelpfulTarget(target, false)) + return SPELL_FAILED_BAD_TARGETS; } - - if (target_hostile) - return SPELL_FAILED_BAD_TARGETS; - explicit_target_mode = true; } else if (IsExplicitNegativeTarget(k)) @@ -6085,10 +6067,7 @@ SpellCastResult Spell::CheckCast(bool strict) // check correctness positive/negative cast target (pet cast real check and cheating check) if (m_spellInfo->IsPositiveSpell()) { - if (!target_hostile_checked) - target_hostile = m_caster->IsHostileTo(target); - - if (target_hostile) + if (!target_hostile_checked && m_caster->IsHostileTo(target)) return SPELL_FAILED_BAD_TARGETS; } else @@ -6759,9 +6738,19 @@ SpellCastResult Spell::CheckCast(bool strict) } case SPELL_EFFECT_DUEL: { - Unit* target = m_targets.getUnitTarget(); - if (target && target->GetTransport() != m_caster->GetTransport()) + if (!m_caster->IsPlayer()) + return SPELL_FAILED_BAD_TARGETS; + + Player* target = ToPlayer(m_targets.getUnitTarget()); + if (!target) + return SPELL_FAILED_BAD_TARGETS; + + if (target->GetTransport() != m_caster->GetTransport()) return SPELL_FAILED_NOT_ON_TRANSPORT; + + if (target->duel) + return SPELL_FAILED_TARGET_DUELING; + break; } case SPELL_EFFECT_SCRIPT_EFFECT: @@ -7165,11 +7154,12 @@ SpellCastResult Spell::CheckPetCast(Unit* target) // for target dead/target not valid if (_target && IsExplicitlySelectedUnitTarget(m_spellInfo->EffectImplicitTargetA[0])) { - if (!_target->IsTargetableBy(m_spellInfo->IsPositiveSpell() ? nullptr : m_casterUnit)) + bool const positive = m_spellInfo->IsPositiveSpell(m_caster, _target); + if (!_target->IsTargetableBy(m_casterUnit, false, true, positive)) return SPELL_FAILED_BAD_TARGETS; // guessed error // SPELL_EFFECT_DISPEL -> Positive or negative depending on the target - if (m_spellInfo->IsPositiveSpell() && !m_spellInfo->HasEffect(SPELL_EFFECT_DISPEL)) + if (positive) { if (m_casterUnit->IsHostileTo(_target)) return SPELL_FAILED_BAD_TARGETS; @@ -8172,9 +8162,12 @@ bool Spell::CheckTarget(Unit* target, SpellEffectIndex eff) Player* casterOwner = m_casterUnit->GetCharmerOrOwnerPlayerOrPlayerItself(); Player* targetOwner = target->GetCharmerOrOwnerPlayerOrPlayerItself(); - if (targetOwner && casterOwner != targetOwner && targetOwner->duel && casterOwner && !casterOwner->IsInDuelWith(targetOwner)) + if (targetOwner && casterOwner && casterOwner != targetOwner && + targetOwner->duel && targetOwner->duel->startTime != 0 && + targetOwner->duel->opponent != casterOwner) return false; } + // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets) if (m_spellInfo->EffectImplicitTargetA[eff] != TARGET_UNIT_CASTER) { @@ -8572,7 +8565,7 @@ public: if (i_TargetType != SPELL_TARGETS_ALL) { bool const forAttack = i_TargetType == SPELL_TARGETS_HOSTILE || i_TargetType == SPELL_TARGETS_NOT_FRIENDLY || i_TargetType == SPELL_TARGETS_AOE_DAMAGE; - if (!unit->IsTargetableBy(forAttack ? i_originalCaster : nullptr, true, false) || !i_spell.m_spellInfo->CanTargetAliveState(unit->IsAlive())) + if (!unit->IsTargetableBy(i_originalCaster, true, false, !forAttack) || !i_spell.m_spellInfo->CanTargetAliveState(unit->IsAlive())) continue; } diff --git a/src/game/Spells/SpellAuras.cpp b/src/game/Spells/SpellAuras.cpp index 06fb2c3c5..a2eb4d169 100644 --- a/src/game/Spells/SpellAuras.cpp +++ b/src/game/Spells/SpellAuras.cpp @@ -5984,10 +5984,16 @@ void Aura::PeriodicTick(SpellEntry const* sProto, AuraType auraType, uint32 data if (!pCaster) return; - if (spellProto->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA && - pCaster->SpellHitResult(target, spellProto, GetEffIndex(), false) != SPELL_MISS_NONE) - return; - + if (spellProto->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA) + { + SpellMissInfo result = pCaster->SpellHitResult(target, spellProto, GetEffIndex(), false); + if (result != SPELL_MISS_NONE) + { + pCaster->SendSpellMiss(target, GetId(), result); + return; + } + } + // Check for immune (not use charges) if (!spellProto->HasAttribute(SPELL_ATTR_NO_IMMUNITIES)) // confirmed Impaling spine goes through immunity { @@ -6092,9 +6098,15 @@ void Aura::PeriodicTick(SpellEntry const* sProto, AuraType auraType, uint32 data if (!pCaster->IsInWorld() || !pCaster->IsAlive()) return; - if (spellProto->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA && - pCaster->SpellHitResult(target, spellProto, GetEffIndex(), false) != SPELL_MISS_NONE) - return; + if (spellProto->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA) + { + SpellMissInfo result = pCaster->SpellHitResult(target, spellProto, GetEffIndex(), false); + if (result != SPELL_MISS_NONE) + { + pCaster->SendSpellMiss(target, GetId(), result); + return; + } + } // Check for immune if (!spellProto->HasAttribute(SPELL_ATTR_NO_IMMUNITIES)) @@ -6281,9 +6293,15 @@ void Aura::PeriodicTick(SpellEntry const* sProto, AuraType auraType, uint32 data if (!pCaster->IsAlive()) return; - if (GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA && - pCaster->SpellHitResult(target, spellProto, GetEffIndex(), false) != SPELL_MISS_NONE) - return; + if (spellProto->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA) + { + SpellMissInfo result = pCaster->SpellHitResult(target, spellProto, GetEffIndex(), false); + if (result != SPELL_MISS_NONE) + { + pCaster->SendSpellMiss(target, GetId(), result); + return; + } + } // Check for immune (not use charges) if (!spellProto->HasAttribute(SPELL_ATTR_NO_IMMUNITIES)) // confirmed Impaling spine goes through immunity