-
Notifications
You must be signed in to change notification settings - Fork 9
/
estate.php
94 lines (93 loc) · 2.6 KB
/
estate.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
<?php
declare(strict_types=1);
/**
* MCCodes v2 by Dabomstew & ColdBlooded
*
* Repository: https://github.com/davemacaulay/mccodesv2
* License: MIT License
*/
global $db, $ir, $userid, $h;
require_once('globals.php');
$mpq =
$db->query(
"SELECT *
FROM `houses`
WHERE `hWILL` = {$ir['maxwill']}
LIMIT 1");
$mp = $db->fetch_row($mpq);
$db->free_result($mpq);
if (isset($_GET['property']) && is_numeric($_GET['property']))
{
$_GET['property'] = abs((int) $_GET['property']);
$npq =
$db->query(
"SELECT `hWILL`, `hPRICE`, `hNAME`
FROM `houses`
WHERE `hID` = {$_GET['property']}");
if ($db->num_rows($npq) == 0)
{
$db->free_result($npq);
echo "That house doesn't exist.";
$h->endpage();
exit;
}
$np = $db->fetch_row($npq);
$db->free_result($npq);
if ($np['hWILL'] < $mp['hWILL'])
{
echo 'You cannot go backwards in houses!';
}
elseif ($np['hPRICE'] > $ir['money'])
{
echo "You do not have enough money to buy the {$np['hNAME']}.";
}
else
{
$db->query(
"UPDATE `users`
SET `money` = `money` - {$np['hPRICE']},
`will` = 0, `maxwill` = {$np['hWILL']}
WHERE `userid` = $userid");
echo "Congrats, you bought the {$np['hNAME']} for "
. money_formatter($np['hPRICE']) . '!';
}
}
elseif (isset($_GET['sellhouse']))
{
if ($ir['maxwill'] == 100)
{
echo 'You already live in the lowest property!';
}
else
{
$db->query(
"UPDATE `users`
SET `money` = `money` + {$mp['hPRICE']},
`will` = 0, `maxwill` = 100
WHERE `userid` = $userid");
echo "You sold your {$mp['hNAME']} and went back to your shed.";
}
}
else
{
echo "Your current property: <b>{$mp['hNAME']}</b><br />
The houses you can buy are listed below. Click a house to buy it.<br />";
if ($ir['maxwill'] > 100)
{
echo "<a href='estate.php?sellhouse'>Sell Your House</a><br />";
}
$hq =
$db->query(
"SELECT *
FROM `houses`
WHERE `hWILL` > {$ir['maxwill']}
ORDER BY `hWILL` ASC");
while ($r = $db->fetch_row($hq))
{
echo "<a href='estate.php?property={$r['hID']}'>{$r['hNAME']}</a>"
. '   - Cost: ' . money_formatter($r['hPRICE'])
. "   - Will Bar: {$r['hWILL']}<br />";
}
$db->free_result($hq);
}
$h->endpage();