private static void CastTargetSpellAtVictim(CharacterInstance ch, CharacterInstance victim, SkillData skill, TargetBooleanValues targetValues, int level) { if (targetValues.GroupSpell || targetValues.AreaSpell) { var resType = EnumerationExtensions.GetEnum <ResistanceTypes>(Macros.SPELL_DAMAGE(skill)); if ((targetValues.GroupSpell && !victim.IsSameGroup(ch)) || victim.Immunity.IsSet(ResistanceTypes.Magic) || victim.IsImmune(resType) || skill.CheckSave(level, ch, victim) || (!skill.Flags.IsSet(SkillFlags.ReCastable) && !victim.IsAffectedBy((int)skill.ID))) { return; } if (targetValues.HitVictim && ch != victim) { comm.act(ATTypes.AT_MAGIC, skill.HitVictimMessage, ch, null, victim, ToTypes.Victim); if (targetValues.HitRoom) { comm.act(ATTypes.AT_MAGIC, skill.HitRoomMessage, ch, null, victim, ToTypes.NotVictim); comm.act(ATTypes.AT_MAGIC, skill.HitRoomMessage, ch, null, victim, ToTypes.Character); } } else if (targetValues.HitRoom) { comm.act(ATTypes.AT_MAGIC, skill.HitRoomMessage, ch, null, victim, ToTypes.Room); } if (ch == victim) { if (targetValues.HitVictim) { comm.act(ATTypes.AT_MAGIC, skill.HitVictimMessage, ch, null, ch, ToTypes.Character); } else if (targetValues.HitCharacter) { comm.act(ATTypes.AT_MAGIC, skill.HitCharacterMessage, ch, null, ch, ToTypes.Character); } } else if (targetValues.HitCharacter) { comm.act(ATTypes.AT_MAGIC, skill.HitCharacterMessage, ch, null, victim, ToTypes.Character); } } var retCode = AffectCharacter.spell_affectchar((int)skill.ID, level, ch, victim); if (!targetValues.GroupSpell && !targetValues.AreaSpell) { if (retCode == ReturnTypes.VictimImmune) { ch.ImmuneCast(skill, victim); } else { ch.SuccessfulCast(skill, victim); } } }
public static ReturnTypes spell_affect(int sn, int level, CharacterInstance ch, object vo) { var skill = RepositoryManager.Instance.SKILLS.Get(sn); if (!skill.Affects.Any()) { return(ReturnTypes.None); } var target = new TargetBooleanValues(); if (skill.Flags.IsSet(SkillFlags.GroupSpell)) { target.GroupSpell = true; } if (skill.Flags.IsSet(SkillFlags.Area)) { target.AreaSpell = true; } var victim = (CharacterInstance)vo; if (!target.GroupSpell && !target.AreaSpell) { var retCode = CastSingleTargetSpell(skill, level, ch, victim); if (retCode == ReturnTypes.SpellFailed) { return(retCode); } } else { if (string.IsNullOrEmpty(skill.HitCharacterMessage)) { target.HitCharacter = true; } else { comm.act(ATTypes.AT_MAGIC, skill.HitCharacterMessage, ch, null, null, ToTypes.Character); } if (string.IsNullOrEmpty(skill.HitRoomMessage)) { target.HitRoom = true; } else { comm.act(ATTypes.AT_MAGIC, skill.HitRoomMessage, ch, null, null, ToTypes.Room); } if (string.IsNullOrEmpty(skill.HitVictimMessage)) { target.HitVictim = true; } victim = victim != null?victim.CurrentRoom.Persons.First() : ch.CurrentRoom.Persons.First(); } if (CheckFunctions.CheckIfNullObjectCasting(victim, skill, ch)) { return(ReturnTypes.SpellFailed); } if (!target.GroupSpell && !target.AreaSpell) { CastTargetSpellAtVictim(ch, victim.CurrentRoom.Persons.First(), skill, target, level); } else { victim.CurrentRoom.Persons.ToList().ForEach(vch => CastTargetSpellAtVictim(ch, vch, skill, target, level)); } return(ReturnTypes.None); }