public static void RestrictCharLevel(Character character, int level, bool capOnly) { //set level if (capOnly) { character.Level = Math.Min(level, character.Level); } else { character.Level = level; } if (character.Level == level) { character.EXP = 0; } //clear boosts character.MaxHPBonus = 0; character.AtkBonus = 0; character.DefBonus = 0; character.MAtkBonus = 0; character.MDefBonus = 0; character.SpeedBonus = 0; if (!character.Dead) { character.HP = character.MaxHP; } //reroll skills BaseMonsterForm form = DataManager.Instance.GetMonster(character.BaseForm.Species).Forms[character.BaseForm.Form]; while (character.BaseSkills[0].SkillNum > -1) { character.DeleteSkill(0); } List <int> final_skills = form.RollLatestSkills(character.Level, new List <int>()); foreach (int skill in final_skills) { character.LearnSkill(skill, true); } character.Relearnables = new List <bool>(); }
private void restoreCharLevel(Character character, Character charFrom, int level) { //compute the amount of experience removed from the original character int removedEXP = 0; MonsterData monsterData = DataManager.Instance.GetMonster(charFrom.BaseForm.Species); BaseMonsterForm monsterForm = monsterData.Forms[charFrom.BaseForm.Form]; int growth = monsterData.EXPTable; GrowthData growthData = DataManager.Instance.GetGrowth(growth); if (level <= charFrom.Level) { removedEXP += charFrom.EXP; int origLevel = charFrom.Level; while (origLevel > level) { removedEXP += growthData.GetExpToNext(origLevel - 1); origLevel--; } } //add the EXP to the character if (character.Level < DataManager.Instance.MaxLevel) { character.EXP += removedEXP; while (character.EXP >= growthData.GetExpToNext(character.Level)) { if (character.Level >= DataManager.Instance.MaxLevel) { character.EXP = 0; break; } character.EXP -= growthData.GetExpToNext(character.Level); character.Level++; } } //add stat boosts character.MaxHPBonus = Math.Min(character.MaxHPBonus + charFrom.MaxHPBonus, monsterForm.GetMaxStatBonus(Stat.HP)); character.AtkBonus = Math.Min(character.AtkBonus + charFrom.AtkBonus, monsterForm.GetMaxStatBonus(Stat.Attack)); character.DefBonus = Math.Min(character.DefBonus + charFrom.DefBonus, monsterForm.GetMaxStatBonus(Stat.Defense)); character.MAtkBonus = Math.Min(character.MAtkBonus + charFrom.MAtkBonus, monsterForm.GetMaxStatBonus(Stat.MAtk)); character.MDefBonus = Math.Min(character.MDefBonus + charFrom.MDefBonus, monsterForm.GetMaxStatBonus(Stat.MDef)); character.SpeedBonus = Math.Min(character.SpeedBonus + charFrom.SpeedBonus, monsterForm.GetMaxStatBonus(Stat.Speed)); character.HP = character.MaxHP; //restore skills while (character.BaseSkills[0].SkillNum > -1) { character.DeleteSkill(0); } for (int ii = 0; ii < charFrom.BaseSkills.Count; ii++) { if (charFrom.BaseSkills[ii].SkillNum > -1) { bool enabled = false; foreach (BackReference <Skill> skill in charFrom.Skills) { if (skill.BackRef == ii) { enabled = skill.Element.Enabled; break; } } character.LearnSkill(charFrom.BaseSkills[ii].SkillNum, enabled); } } //restoreCharLevel the backref character.BackRef = new TempCharBackRef(false, -1); }