-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtown.php
514 lines (389 loc) · 26 KB
/
town.php
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<?php // town.php :: All town functions.
// Dragon Scourge
//
// Program authors: Jamin Blount
// Copyright (C) 2007 by renderse7en
// Script Version 1.0 Beta 5 Build 20
// You may not distribute this program in any manner, modified or
// otherwise, without the express, written consent from
// renderse7en.
//
// You may make modifications, but only for your own use and
// within the confines of the Dragon Scourge License Agreement
// (see our website for that).
// Before allowing anything else, we make sure the person is actually in town.
global $townrow;
if ($townrow == false) { die(header("Location: index.php")); }
function dotown() { // Default town screen.
global $userrow;
$newpm = doquery("SELECT * FROM <<messages>> WHERE recipientid='".$userrow["id"]."' AND status='0'");
if (mysql_num_rows($newpm) > 0) {
$row["unread"] = "<b>(".mysql_num_rows($newpm)." new)</b>";
} else {
$row["unread"] = "";
}
display("In Town", parsetemplate(gettemplate("town"), $row));
}
function inn() { // Resting at the inn restores hp/mp/tp.
global $userrow, $townrow;
// Errors.
if ($userrow["gold"] < $townrow["innprice"]) { err("You do not have enough gold to stay at the inn. Please <a href=\"index.php\">go back</a> and try again."); }
if ($userrow["currenthp"] == $userrow["maxhp"] && $userrow["currentmp"] == $userrow["maxmp"] && $userrow["currenttp"] == $userrow["maxtp"]) { err("Your HP, MP and TP are already at their maximum levels. You do not need to stay at the Inn tonight.<br /><br /><a href=\"index.php\">Click here</a> to return to the main town screen."); }
if (isset($_POST["submit"])) {
// Fill 'er up, my man!
$userrow["currenthp"] = $userrow["maxhp"];
$userrow["currentmp"] = $userrow["maxmp"];
$userrow["currenttp"] = $userrow["maxtp"];
$userrow["gold"] -= $townrow["innprice"];
$query = doquery("UPDATE <<users>> SET currenthp='".$userrow["maxhp"]."', currentmp='".$userrow["maxmp"]."', currenttp='".$userrow["maxtp"]."', gold='".$userrow["gold"]."' WHERE id='".$userrow["id"]."' LIMIT 1");
display("Rest at the Inn", gettemplate("town_inn2"));
} elseif (isset($_POST["abortmission"])) { die(header("Location: index.php")); }
display("Rest at the Inn", parsetemplate(gettemplate("town_inn1"), $townrow));
}
function map() { // Buy maps to towns for the Travel To menu.
global $userrow;
if (isset($_POST["three"])) {
$townquery = doquery("SELECT * FROM <<towns>> WHERE id='".$_POST["id"]."' LIMIT 1");
$townrow = dorow($townquery);
if ($userrow["gold"] < $townrow["mapprice"]) { err("You do not have enough gold to buy this map. Please <a href=\"index.php\">go back</a> and try again."); }
if ($townrow != false) {
$userrow["townslist"] .= "," . $townrow["id"];
$userrow["gold"] -= $townrow["mapprice"];
$query = doquery("UPDATE <<users>> SET townslist='".$userrow["townslist"]."', gold='".$userrow["gold"]."' WHERE id='".$userrow["id"]."' LIMIT 1");
display("Buy Maps", gettemplate("town_map3"));
} else {
err("Invalid action. Please <a href=\"index.php\">go back</a> and try again.");
}
} elseif (isset($_POST["two"])) {
$townquery = doquery("SELECT * FROM <<towns>> WHERE name='".$_POST["two"]."' LIMIT 1");
$townrow = dorow($townquery);
if ($userrow["gold"] < $townrow["mapprice"]) { err("You do not have enough gold to buy this map. Please <a href=\"index.php\">go back</a> and try again."); }
if ($townrow != false) {
display("Buy Maps", parsetemplate(gettemplate("town_map2"), $townrow));
} else {
err("Invalid action. Please <a href=\"index.php\">go back</a> and try again.");
}
} else {
$townquery = doquery("SELECT * FROM <<towns>> WHERE world='".$userrow["world"]."' ORDER BY id");
$townrow = dorow($townquery);
$townslist = explode(",",$userrow["townslist"]);
$row["maptable"] = "<form action=\"index.php?do=maps\" method=\"post\"><table width=\95%\">\n";
foreach($townrow as $a=>$b) {
if (in_array($b["id"], $townslist)) {
if ($b["latitude"] < 0) { $latitude = ($b["latitude"] * -1) . "S"; } else { $latitude = $b["latitude"] . "N"; }
if ($b["longitude"] < 0) { $longitude = ($b["longitude"] * -1) . "W"; } else { $longitude = $b["longitude"] . "E"; }
$row["maptable"] .= "<tr><td width=\"20%\"><input type=\"submit\" name=\"two\" value=\"".$b["name"]."\" style=\"width: 100px;\" disabled=\"disabled\" /></td><td width=\"30%\" style=\"vertical-align: middle;\"><span class=\"grey\">Already Purchased</span></td><td width=\"30%\" style=\"vertical-align: middle;\"><span class=\"grey\">Location: <b>$latitude, $longitude</b></span></td><td width=\"20%\" style=\"vertical-align: middle;\"><span class=\"grey\">TP: <b>".$b["travelpoints"]."</b></span></td></tr>\n";
} else {
$row["maptable"] .= "<tr><td width=\"20%\"><input type=\"submit\" name=\"two\" value=\"".$b["name"]."\" style=\"width: 100px;\" /></td><td width=\"30%\" style=\"vertical-align: middle;\">Price: <b>".$b["mapprice"]." Gold</b></td><td colspan=\"2\" style=\"vertical-align: middle;\">Buy map to reveal details.</td></tr>\n";
}
}
$row["maptable"] .= "</table></form>\n";
display("Buy Maps", parsetemplate(gettemplate("town_map1"), $row));
}
}
function buy() { // Buy items from merchants.
/*
1: Weapon
2: Armor
3: Shield
4: Helmet
5: Jewel
6: Stone
*/
global $userrow, $townrow;
if (isset($_POST["three"])) {
$idstring = explode(",",$_POST["idstring"]);
foreach($idstring as $a=>$b) { if(!is_numeric($b)) { err("Invalid action. Please <a href=\"index.php\">go back</a> and try again."); } }
// Get database info on new item.
$newbaseitem = dorow(doquery("SELECT * FROM <<itembase>> WHERE id='$idstring[1]' LIMIT 1"));
$newprefix = dorow(doquery("SELECT * FROM <<itemprefixes>> WHERE id='$idstring[0]' LIMIT 1"));
$newsuffix = dorow(doquery("SELECT * FROM <<itemsuffixes>> WHERE id='$idstring[2]' LIMIT 1"));
$modrow = dorow(doquery("SELECT * FROM <<itemmodnames>> ORDER BY id"), "fieldname");
$newfullitem = builditem($newprefix, $newbaseitem, $newsuffix, $modrow);
// Get database info on old item, if applicable.
if ($userrow["item" . $newbaseitem["slotnumber"] . "idstring"] != "0") {
$oldidstring = explode(",",$userrow["item" . $newbaseitem["slotnumber"] . "idstring"]);
$oldbaseitem = dorow(doquery("SELECT * FROM <<itembase>> WHERE id='$oldidstring[1]' LIMIT 1"));
$oldprefix = dorow(doquery("SELECT * FROM <<itemprefixes>> WHERE id='$oldidstring[0]' LIMIT 1"));
$oldsuffix = dorow(doquery("SELECT * FROM <<itemsuffixes>> WHERE id='$oldidstring[2]' LIMIT 1"));
$oldfullitem = builditem($oldprefix, $oldbaseitem, $oldsuffix, $modrow);
} else { $oldfullitem = false; $oldprefix = false; $oldsuffix = false; }
// Requirements check.
if ($newfullitem["requirements"] == false) { err("You do not meet one or more of the requirements for this item. Please <a href=\"index.php\">go back</a> and try again."); }
if ($userrow["gold"] < $newfullitem["buycost"]) { err("You do not have enough gold in your pocket to buy this item."); }
// Now do stuff to userrow (new item only).
$userrow["item" . $newfullitem["slotnumber"] . "idstring"] = $newfullitem["fullid"];
$userrow["item" . $newfullitem["slotnumber"] . "name"] = $newfullitem["name"];
$userrow["gold"] -= $newfullitem["buycost"];
$userrow[$newfullitem["basename"]] += $newfullitem["baseattr"];
for($j=1; $j<7; $j++) {
if ($newfullitem["mod".$j."name"] != "") {
$userrow[$newfullitem["mod".$j."name"]] += $newfullitem["mod".$j."attr"];
}
}
if ($newprefix != false) {
$userrow[$newprefix["basename"]] += $newprefix["baseattr"];
}
if ($newsuffix != false) {
$userrow[$newsuffix["basename"]] += $newsuffix["baseattr"];
}
// Do more stuff to userrow (old item only).
if ($oldfullitem != false) {
$userrow["gold"] += $oldfullitem["sellcost"];
$userrow[$oldfullitem["basename"]] -= $oldfullitem["baseattr"];
for($j=1; $j<7; $j++) {
if ($oldfullitem["mod".$j."name"] != "") {
$userrow[$oldfullitem["mod".$j."name"]] -= $oldfullitem["mod".$j."attr"];
}
}
if ($oldprefix != false) {
$userrow[$oldprefix["basename"]] -= $oldprefix["baseattr"];
}
if ($oldsuffix != false) {
$userrow[$oldsuffix["basename"]] -= $oldsuffix["baseattr"];
}
}
// And we're done.
updateuserrow();
display("Buy Weapons & Armor", gettemplate("town_buy3"));
} elseif (isset($_POST["two"])) {
$idstring = explode(",",$_POST["idstring"]);
foreach($idstring as $a=>$b) { if(!is_numeric($b)) { err("Invalid action. Please <a href=\"index.php\">go back</a> and try again."); } }
// Get database info on new item.
$newbaseitem = dorow(doquery("SELECT * FROM <<itembase>> WHERE id='$idstring[1]' LIMIT 1"));
$newprefix = dorow(doquery("SELECT * FROM <<itemprefixes>> WHERE id='$idstring[0]' LIMIT 1"));
$newsuffix = dorow(doquery("SELECT * FROM <<itemsuffixes>> WHERE id='$idstring[2]' LIMIT 1"));
$premodrow = dorow(doquery("SELECT * FROM <<itemmodnames>> ORDER BY id"));
// Format the mod name row.
foreach($premodrow as $a=>$b) {
$modrow[$b["fieldname"]] = $b;
}
$newfullitem = builditem($newprefix, $newbaseitem, $newsuffix, $modrow);
// Get database info on old item, if applicable.
if ($userrow["item" . $newbaseitem["slotnumber"] . "idstring"] != "0") {
$oldidstring = explode(",",$userrow["item" . $newbaseitem["slotnumber"] . "idstring"]);
$oldbaseitem = dorow(doquery("SELECT * FROM <<itembase>> WHERE id='$oldidstring[1]' LIMIT 1"));
$oldprefix = dorow(doquery("SELECT * FROM <<itemprefixes>> WHERE id='$oldidstring[0]' LIMIT 1"));
$oldsuffix = dorow(doquery("SELECT * FROM <<itemsuffixes>> WHERE id='$oldidstring[2]' LIMIT 1"));
$oldfullitem = builditem($oldprefix, $oldbaseitem, $oldsuffix, $modrow);
} else { $oldfullitem = false; }
// Requirements check.
if ($newfullitem["requirements"] == false) { err("You do not meet one or more of the requirements for this item. Please <a href=\"index.php\">go back</a> and try again."); }
if ($userrow["gold"] < $newfullitem["buycost"]) { err("You do not have enough gold in your pocket to buy this item."); }
// Now make a new array to send to the template.
$full = "_empty";
$row["newname"] = $newfullitem["name"];
if ($oldfullitem != false) {
$row["oldname"] = $oldfullitem["name"];
$row["oldsell"] = $oldfullitem["sellcost"];
$full = "_full";
}
$row["newidstring"] = $newfullitem["fullid"];
// And we're done.
display("Buy Weapons & Armor", parsetemplate(gettemplate("town_buy2" . $full),$row));
} else {
// Grab lots of stuff from the DB.
$preitemsrow = dorow(doquery("SELECT * FROM <<itembase>> WHERE reqlevel>='".$townrow["itemminlvl"]."' AND reqlevel<='".$townrow["itemmaxlvl"]."' AND isunique='0' ORDER BY RAND() LIMIT 10"));
$preprefixrow = dorow(doquery("SELECT * FROM <<itemprefixes>> WHERE reqlevel<='".$userrow["level"]."'"));
$presuffixrow = dorow(doquery("SELECT * FROM <<itemsuffixes>> WHERE reqlevel<='".$userrow["level"]."'"));
$allitemsrow = dorow(doquery("SELECT * FROM <<itembase>>"));
$allprefixrow = dorow(doquery("SELECT * FROM <<itemprefixes>>"));
$allsuffixrow = dorow(doquery("SELECT * FROM <<itemsuffixes>>"));
$premodrow = dorow(doquery("SELECT * FROM <<itemmodnames>> ORDER BY id"));
// Format the rows.
foreach($allitemsrow as $a=>$b) {
$itemsrow[$b["id"]] = $b;
}
foreach($allprefixrow as $a=>$b) {
$prefixrow[$b["id"]] = $b;
}
foreach($allsuffixrow as $a=>$b) {
$suffixrow[$b["id"]] = $b;
}
foreach($premodrow as $a=>$b) {
$modrow[$b["fieldname"]] = $b;
}
// Build old item table.
$row["olditems"] = "";
for($i=1; $i<7; $i++) {
if ($userrow["item".$i."idstring"] != "0") {
$ids = explode(",",$userrow["item".$i."idstring"]);
$baseitem = $itemsrow[$ids[1]];
if ($ids[0] != 0) { $prefix = $prefixrow[$ids[0]]; } else { $prefix = false; }
if ($ids[2] != 0) { $suffix = $suffixrow[$ids[2]]; } else { $suffix = false; }
$fullitem = builditem($prefix, $baseitem, $suffix, $modrow);
$row["olditems"] .= parsetemplate(gettemplate("town_buy_olditemrow"), $fullitem);
}
}
// Now build the new item table.
$row["itemtable"] = "";
for($i=0; $i<10; $i++) {
$baseitem = $preitemsrow[rand(0,(sizeof($preitemsrow)-1))];
if (rand(0,4)==1) { $prefix = $preprefixrow[rand(0,(sizeof($preprefixrow)-1))]; } else { $prefix = false; }
if (rand(0,4)==1) { $suffix = $presuffixrow[rand(0,(sizeof($presuffixrow)-1))]; } else { $suffix = false; }
$fullitem = builditem($prefix, $baseitem, $suffix, $modrow);
$row["itemtable"] .= parsetemplate(gettemplate("town_buy_itemrow"), $fullitem);
}
// And we're done.
display("Buy Weapons & Armor", parsetemplate(gettemplate("town_buy1"),$row));
}
}
function gamble() {
global $userrow;
$mode = "easy";
if (isset($_GET["mode"])) { $mode = $_GET["mode"]; }
if (isset($_POST["submit"])) {
$amount = $_POST["amount"];
// Cup errors.
if (!isset($_POST["cup"])) { err("You didn't pick any cup to bet on. Please <a href=\"index.php?do=gamble\">go back</a> and try again."); }
if (!is_numeric($_POST["cup"])) { err("You didn't pick any cup to bet on. Please <a href=\"index.php?do=gamble\">go back</a> and try again."); }
// Bet amount errors.
if (trim($amount) == "") { err("Invalid bet amount. Please <a href=\"index.php?do=gamble\">go back</a> and try again."); }
if (!is_numeric($amount)) { err("Invalid bet amount. Please <a href=\"index.php?do=gamble\">go back</a> and try again."); }
if ($amount <= 0) { err("Invalid bet amount. Please <a href=\"index.php?do=gamble\">go back</a> and try again."); }
if ($userrow["gold"] < $amount) { err("Invalid bet amount. Please <a href=\"index.php?do=gamble\">go back</a> and try again."); }
if ($mode == "hard") {
$thecup = $_POST["cup"];
$thewin = rand(1,9);
if ($thecup == $thewin) {
$userrow["gold"] += ($amount * 10);
doquery("UPDATE <<users>> SET gold=gold+($amount * 10) WHERE id='".$userrow["id"]."' LIMIT 1");
display("Gamble", "You won!<br /><br />You just picked up <b>".($amount * 10)." Gold</b>.<br /><br />Care to <a href=\"index.php?do=gamble&mode=hard\">try again</a> or would you rather go back to <a href=\"index.php\">town</a>?");
} else {
$userrow["gold"] -= $amount;
doquery("UPDATE <<users>> SET gold=gold-$amount WHERE id='".$userrow["id"]."' LIMIT 1");
display("Gamble", "You lost!<br /><br />Sorry buddy, but we're gonna have to take your <b>".$amount." Gold</b>.<br /><br />Care to <a href=\"index.php?do=gamble&mode=hard\">try again</a> or would you rather go back to <a href=\"index.php\">town</a>?");
}
}
if ($mode == "easy") {
$thecup = $_POST["cup"];
$thewin = rand(1,3);
if ($thecup == $thewin) {
$userrow["gold"] += ($amount * 2);
doquery("UPDATE <<users>> SET gold=gold+($amount * 2) WHERE id='".$userrow["id"]."' LIMIT 1");
display("Gamble", "You won!<br /><br />You just picked up <b>".($amount * 2)." Gold</b>.<br /><br />Care to <a href=\"index.php?do=gamble\">try again</a> or would you rather go back to <a href=\"index.php\">town</a>?");
} else {
$userrow["gold"] -= $amount;
doquery("UPDATE <<users>> SET gold=gold-$amount WHERE id='".$userrow["id"]."' LIMIT 1");
display("Gamble", "You lost!<br /><br />Sorry buddy, but we're gonna have to take your <b>".$amount." Gold</b>.<br /><br />Care to <a href=\"index.php?do=gamble\">try again</a> or would you rather go back to <a href=\"index.php\">town</a>?");
}
}
} else {
if ($mode == "hard") {
$row["mode"] = "hard";
$row["form"] = "<table width=\"200\"><tr>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"1\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"1\" id=\"1\" /></label></td>";
$row["form"] .= "<td width=\"34%\" style=\"text-align: center;\"><label for=\"2\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"2\" id=\"2\" /></label></td>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"3\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"3\" id=\"3\" /></label></td>";
$row["form"] .= "</tr><tr>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"4\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"4\" id=\"4\" /></label></td>";
$row["form"] .= "<td width=\"34%\" style=\"text-align: center;\"><label for=\"5\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"5\" id=\"5\" /></label></td>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"6\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"6\" id=\"6\" /></label></td>";
$row["form"] .= "</tr><tr>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"7\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"7\" id=\"7\" /></label></td>";
$row["form"] .= "<td width=\"34%\" style=\"text-align: center;\"><label for=\"8\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"8\" id=\"8\" /></label></td>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"9\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"9\" id=\"9\" /></label></td>";
$row["form"] .= "</tr></table>";
}
if ($mode == "easy") {
$row["mode"] = "easy";
$row["form"] = "<table width=\"200\"><tr>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"1\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"1\" id=\"1\" /></label></td>";
$row["form"] .= "<td width=\"34%\" style=\"text-align: center;\"><label for=\"2\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"2\" id=\"2\" /></label></td>";
$row["form"] .= "<td width=\"33%\" style=\"text-align: center;\"><label for=\"3\"><img src=\"images/cup.gif\" alt=\"cup\" /><br /><input type=\"radio\" name=\"cup\" value=\"3\" id=\"3\" /></label></td>";
$row["form"] .= "</tr></table>";
}
display("Gamble", parsetemplate(gettemplate("town_gamble1"), $row));
}
}
function bank() {
global $userrow;
if (isset($_POST["withdraw"])) {
if (!is_numeric($_POST["amount"])) { err("Invalid action. Please <a href=\"index.php\">go back</a> and try again."); }
if ($_POST["amount"] < 1) { err("Withdrawal amount must be greater than 0."); }
if ($_POST["amount"] > $userrow["bank"]) { err("You do not have that much money in the bank."); }
$userrow["gold"] += $_POST["amount"];
$userrow["bank"] -= $_POST["amount"];
updateuserrow();
$row["formatbank"] = number_format($userrow["bank"]);
$row["formatgold"] = number_format($userrow["gold"]);
display("Deposit/Withdraw Gold at the Bank", parsetemplate(gettemplate("town_bank2"),$row));
} elseif (isset($_POST["deposit"])) {
if (!is_numeric($_POST["amount"])) { err("Invalid action. Please <a href=\"index.php\">go back</a> and try again."); }
if ($_POST["amount"] < 1) { err("Deposit amount must be greater than 0."); }
if ($_POST["amount"] > $userrow["gold"]) { err("You do not have that much money in your pocket."); }
$userrow["gold"] -= $_POST["amount"];
$userrow["bank"] += $_POST["amount"];
updateuserrow();
$row["formatbank"] = number_format($userrow["bank"]);
$row["formatgold"] = number_format($userrow["gold"]);
display("Deposit/Withdraw Gold at the Bank", parsetemplate(gettemplate("town_bank2"),$row));
} else {
$row["formatbank"] = number_format($userrow["bank"]);
$row["formatgold"] = number_format($userrow["gold"]);
$row["maxpocket"] = $userrow["gold"];
$row["maxbank"] = $userrow["bank"];
display("Deposit/Withdraw Gold at the Bank", parsetemplate(gettemplate("town_bank1"),$row));
}
}
function halloffame() {
$top = dorow(doquery("SELECT *, DATE_FORMAT(birthdate, '%m.%d.%Y') AS fregdate FROM <<users>> ORDER BY experience DESC LIMIT 25"), "id");
$row["halltable"] = "";
$i = 1;
foreach ($top as $a => $b) {
if ($b["charpicture"] != "") {
$b["avatar"] = "<img src=\"".$b["charpicture"]."\" alt=\"".$b["charname"]."\" />";
} else {
$b["avatar"] = "<img src=\"images/users/nopicture.gif\" alt=\"".$b["charname"]."\" />";
}
$b["experience"] = number_format($b["experience"]);
$b["number"] = $i;
if ($b["guild"] != 0) {
$charname = "[<span style=\"color: ".$b["tagcolor"].";\">".$b["guildtag"]."</span>]<span style=\"color: ".$b["namecolor"].";\">".$b["charname"]."</span>";
} else {
$charname = $b["charname"];
}
$b["newcharname"] = $charname;
$row["halltable"] .= parsetemplate(gettemplate("town_halloffamerow"), $b);
$i++;
}
$row["halltable"] .= "<br />\n";
display("Hall of Fame", parsetemplate(gettemplate("town_halloffame"), $row));
}
function duel() {
global $userrow;
$row = dorow(doquery("SELECT * FROM <<users>> WHERE UNIX_TIMESTAMP(onlinetime) >= '".(time()-600)."' AND world='".$userrow["world"]."' AND latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' AND id !='".$userrow["id"]."' ORDER BY id"), "id");
$list = "";
if ($row == false) {
$list .= "There is nobody available to challenge at this time.<br />";
} else {
foreach($row as $a=>$b) {
if ($b["guild"] != 0) {
$charname = "[<span style=\"color: ".$b["tagcolor"].";\">".$b["guildtag"]."</span>]<span style=\"color: ".$b["namecolor"].";\">".$b["charname"]."</span>";
} else {
$charname = $b["charname"];
}
$list .= "<a href=\"index.php?do=challenge&uid=".$b["id"]."\">".$b["charname"]." (Level ".$b["level"].")</a><br />";
}
}
$pagerow["list"] = $list;
display("Duel Challenge", parsetemplate(gettemplate("town_pvplist"),$pagerow));
}
function duelchallenge() {
global $userrow, $acctrow;
if(isset($_GET["uid"])) {
if (!is_numeric($_GET["uid"])) { err("Invalid UID."); }
if ($_GET["uid"] == $userrow["id"]) { err("You cannot duel yourself."); }
$newuserrow = dorow(doquery("SELECT *,UNIX_TIMESTAMP(onlinetime) as fonlinetime FROM <<users>> WHERE id='".$_GET["uid"]."' LIMIT 1"));
if ($newuserrow == false) { err("That user doesn't exist."); }
if ($newuserrow["account"] == $userrow["account"]) { err("You cannot duel another character on your own account."); }
if ($newuserrow["fonlinetime"] <= (time() - 600)) { err("That user is not online."); }
if ($newuserrow["currentaction"] != "In Town") { err("That user is busy."); }
if ($newuserrow["latitude"] != $userrow["latitude"] || $newuserrow["longitude"] != $userrow["longitude"]) { err("That user is not in this town."); }
} else { err("Invalid UID."); }
// No errors, so create the PVP record and update everyone's userrow.
$query = doquery("INSERT INTO <<pvp>> SET id='',player1id='".$userrow["id"]."',player2id='".$newuserrow["id"]."',player1name='".$userrow["charname"]."',player2name='".$newuserrow["charname"]."',playerturn='".$newuserrow["id"]."',turntime=NOW(),fightrow=''");
$query2 = doquery("UPDATE <<users>> SET currentpvp='".mysql_insert_id()."' WHERE id='".$newuserrow["id"]."' OR id='".$userrow["id"]."' LIMIT 2");
display("Duel Challenge",parsetemplate(gettemplate("pvp_challenge"),$newuserrow));
}
?>