Example #1
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;
        }
Example #2
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;
            }
        }