Update showchar to use new renderer, move display logic
This commit is contained in:
parent
2801550bdd
commit
c2e15d580a
|
@ -37,8 +37,8 @@ Admin\register_routes($r);
|
|||
$r->post('/move', 'move');
|
||||
|
||||
$r->get('/spell/:id', 'healspells');
|
||||
$r->get('/showchar', 'showchar');
|
||||
$r->get('/onlinechar/:id', 'onlinechar');
|
||||
$r->get('/character', 'show_character_info');
|
||||
$r->get('/character/:id', 'show_character_info');
|
||||
$r->get('/showmap', 'showmap');
|
||||
$r->form('/babblebox', 'babblebox');
|
||||
|
||||
|
@ -96,7 +96,7 @@ function dotown()
|
|||
|
||||
while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) {
|
||||
$online_count++;
|
||||
$online_rows[] = "<a href=\"/onlinechar/{$onlinerow["id"]}\">".$onlinerow["username"]."</a>";
|
||||
$online_rows[] = "<a href=\"javascript:opencharpopup({$onlinerow['id']})\">".$onlinerow["username"]."</a>";
|
||||
}
|
||||
|
||||
$townrow["whosonline"] = '<div class="title">Who\'s Online</div>';
|
||||
|
@ -133,73 +133,40 @@ function doexplore()
|
|||
HTML;
|
||||
}
|
||||
|
||||
function showchar()
|
||||
{
|
||||
global $userrow, $controlrow;
|
||||
|
||||
$userrow["experience"] = number_format($userrow["experience"]);
|
||||
$userrow["gold"] = number_format($userrow["gold"]);
|
||||
|
||||
$userrow["plusexp"] = $userrow["expbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)</span>"
|
||||
: "";
|
||||
|
||||
$userrow["plusgold"] = $userrow["goldbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)</span>"
|
||||
: "";
|
||||
|
||||
$levelrow = db()->query("SELECT `{$userrow["charclass"]}_exp` FROM levels WHERE id=? LIMIT 1;", [$userrow['level'] + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
$userrow["nextlevel"] = $userrow['level'] < 99 ? number_format($levelrow[$userrow["charclass"]."_exp"]) : '<span class="light">None</span>';
|
||||
|
||||
$userrow['charclass'] = match ((int) $userrow['charclass']) {
|
||||
1 => $controlrow["class1name"],
|
||||
2 => $controlrow["class2name"],
|
||||
3 => $controlrow["class3name"]
|
||||
};
|
||||
|
||||
$spells = db()->query('SELECT id, name FROM spells;');
|
||||
$userspells = explode(',', $userrow['spells']);
|
||||
$userrow["magiclist"] = '';
|
||||
while ($spellrow = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||
$spell = false;
|
||||
foreach($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
|
||||
if ($spell == true) $userrow["magiclist"] .= $spellrow["name"]."<br>";
|
||||
}
|
||||
if ($userrow["magiclist"] == "") $userrow["magiclist"] = "None";
|
||||
|
||||
$array = ["content" => parsetemplate(gettemplate("showchar"), $userrow), "title" => "Character Information"];
|
||||
echo render('minimal', $array);
|
||||
}
|
||||
|
||||
function onlinechar($id)
|
||||
/**
|
||||
* Show a character's info. Defaults to the currently logged in user.
|
||||
*/
|
||||
function show_character_info(int $id = 0): void
|
||||
{
|
||||
global $controlrow;
|
||||
|
||||
$query = db()->query('SELECT * FROM users WHERE id=? LIMIT 1;', [$id]);
|
||||
if ($query !== false) { $userrow = $query->fetchArray(SQLITE3_ASSOC); } else { display("No such user.", "Error"); }
|
||||
unset($userrow['password']);
|
||||
if ($id === 0) {
|
||||
global $userrow;
|
||||
} else {
|
||||
$userrow = get_user_by_id($id);
|
||||
}
|
||||
|
||||
$userrow["experience"] = number_format($userrow["experience"]);
|
||||
$userrow["gold"] = number_format($userrow["gold"]);
|
||||
|
||||
$userrow["plusexp"] = $userrow["expbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)</span>"
|
||||
: "";
|
||||
|
||||
$userrow["plusgold"] = $userrow["goldbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)</span>"
|
||||
: "";
|
||||
if ($userrow === false) exit('Failed to show info for user ID '.$id);
|
||||
|
||||
$levelrow = db()->query("SELECT `{$userrow["charclass"]}_exp` FROM levels WHERE id=? LIMIT 1;", [$userrow['level'] + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
$userrow["nextlevel"] = $userrow['level'] < 99 ? number_format($levelrow[$userrow["charclass"]."_exp"]) : '<span class="light">None</span>';
|
||||
|
||||
$userrow['charclass'] = match ((int) $userrow['charclass']) {
|
||||
1 => $controlrow["class1name"],
|
||||
2 => $controlrow["class2name"],
|
||||
3 => $controlrow["class3name"]
|
||||
};
|
||||
$spells = db()->query('SELECT id, name FROM spells;');
|
||||
$userspells = explode(',', $userrow['spells']);
|
||||
$magic_list = '';
|
||||
while ($spellrow = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||
$spell = false;
|
||||
foreach($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
|
||||
if ($spell == true) $magic_list .= $spellrow["name"]."<br>";
|
||||
}
|
||||
if ($magic_list == "") $magic_list = "None";
|
||||
|
||||
display(parsetemplate(gettemplate("onlinechar"), $userrow), "Character Information");
|
||||
$showchar = render('showchar', [
|
||||
'char' => $userrow,
|
||||
'level' => $levelrow,
|
||||
'magic_list' => $magic_list,
|
||||
'controlrow' => $controlrow
|
||||
]);
|
||||
echo render('minimal', ['content' => $showchar, 'title' => $userrow['username'].' Information']);
|
||||
}
|
||||
|
||||
function showmap()
|
||||
|
|
12
src/lib.php
12
src/lib.php
|
@ -138,7 +138,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
|
|||
} else {
|
||||
$topnav = <<<HTML
|
||||
<a href='/login'><img src='/img/button_login.gif' alt='Log In' title='Log In'></a>
|
||||
<a href='users.php?do=register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
|
||||
<a href='/register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
|
||||
<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
|
||||
HTML;
|
||||
}
|
||||
|
@ -310,6 +310,16 @@ function get_town_by_id(int $id): array|false
|
|||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user's data by their ID.
|
||||
*/
|
||||
function get_user_by_id(int $id): array|false
|
||||
{
|
||||
$query = db()->query('SELECT * FROM users WHERE id = ? LIMIT 1;', [$id]);
|
||||
if ($query === false) return false;
|
||||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item by it's ID.
|
||||
*/
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<title><?= $title ?></title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-image: url(/img/background.jpg);
|
||||
background-image: url('/img/background.jpg');
|
||||
color: black;
|
||||
font: 11px verdana;
|
||||
}
|
||||
|
@ -60,8 +60,6 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<?= $content ?>
|
||||
</center>
|
||||
<?= $content ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -9,13 +9,15 @@ $template = <<<HTML
|
|||
<link rel="stylesheet" href="/css/dk.css">
|
||||
|
||||
<script>
|
||||
function opencharpopup(){
|
||||
var popurl="/showchar"
|
||||
winpops=window.open(popurl,"","width=210,height=500,scrollbars")
|
||||
function opencharpopup(id = 0)
|
||||
{
|
||||
const url = id == 0 ? '/character' : '/character/' + id
|
||||
window.open(url, "", "width=210,height=500,scrollbars")
|
||||
}
|
||||
function openmappopup(){
|
||||
var popurl="/showmap"
|
||||
winpops=window.open(popurl,"","width=520,height=520,scrollbars")
|
||||
|
||||
function openmappopup()
|
||||
{
|
||||
window.open("/showmap", "", "width=520,height=520,scrollbars")
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
@ -1,46 +1,36 @@
|
|||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="/img/button_character.gif" alt="Character" title="Character" /></td></tr>
|
||||
<tr><td>
|
||||
<b>{{username}}</b><br><br>
|
||||
<div class="title"><img src="/img/button_character.gif" alt="Character" title="Character"></div>
|
||||
<b><?= $char['username'] ?></b><br><br>
|
||||
|
||||
Class: {{charclass}}<br><br>
|
||||
Class: <?= match ($char['charclass']) {
|
||||
1 => $controlrow["class1name"],
|
||||
2 => $controlrow["class2name"],
|
||||
3 => $controlrow["class3name"]
|
||||
}; ?><br><br>
|
||||
|
||||
Level: {{level}}<br>
|
||||
Experience: {{experience}} {{plusexp}}<br>
|
||||
Next Level: {{nextlevel}}<br>
|
||||
Gold: {{gold}} {{plusgold}}<br>
|
||||
Hit Points: {{currenthp}} / {{maxhp}}<br>
|
||||
Magic Points: {{currentmp}} / {{maxmp}}<br>
|
||||
Travel Points: {{currenttp}} / {{maxtp}}<br><br>
|
||||
Level: <?= $char['level'] ?><br>
|
||||
Experience: <?= number_format($char['experience']) ?>
|
||||
<?php if ($char['expbonus'] !== 0): ?> <span class="light">(<?= $char['expbonus'] > 0 ? '+' : '' ?>) <?= $char['expbonus'] ?>%)</span> <?php endif; ?><br>
|
||||
Next Level: <?php if ($char['level'] < 99) { echo number_format($level[$char['charclass']."_exp"]); } else { ?> <span class="light">None</span> <?php } ?><br>
|
||||
Gold: <?= number_format($char['gold']) ?>
|
||||
<?php if ($char['goldbonus'] !== 0): ?> <span class="light">(<?= $char['goldbonus'] > 0 ? '+' : '' ?>) <?= $char['goldbonus'] ?>%)</span> <?php endif; ?><br>
|
||||
Hit Points: <?= number_format($char['currenthp']) ?> / <?= number_format($char['maxhp']) ?><br>
|
||||
Magic Points: <?= number_format($char['currentmp']) ?> / <?= number_format($char['maxmp']) ?><br>
|
||||
Travel Points: <?= number_format($char['currenttp']) ?> / <?= number_format($char['maxtp']) ?><br><br>
|
||||
|
||||
Strength: {{strength}}<br>
|
||||
Dexterity: {{dexterity}}<br>
|
||||
Attack Power: {{attackpower}}<br>
|
||||
Defense Power: {{defensepower}}<br>
|
||||
</td></tr>
|
||||
</table><br>
|
||||
Strength: <?= number_format($char['strength']) ?><br>
|
||||
Dexterity: <?= number_format($char['dexterity']) ?><br>
|
||||
Attack Power: <?= number_format($char['attackpower']) ?><br>
|
||||
Defense Power: <?= number_format($char['defensepower']) ?><br>
|
||||
<br>
|
||||
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="/img/button_inventory.gif" alt="Inventory" title="Inventory" /></td></tr>
|
||||
<tr><td>
|
||||
<table width="100%">
|
||||
<tr><td><img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon" /></td><td width="100%">Weapon: {{weaponname}}</td></tr>
|
||||
<tr><td><img src="/img/icon_armor.gif" alt="Armor" title="Armor" /></td><td width="100%">Armor: {{armorname}}</td></tr>
|
||||
<tr><td><img src="/img/icon_shield.gif" alt="Shield" title="Shield" /></td><td width="100%">Shield: {{shieldname}}</td></tr>
|
||||
</table>
|
||||
Slot 1: {{slot1name}}<br>
|
||||
Slot 2: {{slot2name}}<br>
|
||||
Slot 3: {{slot3name}}
|
||||
</td></tr>
|
||||
</table><br>
|
||||
<div class="title"><img src="/img/button_inventory.gif" alt="Inventory" title="Inventory"></div>
|
||||
<img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon"> Weapon: <?= $char['weaponname'] ?><br>
|
||||
<img src="/img/icon_armor.gif" alt="Armor" title="Armor"> Armor: <?= $char['armorname'] ?><br>
|
||||
<img src="/img/icon_shield.gif" alt="Shield" title="Shield"> Shield: <?= $char['shieldname'] ?><br>
|
||||
Slot 1: <?= $char['slot1name'] ?><br>
|
||||
Slot 2: <?= $char['slot2name'] ?><br>
|
||||
Slot 3: <?= $char['slot3name'] ?>
|
||||
<br>
|
||||
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="/img/button_spells.gif" alt="Spells" title="Spells" /></td></tr>
|
||||
<tr><td>
|
||||
{{magiclist}}
|
||||
</td></tr>
|
||||
</table><br>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
||||
<div class="title"><img src="/img/button_spells.gif" alt="Spells" title="Spells"></div>
|
||||
<?= $magic_list ?>
|
||||
|
|
Loading…
Reference in New Issue
Block a user