public HeroExpInfo CheckCurrentLevel() { int expToNextLevel = 0; HeroExpInfo expInfo = new HeroExpInfo(); expInfo.hero = this; expInfo.prevExp = previousExp; expInfo.prevLevel = level; do { expToNextLevel = GetStatValueByName("Exp"); if (currentExp >= expToNextLevel) { info.exp -= expToNextLevel; info.level++; } } while (currentExp >= GetStatValueByName("Exp")); expInfo.newExp = currentExp; expInfo.newLevel = level; previousExp = currentExp; return(expInfo); }
IEnumerator DisplayCoroutine(HeroExpInfo info) { container.SetActive(true); expDisplay.SetActive(true); levelUpDisplay.SetActive(false); portrait.sprite = info.hero.data.icon; currentExp.text = info.newExp.ToString(); expBar.fillAmount = info.newExp / (float)info.hero.nextLevelExp; currentLevelText.text = info.newLevel.ToString(); nextLevelText.text = (info.newLevel + 1).ToString(); prevLevelText.text = info.prevLevel.ToString(); newLevelText.text = info.newLevel.ToString(); DataManager.instance.audio["Game/ExpGain"].Play(); anim.SetTrigger("DisplayGain"); continueDisplay = false; yield return(new WaitUntil(() => continueDisplay)); expDisplay.SetActive(false); if (info.newLevel != info.prevLevel) { DataManager.instance.audio["Game/LevelUp"].Play(); levelUpDisplay.SetActive(true); anim.SetTrigger("DisplayLevelUp"); continueDisplay = false; yield return(new WaitUntil(() => continueDisplay)); levelUpDisplay.SetActive(false); } container.SetActive(false); battle.ContinueBattle(); }
IEnumerator BattleCoroutine(Hero _attacker, Hero _attacked) { DataManager.instance.gameState = GameState.Battle; onStartBattle.Invoke(_attacker, _attacked); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); // First the attacker attack onHeroAttack.Invoke(_attacker, _attacked); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); // If the attacked is alive, then attack if (_attacked.isAlive) { onHeroAttack.Invoke(_attacked, _attacker); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } // Check for speed superiority : // if one of them has 5 more in speed than the other // then attack a second time in the turn if (_attacker.speed >= _attacked.speed + 5) { onHeroAttack.Invoke(_attacker, _attacked); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } else if (_attacked.speed >= _attacker.speed + 5) { onHeroAttack.Invoke(_attacked, _attacker); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } battleCoroutine = null; onEndCutscene.Invoke(); // Wait the end of animation continueBattle = false; yield return(new WaitUntil(() => continueBattle)); if (_attacker.isAlive && _attacker.expChanged) { HeroExpInfo info = _attacker.CheckCurrentLevel(); onExpGain.Invoke(info); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } if (_attacked.isAlive && _attacked.expChanged) { HeroExpInfo info = _attacked.CheckCurrentLevel(); onExpGain.Invoke(info); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } DataManager.instance.gameState = GameState.Playing; onEndBattle.Invoke(); }
void DisplayExpGain(HeroExpInfo info) { StartCoroutine(DisplayCoroutine(info)); }