public void DoXPGainAction(XPData curXPData, int levelOfAction) { if (OnGainXP != null) { int newTotalXP = curXPData.TotalXP + GetXPGain(levelOfAction); OnGainXP(new XPData(newTotalXP, GetCurLevel(newTotalXP, curXPData.CurXPLevel))); } }
private void OnUpdateStats() { if (m_statsPanelContentLeft != null) { // clear all stats for (int i = 0; i < m_statsPanelContentLeft.transform.childCount; ++i) { Destroy(m_statsPanelContentLeft.transform.GetChild(i).gameObject); Destroy(m_statsPanelContentRight.transform.GetChild(i).gameObject); } List <BrainCloudStats.Stat> playerStats = BrainCloudStats.Instance.GetStats(); XPData xpData = GPlayerMgr.Instance.PlayerData.PlayerXPData; int currentLevel = xpData.CurrentLevel; if (GPlayerMgr.Instance.PlayerData.PlayerRank != currentLevel) { // Update the PlayerSummaryData only if the Player's rank has changed GPlayerMgr.Instance.PlayerData.PlayerRank = currentLevel; GPlayerMgr.Instance.UpdatePlayerSummaryData(); PlayerRankIcon.UpdateIcon(GPlayerMgr.Instance.PlayerData.PlayerRank); } string rank = BrainCloudStats.Instance.m_playerLevelTitles[0] + "(" + GPlayerMgr.Instance.PlayerData.PlayerXPData.CurrentLevel + ")"; if (currentLevel > 0 && currentLevel < BrainCloudStats.Instance.m_playerLevelTitles.Length) { rank = BrainCloudStats.Instance.m_playerLevelTitles[currentLevel - 1] + " (" + currentLevel + ")"; } // over max else if (currentLevel > 0) { rank = BrainCloudStats.Instance.m_playerLevelTitles[BrainCloudStats.Instance.m_playerLevelTitles.Length - 1] + " (" + currentLevel + ")"; } if (m_statsImage == null) { m_statsImage = m_statsPanelContentLeft.transform.parent.parent.parent.FindDeepChild("XpBar").GetComponent <Image>(); } m_statsImage.fillAmount = Mathf.InverseLerp(xpData.PrevThreshold, xpData.NextThreshold, xpData.ExperiencePoints); Text tempText = null; for (int i = 2; i < playerStats.Count; ++i) { tempText = Instantiate(m_statText, m_statsPanelContentLeft.transform).GetComponent <Text>(); tempText.alignment = TextAnchor.MiddleLeft; tempText.text = " " + playerStats[i].Name; tempText = Instantiate(m_statValue, m_statsPanelContentRight.transform).GetComponent <Text>(); tempText.text = HudHelper.ToGUIString(playerStats[i].Value); } GameObject.Find("RankText").GetComponent <Text>().text = rank; } }
void OnXPChanged(XPData newXP) { if (xpData.TotalXP > 0) { int xpGain = newXP.TotalXP - xpData.TotalXP; MessageLog_Manager.NewMessage("You gain " + xpGain + " XP!", Color.yellow); if (newXP.CurXPLevel > xpData.CurXPLevel) { MessageLog_Manager.NewMessage("You are now level " + newXP.CurXPLevel, Color.yellow); // do level gain effect (gain max hp) fighter.IncreaseMaxHealth(); if (xpData.CurXPLevel == 3) { // gain teleport abilityComponent.AddAbility(AbilityID.Teleport, true, "40% HP"); } } } xpData = new XPData(newXP.TotalXP, newXP.CurXPLevel); UI_Manager.instance.HandlePlayerXPLevel(xpData.TotalXP, xpData.CurXPLevel); }