Update class spell concept, re-finish install, add level control for admin account
This commit is contained in:
parent
b328263aef
commit
28789a26e7
|
@ -34,6 +34,7 @@ const MAP = [
|
|||
// models
|
||||
'Classes' => SERVER.'/models/Classes.php',
|
||||
'Player' => SERVER.'/models/Player.php',
|
||||
'Spell' => SERVER.'/models/Spell.php',
|
||||
];
|
||||
|
||||
// autoloader
|
||||
|
|
6
server/database/packs/Default/class_spells.csv
Normal file
6
server/database/packs/Default/class_spells.csv
Normal file
|
@ -0,0 +1,6 @@
|
|||
Level,"Class ID","Spell ID"
|
||||
1,1,6
|
||||
1,1,18
|
||||
1,3,1
|
||||
1,3,15
|
||||
1,3,18
|
|
|
@ -1,4 +1,4 @@
|
|||
Name,"Start HP","Start MP","Start STR","Start ATK","Start DEF","Start DEX","Growth HP","Growth MP","Growth STR","Growth ATK","Growth DEF","Growth DEX",Spells
|
||||
Mage,10,10,5,5,5,5,3,5,1,3,1,3,"1:6,18"
|
||||
Warrior,20,0,10,5,10,5,6,2,3,1,3,1,
|
||||
Paladin,15,5,5,5,10,10,4,4,2,2,2,2,"1:1,15,18"
|
||||
Name,"Start HP","Start MP","Start STR","Start ATK","Start DEF","Start DEX","Growth HP","Growth MP","Growth STR","Growth ATK","Growth DEF","Growth DEX"
|
||||
Mage,10,10,5,5,5,5,3,5,1,3,1,3
|
||||
Warrior,20,0,10,5,10,5,6,2,3,1,3,1
|
||||
Paladin,15,5,5,5,10,10,4,4,2,2,2,2
|
||||
|
|
|
|
@ -14,18 +14,16 @@ class Classes
|
|||
return $res->fetch() ?: false;
|
||||
}
|
||||
|
||||
// Spell definitions are in the DB under the spell columns;
|
||||
// level:spell_id,spell_id|level:spell_id
|
||||
// This means that as level increases, more spells are available.
|
||||
public static function spellsToArray(string $spells): array
|
||||
public static function spells(int $id): array|false
|
||||
{
|
||||
$list = [];
|
||||
$groups = explode('|', $spells);
|
||||
foreach ($groups as $group) {
|
||||
$parts = explode(':', $group);
|
||||
// first part will be level, second part will be spell_ids
|
||||
$list[$parts[0]] = explode(',', $parts[1]);
|
||||
}
|
||||
return $list;
|
||||
$res = App::$db->do("SELECT level, spell_id FROM class_spells WHERE class_id = ?", [$id]);
|
||||
return $res->fetchAll() ?: false;
|
||||
}
|
||||
|
||||
public static function spellsAtLevel(int $id, int $level): array|false
|
||||
{
|
||||
// get all spells for the class under or equal to the level
|
||||
$ids = App::$db->do("SELECT spell_id FROM class_spells WHERE class_id = ? AND level <= ?", [$id, $level]);
|
||||
return $ids->fetchAll(PDO::FETCH_COLUMN) ?: false;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,12 @@ class Player
|
|||
$data['stat_points'] = $data['stat_points'] ?? (App::$s['stat_point_gain'] * ($l - 1));
|
||||
$data['exp2l'] = $data['exp2l'] ?? expToLevel($l + 1);
|
||||
|
||||
// award spells
|
||||
if (!isset($data['spells']) || empty($data['spells'])) {
|
||||
$spells = Classes::spellsAtLevel($class['id'], $l);
|
||||
$data['spells'] = implode(',', $spells);
|
||||
}
|
||||
|
||||
// compress data and generate placeholers
|
||||
$keys = implode(', ', array_keys($data));
|
||||
$placeholders = implode(', ', array_fill(0, count($data), '?'));
|
||||
|
|
27
server/models/Spell.php
Normal file
27
server/models/Spell.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
class Spell
|
||||
{
|
||||
public static function all(): array|false
|
||||
{
|
||||
$spells = App::$db->do("SELECT * FROM spells");
|
||||
return $spells->fetchAll() ?: false;
|
||||
}
|
||||
|
||||
public static function get(int $id): array|false
|
||||
{
|
||||
$spell = App::$db->do("SELECT * FROM spells WHERE id = ?", [$id]);
|
||||
return $spell->fetch() ?: false;
|
||||
}
|
||||
|
||||
public static function getFromList(string|array $list): array
|
||||
{
|
||||
if (is_string($list)) $list = explode(',', $list);
|
||||
$spells = [];
|
||||
foreach ($list as $id) {
|
||||
$spell = self::get($id);
|
||||
if ($spell !== false) $spells[] = $spell;
|
||||
}
|
||||
return $spells;
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ class InstallModule
|
|||
|
||||
// @Settings
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'settings' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'game_name' TEXT DEFAULT 'Dragon Knight',
|
||||
'game_version' TEXT DEFAULT '1.0',
|
||||
'game_dev' TEXT DEFAULT 'Sharkk',
|
||||
|
@ -57,7 +57,7 @@ class InstallModule
|
|||
|
||||
// @Classes
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'classes' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'name' TEXT DEFAULT '',
|
||||
'start_hp' INT DEFAULT 0,
|
||||
'start_mp' INT DEFAULT 0,
|
||||
|
@ -70,8 +70,7 @@ class InstallModule
|
|||
'growth_str' INT DEFAULT 0,
|
||||
'growth_atk' INT DEFAULT 0,
|
||||
'growth_dex' INT DEFAULT 0,
|
||||
'growth_def' INT DEFAULT 0,
|
||||
'spells' TEXT DEFAULT ''
|
||||
'growth_def' INT DEFAULT 0
|
||||
);");
|
||||
|
||||
if ($complete) {
|
||||
|
@ -84,7 +83,7 @@ class InstallModule
|
|||
|
||||
// @Babble
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'babble' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'author' INTEGER NOT NULL,
|
||||
'babble' TEXT NOT NULL,
|
||||
'posted' DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
|
@ -92,7 +91,7 @@ class InstallModule
|
|||
|
||||
// @Drops
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'drops' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'name' TEXT NOT NULL,
|
||||
'level' INTEGER DEFAULT 1,
|
||||
'type' INTEGER DEFAULT 1,
|
||||
|
@ -104,7 +103,7 @@ class InstallModule
|
|||
|
||||
// @Forum
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'forum' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'posted' DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
'new_post' DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
'author' INTEGER NOT NULL,
|
||||
|
@ -120,7 +119,7 @@ class InstallModule
|
|||
|
||||
// @Items
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'items' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'type' INTEGER DEFAULT 1,
|
||||
'name' TEXT NOT NULL,
|
||||
'cost' INTEGER DEFAULT 0,
|
||||
|
@ -133,7 +132,7 @@ class InstallModule
|
|||
|
||||
// @Monsters
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'monsters' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'name' TEXT NOT NULL,
|
||||
'level' INTEGER DEFAULT 1,
|
||||
'hp' INTEGER DEFAULT 1,
|
||||
|
@ -150,7 +149,7 @@ class InstallModule
|
|||
|
||||
// @News
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'news' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'author' INTEGER DEFAULT 1,
|
||||
'title' TEXT DEFAULT '',
|
||||
'content' TEXT DEFAULT '',
|
||||
|
@ -159,7 +158,7 @@ class InstallModule
|
|||
|
||||
// @Spells
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'spells' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'name' TEXT NOT NULL,
|
||||
'type' INTEGER DEFAULT 1,
|
||||
'mp' INTEGER DEFAULT 0,
|
||||
|
@ -170,6 +169,16 @@ class InstallModule
|
|||
// add default spells if complete install
|
||||
if ($complete) App::$db->insertFromCSV('spells', "$defaults/spells.csv");
|
||||
|
||||
// @LearnedSpells
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'class_spells' (
|
||||
'level' INTEGER NOT NULL,
|
||||
'class_id' INTEGER NOT NULL,
|
||||
'spell_id' INTEGER NOT NULL
|
||||
);");
|
||||
|
||||
// add default class spells if complete install
|
||||
if ($complete) App::$db->insertFromCSV('class_spells', "$defaults/class_spells.csv");
|
||||
|
||||
// @Towns
|
||||
App::$db->q("CREATE TABLE IF NOT EXISTS 'towns' (
|
||||
'id' INTEGER PRIMARY KEY,
|
||||
|
@ -258,8 +267,8 @@ class InstallModule
|
|||
}
|
||||
}
|
||||
|
||||
// Make sure the class selection is valid
|
||||
$class = isset($_POST['class']) ? $_POST['class'] : 1;
|
||||
// Make sure the class selection is present
|
||||
$class = $_POST['class'] ?? 1;
|
||||
|
||||
// If we have any errors, bail to the form and let the user know
|
||||
if (!empty($errors)) {
|
||||
|
@ -267,9 +276,6 @@ class InstallModule
|
|||
exit;
|
||||
}
|
||||
|
||||
// Create the .installed file in the server folder
|
||||
file_put_contents(SERVER.'/.installed', 'Installed on '.date('Y-m-d H:i:s'));
|
||||
|
||||
// Create the admin account
|
||||
Player::create([
|
||||
'username' => trim($_POST['username']),
|
||||
|
@ -283,6 +289,9 @@ class InstallModule
|
|||
|
||||
// Render the finished page!
|
||||
echo render('install/layout', ['title' => 'Finished!', 'step' => 'done', 'name' => $_POST['username'], 'complete' => $_POST['complete'] ?? false]);
|
||||
|
||||
// Create the .installed file in the server folder
|
||||
file_put_contents(SERVER.'/.installed', 'Installed on '.date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
private static function fourOhFour()
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
<div class="form-group">
|
||||
<label for="level">Level</label>
|
||||
<input type="number" name="level" id="level" min="1" placeholder="1" required>
|
||||
<input type="number" name="level" id="level" min="1" placeholder="1" value="1" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="submit">Submit</button>
|
||||
|
|
Loading…
Reference in New Issue
Block a user