adds ability to assign NPCs to POI from POI page, adds POI-NPCs page
This commit is contained in:
parent
7f30383ef3
commit
246a883f57
@ -9,8 +9,11 @@
|
||||
<h2>Tables</h2>
|
||||
|
||||
<p><a href="players.php">Players</a></p>
|
||||
<br />
|
||||
<p><a href="pois.php">Points of Interest</a></p>
|
||||
<p><a href="npcs.php">NPCs</a></p>
|
||||
<p><a href="poi-npcs.php">NPCs assigned to POIs</a></p>
|
||||
<br />
|
||||
<p><a href="items.php">Items</a></p>
|
||||
|
||||
<?php
|
||||
|
84
src/webserver/admin/poi-npcs.php
Normal file
84
src/webserver/admin/poi-npcs.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
$db_path = realpath(dirname(__FILE__) . '/../config/db.php');
|
||||
require_once($db_path);
|
||||
require_once(realpath(dirname(__FILE__) . '/../header.php'));
|
||||
?>
|
||||
|
||||
|
||||
<h1>Wander Admin</h1>
|
||||
|
||||
<h2>POI NPCs</h2>
|
||||
|
||||
<p><a href='./pois.php?action=create'>Create New POI</a></p>
|
||||
<p><a href='./npcs.php?action=create'>Create New NPC</a></p>
|
||||
|
||||
<?php
|
||||
if (!isset($_GET['action']) && !isset($_POST['action'])) {
|
||||
?>
|
||||
|
||||
<table border=1>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>POI</td>
|
||||
<td>NPC</td>
|
||||
<td>Group Size</td>
|
||||
</tr>
|
||||
<?php
|
||||
$results = $conn->query('SELECT * FROM "POI-NPCs"');
|
||||
while ($row = $results->fetchArray()) {
|
||||
$poiRes = $conn->query('SELECT * FROM POIs WHERE id = ' . $row['poi_id']);
|
||||
if ($poiRes) {
|
||||
$thisPoi = $poiRes->fetchArray();
|
||||
}
|
||||
$npcRes = $conn->query('SELECT * FROM NPCs WHERE id = ' . $row['npc_id']);
|
||||
if ($npcRes) {
|
||||
$thisNpc = $npcRes->fetchArray();
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td><a href='./poi-npcs.php?action=edit&id=<?= $row['id'] ?>'><?= $row['id'] ?></a></td>
|
||||
<td><?= $thisPoi['name'] ?></td>
|
||||
<td><?= $thisNpc['description'] ?></td>
|
||||
<td><?= $row['group_size'] ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'create':
|
||||
// create new NPC instance at POI
|
||||
$poi_id = $_GET['poi_id'];
|
||||
$npc_id = $_POST['npc'];
|
||||
$npcRes = $conn->query('SELECT * FROM NPCs WHERE id = ' . $npc_id);
|
||||
if ($npcRes) {
|
||||
$thisNpc = $npcRes->fetchArray();
|
||||
}
|
||||
$groupSize = rand($thisNpc['minimum_group'], $thisNpc['maximum_group']);
|
||||
$createQuery = 'INSERT INTO "POI-NPCs" (poi_id, npc_id, group_size) VALUES (' . $poi_id . ', ' . $npc_id . ', ' . $groupSize . ')';
|
||||
$createRes = $conn->query($createQuery);
|
||||
if ($createRes) {
|
||||
echo "<p>NPC added to POI. <a href='poi-npcs.php'>< View POI-NPCs</a></p>\n";
|
||||
} else {
|
||||
echo "<p><strong>oopsie!</strong> There was a problem adding the NPC to the POI. Check the logs!</p>\n";
|
||||
echo "<p>last error: " . $conn->lastErrorMsg() . "</p>\n";
|
||||
echo "<p>query: " . $createQuery . "</p>\n";
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
case 'save':
|
||||
default:
|
||||
echo "Unknown action: " . $_GET['action'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<p><a href="index.php">< back to Admin</a></p>
|
||||
|
||||
<?php
|
||||
require_once(realpath(dirname(__FILE__) . '/../footer.php'));
|
||||
?>
|
@ -25,6 +25,7 @@
|
||||
<td>Longitude</td>
|
||||
<td>Radius</td>
|
||||
<td>Map Marker</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<?php
|
||||
$results = $conn->query('SELECT * FROM POIs');
|
||||
@ -39,6 +40,15 @@
|
||||
<td><?= $row['longitude'] ?></td>
|
||||
<td><?= $row['radius'] ?></td>
|
||||
<td><?= $row['map_marker_icon'] ?></td>
|
||||
<td><form id='assign-npc-to-<?= $row['id'] ?>' method='POST' action='poi-npcs.php?action=create&poi_id=<?= $row['id'] ?>'><select name='npc' id='npc-selector-<?= $row['id'] ?>'>
|
||||
<?php
|
||||
$npcRes = $conn->query('SELECT * FROM NPCs WHERE is_active = 1');
|
||||
while ($npcRow = $npcRes->fetchArray()) {
|
||||
echo "<option value='" . $npcRow['id'] . "'>" . $npcRow['name'] . " (id " . $npcRow['id'] . ")</option>\n";
|
||||
}
|
||||
?>
|
||||
</select><input type='submit' form='assign-npc-to-<?= $row['id'] ?>' name='poi-<?= $row['id'] ?>-submit' value='Assign NPC' /></form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user