示例#1
0
        private void LoadFromObjectStore(IObjectStore data)
        {
            Name = data.GetString("name");
            ShortLog.Debug("Loading Class: " + Name);
            SkillPoints         = data.GetInteger("skillpoints");
            HitDice             = DiceStrings.ParseSides(data.GetString("hitdice"));
            BaseAttackBonusRate = data.GetFloat("baseattackbonus");
            FortitudeSaveRate   = data.GetFloat("fortitude");
            ReflexSaveRate      = data.GetFloat("reflex");
            WillSaveRate        = data.GetFloat("will");
            ClassDevelopmentAge = data.GetEnum <ClassDevelopmentAge>("developedage");
            CustomBuildStep     = data.GetStringOptional("custom-build-step");

            //Load Levels
            var levels = data.GetObjectListOptional("levels");

            if (levels != null)
            {
                foreach (var l in levels)
                {
                    var level = new Level(l);
                    Levels.Add(level);
                }
            }

            var dice = data.GetStringOptional("startingwealth");

            if (dice != null)
            {
                StartingWealthDice = DiceStrings.ParseDice(dice);
            }

            this.HitDicePerLevel = new DiceClassLevelModifier(new Cup(new Die(HitDice)), StatNames.HitDice, this.Name, 1);
        }
示例#2
0
 public Gear(IObjectStore data)
 {
     Name = data.GetString("name");
     //ShortLog.DebugFormat("Loading Gear: {0}", Name);
     Weight       = data.GetFloat("weight");
     Value        = data.GetString("value").ToCoinValue();
     GroupSimilar = true;
 }
示例#3
0
 public Armor(IObjectStore data)
 {
     ShortLog.DebugFormat("Loading Armor: {0}", data.GetString("name"));
     this.Name                     = data.GetString("name");
     this.ArmorClass               = data.GetInteger("armor_class");
     this.Weight                   = data.GetFloat("weight");
     this.MaximumDexterityBonus    = data.GetInteger("maximum_dexterity_bonus");
     this.ArmorCheckPenalty        = data.GetInteger("armor_check_penalty");
     this.ArcaneSpellFailureChance = data.GetInteger("arcane_spell_failure_chance");
     this.ArmorType                = data.GetEnum <ArmorType>("armor_type");
     this.Value                    = data.GetString("cost").ToCoinValue();
 }
示例#4
0
 public Weapon(IObjectStore data)
 {
     ShortLog.DebugFormat("Loading Weapon: {0}", data.GetString("name"));
     this.Name             = data.GetString("name");
     this.Weight           = data.GetFloat("weight");
     this.Damage           = data.GetString("damage");
     this.DamageType       = data.GetEnum <DamageTypes>("damage_type");
     this.CriticalThreat   = data.GetIntegerOptional("critical_threat");
     this.CriticalModifier = data.GetIntegerOptional("critical_modifier");
     this.Range            = data.GetIntegerOptional("range");
     this.Type             = data.GetEnum <WeaponType>("type");
     this.Group            = data.GetEnum <WeaponGroup>("group");
     this.Level            = data.GetEnum <WeaponTrainingLevel>("training_level");
     this.Value            = data.GetStringOptional("cost").ToCoinValue();
     this.CriticalThreat   = this.CriticalThreat == 0 ? 20 : this.CriticalThreat;
     this.CriticalModifier = this.CriticalModifier == 0 ? 2 : this.CriticalModifier;
 }
示例#5
0
        public static T Deserialize <T>(this IObjectStore data, T result)
        {
            var typeInfo   = typeof(T);
            var properties = typeInfo.GetProperties();

            foreach (var prop in properties)
            {
                var attribute = prop.GetCustomAttribute <ObjectStoreAttribute>();
                if (attribute == null)
                {
                    continue;
                }

                var    propType      = prop.PropertyType.Name.ToLower();
                object propertyValue = null;
                object defaultValue  = attribute.DefaultValue;
                bool   useDefault    = defaultValue != null;
                string keyName       = attribute.PropertyName;

                switch (propType)
                {
                case "single":
                    if (attribute.Optional)
                    {
                        if (useDefault)
                        {
                            propertyValue = data.GetFloatOptional(keyName, (float)defaultValue);
                        }
                        else
                        {
                            propertyValue = data.GetFloatOptional(keyName);
                        }
                    }
                    else
                    {
                        propertyValue = data.GetFloat(keyName);
                    }
                    break;

                case "int32":
                    if (attribute.Optional)
                    {
                        if (useDefault)
                        {
                            propertyValue = data.GetIntegerOptional(keyName, (int)defaultValue);
                        }
                        else
                        {
                            propertyValue = data.GetIntegerOptional(keyName);
                        }
                    }
                    else
                    {
                        propertyValue = data.GetInteger(keyName);
                    }
                    break;

                case "string":
                    if (attribute.Optional)
                    {
                        if (useDefault)
                        {
                            propertyValue = data.GetStringOptional(keyName, defaultValue.ToString());
                        }
                        else
                        {
                            propertyValue = data.GetStringOptional(keyName);
                        }
                    }
                    else
                    {
                        propertyValue = data.GetString(keyName);
                    }
                    break;

                case "string[]":
                    if (attribute.Optional)
                    {
                        propertyValue = data.GetListOptional(keyName);
                    }
                    else
                    {
                        propertyValue = data.GetList(keyName);
                    }
                    break;

                case "boolean":
                    if (attribute.Optional)
                    {
                        if (useDefault)
                        {
                            propertyValue = data.GetBoolOptional(keyName, (bool)defaultValue);
                        }
                        else
                        {
                            propertyValue = data.GetBoolOptional(keyName);
                        }
                    }
                    else
                    {
                        propertyValue = data.GetBool(keyName);
                    }
                    break;

                case "movementtype":
                    //TODO: Cannot just keep adding types here, but let's see how common it is first
                    propertyValue = data.GetEnum <MovementType>(keyName);
                    break;

                case "cup":
                    propertyValue = DiceStrings.ParseDice(data.GetString(keyName));
                    break;

                case "spelltype":
                    propertyValue = data.GetEnum <Spells.SpellType>(keyName);
                    break;

                case "object[]":
                    var objectList = data.GetObjectList(keyName);
                    var newList    = new List <object>();
                    foreach (var o in objectList)
                    {
                        var instance = o.GetString(SERIALIZED_TYPE_KEY).Instantiate <object>(o);
                        newList.Add(instance);
                    }
                    propertyValue = newList.ToArray();
                    break;

                default:
                    ShortLog.DebugFormat("Attempting to deserialize: {0}", propType);
                    if (prop.PropertyType.IsEnum)
                    {
                        propertyValue = System.Enum.Parse(prop.PropertyType, data.GetString(keyName), true);
                    }
                    else
                    {
                        propertyValue = DeserializeObject(data, keyName, attribute.Optional, prop.PropertyType);
                    }
                    break;
                }
                prop.SetValue(result, propertyValue);
            }

            return(result);
        }