aboutsummaryrefslogtreecommitdiffstats
path: root/js/shop.js
blob: 22ca85fe2418bd1564244ae9f4f46a75750e3040 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function displayShop(ret) {
	var tmphtml = "<h4> Select an item to buy it:</h4>";
	tmphtml += "<ul class=\"list-inline\">";
	for(var i=0; i < ret.items.length; i++) {
		tmphtml += "<li>";
		tmphtml += "<button type=\"submit\" class=\"btn btn-primary\" onclick=\"buyItem('" + ret.items[i].name + "')\"><span class=\"item-icon\">" + ret.items[i].icon + "</span><br />" + ret.items[i].name + "</button>";
		tmphtml += "</li>";
	}
	tmphtml += "</ul>"
	document.getElementById("tab2").innerHTML = tmphtml;
}

function displayInventory(items) {
	for(var i=0; i < items.length; i++) {
		addItem(items[i]);
	}
}

function buildShop() {
	sendRequest("craftmine.php", "op=buildShop", function(ret) {
		displayShop(ret);
		debitAccount(ret.cost);
	});
}

function addItem(ret) {
	var itemhtml = "<li>";
	itemhtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"useItem('" + ret.name + "')\"><span class=\"item-icon\">" + ret.icon + "</span><br />" + ret.name + "</button>";
	itemhtml += "</li>";

	var invcontent = document.getElementById("tab3");

	if(invcontent.children.length <= 1)
	{
		var tmphtml = "<h4>Your bag contains the following items:</h4>";
		tmphtml += "<ul class=\"list-inline\">";
		tmphtml += itemhtml;
		tmphtml += "</ul>"
		invcontent.innerHTML = tmphtml;
	} else
		invcontent.getElementsByTagName('ul')[0].innerHTML += itemhtml;

	showInfo(ret.desc);
}

function buyItem(name) {
	sendRequest("craftmine.php", "op=buyItem&item="+name, function(ret) {
		addItem(ret);
		debitAccount(ret.cost);
	});
}

function useItem(name) {
	sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) {
	});
}