-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItems.js
83 lines (67 loc) · 1.99 KB
/
Items.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var Shop = keyvalue.parseKVFile('Shop.kv');
var matrix = new Array();
function check(pID, item)
{
if (matrix[pID] === undefined)
matrix[pID] = new Array();
if (matrix[pID][item] === undefined)
matrix[pID][item] = 0;
}
function buy(client, item)
{
var pID = client.netprops.m_iPlayerID;
var dire = (client.netprops.m_iTeamNum == dota.TEAM_DIRE);
var playerManager = game.findEntityByClassname(-1, "dota_player_manager");
var data = dire ? game.findEntityByClassname(-1, "dota_data_dire") : game.findEntityByClassname(-1, "dota_data_radiant");
if (!playerManager || !data)
{
client.printToChat("Invalid playerManager data");
return false;
}
check(pID, item);
if (matrix[pID][item] >= Shop.items[item].max_level)
{
client.printToChat("You are already at the max level!");
return false;
}
var cost = getCost(pID, item);
// Get gold...
var gold = [ data.netprops.m_iReliableGold[pID],
data.netprops.m_iUnreliableGold[pID] ];
// Check player has enough $$$
if ((gold[0] + gold[1]) < cost)
{
client.printToChat("You don't have enough money! Cost: "+cost);
return false;
}
// Buy item and deduce gold
matrix[pID][item] += 1;
// XXX dota.givePlayerGold(pID, -cost,
// Unreliable gold first...
if (gold[1] >= cost)
gold[1] -= cost;
else
{
cost -= gold[1];
gold[0] -= cost;
gold[1] = 0;
}
data.netprops.m_iReliableGold[pID] = gold[0];
data.netprops.m_iUnreliableGold[pID] = gold[1];
client.printToChat(Shop.messages.on_buy.replace("%1", Shop.items[item].name).replace("%2",cost) + " level="+matrix[pID][item]);
return true;
}
function getLevel(pID, item)
{
check(pID, item);
return matrix[pID][item];
}
function getCost(pID, item)
{
check(pID, item);
// TODO maybe exponential increase
return parseInt(Shop.items[item].price_base + (matrix[pID][item] * Shop.items[item].price_incr));
}
exports.buy = buy;
exports.getCost = getCost;
exports.getLevel = getLevel;