예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        private static void CreateAnimatedCorpse(int level, CharacterInstance ch, MobileTemplate template, ObjectInstance corpse)
        {
            var mob = RepositoryManager.Instance.CHARACTERS.Create(template, 0,
                                                                   $"animated corpse {template.PlayerName}");

            ch.CurrentRoom.AddTo(mob);
            mob.Level       = (ch.Level / 2).GetLowestOfTwoNumbers(template.Level);
            mob.CurrentRace = EnumerationExtensions.GetEnumByName <RaceTypes>(template.Race);

            mob.MaximumHealth = template.Level * 8 +
                                SmaugRandom.Between(template.Level * template.Level / 4, template.Level * template.Level);
            mob.MaximumHealth = (mob.MaximumHealth / 4).GetNumberThatIsBetween(
                mob.MaximumHealth * corpse.Value.ToList()[3] / 100, ch.Level * SmaugRandom.D20(10));
            mob.MaximumHealth = mob.MaximumHealth.GetHighestOfTwoNumbers(1);
            mob.CurrentHealth = mob.MaximumHealth;
            mob.DamageRoll    = new DiceData {
                SizeOf = ch.Level / 8
            };
            mob.HitRoll = new DiceData {
                SizeOf = ch.Level / 6
            };
            mob.CurrentAlignment = ch.CurrentAlignment;
            mob.ShortDescription = $"The animated corpse of {template.ShortDescription}";
            mob.LongDescription  =
                $"An animated corpse of {template.ShortDescription} struggles with the horror of its undeath.";
            mob.AddFollower(ch);

            MakeCorpseTemporary(level, mob);
            TransferContentsOfCorpse(corpse);
        }
예제 #3
0
        public static ReturnTypes spell_attack(int sn, int level, CharacterInstance ch, object vo)
        {
            var skill = RepositoryManager.Instance.SKILLS.Get(sn);
            var vch   = (CharacterInstance)vo;

            var saved = skill.CheckSave(level, ch, vch);

            if (CheckFunctions.CheckIfTrueCasting(
                    saved && Macros.SPELL_SAVE(skill) == (int)SpellSaveEffectTypes.Negate, skill, ch,
                    CastingFunctionType.Failed, vch))
            {
                return(ReturnTypes.SpellFailed);
            }

            var damage = GetBaseDamage(level, ch, skill);

            if (saved)
            {
                var spellSaveType =
                    EnumerationExtensions.GetEnum <SpellSaveEffectTypes>(Macros.SPELL_SAVE(skill));
                switch (spellSaveType)
                {
                case SpellSaveEffectTypes.ThreeQuartersDamage:
                    damage = GetThreeQuartersDamage(damage);
                    break;

                case SpellSaveEffectTypes.HalfDamage:
                    damage = GetHalfDamage(damage);
                    break;

                case SpellSaveEffectTypes.QuarterDamage:
                    damage = GetQuarterDamage(damage);
                    break;

                case SpellSaveEffectTypes.EighthDamage:
                    damage = GetEighthDamage(damage);
                    break;

                case SpellSaveEffectTypes.Absorb:
                    AbsorbDamage(ch, skill, vch, damage);
                    return(ReturnTypes.None);

                case SpellSaveEffectTypes.Reflect:
                    return(spell_attack(sn, level, vch, ch));
                }
            }

            var retcode = ch.CauseDamageTo(vch, damage, sn);

            if (retcode == ReturnTypes.None &&
                !ch.CharDied() && !vch.CharDied()
                &&
                (!vch.IsAffectedBy(sn) || skill.Flags.IsSet(SkillFlags.Accumulative) ||
                 skill.Flags.IsSet(SkillFlags.ReCastable)))
            {
                retcode = AffectCharacter.spell_affectchar(sn, level, ch, vch);
            }

            return(retcode);
        }
예제 #4
0
        public void Initialize()
        {
            for (var y = 0; y < Height; y++)
            {
                for (var x = 0; x < Width; x++)
                {
                    var cell = new WeatherCell(0)
                    {
                        Hemisphere =
                            EnumerationExtensions.GetEnum <HemisphereTypes>(SmaugRandom.Between(0, 1))
                    };

                    cell.ChangeTemperature(SmaugRandom.Between(-30, 100));
                    cell.ChangePressure(SmaugRandom.Between(0, 100));
                    cell.ChangeCloudCover(SmaugRandom.Between(0, 100));
                    cell.ChangeHumidity(SmaugRandom.Between(0, 100));
                    cell.ChangePrecip(SmaugRandom.Between(0, 100));
                    cell.ChangeWindSpeedX(SmaugRandom.Between(-100, 100));
                    cell.ChangeWindSpeedY(SmaugRandom.Between(-100, 100));
                    cell.ChangeEnergy(SmaugRandom.Between(0, 100));

                    _map[x][y] = cell;
                }
            }
        }
예제 #5
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);
        }
        public static ExtendedBitvector GetAttacks(this MobileTemplate template)
        {
            var bv    = new ExtendedBitvector();
            var words = template.Attacks.Split(' ');

            foreach (var word in words)
            {
                bv.SetBit((int)EnumerationExtensions.GetEnumIgnoreCase <AttackTypes>(word));
            }
            return(bv);
        }
        public static ExtendedBitvector GetAffected(this MobileTemplate template)
        {
            var bv    = new ExtendedBitvector();
            var words = template.GetStatistic <string>(StatisticTypes.AffectedByFlags).Split(' ');

            foreach (var word in words)
            {
                bv.SetBit((int)EnumerationExtensions.GetEnumIgnoreCase <AffectedByTypes>(word));
            }
            return(bv);
        }
        public static ExtendedBitvector GetDefenses(this MobileTemplate template)
        {
            var flags = new ExtendedBitvector();
            var words = template.Defenses.Split(' ');

            foreach (var word in words)
            {
                flags.SetBit((int)EnumerationExtensions.GetEnumIgnoreCase <DefenseTypes>(word));
            }

            return(flags);
        }
예제 #9
0
        public static ReturnTypes SpringTheTrap(this CharacterInstance ch, ObjectInstance obj)
        {
            var level    = obj.Value.ToList()[2];
            var txt      = string.Empty;
            var trapType = TrapTypes.None;
            DescriptorAttribute attrib = null;

            try
            {
                trapType = EnumerationExtensions.GetEnum <TrapTypes>(obj.Value.ToList()[1]);
                attrib   = trapType.GetAttribute <DescriptorAttribute>();
                txt      = attrib.Messages.FirstOrDefault();
            }
            catch (ArgumentException)
            {
                txt = TrapTypeLookupDefault;
            }

            var dam = SmaugRandom.Between(obj.Value.ToList()[2], obj.Value.ToList()[2] * 2);

            comm.act(ATTypes.AT_HITME, $"You are {txt}!", ch, null, null, ToTypes.Character);
            comm.act(ATTypes.AT_ACTION, $"$n is {txt}.", ch, null, null, ToTypes.Room);

            --obj.Value.ToList()[0];
            if (obj.Value.ToList()[0] <= 0)
            {
                obj.Extract();
            }

            var returnCode = ReturnTypes.None;

            if (!string.IsNullOrEmpty(attrib?.Messages.ToList()[1]))
            {
                var skill = RepositoryManager.Instance.GetEntity <SkillData>(attrib.Messages.ToList()[1]);
                returnCode = ch.ObjectCastSpell((int)skill.ID, level, ch);
            }

            if (trapType == TrapTypes.Blade || trapType == TrapTypes.ElectricShock)
            {
                returnCode = ch.CauseDamageTo(ch, dam, Program.TYPE_UNDEFINED);
            }
            if ((trapType == TrapTypes.PoisonArrow ||
                 trapType == TrapTypes.PoisonDagger ||
                 trapType == TrapTypes.PoisonDart ||
                 trapType == TrapTypes.PoisonNeedle) &&
                returnCode == ReturnTypes.None)
            {
                returnCode = ch.CauseDamageTo(ch, dam, Program.TYPE_UNDEFINED);
            }

            return(returnCode);
        }
예제 #10
0
        private static int GetDamageIfSaved(int sn, int level, CharacterInstance ch, SkillData skill, CharacterInstance vch,
                                            int damage)
        {
            var spellSaveType =
                EnumerationExtensions.GetEnum <SpellSaveEffectTypes>(
                    Macros.SPELL_SAVE(skill));

            switch (spellSaveType)
            {
            case SpellSaveEffectTypes.ThreeQuartersDamage:
                damage = GetThreeQuartersDamage(damage);
                break;

            case SpellSaveEffectTypes.HalfDamage:
                damage = GetHalfDamage(damage);
                break;

            case SpellSaveEffectTypes.QuarterDamage:
                damage = GetQuarterDamage(damage);
                break;

            case SpellSaveEffectTypes.EighthDamage:
                damage = GetEighthDamage(damage);
                break;

            case SpellSaveEffectTypes.Absorb:
                AbsorbDamage(ch, skill, vch, damage);
                return(damage);

            case SpellSaveEffectTypes.Reflect:
                if (ReflectDamage(sn, level, ch, vch))
                {
                    break;
                }
                return(damage);
            }
            return(damage);
        }
예제 #11
0
        private static ReturnTypes CastSingleTargetSpell(SkillData skill, int level, CharacterInstance ch, CharacterInstance victim)
        {
            if (CheckFunctions.CheckIfNullObjectCasting(victim, skill, ch))
            {
                return(ReturnTypes.SpellFailed);
            }

            if (CheckFunctions.CheckIfTrueCasting(
                    (skill.Type != SkillTypes.Herb && victim.Immunity.IsSet(ResistanceTypes.Magic))
                    ||
                    victim.IsImmune(
                        EnumerationExtensions.GetEnum <ResistanceTypes>(Macros.SPELL_DAMAGE(skill))),
                    skill, ch, CastingFunctionType.Immune, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            if (CheckFunctions.CheckIfTrueCasting(
                    victim.IsAffectedBy((int)skill.ID) && !skill.Flags.IsSet(SkillFlags.Accumulative) &&
                    !skill.Flags.IsSet(SkillFlags.ReCastable), skill, ch, CastingFunctionType.Failed, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            var saf = skill.Affects.FirstOrDefault();

            if (CheckFunctions.CheckIfTrueCasting(saf != null && saf.Location == (int)ApplyTypes.StripSN &&
                                                  !victim.IsAffectedBy(magic.ParseDiceExpression(ch, saf.Modifier)),
                                                  skill, ch, CastingFunctionType.Failed, victim))
            {
                return(ReturnTypes.SpellFailed);
            }

            return(CheckFunctions.CheckIfTrueCasting(skill.CheckSave(level, ch, victim), skill, ch,
                                                     CastingFunctionType.Failed, victim)
                ? ReturnTypes.SpellFailed
                : ReturnTypes.None);
        }
 public static GenderTypes GetGender(this MobileTemplate template)
 =>
 EnumerationExtensions.GetEnumIgnoreCase <GenderTypes>(template.GetStatistic <string>(StatisticTypes.Gender));
 public static PositionTypes GetDefensivePosition(this MobileTemplate template)
 => EnumerationExtensions.GetEnumIgnoreCase <PositionTypes>(template.DefensivePosition);
 public static int GetRace(this MobileTemplate template)
 => (int)EnumerationExtensions.GetEnumIgnoreCase <RaceTypes>(template.Race);
        public CharacterInstance Create(Template parent, params object[] args)
        {
            Validation.IsNotNull(parent, "parent");
            Validation.Validate(parent is MobileTemplate, "Invalid Template Type");

            var mobParent = parent.CastAs <MobileTemplate>();

            long id;

            if (args != null && args.Length > 0)
            {
                id = Convert.ToInt64(args[0]);
            }
            else
            {
                id = GetNextId;
            }

            var name = parent.Name;

            if (args != null && args.Length > 1)
            {
                name = args[1].ToString();
            }

            var isMobile = true;
            //if (args != null && args.Length > 2)
            //    isMobile = (bool) args[2];

            var mob = new CharacterInstance(id, name)
            {
                Parent           = parent,
                ShortDescription = mobParent.ShortDescription,
                LongDescription  = mobParent.LongDescription,
                Description      = parent.Description,
                Level            = SmaugRandom.Fuzzy(mobParent.Level),
                Act              = mobParent.GetActFlags(),
                HomeVNum         = -1,
                ResetVnum        = -1,
                ResetNum         = -1,
                AffectedBy       = mobParent.GetAffected(),
                CurrentAlignment = mobParent.GetStatistic <int>(StatisticTypes.Alignment),
                Gender           = EnumerationExtensions.GetEnum <GenderTypes>(mobParent.GetStatistic <string>(StatisticTypes.Gender))
            };

            if (isMobile)
            {
                var mi = (MobileInstance)mob;
                mi.SpecialFunction = mobParent.SpecialFunction;

                if (!string.IsNullOrEmpty(mobParent.SpecFun))
                {
                    mi.SpecialFunctionName = mobParent.SpecFun;
                }
            }

            if (mob.Act.IsSet((int)ActFlags.MobInvisibility))
            {
                mob.MobInvisible = mob.Level;
            }

            mob.ArmorClass = mobParent.GetStatistic <int>(StatisticTypes.ArmorClass) > 0
                                 ? mobParent.GetStatistic <int>(StatisticTypes.ArmorClass)
                                 : mob.Level.Interpolate(100, -100);

            if (mobParent.HitDice == null || mobParent.HitDice.NumberOf == 0)
            {
                mob.MaximumHealth = mob.Level * 8 + SmaugRandom.Between(mob.Level * mob.Level / 4, mob.Level * mob.Level);
            }
            else
            {
                mob.MaximumHealth = mobParent.HitDice.NumberOf * SmaugRandom.Between(1, mobParent.HitDice.SizeOf) +
                                    mobParent.HitDice.Bonus;
            }

            mob.CurrentCoin              = mobParent.GetStatistic <int>(StatisticTypes.Coin);
            mob.Experience               = mobParent.GetStatistic <int>(StatisticTypes.Experience);
            mob.CurrentPosition          = mobParent.GetPosition();
            mob.CurrentDefensivePosition = mobParent.GetDefensivePosition();
            mob.BareDice = new DiceData
            {
                NumberOf = mobParent.DamageDice.NumberOf,
                SizeOf   = mobParent.DamageDice.SizeOf
            };
            mob.ToHitArmorClass0 = mobParent.GetStatistic <int>(StatisticTypes.ToHitArmorClass0);
            mob.HitRoll          = new DiceData
            {
                Bonus = mobParent.HitDice.Bonus
            };
            mob.DamageRoll = new DiceData
            {
                Bonus = mobParent.DamageDice.Bonus
            };
            mob.PermanentStrength     = mobParent.GetStatistic <int>(StatisticTypes.PermanentStrength);
            mob.PermanentDexterity    = mobParent.GetStatistic <int>(StatisticTypes.PermanentDexterity);
            mob.PermanentWisdom       = mobParent.GetStatistic <int>(StatisticTypes.PermanentWisdom);
            mob.PermanentIntelligence = mobParent.GetStatistic <int>(StatisticTypes.PermanentIntelligence);
            mob.PermanentConstitution = mobParent.GetStatistic <int>(StatisticTypes.PermanentConstitution);
            mob.PermanentCharisma     = mobParent.GetStatistic <int>(StatisticTypes.PermanentCharisma);
            mob.PermanentLuck         = mobParent.GetStatistic <int>(StatisticTypes.PermanentLuck);
            mob.CurrentRace           = EnumerationExtensions.GetEnum <RaceTypes>(mobParent.GetRace());
            mob.CurrentClass          = EnumerationExtensions.GetEnum <ClassTypes>(mobParent.Class);
            mob.ExtraFlags            = mobParent.ExtraFlags;
            mob.SavingThrows          = new SavingThrowData(mobParent.SavingThrows);
            mob.Height         = mobParent.GetStatistic <int>(StatisticTypes.Height);
            mob.Weight         = mobParent.GetStatistic <int>(StatisticTypes.Weight);
            mob.Resistance     = mobParent.GetResistance();
            mob.Immunity       = mobParent.GetImmunity();
            mob.Susceptibility = mobParent.GetSusceptibility();

            if (isMobile)
            {
                ((MobileInstance)mob).Attacks = new ExtendedBitvector(mobParent.GetAttacks());
            }

            mob.Defenses        = mobParent.GetDefenses();
            mob.NumberOfAttacks = mobParent.GetStatistic <int>(StatisticTypes.NumberOfAttacks);
            //mob.Speaks = build.get_langflag(mobParent.Speaks);
            //mob.Speaking = build.get_langflag(mobParent.Speaking);

            Add(mob.ID, mob);

            return(mob);
        }
예제 #16
0
        public static void fread_variable(CharacterInstance ch, TextReaderProxy proxy)
        {
            var vd = new VariableData();

            for (; ;)
            {
                var word = proxy.EndOfStream ? "End" : proxy.ReadNextWord();

                switch (char.ToUpper(word.ToCharArray()[0]))
                {
                case '*':
                    proxy.ReadToEndOfLine();
                    break;

                case 'C':
                    vd.CTime = DateTime.FromFileTimeUtc(proxy.ReadNumber());
                    break;

                case 'E':
                    if (word.Equals("End", StringComparison.OrdinalIgnoreCase))
                    {
                        if (vd.Type == VariableTypes.Integer)
                        {
                            tag_char(ch, vd, 1);
                        }
                        else
                        {
                            LogManager.Instance.Bug("%s: invalid/incomplete variable: %s",
                                                    "fread_variable", vd.Tag);
                        }
                    }
                    break;

                case 'F':
                    vd.Flags = proxy.ReadNumber();
                    break;

                case 'I':
                    if (word.Equals("Int", StringComparison.OrdinalIgnoreCase))
                    {
                        if (vd.Type != VariableTypes.Integer)
                        {
                            LogManager.Instance.Bug("%s: Type mismatch -- type(%d) != vtInt",
                                                    "fread_variable", vd.Type);
                        }
                        else
                        {
                            vd.Data = proxy.ReadNumber();
                        }
                    }
                    break;

                case 'M':
                    vd.MTime = DateTime.FromFileTimeUtc(proxy.ReadNumber());
                    break;

                case 'R':
                    vd.RTime = DateTime.FromFileTimeUtc(proxy.ReadNumber());
                    break;

                case 'S':
                    if (word.Equals("Str", StringComparison.OrdinalIgnoreCase))
                    {
                        if (vd.Type != VariableTypes.String)
                        {
                            LogManager.Instance.Bug("%s: Type mismatch -- type(%d) != String",
                                                    "fread_variable", vd.Type);
                        }
                        else
                        {
                            vd.Data = proxy.ReadString();
                        }
                    }
                    break;

                case 'T':
                    vd.Tag   = proxy.ReadString("~");
                    vd.Timer = proxy.ReadNumber();
                    vd.Type  = EnumerationExtensions.GetEnum <VariableTypes>(proxy.ReadNumber());
                    break;

                case 'V':
                    vd.vnum = proxy.ReadNumber();
                    break;

                case 'X':
                    if (word.Equals("Xbit", StringComparison.OrdinalIgnoreCase))
                    {
                        if (vd.Type != VariableTypes.ExtendedBit)
                        {
                            LogManager.Instance.Bug("%s: Type mismatch -- type(%d) != ExtendedBit",
                                                    "fread_variable", vd.Type);
                        }
                        else
                        {
                            vd.Data = proxy.ReadBitvector();
                        }
                    }
                    break;
                }
            }
        }