Пример #1
0
        public override void Deserialize(JSONObject obj)
        {
            mName       = obj.GetString(NAME);
            mGender     = (CharacterGender)(int)obj.GetNumber(GENDER);
            mExperience = (int)obj.GetNumber(EXPERIENCE);
            mAvatar     = obj.GetString(AVATAR);
            mAlignment  = (DnDAlignment)(int)obj.GetNumber(ALIGNMENT);
            mRace       = (DnDRace)(int)obj.GetNumber(RACE);
            mAge        = (int)obj.GetNumber(AGE);
            if (obj.ContainsKey(DEITY))
            {
                mDeity = new DnDDeity();
                mDeity.Deserialize(obj.GetObject(DEITY));
            }
            mSize = (DnDCharacterSize)(int)obj.GetNumber(SIZE);
            // souls:
            JSONObject jSouls  = obj.GetObject(CLASS_SOULS);
            var        classes = Enum.GetValues(typeof(DnDCharClass)).Cast <DnDCharClass>();

            foreach (DnDCharClass charClass in classes)
            {
                if (jSouls.ContainsKey(charClass.ToString()))
                {
                    if (!string.IsNullOrEmpty(jSouls.GetObject(charClass.ToString()).ToString()))
                    {
                        DnDClassSoul newSoul = null;
                        switch (charClass)
                        {
                        case DnDCharClass.Wizard:
                            newSoul = new DnDWizard(this);
                            break;

                        default:
                            break;
                        }
                        if (newSoul != null)
                        {
                            newSoul.Deserialize(jSouls.GetObject(charClass.ToString()));
                            mClasses.Add(newSoul);
                        }
                    }
                }
            }
            // abilities:
            JSONArray tempArray = obj.GetArray(ABILITIES);

            foreach (var val in tempArray)
            {
                mAbilities[(DnDAbilities)((int)val.Array[0].Number)] = (int)val.Array[1].Number;
            }
        }
Пример #2
0
		public override void Deserialize(JSONObject obj)
		{
			mName = obj.GetString(NAME);
			mGender = (CharacterGender)(int)obj.GetNumber(GENDER);
			mExperience = (int)obj.GetNumber(EXPERIENCE);
			mAvatar = obj.GetString(AVATAR);
			mAlignment = (DnDAlignment)(int)obj.GetNumber(ALIGNMENT);
			mRace = (DnDRace)(int)obj.GetNumber(RACE);
			mAge = (int)obj.GetNumber(AGE);
			if (obj.ContainsKey(DEITY))
			{
				mDeity = new DnDDeity();
				mDeity.Deserialize(obj.GetObject(DEITY));
			}
			mSize = (DnDCharacterSize)(int)obj.GetNumber(SIZE);
			// souls:
			JSONObject jSouls = obj.GetObject(CLASS_SOULS);
			var classes = Enum.GetValues(typeof(DnDCharClass)).Cast<DnDCharClass>();
			foreach (DnDCharClass charClass in classes)
			{
				if (jSouls.ContainsKey(charClass.ToString()))
				{
					if (!string.IsNullOrEmpty(jSouls.GetObject(charClass.ToString()).ToString()))
					{
						DnDClassSoul newSoul = null;
						switch (charClass)
						{
							case DnDCharClass.Wizard:
								newSoul = new DnDWizard(this);
								break;
							default:
								break;
						}
						if (newSoul != null)
						{
							newSoul.Deserialize(jSouls.GetObject(charClass.ToString()));
							mClasses.Add(newSoul);
						}
					}
				}
			}
			// abilities:
			JSONArray tempArray = obj.GetArray(ABILITIES);
			foreach (var val in tempArray)
			{
				mAbilities[(DnDAbilities)((int)val.Array[0].Number)] = (int)val.Array[1].Number;
			}
		}