stuffAndThings

This commit is contained in:
Kim Ravn Hansen
2025-09-09 12:55:50 +02:00
parent c8c7259574
commit 5d0cc61cf9
23 changed files with 823 additions and 358 deletions

View File

@@ -0,0 +1,15 @@
// ____ _ _
// / ___| |__ __ _ _ __ __ _ ___| |_ ___ _ __
// | | | '_ \ / _` | '__/ _` |/ __| __/ _ \ '__|
// | |___| | | | (_| | | | (_| | (__| || __/ |
// \____|_| |_|\__,_|_| \__,_|\___|\__\___|_|
//
// ____ _
// / ___| ___ ___ __| | ___ _ __
// \___ \ / _ \/ _ \/ _` |/ _ \ '__|
// ___) | __/ __/ (_| | __/ |
// |____/ \___|\___|\__,_|\___|_|
//
export class CharacterSeeder {
}

View File

@@ -0,0 +1,36 @@
import { Game } from "../models/game.js";
import { ItemSeeder } from "./itemSeeder.js";
import { PlayerSeeder } from "./playerSeeder.js";
/**
* Create and populate a Game object.
*
* This seeder creates all models necessary to play the game.
*
* If dev mode, we create some known debug logins. (username = user, password = pass) as well as a few others
*/
export class GameSeeder {
/** @returns {Game} */
createGame() {
/** @type {Game} */
this.game = new Game();
this.work(); // Seeding may take a bit, so let's defer it so we can return early.
return this.game;
}
work() {
console.info("seeding...");
//
(new PlayerSeeder(this.game)).seed(); // Create debug players
(new ItemSeeder(this.game)).seed(); // Create items, etc.
//
// Done
console.info("seeding done");
}
}

71
server/seeders/itemSeeder.js Executable file
View File

@@ -0,0 +1,71 @@
import { Game } from "../models/game.js";
import { ItemTemplate } from "../models/item.js";
//
// ___ _ _____ _ _
// |_ _| |_ ___ _ __ ___ |_ _|__ _ __ ___ _ __ | | __ _| |_ ___ ___
// | || __/ _ \ '_ ` _ \ | |/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \/ __|
// | || || __/ | | | | | | | __/ | | | | | |_) | | (_| | || __/\__ \
// |___|\__\___|_| |_| |_| |_|\___|_| |_| |_| .__/|_|\__,_|\__\___||___/
// |_|
//
// Seed the Game.itemTemplate store
export class ItemSeeder {
/** @param {Game} game */
constructor(game) {
this.game = game;
}
seed() {
// __ __
// \ \ / /__ __ _ _ __ ___ _ __ ___
// \ \ /\ / / _ \/ _` | '_ \ / _ \| '_ \/ __|
// \ V V / __/ (_| | |_) | (_) | | | \__ \
// \_/\_/ \___|\__,_| .__/ \___/|_| |_|___/
// |_|
//-------------------------------------------------------
this.game.createItemTemplate("weapons.light.dagger", {
name: "Dagger",
description: "Small shady blady",
itemSlots: 0.5,
damage: 3,
melee: true,
ranged: true,
specialEffect: "effects.weapons.fast",
});
this.game.createItemTemplate("weapons.light.sickle", {
name: "Sickle",
description: "For cutting nuts, and branches",
itemSlots: 1,
damage: 4,
specialEffect: "effects.weapons.sickle",
});
this.game.createItemTemplate("weapons.light.spiked_gauntlets", {
name: "Spiked Gauntlets",
description: "Spikes with gauntlets on them!",
itemSlots: 1,
damage: 5,
specialEffect: "TBD",
});
// _
// / \ _ __ _ __ ___ ___ _ __ ___
// / _ \ | '__| '_ ` _ \ / _ \| '__/ __|
// / ___ \| | | | | | | | (_) | | \__ \
// /_/ \_\_| |_| |_| |_|\___/|_| |___/
// ---------------------------------------
//
this.game.createItemTemplate("armors.light.studded_leather", {
name: "Studded Leather",
description: "Padded and hardened leather with metal stud reinforcement",
itemSlots: 3,
specialEffect: "TBD",
});
console.log(this.game._itemTemplates);
}
}

35
server/seeders/playerSeeder.js Executable file
View File

@@ -0,0 +1,35 @@
import { Game } from "../models/game.js";
import { Player } from "../models/player.js";
export class PlayerSeeder {
/** @param {Game} game */
constructor(game) {
/** @type {Game} */
this.game = game;
}
seed() {
// Examples of the word "pass" hashed by the client and then the server:
// Note that the word "pass" has gajillions of hashed representations, all depending on the salts used to hash them.
// "pass" hashed by client: KimsKrappyKryptoV1:userSalt:1000:SHA-256:b106e097f92ff7c288ac5048efb15f1a39a15e5d64261bbbe3f7eacee24b0ef4
// "pass" hashed by server: 1000:15d79316f95ff6c89276308e4b9eb64d:2178d5ded9174c667fe0624690180012f13264a52900fe7067a13f235f4528ef
//
// Since the server-side hashes have random salts, the hashes themselves can change for the same password.
// The client side hash must not have a random salt, otherwise, it must change every time.
//
// The hash below is just one has that represents the password "pass" sent via V1 of the "Kims Krappy Krypto" scheme.
this.game.createPlayer(
"user",
"1000:15d79316f95ff6c89276308e4b9eb64d:2178d5ded9174c667fe0624690180012f13264a52900fe7067a13f235f4528ef",
"userSalt",
);
this.game.createPlayer(
"admin",
"1000:a84760824d28a9b420ee5f175a04d1e3:a6694e5c9fd41d8ee59f0a6e34c822ee2ce337c187e2d5bb5ba8612d6145aa8e",
"adminSalt",
);
}
}