public static void RewardExperience(int prize, Party activeParty) { List <GameObject> partyMembers = new List <GameObject>(activeParty.Count); // Obtain active party members for (int i = 0; i < activeParty.Count; i++) { GameObject u = activeParty[i]; if (u != null) { partyMembers.Add(u); } } int min = Consts.GAME_MIN_LEVEL; int max = Consts.GAME_MAX_LEVEL; // Determine the range of levels in party for (int i = partyMembers.Count - 1; i >= 0; i--) { Parameters p = partyMembers[i].GetComponent <Parameters>(); min = Mathf.Min(p.LVL, min); max = Mathf.Max(p.LVL, max); } // Weight awarded exp based on individual level float[] weights = new float[activeParty.Count]; float summed = 0; for (int i = partyMembers.Count; i >= 0; i--) { Parameters p = partyMembers[i].GetComponent <Parameters>(); float percent = (float)(p.LVL - min) / (float)(max - min); weights[i] = Mathf.Lerp(minLevelBonus, maxLevelBonus, percent); summed += weights[i]; } // Distribute weighted experience for (int i = partyMembers.Count; i >= 0; i--) { Parameters p = partyMembers[i].GetComponent <Parameters>(); if (p.LVL != Consts.GAME_MAX_LEVEL) { p.EXP += Mathf.FloorToInt((weights[i] / summed) * prize); // Check if distributed experience causes unit to level up int totalAccumulatedExp = p.EXP + Experience.ExperienceForLevel(p.LVL); if (totalAccumulatedExp >= Experience.ExperienceForLevel(p.EXP + 1)) { p.LevelUp(); } } } }
// Should be semi-random, but for now stats grow linearly public void LevelUp() { EXP = EXP + Experience.ExperienceForLevel(LVL) - Experience.ExperienceForLevel(LVL + 1); LVL += 1; for (int i = 0; i < Job.statOrder.Length; ++i) { StatTypes parameter = Job.statOrder[i]; int currentStat = GetBaseStat(parameter); int growthStat = currentJob.GetGrowthStat(parameter); int newStat = currentStat + growthStat; SetStat(parameter, currentStat + growthStat); // UpdateRealStat(); } CHP = MHP; CMP = MMP; }