示例#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;
            }
        }
		protected override void InitRankSelection()
		{
			SetTopText("Select the spell Rank");
			DnDCharacter character = (DnDCharacter)AppStorage.Instance.CurrentCharacter;
			if (mSelectedClass > character.Classes.Count)
				return;
			mSoul = character.Classes[mSelectedClass];

			GameObject buttonPref = Resources.Load(cSimplePrefab) as GameObject;
			int buttonHeight = (int)buttonPref.GetComponent<LayoutElement>().minHeight;
			int spacing = (int)DragArea.transform.FindChild("ScrollArea").GetComponent<VerticalLayoutGroup>().spacing;
			buttonHeight += spacing;
			for (int i = 0; i < mSoul.KnownSpells.Count; ++i)
			{
				GameObject button = GameObject.Instantiate(buttonPref) as GameObject;
				button.transform.SetParent(DragArea.transform.FindChild("ScrollArea"));
				ViewUtility.ChangeSimpleButtonText("rank  " + i, button);
				button.GetComponent<IntButtonHandler>().NotificationInt = i;
				button.GetComponent<IntButtonHandler>().NotificationCatcher = this;
				mTotalHeight += buttonHeight;
				ViewUtility.EnableSimpleButton(button, mSoul.KnownSpells[i].Count > 0);
				mButtonList.Add(button);
			}
			if (mViewHeight < mTotalHeight)
			{
				mTotalHeight -= spacing;
			}
			UpdateNow = true;
		}
		protected override void InitSpellSelection()
		{
			DnDCharacter character = (DnDCharacter)AppStorage.Instance.CurrentCharacter;
			if (character.Classes.Count < mSelectedClass)
				return;
			mSoul = character.Classes[mSelectedClass];

			if (mSoul.NeedsToPrepareSpells)
			{
				SetTopText("Cast spells", "");
				InitPreparedSpells();
			}
			else
			{
				SetTopText("Cast spells", GetExtraTopText());
				InitKnownSpells();
			}
			int spacing = (int)DragArea.transform.FindChild("ScrollArea").GetComponent<VerticalLayoutGroup>().spacing;
			if (mViewHeight < mTotalHeight)
			{
				mTotalHeight -= spacing;
			}
		}