Esempio n. 1
0
        public static void Init()
        {
            TagSets.Clear();

            if (Program.MainForm != null)
            {
                Program.MainForm.ProgressStatus.Minimum = 0;
                Program.MainForm.ProgressStatus.Maximum = Enum.GetValues(typeof(TagCategoryTypes)).Length;
                Program.MainForm.ProgressStatus.Value   = 0;
            }

            foreach (var category in EnumerationFunctions.GetAllEnumValues <TagCategoryTypes>())
            {
                var tagSet = new SystemTagSet(category.ToString(), category);
                tagSet.AddTags(category);
                TagSets.Add(category.ToString(), tagSet);

                Application.DoEvents();
                if (Program.MainForm == null)
                {
                    continue;
                }

                Program.MainForm.ProgressStatus.Value++;
                Program.MainForm.SetStatusMessage($"Loading Tag Category [{category}]");
            }

            Program.Log.InfoFormat($"{Enum.GetValues(typeof(TagCategoryTypes)).Length} tag categories loaded.");
        }
Esempio n. 2
0
        public void GetValuesFact()
        {
            IEnumerable <Fact> list = EnumerationFunctions.GetAllEnumValues <Fact>();

            list.Should().NotBeNull();

            List <Fact> enumList = list.ToList();

            enumList.Should().Contain(Fact.Fact1);
            enumList.Should().Contain(Fact.Fact2);
        }
Esempio n. 3
0
        private static string GetConditionPhrase(int percent, bool isSelf)
        {
            var healthCond = HealthConditionTypes.PerfectHealth;

            foreach (var cond in EnumerationFunctions.GetAllEnumValues <HealthConditionTypes>()
                     .Where(cond => percent >= cond.GetValue()))
            {
                healthCond = cond;
            }

            var attrib = healthCond.GetAttribute <DescriptorAttribute>();

            return(isSelf ? attrib.Messages.First() : attrib.Messages.ToList()[1]);
        }
Esempio n. 4
0
        /// <summary>
        /// Matches the given type to an equivalent enumerated repository type
        /// </summary>
        /// <param name="objectType"></param>
        /// <returns></returns>
        private static RepositoryTypes ObjectTypeToRepositoryType(Type objectType)
        {
            foreach (var repoType in EnumerationFunctions.GetAllEnumValues <RepositoryTypes>())
            {
                var attrib = EnumerationExtensions.GetAttribute <TypeMapAttribute>(repoType);
                if (attrib?.Object == null)
                {
                    continue;
                }
                if (attrib.Object == objectType)
                {
                    return(repoType);
                }
            }

            throw new ArgumentException($"{objectType} is not a valid Repository Type", nameof(objectType));
        }
Esempio n. 5
0
        public RepositoryManager(IKernel kernel, ILogManager logManager)
        {
            LogManager = logManager;
            Kernel     = kernel;

            _repositories = new Dictionary <RepositoryTypes, object>();
            foreach (var repoType in EnumerationFunctions.GetAllEnumValues <RepositoryTypes>())
            {
                var attrib = EnumerationExtensions.GetAttribute <TypeMapAttribute>(repoType);
                if (attrib?.Repository == null)
                {
                    continue;
                }

                _repositories.Add(repoType, Activator.CreateInstance(attrib.Repository));
            }
        }
Esempio n. 6
0
        public override bool SaveImpl()
        {
            try
            {
                var dbContext = Program.NinjectKernel.Get <IRealmDbContext>();
                var race      = (Race)(Id == 0 ? new Race() : dbContext.GetPrimitive(SystemTypes.Race, Id));

                if (Id == 0)
                {
                    race.SystemClass = dbContext.SystemClasses.FirstOrDefault(x => x.Id == ClassId);
                    dbContext.Races.Add(race);
                }

                race.SystemName         = txtSystemName.Text;
                race.DisplayName        = txtDisplayName.Text;
                race.DisplayDescription = txtDisplayDescription.Text;
                race.Abbreviation       = txtAbbreviation.Text;
                race.SizeType           = (SizeTypes)EnumerationFunctions.GetEnumByName <SizeTypes>(cboSize.Text);

                int bits = chkPlayerRace.Checked ? dbContext.GetBitValue(BitTypes.RaceBits, "PlayerRace") : 0;
                race.Bits = bits;

                // todo stat mod grid
                // todo ability grid
                // todo hit location grid

                dbContext.SaveChanges();

                Id = race.Id;
                InitContent(Id);

                return(true);
            }
            catch (DataException ex)
            {
                Program.Log.Error($"Error saving {ControlName}", ex);
                return(false);
            }
            catch (Exception ex)
            {
                Program.Log.Error(ex);
                throw;
            }
        }
Esempio n. 7
0
        public static void mudprog_read_programs(TextReaderProxy proxy, Template index)
        {
            for (; ;)
            {
                var letter = proxy.ReadNextLetter();
                if (letter == '|')
                {
                    return;
                }
                if (letter != '>')
                {
                    LogManager.Instance.Bug("Vnum {0} MudProg Char", index.ID);
                    throw new Exception();
                }

                var prog = new MudProgData();
                index.AddMudProg(prog);

                var type = (MudProgTypes)EnumerationFunctions.GetEnumByName <MudProgTypes>(proxy.ReadNextWord());
                if (type == MudProgTypes.Error)
                {
                    LogManager.Instance.Bug("Invalid mud prog type {0} for Index {1}", type, index.ID);
                    throw new Exception();
                }
                prog.Type = type;

                if (type == MudProgTypes.InFile)
                {
                    prog.IsFileProg = false;
                    prog.ArgList    = proxy.ReadString();
                    mudprog_file_read(index, prog.ArgList);
                }
                else
                {
                    // index.ProgTypes.SetBit((int)prog.Type);
                    prog.IsFileProg = false;
                    prog.ArgList    = proxy.ReadString();
                    prog.Script     = proxy.ReadString();
                }
            }
        }
Esempio n. 8
0
        public static void mudprog_file_read(Template index, string filename)
        {
            var path = SystemConstants.GetSystemDirectory(SystemDirectoryTypes.Prog) + filename;

            using (var proxy = new TextReaderProxy(new StreamReader(path)))
            {
                do
                {
                    var line = proxy.ReadLine();
                    if (line.StartsWith("|"))
                    {
                        break;
                    }
                    if (line.StartsWith(">"))
                    {
                        continue;
                    }

                    var type = (MudProgTypes)EnumerationFunctions.GetEnumByName <MudProgTypes>(proxy.ReadNextWord());
                    if (type == MudProgTypes.Error ||
                        type == MudProgTypes.InFile)
                    {
                        LogManager.Instance.Bug("Invalid mud prog type {0} in file {1}", type, path);
                        continue;
                    }

                    var prog = new MudProgData
                    {
                        Type       = type,
                        ArgList    = proxy.ReadString(),
                        Script     = proxy.ReadString(),
                        IsFileProg = true
                    };

                    index.AddMudProg(prog);
                    break;
                } while (!proxy.EndOfStream);
            }
        }
Esempio n. 9
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. 10
0
        public override bool SaveImpl()
        {
            try
            {
                IRealmDbContext dbContext = Program.NinjectKernel.Get <IRealmDbContext>();
                var             ability   = (Ability)(Id == 0 ? new Ability() : dbContext.GetPrimitive(SystemTypes.Ability, Id));

                if (Id == 0)
                {
                    ability.SystemClass = dbContext.SystemClasses.FirstOrDefault(x => x.Id == ClassId);
                    dbContext.Abilities.Add(ability);
                }

                ability.SystemName         = txtSystemName.Text;
                ability.DisplayName        = txtDisplayName.Text;
                ability.DisplayDescription = txtDisplayDescription.Text;

                ability.RechargeRate  = (float)numRechargeRate.Value;
                ability.StaminaCost   = (int)numStaminaCost.Value;
                ability.ManaCost      = (int)numManaCost.Value;
                ability.PreDelay      = (float)numericUpDownPreDelay.Value;
                ability.PostDelay     = (float)numericUpDownPostDelay.Value;
                ability.OffensiveStat = (Statistic)EnumerationFunctions.GetEnumByName <Statistic>(cboOffensiveStat.Text);
                ability.DefensiveStat = (Statistic)EnumerationFunctions.GetEnumByName <Statistic>(cboDefensiveStat.Text);

                ability.InterruptionEffect = linkInterruptEffect.GetContentId() == 0
                    ? null
                    : dbContext.Effects.FirstOrDefault(x => x.Id == linkInterruptEffect.GetContentId());

                ability.InterruptionResistSkill = linkInterruptResist.GetContentId() == 0
                    ? null
                    : dbContext.Skills.FirstOrDefault(x => x.Id == linkInterruptResist.GetContentId());

                ability.Terrain = linkTerrain.GetContentId() == 0
                    ? null
                    : dbContext.Terrains.FirstOrDefault(x => x.Id == linkTerrain.GetContentId());

                int bits = chkNotInterruptible.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "NotInterruptible") : 0;
                bits        += chkAutoAttack.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "AutoAttack") : 0;
                bits        += chkWeaponRequired.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "WeaponRequired") : 0;
                bits        += chkImplementRequired.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "ImplementRequired") : 0;
                bits        += chkVerbalRequired.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "VerbalRequired") : 0;
                bits        += chkPassive.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "Passive") : 0;
                bits        += chkTerrainRequired.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "TerrainRequired") : 0;
                bits        += chkNoCombatUse.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "NoCombatUse") : 0;
                bits        += chkSightRequired.Checked ? dbContext.GetBitValue(BitTypes.AbilityBits, "SightRequired") : 0;
                ability.Bits = bits;

                // todo tag set

                // TODO: Save AbilityEffects
                // TODO: Save AbilityPrerequisites
                // TODO: Save AbilityReagants
                // TODO: Save AbilityGuild

                dbContext.SaveChanges();

                Id = ability.Id;
                InitContent(Id);

                return(true);
            }
            catch (DataException ex)
            {
                Program.Log.Error($"Error saving {ControlName}", ex);
                return(false);
            }
            catch (Exception ex)
            {
                Program.Log.Error(ex);
                throw;
            }
        }
Esempio n. 11
0
        public void MinFact()
        {
            var result = EnumerationFunctions.MinimumEnumValue <Fact>();

            result.Should().Be(1);
        }
Esempio n. 12
0
        public void MaxFact()
        {
            var result = EnumerationFunctions.MaximumEnumValue <Fact>();

            result.Should().Be(2);
        }
Esempio n. 13
0
        public void GetEnumByNameFact(string name, Enum expectedVal)
        {
            var result = EnumerationFunctions.GetEnumByName <Fact>(name);

            result.Should().Be(expectedVal);
        }
Esempio n. 14
0
 public void SetStatistic(string name, object value)
 => Statistics[(StatisticTypes)EnumerationFunctions.GetEnumByName <StatisticTypes>(name)] = value;