Initial commit

This commit is contained in:
Joey Kimsey
2024-08-04 21:15:59 -04:00
parent c9d1fb983f
commit 0d469501ee
695 changed files with 70184 additions and 71 deletions

View File

@ -0,0 +1,213 @@
<?php
/**
* app/plugins/dnd/models/races.php
*
* This class is used for the manipulation of the dnd_races database table.
*
* @package TTE Dungeons & Dragons
* @version 3.0
* @author Joey Kimsey <Joey@tabletopelite.com>
* @link https://TableTopElite.com
*/
namespace TheTempusProject\Models;
use TheTempusProject\Canary\Canary as Debug;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Bedrock\Classes\CustomException;
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
class Races extends DatabaseModel {
protected static $sourcebooks;
public $tableName = 'dnd_races';
public $databaseMatrix = [
// Name
[ 'name', 'varchar', '32' ],
[ 'languages', 'varchar', '32' ],
[ 'racial_traits', 'varchar', '32' ],
[ 'size', 'varchar', '16' ],
[ 'age', 'text', '' ],
[ 'raceID', 'int', '11' ],
[ 'suggested_classes', 'text', '' ],
[ 'abilityScores', 'text', '' ], // json
// General
[ 'createdBy', 'int', '11' ],
[ 'createdAt', 'int', '11' ],
[ 'privacy', 'varchar', '16' ],
[ 'version', 'varchar', '5' ],
[ 'sourcebookID', 'int', '11' ],
[ 'description', 'text', '' ],
[ 'shortDescription', 'text', '' ],
[ 'image', 'text', '' ],
[ 'avatar', 'text', '' ],
// Speeds
[ 'walking_speed', 'int', '4' ],
[ 'climbing_speed', 'int', '4' ],
[ 'swimming_speed', 'int', '4' ],
[ 'burrowing_speed', 'int', '4' ],
[ 'flying_speed', 'int', '4' ],
];
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
self::$sourcebooks = new SourcebooksModel;
}
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
$fields = [
'name' => $name,
'privacy' => $privacy,
'version' => $version,
'sourcebookID' => $sourcebookID,
'description' => $description,
'shortDescription' => $shortDescription,
'createdBy' => App::$activeUser->ID,
'createdAt' => time(),
];
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
new CustomException( 'Create' );
Debug::error( "Race: not created " . var_export($fields,true) );
return false;
}
return self::$db->lastId();
}
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
$fields = [
'name' => $name,
'privacy' => $privacy,
'version' => $version,
'sourcebookID' => $sourcebookID,
'description' => $description,
'shortDescription' => $shortDescription,
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'Update' );
Debug::error( "Race: $id not updated: $fields" );
return false;
}
return true;
}
public function byUser( $limit = null ) {
$whereClause = ['createdBy', '=', App::$activeUser->ID];
if ( empty( $limit ) ) {
$objects = self::$db->get( $this->tableName, $whereClause );
} else {
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
}
if ( !$objects->count() ) {
Debug::info( 'No Races found.' );
return false;
}
return $this->filter( $objects->results() );
}
public function filter( $data, $params = [] ) {
$out = [];
foreach ( $data as $instance ) {
if ( !is_object( $instance ) ) {
$instance = $data;
$end = true;
}
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
if ( !empty( $sourcebook ) ) {
$instance->sourcebookName = $sourcebook->name;
} else {
$instance->sourcebookName = 'Unknown';
}
$out[] = $instance;
if ( !empty( $end ) ) {
$out = $out[0];
break;
}
}
return $out;
}
}
// Master list with origins 2:
// Aarakocra - Elemental Evil Player's Companion, Monsters of the Multiverse
// Aasimar - Volo's Guide to Monsters, Monsters of the Multiverse
// Autognome - Spelljammer: Adventures in Space
// Bugbear - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
// Centaur - Guildmasters Guide to Ravnica, Mythic Odysseys of Theros, Monsters of the Multiverse
// Cervan - Humblewood Campaign Setting
// Changeling - Eberron: Rising from the Last War, Monsters of the Multiverse
// Corvum - Humblewood Campaign Setting
// Dhampir - Van Richten's Guide to Ravenloft
// The Disembodied - Grim Hollow: Player Pack
// Fairy - The Wild Beyond the Witchlight, Monsters of the Multiverse
// Firbolg - Volo's Guide to Monsters, Monsters of the Multiverse
// Gallus - Humblewood Campaign Setting
// Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
// Giff - Spelljammer: Adventures in Space
// Gith - Mordenkainens Tome of Foes, Monsters of the Multiverse (Githyanki, Githzerai)
// Goblin - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
// Goliath - Elemental Evil Player's Companion, Volo's Guide to Monsters, Monsters of the Multiverse
// Grung - One Grung Above
// Hadozee - Spelljammer: Adventures in Space
// Harengon - The Wild Beyond the Witchlight, Monsters of the Multiverse
// Hedge - Humblewood Campaign Setting
// Hexblood - Van Richten's Guide to Ravenloft
// Hobgoblin - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
// Jerbeen - Humblewood Campaign Setting
// Kalashtar - Eberron: Rising from the Last War
// Kender - Dragonlance: Shadow of the Dragon Queen
// Kenku - Volo's Guide to Monsters, Monsters of the Multiverse
// Kobold - Volo's Guide to Monsters, Monsters of the Multiverse
// Leonin - Mythic Odysseys of Theros
// Lizardfolk - Volo's Guide to Monsters, Monsters of the Multiverse
// Locathah - Locathah Rising
// Loxodon - Guildmasters Guide to Ravnica
// Luma - Humblewood Campaign Setting
// Mapach - Humblewood Campaign Setting
// Minotaur - Guildmasters Guide to Ravnica, Mythic Odysseys of Theros, Monsters of the Multiverse
// Orc - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
// Owlin - Strixhaven: Curriculum of Chaos
// Plasmoid - Spelljammer: Adventures in Space
// Raptor - Humblewood Campaign Setting
// Reborn - Van Richten's Guide to Ravenloft
// Satyr - Mythic Odysseys of Theros, Monsters of the Multiverse
// Shadar-kai - Mordenkainens Tome of Foes, Monsters of the Multiverse
// Shifter - Eberron: Rising from the Last War, Monsters of the Multiverse
// Simic Hybrid - Guildmasters Guide to Ravnica
// Strig - Humblewood Campaign Setting
// Tabaxi - Volo's Guide to Monsters, Monsters of the Multiverse
// Thri-kreen - Spelljammer: Adventures in Space, Monsters of the Multiverse
// Tortle - The Tortle Package, Monsters of the Multiverse
// Triton - Mythic Odysseys of Theros, Monsters of the Multiverse
// Vedalken - Guildmasters Guide to Ravnica
// Verdan - Acquisitions Incorporated
// Vulpin - Humblewood Campaign Setting
// Warforged - Eberron: Rising from the Last War
// Wechselkind - Grim Hollow: Player Pack
// Yuan-ti Pureblood - Volo's Guide to Monsters, Monsters of the Multiverse
// Custom Lineage - Tasha's Cauldron of Everything
// Deep Gnome - Elemental Evil Player's Companion, Mordenkainens Tome of Foes, Monsters of the Multiverse
// Duergar - Mordenkainens Tome of Foes, Monsters of the Multiverse
// Eladrin - Mordenkainens Tome of Foes, Monsters of the Multiverse
// Air Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
// Earth Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
// Fire Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
// Water Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
// Astral Elf - Spelljammer: Adventures in Space
// Sea Elf - Mordenkainens Tome of Foes, Monsters of the Multiverse
// Githyanki - Mordenkainens Tome of Foes, Monsters of the Multiverse
// Githzerai - Mordenkainens Tome of Foes, Monsters of the Multiverse