aboutsummaryrefslogtreecommitdiffstats
path: root/js/perso.js
blob: 7977a9db273474f408a5be791ea6241016cbb9fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function displayPerso(hp,maxHP,xp,lv,power,bonusPower){
	document.getElementById("hp").innerHTML = hp;
	document.getElementById("maxHP").innerHTML = maxHP;
	document.getElementById("lv").innerHTML = lv;
	document.getElementById("xp").innerHTML = xp;
	document.getElementById("power").innerHTML = power;
	document.getElementById("bonusPower").innerHTML = bonusPower;
}

function updatePerso(perso) {
	data.hp = perso.hp;
	data.maxHP = perso.maxHP;
	data.xp = perso.xp;
	data.level = perso.lv;
	data.power = perso.power;
	data.bonusPower = perso.bonusPower;
	displayPerso(perso.hp, perso.maxHP, perso.xp, perso.lv, perso.power, perso.bonusPower);
}

function levelUp(xp){
	data.xp += parseInt(xp);
	while(data.xp>=data.level){
		data.xp-=data.level;
		data.level++;
		data.power++;
		data.maxHP+=2;
	}
	//need to send the xp to the server
	sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&maxHP="+data.maxHP+"&xp="+data.xp+"&lv="+data.level
				+"&power="+data.power+"&bonusPower="+bonusPower, function(){
		displayPerso(data.hp,data.maxHP,data.maxHP,data.xp,data.level,data.power,data.bonusPower);
	});
}