我对这篇文章有很多不喜欢的地方,我不知道为什么,但是为了让你们帮我解决这个问题,我会把这个剧本作为礼物给你.此脚本将经验转换为级别,并从给定指数表达式的级别转换为经验点.这些常数确保100级将等于1000万经验.在Runescape中,它们的等级99等于13,032,xxx是一个奇怪的数字.
using System.IO;
using System;
class Program
{
const float salt = 2.82842712474619f;
const float factor = 0.64977928f;
const int lvl_100_XP = 10000000;
static void Main()
{
int xp = 9717096;// lvl 99
int lvl = ExperienceToLevel(xp);
Console.WriteLine("LVL: " + lvl.ToString()+ " XP: " + LevelToExperience(lvl).ToString());
}
static public int ExperienceToLevel(int xp){
int lvl = 0;
if (xp == lvl_100_XP){//9999987 is lvl 100 due to roundoff issues so it is fixed to 10mill
lvl = 100;
}
else{
lvl = (int)((1f / salt) * (float)Math.Pow((float)xp, (1f - factor)));
if (lvl == 0){
//lvl = 1;
}
}
if (lvl == 100 && xp < lvl_100_XP){
lvl = 99;
}
return lvl;
}
static public int LevelToExperience(int lvl){
int xp = 0;
if (lvl == 100){//9999987 is lvl 100 due to roundoff issues so it is fixed to 10mill
xp = lvl_100_XP;
}
else{
xp = (int)Math.Exp((float)Math.Log(salt * (float)lvl) / (1f - factor))+1;
if (xp <= 1){
xp= 0;
}
if (lvl == 100){
xp = lvl_100_XP;
}
}
return xp;
}
}
Run Code Online (Sandbox Code Playgroud)
让我们解决吧.
让我们x成为经验,a并且c是常数.L是水平.我们将取幂表示为^; 请注意,C#没有这样的运算符.^在C#中是异或.
你有
b = x / a
d = x ^ c
L = b / d
Run Code Online (Sandbox Code Playgroud)
所以那是
L = x / (a * x ^ c)
Run Code Online (Sandbox Code Playgroud)
是的
L = (1 / a) * (x / x ^ c)
Run Code Online (Sandbox Code Playgroud)
是的
L = (1 / a) * x ^ (1 - c)
Run Code Online (Sandbox Code Playgroud)
你希望解决x.因此,将两边乘以'a':
a * L = x ^ (1 - c)
Run Code Online (Sandbox Code Playgroud)
拿两边的ln.(或者你最喜欢的任何对数.)
ln (a * L) = (1 - c) ln (x)
Run Code Online (Sandbox Code Playgroud)
将双方除以1 - c
ln (a * L) / (1 - c) = ln x
Run Code Online (Sandbox Code Playgroud)
并消除ln; 记住exp是ln的倒数.如果你使用了其他一些对数,那么使用其他一些指数.
exp (ln (a * L) / (1 - c)) = x
Run Code Online (Sandbox Code Playgroud)
我们已经完成了.