Skip to content

Instantly share code, notes, and snippets.

@TwoSquirrels
Created January 20, 2022 23:24
Show Gist options
  • Select an option

  • Save TwoSquirrels/07862ef908397d25889baf070a0a6431 to your computer and use it in GitHub Desktop.

Select an option

Save TwoSquirrels/07862ef908397d25889baf070a0a6431 to your computer and use it in GitHub Desktop.
/*
* 経験値計算
* @author TwoSquirrels
*/
// レベルアップに必要な経験値は (level*level+a)*b とする(つまり二次関数)
// ここでは a=2,B=10 としとく
const a = 2, b = 10;
const expToLevelUp = (level) => (level * level + a) + b;
// するとレベルまでに必要な総合経験値は (((level-1)*level*(level*2+1)/6)+level*a)*b となる(二乗の和の公式を利用<-これ数B範囲)
const totalExpToLevel = (level) = (((level - 1) * level * (level * 2 + 1) / 6) + level * a) * b;
// これがデータだとする(鯖ならデータベースとか小規模ならjsonファイルとかに保管しといて毎回取り出すべき)
const levelData = {
"hogehoge": { level: 0, exp: 5n },
"fugafuga": { level: 314, exp: 1592n },
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment