From 08c290ea4f4346719d96f8f751748e23428f91ee Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Fri, 12 Jul 2024 23:24:59 -0500 Subject: [PATCH] Extract Default data, continue work on installer --- server/app/database.php | 50 +++++-- server/database/README.md | 7 +- server/database/packs/Default.zip | Bin 4542 -> 0 bytes server/database/packs/Default/classes.csv | 4 + server/database/packs/Default/drops.csv | 42 ++++++ server/database/packs/Default/items.csv | 35 +++++ server/database/packs/Default/monsters.csv | 152 +++++++++++++++++++++ server/database/packs/Default/spells.csv | 21 +++ server/database/packs/Default/towns.csv | 9 ++ server/modules/InstallModule.php | 56 ++++---- 10 files changed, 340 insertions(+), 36 deletions(-) delete mode 100644 server/database/packs/Default.zip create mode 100644 server/database/packs/Default/classes.csv create mode 100644 server/database/packs/Default/drops.csv create mode 100644 server/database/packs/Default/items.csv create mode 100644 server/database/packs/Default/monsters.csv create mode 100644 server/database/packs/Default/spells.csv create mode 100644 server/database/packs/Default/towns.csv diff --git a/server/app/database.php b/server/app/database.php index c63ce28..c70eafa 100644 --- a/server/app/database.php +++ b/server/app/database.php @@ -12,7 +12,6 @@ class Database private PDO $c; private int $queries = 0; private array $log = []; - private string $error = ''; private float $time = 0; public function __construct(string $path, array $opts = []) @@ -27,7 +26,6 @@ class Database $this->c->exec('PRAGMA foreign_keys = ON;'); // Enable foreign keys $this->c->exec('PRAGMA journal_mode = WAL;'); // Enable WAL } catch (PDOException $e) { - $this->error = "Failed to open database: " . $e->getMessage(); throw $e; } } @@ -42,8 +40,8 @@ class Database $this->record($query, $start); return $stmt; } catch (PDOException $e) { - $this->error = $e->getMessage(); - return false; + print_r($query); + throw $e; } } @@ -56,8 +54,8 @@ class Database $this->record($query, $start); return $stmt; } catch (PDOException $e) { - $this->error = $e->getMessage(); - return false; + print_r($query); + throw $e; } } @@ -69,11 +67,6 @@ class Database $this->time += $time; } - public function error(): string - { - return $this->error; - } - public function queries(): int { return $this->queries; @@ -88,4 +81,39 @@ class Database { return $this->time; } + + public function insertFromCSV(string $table, string $path): PDOStatement|false + { + // open the file + $handle = fopen($path, 'r'); + if ($handle === false) return false; + + // reduce the column names to lower case with underscores + $columns = array_map(function ($column) { + return strtolower(str_replace(' ', '_', $column)); + }, fgetcsv($handle)); + + // set up the query + $query = "INSERT INTO $table (" . implode(',', $columns) . ') VALUES '; + + // read the rows and add them to the query + while (($row = fgetcsv($handle)) !== false) { + // go through the row and put strings into single quotes + $row = array_map(function ($column) { + if (is_numeric($column)) return $column; + return "'" . str_replace("'", "\'", $column) . "'"; + }, $row); + + // add the row to the query + $query .= '(' . implode(',', $row) . '),'; + } + + // remove the trailing comma + $query = rtrim($query, ',') . ';'; + + dd($query); + + // execute the insert + return $this->q($query); + } } diff --git a/server/database/README.md b/server/database/README.md index 93b603f..b6b385a 100644 --- a/server/database/README.md +++ b/server/database/README.md @@ -4,7 +4,10 @@ This folder serves as the home for the game's database; `dragon.db` by default. ### Packs New to Dragon Knight is the ability to upload "data packs" to the game! Using this feature, it is possible to upload and store `.zip` files that contain `.csv` files (spreadsheets) of data for the game. These spreadsheets must have a 1:1 structure to what's expected in Dragon Knight. This allows an admin to populate the game data quickly and easily with data they either make or get from someone else. -The `Default.zip` data pack is the default data used when doing a **Complete** install of Dragon Knight. You can edit this before running the installer to change the default data. You can also use it as a template for your own data packs! +The `Default` data pack is the default data used when doing a **Complete** install of Dragon Knight. You can edit this before running the installer to change the default data. You can also use it as a template for your own data packs! + +#### Installing +@TODO ### Installation -When performing a **Complete** install, the installer will look for and use the `Default.zip` data pack if it exists. If not, the installer will error. When performing a **Partial** install, the installer itself will insert the bare minimum data needed (at the moment this is a single class, "Adventurer") to create a user account, and data can be added in the admin panel afterwards. \ No newline at end of file +When performing a **Complete** install, the installer will look for and use the `Default` data pack if it exists. If not, the installer will error. When performing a **Partial** install, the installer itself will insert the bare minimum data needed (at the moment this is a single class, "Adventurer") to create a user account, and data can be added in the admin panel afterwards. \ No newline at end of file diff --git a/server/database/packs/Default.zip b/server/database/packs/Default.zip deleted file mode 100644 index 81c6c0f8c079e7642020da4ea90e1c020c0f3411..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4542 zcmZ{ocQjmE1H~tL3&H3THA*mA7(|O+V~7?(5TlGXdY1?xdhcD7QKO3*j54A`8$F_z z=q75A&wFpJm;CX*d;d81uDgC~?RC#SXYG9;>ex6y02Y7%z+Am!=#UXq5eEPO=xzZ3 z#5dzhdvjM;s4M8DtA}Rf08y8~9mUggqJAIhEQI1bVY@7A576zA*@#>n1@?7&SX!@( zFtW)~OxedUmLrxd!JiF(;?=|5l7mtyps7;>Tf4%-`8DOWJ z%a>RaOl(*P-q2Vvo3~{L*>$`HS|7D~&@J^I^N|ORR7P zr09qUU(|h8KLX%aLq(bP)q`6#vP)4?8^ddBUS~mYF3$sELvJGvF0fIVR!_94S$!xb z?Xh;{P%&+>iwRXWV?B^sH+w>p8GojYX1x(#)86}OQC>;D9?tVc#hH*05f493?A;?w zlgzg~Ucl)sMm0)!PDdO&78yCCs?b5~l4{)J@D^|P9fAn!W4LpuVym?RgCCRg!W9ao zY{PMJm9tL68Zu&MyWoqJPts#ttIuJs_DW~RVZI5h71%POi(^%E(NuD67{p()`c{DY z;iXLaT@eG{ccNBSh-XtJn+&9jEc9!oQM9k=&}GK)JqU(G%W&+h6=r8o$Qw4o_=M)~ zf=!0o_OlaKWh&Mf_LlYKMWz58#iG$CDm-_B+#^~n;}Hfr`9YO90oMBF6H(? zC)=ZY8v^1f&vzp{Myt*g!p`x3BHGT-ueM*mLmS{>A|FjQIAfQUx}OTY*ue<$b0fdmT6z%x0q$aNMn|~mHpkerw3G#`gXYA9&k%TA>S({9w%e1T;PZY z_2aZh=Ce2#e?%A=dbdLmjXDm?JG$%Qt8$4Q$o+6ii zD(CRJFL9>>&CRXJhPQn#?u|m})atv3E1Q4w9@qON>g_={VIkl$VNu*%g#HEY7X|hF z5HsS~bAhzREu(Oy#5Fghinsjp$A!wut-Fd=51vjSK)oMZ0s1RWs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W8Vuz99CXv( z*%}-f(_pV2hItq*_0-Dc*5c%0YFA1hP>QK{WjPP+h3@lrt#sZy-dB39>cV>tgIOmAL%r3g*1=L*uP;j# zH>#5Ck$W$vL=1(t=z@3Z`oloVfofz{Wc=vQ^c2^5iH8|tZH*X4MV45;xASpsT~IFV zAUeit@jKJzVo0mzh%1kaAp<1uot_2}xVB5|f!2+i)`yn=;bXK@_~^Cx0U^eCb`n1W~_*C4>F{PZn-| z=-*de;9tWZ=L~;>|5fb&!2p1|z~-CBe{24q*nf4u-`McYeE!=6|HS?)yZ^=%Z%X8! uN&Zjrzt-(+OGXI7G<+ diff --git a/server/database/packs/Default/classes.csv b/server/database/packs/Default/classes.csv new file mode 100644 index 0000000..a0cefdb --- /dev/null +++ b/server/database/packs/Default/classes.csv @@ -0,0 +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" diff --git a/server/database/packs/Default/drops.csv b/server/database/packs/Default/drops.csv new file mode 100644 index 0000000..a82e4b6 --- /dev/null +++ b/server/database/packs/Default/drops.csv @@ -0,0 +1,42 @@ +Name,Level,Type,Attr +"Life Pebble",1,1,"hp,10" +"Life Stone",10,1,"hp,25" +"Life Rock",25,1,"hp,50" +"Life Ore",50,1,"hp,100" +"Life Gem",75,1,"hp,150" +"Magic Pebble",1,1,"mp,10" +"Magic Stone",10,1,"mp,25" +"Magic Rock",25,1,"mp,50" +"Magic Ore",50,1,"mp,100" +"Magic Gem",75,1,"mp,150" +"Dragon's Scale",10,1,"def,25" +"Dragon's Plate",30,1,"def,50" +"Dragon's Claw",10,1,"atk,25" +"Dragon's Fang",30,1,"atk,50" +"Dragon's Tear",35,1,"str,75" +"Dragon's Wing",35,1,"dex,75" +"Demon's Sin",35,1,"hp,-50|str,65" +"Demon's Fall",35,1,"mp,-50|str,65" +"Demon's Lie",45,1,"hp,-100|str,125" +"Demon's Hate",45,1,"mp,-100|str,125" +"Angel's Joy",25,1,"hp,25|str,25" +"Angel's Rise",30,1,"hp,50|str,50" +"Angel's Truth",35,1,"hp,75|str,75" +"Angel's Grace",40,1,"hp,100|str,100" +"Seraph's Strength",25,1,"mp,25|dex,25" +"Seraph's Power",30,1,"mp,50|dex,50" +"Seraph's Justice",35,1,"mp,75|dex,75" +"Seraph's Judgement",40,1,"mp,100|dex,100" +Ruby,50,1,"hp,150" +Sapphire,50,1,"mp,150" +Emerald,50,1,"str,150" +Amethyst,50,1,"dex,150" +Topaz,50,1,"atk,150" +Diamond,50,1,"def,150" +"Ocean Blessing",77,1,"str,7007|dex,7007" +"Memory Tonic",5,1,"exp,10" +"Memory Potion",30,1,"exp,20" +"Memory Elixir",50,1,"exp,30" +"Gold Tonic",5,1,"gold,10" +"Gold Potion",30,1,"gold,20" +"Gold Elixir",50,1,"gold,30" diff --git a/server/database/packs/Default/items.csv b/server/database/packs/Default/items.csv new file mode 100644 index 0000000..1820c3e --- /dev/null +++ b/server/database/packs/Default/items.csv @@ -0,0 +1,35 @@ +Type,Name,Cost,Attr,Icon +1,Stick,10,"atk,2",stick.png +1,Branch,30,"atk,4",branch.png +1,Club,40,"atk,6",club.png +1,Dagger,80,"atk,8",dagger.png +1,Hatchet,120,"atk,12",hatchet.png +1,Axe,200,"atk,18",axe.png +1,Spear,300,"atk,25",spear.png +1,Poleaxe,500,"atk,35",poleaxe.png +1,Warhammer,800,"atk,50",warhammer.png +1,Longsword,1200,"atk,65",longsword.png +1,Claymore,1800,"atk,85",claymore.png +1,"Demon Axe",2800,"atk,125|exp,-5",demonaxe.png +1,"Dark Sword",4500,"atk,225|exp,-10",darksword.png +1,"Magic Axe",2800,"atk,95|exp,5",magicaxe.png +1,"Bright Sword",4500,"atk,185|exp,10",brightsword.png +1,Dragonbane,10000,"atk,300|str,50",dragonbane.png +2,Underwear,25,"def,2|gold,10",underwear.png +2,Clothes,50,"def,5",clothes.png +2,Leather,75,"def,10",leather.png +2,"Hard Leather",150,"def,25",hardleather.png +2,Chainmail,300,"def,35",chainmail.png +2,"Scale Armor",900,"def,50",scalearmor.png +2,Platemail,1800,"def,100",platemail.png +2,"Magic Plate",3000,"def,125|mp,50",magicplate.png +2,Darkmail,5000,"def,200|exp,-10",darkmail.png +2,"Dragon Plate",10000,"def,165|exp,10",dragonplate.png +2,"Destiny Raiment",50000,"def,200|dex,50",destinyraiment.png +3,"Reed Shield",50,"def,5",reedshield.png +3,Buckler,100,"def,10",nuckler.png +3,"Round Shield",500,"def,25",roundshield.png +3,"Tower Shield",2500,"def,50",towershield.png +3,"Silver Shield",10000,"def,100",silvershield.png +3,"Dragon Shield",25000,"def,125|mp,100",dragonshield.png +3,Aegis,50000,"def,225|exp,10",aegis.png diff --git a/server/database/packs/Default/monsters.csv b/server/database/packs/Default/monsters.csv new file mode 100644 index 0000000..25ebbe2 --- /dev/null +++ b/server/database/packs/Default/monsters.csv @@ -0,0 +1,152 @@ +Name,Level,HP,ATK,DEF,EXP,Gold,Immune +"Blue Slime",1,4,3,1,1,1,0 +"Red Slime",1,6,5,1,2,1,0 +Critter,1,6,5,2,4,2,0 +Creature,2,10,8,2,4,2,0 +Shadow,2,10,9,3,6,2,1 +Drake,2,11,10,3,8,3,0 +Shade,3,12,10,3,10,3,1 +Drakelor,3,14,12,4,10,3,0 +"Silver Slime",30,15,100,200,15,1000,2 +Scamp,4,16,13,5,15,5,0 +Raven,4,16,13,5,18,6,0 +Scorpion,5,18,14,6,20,7,0 +Illusion,5,20,15,6,20,7,1 +Nightshade,6,22,16,6,24,8,0 +Drakemal,6,22,18,7,24,8,0 +"Shadow Raven",6,24,18,7,26,9,1 +Ghost,6,24,20,8,28,9,0 +"Frost Raven",7,26,20,8,30,10,0 +"Rogue Scorpion",7,28,22,9,32,11,0 +Ghoul,7,29,24,9,34,11,0 +Magician,8,30,24,10,36,12,0 +Rogue,8,30,25,12,40,13,0 +Drakefin,8,32,26,12,40,13,0 +Shimmer,8,32,26,14,45,15,1 +"Fire Raven",9,34,28,14,45,15,0 +Dybbuk,9,34,28,14,50,17,0 +Knave,9,36,30,15,52,17,0 +Goblin,10,36,30,15,54,18,0 +Skeleton,10,38,30,18,58,19,0 +"Dark Slime",10,38,32,18,62,21,0 +"Silver Scorpion",40,30,160,350,63,2000,2 +Mirage,11,40,32,20,64,21,1 +Sorceror,11,41,33,22,68,23,0 +Imp,12,42,34,22,70,23,0 +Nymph,12,43,35,22,70,23,0 +Scoundrel,12,43,35,22,75,25,0 +Megaskeleton,13,44,36,24,78,26,0 +"Grey Wolf",13,44,36,24,82,27,0 +Phantom,14,46,38,24,85,28,1 +Specter,14,46,38,24,90,30,0 +"Dark Scorpion",15,48,40,26,95,32,1 +Warlock,15,48,40,26,100,33,1 +Orc,15,49,42,28,104,35,0 +Sylph,15,49,42,28,106,35,0 +Wraith,16,50,45,30,108,36,0 +Hellion,16,50,45,30,110,37,0 +Bandit,16,52,45,30,114,38,0 +Ultraskeleton,16,52,46,32,116,39,0 +"Dark Wolf",17,54,47,36,120,40,1 +Troll,17,56,48,36,120,40,0 +Werewolf,17,56,48,38,124,41,0 +Hellcat,18,58,50,38,128,43,0 +Spirit,18,58,50,38,132,44,0 +Nisse,19,60,52,40,132,44,0 +Dawk,19,60,54,40,136,45,0 +Figment,19,64,55,42,140,47,1 +Hellhound,20,66,56,44,140,47,0 +Wizard,20,66,56,44,144,48,0 +Uruk,20,68,58,44,146,49,0 +Siren,50,68,400,800,10000,50,2 +Megawraith,21,70,60,46,155,52,0 +Dawkin,21,70,60,46,155,52,0 +"Grey Bear",21,70,62,48,160,53,0 +Haunt,22,72,62,48,160,53,0 +Hellbeast,22,74,64,50,165,55,0 +Fear,23,76,66,52,165,55,0 +Beast,23,76,66,52,170,57,0 +Ogre,23,78,68,54,170,57,0 +"Dark Bear",24,80,70,56,175,58,1 +Fire,24,80,72,56,175,58,0 +Polgergeist,25,84,74,58,180,60,0 +Fright,25,86,76,58,180,60,0 +Lycan,25,88,78,60,185,62,0 +"Terra Elemental",25,88,80,62,185,62,1 +Necromancer,26,90,80,62,190,63,0 +Ultrawraith,26,90,82,64,190,63,0 +Dawkor,26,92,82,64,195,65,0 +Werebear,26,92,84,65,195,65,0 +Brute,27,94,84,65,200,67,0 +"Large Beast",27,96,88,66,200,67,0 +Horror,27,96,88,68,210,70,0 +Flame,28,100,90,70,210,70,0 +Lycanthor,28,100,90,70,210,70,0 +Wyrm,28,100,92,72,220,73,0 +"Aero Elemental",29,104,94,74,220,73,1 +Dawkare,29,106,96,76,220,73,0 +"Large Brute",29,108,98,78,230,77,0 +"Frost Wyrm",30,110,100,80,230,77,0 +Knight,30,110,102,80,240,80,0 +Lycanthra,30,112,104,82,240,80,0 +Terror,31,115,108,84,250,83,0 +Blaze,31,118,108,84,250,83,0 +"Aqua Elemental",31,120,110,90,260,87,1 +"Fire Wyrm",32,120,110,90,260,87,0 +"Lesser Wyvern",32,122,110,92,270,90,0 +Doomer,32,124,112,92,270,90,0 +"Armor Knight",33,130,115,95,280,93,0 +Wyvern,33,134,120,95,290,97,0 +Nightmare,33,138,125,100,300,100,0 +"Fira Elemental",34,140,125,100,310,103,1 +Megadoomer,34,140,128,105,320,107,0 +"Greater Wyvern",34,145,130,105,335,112,0 +Advocate,35,148,132,108,350,117,0 +"Strong Knight",35,150,135,110,365,122,0 +Liche,35,150,135,110,380,127,0 +Ultradoomer,36,155,140,115,395,132,0 +Fanatic,36,160,140,115,410,137,0 +"Green Dragon",36,160,140,115,425,142,0 +Fiend,37,160,145,120,445,148,0 +"Greatest Wyvern",37,162,150,120,465,155,0 +"Lesser Devil",37,164,150,120,485,162,0 +"Liche Master",38,168,155,125,505,168,0 +Zealot,38,168,155,125,530,177,0 +Serafiend,38,170,155,125,555,185,0 +"Pale Knight",39,175,160,130,580,193,0 +"Blue Dragon",39,180,160,130,605,202,0 +Obsessive,40,180,160,135,630,210,0 +Devil,40,184,164,135,666,222,0 +"Liche Prince",40,190,168,138,660,220,0 +Cherufiend,41,195,170,140,690,230,0 +"Red Dragon",41,200,180,145,720,240,0 +"Greater Devil",41,200,180,145,750,250,0 +Renegade,42,205,185,150,780,260,0 +Archfiend,42,210,190,150,810,270,0 +"Liche Lord",42,210,190,155,850,283,0 +"Greatest Devil",43,215,195,160,890,297,0 +"Dark Knight",43,220,200,160,930,310,0 +Giant,43,220,200,165,970,323,0 +"Shadow Dragon",44,225,200,170,1010,337,0 +"Liche King",44,225,205,170,1050,350,0 +Incubus,44,230,205,175,1100,367,1 +Traitor,45,230,205,175,1150,383,0 +Demon,45,240,210,180,1200,400,0 +"Dark Dragon",45,245,215,180,1250,417,1 +Insurgent,46,250,220,190,1300,433,0 +Leviathan,46,255,225,190,1350,450,0 +"Grey Daemon",46,260,230,190,1400,467,0 +Succubus,47,265,240,200,1460,487,1 +"Demon Prince",47,270,240,200,1520,507,0 +"Black Dragon",47,275,250,205,1580,527,1 +Nihilist,47,280,250,205,1640,547,0 +Behemoth,48,285,260,210,1700,567,0 +Demagogue,48,290,260,210,1760,587,0 +"Demon Lord",48,300,270,220,1820,607,0 +"Red Daemon",48,310,280,230,1880,627,0 +Colossus,49,320,300,240,1940,647,0 +"Demon King",49,330,300,250,2000,667,0 +"Dark Daemon",49,340,320,260,2200,733,1 +Titan,50,360,340,270,2400,800,0 +"Black Daemon",50,400,400,280,3000,1000,1 +Lucifuge,50,600,600,400,10000,10000,2 diff --git a/server/database/packs/Default/spells.csv b/server/database/packs/Default/spells.csv new file mode 100644 index 0000000..bb9da3c --- /dev/null +++ b/server/database/packs/Default/spells.csv @@ -0,0 +1,21 @@ +Name,Type,MP,Effect,Icon +Heal,1,5,"heal:self,10",heal.png +Cure,1,10,"heal:self,25",cure.png +Breath,1,25,"heal:self,50",breath.png +Revive,1,50,"heal:self,100",revive.png +Gaia,1,75,"heal:self,150",gaia.png +Slash,2,5,"damage:opp,10",slash.png +"Magic Missile",2,12,"damage:opp,35",missile.png +Fireball,2,25,"damage:opp,70",fireball.png +Pain,2,40,"damage:opp,100",pain.png +Lightning,2,50,"damage:opp,130",lightning.png +Chaos,2,75,"damage:opp,200",chaos.png +Sleep,3,10,"sleep:opp,3",sleep.png +Dream,3,30,"sleep:opp,6",dream.png +Nightmare,3,60,"sleep:opp,13",nightmare.png +Craze,4,10,"rage:self,3",craze.png +Rage,4,30,"rage:self,6",rage.png +Fury,4,60,"rage:self,13",fury.png +Ward,5,10,"protect:self,3",ward.png +Guard,5,30,"protect:self,6",guard.png +Barrier,5,60,"protect:self,13",barrier.png diff --git a/server/database/packs/Default/towns.csv b/server/database/packs/Default/towns.csv new file mode 100644 index 0000000..b9b578d --- /dev/null +++ b/server/database/packs/Default/towns.csv @@ -0,0 +1,9 @@ +Name,X,Y,"Inn Cost","Map Cost","TP Cost","Shop List",Image +Midworld,0,0,5,5,0,"1,2,3,17,18,19,28,29",midworld.png +Roma,30,30,10,25,5,"2,3,4,18,19,29",roma.png +Bris,70,-70,25,50,15,"2,3,4,5,18,19,20,29,30",bris.png +Kalle,-100,100,40,100,30,"5,6,8,10,12,21,22,23,29,30",kalle.png +Narcissa,-130,-130,60,500,50,"4,7,9,11,13,21,22,23,29,30,31",narcissa.png +Hambry,170,170,90,1000,80,"10,11,12,13,14,23,24,30,31",hambry.png +Gilead,200,-200,100,3000,110,"12,13,14,15,24,25,26,32",gilead.png +Endworld,-250,-250,150,9000,160,"16,27,33",endworld.png diff --git a/server/modules/InstallModule.php b/server/modules/InstallModule.php index b8fa2d6..a5a05d2 100644 --- a/server/modules/InstallModule.php +++ b/server/modules/InstallModule.php @@ -26,11 +26,12 @@ class InstallModule if (!isset($_POST['mode'])) redirect('/install'); // redirect if no mode $complete = $_POST['mode'] == 'complete'; // complete or partial setup $resFmt = '%s (%ss)
'; + $defaults = SERVER.'/database/packs/Default/'; $results = ''; // @Settings - App::$db->q("CREATE TABLE IF NOT EXISTS settings ( + App::$db->q("CREATE TABLE IF NOT EXISTS 'settings' ( id INTEGER PRIMARY KEY, game_name TEXT DEFAULT 'Dragon Knight', game_version TEXT DEFAULT '1.0', @@ -55,32 +56,29 @@ class InstallModule $results .= sprintf($resFmt, 'Default settings inserted', stopwatch($istart)); // @Classes - App::$db->q("CREATE TABLE IF NOT EXISTS classes ( - id INTEGER PRIMARY KEY, - name TEXT DEFAULT '', - start_hp INT DEFAULT 0, - start_mp INT DEFAULT 0, - start_str INT DEFAULT 0, - start_atk INT DEFAULT 0, - start_dex INT DEFAULT 0, - start_def INT DEFAULT 0, - growth_hp INT DEFAULT 0, - growth_mp INT DEFAULT 0, - growth_str INT DEFAULT 0, - growth_atk INT DEFAULT 0, - growth_dex INT DEFAULT 0, - growth_def INT DEFAULT 0, - spells TEXT DEFAULT '', + App::$db->q("CREATE TABLE IF NOT EXISTS 'classes' ( + 'id' INTEGER PRIMARY KEY, + 'name' TEXT DEFAULT '', + 'start_hp' INT DEFAULT 0, + 'start_mp' INT DEFAULT 0, + 'start_str' INT DEFAULT 0, + 'start_atk' INT DEFAULT 0, + 'start_dex' INT DEFAULT 0, + 'start_def' INT DEFAULT 0, + 'growth_hp' INT DEFAULT 0, + 'growth_mp' INT DEFAULT 0, + 'growth_str' INT DEFAULT 0, + 'growth_atk' INT DEFAULT 0, + 'growth_dex' INT DEFAULT 0, + 'growth_def' INT DEFAULT 0, + 'spells' TEXT DEFAULT '' );"); $results .= sprintf($resFmt, 'Classes table created', stopwatch($istart)); if ($complete) { // add default classes if complete install - App::$db->q("INSERT INTO classes VALUES - (1, 'Mage', 10, 10, 5, 5, 5, 5, 3, 5, 1, 3, 1, 3, '1:6,18'), - (2, 'Warrior', 20, 0, 10, 5, 10, 5, 6, 2, 3, 1, 3, 1, ''), - (3, 'Paladin', 15, 5, 5, 5, 10, 10, 4, 4, 2, 2, 2, 2, '1:1,15,18');"); + App::$db->insertFromCSV('classes', "$defaults/classes.csv"); } else { // there must be at least one class, for user creation to work App::$db->q("INSERT INTO classes (name) VALUES ('Adventurer');"); @@ -89,7 +87,7 @@ class InstallModule $results .= sprintf($resFmt, 'Default classes inserted', stopwatch($istart)); // @Babble - App::$db->q("CREATE TABLE IF NOT EXISTS babble ( + App::$db->q("CREATE TABLE IF NOT EXISTS 'babble' ( id INTEGER PRIMARY KEY, author INTEGER NOT NULL, babble TEXT NOT NULL, @@ -99,12 +97,24 @@ class InstallModule $results .= sprintf($resFmt, 'Babble table created', stopwatch($istart)); // @Drops - App::$db->q("CREATE TABLE IF NOT EXISTS drops ( + App::$db->q("CREATE TABLE IF NOT EXISTS 'drops' ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, level INTEGER DEFAULT 1, type INTEGER DEFAULT 1, attr TEXT DEFAULT '' );"); + + + $results .= sprintf($resFmt, 'Drops table created', stopwatch($istart)); + + if ($complete) { + // add default drops if complete install + App::$db->insertFromCSV('drops', "$defaults/drops.csv"); + + $results .= sprintf($resFmt, 'Default drops inserted', stopwatch($istart)); + } + + echo $results; } } \ No newline at end of file