From 8c95323728dc5815b087a3873180e0b0c521af84 Mon Sep 17 00:00:00 2001 From: KayenEQ Date: Fri, 5 Nov 2021 10:39:17 -0400 Subject: [PATCH] [Spells] Update to Charm target restriction code (#1666) * charm target restrictions * fixed * Update spells.cpp * Update spells.cpp * Update spells.cpp only send spell bar when we have to, avoid potential exploit. * logs --- zone/mob.h | 1 + zone/spell_effects.cpp | 50 ++++++++++++++++++++++++------------------ zone/spells.cpp | 15 +++++++++++++ 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/zone/mob.h b/zone/mob.h index c3da39e27..9b8361b9c 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -846,6 +846,7 @@ public: inline void SetSpellPowerDistanceMod(int16 value) { SpellPowerDistanceMod = value; }; int32 GetSpellStat(uint32 spell_id, const char *identifier, uint8 slot = 0); bool HarmonySpellLevelCheck(int32 spell_id, Mob* target = nullptr); + bool PassCharmTargetRestriction(Mob *target); bool CanFocusUseRandomEffectivenessByType(focusType type); int GetFocusRandomEffectivenessValue(int focus_base, int focus_base2, bool best_focus = 0); int GetHealRate() const { return itembonuses.HealRate + spellbonuses.HealRate + aabonuses.HealRate; } diff --git a/zone/spell_effects.cpp b/zone/spell_effects.cpp index c9538523b..44d07f957 100644 --- a/zone/spell_effects.cpp +++ b/zone/spell_effects.cpp @@ -732,27 +732,6 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove break; } - if (IsClient() && caster->IsClient()) { - caster->Message(Chat::White, "Unable to cast charm on a fellow player."); - BuffFadeByEffect(SE_Charm); - break; - } - else if (IsCorpse()) { - caster->Message(Chat::White, "Unable to cast charm on a corpse."); - BuffFadeByEffect(SE_Charm); - break; - } - else if (caster->GetPet() != nullptr && caster->IsClient()) { - caster->Message(Chat::White, "You cannot charm something when you already have a pet."); - BuffFadeByEffect(SE_Charm); - break; - } - else if (GetOwner()) { - caster->Message(Chat::White, "You cannot charm someone else's pet!"); - BuffFadeByEffect(SE_Charm); - break; - } - if (IsNPC()) { CastToNPC()->SaveGuardSpotCharm(); } @@ -8439,6 +8418,35 @@ bool Mob::HarmonySpellLevelCheck(int32 spell_id, Mob *target) return true; } +bool Mob::PassCharmTargetRestriction(Mob *target) { + + //Level restriction check should not go here. + if (!target) { + return false; + } + + if (target->IsClient() && IsClient()) { + MessageString(Chat::Red, CANNOT_AFFECT_PC); + LogSpells("Spell casting canceled: Can not cast charm on a client."); + return false; + } + else if (target->IsCorpse()) { + LogSpells("Spell casting canceled: Can not cast charm on a corpse."); + return false; + } + else if (GetPet() && IsClient()) { + MessageString(Chat::Red, ONLY_ONE_PET); + LogSpells("Spell casting canceled: Can not cast charm if you have a pet."); + return false; + } + else if (target->GetOwner()) { + MessageString(Chat::Red, CANNOT_CHARM); + LogSpells("Spell casting canceled: Can not cast charm on a pet."); + return false; + } + return true; +} + bool Mob::CanFocusUseRandomEffectivenessByType(focusType type) { switch (type) { diff --git a/zone/spells.cpp b/zone/spells.cpp index 5def206bc..6cf9837c9 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -229,6 +229,21 @@ bool Mob::CastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot, return false; } + if (IsEffectInSpell(spell_id, SE_Charm) && !PassCharmTargetRestriction(entity_list.GetMobID(target_id))) { + bool can_send_spellbar_enable = true; + if ((item_slot != -1 && cast_time == 0) || aa_id) { + can_send_spellbar_enable = false; + } + + if (can_send_spellbar_enable) { + SendSpellBarEnable(spell_id); + } + if (casting_spell_id && IsNPC()) { + CastToNPC()->AI_Event_SpellCastFinished(false, static_cast(casting_spell_slot)); + } + return false; + } + if (HasActiveSong() && IsBardSong(spell_id)) { LogSpells("Casting a new song while singing a song. Killing old song [{}]", bardsong); //Note: this does NOT tell the client