示例#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;
            }
        }
		public override void Update()
		{
			if (mWizard == null)
			{
				mWizard = (DnDWizard)((DnDCharacter)Storage.Character).Classes.Find(x => x.CharacterClass == DnDCharClass.Wizard);
			}
			if (!mInitialized)
			{
				if (mWizard != null)
				{
					mNumberOfButtons = mWizard.HighestCastableRank; // Rank 0 is not needed (otherwhise would be +1)
					InitButtons();
				}
			}
			base.Update();
		}
	public override void Next()
	{
		int level = 1;
		if (!string.IsNullOrEmpty(LevelInput.text))
		{
			level = int.Parse(LevelInput.text);
		}
		DnDCharClass chosen = (DnDCharClass)((int)ClassSlider.value);
		DnDClassSoul soul = null;
		int nextScreen = -1;
		switch (chosen)
		{
			case DnDCharClass.Wizard:
				soul = new DnDWizard((DnDCharacter)Storage.Character, level);
				nextScreen = cWizardScreen;
				break;
			default:
				break;
		}
		if (soul != null)
		{
			((DnDCharacter)Storage.Character).Classes.Add(soul);
		}
		if (nextScreen >= 0)
		{
			Storage.Screens[nextScreen].SetActive(true);
			this.gameObject.SetActive(false);
		}
		else
		{
			SwitchScene(ScreenBase.SCENE_SPELLMASTERY);
		}
	}
		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;
			}
		}
	// Update is called once per frame
	public override void Update()
	{
		base.Update();
		if (mSoul == null)
		{
			mSoul = ((DnDCharacter)(Storage.Character)).Classes.Find(x => x.CharacterClass == DnDCharClass.Wizard) as DnDWizard;
		}
		if (!mSetText)
		{
			mSetText = true;
			int numberOfUnknownSpells = 0;
			for (int i = 1; i <= mSoul.HighestCastableRank; ++i)
			{
				numberOfUnknownSpells += mSoul.NumberofUnknownSpells(i);
			}
			//disabling button if no more spells can be added:
			ViewUtility.EnableSimpleButton(transform.FindChild("Menu").FindChild("AddSpellsButton").gameObject, numberOfUnknownSpells != 0);
			// setting the top text:
			if (TopText != null)
			{
				if (mSoul.HighestCastableRank < 0)
				{
					TopText.text = string.Format(cSpellBookExplanation, string.Format(cLowAbility, mSoul.SpellModifier.ToString()));
				}
				else if (mSoul.KnownSpells.Count == 0)
				{
					AddZeroRankSpells();
					TopText.text = string.Format(cSpellBookExplanation, cAddedZeroRankText);
				}
				else if (numberOfUnknownSpells == 0)
				{
					TopText.text = cCantAddMore;
				}
				else
				{
					TopText.text = string.Format(cSpellBookExplanation, cAddMoreText);
				}
			}
			// setting the current known spell texts:
			if (FirstRanksText != null && LastRanksText != null)
			{
				int rank = -1;
				string textFirst = "";
				string textLast = "";
				foreach (var list in mSoul.KnownSpells)
				{
					rank++;
					if (rank > cMaxRankFirst)
					{
						textLast += string.Format(cShortRankText, rank, list.Count);
						if (rank < cMaxRankLast)
						{
							textLast += "\n";
						}
					}
					else
					{
						textFirst += string.Format(cShortRankText, rank, list.Count);
						if (rank < cMaxRankFirst)
						{
							textFirst += "\n";
						}
					}
				}
				FirstRanksText.text = textFirst;
				LastRanksText.text = textLast;
			}
		}
	}
	private void Reset()
	{
		mSetText = false;
		if (mSoul != null)
		{
			mSoul.KnownSpells.Clear();
			mSoul = null;
		}
	}