-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarket.js
156 lines (145 loc) · 5.21 KB
/
market.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
sellRice.addEventListener("click", function sell() {
let total = playerdata.rice + playerdata.brownRice + playerdata.goldRice
let sold = playerdata.rice + playerdata.brownRice * 9 + playerdata.goldRice * 100
playerdata.money += sold
playerdata.stats.money += sold
playerdata.stats.sold += total
playerdata.rice -= playerdata.rice
playerdata.brownRice -= playerdata.brownRice
playerdata.goldRice -= playerdata.goldRice
gainXP(2, 3)
dialog("All rice sold successfully for " + sold + "元!")
})
shop[0].addEventListener("click", function buyPlain() {
if (playerdata.money > 0) {
let howMuch = prompt("How many RICE SEEDS do you wish to buy? 1元 = 2 seeds.")
if (Number.isInteger(parseFloat(howMuch))) {
if (parseInt(howMuch) / 2 > playerdata.money || parseInt(howMuch) < 1) {
alert("Error! Please try again.")
} else {
let spent = round2(parseInt(howMuch) / 2)
playerdata.money -= spent
playerdata.stats.spent += spent
if (playerdata.unlocked.select == true) {
let seel = 0
for (let i = 0; i < parseInt(howMuch); i++) {
if (chance(0.1)) {
seel++
} else {
continue
}
}
let amt = parseInt(howMuch) - seel
playerdata.seeds += amt
playerdata.stats.seeds += amt
playerdata.selectSeeds += seel
playerdata.stats.selectSeeds += seel
alert("Bought " + amt + " PLAIN rice seeds and " + seel + " SELECT seeds for " + spent + "元")
} else {
playerdata.seeds += parseInt(howMuch)
playerdata.stats.seeds += parseInt(howMuch)
alert("Bought " + howMuch + " PLAIN rice seeds for " + spent + "元!")
}
gainXP(1, 2)
}
} else {
alert("Error! Please try again.")
}
} else {
alert("No money left! Go farm some rice!")
}
})
shop[2].addEventListener("click", function tradee() {
if (playerdata.unlocked.brown[1] == true) {
if (playerdata.selectSeeds >= 5) {let howMuch = prompt("How many BROWN SEEDS would you like to trade for? 5 select = 1 brown")
if (Number.isInteger(parseFloat(howMuch))) {
if (parseInt(howMuch) * 5 > playerdata.selectSeeds || parseInt(howMuch) < 1) {
alert("Error! Please try again.")
} else {
let spent = round2(parseInt(howMuch) * 5)
playerdata.selectSeeds -= spent
let amt = parseInt(howMuch)
playerdata.brownSeeds += amt
playerdata.stats.brownSeeds += amt
alert("Bartered " + spent + " Select seeds for " + amt + " Brown seeds!")
gainXP(1, 2)
}
} else {
alert("Error! Please try again.")
}} else {
alert("Not enough select seeds! Go buy some!")
}
} else {
alert("Not unlocked yet!")
}
})
shop[8].addEventListener("click", function buyland() {
if (playerdata.xpLevel >= 5) {
if (playerdata.money >= 1000) {
if (playerdata.tiles < 9) {
let yesland = confirm("Are you sure you want to buy a plot of land for 1000元? Press ok to proceed...")
if (yesland) {
alert("A plot of land purchased for 1000元.")
playerdata.tiles += 1
playerdata.stats.tiles += 1
playerdata.money -= 1000
playerdata.stats.spent += 1000
gainXP(5, 7)
updateTiles()
} else {
alert("Land purchase cancelled.")
}
} else {
alert("Already purchased max farmlands!")
}
} else {
alert("Not enough money! Need 1000元.")
}
} else {
alert("Not unlocked yet!")
}
})
shop[6].addEventListener("click", function buyElBoost() {
if (playerdata.money >= 1.5) {
let howMuch = prompt("Please write how much fertilizer you would like to buy (1 fertilizer for 1.5元):")
if (Number.isInteger(parseFloat(howMuch))) {
if (parseInt(howMuch) < 1 || parseInt(howMuch) * 1.5 > playerdata.money) {
alert("Error! Please try again.")
} else {
let spent = parseInt(howMuch) * 1.5
playerdata.money = playerdata.money - spent
playerdata.stats.spent += spent
playerdata.fertile += parseInt(howMuch)
playerdata.stats.fertile += parseInt(howMuch)
gainXP(2, 3)
alert("Purchased " + howMuch + " fertilizer for " + spent + "元!")
}
} else {
alert("Error! Please try again.")
}
} else {
alert("Not enough money! You need at least 1.5元.")
}
})
shop[4].addEventListener("click", function buyWater() {
if (playerdata.money > 0) {
let howMuch = prompt("How many liters of WATER do you wish to buy? 1元 = 2 liters of water.")
if (Number.isInteger(parseFloat(howMuch))) {
if (parseInt(howMuch) / 2 > playerdata.money || parseInt(howMuch) < 1) {
alert("Error! Please try again.")
} else {
let spent = round2(parseInt(howMuch) / 2)
playerdata.money -= spent
playerdata.stats.spent += spent
playerdata.water += parseInt(howMuch)
playerdata.stats.water += parseInt(howMuch)
gainXP(1, 2)
alert("Bought " + howMuch + " liters of water for " + spent + "元!")
}
} else {
alert("Error! Please try again.")
}
} else {
alert("No money left! Go farm some rice!")
}
})