public GameStateLoader(IRealmLiveDbContext liveDbContext, IRealmDbContext dbContext, ILogWrapper logger)
     : base(1, "GameStateLoader")
 {
     _liveDbContext = liveDbContext;
     _dbContext     = dbContext;
     _log           = logger;
 }
Exemple #2
0
        public static int GetClassId(this IRealmDbContext dbContext, SystemTypes systemType, string className)
        {
            var obj = dbContext.SystemClasses.Where(x => x.SystemType == systemType)
                      .Where(x => x.Name == className);

            return(obj.Count() != 1 ? 0 : obj.ToList()[0].Id);
        }
Exemple #3
0
        private void SaveTags()
        {
            IRealmDbContext dbContext = Program.NinjectKernel.Get <IRealmDbContext>();

            foreach (SystemTagSet set in cboCategory.Items)
            {
                var tagSet = set;

                foreach (var id in DeletedTags[tagSet.Name])
                {
                    var tag = dbContext.Tags.FirstOrDefault(x => x.Id == id);
                    dbContext.Tags.Remove(tag);
                }

                foreach (var tag in tagSet.Tags.Values)
                {
                    var foundTag = dbContext.Tags.FirstOrDefault(x => x.Name == tag.Name &&
                                                                 x.TagCategory == set.Category);
                    if (foundTag == null)
                    {
                        foundTag = new Tag();
                        dbContext.Tags.Add(foundTag);
                    }

                    foundTag.Name        = tag.Name;
                    foundTag.TagCategory = set.Category;
                }

                dbContext.SaveChanges();
            }

            Close();
        }
Exemple #4
0
        public static int GetBitValue(this IRealmDbContext dbContext, BitTypes bitType, string name)
        {
            var bit =
                dbContext.Bits.Where(x => x.BitType == bitType)
                .FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            return(bit?.Value ?? 0);
        }
Exemple #5
0
 protected EditorBuilder(SystemTypes aSystemType, string aDisplayName, string aDisplayPlural,
                         IRealmDbContext realmDbContext, IRealmAdminDbContext realmAdminContext)
 {
     DisplayName       = aDisplayName;
     DisplayPlural     = aDisplayPlural;
     SystemType        = aSystemType;
     Icon              = null;
     IsVisible         = true;
     RealmContext      = realmDbContext;
     RealmAdminContext = realmAdminContext;
 }
Exemple #6
0
        public static bool DoesPrimitiveHaveBit(this IRealmDbContext dbContext, BitTypes bitType, int bitField, string bitName)
        {
            var bits = dbContext.Bits.Where(x => x.BitType == bitType).ToList();
            var bit  = bits.FirstOrDefault(x => x.Name.Equals(bitName, StringComparison.OrdinalIgnoreCase));

            if (bit == null)
            {
                return(false);
            }

            return((bitField & bit.Value) != 0);
        }
Exemple #7
0
 private void SeedTags(IRealmDbContext context)
 {
     foreach (var key in _tagTable.Keys)
     {
         var values = _tagTable[key];
         context.Tags.AddOrUpdate(x => x.Id, new Tag
         {
             Id          = key,
             TagCategory = (TagCategoryTypes)values[0],
             Name        = (string)values[1],
         });
     }
 }
Exemple #8
0
        public static IEnumerable <IPrimitive> GetPrimitives(this IRealmDbContext dbContext, SystemTypes systemType,
                                                             int classId)
        {
            IQueryable <IPrimitive> queryableSet = GetQueryableSet(dbContext, systemType);

            if (queryableSet == null)
            {
                return(null);
            }

            return(queryableSet.Where(x => x.SystemClass.SystemType == systemType)
                   .Where(x => x.SystemClass.Id == classId)
                   .ToEnumerable());
        }
Exemple #9
0
        private void SeedSystemClasses(IRealmDbContext context)
        {
            foreach (var key in _systemClassTable.Keys)
            {
                var kvp = _systemClassTable[key];

                context.SystemClasses.AddOrUpdate(x => x.Id, new SystemClass
                {
                    Id         = key,
                    Name       = kvp.Key,
                    SystemType = kvp.Value
                });
            }
        }
Exemple #10
0
        public override void InitContentImpl(int id)
        {
            IRealmDbContext dbContext = Program.NinjectKernel.Get <IRealmDbContext>();
            var             obj       = (Ability)dbContext.GetPrimitive(SystemTypes.Ability, id);

            txtSystemName.Text           = obj.SystemName;
            txtDisplayName.Text          = obj.DisplayName;
            txtDisplayDescription.Text   = obj.DisplayDescription;
            numRechargeRate.Value        = (decimal)obj.RechargeRate;
            numericUpDownPreDelay.Value  = (decimal)obj.PreDelay;
            numericUpDownPostDelay.Value = (decimal)obj.PostDelay;
            numStaminaCost.Value         = obj.StaminaCost;
            numManaCost.Value            = obj.ManaCost;

            cboOffensiveStat.Fill <Statistic>((int)obj.OffensiveStat);
            cboDefensiveStat.Fill <Statistic>((int)obj.DefensiveStat);

            if (obj.Terrain != null)
            {
                linkTerrain.Setup(SystemTypes.Terrain, obj.Terrain.Id);
            }
            if (obj.InterruptionResistSkill != null)
            {
                linkInterruptResist.Setup(SystemTypes.Skill, obj.InterruptionResistSkill.Id);
            }
            if (obj.InterruptionEffect != null)
            {
                linkInterruptEffect.Setup(SystemTypes.Effect, obj.InterruptionEffect.Id);
            }

            PopulateCheckboxes(dbContext, obj);

            _tagSetId = obj.TagSet?.Id ?? 0;
            if (_tagSetId > 0)
            {
                lstAbilityTags.Fill("AbilityTags", _tagSetId);
            }
            else
            {
                lstAbilityTags.Fill("AbilityTags");
            }

            // TODO: Populate AbilityEffects
            // TODO: Populate AbilityPrerequisites
            // TODO: Populate AbilityReagants
            // TODO: Populate AbilityGuild

            ControlName = txtSystemName.Text;
        }
Exemple #11
0
        private void SeedColors(IRealmDbContext context)
        {
            foreach (var key in _colorsTable.Keys)
            {
                var values = _colorsTable[key];

                context.Colors.AddOrUpdate(x => x.Id, new Color
                {
                    Id     = key,
                    Name   = (string)values[0],
                    Ascii  = (string)values[1],
                    Escape = (string)values[2]
                });
            }
        }
Exemple #12
0
        private void SeedGuildLevels(IRealmDbContext context)
        {
            foreach (var key in _guildLevelTable.Keys)
            {
                var values = _guildLevelTable[key];

                context.GuildLevels.AddOrUpdate(x => x.Id, new GuildLevel
                {
                    Id                 = key,
                    Level              = (int)values[0],
                    XpRequired         = (int)values[1],
                    MaxNumberOfMembers = (int)values[2]
                });
            }
        }
Exemple #13
0
        private void SeedMovementModes(IRealmDbContext context)
        {
            foreach (var key in _movementModeTable.Keys)
            {
                var values = _movementModeTable[key];

                context.MovementModes.AddOrUpdate(x => x.Id, new MovementMode
                {
                    Id         = key,
                    Name       = (string)values[0],
                    Value      = (int)values[1],
                    ShortNamne = (string)values[2]
                });
            }
        }
Exemple #14
0
        private void SeedWearLocations(IRealmDbContext context)
        {
            foreach (var key in _wearLocationTable.Keys)
            {
                var values = _wearLocationTable[key];

                context.WearLocations.AddOrUpdate(x => x.Id, new WearLocation
                {
                    Id         = key,
                    Name       = (string)values[0],
                    Value      = (int)values[1],
                    ShortNamne = (string)values[2],
                    LongName   = (string)values[3]
                });
            }
        }
Exemple #15
0
        private void SeedElements(IRealmDbContext context)
        {
            foreach (var key in _elementsTable.Keys)
            {
                var values = _elementsTable[key];

                context.Elements.AddOrUpdate(x => x.Id, new Element
                {
                    Id   = key,
                    Name = (string)values[0],
                    OppositeElementId = (int)values[1],
                    LeftElementId     = (int)values[2],
                    RightElementId    = (int)values[3]
                });
            }
        }
Exemple #16
0
        private void SeedEvents(IRealmDbContext context)
        {
            foreach (var key in _eventsTable.Keys)
            {
                var values = _eventsTable[key];

                context.Events.AddOrUpdate(x => x.Id, new Event
                {
                    Id            = key,
                    Name          = (string)values[0],
                    IsItemEvent   = (bool)values[1],
                    IsMobileEvent = (bool)values[2],
                    IsSpaceEvent  = (bool)values[3]
                });
            }
        }
Exemple #17
0
 private void PopulateCheckboxes(IRealmDbContext dbContext, Ability obj)
 {
     chkNotInterruptible.Checked = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits,
                                                                  "NotInterruptible");
     chkAutoAttack.Checked     = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits, "AutoAttack");
     chkWeaponRequired.Checked = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits,
                                                                "WeaponRequired");
     chkImplementRequired.Checked = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits,
                                                                   "ImplementRequired");
     chkVerbalRequired.Checked  = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits, "VerbalRequired");
     chkPassive.Checked         = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits, "Passive");
     chkTerrainRequired.Checked = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits,
                                                                 "TerrainRequired");
     chkNoCombatUse.Checked   = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits, "NoCombatUse");
     chkSightRequired.Checked = dbContext.DoesPrimitiveHaveBit(BitTypes.AbilityBits, obj.Bits, "SightRequired");
 }
Exemple #18
0
        private void SeedBits(IRealmDbContext context)
        {
            foreach (var key in _bitTable.Keys)
            {
                var values = _bitTable[key];

                context.Bits.AddOrUpdate(x => x.Id, new Bit
                {
                    Id          = key,
                    Name        = (string)values[0],
                    Value       = (int)values[1],
                    BitType     = (BitTypes)values[2],
                    Description = values[3] == null ? string.Empty : (string)values[3],
                    UniqueGroup = values[4] == null ? string.Empty : (string)values[4]
                });
            }
        }
Exemple #19
0
        public static EditorSystemClass GetSystemClass(this IRealmDbContext dbContext, int classId)
        {
            var classList = dbContext.SystemClasses.Where(x => x.ParentClassId == null).ToList();

            var foundClass = classList.Find(x => x.Id == classId);

            if (foundClass == null)
            {
                return(null);
            }

            return(new EditorSystemClass
            {
                ClassId = foundClass.Id,
                Name = foundClass.Name,
                SystemType = (int)foundClass.SystemType
            });
        }
Exemple #20
0
        private static IQueryable <IPrimitive> GetQueryableSet(IRealmDbContext dbContext, SystemTypes systemType)
        {
            IQueryable <IPrimitive> queryableSet;

            switch (systemType)
            {
            case SystemTypes.Ability:
                queryableSet = dbContext.Abilities.Include(x => x.SystemClass); break;

            case SystemTypes.Archetype:
                queryableSet = dbContext.Archetypes.Include(x => x.SystemClass); break;

            case SystemTypes.Barrier:
                queryableSet = dbContext.Barriers.Include(x => x.SystemClass); break;

            case SystemTypes.Behavior:
                queryableSet = dbContext.Behaviors.Include(x => x.SystemClass); break;

            case SystemTypes.Conversation:
                queryableSet = dbContext.Conversations.Include(x => x.SystemClass); break;

            case SystemTypes.Effect:
                queryableSet = dbContext.Effects.Include(x => x.SystemClass); break;

            case SystemTypes.Faction:
                queryableSet = dbContext.Factions.Include(x => x.SystemClass); break;

            case SystemTypes.GameCommand:
                queryableSet = dbContext.GameCommands.Include(x => x.SystemClass); break;

            case SystemTypes.HelpLookup:
                queryableSet = dbContext.Helps.Include(x => x.SystemClass); break;

            case SystemTypes.Item:
                queryableSet = dbContext.Items.Include(x => x.SystemClass); break;

            case SystemTypes.ItemSet:
                queryableSet = dbContext.ItemSets.Include(x => x.SystemClass); break;

            case SystemTypes.Liquid:
                queryableSet = dbContext.Liquids.Include(x => x.SystemClass); break;

            case SystemTypes.Mobile:
                queryableSet = dbContext.Mobiles.Include(x => x.SystemClass); break;

            case SystemTypes.Month:
                queryableSet = dbContext.Months.Include(x => x.SystemClass); break;

            case SystemTypes.MudProg:
                queryableSet = dbContext.MudProgs.Include(x => x.SystemClass); break;

            case SystemTypes.Quest:
                queryableSet = dbContext.Quests.Include(x => x.SystemClass); break;

            case SystemTypes.Race:
                queryableSet = dbContext.Races.Include(x => x.SystemClass); break;

            case SystemTypes.Reset:
                queryableSet = dbContext.Resets.Include(x => x.SystemClass); break;

            case SystemTypes.Ritual:
                queryableSet = dbContext.Rituals.Include(x => x.SystemClass); break;

            case SystemTypes.Shop:
                queryableSet = dbContext.Shops.Include(x => x.SystemClass); break;

            case SystemTypes.Skill:
                queryableSet = dbContext.Skills.Include(x => x.SystemClass); break;

            case SystemTypes.SkillCategory:
                queryableSet = dbContext.SkillCategories.Include(x => x.SystemClass); break;

            case SystemTypes.Social:
                queryableSet = dbContext.Socials.Include(x => x.SystemClass); break;

            case SystemTypes.Space:
                queryableSet = dbContext.Spaces.Include(x => x.SystemClass); break;

            case SystemTypes.Spawn:
                queryableSet = dbContext.Spawns.Include(x => x.SystemClass); break;

            case SystemTypes.Terrain:
                queryableSet = dbContext.Terrains.Include(x => x.SystemClass); break;

            case SystemTypes.Treasure:
                queryableSet = dbContext.Treasures.Include(x => x.SystemClass); break;

            case SystemTypes.Zone:
                queryableSet = dbContext.Zones.Include(x => x.SystemClass); break;

            default:
                throw new InvalidDataException();
            }

            return(queryableSet);
        }
Exemple #21
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;
            }
        }
Exemple #22
0
        public static string GetClassName(this IRealmDbContext dbContext, int classId)
        {
            var obj = dbContext.SystemClasses.FirstOrDefault(x => x.Id == classId);

            return(obj != null ? obj.Name : string.Empty);
        }
Exemple #23
0
 public MonthBuilder(IRealmDbContext realmContext, IRealmAdminDbContext realmAdminContext)
     : base(SystemTypes.Month, "Month", "Months", realmContext, realmAdminContext)
 {
     Icon = Icon.FromHandle(Properties.Resources.icons_ability_16.GetHicon());
 }
Exemple #24
0
 public AbilityBuilder(IRealmDbContext realmContext, IRealmAdminDbContext realmAdminContext)
     : base(SystemTypes.Ability, "Ability", "Abilities", realmContext, realmAdminContext)
 {
     Icon = Icon.FromHandle(Resources.icons_ability_16.GetHicon());
 }
Exemple #25
0
 public static SystemClass GetClass(this IRealmDbContext dbContext, int classId)
 {
     return(dbContext.SystemClasses.FirstOrDefault(x => x.Id == classId));
 }
Exemple #26
0
 public static SystemTypes GetSystemType(this IRealmDbContext dbContext, int classId)
 {
     return(dbContext.GetClass(classId).SystemType);
 }
Exemple #27
0
        public static IPrimitive GetPrimitive(this IRealmDbContext dbContext, SystemTypes systemType, int id)
        {
            IQueryable <IPrimitive> queryableSet = GetQueryableSet(dbContext, systemType);

            return(queryableSet.SingleOrDefault(x => x.Id == id));
        }