All should charm all not just npcs with a set type body.
Pulls the ((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.None failure check into the section that checks and bellow the can charm type is all check.
CharmSpellHandler.cs
Origional
- Code: Select all
/// <summary> /// Apply effect on target or do spell action if non duration spell /// </summary> /// <param name="target">target that gets the effect</param> /// <param name="effectiveness">factor from 0..1 (0%-100%)</param> public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) { // This prevent most of type casting errors if(target is GameNPC == false) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } // check only if brain wasn't changed at least once if (m_controlledBrain == null) { // Target is already controlled if(((GameNPC)target).Brain != null && ((GameNPC)target).Brain is IControlledBrain && (((IControlledBrain)((GameNPC)target).Brain).Owner as GamePlayer) != Caster) { // TODO: proper message MessageToCaster("Your target is not valid.", eChatType.CT_SpellResisted); return; } // Already have a pet... if(Caster.ControlledBrain != null) { MessageToCaster("You already have a charmed creature, release it first!", eChatType.CT_SpellResisted); return; } // Body Type None (0) is used to make mobs un-charmable , Realm Guards or NPC cannot be charmed. if (target.Realm != 0 || ((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.None) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } // If server properties prevent Named charm. if(ServerProperties.Properties.SPELL_CHARM_NAMED_CHECK != 0 && !target.Name[0].ToString().ToLower().Equals(target.Name[0].ToString())) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } // Check if Body type applies if (m_spell.AmnesiaChance != (ushort)eCharmType.All) { bool charmable = false; // gets true only for charm-able mobs for this spell type switch((eCharmType)m_spell.AmnesiaChance) { case eCharmType.HumanoidAnimalInsectMagicalUndead : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Undead) charmable = true; goto case eCharmType.HumanoidAnimalInsectMagical; case eCharmType.HumanoidAnimalInsectMagical : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Magical) charmable = true; if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Plant) charmable = true; if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Elemental) charmable = true; goto case eCharmType.HumanoidAnimalInsect; case eCharmType.HumanoidAnimalInsect : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Insect) charmable = true; if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Reptile) charmable = true; goto case eCharmType.HumanoidAnimal; case eCharmType.HumanoidAnimal : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Animal) charmable = true; goto case eCharmType.Humanoid; case eCharmType.Humanoid : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Humanoid) charmable = true; break; case eCharmType.Animal : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Animal) charmable = true; break; case eCharmType.Insect : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Insect) charmable = true; break; case eCharmType.Reptile : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Reptile) charmable = true; break; } // The NPC type doesn't match spell charm types. if(!charmable) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } } } // Spell.Value == Max Level this spell can charm, Spell.Damage == Max percent of the caster level this spell can charm if (target.Level > Spell.Value || target.Level > Caster.Level * Spell.Damage / 100) { MessageToCaster(target.GetName(0, true) + " is too strong for you to charm!", eChatType.CT_SpellResisted); return; } if (Caster is GamePlayer) { // base resists for all charm spells int resistChance = 100 - (85 + ((Caster.Level - target.Level) / 2)); if (this.Spell.Pulse != 0) // not permanent { /* * The Minstrel/Mentalist has an almost certain chance to charm/retain control of * a creature his level or lower, although there is a small random chance that it * could fail. The higher the level of the charmed creature compared to the * Minstrel/Mentalist, the greater the chance the monster has of breaking the charm. * Please note that your specialization level in the magic skill that contains the * charm spell will modify your base chance of charming and retaining control. * The higher your spec level, the greater your chance of controlling. */ int diffLevel = (int)(Caster.Level / 1.5 + Caster.GetModifiedSpecLevel(m_spellLine.Spec) / 3) - target.Level; if (diffLevel >= 0) { resistChance = 10 - diffLevel * 3; resistChance = Math.Max(resistChance, 1); } else { resistChance = 10 + diffLevel * diffLevel * 3; resistChance = Math.Min(resistChance, 99); } } if (Util.Chance(resistChance)) { MessageToCaster(target.GetName(0, true) + " resists the charm!", eChatType.CT_SpellResisted); return; } } base.ApplyEffectOnTarget(target, effectiveness); }
- Code: Select all
/// <summary> /// Apply effect on target or do spell action if non duration spell /// </summary> /// <param name="target">target that gets the effect</param> /// <param name="effectiveness">factor from 0..1 (0%-100%)</param> public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) { // This prevent most of type casting errors if(target is GameNPC == false) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } // check only if brain wasn't changed at least once if (m_controlledBrain == null) { // Target is already controlled if(((GameNPC)target).Brain != null && ((GameNPC)target).Brain is IControlledBrain && (((IControlledBrain)((GameNPC)target).Brain).Owner as GamePlayer) != Caster) { // TODO: proper message MessageToCaster("Your target is not valid.", eChatType.CT_SpellResisted); return; } // Already have a pet... if(Caster.ControlledBrain != null) { MessageToCaster("You already have a charmed creature, release it first!", eChatType.CT_SpellResisted); return; } // Body Type None (0) is used to make mobs un-charmable , Realm Guards or NPC cannot be charmed. if (target.Realm != 0) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } // If server properties prevent Named charm. if(ServerProperties.Properties.SPELL_CHARM_NAMED_CHECK != 0 && !target.Name[0].ToString().ToLower().Equals(target.Name[0].ToString())) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } // Check if Body type applies if (m_spell.AmnesiaChance != (ushort)eCharmType.All) { if (((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.None) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } bool charmable = false; // gets true only for charm-able mobs for this spell type switch((eCharmType)m_spell.AmnesiaChance) { case eCharmType.HumanoidAnimalInsectMagicalUndead : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Undead) charmable = true; goto case eCharmType.HumanoidAnimalInsectMagical; case eCharmType.HumanoidAnimalInsectMagical : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Magical) charmable = true; if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Plant) charmable = true; if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Elemental) charmable = true; goto case eCharmType.HumanoidAnimalInsect; case eCharmType.HumanoidAnimalInsect : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Insect) charmable = true; if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Reptile) charmable = true; goto case eCharmType.HumanoidAnimal; case eCharmType.HumanoidAnimal : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Animal) charmable = true; goto case eCharmType.Humanoid; case eCharmType.Humanoid : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Humanoid) charmable = true; break; case eCharmType.Animal : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Animal) charmable = true; break; case eCharmType.Insect : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Insect) charmable = true; break; case eCharmType.Reptile : if(((GameNPC)target).BodyType == (ushort)NpcTemplateMgr.eBodyType.Reptile) charmable = true; break; } // The NPC type doesn't match spell charm types. if(!charmable) { MessageToCaster("This spell does not charm this type of monster!", eChatType.CT_SpellResisted); return; } } } // Spell.Value == Max Level this spell can charm, Spell.Damage == Max percent of the caster level this spell can charm if (target.Level > Spell.Value || target.Level > Caster.Level * Spell.Damage / 100) { MessageToCaster(target.GetName(0, true) + " is too strong for you to charm!", eChatType.CT_SpellResisted); return; } if (Caster is GamePlayer) { // base resists for all charm spells int resistChance = 100 - (85 + ((Caster.Level - target.Level) / 2)); if (this.Spell.Pulse != 0) // not permanent { /* * The Minstrel/Mentalist has an almost certain chance to charm/retain control of * a creature his level or lower, although there is a small random chance that it * could fail. The higher the level of the charmed creature compared to the * Minstrel/Mentalist, the greater the chance the monster has of breaking the charm. * Please note that your specialization level in the magic skill that contains the * charm spell will modify your base chance of charming and retaining control. * The higher your spec level, the greater your chance of controlling. */ int diffLevel = (int)(Caster.Level / 1.5 + Caster.GetModifiedSpecLevel(m_spellLine.Spec) / 3) - target.Level; if (diffLevel >= 0) { resistChance = 10 - diffLevel * 3; resistChance = Math.Max(resistChance, 1); } else { resistChance = 10 + diffLevel * diffLevel * 3; resistChance = Math.Min(resistChance, 99); } } if (Util.Chance(resistChance)) { MessageToCaster(target.GetName(0, true) + " resists the charm!", eChatType.CT_SpellResisted); return; } } base.ApplyEffectOnTarget(target, effectiveness); }