Esempio n. 1
0
 public void RemoveAffect(AffectData affect)
 {
     if (Affects.Contains(affect))
     {
         Affects.Remove(affect);
     }
 }
Esempio n. 2
0
        public static ReturnTypes spell_change_sex(int sn, int level, CharacterInstance ch, object vo)
        {
            var victim = (CharacterInstance)vo;
            var skill  = RepositoryManager.Instance.GetEntity <SkillData>(sn);

            if (CheckFunctions.CheckIfTrueCasting(victim.IsImmune(ResistanceTypes.Magic), skill, ch,
                                                  CastingFunctionType.Immune, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            if (CheckFunctions.CheckIfTrueCasting(victim.IsAffectedBy(sn), skill, ch, CastingFunctionType.Failed, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            var af = new AffectData
            {
                SkillNumber = sn,
                Duration    = GetDuration(level),
                Location    = ApplyTypes.Gender
            };

            do
            {
                af.Modifier = SmaugRandom.Between(0, 2) - (int)victim.Gender;
            } while (af.Modifier == 0);

            victim.AddAffect(af);
            ch.SuccessfulCast(skill, victim);

            return(ReturnTypes.None);
        }
Esempio n. 3
0
        public static void showaffect(CharacterInstance ch, AffectData paf)
        {
            Validation.IsNotNull(paf, "paf");

            var buf = string.Empty;

            if (paf.Location == ApplyTypes.None || paf.Modifier == 0)
            {
                return;
            }

            switch (paf.Location)
            {
            default:
                buf = $"Affects {affect_loc_name((int)paf.Location)} by {paf.Modifier}.";
                break;

            case ApplyTypes.Affect:
                buf = $"Affects {affect_loc_name((int)paf.Location)} by {paf.Modifier}.";

                for (var i = 0; i < 32; i++)
                {
                    if (paf.Modifier.IsSet(1 << i))
                    {
                        buf += " " + BuilderConstants.a_flags[i];
                    }
                }
                break;

            case ApplyTypes.WeaponSpell:
            case ApplyTypes.WearSpell:
            case ApplyTypes.RemoveSpell:
                var name = "unknown";
                if (Macros.IS_VALID_SN(paf.Modifier))
                {
                    var skill = RepositoryManager.Instance.SKILLS.Get(paf.Modifier);
                    name = skill.Name;
                }
                buf = $"Casts spell '{name}'";
                break;

            case ApplyTypes.Resistance:
            case ApplyTypes.Immunity:
            case ApplyTypes.Susceptibility:
                buf = $"Affects {affect_loc_name((int)paf.Location)} by {paf.Modifier}";

                for (var i = 0; i < 32; i++)
                {
                    if (paf.Modifier.IsSet(1 << i))
                    {
                        buf += " " + BuilderConstants.ris_flags[i];
                    }
                }

                break;
            }

            ch.SendTo(buf);
        }
Esempio n. 4
0
        public static ReturnTypes spell_create_mob(int sn, int level, CharacterInstance ch, object vo)
        {
            var skill = RepositoryManager.Instance.SKILLS.Get(sn);

            var targetName = Cast.TargetName;

            var lvl = GetMobLevel(skill, level);
            var id  = skill.value;

            if (id == 0)
            {
                if (!targetName.Equals("cityguard"))
                {
                    id = GameConstants.GetVnum("cityguard");
                }
                else if (!targetName.Equals("vampire"))
                {
                    id = GameConstants.GetVnum("vampire");
                }
            }

            var mi = RepositoryManager.Instance.MOBILETEMPLATES.Get(id);

            if (CheckFunctions.CheckIfNullObjectCasting(mi, skill, ch))
            {
                return(ReturnTypes.None);
            }

            var mob = RepositoryManager.Instance.CHARACTERS.Create(mi);

            if (CheckFunctions.CheckIfNullObjectCasting(mob, skill, ch))
            {
                return(ReturnTypes.None);
            }

            mob.Level         = lvl.GetLowestOfTwoNumbers(!string.IsNullOrEmpty(skill.Dice) ? magic.ParseDiceExpression(ch, skill.Dice) : mob.Level);
            mob.ArmorClass    = mob.Level.Interpolate(100, -100);
            mob.MaximumHealth = mob.Level * 8 + SmaugRandom.Between(mob.Level * mob.Level / 4, mob.Level * mob.Level);
            mob.CurrentHealth = mob.MaximumHealth;
            mob.CurrentCoin   = 0;

            ch.SuccessfulCast(skill, mob);
            ch.CurrentRoom.AddTo(mob);
            mob.AddFollower(ch);

            var af = new AffectData
            {
                Type     = EnumerationExtensions.GetEnum <AffectedByTypes>((int)skill.ID),
                Duration = (SmaugRandom.Fuzzy((level + 1) / 3) + 1) *
                           GameConstants.GetConstant <int>("AffectDurationConversionValue")
            };

            mob.AddAffect(af);

            return(ReturnTypes.None);
        }
Esempio n. 5
0
        private static void MakeCorpseTemporary(int level, CharacterInstance mob)
        {
            var af = new AffectData
            {
                Type     = AffectedByTypes.Charm,
                Duration = (SmaugRandom.Fuzzy((level + 1) / 4) + 1) *
                           GameConstants.GetSystemValue <int>("AffectDurationConversionValue")
            };

            mob.AddAffect(af);
        }
Esempio n. 6
0
        public static void RemoveAffect(this CharacterInstance ch, AffectData paf)
        {
            if (ch.Affects == null || ch.Affects.Count == 0)
            {
                throw new InvalidDataException($"Character {ch.ID} has no affects");
            }

            ch.ModifyAffect(paf, false);

            ch.CurrentRoom?.RemoveAffect(paf);

            ch.Affects.Remove(paf);
        }
Esempio n. 7
0
        private static void AddAffectToTarget(CharacterInstance ch, int sn, int level, ApplyTypes appLocation)
        {
            int duration = 4 * level * GameConstants.GetConstant <int>("AffectDurationConversionValue");
            var af       = new AffectData
            {
                SkillNumber = sn,
                Duration    = duration,
                Location    = appLocation,
                Modifier    = -1
            };

            ch.AddAffect(af);
        }
Esempio n. 8
0
        private static void DrinkPoison(CharacterInstance ch, ObjectInstance obj)
        {
            comm.act(ATTypes.AT_POISON, "$n sputters and gags.", ch, null, null, ToTypes.Room);
            comm.act(ATTypes.AT_POISON, "You sputter and gag.", ch, null, null, ToTypes.Character);
            ch.MentalState = 20.GetNumberThatIsBetween(ch.MentalState + 5, 100);

            var af = new AffectData
            {
                Type     = AffectedByTypes.Poison,
                Duration = obj.Values.Poison,
                Location = ApplyTypes.None
            };

            ch.AddAffect(af);
        }
Esempio n. 9
0
        private static void SupplicateForObject(PlayerInstance ch, string argument)
        {
            var oldfavor = ch.PlayerData.Favor;

            if (CheckFunctions.CheckIfTrue(ch, ch.PlayerData.Favor < ch.PlayerData.CurrentDeity.SupplicateDeityObjectCost,
                                           "You are not favored enough for that."))
            {
                return;
            }

            var template = RepositoryManager.Instance.OBJECTTEMPLATES.Get(VnumConstants.OBJ_VNUM_DEITY);
            var obj      = RepositoryManager.Instance.OBJECTS.Create(template, ch.Level,
                                                                     $"sigil {ch.PlayerData.CurrentDeity.Name}");

            obj = obj.WearFlags.IsSet(ItemWearFlags.Take) ? obj.AddTo(ch) : ch.CurrentRoom.AddTo(obj);

            comm.act(ATTypes.AT_MAGIC, "$n weaves $p from divine matter!", ch, obj, null, ToTypes.Room);
            comm.act(ATTypes.AT_MAGIC, "You weave $p from divine matter!", ch, obj, null, ToTypes.Character);
            ch.PlayerData.Favor -= ch.PlayerData.CurrentDeity.SupplicateDeityObjectCost;

            if (ch.PlayerData.Favor < ch.PlayerData.CurrentDeity.SusceptNum)
            {
                ch.Susceptibility.SetBit(ch.PlayerData.CurrentDeity.Suscept);
            }

            if ((oldfavor > ch.PlayerData.CurrentDeity.AffectedNum &&
                 ch.PlayerData.Favor <= ch.PlayerData.CurrentDeity.AffectedNum) ||
                (oldfavor > ch.PlayerData.CurrentDeity.ElementNum &&
                 ch.PlayerData.Favor <= ch.PlayerData.CurrentDeity.ElementNum) ||
                (oldfavor < ch.PlayerData.CurrentDeity.SusceptNum &&
                 ch.PlayerData.Favor >= ch.PlayerData.CurrentDeity.SusceptNum))
            {
                ch.update_aris();
            }

            var af = new AffectData
            {
                Type     = AffectedByTypes.None,
                Duration = -1,
                Location = GetApplyTypeForDeity(ch.PlayerData.CurrentDeity),
                Modifier = 1
            };

            af.BitVector.ClearBits();
            obj.Affects.Add(af);
        }
Esempio n. 10
0
 private static void InflictPoison(CharacterInstance ch, CharacterInstance victim)
 {
     if (!victim.SavingThrows.CheckSaveVsPoisonDeath(ch.Level, victim))
     {
         var af = new AffectData
         {
             Type     = AffectedByTypes.Poison,
             Duration = 20,
             Location = ApplyTypes.Strength,
             Modifier = -2
         };
         victim.AddAffect(af);
         ((PlayerInstance)victim).WorsenMentalState(
             20.GetNumberThatIsBetween(victim.MentalState + (victim.IsPKill() ? 1 : 2),
                                       100));
     }
 }
Esempio n. 11
0
        public static void JoinAffect(this CharacterInstance ch, AffectData paf)
        {
            if (ch.Affects == null || ch.Affects.Count == 0)
            {
                return;
            }

            var matchingAffects = ch.Affects.Where(x => x.Type == paf.Type);

            foreach (var affect in matchingAffects)
            {
                paf.Duration = 1000000.GetLowestOfTwoNumbers(paf.Duration + affect.Duration);
                paf.Modifier = paf.Modifier > 0 ? 5000.GetLowestOfTwoNumbers(paf.Modifier + affect.Modifier) : affect.Modifier;
                ch.RemoveAffect(affect);
                break;
            }

            ch.AddAffect(paf);
        }
Esempio n. 12
0
        private static int ModifyAndAddAffect(CharacterInstance ch, AffectData affect, int mod)
        {
            ch.AffectedBy.SetBit((int)affect.Type);
            if ((int)affect.Location % Program.REVERSE_APPLY == (int)ApplyTypes.RecurringSpell)
            {
                mod = Math.Abs(mod);
                var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod];

                if (Macros.IS_VALID_SN(mod) && skill != null && skill.Type == SkillTypes.Spell)
                {
                    ch.AffectedBy.SetBit((int)AffectedByTypes.RecurringSpell);
                }
                else
                {
                    throw new InvalidDataException($"RecurringSpell with bad SN {mod}");
                }
            }
            return(mod);
        }
Esempio n. 13
0
        public void AddAffect(int type, int duration, int modifier, int location, int bits)
        {
            if (type < 0)
            {
                throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(AffectedByTypes));
            }

            AffectData newAffect = new AffectData
            {
                Type     = Common.EnumerationExtensions.GetEnum <AffectedByTypes>(type),
                Duration = duration,
                Modifier = modifier,
                Location = Realm.Library.Common.Extensions.EnumerationExtensions.GetEnum <ApplyTypes>(location)
            };

            newAffect.BitVector.SetBit(bits);

            Affects.Add(newAffect);
        }
Esempio n. 14
0
        private static void RemoveDevotion(PlayerInstance ch)
        {
            if (CheckFunctions.CheckIfNullObject(ch, ch.PlayerData.CurrentDeity,
                                                 "You have already chosen to worship no deities."))
            {
                return;
            }

            var deity = ch.PlayerData.CurrentDeity;

            --deity.Worshippers;
            if (deity.Worshippers < 0)
            {
                deity.Worshippers = 0;
            }

            ch.PlayerData.Favor = -2500;
            ch.MentalState      = -80;
            ch.SendTo("A terrible curse afflicts you as you forsake a deity!");

            ch.AffectedBy.RemoveBits(deity.Affected);
            ch.Resistance.RemoveBit(deity.Element);
            ch.Susceptibility.RemoveBit(deity.Suscept);

            var af = new AffectData
            {
                Type      = AffectedByTypes.Blind,
                Location  = ApplyTypes.HitRoll,
                Modifier  = -4,
                Duration  = 50 * GameConstants.GetConstant <int>("AffectDurationConversionValue"),
                BitVector = ExtendedBitvector.Meb((int)AffectedByTypes.Blind)
            };

            ch.AddAffect(af);

            // TODO Save the deity data to the database
            // save_deity(ch->pcdata->deity);

            ch.SendTo("You cease to worship any deity.");
            ch.PlayerData.CurrentDeity = null;
            save.save_char_obj(ch);
        }
Esempio n. 15
0
        public static void AddAffect(this CharacterInstance ch, AffectData affect)
        {
            if (affect == null)
            {
                throw new ArgumentNullException(nameof(affect));
            }

            var newAffect = new AffectData
            {
                Type      = affect.Type,
                Duration  = affect.Duration,
                Location  = affect.Location,
                Modifier  = affect.Modifier,
                BitVector = affect.BitVector
            };

            ch.Affects.Add(newAffect);
            ch.ModifyAffect(newAffect, true);

            ch.CurrentRoom?.AddAffect(newAffect);
        }
Esempio n. 16
0
        public static ReturnTypes spell_blindness(int sn, int level, CharacterInstance ch, object vo)
        {
            var victim = (CharacterInstance)vo;
            var skill  = RepositoryManager.Instance.GetEntity <SkillData>(sn);

            var tmp = skill.Flags.IsSet(SkillFlags.PKSensitive) ? level / 2 : level;

            if (victim.IsImmune(ResistanceTypes.Magic))
            {
                ch.ImmuneCast(skill, victim);
                return(ReturnTypes.SpellFailed);
            }

            if (ch.IsAffected(AffectedByTypes.Blind) || ch.SavingThrows.CheckSaveVsSpellStaff(tmp, victim))
            {
                ch.FailedCast(skill, victim);
                return(ReturnTypes.SpellFailed);
            }

            var af = new AffectData
            {
                SkillNumber = sn,
                Location    = ApplyTypes.HitRoll,
                Modifier    = -4,
                Duration    = GetDuration(level)
            };

            victim.AddAffect(af);
            victim.SetColor(ATTypes.AT_MAGIC);
            victim.SendTo("You are blinded!");

            if (ch != victim)
            {
                comm.act(ATTypes.AT_MAGIC, "You weave a spell of blindness around $N.", ch, null, victim, ToTypes.Character);
                comm.act(ATTypes.AT_MAGIC, "$n weaves a spell of blindness about $N.", ch, null, victim, ToTypes.NotVictim);
            }

            return(ReturnTypes.None);
        }
Esempio n. 17
0
        public static void aris_affect(this CharacterInstance ch, AffectData paf)
        {
            ch.AffectedBy.SetBits(paf.BitVector);
            switch ((int)paf.Location % Program.REVERSE_APPLY)
            {
            case (int)ApplyTypes.Affect:
                ch.AffectedBy.Bits[0].SetBit(paf.Modifier);
                break;

            case (int)ApplyTypes.Resistance:
                ch.Resistance.SetBit(paf.Modifier);
                break;

            case (int)ApplyTypes.Immunity:
                ch.Immunity.SetBit(paf.Modifier);
                break;

            case (int)ApplyTypes.Susceptibility:
                ch.Susceptibility.SetBit(paf.Modifier);
                break;
            }
        }
Esempio n. 18
0
 public void AddAffect(AffectData affect) => Affects.Add(affect);
Esempio n. 19
0
        public static ReturnTypes spell_dispel_magic(int sn, int level, CharacterInstance ch, object vo)
        {
            var victim = (CharacterInstance)vo;
            var skill  = RepositoryManager.Instance.GetEntity <SkillData>(sn);

            ch.SetColor(ATTypes.AT_MAGIC);

            if (CheckFunctions.CheckIfTrueCasting(victim.Immunity.IsSet(ResistanceTypes.Magic), skill, ch, CastingFunctionType.Immune, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            if (CheckFunctions.CheckIfTrueCasting(victim.IsNpc() && victim.IsAffected(AffectedByTypes.Possess), skill,
                                                  ch, CastingFunctionType.Immune, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            if (ch == victim)
            {
                return(DispelSelf(ch, victim));
            }

            var isMage = ch.IsNpc() || ch.CurrentClass == ClassTypes.Mage;

            if (!isMage && !ch.IsAffected(AffectedByTypes.DetectMagic))
            {
                ch.SendTo("You don't sense a magical aura to dispel.");
                return(ReturnTypes.Error);
            }

            int chance = ch.GetCurrentIntelligence() - victim.GetCurrentIntelligence();

            if (isMage)
            {
                chance += 5;
            }
            else
            {
                chance -= 15;
            }

            bool twice = false, three = false;

            if (SmaugRandom.D100() > 75 - chance)
            {
                twice = true;
                if (SmaugRandom.D100() > 75 - chance)
                {
                    three = true;
                }
            }

            bool continueOuterLoop = true;
            int  affectedBy;
            bool found = false;
            int  cnt = 0, times = 0;

            while (continueOuterLoop)
            {
                AffectData paf = null;

                // grab affected_by from mobs first
                if (victim.IsNpc() && victim.AffectedBy.IsEmpty())
                {
                    for (; ;)
                    {
                        affectedBy = SmaugRandom.Between(0, EnumerationFunctions.MaximumEnumValue <AffectedByTypes>() - 1);
                        if (victim.IsAffectedBy(affectedBy))
                        {
                            found = true;
                            break;
                        }
                        if (cnt++ > 30)
                        {
                            found = false;
                            break;
                        }
                    }

                    // is it a spell?
                    if (found)
                    {
                        foreach (var af in victim.Affects)
                        {
                            paf = af;
                            if (paf.Type.IsSet(affectedBy))
                            {
                                break;
                            }
                        }

                        // its a spell, remove it
                        if (paf != null)
                        {
                            if (level < victim.Level || victim.SavingThrows.CheckSaveVsSpellStaff(level, victim))
                            {
                                if (magic.dispel_casting(paf, ch, victim, 0, false) != 0)
                                {
                                    ch.FailedCast(skill, victim);
                                }
                                return(ReturnTypes.SpellFailed);
                            }
                            if (skill.Flags.IsSet(SkillFlags.NoDispel))
                            {
                                if (magic.dispel_casting(paf, ch, victim, 0, false) != 0 && times == 0)
                                {
                                    ch.FailedCast(skill, victim);
                                }
                                return(ReturnTypes.SpellFailed);
                            }

                            if (magic.dispel_casting(paf, ch, victim, 0, true) != 0 && times == 0)
                            {
                                ch.SuccessfulCast(skill, victim);
                            }
                            victim.RemoveAffect(paf);

                            if ((twice && times < 1) || (three && times < 2))
                            {
                                times++;
                                continue;
                            }
                            return(ReturnTypes.None);
                        }

                        // not a spell, just remove the bit (for mobs only)
                        else
                        {
                            if (level < victim.Level || victim.SavingThrows.CheckSaveVsSpellStaff(level, victim))
                            {
                                if (magic.dispel_casting(null, ch, victim, affectedBy, false) != 0)
                                {
                                    ch.FailedCast(skill, victim);
                                }
                                return(ReturnTypes.SpellFailed);
                            }

                            if (magic.dispel_casting(null, ch, victim, affectedBy, true) != 0 && times == 0)
                            {
                                ch.SuccessfulCast(skill, victim);
                            }
                            victim.AffectedBy.RemoveBit(affectedBy);

                            if ((twice && times < 1) || (three && times < 2))
                            {
                                times++;
                                continue;
                            }
                            return(ReturnTypes.None);
                        }
                    }
                }

                // mob has no affectedBys or we didn't catch them
                if (!victim.Affects.Any())
                {
                    ch.FailedCast(skill, victim);
                    return(ReturnTypes.SpellFailed);
                }

                // randomize the affects
                cnt = victim.Affects.Count;
                paf = victim.Affects.First();

                int affectNum;
                int i = 0;
                for (affectNum = SmaugRandom.Between(0, cnt - 1); affectNum > 0; affectNum--)
                {
                    paf = victim.Affects.ToList()[i];
                }

                if (level < victim.Level || victim.SavingThrows.CheckSaveVsSpellStaff(level, victim))
                {
                    if (magic.dispel_casting(paf, ch, victim, 0, false) != 0)
                    {
                        ch.FailedCast(skill, victim);
                    }
                    return(ReturnTypes.SpellFailed);
                }

                // make sure we have an affect and it isn't a dispel
                if (paf == null || paf.Type.IsSet(SkillFlags.NoDispel))
                {
                    if (magic.dispel_casting(paf, ch, victim, 0, false) != 0)
                    {
                        ch.FailedCast(skill, victim);
                    }
                    return(ReturnTypes.SpellFailed);
                }

                if (magic.dispel_casting(null, ch, victim, 0, true) != 0 && times == 0)
                {
                    ch.SuccessfulCast(skill, victim);
                }
                victim.RemoveAffect(paf);

                if ((twice && times < 1) || (three && times < 2))
                {
                    times++;
                    continue;
                }
            }

            if (!victim.IsNpc())
            {
                victim.update_aris();
            }
            return(ReturnTypes.None);
        }
Esempio n. 20
0
        public static ReturnTypes spell_charm_person(int sn, int level, CharacterInstance ch, object vo)
        {
            var victim = (CharacterInstance)vo;
            var skill  = RepositoryManager.Instance.GetEntity <SkillData>(sn);

            if (CheckFunctions.CheckIfEquivalent(ch, ch, victim, "You like yourself even better!"))
            {
                return(ReturnTypes.SpellFailed);
            }

            if (CheckFunctions.CheckIfTrueCasting(victim.IsImmune(ResistanceTypes.Magic) ||
                                                  victim.IsImmune(ResistanceTypes.Charm), skill, ch, CastingFunctionType.Immune, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            if (!victim.IsNpc() && !ch.IsNpc())
            {
                ch.SendTo("I don't think so...");
                victim.SendTo("You feel charmed...");
                return(ReturnTypes.SpellFailed);
            }

            var schance = victim.ModifySavingThrowWithResistance(level, ResistanceTypes.Charm);

            if (victim.IsAffected(AffectedByTypes.Charm) ||
                schance == 1000 ||
                ch.IsAffected(AffectedByTypes.Charm) ||
                level < victim.Level ||
                victim.IsCircleFollowing(ch) ||
                !ch.CanCharm() ||
                victim.SavingThrows.CheckSaveVsSpellStaff(schance, victim))
            {
                ch.FailedCast(skill, victim);
                return(ReturnTypes.SpellFailed);
            }

            if (victim.Master != null)
            {
                victim.StopFollower();
            }
            victim.AddFollower(ch);

            var af = new AffectData
            {
                SkillNumber = sn,
                Duration    = GetDuration(level)
            };

            victim.AddAffect(af);

            ch.SuccessfulCast(skill, victim);

            if (!ch.IsNpc())
            {
                ((PlayerInstance)ch).PlayerData.NumberOfCharmies++;
            }
            if (!victim.IsNpc())
            {
                return(ReturnTypes.None);
            }

            var mob = (MobileInstance)victim;

            mob.StartHating(ch);
            mob.StartHunting(ch);

            return(ReturnTypes.None);
        }
Esempio n. 21
0
        public static void ModifyAffect(this CharacterInstance ch, AffectData affect, bool add)
        {
            var mod = affect.Modifier;

            if (add)
            {
                mod = ModifyAndAddAffect(ch, affect, mod);
            }
            else
            {
                ch.AffectedBy.RemoveBit((int)affect.Type);

                if ((int)affect.Location % Program.REVERSE_APPLY == (int)ApplyTypes.RecurringSpell)
                {
                    mod = Math.Abs(mod);
                    var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod];

                    if (!Macros.IS_VALID_SN(mod) || skill == null || skill.Type != SkillTypes.Spell)
                    {
                        throw new InvalidDataException($"RecurringSpell with bad SN {mod}");
                    }
                    ch.AffectedBy.RemoveBit((int)AffectedByTypes.RecurringSpell);
                    return;
                }

                switch ((int)affect.Location % Program.REVERSE_APPLY)
                {
                case (int)ApplyTypes.Affect:
                    return;

                case (int)ApplyTypes.ExtendedAffect:
                    ch.AffectedBy.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Resistance:
                    ch.Resistance.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Immunity:
                    ch.Immunity.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Susceptibility:
                    ch.Susceptibility.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Remove:
                    return;
                }
                mod = 0 - mod;
            }

            var applyType = Common.EnumerationExtensions.GetEnum <ApplyTypes>((int)affect.Location % Program.REVERSE_APPLY);

            switch (applyType)
            {
            case ApplyTypes.Strength:
                ch.ModStrength += mod;
                break;

            case ApplyTypes.Dexterity:
                ch.ModDexterity += mod;
                break;

            case ApplyTypes.Intelligence:
                ch.ModIntelligence += mod;
                break;

            case ApplyTypes.Wisdom:
                ch.ModWisdom += mod;
                break;

            case ApplyTypes.Constitution:
                ch.ModConstitution += mod;
                break;

            case ApplyTypes.Charisma:
                ch.ModCharisma += mod;
                break;

            case ApplyTypes.Luck:
                ch.ModLuck += mod;
                break;

            case ApplyTypes.Gender:
                //ch.Gender = (ch.Gender + mod) % 3;
                // TODO Fix this
                //if (ch.Gender < 0)
                //    ch.Gender += 2;
                //ch.Gender = Check.Range(0, ch.Gender, 2);
                break;

            case ApplyTypes.Height:
                ch.Height += mod;
                break;

            case ApplyTypes.Weight:
                ch.Weight += mod;
                break;

            case ApplyTypes.Mana:
                ch.MaximumMana += mod;
                break;

            case ApplyTypes.Hit:
                ch.MaximumHealth += mod;
                break;

            case ApplyTypes.Movement:
                ch.MaximumMovement += mod;
                break;

            case ApplyTypes.ArmorClass:
                ch.ArmorClass += mod;
                break;

            case ApplyTypes.HitRoll:
                ch.HitRoll.SizeOf += mod;
                break;

            case ApplyTypes.DamageRoll:
                ch.DamageRoll.SizeOf += mod;
                break;

            case ApplyTypes.SaveVsPoison:
                ch.SavingThrows.SaveVsPoisonDeath += mod;
                break;

            case ApplyTypes.SaveVsRod:
                ch.SavingThrows.SaveVsWandRod += mod;
                break;

            case ApplyTypes.SaveVsParalysis:
                ch.SavingThrows.SaveVsParalysisPetrify += mod;
                break;

            case ApplyTypes.SaveVsBreath:
                ch.SavingThrows.SaveVsBreath += mod;
                break;

            case ApplyTypes.SaveVsSpell:
                ch.SavingThrows.SaveVsSpellStaff += mod;
                break;

            case ApplyTypes.Affect:
                ch.AffectedBy.Bits[0].SetBit(mod);
                break;

            case ApplyTypes.ExtendedAffect:
                ch.AffectedBy.SetBit(mod);
                break;

            case ApplyTypes.Resistance:
                ch.Resistance.SetBit(mod);
                break;

            case ApplyTypes.Immunity:
                ch.Immunity.SetBit(mod);
                break;

            case ApplyTypes.Susceptibility:
                ch.Susceptibility.SetBit(mod);
                break;

            case ApplyTypes.Remove:
                ch.AffectedBy.Bits[0].RemoveBit(mod);
                break;

            case ApplyTypes.Full:
            case ApplyTypes.Thirst:
            case ApplyTypes.Drunk:
            case ApplyTypes.Blood:
                HandlePlayerCondition(ch, applyType, mod);
                break;

            case ApplyTypes.MentalState:
                ch.MentalState = (ch.MentalState + mod).GetNumberThatIsBetween(-100, 100);
                break;

            case ApplyTypes.Emotion:
                ch.EmotionalState = ch.EmotionalState.GetNumberThatIsBetween(-100, 100);
                break;

            case ApplyTypes.StripSN:
                if (Macros.IS_VALID_SN(mod))
                {
                    ch.StripAffects(mod);
                }
                else
                {
                    LogManager.Instance.Bug("apply_modify: ApplyTypes.StripSN invalid SN %d", mod);
                }
                break;

            case ApplyTypes.WearSpell:
            case ApplyTypes.RemoveSpell:
                if (ch.CurrentRoom.Flags.IsSet(RoomFlags.NoMagic) ||
                    ch.Immunity.IsSet(ResistanceTypes.Magic) ||
                    (applyType == ApplyTypes.WearSpell && !add) ||
                    (applyType == ApplyTypes.RemoveSpell && add) ||
                    handler.SavingCharacter == ch ||
                    handler.LoadingCharacter == ch)
                {
                    return;
                }

                mod = Math.Abs(mod);
                var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod];

                if (Macros.IS_VALID_SN(mod) && skill != null && skill.Type == SkillTypes.Spell)
                {
                    if (skill.Target == TargetTypes.Ignore ||
                        skill.Target == TargetTypes.InventoryObject)
                    {
                        LogManager.Instance.Bug("ApplyTypes.WearSpell trying to apply bad target spell. SN is %d.", mod);
                        return;
                    }
                    var retcode = skill.SpellFunction.Value.Invoke(mod, ch.Level, ch, ch);
                    if (retcode == ReturnTypes.CharacterDied || ch.CharDied())
                    {
                        return;
                    }
                }
                break;

            default:
                var skillData = RepositoryManager.Instance.GetEntity <SkillData>(applyType.GetName());
                if (skillData != null)
                {
                    ch.ModifySkill((int)skillData.Type, mod, add);
                }
                else
                {
                    LogManager.Instance.Bug("affect_modify: unknown location %d", affect.Location);
                }
                break;
            }

            var wield       = ch.GetEquippedItem(WearLocations.Wield);
            var strWieldMod = (int)LookupManager.Instance.GetStatMod("Strength", ch.GetCurrentStrength(),
                                                                     StrengthModTypes.Wield);

            if (!ch.IsNpc() && handler.SavingCharacter != ch && wield != null && wield.GetWeight() > strWieldMod)
            {
                if (Depth == 0)
                {
                    Depth++;
                    comm.act(ATTypes.AT_ACTION, "You are too weak to wield $p any longer.", ch, wield, null,
                             ToTypes.Character);
                    comm.act(ATTypes.AT_ACTION, "$n stops wielding $p.", ch, wield, null, ToTypes.Room);
                    ch.Unequip(wield);
                    Depth--;
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Handlers to tell the victim which spell is being effected
        /// </summary>
        public static int dispel_casting(AffectData paf, CharacterInstance ch, CharacterInstance victim, int affect, bool dispel)
        {
            var isMage    = false;
            var hasDetect = false;

            if (ch.IsNpc() || ch.CurrentClass == ClassTypes.Mage)
            {
                isMage = true;
            }
            if (ch.IsAffected(AffectedByTypes.DetectMagic))
            {
                hasDetect = true;
            }

            string spell;

            if (paf != null)
            {
                var skill = RepositoryManager.Instance.GetEntity <SkillData>((int)paf.Type);
                if (skill == null)
                {
                    return(0);
                }
                spell = skill.Name;
            }
            else
            {
                spell = EnumerationExtensions.GetEnum <AffectedByTypes>(affect).GetName().ToLower();
            }

            ch.SetColor(ATTypes.AT_MAGIC);
            victim.SetColor(ATTypes.AT_HITME);

            var buffer = !ch.CanSee(victim)
                         ? "Someone"
                         : (victim.IsNpc()
                                ? victim.ShortDescription
                                : victim.Name).CapitalizeFirst();

            if (dispel)
            {
                victim.Printf("Your %s vanishes.", spell);
                if (isMage && hasDetect)
                {
                    ch.Printf("%s's %s vanishes.", buffer, spell);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                if (isMage && hasDetect)
                {
                    ch.Printf("%s's %s wavers but holds.", buffer, spell);
                }
                else
                {
                    return(0);
                }
            }

            return(1);
        }