Skip to content

Instantly share code, notes, and snippets.

@aadnk
Created January 16, 2013 10:10
Show Gist options
  • Save aadnk/4546090 to your computer and use it in GitHub Desktop.
Save aadnk/4546090 to your computer and use it in GitHub Desktop.
Correct Experience Test
package com.comphenix.testing;
class Test {
private int expTotal;
private int expLevel;
private float exp;
public static void main(String[] args) {
Test test = new Test();
test.test();
}
public void test() {
int previous = 0;
int level = 0;
while (expLevel < 45) {
giveExp(1);
if (level != expLevel) {
System.out.println(expLevel + ": " + (expTotal - previous));
level = expLevel;
previous = expTotal;
}
}
}
public void giveExp(int i) {
int j = 2147483647 - this.expTotal;
if (i > j) {
i = j;
}
this.exp += (float) i / (float) getExpToLevel();
for (this.expTotal += i; this.exp >= 1.0F; this.exp /= (float) getExpToLevel()) {
this.exp = ((this.exp - 1.0F) * (float) getExpToLevel());
levelUp(1);
}
}
public void levelUp(int i) {
this.expLevel += i;
if (this.expLevel < 0) {
this.expLevel = 0;
this.exp = 0.0F;
this.expTotal = 0;
}
}
public int getExpToLevel() {
return this.expLevel >= 30 ? 62 + (this.expLevel - 30) * 7 : (this.expLevel >= 15 ? 17 + (this.expLevel - 15) * 3 : 17);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment