forked from noxious/server
Compare commits
47 Commits
feature/im
...
issue/#307
Author | SHA1 | Date | |
---|---|---|---|
7b90fa5c13 | |||
514ed87818 | |||
24586855cb | |||
be9ee97385 | |||
a05cd97430 | |||
cc1dbe5179 | |||
d7982493e1 | |||
57b21f1499 | |||
33afef5466 | |||
813ddbd8b1 | |||
4a55f47c06 | |||
097773995f | |||
04e4170c2d | |||
46cfb61cf5 | |||
db7121a4fa | |||
1dd0e73c4a | |||
747d05a92a | |||
48784a437f | |||
6b12d8e7b1 | |||
50c2b249f4 | |||
82aaf8a015 | |||
0e0854d365 | |||
b2e0ac47e7 | |||
f2d0e87e26 | |||
9bdafd5026 | |||
ae269be196 | |||
21f4c5328f | |||
47ec425acf | |||
1f0db75806 | |||
9a448542d3 | |||
067976c54a | |||
0b4420f956 | |||
e843213b0a | |||
4d50edd5dd | |||
0cadbc33b9 | |||
0c155347c4 | |||
149485634d | |||
bc67db7db7 | |||
a40b71140a | |||
9a016a1fb6 | |||
ce80eb223c | |||
fecdf222d7 | |||
11041fec83 | |||
887da447e0 | |||
347554998a | |||
f7dbf09bf5 | |||
ab89d0cbb0 |
@ -3,6 +3,6 @@
|
|||||||
"semi": false,
|
"semi": false,
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"printWidth": 300,
|
"printWidth": 200,
|
||||||
"trailingComma": "none"
|
"trailingComma": "none"
|
||||||
}
|
}
|
@ -33,8 +33,12 @@ Run `npx mikro-orm migration:create --initial` to create a new initial migration
|
|||||||
|
|
||||||
### Create migrations
|
### Create migrations
|
||||||
|
|
||||||
Run `npx mikro-orm migration:create` to create a new migration.
|
Run `npx mikro-orm migration:create` to create a new migration. You do this when you want to add a new table or change an existing one.
|
||||||
|
|
||||||
### Apply migrations
|
### Apply migrations
|
||||||
|
|
||||||
Run `npx mikro-orm migration:up` to apply all pending migrations.
|
Run `npx mikro-orm migration:up` to apply all pending migrations.
|
||||||
|
|
||||||
|
### Import default data
|
||||||
|
|
||||||
|
After running the server, write `init` in the console to import default data.
|
@ -1,13 +1,29 @@
|
|||||||
import { Migration } from '@mikro-orm/migrations';
|
import { Migration } from '@mikro-orm/migrations';
|
||||||
|
|
||||||
export class Migration20250101224501 extends Migration {
|
export class Migration20250106170204 extends Migration {
|
||||||
|
|
||||||
override async up(): Promise<void> {
|
override async up(): Promise<void> {
|
||||||
this.addSql(`create table \`map_object\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`tags\` json null, \`origin_x\` int not null default 0, \`origin_y\` int not null default 0, \`is_animated\` tinyint(1) not null default false, \`frame_rate\` int not null default 0, \`frame_width\` int not null default 0, \`frame_height\` int not null default 0, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`map\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`width\` int not null default 10, \`height\` int not null default 10, \`tiles\` json null, \`pvp\` tinyint(1) not null default false, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
|
||||||
|
this.addSql(`create table \`map_effect\` (\`id\` varchar(255) not null, \`map_id\` varchar(255) not null, \`effect\` varchar(255) not null, \`strength\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
this.addSql(`alter table \`map_effect\` add index \`map_effect_map_id_index\`(\`map_id\`);`);
|
||||||
|
|
||||||
|
this.addSql(`create table \`map_event_tile\` (\`id\` varchar(255) not null, \`map_id\` varchar(255) not null, \`type\` enum('BLOCK', 'TELEPORT', 'NPC', 'ITEM') not null, \`position_x\` int not null, \`position_y\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
this.addSql(`alter table \`map_event_tile\` add index \`map_event_tile_map_id_index\`(\`map_id\`);`);
|
||||||
|
|
||||||
|
this.addSql(`create table \`map_event_tile_teleport\` (\`id\` varchar(255) not null, \`map_event_tile_id\` varchar(255) not null, \`to_map_id\` varchar(255) not null, \`to_rotation\` int not null, \`to_position_x\` int not null, \`to_position_y\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
this.addSql(`alter table \`map_event_tile_teleport\` add unique \`map_event_tile_teleport_map_event_tile_id_unique\`(\`map_event_tile_id\`);`);
|
||||||
|
this.addSql(`alter table \`map_event_tile_teleport\` add index \`map_event_tile_teleport_to_map_id_index\`(\`to_map_id\`);`);
|
||||||
|
|
||||||
|
this.addSql(`create table \`map_object\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`tags\` json null, \`origin_x\` numeric(10,2) not null default 0, \`origin_y\` numeric(10,2) not null default 0, \`is_animated\` tinyint(1) not null default false, \`frame_rate\` int not null default 0, \`frame_width\` int not null default 0, \`frame_height\` int not null default 0, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
|
||||||
|
this.addSql(`create table \`placed_map_object\` (\`id\` varchar(255) not null, \`map_id\` varchar(255) not null, \`map_object_id\` varchar(255) not null, \`depth\` int not null default 0, \`is_rotated\` tinyint(1) not null default false, \`position_x\` int not null default 0, \`position_y\` int not null default 0, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
this.addSql(`alter table \`placed_map_object\` add index \`placed_map_object_map_id_index\`(\`map_id\`);`);
|
||||||
|
this.addSql(`alter table \`placed_map_object\` add index \`placed_map_object_map_object_id_index\`(\`map_object_id\`);`);
|
||||||
|
|
||||||
this.addSql(`create table \`sprite\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`sprite\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
|
||||||
this.addSql(`create table \`item\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`description\` varchar(255) null, \`item_type\` enum('WEAPON', 'HELMET', 'CHEST', 'LEGS', 'BOOTS', 'GLOVES', 'RING', 'NECKLACE') not null, \`stackable\` tinyint(1) not null default false, \`rarity\` enum('COMMON', 'UNCOMMON', 'RARE', 'EPIC', 'LEGENDARY') not null default 'COMMON', \`sprite_id\` varchar(255) null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`item\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`description\` varchar(255) not null default '', \`item_type\` enum('WEAPON', 'HELMET', 'CHEST', 'LEGS', 'BOOTS', 'GLOVES', 'RING', 'NECKLACE') not null, \`stackable\` tinyint(1) not null default false, \`rarity\` enum('COMMON', 'UNCOMMON', 'RARE', 'EPIC', 'LEGENDARY') not null default 'COMMON', \`sprite_id\` varchar(255) null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
this.addSql(`alter table \`item\` add index \`item_sprite_id_index\`(\`sprite_id\`);`);
|
this.addSql(`alter table \`item\` add index \`item_sprite_id_index\`(\`sprite_id\`);`);
|
||||||
|
|
||||||
this.addSql(`create table \`character_type\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`gender\` enum('MALE', 'FEMALE') not null, \`race\` enum('HUMAN', 'ELF', 'DWARF', 'ORC', 'GOBLIN') not null, \`is_selectable\` tinyint(1) not null default false, \`sprite_id\` varchar(255) null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`character_type\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`gender\` enum('MALE', 'FEMALE') not null, \`race\` enum('HUMAN', 'ELF', 'DWARF', 'ORC', 'GOBLIN') not null, \`is_selectable\` tinyint(1) not null default false, \`sprite_id\` varchar(255) null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
@ -29,20 +45,16 @@ export class Migration20250101224501 extends Migration {
|
|||||||
this.addSql(`alter table \`password_reset_token\` add index \`password_reset_token_user_id_index\`(\`user_id\`);`);
|
this.addSql(`alter table \`password_reset_token\` add index \`password_reset_token_user_id_index\`(\`user_id\`);`);
|
||||||
this.addSql(`alter table \`password_reset_token\` add unique \`password_reset_token_token_unique\`(\`token\`);`);
|
this.addSql(`alter table \`password_reset_token\` add unique \`password_reset_token_token_unique\`(\`token\`);`);
|
||||||
|
|
||||||
this.addSql(`create table \`world\` (\`date\` datetime not null, \`is_rain_enabled\` tinyint(1) not null default false, \`rain_percentage\` int not null default 0, \`is_fog_enabled\` tinyint(1) not null default false, \`fog_density\` int not null default 0, primary key (\`date\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`character\` (\`id\` varchar(255) not null, \`user_id\` varchar(255) not null, \`name\` varchar(255) not null, \`online\` tinyint(1) not null default false, \`role\` varchar(255) not null default 'player', \`map_id\` varchar(255) not null, \`position_x\` int not null default 0, \`position_y\` int not null default 0, \`rotation\` int not null default 0, \`character_type_id\` varchar(255) null, \`character_hair_id\` varchar(255) null, \`alignment\` int not null default 50, \`hitpoints\` int not null default 100, \`mana\` int not null default 100, \`level\` int not null default 1, \`experience\` int not null default 0, \`strength\` int not null default 10, \`dexterity\` int not null default 10, \`intelligence\` int not null default 10, \`wisdom\` int not null default 10, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
|
|
||||||
this.addSql(`create table \`zone\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`width\` int not null default 10, \`height\` int not null default 10, \`tiles\` json null, \`pvp\` tinyint(1) not null default false, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
|
||||||
|
|
||||||
this.addSql(`create table \`character\` (\`id\` varchar(255) not null, \`user_id\` varchar(255) not null, \`name\` varchar(255) not null, \`online\` tinyint(1) not null default false, \`role\` varchar(255) not null default 'player', \`zone_id\` varchar(255) not null, \`position_x\` int not null default 0, \`position_y\` int not null default 0, \`rotation\` int not null default 0, \`character_type_id\` varchar(255) null, \`character_hair_id\` varchar(255) null, \`alignment\` int not null default 50, \`hitpoints\` int not null default 100, \`mana\` int not null default 100, \`level\` int not null default 1, \`experience\` int not null default 0, \`strength\` int not null default 10, \`dexterity\` int not null default 10, \`intelligence\` int not null default 10, \`wisdom\` int not null default 10, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
|
||||||
this.addSql(`alter table \`character\` add index \`character_user_id_index\`(\`user_id\`);`);
|
this.addSql(`alter table \`character\` add index \`character_user_id_index\`(\`user_id\`);`);
|
||||||
this.addSql(`alter table \`character\` add unique \`character_name_unique\`(\`name\`);`);
|
this.addSql(`alter table \`character\` add unique \`character_name_unique\`(\`name\`);`);
|
||||||
this.addSql(`alter table \`character\` add index \`character_zone_id_index\`(\`zone_id\`);`);
|
this.addSql(`alter table \`character\` add index \`character_map_id_index\`(\`map_id\`);`);
|
||||||
this.addSql(`alter table \`character\` add index \`character_character_type_id_index\`(\`character_type_id\`);`);
|
this.addSql(`alter table \`character\` add index \`character_character_type_id_index\`(\`character_type_id\`);`);
|
||||||
this.addSql(`alter table \`character\` add index \`character_character_hair_id_index\`(\`character_hair_id\`);`);
|
this.addSql(`alter table \`character\` add index \`character_character_hair_id_index\`(\`character_hair_id\`);`);
|
||||||
|
|
||||||
this.addSql(`create table \`chat\` (\`id\` varchar(255) not null, \`character_id\` varchar(255) not null, \`zone_id\` varchar(255) not null, \`message\` varchar(255) not null, \`created_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`chat\` (\`id\` varchar(255) not null, \`character_id\` varchar(255) not null, \`map_id\` varchar(255) not null, \`message\` varchar(255) not null, \`created_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
this.addSql(`alter table \`chat\` add index \`chat_character_id_index\`(\`character_id\`);`);
|
this.addSql(`alter table \`chat\` add index \`chat_character_id_index\`(\`character_id\`);`);
|
||||||
this.addSql(`alter table \`chat\` add index \`chat_zone_id_index\`(\`zone_id\`);`);
|
this.addSql(`alter table \`chat\` add index \`chat_map_id_index\`(\`map_id\`);`);
|
||||||
|
|
||||||
this.addSql(`create table \`character_item\` (\`id\` varchar(255) not null, \`character_id\` varchar(255) not null, \`item_id\` varchar(255) not null, \`quantity\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`character_item\` (\`id\` varchar(255) not null, \`character_id\` varchar(255) not null, \`item_id\` varchar(255) not null, \`quantity\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
this.addSql(`alter table \`character_item\` add index \`character_item_character_id_index\`(\`character_id\`);`);
|
this.addSql(`alter table \`character_item\` add index \`character_item_character_id_index\`(\`character_id\`);`);
|
||||||
@ -52,19 +64,17 @@ export class Migration20250101224501 extends Migration {
|
|||||||
this.addSql(`alter table \`character_equipment\` add index \`character_equipment_character_id_index\`(\`character_id\`);`);
|
this.addSql(`alter table \`character_equipment\` add index \`character_equipment_character_id_index\`(\`character_id\`);`);
|
||||||
this.addSql(`alter table \`character_equipment\` add index \`character_equipment_character_item_id_index\`(\`character_item_id\`);`);
|
this.addSql(`alter table \`character_equipment\` add index \`character_equipment_character_item_id_index\`(\`character_item_id\`);`);
|
||||||
|
|
||||||
this.addSql(`create table \`zone_effect\` (\`id\` varchar(255) not null, \`zone_id\` varchar(255) not null, \`effect\` varchar(255) not null, \`strength\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`create table \`world\` (\`date\` datetime not null, \`is_rain_enabled\` tinyint(1) not null default false, \`rain_percentage\` int not null default 0, \`is_fog_enabled\` tinyint(1) not null default false, \`fog_density\` int not null default 0, primary key (\`date\`)) default character set utf8mb4 engine = InnoDB;`);
|
||||||
this.addSql(`alter table \`zone_effect\` add index \`zone_effect_zone_id_index\`(\`zone_id\`);`);
|
|
||||||
|
|
||||||
this.addSql(`create table \`zone_event_tile\` (\`id\` varchar(255) not null, \`zone_id\` varchar(255) not null, \`type\` enum('BLOCK', 'TELEPORT', 'NPC', 'ITEM') not null, \`position_x\` int not null, \`position_y\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`alter table \`map_effect\` add constraint \`map_effect_map_id_foreign\` foreign key (\`map_id\`) references \`map\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`zone_event_tile\` add index \`zone_event_tile_zone_id_index\`(\`zone_id\`);`);
|
|
||||||
|
|
||||||
this.addSql(`create table \`zone_event_tile_teleport\` (\`id\` varchar(255) not null, \`zone_event_tile_id\` varchar(255) not null, \`to_zone_id\` varchar(255) not null, \`to_rotation\` int not null, \`to_position_x\` int not null, \`to_position_y\` int not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`alter table \`map_event_tile\` add constraint \`map_event_tile_map_id_foreign\` foreign key (\`map_id\`) references \`map\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`zone_event_tile_teleport\` add unique \`zone_event_tile_teleport_zone_event_tile_id_unique\`(\`zone_event_tile_id\`);`);
|
|
||||||
this.addSql(`alter table \`zone_event_tile_teleport\` add index \`zone_event_tile_teleport_to_zone_id_index\`(\`to_zone_id\`);`);
|
|
||||||
|
|
||||||
this.addSql(`create table \`zone_object\` (\`id\` varchar(255) not null, \`zone_id\` varchar(255) not null, \`map_object_id\` varchar(255) not null, \`depth\` int not null default 0, \`is_rotated\` tinyint(1) not null default false, \`position_x\` int not null default 0, \`position_y\` int not null default 0, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
this.addSql(`alter table \`map_event_tile_teleport\` add constraint \`map_event_tile_teleport_map_event_tile_id_foreign\` foreign key (\`map_event_tile_id\`) references \`map_event_tile\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`zone_object\` add index \`zone_object_zone_id_index\`(\`zone_id\`);`);
|
this.addSql(`alter table \`map_event_tile_teleport\` add constraint \`map_event_tile_teleport_to_map_id_foreign\` foreign key (\`to_map_id\`) references \`map\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`zone_object\` add index \`zone_object_map_object_id_index\`(\`map_object_id\`);`);
|
|
||||||
|
this.addSql(`alter table \`placed_map_object\` add constraint \`placed_map_object_map_id_foreign\` foreign key (\`map_id\`) references \`map\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
|
this.addSql(`alter table \`placed_map_object\` add constraint \`placed_map_object_map_object_id_foreign\` foreign key (\`map_object_id\`) references \`map_object\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
|
|
||||||
this.addSql(`alter table \`item\` add constraint \`item_sprite_id_foreign\` foreign key (\`sprite_id\`) references \`sprite\` (\`id\`) on update cascade on delete set null;`);
|
this.addSql(`alter table \`item\` add constraint \`item_sprite_id_foreign\` foreign key (\`sprite_id\`) references \`sprite\` (\`id\`) on update cascade on delete set null;`);
|
||||||
|
|
||||||
@ -77,28 +87,18 @@ export class Migration20250101224501 extends Migration {
|
|||||||
this.addSql(`alter table \`password_reset_token\` add constraint \`password_reset_token_user_id_foreign\` foreign key (\`user_id\`) references \`user\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`password_reset_token\` add constraint \`password_reset_token_user_id_foreign\` foreign key (\`user_id\`) references \`user\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
|
|
||||||
this.addSql(`alter table \`character\` add constraint \`character_user_id_foreign\` foreign key (\`user_id\`) references \`user\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`character\` add constraint \`character_user_id_foreign\` foreign key (\`user_id\`) references \`user\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`character\` add constraint \`character_zone_id_foreign\` foreign key (\`zone_id\`) references \`zone\` (\`id\`) on update cascade;`);
|
this.addSql(`alter table \`character\` add constraint \`character_map_id_foreign\` foreign key (\`map_id\`) references \`map\` (\`id\`) on update cascade;`);
|
||||||
this.addSql(`alter table \`character\` add constraint \`character_character_type_id_foreign\` foreign key (\`character_type_id\`) references \`character_type\` (\`id\`) on update cascade on delete set null;`);
|
this.addSql(`alter table \`character\` add constraint \`character_character_type_id_foreign\` foreign key (\`character_type_id\`) references \`character_type\` (\`id\`) on update cascade on delete set null;`);
|
||||||
this.addSql(`alter table \`character\` add constraint \`character_character_hair_id_foreign\` foreign key (\`character_hair_id\`) references \`character_hair\` (\`id\`) on update cascade on delete set null;`);
|
this.addSql(`alter table \`character\` add constraint \`character_character_hair_id_foreign\` foreign key (\`character_hair_id\`) references \`character_hair\` (\`id\`) on update cascade on delete set null;`);
|
||||||
|
|
||||||
this.addSql(`alter table \`chat\` add constraint \`chat_character_id_foreign\` foreign key (\`character_id\`) references \`character\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`chat\` add constraint \`chat_character_id_foreign\` foreign key (\`character_id\`) references \`character\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`chat\` add constraint \`chat_zone_id_foreign\` foreign key (\`zone_id\`) references \`zone\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`chat\` add constraint \`chat_map_id_foreign\` foreign key (\`map_id\`) references \`map\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
|
|
||||||
this.addSql(`alter table \`character_item\` add constraint \`character_item_character_id_foreign\` foreign key (\`character_id\`) references \`character\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`character_item\` add constraint \`character_item_character_id_foreign\` foreign key (\`character_id\`) references \`character\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`character_item\` add constraint \`character_item_item_id_foreign\` foreign key (\`item_id\`) references \`item\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`character_item\` add constraint \`character_item_item_id_foreign\` foreign key (\`item_id\`) references \`item\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
|
|
||||||
this.addSql(`alter table \`character_equipment\` add constraint \`character_equipment_character_id_foreign\` foreign key (\`character_id\`) references \`character\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`character_equipment\` add constraint \`character_equipment_character_id_foreign\` foreign key (\`character_id\`) references \`character\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
this.addSql(`alter table \`character_equipment\` add constraint \`character_equipment_character_item_id_foreign\` foreign key (\`character_item_id\`) references \`character_item\` (\`id\`) on update cascade on delete cascade;`);
|
this.addSql(`alter table \`character_equipment\` add constraint \`character_equipment_character_item_id_foreign\` foreign key (\`character_item_id\`) references \`character_item\` (\`id\`) on update cascade on delete cascade;`);
|
||||||
|
|
||||||
this.addSql(`alter table \`zone_effect\` add constraint \`zone_effect_zone_id_foreign\` foreign key (\`zone_id\`) references \`zone\` (\`id\`) on update cascade on delete cascade;`);
|
|
||||||
|
|
||||||
this.addSql(`alter table \`zone_event_tile\` add constraint \`zone_event_tile_zone_id_foreign\` foreign key (\`zone_id\`) references \`zone\` (\`id\`) on update cascade on delete cascade;`);
|
|
||||||
|
|
||||||
this.addSql(`alter table \`zone_event_tile_teleport\` add constraint \`zone_event_tile_teleport_zone_event_tile_id_foreign\` foreign key (\`zone_event_tile_id\`) references \`zone_event_tile\` (\`id\`) on update cascade on delete cascade;`);
|
|
||||||
this.addSql(`alter table \`zone_event_tile_teleport\` add constraint \`zone_event_tile_teleport_to_zone_id_foreign\` foreign key (\`to_zone_id\`) references \`zone\` (\`id\`) on update cascade on delete cascade;`);
|
|
||||||
|
|
||||||
this.addSql(`alter table \`zone_object\` add constraint \`zone_object_zone_id_foreign\` foreign key (\`zone_id\`) references \`zone\` (\`id\`) on update cascade on delete cascade;`);
|
|
||||||
this.addSql(`alter table \`zone_object\` add constraint \`zone_object_map_object_id_foreign\` foreign key (\`map_object_id\`) references \`map_object\` (\`id\`) on update cascade on delete cascade;`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,8 +8,8 @@ import serverConfig from './src/application/config'
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
extensions: [Migrator],
|
extensions: [Migrator],
|
||||||
metadataProvider: TsMorphMetadataProvider,
|
metadataProvider: TsMorphMetadataProvider,
|
||||||
entities: ['./src/entities/**/*.js'],
|
entities: ['./src/entities/*.js'],
|
||||||
entitiesTs: ['./src/entities/**/*.ts'],
|
entitiesTs: ['./src/entities/*.ts'],
|
||||||
driver: MySqlDriver,
|
driver: MySqlDriver,
|
||||||
host: serverConfig.DB_HOST,
|
host: serverConfig.DB_HOST,
|
||||||
port: serverConfig.DB_PORT,
|
port: serverConfig.DB_PORT,
|
||||||
@ -17,6 +17,7 @@ export default defineConfig({
|
|||||||
password: serverConfig.DB_PASS,
|
password: serverConfig.DB_PASS,
|
||||||
dbName: serverConfig.DB_NAME,
|
dbName: serverConfig.DB_NAME,
|
||||||
debug: serverConfig.ENV !== 'production',
|
debug: serverConfig.ENV !== 'production',
|
||||||
|
// allowGlobalContext: true,
|
||||||
driverOptions: {
|
driverOptions: {
|
||||||
allowPublicKeyRetrieval: true
|
allowPublicKeyRetrieval: true
|
||||||
},
|
},
|
||||||
|
161
package-lock.json
generated
161
package-lock.json
generated
@ -1784,9 +1784,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "20.17.11",
|
"version": "20.17.12",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.11.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.12.tgz",
|
||||||
"integrity": "sha512-Ept5glCK35R8yeyIeYlRIZtX6SLRyqMhOFTgj5SOkMpLTdw3SEHI9fHx60xaUZ+V1aJxQJODE+7/j5ocZydYTg==",
|
"integrity": "sha512-vo/wmBgMIiEA23A/knMfn/cf37VnuF52nZh5ZoW0GWt4e4sxNquibrMRJ7UQsA06+MBx9r/H1jsI9grYjQCQlw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.19.2"
|
"undici-types": "~6.19.2"
|
||||||
@ -3085,9 +3085,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/es-abstract": {
|
"node_modules/es-abstract": {
|
||||||
"version": "1.23.8",
|
"version": "1.23.9",
|
||||||
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.23.8.tgz",
|
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.23.9.tgz",
|
||||||
"integrity": "sha512-lfab8IzDn6EpI1ibZakcgS6WsfEBiB+43cuJo+wgylx1xKXf+Sp+YR3vFuQwC/u3sxYwV8Cxe3B0DpVUu/WiJQ==",
|
"integrity": "sha512-py07lI0wjxAC/DcfK1S6G7iANonniZwTISvdPzk9hzeH0IZIshbuuFxLIU96OyF89Yb9hiqWn8M/bY83KY5vzA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -3102,10 +3102,11 @@
|
|||||||
"es-define-property": "^1.0.1",
|
"es-define-property": "^1.0.1",
|
||||||
"es-errors": "^1.3.0",
|
"es-errors": "^1.3.0",
|
||||||
"es-object-atoms": "^1.0.0",
|
"es-object-atoms": "^1.0.0",
|
||||||
"es-set-tostringtag": "^2.0.3",
|
"es-set-tostringtag": "^2.1.0",
|
||||||
"es-to-primitive": "^1.3.0",
|
"es-to-primitive": "^1.3.0",
|
||||||
"function.prototype.name": "^1.1.8",
|
"function.prototype.name": "^1.1.8",
|
||||||
"get-intrinsic": "^1.2.6",
|
"get-intrinsic": "^1.2.7",
|
||||||
|
"get-proto": "^1.0.0",
|
||||||
"get-symbol-description": "^1.1.0",
|
"get-symbol-description": "^1.1.0",
|
||||||
"globalthis": "^1.0.4",
|
"globalthis": "^1.0.4",
|
||||||
"gopd": "^1.2.0",
|
"gopd": "^1.2.0",
|
||||||
@ -3126,11 +3127,12 @@
|
|||||||
"object-inspect": "^1.13.3",
|
"object-inspect": "^1.13.3",
|
||||||
"object-keys": "^1.1.1",
|
"object-keys": "^1.1.1",
|
||||||
"object.assign": "^4.1.7",
|
"object.assign": "^4.1.7",
|
||||||
"own-keys": "^1.0.0",
|
"own-keys": "^1.0.1",
|
||||||
"regexp.prototype.flags": "^1.5.3",
|
"regexp.prototype.flags": "^1.5.3",
|
||||||
"safe-array-concat": "^1.1.3",
|
"safe-array-concat": "^1.1.3",
|
||||||
"safe-push-apply": "^1.0.0",
|
"safe-push-apply": "^1.0.0",
|
||||||
"safe-regex-test": "^1.1.0",
|
"safe-regex-test": "^1.1.0",
|
||||||
|
"set-proto": "^1.0.0",
|
||||||
"string.prototype.trim": "^1.2.10",
|
"string.prototype.trim": "^1.2.10",
|
||||||
"string.prototype.trimend": "^1.0.9",
|
"string.prototype.trimend": "^1.0.9",
|
||||||
"string.prototype.trimstart": "^1.0.8",
|
"string.prototype.trimstart": "^1.0.8",
|
||||||
@ -3179,15 +3181,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/es-set-tostringtag": {
|
"node_modules/es-set-tostringtag": {
|
||||||
"version": "2.0.3",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
||||||
"integrity": "sha512-3T8uNMC3OQTHkFUsFq8r/BwAXLHvU/9O9mE0fBc/MY5iq/8H7ncvO947LmYA6ldWw9Uh8Yhf25zu6n7nML5QWQ==",
|
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"get-intrinsic": "^1.2.4",
|
"es-errors": "^1.3.0",
|
||||||
|
"get-intrinsic": "^1.2.6",
|
||||||
"has-tostringtag": "^1.0.2",
|
"has-tostringtag": "^1.0.2",
|
||||||
"hasown": "^2.0.1"
|
"hasown": "^2.0.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
@ -3759,16 +3762,16 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/fast-glob": {
|
"node_modules/fast-glob": {
|
||||||
"version": "3.3.2",
|
"version": "3.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz",
|
||||||
"integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==",
|
"integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodelib/fs.stat": "^2.0.2",
|
"@nodelib/fs.stat": "^2.0.2",
|
||||||
"@nodelib/fs.walk": "^1.2.3",
|
"@nodelib/fs.walk": "^1.2.3",
|
||||||
"glob-parent": "^5.1.2",
|
"glob-parent": "^5.1.2",
|
||||||
"merge2": "^1.3.0",
|
"merge2": "^1.3.0",
|
||||||
"micromatch": "^4.0.4"
|
"micromatch": "^4.0.8"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.6.0"
|
"node": ">=8.6.0"
|
||||||
@ -3810,9 +3813,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fast-uri": {
|
"node_modules/fast-uri": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.5.tgz",
|
||||||
"integrity": "sha512-aLrHthzCjH5He4Z2H9YZ+v6Ujb9ocRuW6ZzkJQOrTxleEijANq4v1TsaPaVG1PZcuurEzrLcWRyYBYXD5cEiaw==",
|
"integrity": "sha512-5JnBCWpFlMo0a3ciDy/JckMzzv1U9coZrIhedq+HXxxUfDTAiS0LA8OKVao4G9BxmCVck/jtA5r3KAtRWEyD8Q==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/fastify"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/fastify"
|
||||||
|
}
|
||||||
|
],
|
||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/fastq": {
|
"node_modules/fastq": {
|
||||||
@ -4050,21 +4063,21 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/get-intrinsic": {
|
"node_modules/get-intrinsic": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.7",
|
||||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.7.tgz",
|
||||||
"integrity": "sha512-qxsEs+9A+u85HhllWJJFicJfPDhRmjzoYdl64aMWW9yRIJmSyxdn8IEkuIM530/7T+lv0TIHd8L6Q/ra0tEoeA==",
|
"integrity": "sha512-VW6Pxhsrk0KAOqs3WEd0klDiF/+V7gQOpAvY1jVU/LHmaD/kQO4523aiJuikX/QAKYiW6x8Jh+RJej1almdtCA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"call-bind-apply-helpers": "^1.0.1",
|
"call-bind-apply-helpers": "^1.0.1",
|
||||||
"dunder-proto": "^1.0.0",
|
|
||||||
"es-define-property": "^1.0.1",
|
"es-define-property": "^1.0.1",
|
||||||
"es-errors": "^1.3.0",
|
"es-errors": "^1.3.0",
|
||||||
"es-object-atoms": "^1.0.0",
|
"es-object-atoms": "^1.0.0",
|
||||||
"function-bind": "^1.1.2",
|
"function-bind": "^1.1.2",
|
||||||
|
"get-proto": "^1.0.0",
|
||||||
"gopd": "^1.2.0",
|
"gopd": "^1.2.0",
|
||||||
"has-symbols": "^1.1.0",
|
"has-symbols": "^1.1.0",
|
||||||
"hasown": "^2.0.2",
|
"hasown": "^2.0.2",
|
||||||
"math-intrinsics": "^1.0.0"
|
"math-intrinsics": "^1.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
@ -4082,6 +4095,19 @@
|
|||||||
"node": ">=8.0.0"
|
"node": ">=8.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/get-proto": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"dunder-proto": "^1.0.1",
|
||||||
|
"es-object-atoms": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/get-symbol-description": {
|
"node_modules/get-symbol-description": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.1.0.tgz",
|
||||||
@ -4466,13 +4492,16 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/is-async-function": {
|
"node_modules/is-async-function": {
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-async-function/-/is-async-function-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-async-function/-/is-async-function-2.1.0.tgz",
|
||||||
"integrity": "sha512-Y1JXKrfykRJGdlDwdKlLpLyMIiWqWvuSd17TvZk68PLAOGOoF4Xyav1z0Xhoi+gCYjZVeC5SI+hYFOfvXmGRCA==",
|
"integrity": "sha512-GExz9MtyhlZyXYLxzlJRj5WUCE661zhDa1Yna52CN57AJsymh+DvXXjyveSioqSRdxvUrdKdvqB1b5cVKsNpWQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"has-tostringtag": "^1.0.0"
|
"call-bound": "^1.0.3",
|
||||||
|
"get-proto": "^1.0.1",
|
||||||
|
"has-tostringtag": "^1.0.2",
|
||||||
|
"safe-regex-test": "^1.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
@ -4626,13 +4655,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/is-generator-function": {
|
"node_modules/is-generator-function": {
|
||||||
"version": "1.0.10",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz",
|
"resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.0.tgz",
|
||||||
"integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==",
|
"integrity": "sha512-nPUB5km40q9e8UfN/Zc24eLlzdSf9OfKByBw9CIdw4H1giPMeA0OIJvbchsCu4npfI2QcMVBsGEBHKZ7wLTWmQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"has-tostringtag": "^1.0.0"
|
"call-bound": "^1.0.3",
|
||||||
|
"get-proto": "^1.0.0",
|
||||||
|
"has-tostringtag": "^1.0.2",
|
||||||
|
"safe-regex-test": "^1.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
@ -5214,9 +5246,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mariadb/node_modules/@types/node": {
|
"node_modules/mariadb/node_modules/@types/node": {
|
||||||
"version": "22.10.3",
|
"version": "22.10.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.5.tgz",
|
||||||
"integrity": "sha512-DifAyw4BkrufCILvD3ucnuN8eydUfc/C1GlyrnI+LK6543w5/L3VeVgf05o3B4fqSXP1dKYLOZsKfutpxPzZrw==",
|
"integrity": "sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.20.0"
|
"undici-types": "~6.20.0"
|
||||||
@ -5980,9 +6012,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/process-warning": {
|
"node_modules/process-warning": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-4.0.1.tgz",
|
||||||
"integrity": "sha512-/MyYDxttz7DfGMMHiysAsFE4qF+pQYAA8ziO/3NcRVrQ5fSk+Mns4QZA/oRPFzvcqNoVJXQNWNAsdwBXLUkQKw==",
|
"integrity": "sha512-3c2LzQ3rY9d0hc1emcsHhfT9Jwz0cChib/QN89oME2R451w5fy3f0afAhERFZAwrbDU43wk12d0ORBpDVME50Q==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/fastify"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/fastify"
|
||||||
|
}
|
||||||
|
],
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/proxy-addr": {
|
"node_modules/proxy-addr": {
|
||||||
@ -6141,19 +6183,19 @@
|
|||||||
"license": "Apache-2.0"
|
"license": "Apache-2.0"
|
||||||
},
|
},
|
||||||
"node_modules/reflect.getprototypeof": {
|
"node_modules/reflect.getprototypeof": {
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
"resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz",
|
||||||
"integrity": "sha512-r0Ay04Snci87djAsI4U+WNRcSw5S4pOH7qFjd/veA5gC7TbqESR3tcj28ia95L/fYUDw11JKP7uqUKUAfVvV5Q==",
|
"integrity": "sha512-00o4I+DVrefhv+nX0ulyi3biSHCPDe+yLv5o/p6d/UVlirijB8E16FtfwSAi4g3tcqrQ4lRAqQSoFEZJehYEcw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"call-bind": "^1.0.8",
|
"call-bind": "^1.0.8",
|
||||||
"define-properties": "^1.2.1",
|
"define-properties": "^1.2.1",
|
||||||
"dunder-proto": "^1.0.1",
|
"es-abstract": "^1.23.9",
|
||||||
"es-abstract": "^1.23.6",
|
|
||||||
"es-errors": "^1.3.0",
|
"es-errors": "^1.3.0",
|
||||||
"get-intrinsic": "^1.2.6",
|
"es-object-atoms": "^1.0.0",
|
||||||
"gopd": "^1.2.0",
|
"get-intrinsic": "^1.2.7",
|
||||||
|
"get-proto": "^1.0.1",
|
||||||
"which-builtin-type": "^1.2.1"
|
"which-builtin-type": "^1.2.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@ -6164,15 +6206,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/regexp.prototype.flags": {
|
"node_modules/regexp.prototype.flags": {
|
||||||
"version": "1.5.3",
|
"version": "1.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz",
|
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz",
|
||||||
"integrity": "sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ==",
|
"integrity": "sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"call-bind": "^1.0.7",
|
"call-bind": "^1.0.8",
|
||||||
"define-properties": "^1.2.1",
|
"define-properties": "^1.2.1",
|
||||||
"es-errors": "^1.3.0",
|
"es-errors": "^1.3.0",
|
||||||
|
"get-proto": "^1.0.1",
|
||||||
|
"gopd": "^1.2.0",
|
||||||
"set-function-name": "^2.0.2"
|
"set-function-name": "^2.0.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@ -6478,6 +6522,21 @@
|
|||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/set-proto": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/set-proto/-/set-proto-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-RJRdvCo6IAnPdsvP/7m6bsQqNnn1FCBX5ZNtFL98MmFF/4xAIJTIg1YbHW5DC2W5SKZanrC6i4HsJqlajw/dZw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"dunder-proto": "^1.0.1",
|
||||||
|
"es-errors": "^1.3.0",
|
||||||
|
"es-object-atoms": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/setprototypeof": {
|
"node_modules/setprototypeof": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
{
|
{
|
||||||
"useTsNode": true,
|
|
||||||
"alwaysAllowTs": true,
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "npx prisma migrate deploy && node dist/server.js",
|
"start": "node dist/server.js",
|
||||||
"dev": "nodemon --ignore 'data/*' --exec tsx src/server.ts",
|
"dev": "nodemon --exec tsx src/server.ts",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"format": "prettier --write src/",
|
"format": "prettier --write src/",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
Binary file not shown.
@ -5,23 +5,32 @@ import Logger, { LoggerType } from '#application/logger'
|
|||||||
|
|
||||||
export abstract class BaseEntity {
|
export abstract class BaseEntity {
|
||||||
protected readonly logger = Logger.type(LoggerType.ENTITY)
|
protected readonly logger = Logger.type(LoggerType.ENTITY)
|
||||||
|
protected entityManager?: EntityManager
|
||||||
|
|
||||||
private getEntityManager(): EntityManager {
|
private getEntityManager(): EntityManager {
|
||||||
return Database.getEntityManager()
|
if (!this.entityManager) {
|
||||||
|
this.entityManager = Database.getORM().em.fork()
|
||||||
|
}
|
||||||
|
return this.entityManager
|
||||||
|
}
|
||||||
|
|
||||||
|
public setEntityManager(entityManager: EntityManager) {
|
||||||
|
this.entityManager = entityManager
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(): Promise<this> {
|
async save(): Promise<this> {
|
||||||
return this.execute('persist', 'save entity')
|
return this.execute('persist', 'save entity')
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(): Promise<this> {
|
|
||||||
return this.execute('merge', 'update entity')
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(): Promise<this> {
|
async delete(): Promise<this> {
|
||||||
return this.execute('remove', 'remove entity')
|
return this.execute('remove', 'remove entity')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async update(): Promise<this> {
|
||||||
|
return this.execute('merge', 'update entity')
|
||||||
|
}
|
||||||
|
|
||||||
private async execute(method: 'persist' | 'merge' | 'remove', actionDescription: string): Promise<this> {
|
private async execute(method: 'persist' | 'merge' | 'remove', actionDescription: string): Promise<this> {
|
||||||
try {
|
try {
|
||||||
const em = this.getEntityManager()
|
const em = this.getEntityManager()
|
||||||
|
@ -2,6 +2,8 @@ import { Server } from 'socket.io'
|
|||||||
|
|
||||||
import Logger, { LoggerType } from '#application/logger'
|
import Logger, { LoggerType } from '#application/logger'
|
||||||
import { TSocket } from '#application/types'
|
import { TSocket } from '#application/types'
|
||||||
|
import { Character } from '#entities/character'
|
||||||
|
import CharacterRepository from '#repositories/characterRepository'
|
||||||
|
|
||||||
export abstract class BaseEvent {
|
export abstract class BaseEvent {
|
||||||
protected readonly logger = Logger.type(LoggerType.GAME)
|
protected readonly logger = Logger.type(LoggerType.GAME)
|
||||||
@ -11,6 +13,16 @@ export abstract class BaseEvent {
|
|||||||
readonly socket: TSocket
|
readonly socket: TSocket
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
protected async getCharacter(): Promise<Character | null> {
|
||||||
|
const characterRepository = new CharacterRepository()
|
||||||
|
return characterRepository.getById(this.socket.characterId!)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async isCharacterGM(): Promise<boolean> {
|
||||||
|
const character = await this.getCharacter()
|
||||||
|
return character?.getRole() === 'gm'
|
||||||
|
}
|
||||||
|
|
||||||
protected emitError(message: string): void {
|
protected emitError(message: string): void {
|
||||||
this.socket.emit('notification', { title: 'Server message', message })
|
this.socket.emit('notification', { title: 'Server message', message })
|
||||||
this.logger.error('character:connect error', `Player ${this.socket.userId}: ${message}`)
|
this.logger.error('character:connect error', `Player ${this.socket.userId}: ${message}`)
|
||||||
|
@ -6,8 +6,12 @@ import Logger, { LoggerType } from '#application/logger'
|
|||||||
|
|
||||||
export abstract class BaseRepository {
|
export abstract class BaseRepository {
|
||||||
protected readonly logger = Logger.type(LoggerType.REPOSITORY)
|
protected readonly logger = Logger.type(LoggerType.REPOSITORY)
|
||||||
|
private entityManager?: EntityManager
|
||||||
|
|
||||||
protected get em(): EntityManager {
|
getEntityManager(): EntityManager {
|
||||||
return Database.getEntityManager()
|
if (!this.entityManager) {
|
||||||
|
this.entityManager = Database.getORM().em.fork()
|
||||||
|
}
|
||||||
|
return this.entityManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,8 @@ export class LogReader {
|
|||||||
})
|
})
|
||||||
|
|
||||||
stream.on('data', (data) => {
|
stream.on('data', (data) => {
|
||||||
process.stdout.write('\r' + `[${filename}]\n${data}`)
|
console.log(`[${filename}]`);
|
||||||
process.stdout.write('\n> ')
|
console.log(data.toString()); //
|
||||||
})
|
})
|
||||||
|
|
||||||
currentPosition = newPosition
|
currentPosition = newPosition
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { EntityManager } from '@mikro-orm/core'
|
|
||||||
import { MikroORM } from '@mikro-orm/mysql'
|
import { MikroORM } from '@mikro-orm/mysql'
|
||||||
|
|
||||||
import Logger, { LoggerType } from './logger'
|
import Logger, { LoggerType } from './logger'
|
||||||
@ -6,13 +5,11 @@ import config from '../../mikro-orm.config'
|
|||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
private static orm: MikroORM
|
private static orm: MikroORM
|
||||||
private static em: EntityManager
|
|
||||||
private static logger = Logger.type(LoggerType.APP)
|
private static logger = Logger.type(LoggerType.APP)
|
||||||
|
|
||||||
public static async initialize(): Promise<void> {
|
public static async initialize(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
Database.orm = await MikroORM.init(config)
|
this.orm = await MikroORM.init(config)
|
||||||
Database.em = Database.orm.em.fork()
|
|
||||||
this.logger.info('Database connection initialized')
|
this.logger.info('Database connection initialized')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`MikroORM connection failed: ${error}`)
|
this.logger.error(`MikroORM connection failed: ${error}`)
|
||||||
@ -21,17 +18,7 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static getORM(): MikroORM {
|
public static getORM(): MikroORM {
|
||||||
if (!Database.orm) {
|
return this.orm
|
||||||
throw new Error('Database not initialized. Call Database.initialize() first.')
|
|
||||||
}
|
|
||||||
return Database.orm
|
|
||||||
}
|
|
||||||
|
|
||||||
public static getEntityManager(): EntityManager {
|
|
||||||
if (!Database.em) {
|
|
||||||
throw new Error('Database not initialized. Call Database.initialize() first.')
|
|
||||||
}
|
|
||||||
return Database.em
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ export enum CharacterEquipmentSlotType {
|
|||||||
RING = 'RING'
|
RING = 'RING'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ZoneEventTileType {
|
export enum MapEventTileType {
|
||||||
BLOCK = 'BLOCK',
|
BLOCK = 'BLOCK',
|
||||||
TELEPORT = 'TELEPORT',
|
TELEPORT = 'TELEPORT',
|
||||||
NPC = 'NPC',
|
NPC = 'NPC',
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Server, Socket } from 'socket.io'
|
import { Server, Socket } from 'socket.io'
|
||||||
|
|
||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import { ZoneEventTile } from '#entities/zoneEventTile'
|
import { MapEventTile } from '#entities/mapEventTile'
|
||||||
import { ZoneEventTileTeleport } from '#entities/zoneEventTileTeleport'
|
import { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
||||||
|
|
||||||
export type UUID = `${string}-${string}-${string}-${string}-${string}`
|
export type UUID = `${string}-${string}-${string}-${string}-${string}`
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ export type ExtendedCharacter = Character & {
|
|||||||
resetMovement?: boolean
|
resetMovement?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ZoneEventTileWithTeleport = ZoneEventTile & {
|
export type MapEventTileWithTeleport = MapEventTile & {
|
||||||
teleport: ZoneEventTileTeleport
|
teleport: MapEventTileTeleport
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AssetData = {
|
export type AssetData = {
|
||||||
|
@ -9,31 +9,35 @@ import { UUID } from '#application/types'
|
|||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import { CharacterHair } from '#entities/characterHair'
|
import { CharacterHair } from '#entities/characterHair'
|
||||||
import { CharacterType } from '#entities/characterType'
|
import { CharacterType } from '#entities/characterType'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import { MapEffect } from '#entities/mapEffect'
|
||||||
import { MapObject } from '#entities/mapObject'
|
import { MapObject } from '#entities/mapObject'
|
||||||
import { Sprite } from '#entities/sprite'
|
import { Sprite } from '#entities/sprite'
|
||||||
import { SpriteAction } from '#entities/spriteAction'
|
import { SpriteAction } from '#entities/spriteAction'
|
||||||
import { Tile } from '#entities/tile'
|
import { Tile } from '#entities/tile'
|
||||||
import { User } from '#entities/user'
|
import { User } from '#entities/user'
|
||||||
import { Zone } from '#entities/zone'
|
|
||||||
import { ZoneEffect } from '#entities/zoneEffect'
|
|
||||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||||
import ZoneRepository from '#repositories/zoneRepository'
|
import MapRepository from '#repositories/mapRepository'
|
||||||
|
|
||||||
// @TODO : Replace this with seeding
|
// @TODO : Replace this with seeding
|
||||||
// https://mikro-orm.io/docs/seeding
|
// https://mikro-orm.io/docs/seeding
|
||||||
|
|
||||||
export default class InitCommand extends BaseCommand {
|
export default class InitCommand extends BaseCommand {
|
||||||
|
private readonly mapRepository = new MapRepository()
|
||||||
|
private readonly characterTypeRepository = new CharacterTypeRepository()
|
||||||
|
private readonly characterHairRepository = new CharacterHairRepository()
|
||||||
|
|
||||||
public async execute(): Promise<void> {
|
public async execute(): Promise<void> {
|
||||||
// Assets
|
// Assets
|
||||||
await this.importTiles()
|
await this.importTiles()
|
||||||
await this.importObjects()
|
await this.importMapObjects()
|
||||||
await this.createCharacterType()
|
await this.createCharacterType()
|
||||||
await this.createCharacterHair()
|
await this.createCharacterHair()
|
||||||
// await this.createCharacterEquipment()
|
// await this.createCharacterEquipment()
|
||||||
|
|
||||||
// Zone
|
// Map
|
||||||
await this.createZone()
|
await this.createMap()
|
||||||
|
|
||||||
// User
|
// User
|
||||||
await this.createUser()
|
await this.createUser()
|
||||||
@ -51,19 +55,19 @@ export default class InitCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importObjects(): Promise<void> {
|
private async importMapObjects(): Promise<void> {
|
||||||
for (const object of fs.readdirSync(Storage.getPublicPath('objects'))) {
|
for (const mapObject of fs.readdirSync(Storage.getPublicPath('map_objects'))) {
|
||||||
const newMapObject = new MapObject()
|
const newMapObject = new MapObject()
|
||||||
newMapObject
|
newMapObject
|
||||||
.setId(object.split('.')[0] as UUID)
|
.setId(mapObject.split('.')[0] as UUID)
|
||||||
.setName('New object')
|
.setName('New map object')
|
||||||
.setFrameWidth(
|
.setFrameWidth(
|
||||||
(await sharp(Storage.getPublicPath('objects', object))
|
(await sharp(Storage.getPublicPath('map_objects', mapObject))
|
||||||
.metadata()
|
.metadata()
|
||||||
.then((metadata) => metadata.height)) ?? 0
|
.then((metadata) => metadata.height)) ?? 0
|
||||||
)
|
)
|
||||||
.setFrameHeight(
|
.setFrameHeight(
|
||||||
(await sharp(Storage.getPublicPath('objects', object))
|
(await sharp(Storage.getPublicPath('map_objects', mapObject))
|
||||||
.metadata()
|
.metadata()
|
||||||
.then((metadata) => metadata.width)) ?? 0
|
.then((metadata) => metadata.width)) ?? 0
|
||||||
)
|
)
|
||||||
@ -148,7 +152,14 @@ export default class InitCommand extends BaseCommand {
|
|||||||
.save()
|
.save()
|
||||||
|
|
||||||
const characterType = new CharacterType()
|
const characterType = new CharacterType()
|
||||||
await characterType.setId('75b70c78-17f0-44c0-a4fa-15043cb95be0').setName('New character type').setGender(CharacterGender.MALE).setRace(CharacterRace.HUMAN).setIsSelectable(true).setSprite(characterSprite).save()
|
await characterType
|
||||||
|
.setId('75b70c78-17f0-44c0-a4fa-15043cb95be0')
|
||||||
|
.setName('New character type')
|
||||||
|
.setGender(CharacterGender.MALE)
|
||||||
|
.setRace(CharacterRace.HUMAN)
|
||||||
|
.setIsSelectable(true)
|
||||||
|
.setSprite(characterSprite)
|
||||||
|
.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createCharacterHair(): Promise<void> {
|
private async createCharacterHair(): Promise<void> {
|
||||||
@ -224,17 +235,17 @@ export default class InitCommand extends BaseCommand {
|
|||||||
await equipmentSprite.save()
|
await equipmentSprite.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createZone(): Promise<void> {
|
private async createMap(): Promise<void> {
|
||||||
const zone = new Zone()
|
const map = new Map()
|
||||||
await zone
|
await map
|
||||||
.setName('New zone')
|
.setName('New map')
|
||||||
.setWidth(100)
|
.setWidth(100)
|
||||||
.setHeight(100)
|
.setHeight(100)
|
||||||
.setTiles(Array.from({ length: 100 }, () => Array.from({ length: 100 }, () => 'a2fd8d6f-5042-437a-9c1e-c66b91ecc35b')))
|
.setTiles(Array.from({ length: 100 }, () => Array.from({ length: 100 }, () => 'a2fd8d6f-5042-437a-9c1e-c66b91ecc35b')))
|
||||||
.save()
|
.save()
|
||||||
|
|
||||||
const effect = new ZoneEffect()
|
const effect = new MapEffect()
|
||||||
await effect.setEffect('light').setStrength(100).setZone(zone).save()
|
await effect.setEffect('light').setStrength(100).setMap(map).save()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createUser(): Promise<void> {
|
private async createUser(): Promise<void> {
|
||||||
@ -247,9 +258,9 @@ export default class InitCommand extends BaseCommand {
|
|||||||
.setUser(user)
|
.setUser(user)
|
||||||
.setName('root')
|
.setName('root')
|
||||||
.setRole('gm')
|
.setRole('gm')
|
||||||
.setZone((await ZoneRepository.getFirst())!)
|
.setMap((await this.mapRepository.getFirst())!)
|
||||||
.setCharacterType((await CharacterTypeRepository.getFirst()) ?? undefined)
|
.setCharacterType((await this.characterTypeRepository.getFirst()) ?? undefined)
|
||||||
.setCharacterHair((await CharacterHairRepository.getFirst()) ?? undefined)
|
.setCharacterHair((await this.characterHairRepository.getFirst()) ?? undefined)
|
||||||
.save()
|
.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/commands/listMaps.ts
Normal file
10
src/commands/listMaps.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { BaseCommand } from '#application/base/baseCommand'
|
||||||
|
import MapManager from '#managers/mapManager'
|
||||||
|
|
||||||
|
type CommandInput = string[]
|
||||||
|
|
||||||
|
export default class ListMapsCommand extends BaseCommand {
|
||||||
|
public execute(input: CommandInput): void {
|
||||||
|
console.log(MapManager.getLoadedMaps())
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +0,0 @@
|
|||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import { BaseCommand } from '#application/base/baseCommand'
|
|
||||||
import ZoneManager from '#managers/zoneManager'
|
|
||||||
|
|
||||||
type CommandInput = string[]
|
|
||||||
|
|
||||||
export default class ListZonesCommand extends BaseCommand {
|
|
||||||
public execute(input: CommandInput): void {
|
|
||||||
console.log(ZoneManager.getLoadedZones())
|
|
||||||
}
|
|
||||||
}
|
|
296
src/entities/base/character.ts
Normal file
296
src/entities/base/character.ts
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { CharacterEquipment } from '#entities/characterEquipment'
|
||||||
|
import { CharacterHair } from '#entities/characterHair'
|
||||||
|
import { CharacterItem } from '#entities/characterItem'
|
||||||
|
import { CharacterType } from '#entities/characterType'
|
||||||
|
import { Chat } from '#entities/chat'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import { User } from '#entities/user'
|
||||||
|
|
||||||
|
|
||||||
|
export class BaseCharacter extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
user!: User
|
||||||
|
|
||||||
|
@Property({ unique: true })
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
online = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
role = 'player'
|
||||||
|
|
||||||
|
@OneToMany(() => Chat, (chat) => chat.character)
|
||||||
|
chats = new Collection<Chat>(this)
|
||||||
|
|
||||||
|
// Position - @TODO: Update to spawn point when current map is not found
|
||||||
|
@ManyToOne()
|
||||||
|
map!: Map
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
positionX = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
positionY = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
rotation = 0
|
||||||
|
|
||||||
|
// Customization
|
||||||
|
@ManyToOne({ deleteRule: 'set null' })
|
||||||
|
characterType?: CharacterType | null | undefined
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'set null' })
|
||||||
|
characterHair?: CharacterHair | null | undefined
|
||||||
|
|
||||||
|
// Inventory
|
||||||
|
@OneToMany({ mappedBy: 'character' })
|
||||||
|
items = new Collection<CharacterItem>(this)
|
||||||
|
|
||||||
|
@OneToMany({ mappedBy: 'character' })
|
||||||
|
equipment = new Collection<CharacterEquipment>(this)
|
||||||
|
|
||||||
|
// Stats
|
||||||
|
@Property()
|
||||||
|
alignment = 50
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
hitpoints = 100
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
mana = 100
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
level = 1
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
experience = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
strength = 10
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
dexterity = 10
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
intelligence = 10
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
wisdom = 10
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setUser(user: User) {
|
||||||
|
this.user = user
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUser() {
|
||||||
|
return this.user
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setOnline(online: boolean) {
|
||||||
|
this.online = online
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOnline() {
|
||||||
|
return this.online
|
||||||
|
}
|
||||||
|
|
||||||
|
setRole(role: string) {
|
||||||
|
this.role = role
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getRole() {
|
||||||
|
return this.role
|
||||||
|
}
|
||||||
|
|
||||||
|
setChats(chats: Collection<Chat>) {
|
||||||
|
this.chats = chats
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getChats() {
|
||||||
|
return this.chats
|
||||||
|
}
|
||||||
|
|
||||||
|
setMap(map: Map) {
|
||||||
|
this.map = map
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMap() {
|
||||||
|
return this.map
|
||||||
|
}
|
||||||
|
|
||||||
|
setPositionX(positionX: number) {
|
||||||
|
this.positionX = positionX
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPositionX() {
|
||||||
|
return this.positionX
|
||||||
|
}
|
||||||
|
|
||||||
|
setPositionY(positionY: number) {
|
||||||
|
this.positionY = positionY
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPositionY() {
|
||||||
|
return this.positionY
|
||||||
|
}
|
||||||
|
|
||||||
|
setRotation(rotation: number) {
|
||||||
|
this.rotation = rotation
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getRotation() {
|
||||||
|
return this.rotation
|
||||||
|
}
|
||||||
|
|
||||||
|
setCharacterType(characterType: CharacterType | null | undefined) {
|
||||||
|
this.characterType = characterType
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCharacterType() {
|
||||||
|
return this.characterType
|
||||||
|
}
|
||||||
|
|
||||||
|
setCharacterHair(characterHair: CharacterHair | null | undefined) {
|
||||||
|
this.characterHair = characterHair
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCharacterHair() {
|
||||||
|
return this.characterHair
|
||||||
|
}
|
||||||
|
|
||||||
|
setItems(items: Collection<CharacterItem>) {
|
||||||
|
this.items = items
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getItems() {
|
||||||
|
return this.items
|
||||||
|
}
|
||||||
|
|
||||||
|
setEquipment(equipment: Collection<CharacterEquipment>) {
|
||||||
|
this.equipment = equipment
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getEquipment() {
|
||||||
|
return this.equipment
|
||||||
|
}
|
||||||
|
|
||||||
|
setAlignment(alignment: number) {
|
||||||
|
this.alignment = alignment
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getAlignment() {
|
||||||
|
return this.alignment
|
||||||
|
}
|
||||||
|
|
||||||
|
setHitpoints(hitpoints: number) {
|
||||||
|
this.hitpoints = hitpoints
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getHitpoints() {
|
||||||
|
return this.hitpoints
|
||||||
|
}
|
||||||
|
|
||||||
|
setMana(mana: number) {
|
||||||
|
this.mana = mana
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMana() {
|
||||||
|
return this.mana
|
||||||
|
}
|
||||||
|
|
||||||
|
setLevel(level: number) {
|
||||||
|
this.level = level
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getLevel() {
|
||||||
|
return this.level
|
||||||
|
}
|
||||||
|
|
||||||
|
setExperience(experience: number) {
|
||||||
|
this.experience = experience
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getExperience() {
|
||||||
|
return this.experience
|
||||||
|
}
|
||||||
|
|
||||||
|
setStrength(strength: number) {
|
||||||
|
this.strength = strength
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getStrength() {
|
||||||
|
return this.strength
|
||||||
|
}
|
||||||
|
|
||||||
|
setDexterity(dexterity: number) {
|
||||||
|
this.dexterity = dexterity
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getDexterity() {
|
||||||
|
return this.dexterity
|
||||||
|
}
|
||||||
|
|
||||||
|
setIntelligence(intelligence: number) {
|
||||||
|
this.intelligence = intelligence
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIntelligence() {
|
||||||
|
return this.intelligence
|
||||||
|
}
|
||||||
|
|
||||||
|
setWisdom(wisdom: number) {
|
||||||
|
this.wisdom = wisdom
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getWisdom() {
|
||||||
|
return this.wisdom
|
||||||
|
}
|
||||||
|
}
|
60
src/entities/base/characterEquipment.ts
Normal file
60
src/entities/base/characterEquipment.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Enum, ManyToOne, PrimaryKey } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { CharacterEquipmentSlotType } from '#application/enums'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Character } from '#entities/character'
|
||||||
|
import { CharacterItem } from '#entities/characterItem'
|
||||||
|
|
||||||
|
export class BaseCharacterEquipment extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Enum(() => CharacterEquipmentSlotType)
|
||||||
|
slot!: CharacterEquipmentSlotType
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
character!: Character
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
characterItem!: CharacterItem
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setSlot(slot: CharacterEquipmentSlotType) {
|
||||||
|
this.slot = slot
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getSlot() {
|
||||||
|
return this.slot
|
||||||
|
}
|
||||||
|
|
||||||
|
setCharacter(character: Character) {
|
||||||
|
this.character = character
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCharacter() {
|
||||||
|
return this.character
|
||||||
|
}
|
||||||
|
|
||||||
|
setCharacterItem(characterItem: CharacterItem) {
|
||||||
|
this.characterItem = characterItem
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCharacterItem() {
|
||||||
|
return this.characterItem
|
||||||
|
}
|
||||||
|
}
|
72
src/entities/base/characterHair.ts
Normal file
72
src/entities/base/characterHair.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { CharacterGender } from '#application/enums'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Character } from '#entities/character'
|
||||||
|
import { Sprite } from '#entities/sprite'
|
||||||
|
|
||||||
|
export class BaseCharacterHair extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
gender: CharacterGender = CharacterGender.MALE
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isSelectable = false
|
||||||
|
|
||||||
|
@ManyToOne()
|
||||||
|
sprite?: Sprite
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setGender(gender: CharacterGender) {
|
||||||
|
this.gender = gender
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getGender() {
|
||||||
|
return this.gender
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSelectable(isSelectable: boolean) {
|
||||||
|
this.isSelectable = isSelectable
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsSelectable() {
|
||||||
|
return this.isSelectable
|
||||||
|
}
|
||||||
|
|
||||||
|
setSprite(sprite: Sprite) {
|
||||||
|
this.sprite = sprite
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getSprite() {
|
||||||
|
return this.sprite
|
||||||
|
}
|
||||||
|
}
|
60
src/entities/base/characterItem.ts
Normal file
60
src/entities/base/characterItem.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Character } from '#entities/character'
|
||||||
|
import { CharacterEquipment } from '#entities/characterEquipment'
|
||||||
|
import { Item } from '#entities/item'
|
||||||
|
|
||||||
|
|
||||||
|
export class BaseCharacterItem extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
character!: Character
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
item!: Item
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
quantity!: number
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setCharacter(character: Character) {
|
||||||
|
this.character = character
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCharacter() {
|
||||||
|
return this.character
|
||||||
|
}
|
||||||
|
|
||||||
|
setItem(item: Item) {
|
||||||
|
this.item = item
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getItem() {
|
||||||
|
return this.item
|
||||||
|
}
|
||||||
|
|
||||||
|
setQuantity(quantity: number) {
|
||||||
|
this.quantity = quantity
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getQuantity() {
|
||||||
|
return this.quantity
|
||||||
|
}
|
||||||
|
}
|
108
src/entities/base/characterType.ts
Normal file
108
src/entities/base/characterType.ts
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { CharacterGender, CharacterRace } from '#application/enums'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Character } from '#entities/character'
|
||||||
|
import { Sprite } from '#entities/sprite'
|
||||||
|
|
||||||
|
export class BaseCharacterType extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@Enum(() => CharacterGender)
|
||||||
|
gender!: CharacterGender
|
||||||
|
|
||||||
|
@Enum(() => CharacterRace)
|
||||||
|
race!: CharacterRace
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isSelectable = false
|
||||||
|
|
||||||
|
@ManyToOne()
|
||||||
|
sprite?: Sprite
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
updatedAt = new Date()
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setGender(gender: CharacterGender) {
|
||||||
|
this.gender = gender
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getGender() {
|
||||||
|
return this.gender
|
||||||
|
}
|
||||||
|
|
||||||
|
setRace(race: CharacterRace) {
|
||||||
|
this.race = race
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getRace() {
|
||||||
|
return this.race
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSelectable(isSelectable: boolean) {
|
||||||
|
this.isSelectable = isSelectable
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsSelectable() {
|
||||||
|
return this.isSelectable
|
||||||
|
}
|
||||||
|
|
||||||
|
setSprite(sprite: Sprite) {
|
||||||
|
this.sprite = sprite
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getSprite() {
|
||||||
|
return this.sprite
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatedAt(updatedAt: Date) {
|
||||||
|
this.updatedAt = updatedAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdatedAt() {
|
||||||
|
return this.updatedAt
|
||||||
|
}
|
||||||
|
}
|
71
src/entities/base/chat.ts
Normal file
71
src/entities/base/chat.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Character } from '#entities/character'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
|
||||||
|
|
||||||
|
export class BaseChat extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
character!: Character
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
map!: Map
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
message!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setCharacter(character: Character) {
|
||||||
|
this.character = character
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCharacter() {
|
||||||
|
return this.character
|
||||||
|
}
|
||||||
|
|
||||||
|
setMap(map: Map) {
|
||||||
|
this.map = map
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMap() {
|
||||||
|
return this.map
|
||||||
|
}
|
||||||
|
|
||||||
|
setMessage(message: string) {
|
||||||
|
this.message = message
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMessage() {
|
||||||
|
return this.message
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
}
|
120
src/entities/base/item.ts
Normal file
120
src/entities/base/item.ts
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { ItemType, ItemRarity } from '#application/enums'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { CharacterItem } from '#entities/characterItem'
|
||||||
|
import { Sprite } from '#entities/sprite'
|
||||||
|
|
||||||
|
export class BaseItem extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
description: string = ''
|
||||||
|
|
||||||
|
@Enum(() => ItemType)
|
||||||
|
itemType!: ItemType
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
stackable = false
|
||||||
|
|
||||||
|
@Enum(() => ItemRarity)
|
||||||
|
rarity: ItemRarity = ItemRarity.COMMON
|
||||||
|
|
||||||
|
@ManyToOne(() => Sprite)
|
||||||
|
sprite?: Sprite
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
updatedAt = new Date()
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setDescription(description: string) {
|
||||||
|
this.description = description
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getDescription() {
|
||||||
|
return this.description
|
||||||
|
}
|
||||||
|
|
||||||
|
setItemType(itemType: ItemType) {
|
||||||
|
this.itemType = itemType
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getItemType() {
|
||||||
|
return this.itemType
|
||||||
|
}
|
||||||
|
|
||||||
|
setStackable(stackable: boolean) {
|
||||||
|
this.stackable = stackable
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getStackable() {
|
||||||
|
return this.stackable
|
||||||
|
}
|
||||||
|
|
||||||
|
setRarity(rarity: ItemRarity) {
|
||||||
|
this.rarity = rarity
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getRarity() {
|
||||||
|
return this.rarity
|
||||||
|
}
|
||||||
|
|
||||||
|
setSprite(sprite: Sprite) {
|
||||||
|
this.sprite = sprite
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getSprite() {
|
||||||
|
return this.sprite
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatedAt(updatedAt: Date) {
|
||||||
|
this.updatedAt = updatedAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdatedAt() {
|
||||||
|
return this.updatedAt
|
||||||
|
}
|
||||||
|
}
|
143
src/entities/base/map.ts
Normal file
143
src/entities/base/map.ts
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { MapEffect } from '#entities/mapEffect'
|
||||||
|
import { MapEventTile } from '#entities/mapEventTile'
|
||||||
|
import { PlacedMapObject } from '#entities/placedMapObject'
|
||||||
|
|
||||||
|
export class BaseMap extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
width = 10
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
height = 10
|
||||||
|
|
||||||
|
@Property({ type: 'json', nullable: true })
|
||||||
|
tiles?: any
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
pvp = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
updatedAt = new Date()
|
||||||
|
|
||||||
|
@OneToMany(() => MapEffect, (effect) => effect.map, { orphanRemoval: true })
|
||||||
|
mapEffects = new Collection<MapEffect>(this)
|
||||||
|
|
||||||
|
@OneToMany(() => MapEventTile, (tile) => tile.map, { orphanRemoval: true })
|
||||||
|
mapEventTiles = new Collection<MapEventTile>(this)
|
||||||
|
|
||||||
|
@OneToMany(() => PlacedMapObject, (placedMapObject) => placedMapObject.map, { orphanRemoval: true })
|
||||||
|
placedMapObjects = new Collection<PlacedMapObject>(this)
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setWidth(width: number) {
|
||||||
|
this.width = width
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getWidth() {
|
||||||
|
return this.width
|
||||||
|
}
|
||||||
|
|
||||||
|
setHeight(height: number) {
|
||||||
|
this.height = height
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getHeight() {
|
||||||
|
return this.height
|
||||||
|
}
|
||||||
|
|
||||||
|
setTiles(tiles: any) {
|
||||||
|
this.tiles = tiles
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getTiles() {
|
||||||
|
return this.tiles
|
||||||
|
}
|
||||||
|
|
||||||
|
setPvp(pvp: boolean) {
|
||||||
|
this.pvp = pvp
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPvp() {
|
||||||
|
return this.pvp
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatedAt(updatedAt: Date) {
|
||||||
|
this.updatedAt = updatedAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdatedAt() {
|
||||||
|
return this.updatedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
setMapEffects(mapEffects: Collection<MapEffect>) {
|
||||||
|
this.mapEffects = mapEffects
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMapEffects() {
|
||||||
|
return this.mapEffects
|
||||||
|
}
|
||||||
|
|
||||||
|
setMapEventTiles(mapEventTiles: Collection<MapEventTile>) {
|
||||||
|
this.mapEventTiles = mapEventTiles
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMapEventTiles() {
|
||||||
|
return this.mapEventTiles
|
||||||
|
}
|
||||||
|
|
||||||
|
setPlacedMapObjects(placedMapObjects: Collection<PlacedMapObject>) {
|
||||||
|
this.placedMapObjects = placedMapObjects
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPlacedMapObjects() {
|
||||||
|
return this.placedMapObjects
|
||||||
|
}
|
||||||
|
}
|
@ -2,18 +2,17 @@ import { randomUUID } from 'node:crypto'
|
|||||||
|
|
||||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Zone } from './zone'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
|
||||||
@Entity()
|
export class BaseMapEffect extends BaseEntity {
|
||||||
export class ZoneEffect extends BaseEntity {
|
|
||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id = randomUUID()
|
id = randomUUID()
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
zone!: Zone
|
map!: Map
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
effect!: string
|
effect!: string
|
||||||
@ -30,13 +29,13 @@ export class ZoneEffect extends BaseEntity {
|
|||||||
return this.id
|
return this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
setZone(zone: Zone) {
|
setMap(map: Map) {
|
||||||
this.zone = zone
|
this.map = map
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
getZone() {
|
getMap() {
|
||||||
return this.zone
|
return this.map
|
||||||
}
|
}
|
||||||
|
|
||||||
setEffect(effect: string) {
|
setEffect(effect: string) {
|
@ -2,23 +2,22 @@ import { randomUUID } from 'node:crypto'
|
|||||||
|
|
||||||
import { Entity, Enum, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { Entity, Enum, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Zone } from './zone'
|
|
||||||
import { ZoneEventTileTeleport } from './zoneEventTileTeleport'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
import { ZoneEventTileType } from '#application/enums'
|
import { MapEventTileType } from '#application/enums'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
||||||
|
|
||||||
@Entity()
|
export class BaseMapEventTile extends BaseEntity {
|
||||||
export class ZoneEventTile extends BaseEntity {
|
|
||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id = randomUUID()
|
id = randomUUID()
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
zone!: Zone
|
map!: Map
|
||||||
|
|
||||||
@Enum(() => ZoneEventTileType)
|
@Enum(() => MapEventTileType)
|
||||||
type!: ZoneEventTileType
|
type!: MapEventTileType
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
positionX!: number
|
positionX!: number
|
||||||
@ -26,8 +25,8 @@ export class ZoneEventTile extends BaseEntity {
|
|||||||
@Property()
|
@Property()
|
||||||
positionY!: number
|
positionY!: number
|
||||||
|
|
||||||
@OneToOne(() => ZoneEventTileTeleport, (teleport) => teleport.zoneEventTile)
|
@OneToOne(() => MapEventTileTeleport, (teleport) => teleport.mapEventTile, { eager: true })
|
||||||
teleport?: ZoneEventTileTeleport
|
teleport?: MapEventTileTeleport
|
||||||
|
|
||||||
setId(id: UUID) {
|
setId(id: UUID) {
|
||||||
this.id = id
|
this.id = id
|
||||||
@ -38,16 +37,16 @@ export class ZoneEventTile extends BaseEntity {
|
|||||||
return this.id
|
return this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
setZone(zone: Zone) {
|
setMap(map: Map) {
|
||||||
this.zone = zone
|
this.map = map
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
getZone() {
|
getMap() {
|
||||||
return this.zone
|
return this.map
|
||||||
}
|
}
|
||||||
|
|
||||||
setType(type: ZoneEventTileType) {
|
setType(type: MapEventTileType) {
|
||||||
this.type = type
|
this.type = type
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -74,7 +73,7 @@ export class ZoneEventTile extends BaseEntity {
|
|||||||
return this.positionY
|
return this.positionY
|
||||||
}
|
}
|
||||||
|
|
||||||
setTeleport(teleport: ZoneEventTileTeleport) {
|
setTeleport(teleport: MapEventTileTeleport) {
|
||||||
this.teleport = teleport
|
this.teleport = teleport
|
||||||
return this
|
return this
|
||||||
}
|
}
|
@ -2,22 +2,21 @@ import { randomUUID } from 'node:crypto'
|
|||||||
|
|
||||||
import { Entity, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { Entity, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Zone } from './zone'
|
|
||||||
import { ZoneEventTile } from './zoneEventTile'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import { MapEventTile } from '#entities/mapEventTile'
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export class ZoneEventTileTeleport extends BaseEntity {
|
export class BaseMapEventTileTeleport extends BaseEntity {
|
||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id = randomUUID()
|
id = randomUUID()
|
||||||
|
|
||||||
@OneToOne({ deleteRule: 'cascade' })
|
@OneToOne({ deleteRule: 'cascade' })
|
||||||
zoneEventTile!: ZoneEventTile
|
mapEventTile!: MapEventTile
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
@ManyToOne({ deleteRule: 'cascade', eager: true })
|
||||||
toZone!: Zone
|
toMap!: Map
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
toRotation!: number
|
toRotation!: number
|
||||||
@ -37,22 +36,22 @@ export class ZoneEventTileTeleport extends BaseEntity {
|
|||||||
return this.id
|
return this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
setZoneEventTile(zoneEventTile: ZoneEventTile) {
|
setMapEventTile(mapEventTile: MapEventTile) {
|
||||||
this.zoneEventTile = zoneEventTile
|
this.mapEventTile = mapEventTile
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
getZoneEventTile() {
|
getMapEventTile() {
|
||||||
return this.zoneEventTile
|
return this.mapEventTile
|
||||||
}
|
}
|
||||||
|
|
||||||
setToZone(toZone: Zone) {
|
setToMap(toMap: Map) {
|
||||||
this.toZone = toZone
|
this.toMap = toMap
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
getToZone() {
|
getToMap() {
|
||||||
return this.toZone
|
return this.toMap
|
||||||
}
|
}
|
||||||
|
|
||||||
setToRotation(toRotation: number) {
|
setToRotation(toRotation: number) {
|
140
src/entities/base/mapObject.ts
Normal file
140
src/entities/base/mapObject.ts
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
|
||||||
|
export class BaseMapObject extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@Property({ type: 'json', nullable: true })
|
||||||
|
tags?: any
|
||||||
|
|
||||||
|
@Property({ type: 'decimal', precision: 10, scale: 2 })
|
||||||
|
originX = 0
|
||||||
|
|
||||||
|
@Property({ type: 'decimal', precision: 10, scale: 2 })
|
||||||
|
originY = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isAnimated = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
frameRate = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
frameWidth = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
frameHeight = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
updatedAt = new Date()
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setTags(tags: any) {
|
||||||
|
this.tags = tags
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getTags() {
|
||||||
|
return this.tags
|
||||||
|
}
|
||||||
|
|
||||||
|
setOriginX(originX: number) {
|
||||||
|
this.originX = originX
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOriginX() {
|
||||||
|
return this.originX
|
||||||
|
}
|
||||||
|
|
||||||
|
setOriginY(originY: number) {
|
||||||
|
this.originY = originY
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOriginY() {
|
||||||
|
return this.originY
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsAnimated(isAnimated: boolean) {
|
||||||
|
this.isAnimated = isAnimated
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsAnimated() {
|
||||||
|
return this.isAnimated
|
||||||
|
}
|
||||||
|
|
||||||
|
setFrameRate(frameRate: number) {
|
||||||
|
this.frameRate = frameRate
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getFrameRate() {
|
||||||
|
return this.frameRate
|
||||||
|
}
|
||||||
|
|
||||||
|
setFrameWidth(frameWidth: number) {
|
||||||
|
this.frameWidth = frameWidth
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getFrameWidth() {
|
||||||
|
return this.frameWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
setFrameHeight(frameHeight: number) {
|
||||||
|
this.frameHeight = frameHeight
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getFrameHeight() {
|
||||||
|
return this.frameHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatedAt(updatedAt: Date) {
|
||||||
|
this.updatedAt = updatedAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdatedAt() {
|
||||||
|
return this.updatedAt
|
||||||
|
}
|
||||||
|
}
|
58
src/entities/base/passwordResetToken.ts
Normal file
58
src/entities/base/passwordResetToken.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { User } from '#entities/user'
|
||||||
|
|
||||||
|
export class BasePasswordResetToken extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
user!: User
|
||||||
|
|
||||||
|
@Property({ unique: true })
|
||||||
|
token!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setUser(user: User) {
|
||||||
|
this.user = user
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUser() {
|
||||||
|
return this.user
|
||||||
|
}
|
||||||
|
|
||||||
|
setToken(token: string) {
|
||||||
|
this.token = token
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getToken() {
|
||||||
|
return this.token
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
}
|
@ -2,22 +2,22 @@ import { randomUUID } from 'node:crypto'
|
|||||||
|
|
||||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Zone } from './zone'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
import { MapObject } from '#entities/mapObject'
|
import { MapObject } from '#entities/mapObject'
|
||||||
|
|
||||||
//@TODO : Rename mapObject
|
//@TODO : Rename mapObject
|
||||||
@Entity()
|
|
||||||
export class ZoneObject extends BaseEntity {
|
export class BasePlacedMapObject extends BaseEntity {
|
||||||
@PrimaryKey()
|
@PrimaryKey()
|
||||||
id = randomUUID()
|
id = randomUUID()
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
zone!: Zone
|
map!: Map
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
@ManyToOne({ deleteRule: 'cascade', eager: true })
|
||||||
mapObject!: MapObject
|
mapObject!: MapObject
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
@ -41,13 +41,13 @@ export class ZoneObject extends BaseEntity {
|
|||||||
return this.id
|
return this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
setZone(zone: Zone) {
|
setMap(map: Map) {
|
||||||
this.zone = zone
|
this.map = map
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
getZone() {
|
getMap() {
|
||||||
return this.zone
|
return this.map
|
||||||
}
|
}
|
||||||
|
|
||||||
setMapObject(mapObject: MapObject) {
|
setMapObject(mapObject: MapObject) {
|
70
src/entities/base/sprite.ts
Normal file
70
src/entities/base/sprite.ts
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { SpriteAction } from '#entities/spriteAction'
|
||||||
|
|
||||||
|
export class BaseSprite extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@OneToMany(() => SpriteAction, (action) => action.sprite)
|
||||||
|
spriteActions = new Collection<SpriteAction>(this)
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
updatedAt = new Date()
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setSpriteActions(spriteActions: Collection<SpriteAction>) {
|
||||||
|
this.spriteActions = spriteActions
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getSpriteActions() {
|
||||||
|
return this.spriteActions
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatedAt(updatedAt: Date) {
|
||||||
|
this.updatedAt = updatedAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdatedAt() {
|
||||||
|
return this.updatedAt
|
||||||
|
}
|
||||||
|
}
|
142
src/entities/base/spriteAction.ts
Normal file
142
src/entities/base/spriteAction.ts
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Sprite } from '#entities/sprite'
|
||||||
|
|
||||||
|
export class BaseSpriteAction extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
sprite!: Sprite
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
action!: string
|
||||||
|
|
||||||
|
@Property({ type: 'json', nullable: true })
|
||||||
|
sprites?: string[]
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
originX = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
originY = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isAnimated = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isLooping = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
frameWidth = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
frameHeight = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
frameRate = 0
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setSprite(sprite: Sprite) {
|
||||||
|
this.sprite = sprite
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getSprite() {
|
||||||
|
return this.sprite
|
||||||
|
}
|
||||||
|
|
||||||
|
setAction(action: string) {
|
||||||
|
this.action = action
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getAction() {
|
||||||
|
return this.action
|
||||||
|
}
|
||||||
|
|
||||||
|
setSprites(sprites: string[]) {
|
||||||
|
this.sprites = sprites
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getSprites() {
|
||||||
|
return this.sprites
|
||||||
|
}
|
||||||
|
|
||||||
|
setOriginX(originX: number) {
|
||||||
|
this.originX = originX
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOriginX() {
|
||||||
|
return this.originX
|
||||||
|
}
|
||||||
|
|
||||||
|
setOriginY(originY: number) {
|
||||||
|
this.originY = originY
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOriginY() {
|
||||||
|
return this.originY
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsAnimated(isAnimated: boolean) {
|
||||||
|
this.isAnimated = isAnimated
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsAnimated() {
|
||||||
|
return this.isAnimated
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLooping(isLooping: boolean) {
|
||||||
|
this.isLooping = isLooping
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsLooping() {
|
||||||
|
return this.isLooping
|
||||||
|
}
|
||||||
|
|
||||||
|
setFrameWidth(frameWidth: number) {
|
||||||
|
this.frameWidth = frameWidth
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getFrameWidth() {
|
||||||
|
return this.frameWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
setFrameHeight(frameHeight: number) {
|
||||||
|
this.frameHeight = frameHeight
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getFrameHeight() {
|
||||||
|
return this.frameHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
setFrameRate(frameRate: number) {
|
||||||
|
this.frameRate = frameRate
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getFrameRate() {
|
||||||
|
return this.frameRate
|
||||||
|
}
|
||||||
|
}
|
68
src/entities/base/tile.ts
Normal file
68
src/entities/base/tile.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
|
||||||
|
export class BaseTile extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
name!: string
|
||||||
|
|
||||||
|
@Property({ type: 'json', nullable: true })
|
||||||
|
tags?: any
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
createdAt = new Date()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
updatedAt = new Date()
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setName(name: string) {
|
||||||
|
this.name = name
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
setTags(tags: any) {
|
||||||
|
this.tags = tags
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getTags() {
|
||||||
|
return this.tags
|
||||||
|
}
|
||||||
|
|
||||||
|
setCreatedAt(createdAt: Date) {
|
||||||
|
this.createdAt = createdAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCreatedAt() {
|
||||||
|
return this.createdAt
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatedAt(updatedAt: Date) {
|
||||||
|
this.updatedAt = updatedAt
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdatedAt() {
|
||||||
|
return this.updatedAt
|
||||||
|
}
|
||||||
|
}
|
97
src/entities/base/user.ts
Normal file
97
src/entities/base/user.ts
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
import bcrypt from 'bcryptjs'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Character } from '#entities/character'
|
||||||
|
import { PasswordResetToken } from '#entities/passwordResetToken'
|
||||||
|
|
||||||
|
|
||||||
|
export class BaseUser extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@Property({ unique: true })
|
||||||
|
username!: string
|
||||||
|
|
||||||
|
@Property({ unique: true })
|
||||||
|
email!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
password!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
online = false
|
||||||
|
|
||||||
|
@OneToMany(() => Character, (character) => character.user)
|
||||||
|
characters = new Collection<Character>(this)
|
||||||
|
|
||||||
|
@OneToMany(() => PasswordResetToken, (token) => token.user)
|
||||||
|
passwordResetTokens = new Collection<PasswordResetToken>(this)
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setUsername(username: string) {
|
||||||
|
this.username = username
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getUsername() {
|
||||||
|
return this.username
|
||||||
|
}
|
||||||
|
|
||||||
|
setEmail(email: string) {
|
||||||
|
this.email = email
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getEmail() {
|
||||||
|
return this.email
|
||||||
|
}
|
||||||
|
|
||||||
|
setPassword(password: string) {
|
||||||
|
this.password = bcrypt.hashSync(password, 10)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPassword() {
|
||||||
|
return this.password
|
||||||
|
}
|
||||||
|
|
||||||
|
setOnline(online: boolean) {
|
||||||
|
this.online = online
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOnline() {
|
||||||
|
return this.online
|
||||||
|
}
|
||||||
|
|
||||||
|
setCharacters(characters: Collection<Character>) {
|
||||||
|
this.characters = characters
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCharacters() {
|
||||||
|
return this.characters
|
||||||
|
}
|
||||||
|
|
||||||
|
setPasswordResetTokens(passwordResetTokens: Collection<PasswordResetToken>) {
|
||||||
|
this.passwordResetTokens = passwordResetTokens
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPasswordResetTokens() {
|
||||||
|
return this.passwordResetTokens
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}
|
65
src/entities/base/world.ts
Normal file
65
src/entities/base/world.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
|
||||||
|
export class BaseWorld extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
date = new Date()
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isRainEnabled = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
rainPercentage = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isFogEnabled = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
fogDensity = 0
|
||||||
|
|
||||||
|
setDate(date: Date) {
|
||||||
|
this.date = date
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getDate() {
|
||||||
|
return this.date
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsRainEnabled(isRainEnabled: boolean) {
|
||||||
|
this.isRainEnabled = isRainEnabled
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsRainEnabled() {
|
||||||
|
return this.isRainEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
setRainPercentage(rainPercentage: number) {
|
||||||
|
this.rainPercentage = rainPercentage
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getRainPercentage() {
|
||||||
|
return this.rainPercentage
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsFogEnabled(isFogEnabled: boolean) {
|
||||||
|
this.isFogEnabled = isFogEnabled
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsFogEnabled() {
|
||||||
|
return this.isFogEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
setFogDensity(fogDensity: number) {
|
||||||
|
this.fogDensity = fogDensity
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getFogDensity() {
|
||||||
|
return this.fogDensity
|
||||||
|
}
|
||||||
|
}
|
@ -1,297 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseCharacter } from '#entities/base/character'
|
||||||
|
|
||||||
import { CharacterEquipment } from './characterEquipment'
|
|
||||||
import { CharacterHair } from './characterHair'
|
|
||||||
import { CharacterItem } from './characterItem'
|
|
||||||
import { CharacterType } from './characterType'
|
|
||||||
import { Chat } from './chat'
|
|
||||||
import { User } from './user'
|
|
||||||
import { Zone } from './zone'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Character extends BaseEntity {
|
export class Character extends BaseCharacter {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
user!: User
|
|
||||||
|
|
||||||
@Property({ unique: true })
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
online = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
role = 'player'
|
|
||||||
|
|
||||||
@OneToMany(() => Chat, (chat) => chat.character)
|
|
||||||
chats = new Collection<Chat>(this)
|
|
||||||
|
|
||||||
// Position
|
|
||||||
@ManyToOne()
|
|
||||||
zone!: Zone // @TODO: Update to spawn point when current zone is not found
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
positionX = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
positionY = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
rotation = 0
|
|
||||||
|
|
||||||
// Customization
|
|
||||||
@ManyToOne({ deleteRule: 'set null' })
|
|
||||||
characterType?: CharacterType | null | undefined
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'set null' })
|
|
||||||
characterHair?: CharacterHair | null | undefined
|
|
||||||
|
|
||||||
// Inventory
|
|
||||||
@OneToMany({ mappedBy: 'character' })
|
|
||||||
items = new Collection<CharacterItem>(this)
|
|
||||||
|
|
||||||
@OneToMany({ mappedBy: 'character' })
|
|
||||||
equipment = new Collection<CharacterEquipment>(this)
|
|
||||||
|
|
||||||
// Stats
|
|
||||||
@Property()
|
|
||||||
alignment = 50
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
hitpoints = 100
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
mana = 100
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
level = 1
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
experience = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
strength = 10
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
dexterity = 10
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
intelligence = 10
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
wisdom = 10
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setUser(user: User) {
|
|
||||||
this.user = user
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUser() {
|
|
||||||
return this.user
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setOnline(online: boolean) {
|
|
||||||
this.online = online
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getOnline() {
|
|
||||||
return this.online
|
|
||||||
}
|
|
||||||
|
|
||||||
setRole(role: string) {
|
|
||||||
this.role = role
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getRole() {
|
|
||||||
return this.role
|
|
||||||
}
|
|
||||||
|
|
||||||
setChats(chats: Collection<Chat>) {
|
|
||||||
this.chats = chats
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getChats() {
|
|
||||||
return this.chats
|
|
||||||
}
|
|
||||||
|
|
||||||
setZone(zone: Zone) {
|
|
||||||
this.zone = zone
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getZone() {
|
|
||||||
return this.zone
|
|
||||||
}
|
|
||||||
|
|
||||||
setPositionX(positionX: number) {
|
|
||||||
this.positionX = positionX
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPositionX() {
|
|
||||||
return this.positionX
|
|
||||||
}
|
|
||||||
|
|
||||||
setPositionY(positionY: number) {
|
|
||||||
this.positionY = positionY
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPositionY() {
|
|
||||||
return this.positionY
|
|
||||||
}
|
|
||||||
|
|
||||||
setRotation(rotation: number) {
|
|
||||||
this.rotation = rotation
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getRotation() {
|
|
||||||
return this.rotation
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacterType(characterType: CharacterType | null | undefined) {
|
|
||||||
this.characterType = characterType
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacterType() {
|
|
||||||
return this.characterType
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacterHair(characterHair: CharacterHair | null | undefined) {
|
|
||||||
this.characterHair = characterHair
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacterHair() {
|
|
||||||
return this.characterHair
|
|
||||||
}
|
|
||||||
|
|
||||||
setItems(items: Collection<CharacterItem>) {
|
|
||||||
this.items = items
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getItems() {
|
|
||||||
return this.items
|
|
||||||
}
|
|
||||||
|
|
||||||
setEquipment(equipment: Collection<CharacterEquipment>) {
|
|
||||||
this.equipment = equipment
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getEquipment() {
|
|
||||||
return this.equipment
|
|
||||||
}
|
|
||||||
|
|
||||||
setAlignment(alignment: number) {
|
|
||||||
this.alignment = alignment
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getAlignment() {
|
|
||||||
return this.alignment
|
|
||||||
}
|
|
||||||
|
|
||||||
setHitpoints(hitpoints: number) {
|
|
||||||
this.hitpoints = hitpoints
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getHitpoints() {
|
|
||||||
return this.hitpoints
|
|
||||||
}
|
|
||||||
|
|
||||||
setMana(mana: number) {
|
|
||||||
this.mana = mana
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMana() {
|
|
||||||
return this.mana
|
|
||||||
}
|
|
||||||
|
|
||||||
setLevel(level: number) {
|
|
||||||
this.level = level
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getLevel() {
|
|
||||||
return this.level
|
|
||||||
}
|
|
||||||
|
|
||||||
setExperience(experience: number) {
|
|
||||||
this.experience = experience
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getExperience() {
|
|
||||||
return this.experience
|
|
||||||
}
|
|
||||||
|
|
||||||
setStrength(strength: number) {
|
|
||||||
this.strength = strength
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getStrength() {
|
|
||||||
return this.strength
|
|
||||||
}
|
|
||||||
|
|
||||||
setDexterity(dexterity: number) {
|
|
||||||
this.dexterity = dexterity
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getDexterity() {
|
|
||||||
return this.dexterity
|
|
||||||
}
|
|
||||||
|
|
||||||
setIntelligence(intelligence: number) {
|
|
||||||
this.intelligence = intelligence
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIntelligence() {
|
|
||||||
return this.intelligence
|
|
||||||
}
|
|
||||||
|
|
||||||
setWisdom(wisdom: number) {
|
|
||||||
this.wisdom = wisdom
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getWisdom() {
|
|
||||||
return this.wisdom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,61 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, Enum, ManyToOne, PrimaryKey } from '@mikro-orm/core'
|
import { BaseCharacterEquipment } from '#entities/base/characterEquipment'
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { CharacterItem } from './characterItem'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { CharacterEquipmentSlotType } from '#application/enums'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class CharacterEquipment extends BaseEntity {
|
export class CharacterEquipment extends BaseCharacterEquipment {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Enum(() => CharacterEquipmentSlotType)
|
|
||||||
slot!: CharacterEquipmentSlotType
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
character!: Character
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
characterItem!: CharacterItem
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setSlot(slot: CharacterEquipmentSlotType) {
|
|
||||||
this.slot = slot
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getSlot() {
|
|
||||||
return this.slot
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacter(character: Character) {
|
|
||||||
this.character = character
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacter() {
|
|
||||||
return this.character
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacterItem(characterItem: CharacterItem) {
|
|
||||||
this.characterItem = characterItem
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacterItem() {
|
|
||||||
return this.characterItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,73 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseCharacterHair } from '#entities/base/characterHair'
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { Sprite } from './sprite'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { CharacterGender } from '#application/enums'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class CharacterHair extends BaseEntity {
|
export class CharacterHair extends BaseCharacterHair {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
gender: CharacterGender = CharacterGender.MALE
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isSelectable = false
|
|
||||||
|
|
||||||
@ManyToOne({ nullable: true })
|
|
||||||
sprite?: Sprite
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setGender(gender: CharacterGender) {
|
|
||||||
this.gender = gender
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getGender() {
|
|
||||||
return this.gender
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsSelectable(isSelectable: boolean) {
|
|
||||||
this.isSelectable = isSelectable
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsSelectable() {
|
|
||||||
return this.isSelectable
|
|
||||||
}
|
|
||||||
|
|
||||||
setSprite(sprite: Sprite) {
|
|
||||||
this.sprite = sprite
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getSprite() {
|
|
||||||
return this.sprite
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,61 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseCharacterItem } from '#entities/base/characterItem'
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { CharacterEquipment } from './characterEquipment'
|
|
||||||
import { Item } from './item'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class CharacterItem extends BaseEntity {
|
export class CharacterItem extends BaseCharacterItem {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
character!: Character
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
item!: Item
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
quantity!: number
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacter(character: Character) {
|
|
||||||
this.character = character
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacter() {
|
|
||||||
return this.character
|
|
||||||
}
|
|
||||||
|
|
||||||
setItem(item: Item) {
|
|
||||||
this.item = item
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getItem() {
|
|
||||||
return this.item
|
|
||||||
}
|
|
||||||
|
|
||||||
setQuantity(quantity: number) {
|
|
||||||
this.quantity = quantity
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getQuantity() {
|
|
||||||
return this.quantity
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,121 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseCharacterType } from '#entities/base/characterType'
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { Sprite } from './sprite'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { CharacterGender, CharacterRace } from '#application/enums'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class CharacterType extends BaseEntity {
|
export class CharacterType extends BaseCharacterType {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Enum(() => CharacterGender)
|
|
||||||
gender!: CharacterGender
|
|
||||||
|
|
||||||
@Enum(() => CharacterRace)
|
|
||||||
race!: CharacterRace
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isSelectable = false
|
|
||||||
|
|
||||||
@OneToMany(() => Character, (character) => character.characterType)
|
|
||||||
characters = new Collection<Character>(this)
|
|
||||||
|
|
||||||
@ManyToOne(() => Sprite, { nullable: true })
|
|
||||||
sprite?: Sprite
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
updatedAt = new Date()
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setGender(gender: CharacterGender) {
|
|
||||||
this.gender = gender
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getGender() {
|
|
||||||
return this.gender
|
|
||||||
}
|
|
||||||
|
|
||||||
setRace(race: CharacterRace) {
|
|
||||||
this.race = race
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getRace() {
|
|
||||||
return this.race
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsSelectable(isSelectable: boolean) {
|
|
||||||
this.isSelectable = isSelectable
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsSelectable() {
|
|
||||||
return this.isSelectable
|
|
||||||
}
|
|
||||||
|
|
||||||
setSprite(sprite: Sprite) {
|
|
||||||
this.sprite = sprite
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getSprite() {
|
|
||||||
return this.sprite
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setUpdatedAt(updatedAt: Date) {
|
|
||||||
this.updatedAt = updatedAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUpdatedAt() {
|
|
||||||
return this.updatedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacters(characters: Collection<Character>) {
|
|
||||||
this.characters = characters
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacters() {
|
|
||||||
return this.characters
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,72 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseChat } from '#entities/base/chat'
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { Zone } from './zone'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Chat extends BaseEntity {
|
export class Chat extends BaseChat {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
character!: Character
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
zone!: Zone
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
message!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacter(character: Character) {
|
|
||||||
this.character = character
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacter() {
|
|
||||||
return this.character
|
|
||||||
}
|
|
||||||
|
|
||||||
setZone(zone: Zone) {
|
|
||||||
this.zone = zone
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getZone() {
|
|
||||||
return this.zone
|
|
||||||
}
|
|
||||||
|
|
||||||
setMessage(message: string) {
|
|
||||||
this.message = message
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMessage() {
|
|
||||||
return this.message
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,121 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseItem } from '#entities/base/item'
|
||||||
|
|
||||||
import { CharacterItem } from './characterItem'
|
|
||||||
import { Sprite } from './sprite'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { ItemType, ItemRarity } from '#application/enums'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Item extends BaseEntity {
|
export class Item extends BaseItem {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Property({ nullable: true })
|
|
||||||
description?: string
|
|
||||||
|
|
||||||
@Enum(() => ItemType)
|
|
||||||
itemType!: ItemType
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
stackable = false
|
|
||||||
|
|
||||||
@Enum(() => ItemRarity)
|
|
||||||
rarity: ItemRarity = ItemRarity.COMMON
|
|
||||||
|
|
||||||
@ManyToOne(() => Sprite, { nullable: true })
|
|
||||||
sprite?: Sprite
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
updatedAt = new Date()
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setDescription(description: string) {
|
|
||||||
this.description = description
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getDescription() {
|
|
||||||
return this.description
|
|
||||||
}
|
|
||||||
|
|
||||||
setItemType(itemType: ItemType) {
|
|
||||||
this.itemType = itemType
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getItemType() {
|
|
||||||
return this.itemType
|
|
||||||
}
|
|
||||||
|
|
||||||
setStackable(stackable: boolean) {
|
|
||||||
this.stackable = stackable
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getStackable() {
|
|
||||||
return this.stackable
|
|
||||||
}
|
|
||||||
|
|
||||||
setRarity(rarity: ItemRarity) {
|
|
||||||
this.rarity = rarity
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getRarity() {
|
|
||||||
return this.rarity
|
|
||||||
}
|
|
||||||
|
|
||||||
setSprite(sprite: Sprite) {
|
|
||||||
this.sprite = sprite
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getSprite() {
|
|
||||||
return this.sprite
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setUpdatedAt(updatedAt: Date) {
|
|
||||||
this.updatedAt = updatedAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUpdatedAt() {
|
|
||||||
return this.updatedAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
6
src/entities/map.ts
Normal file
6
src/entities/map.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseMap } from '#entities/base/map'
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Map extends BaseMap {}
|
6
src/entities/mapEffect.ts
Normal file
6
src/entities/mapEffect.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseMapEffect } from '#entities/base/mapEffect'
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class MapEffect extends BaseMapEffect {}
|
6
src/entities/mapEventTile.ts
Normal file
6
src/entities/mapEventTile.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseMapEventTile } from '#entities/base/mapEventTile'
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class MapEventTile extends BaseMapEventTile {}
|
6
src/entities/mapEventTileTeleport.ts
Normal file
6
src/entities/mapEventTileTeleport.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseMapEventTileTeleport } from '#entities/base/mapEventTileTeleport'
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class MapEventTileTeleport extends BaseMapEventTileTeleport {}
|
@ -1,143 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseMapObject } from '#entities/base/mapObject'
|
||||||
|
|
||||||
import { ZoneObject } from './zoneObject'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class MapObject extends BaseEntity {
|
export class MapObject extends BaseMapObject {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
|
||||||
tags?: any
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
originX = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
originY = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isAnimated = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
frameRate = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
frameWidth = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
frameHeight = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
updatedAt = new Date()
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setTags(tags: any) {
|
|
||||||
this.tags = tags
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getTags() {
|
|
||||||
return this.tags
|
|
||||||
}
|
|
||||||
|
|
||||||
setOriginX(originX: number) {
|
|
||||||
this.originX = originX
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getOriginX() {
|
|
||||||
return this.originX
|
|
||||||
}
|
|
||||||
|
|
||||||
setOriginY(originY: number) {
|
|
||||||
this.originY = originY
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getOriginY() {
|
|
||||||
return this.originY
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsAnimated(isAnimated: boolean) {
|
|
||||||
this.isAnimated = isAnimated
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsAnimated() {
|
|
||||||
return this.isAnimated
|
|
||||||
}
|
|
||||||
|
|
||||||
setFrameRate(frameRate: number) {
|
|
||||||
this.frameRate = frameRate
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getFrameRate() {
|
|
||||||
return this.frameRate
|
|
||||||
}
|
|
||||||
|
|
||||||
setFrameWidth(frameWidth: number) {
|
|
||||||
this.frameWidth = frameWidth
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getFrameWidth() {
|
|
||||||
return this.frameWidth
|
|
||||||
}
|
|
||||||
|
|
||||||
setFrameHeight(frameHeight: number) {
|
|
||||||
this.frameHeight = frameHeight
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getFrameHeight() {
|
|
||||||
return this.frameHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setUpdatedAt(updatedAt: Date) {
|
|
||||||
this.updatedAt = updatedAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUpdatedAt() {
|
|
||||||
return this.updatedAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,59 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BasePasswordResetToken } from '#entities/base/passwordResetToken'
|
||||||
|
|
||||||
import { User } from './user'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class PasswordResetToken extends BaseEntity {
|
export class PasswordResetToken extends BasePasswordResetToken {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
user!: User
|
|
||||||
|
|
||||||
@Property({ unique: true })
|
|
||||||
token!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setUser(user: User) {
|
|
||||||
this.user = user
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUser() {
|
|
||||||
return this.user
|
|
||||||
}
|
|
||||||
|
|
||||||
setToken(token: string) {
|
|
||||||
this.token = token
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getToken() {
|
|
||||||
return this.token
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
6
src/entities/placedMapObject.ts
Normal file
6
src/entities/placedMapObject.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BasePlacedMapObject } from '#entities/base/placedMapObject'
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class PlacedMapObject extends BasePlacedMapObject {}
|
@ -1,71 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseSprite } from '#entities/base/sprite'
|
||||||
|
|
||||||
import { SpriteAction } from './spriteAction'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Sprite extends BaseEntity {
|
export class Sprite extends BaseSprite {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@OneToMany(() => SpriteAction, (action) => action.sprite)
|
|
||||||
spriteActions = new Collection<SpriteAction>(this)
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
updatedAt = new Date()
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setSpriteActions(spriteActions: Collection<SpriteAction>) {
|
|
||||||
this.spriteActions = spriteActions
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getSpriteActions() {
|
|
||||||
return this.spriteActions
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setUpdatedAt(updatedAt: Date) {
|
|
||||||
this.updatedAt = updatedAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUpdatedAt() {
|
|
||||||
return this.updatedAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,143 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseSpriteAction } from '#entities/base/spriteAction'
|
||||||
|
|
||||||
import { Sprite } from './sprite'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class SpriteAction extends BaseEntity {
|
export class SpriteAction extends BaseSpriteAction {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
sprite!: Sprite
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
action!: string
|
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
|
||||||
sprites?: string[]
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
originX = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
originY = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isAnimated = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isLooping = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
frameWidth = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
frameHeight = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
frameRate = 0
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setSprite(sprite: Sprite) {
|
|
||||||
this.sprite = sprite
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getSprite() {
|
|
||||||
return this.sprite
|
|
||||||
}
|
|
||||||
|
|
||||||
setAction(action: string) {
|
|
||||||
this.action = action
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getAction() {
|
|
||||||
return this.action
|
|
||||||
}
|
|
||||||
|
|
||||||
setSprites(sprites: string[]) {
|
|
||||||
this.sprites = sprites
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getSprites() {
|
|
||||||
return this.sprites
|
|
||||||
}
|
|
||||||
|
|
||||||
setOriginX(originX: number) {
|
|
||||||
this.originX = originX
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getOriginX() {
|
|
||||||
return this.originX
|
|
||||||
}
|
|
||||||
|
|
||||||
setOriginY(originY: number) {
|
|
||||||
this.originY = originY
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getOriginY() {
|
|
||||||
return this.originY
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsAnimated(isAnimated: boolean) {
|
|
||||||
this.isAnimated = isAnimated
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsAnimated() {
|
|
||||||
return this.isAnimated
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsLooping(isLooping: boolean) {
|
|
||||||
this.isLooping = isLooping
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsLooping() {
|
|
||||||
return this.isLooping
|
|
||||||
}
|
|
||||||
|
|
||||||
setFrameWidth(frameWidth: number) {
|
|
||||||
this.frameWidth = frameWidth
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getFrameWidth() {
|
|
||||||
return this.frameWidth
|
|
||||||
}
|
|
||||||
|
|
||||||
setFrameHeight(frameHeight: number) {
|
|
||||||
this.frameHeight = frameHeight
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getFrameHeight() {
|
|
||||||
return this.frameHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
setFrameRate(frameRate: number) {
|
|
||||||
this.frameRate = frameRate
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getFrameRate() {
|
|
||||||
return this.frameRate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,69 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseTile } from '#entities/base/tile'
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Tile extends BaseEntity {
|
export class Tile extends BaseTile {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
|
||||||
tags?: any
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
updatedAt = new Date()
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setTags(tags: any) {
|
|
||||||
this.tags = tags
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getTags() {
|
|
||||||
return this.tags
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setUpdatedAt(updatedAt: Date) {
|
|
||||||
this.updatedAt = updatedAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUpdatedAt() {
|
|
||||||
return this.updatedAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,98 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseUser } from '#entities/base/user'
|
||||||
import bcrypt from 'bcryptjs'
|
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { PasswordResetToken } from './passwordResetToken'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class User extends BaseEntity {
|
export class User extends BaseUser {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property({ unique: true })
|
|
||||||
username!: string
|
|
||||||
|
|
||||||
@Property({ unique: true })
|
|
||||||
email!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
password!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
online = false
|
|
||||||
|
|
||||||
@OneToMany(() => Character, (character) => character.user)
|
|
||||||
characters = new Collection<Character>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => PasswordResetToken, (token) => token.user)
|
|
||||||
passwordResetTokens = new Collection<PasswordResetToken>(this)
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setUsername(username: string) {
|
|
||||||
this.username = username
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUsername() {
|
|
||||||
return this.username
|
|
||||||
}
|
|
||||||
|
|
||||||
setEmail(email: string) {
|
|
||||||
this.email = email
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getEmail() {
|
|
||||||
return this.email
|
|
||||||
}
|
|
||||||
|
|
||||||
setPassword(password: string) {
|
|
||||||
this.password = bcrypt.hashSync(password, 10)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPassword() {
|
|
||||||
return this.password
|
|
||||||
}
|
|
||||||
|
|
||||||
setOnline(online: boolean) {
|
|
||||||
this.online = online
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getOnline() {
|
|
||||||
return this.online
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacters(characters: Collection<Character>) {
|
|
||||||
this.characters = characters
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacters() {
|
|
||||||
return this.characters
|
|
||||||
}
|
|
||||||
|
|
||||||
setPasswordResetTokens(passwordResetTokens: Collection<PasswordResetToken>) {
|
|
||||||
this.passwordResetTokens = passwordResetTokens
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPasswordResetTokens() {
|
|
||||||
return this.passwordResetTokens
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,66 +1,6 @@
|
|||||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
import { BaseWorld } from '#entities/base/world'
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class World extends BaseEntity {
|
export class World extends BaseWorld {}
|
||||||
@PrimaryKey()
|
|
||||||
date = new Date()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isRainEnabled = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
rainPercentage = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isFogEnabled = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
fogDensity = 0
|
|
||||||
|
|
||||||
setDate(date: Date) {
|
|
||||||
this.date = date
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getDate() {
|
|
||||||
return this.date
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsRainEnabled(isRainEnabled: boolean) {
|
|
||||||
this.isRainEnabled = isRainEnabled
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsRainEnabled() {
|
|
||||||
return this.isRainEnabled
|
|
||||||
}
|
|
||||||
|
|
||||||
setRainPercentage(rainPercentage: number) {
|
|
||||||
this.rainPercentage = rainPercentage
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getRainPercentage() {
|
|
||||||
return this.rainPercentage
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsFogEnabled(isFogEnabled: boolean) {
|
|
||||||
this.isFogEnabled = isFogEnabled
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsFogEnabled() {
|
|
||||||
return this.isFogEnabled
|
|
||||||
}
|
|
||||||
|
|
||||||
setFogDensity(fogDensity: number) {
|
|
||||||
this.fogDensity = fogDensity
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getFogDensity() {
|
|
||||||
return this.fogDensity
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,184 +0,0 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
|
||||||
|
|
||||||
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { Chat } from './chat'
|
|
||||||
import { ZoneEffect } from './zoneEffect'
|
|
||||||
import { ZoneEventTile } from './zoneEventTile'
|
|
||||||
import { ZoneEventTileTeleport } from './zoneEventTileTeleport'
|
|
||||||
import { ZoneObject } from './zoneObject'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export class Zone extends BaseEntity {
|
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
width = 10
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
height = 10
|
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
|
||||||
tiles?: any
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
pvp = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
createdAt = new Date()
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
updatedAt = new Date()
|
|
||||||
|
|
||||||
@OneToMany(() => ZoneEffect, (effect) => effect.zone)
|
|
||||||
zoneEffects = new Collection<ZoneEffect>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => ZoneEventTile, (tile) => tile.zone)
|
|
||||||
zoneEventTiles = new Collection<ZoneEventTile>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => ZoneEventTileTeleport, (teleport) => teleport.toZone)
|
|
||||||
zoneEventTileTeleports = new Collection<ZoneEventTileTeleport>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => ZoneObject, (object) => object.zone)
|
|
||||||
zoneObjects = new Collection<ZoneObject>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => Character, (character) => character.zone)
|
|
||||||
characters = new Collection<Character>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => Chat, (chat) => chat.zone)
|
|
||||||
chats = new Collection<Chat>(this)
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setName(name: string) {
|
|
||||||
this.name = name
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.name
|
|
||||||
}
|
|
||||||
|
|
||||||
setWidth(width: number) {
|
|
||||||
this.width = width
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getWidth() {
|
|
||||||
return this.width
|
|
||||||
}
|
|
||||||
|
|
||||||
setHeight(height: number) {
|
|
||||||
this.height = height
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getHeight() {
|
|
||||||
return this.height
|
|
||||||
}
|
|
||||||
|
|
||||||
setTiles(tiles: any) {
|
|
||||||
this.tiles = tiles
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getTiles() {
|
|
||||||
return this.tiles
|
|
||||||
}
|
|
||||||
|
|
||||||
setPvp(pvp: boolean) {
|
|
||||||
this.pvp = pvp
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPvp() {
|
|
||||||
return this.pvp
|
|
||||||
}
|
|
||||||
|
|
||||||
setCreatedAt(createdAt: Date) {
|
|
||||||
this.createdAt = createdAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCreatedAt() {
|
|
||||||
return this.createdAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setUpdatedAt(updatedAt: Date) {
|
|
||||||
this.updatedAt = updatedAt
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getUpdatedAt() {
|
|
||||||
return this.updatedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
setZoneEffects(zoneEffects: Collection<ZoneEffect>) {
|
|
||||||
this.zoneEffects = zoneEffects
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getZoneEffects() {
|
|
||||||
return this.zoneEffects
|
|
||||||
}
|
|
||||||
|
|
||||||
setZoneEventTiles(zoneEventTiles: Collection<ZoneEventTile>) {
|
|
||||||
this.zoneEventTiles = zoneEventTiles
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getZoneEventTiles() {
|
|
||||||
return this.zoneEventTiles
|
|
||||||
}
|
|
||||||
|
|
||||||
setZoneEventTileTeleports(zoneEventTileTeleports: Collection<ZoneEventTileTeleport>) {
|
|
||||||
this.zoneEventTileTeleports = zoneEventTileTeleports
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getZoneEventTileTeleports() {
|
|
||||||
return this.zoneEventTileTeleports
|
|
||||||
}
|
|
||||||
|
|
||||||
setZoneObjects(zoneObjects: Collection<ZoneObject>) {
|
|
||||||
this.zoneObjects = zoneObjects
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getZoneObjects() {
|
|
||||||
return this.zoneObjects
|
|
||||||
}
|
|
||||||
|
|
||||||
setCharacters(characters: Collection<Character>) {
|
|
||||||
this.characters = characters
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getCharacters() {
|
|
||||||
return this.characters
|
|
||||||
}
|
|
||||||
|
|
||||||
setChats(chats: Collection<Chat>) {
|
|
||||||
this.chats = chats
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getChats() {
|
|
||||||
return this.chats
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import Database from '#application/database'
|
|
||||||
import { CharacterHair } from '#entities/characterHair'
|
import { CharacterHair } from '#entities/characterHair'
|
||||||
import characterHairRepository from '#repositories/characterHairRepository'
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -11,8 +10,14 @@ export default class characterHairListEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: CharacterHair[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: CharacterHair[]) => void): Promise<void> {
|
||||||
const items: CharacterHair[] = await characterHairRepository.getAllSelectable()
|
try {
|
||||||
await Database.getEntityManager().populate(items, ['sprite'])
|
const characterHairRepository = new CharacterHairRepository()
|
||||||
callback(items)
|
const items: CharacterHair[] = await characterHairRepository.getAllSelectable(['sprite'])
|
||||||
|
|
||||||
|
return callback(items)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('character:hair:list error', error)
|
||||||
|
return callback([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import ZoneManager from '#managers/zoneManager'
|
import MapManager from '#managers/mapManager'
|
||||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
import CharacterRepository from '#repositories/characterRepository'
|
||||||
import TeleportService from '#services/teleportService'
|
import TeleportService from '#services/teleportService'
|
||||||
@ -11,57 +11,47 @@ interface CharacterConnectPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class CharacterConnectEvent extends BaseEvent {
|
export default class CharacterConnectEvent extends BaseEvent {
|
||||||
|
private readonly characterHairRepository = new CharacterHairRepository()
|
||||||
|
private readonly characterRepository = new CharacterRepository()
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('character:connect', this.handleEvent.bind(this))
|
this.socket.on('character:connect', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle character connect event
|
|
||||||
* @TODO:
|
|
||||||
* 1. Check if character is already connected
|
|
||||||
* 2. Update character hair if provided
|
|
||||||
* 3. Emit character connect event
|
|
||||||
* 4. Let other clients know of new character
|
|
||||||
* @param data
|
|
||||||
* @param callback
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
private async handleEvent(data: CharacterConnectPayload, callback: (response: any) => void): Promise<void> {
|
private async handleEvent(data: CharacterConnectPayload, callback: (response: any) => void): Promise<void> {
|
||||||
if (!this.socket.userId) {
|
|
||||||
this.emitError('User not authenticated')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (await this.checkForActiveCharacters()) {
|
if (await this.checkForActiveCharacters()) {
|
||||||
this.emitError('You are already connected to another character')
|
this.emitError('You are already connected to another character')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const character = await CharacterRepository.getByUserAndId(this.socket.userId, data.characterId)
|
const character = await this.characterRepository.getByUserAndId(this.socket.userId!, data.characterId)
|
||||||
|
|
||||||
if (!character) {
|
if (!character) {
|
||||||
this.emitError('Character not found or does not belong to this user')
|
this.emitError('Character not found or does not belong to this user')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Populate character with characterType and characterHair
|
||||||
|
await this.characterRepository.getEntityManager().populate(character, ['characterType', 'characterHair'])
|
||||||
|
|
||||||
// Set character id
|
// Set character id
|
||||||
this.socket.characterId = character.id
|
this.socket.characterId = character.id
|
||||||
|
|
||||||
// Set character hair
|
// Set character hair
|
||||||
if (data.characterHairId !== undefined && data.characterHairId !== null) {
|
if (data.characterHairId !== undefined && data.characterHairId !== null) {
|
||||||
const characterHair = await CharacterHairRepository.getById(data.characterHairId)
|
const characterHair = await this.characterHairRepository.getById(data.characterHairId)
|
||||||
await character.setCharacterHair(characterHair).update()
|
await character.setCharacterHair(characterHair).save()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit character connect event
|
// Emit character connect event
|
||||||
callback({ character })
|
callback({ character })
|
||||||
|
|
||||||
// wait 300 ms, @TODO: Find a better way to do this
|
// wait 300 ms, @TODO: Find a better way to do this, race condition
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||||
|
|
||||||
await TeleportService.teleportCharacter(character.id, {
|
await TeleportService.teleportCharacter(character.id, {
|
||||||
targetZoneId: character.zone.id,
|
targetMapId: character.map.id,
|
||||||
targetX: character.positionX,
|
targetX: character.positionX,
|
||||||
targetY: character.positionY,
|
targetY: character.positionY,
|
||||||
rotation: character.rotation,
|
rotation: character.rotation,
|
||||||
@ -74,7 +64,7 @@ export default class CharacterConnectEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async checkForActiveCharacters(): Promise<boolean> {
|
private async checkForActiveCharacters(): Promise<boolean> {
|
||||||
const characters = await CharacterRepository.getByUserId(this.socket.userId!)
|
const characters = await this.characterRepository.getByUserId(this.socket.userId!)
|
||||||
return characters?.some((char) => ZoneManager.getCharacterById(char.id)) ?? false
|
return characters?.some((char) => MapManager.getCharacterById(char.id)) ?? false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import { BaseEvent } from '#application/base/baseEvent'
|
|||||||
import { ZCharacterCreate } from '#application/zodTypes'
|
import { ZCharacterCreate } from '#application/zodTypes'
|
||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
import CharacterRepository from '#repositories/characterRepository'
|
||||||
|
import MapRepository from '#repositories/mapRepository'
|
||||||
import UserRepository from '#repositories/userRepository'
|
import UserRepository from '#repositories/userRepository'
|
||||||
import ZoneRepository from '#repositories/zoneRepository'
|
|
||||||
|
|
||||||
export default class CharacterCreateEvent extends BaseEvent {
|
export default class CharacterCreateEvent extends BaseEvent {
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
@ -17,30 +17,34 @@ export default class CharacterCreateEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
data = ZCharacterCreate.parse(data)
|
data = ZCharacterCreate.parse(data)
|
||||||
|
|
||||||
const user = await UserRepository.getById(this.socket.userId!)
|
const userRepository = new UserRepository()
|
||||||
|
const characterRepository = new CharacterRepository()
|
||||||
|
const mapRepository = new MapRepository()
|
||||||
|
|
||||||
|
const user = await userRepository.getById(this.socket.userId!)
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return this.socket.emit('notification', { message: 'User not found' })
|
return this.socket.emit('notification', { message: 'User not found' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if character name already exists
|
// Check if character name already exists
|
||||||
const characterExists = await CharacterRepository.getByName(data.name)
|
const characterExists = await characterRepository.getByName(data.name)
|
||||||
|
|
||||||
if (characterExists) {
|
if (characterExists) {
|
||||||
return this.socket.emit('notification', { message: 'Character name already exists' })
|
return this.socket.emit('notification', { message: 'Character name already exists' })
|
||||||
}
|
}
|
||||||
|
|
||||||
let characters: Character[] = await CharacterRepository.getByUserId(user.getId())
|
let characters: Character[] = await characterRepository.getByUserId(user.getId())
|
||||||
|
|
||||||
if (characters.length >= 4) {
|
if (characters.length >= 4) {
|
||||||
return this.socket.emit('notification', { message: 'You can only have 4 characters' })
|
return this.socket.emit('notification', { message: 'You can only have 4 characters' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO: Change to default location
|
// @TODO: Change to default location
|
||||||
const zone = await ZoneRepository.getFirst()
|
const map = await mapRepository.getFirst()
|
||||||
|
|
||||||
const newCharacter = new Character()
|
const newCharacter = new Character()
|
||||||
await newCharacter.setName(data.name).setUser(user).setZone(zone!).save()
|
await newCharacter.setName(data.name).setUser(user).setMap(map!).save()
|
||||||
|
|
||||||
if (!newCharacter) {
|
if (!newCharacter) {
|
||||||
return this.socket.emit('notification', { message: 'Failed to create character. Please try again (later).' })
|
return this.socket.emit('notification', { message: 'Failed to create character. Please try again (later).' })
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import { Zone } from '#entities/zone'
|
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
import CharacterRepository from '#repositories/characterRepository'
|
||||||
|
|
||||||
type TypePayload = {
|
type TypePayload = {
|
||||||
@ -9,7 +8,6 @@ type TypePayload = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TypeResponse = {
|
type TypeResponse = {
|
||||||
zone: Zone
|
|
||||||
characters: Character[]
|
characters: Character[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,12 +18,9 @@ export default class CharacterDeleteEvent extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: TypePayload, callback: (response: TypeResponse) => void): Promise<any> {
|
private async handleEvent(data: TypePayload, callback: (response: TypeResponse) => void): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, data.characterId)
|
const characterRepository = new CharacterRepository()
|
||||||
if (character) {
|
await (await characterRepository.getByUserAndId(this.socket.userId!, data.characterId))?.delete()
|
||||||
await character.delete()
|
const characters: Character[] = await characterRepository.getByUserId(this.socket.userId!)
|
||||||
}
|
|
||||||
|
|
||||||
const characters: Character[] = await CharacterRepository.getByUserId(this.socket.userId!)
|
|
||||||
|
|
||||||
this.socket.emit('character:list', characters)
|
this.socket.emit('character:list', characters)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import Database from '#application/database'
|
|
||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
import CharacterRepository from '#repositories/characterRepository'
|
||||||
|
|
||||||
@ -10,8 +9,11 @@ export default class CharacterListEvent extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: any): Promise<void> {
|
private async handleEvent(data: any): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const characters: Character[] = await CharacterRepository.getByUserId(this.socket.userId!)
|
const characterRepository = new CharacterRepository()
|
||||||
await Database.getEntityManager().populate(characters, ['characterType', 'characterHair'])
|
let characters: Character[] = await characterRepository.getByUserId(this.socket.userId!)
|
||||||
|
|
||||||
|
// Populate characters with characterType and characterHair
|
||||||
|
await characterRepository.getEntityManager().populate(characters, ['characterType', 'characterHair'])
|
||||||
|
|
||||||
this.socket.emit('character:list', characters)
|
this.socket.emit('character:list', characters)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -13,22 +13,11 @@ export default class AlertCommandEvent extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!ChatService.isCommand(data.message, 'alert')) {
|
// Check if command is alert
|
||||||
return
|
if (!ChatService.isCommand(data.message, 'alert')) return
|
||||||
}
|
|
||||||
|
|
||||||
// Check if character exists
|
// Check if character exists
|
||||||
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) {
|
|
||||||
this.logger.error('chat:alert_command error', 'Character not found')
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the user is the GM
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
this.logger.info(`User ${character.id} tried to set time but is not a game master.`)
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
const args = ChatService.getArgs('alert', data.message)
|
const args = ChatService.getArgs('alert', data.message)
|
||||||
|
|
||||||
|
@ -14,22 +14,11 @@ export default class SetTimeCommand extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!ChatService.isCommand(data.message, 'time')) {
|
// Check if command is time
|
||||||
return
|
if (!ChatService.isCommand(data.message, 'time')) return
|
||||||
}
|
|
||||||
|
|
||||||
// Check if character exists
|
// Check if character exists and is GM
|
||||||
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) {
|
|
||||||
this.logger.error('chat:alert_command error', 'Character not found')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the user is the GM
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
this.logger.info(`User ${character.id} tried to set time but is not a game master.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get arguments
|
// Get arguments
|
||||||
const args = ChatService.getArgs('time', data.message)
|
const args = ChatService.getArgs('time', data.message)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import ZoneManager from '#managers/zoneManager'
|
import MapManager from '#managers/mapManager'
|
||||||
import ZoneRepository from '#repositories/zoneRepository'
|
import MapRepository from '#repositories/mapRepository'
|
||||||
import ChatService from '#services/chatService'
|
import ChatService from '#services/chatService'
|
||||||
import TeleportService from '#services/teleportService'
|
import TeleportService from '#services/teleportService'
|
||||||
|
|
||||||
@ -16,36 +16,30 @@ export default class TeleportCommandEvent extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void) {
|
private async handleEvent(data: TypePayload, callback: (response: boolean) => void) {
|
||||||
try {
|
try {
|
||||||
const zoneCharacter = ZoneManager.getCharacterById(this.socket.characterId!)
|
// Check if command is teleport
|
||||||
if (!zoneCharacter) {
|
|
||||||
this.logger.error('chat:message error', 'Character not found')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const character = zoneCharacter.character
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
this.logger.info(`User ${character.id} tried to set time but is not a game master.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ChatService.isCommand(data.message, 'teleport')) return
|
if (!ChatService.isCommand(data.message, 'teleport')) return
|
||||||
|
|
||||||
|
// Check if character exists and is GM
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
const character = await this.getCharacter()
|
||||||
|
if (!character) return
|
||||||
|
|
||||||
const args = ChatService.getArgs('teleport', data.message)
|
const args = ChatService.getArgs('teleport', data.message)
|
||||||
|
|
||||||
if (!args || args.length === 0 || args.length > 3) {
|
if (!args || args.length === 0 || args.length > 3) {
|
||||||
this.socket.emit('notification', {
|
this.socket.emit('notification', {
|
||||||
title: 'Server message',
|
title: 'Server message',
|
||||||
message: 'Usage: /teleport <zoneId> [x] [y]'
|
message: 'Usage: /teleport <mapId> [x] [y]'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const zoneId = args[0] as UUID
|
const mapId = args[0] as UUID
|
||||||
const targetX = args[1] ? parseInt(args[1], 10) : 0
|
const targetX = args[1] ? parseInt(args[1], 10) : 0
|
||||||
const targetY = args[2] ? parseInt(args[2], 10) : 0
|
const targetY = args[2] ? parseInt(args[2], 10) : 0
|
||||||
|
|
||||||
if (!zoneId || isNaN(targetX) || isNaN(targetY)) {
|
if (!mapId || isNaN(targetX) || isNaN(targetY)) {
|
||||||
this.socket.emit('notification', {
|
this.socket.emit('notification', {
|
||||||
title: 'Server message',
|
title: 'Server message',
|
||||||
message: 'Invalid parameters. X and Y coordinates must be numbers.'
|
message: 'Invalid parameters. X and Y coordinates must be numbers.'
|
||||||
@ -53,16 +47,17 @@ export default class TeleportCommandEvent extends BaseEvent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const zone = await ZoneRepository.getById(zoneId)
|
const mapRepository = new MapRepository()
|
||||||
if (!zone) {
|
const map = await mapRepository.getById(mapId)
|
||||||
|
if (!map) {
|
||||||
this.socket.emit('notification', {
|
this.socket.emit('notification', {
|
||||||
title: 'Server message',
|
title: 'Server message',
|
||||||
message: 'Zone not found'
|
message: 'Map not found'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.zone.id === zone.id && targetX === character.positionX && targetY === character.positionY) {
|
if (character.map.id === map.id && targetX === character.positionX && targetY === character.positionY) {
|
||||||
this.socket.emit('notification', {
|
this.socket.emit('notification', {
|
||||||
title: 'Server message',
|
title: 'Server message',
|
||||||
message: 'You are already at that location'
|
message: 'You are already at that location'
|
||||||
@ -71,7 +66,7 @@ export default class TeleportCommandEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const success = await TeleportService.teleportCharacter(character.id, {
|
const success = await TeleportService.teleportCharacter(character.id, {
|
||||||
targetZoneId: zone.id,
|
targetMapId: map.id,
|
||||||
targetX,
|
targetX,
|
||||||
targetY,
|
targetY,
|
||||||
rotation: character.rotation
|
rotation: character.rotation
|
||||||
@ -86,9 +81,9 @@ export default class TeleportCommandEvent extends BaseEvent {
|
|||||||
|
|
||||||
this.socket.emit('notification', {
|
this.socket.emit('notification', {
|
||||||
title: 'Server message',
|
title: 'Server message',
|
||||||
message: `Teleported to ${zone.name} (${targetX}, ${targetY})`
|
message: `Teleported to ${map.name} (${targetX}, ${targetY})`
|
||||||
})
|
})
|
||||||
this.logger.info('teleport', `Character ${character.id} teleported to zone ${zone.id} at position (${targetX}, ${targetY})`)
|
this.logger.info('teleport', `Character ${character.id} teleported to map ${map.id} at position (${targetX}, ${targetY})`)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Error in teleport command: ${error.message}`)
|
this.logger.error(`Error in teleport command: ${error.message}`)
|
||||||
this.socket.emit('notification', {
|
this.socket.emit('notification', {
|
||||||
|
@ -14,22 +14,11 @@ export default class ToggleFogCommand extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!ChatService.isCommand(data.message, 'fog')) {
|
// Check if command is fog
|
||||||
return
|
if (!ChatService.isCommand(data.message, 'fog')) return
|
||||||
}
|
|
||||||
|
|
||||||
// Check if character exists
|
// Check if character exists and is GM
|
||||||
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) {
|
|
||||||
this.logger.error('chat:alert_command error', 'Character not found')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the user is the GM
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
this.logger.info(`User ${character.id} tried to set time but is not a game master.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await WeatherManager.toggleFog()
|
await WeatherManager.toggleFog()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -14,22 +14,11 @@ export default class ToggleRainCommand extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!ChatService.isCommand(data.message, 'rain')) {
|
// Check if command is rain
|
||||||
return
|
if (!ChatService.isCommand(data.message, 'rain')) return
|
||||||
}
|
|
||||||
|
|
||||||
// Check if character exists
|
// Check if character exists and is GM
|
||||||
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) {
|
|
||||||
this.logger.error('chat:alert_command error', 'Character not found')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the user is the GM
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
this.logger.info(`User ${character.id} tried to set time but is not a game master.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await WeatherManager.toggleRain()
|
await WeatherManager.toggleRain()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import ZoneManager from '#managers/zoneManager'
|
import MapManager from '#managers/mapManager'
|
||||||
import ZoneRepository from '#repositories/zoneRepository'
|
import MapRepository from '#repositories/mapRepository'
|
||||||
import ChatService from '#services/chatService'
|
import ChatService from '#services/chatService'
|
||||||
|
|
||||||
type TypePayload = {
|
type TypePayload = {
|
||||||
@ -18,21 +18,22 @@ export default class ChatMessageEvent extends BaseEvent {
|
|||||||
return callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const zoneCharacter = ZoneManager.getCharacterById(this.socket.characterId!)
|
const mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
||||||
if (!zoneCharacter) {
|
if (!mapCharacter) {
|
||||||
this.logger.error('chat:message error', 'Character not found')
|
this.logger.error('chat:message error', 'Character not found')
|
||||||
return callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const character = zoneCharacter.character
|
const character = mapCharacter.character
|
||||||
|
|
||||||
const zone = await ZoneRepository.getById(character.zone.id)
|
const mapRepository = new MapRepository()
|
||||||
if (!zone) {
|
const map = await mapRepository.getById(character.map.id)
|
||||||
this.logger.error('chat:message error', 'Zone not found')
|
if (!map) {
|
||||||
|
this.logger.error('chat:message error', 'Map not found')
|
||||||
return callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await ChatService.sendZoneMessage(character.getId(), zone.getId(), data.message)) {
|
if (await ChatService.sendMapMessage(character.getId(), map.getId(), data.message)) {
|
||||||
return callback(true)
|
return callback(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import ZoneManager from '#managers/zoneManager'
|
import MapManager from '#managers/mapManager'
|
||||||
|
|
||||||
export default class DisconnectEvent extends BaseEvent {
|
export default class DisconnectEvent extends BaseEvent {
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
@ -15,13 +15,13 @@ export default class DisconnectEvent extends BaseEvent {
|
|||||||
|
|
||||||
this.io.emit('user:disconnect', this.socket.userId)
|
this.io.emit('user:disconnect', this.socket.userId)
|
||||||
|
|
||||||
const zoneCharacter = ZoneManager.getCharacterById(this.socket.characterId!)
|
const mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
||||||
if (!zoneCharacter) {
|
if (!mapCharacter) {
|
||||||
this.logger.info('User disconnected but had no character set')
|
this.logger.info('User disconnected but had no character set')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await zoneCharacter.disconnect(this.socket, this.io)
|
await mapCharacter.disconnect(this.socket, this.io)
|
||||||
this.logger.info('User disconnected along with their character')
|
this.logger.info('User disconnected along with their character')
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error('disconnect error: ' + error.message)
|
this.logger.error('disconnect error: ' + error.message)
|
||||||
|
@ -1,28 +1,22 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { CharacterHair } from '#entities/characterHair'
|
import { CharacterHair } from '#entities/characterHair'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
export default class CharacterHairCreateEvent extends BaseEvent {
|
export default class CharacterHairCreateEvent extends BaseEvent {
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:characterHair:create', this.handleEvent.bind(this))
|
this.socket.on('gm:characterHair:create', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: undefined, callback: (response: boolean, characterType?: any) => void): Promise<void> {
|
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const character = await characterRepository.getById(this.socket.characterId!)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
const newCharacterHair = new CharacterHair()
|
const newCharacterHair = new CharacterHair()
|
||||||
await newCharacterHair.setName('New hair').save()
|
await newCharacterHair.setName('New hair').save()
|
||||||
|
|
||||||
callback(true, newCharacterHair)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating character hair:', error)
|
console.error('Error creating character hair:', error)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
id: number
|
id: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class characterHairDeleteEvent extends BaseEvent {
|
export default class characterHairDeleteEvent extends BaseEvent {
|
||||||
@ -12,20 +12,13 @@ export default class characterHairDeleteEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const characterHair = await CharacterHairRepository.getById(data.id)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (characterHair) {
|
|
||||||
await characterHair.delete()
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(true)
|
const characterHair = await CharacterHairRepository.getById(data.id)
|
||||||
|
await (await CharacterHairRepository.getById(data.id))?.delete()
|
||||||
|
|
||||||
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error deleting character type ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Error deleting character type ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
callback(false)
|
callback(false)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { CharacterHair } from '#entities/characterHair'
|
import { CharacterHair } from '#entities/characterHair'
|
||||||
import characterHairRepository from '#repositories/characterHairRepository'
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -11,19 +10,17 @@ export default class characterHairListEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: CharacterHair[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: CharacterHair[]) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
try {
|
||||||
if (!character) {
|
if (!(await this.isCharacterGM())) return
|
||||||
this.logger.error('gm:characterHair:list error', 'Character not found')
|
|
||||||
|
const characterHairRepository = new CharacterHairRepository()
|
||||||
|
const items = await characterHairRepository.getAll()
|
||||||
|
await characterHairRepository.getEntityManager().populate(items, ['sprite'])
|
||||||
|
|
||||||
|
return callback(items)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:characterHair:list error', error)
|
||||||
return callback([])
|
return callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
this.logger.info(`User ${character.id} tried to list character hair but is not a game master.`)
|
|
||||||
return callback([])
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all objects
|
|
||||||
const items = await characterHairRepository.getAll()
|
|
||||||
callback(items)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,10 @@ import { BaseEvent } from '#application/base/baseEvent'
|
|||||||
import { CharacterGender } from '#application/enums'
|
import { CharacterGender } from '#application/enums'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
import SpriteRepository from '#repositories/spriteRepository'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: number
|
id: UUID
|
||||||
name: string
|
name: string
|
||||||
gender: CharacterGender
|
gender: CharacterGender
|
||||||
isSelectable: boolean
|
isSelectable: boolean
|
||||||
@ -19,21 +18,18 @@ export default class CharacterHairUpdateEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sprite = await SpriteRepository.getById(data.spriteId)
|
if (!(await this.isCharacterGM())) return
|
||||||
const characterHair = await CharacterHairRepository.getById(data.id)
|
|
||||||
|
|
||||||
if (characterHair) {
|
const spriteRepository = new SpriteRepository()
|
||||||
await characterHair.setName(data.name).setGender(data.gender).setIsSelectable(data.isSelectable).setSprite(sprite!).update()
|
const sprite = await spriteRepository.getById(data.spriteId)
|
||||||
}
|
if (!sprite) return callback(false)
|
||||||
|
|
||||||
|
const characterHairRepository = new CharacterHairRepository()
|
||||||
|
const characterHair = await characterHairRepository.getById(data.id)
|
||||||
|
if (!characterHair) return callback(false)
|
||||||
|
|
||||||
|
await characterHair.setName(data.name).setGender(data.gender).setIsSelectable(data.isSelectable).setSprite(sprite).save()
|
||||||
return callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error updating character hair: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Error updating character hair: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
|
@ -1,41 +1,22 @@
|
|||||||
import { CharacterGender, CharacterRace } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { Server } from 'socket.io'
|
import { CharacterType } from '#entities/characterType'
|
||||||
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
export default class CharacterTypeCreateEvent {
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
|
export default class CharacterTypeCreateEvent extends BaseEvent {
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:characterType:create', this.handleEvent.bind(this))
|
this.socket.on('gm:characterType:create', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: undefined, callback: (response: boolean, characterType?: any) => void): Promise<void> {
|
private async handleEvent(data: undefined, callback: (response: boolean, characterType?: any) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
const newCharacterType = new CharacterType()
|
||||||
return callback(false)
|
await newCharacterType.setName('New character type').save()
|
||||||
}
|
|
||||||
|
|
||||||
const newCharacterType = await prisma.characterType.create({
|
return callback(true, newCharacterType)
|
||||||
data: {
|
|
||||||
name: 'New character type',
|
|
||||||
gender: CharacterGender.MALE,
|
|
||||||
race: CharacterRace.HUMAN
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
callback(true, newCharacterType)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating character type:', error)
|
console.error('Error creating character type:', error)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,29 @@
|
|||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
id: number
|
id: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CharacterTypeDeleteEvent {
|
export default class CharacterTypeDeleteEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:characterType:remove', this.handleEvent.bind(this))
|
this.socket.on('gm:characterType:remove', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId!)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const characterType = await CharacterTypeRepository.getById(data.id)
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
const characterTypeRepository = new CharacterTypeRepository()
|
||||||
|
const characterType = await characterTypeRepository.getById(data.id)
|
||||||
if (!characterType) return callback(false)
|
if (!characterType) return callback(false)
|
||||||
|
|
||||||
await characterType.delete()
|
await characterType.delete()
|
||||||
callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
gameMasterLogger.error(`Error deleting character type ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Error deleting character type ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,26 @@
|
|||||||
import { CharacterType } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { Server } from 'socket.io'
|
import { CharacterType } from '#entities/characterType'
|
||||||
|
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
export default class CharacterTypeListEvent {
|
export default class CharacterTypeListEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:characterType:list', this.handleEvent.bind(this))
|
this.socket.on('gm:characterType:list', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: CharacterType[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: CharacterType[]) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
try {
|
||||||
if (!character) {
|
if (!(await this.isCharacterGM())) return
|
||||||
gameMasterLogger.error('gm:characterType:list error', 'Character not found')
|
|
||||||
|
const characterTypeRepository = new CharacterTypeRepository()
|
||||||
|
const items = await characterTypeRepository.getAll()
|
||||||
|
await characterTypeRepository.getEntityManager().populate(items, ['sprite'])
|
||||||
|
|
||||||
|
return callback(items)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:characterType:list error', error)
|
||||||
return callback([])
|
return callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
gameMasterLogger.info(`User ${character.id} tried to list character types but is not a game master.`)
|
|
||||||
return callback([])
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all objects
|
|
||||||
const items = await CharacterTypeRepository.getAll()
|
|
||||||
callback(items)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +1,41 @@
|
|||||||
import { CharacterGender, CharacterRace } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { Server } from 'socket.io'
|
import { CharacterGender, CharacterRace } from '#application/enums'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import prisma from '#application/prisma'
|
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||||
import { TSocket } from '#application/types'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: number
|
id: UUID
|
||||||
name: string
|
name: string
|
||||||
gender: CharacterGender
|
gender: CharacterGender
|
||||||
race: CharacterRace
|
race: CharacterRace
|
||||||
isSelectable: boolean
|
isSelectable: boolean
|
||||||
spriteId: string
|
spriteId: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CharacterTypeUpdateEvent {
|
export default class CharacterTypeUpdateEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:characterType:update', this.handleEvent.bind(this))
|
this.socket.on('gm:characterType:update', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId!)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prisma.characterType.update({
|
if (!(await this.isCharacterGM())) return
|
||||||
where: { id: data.id },
|
|
||||||
data: {
|
|
||||||
name: data.name,
|
|
||||||
gender: data.gender,
|
|
||||||
race: data.race,
|
|
||||||
isSelectable: data.isSelectable,
|
|
||||||
spriteId: data.spriteId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
callback(true)
|
const characterTypeRepository = new CharacterTypeRepository()
|
||||||
|
const characterType = await characterTypeRepository.getById(data.id)
|
||||||
|
if (!characterType) return callback(false)
|
||||||
|
|
||||||
|
const spriteRepository = new SpriteRepository()
|
||||||
|
const sprite = await spriteRepository.getById(data.spriteId)
|
||||||
|
if (!sprite) return callback(false)
|
||||||
|
|
||||||
|
await characterType.setName(data.name).setGender(data.gender).setRace(data.race).setIsSelectable(data.isSelectable).setSprite(sprite).save()
|
||||||
|
|
||||||
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,22 @@
|
|||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { Item } from '#entities/item'
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
export default class ItemCreateEvent {
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
|
export default class ItemCreateEvent extends BaseEvent {
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:item:create', this.handleEvent.bind(this))
|
this.socket.on('gm:item:create', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: undefined, callback: (response: boolean, item?: any) => void): Promise<void> {
|
private async handleEvent(data: undefined, callback: (response: boolean, item?: any) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
const newItem = new Item()
|
||||||
return callback(false)
|
await newItem.setName('New Item').setItemType('WEAPON').setStackable(false).setRarity('COMMON').setSprite(null).save()
|
||||||
}
|
|
||||||
|
|
||||||
const newItem = await prisma.item.create({
|
return callback(true, newItem)
|
||||||
data: {
|
|
||||||
name: 'New Item',
|
|
||||||
itemType: 'WEAPON',
|
|
||||||
stackable: false,
|
|
||||||
rarity: 'COMMON',
|
|
||||||
spriteId: null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
callback(true, newItem)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating item:', error)
|
console.error('Error creating item:', error)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,30 @@
|
|||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import { gameMasterLogger } from '#application/logger'
|
import ItemRepository from '#repositories/itemRepository'
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
id: string
|
id: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ItemDeleteEvent {
|
export default class ItemDeleteEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:item:remove', this.handleEvent.bind(this))
|
this.socket.on('gm:item:remove', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prisma.item.delete({
|
if (!(await this.isCharacterGM())) return
|
||||||
where: { id: data.id }
|
|
||||||
})
|
|
||||||
|
|
||||||
callback(true)
|
const itemRepository = new ItemRepository()
|
||||||
|
const item = await itemRepository.getById(data.id)
|
||||||
|
if (!item) return callback(false)
|
||||||
|
|
||||||
|
await item.delete()
|
||||||
|
|
||||||
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
gameMasterLogger.error(`Error deleting item ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Error deleting item ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,25 @@
|
|||||||
import { Item } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { Server } from 'socket.io'
|
import { Item } from '#entities/item'
|
||||||
|
import ItemRepository from '#repositories/itemRepository'
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
import itemRepository from '#repositories/itemRepository'
|
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
export default class ItemListEvent {
|
export default class ItemListEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:item:list', this.handleEvent.bind(this))
|
this.socket.on('gm:item:list', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: Item[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: Item[]) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
try {
|
||||||
if (!character) {
|
if (!(await this.isCharacterGM())) return
|
||||||
gameMasterLogger.error('gm:item:list error', 'Character not found')
|
|
||||||
|
const itemRepository = new ItemRepository()
|
||||||
|
const items = await itemRepository.getAll()
|
||||||
|
|
||||||
|
return callback(items)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:item:list error', error)
|
||||||
return callback([])
|
return callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
gameMasterLogger.info(`User ${character.id} tried to list items but is not a game master.`)
|
|
||||||
return callback([])
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all items
|
|
||||||
const items = await itemRepository.getAll()
|
|
||||||
callback(items)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,55 +1,41 @@
|
|||||||
import { ItemType, ItemRarity } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { Server } from 'socket.io'
|
import { ItemType, ItemRarity } from '#application/enums'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import { gameMasterLogger } from '#application/logger'
|
import ItemRepository from '#repositories/itemRepository'
|
||||||
import prisma from '#application/prisma'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: string
|
id: UUID
|
||||||
name: string
|
name: string
|
||||||
description: string | null
|
description: string
|
||||||
itemType: ItemType
|
itemType: ItemType
|
||||||
stackable: boolean
|
stackable: boolean
|
||||||
rarity: ItemRarity
|
rarity: ItemRarity
|
||||||
spriteId: string | null
|
spriteId: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ItemUpdateEvent {
|
export default class ItemUpdateEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:item:update', this.handleEvent.bind(this))
|
this.socket.on('gm:item:update', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prisma.item.update({
|
if (!(await this.isCharacterGM())) return
|
||||||
where: { id: data.id },
|
|
||||||
data: {
|
const itemRepository = new ItemRepository()
|
||||||
name: data.name,
|
const item = await itemRepository.getById(data.id)
|
||||||
description: data.description,
|
if (!item) return callback(false)
|
||||||
itemType: data.itemType,
|
|
||||||
stackable: data.stackable,
|
const spriteRepository = new SpriteRepository()
|
||||||
rarity: data.rarity,
|
const sprite = await spriteRepository.getById(data.spriteId)
|
||||||
spriteId: data.spriteId
|
if (!sprite) return callback(false)
|
||||||
}
|
|
||||||
})
|
await item.setName(data.name).setDescription(data.description).setItemType(data.itemType).setStackable(data.stackable).setRarity(data.rarity).setSprite(sprite).save()
|
||||||
|
|
||||||
return callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
gameMasterLogger.error(`Error updating item: ${error instanceof Error ? error.message : String(error)}`)
|
console.error(error)
|
||||||
return callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
src/events/gameMaster/assetManager/mapObject/list.ts
Normal file
26
src/events/gameMaster/assetManager/mapObject/list.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { MapObject } from '#entities/mapObject'
|
||||||
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||||
|
|
||||||
|
interface IPayload {}
|
||||||
|
|
||||||
|
export default class MapObjectListEvent extends BaseEvent {
|
||||||
|
public listen(): void {
|
||||||
|
this.socket.on('gm:mapObject:list', this.handleEvent.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
// Get all map objects
|
||||||
|
const mapObjectRepository = new MapObjectRepository()
|
||||||
|
const mapObjects = await mapObjectRepository.getAll()
|
||||||
|
|
||||||
|
return callback(mapObjects)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:mapObject:list error', error)
|
||||||
|
return callback([])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
src/events/gameMaster/assetManager/mapObject/remove.ts
Normal file
39
src/events/gameMaster/assetManager/mapObject/remove.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import Storage from '#application/storage'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||||
|
|
||||||
|
interface IPayload {
|
||||||
|
mapObjectId: UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class MapObjectRemoveEvent extends BaseEvent {
|
||||||
|
public listen(): void {
|
||||||
|
this.socket.on('gm:mapObject:remove', this.handleEvent.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
// remove the tile from the disk
|
||||||
|
const finalFilePath = Storage.getPublicPath('map_objects', data.mapObjectId + '.png')
|
||||||
|
fs.unlink(finalFilePath, async (err) => {
|
||||||
|
if (err) {
|
||||||
|
this.logger.error(`Error deleting object ${data.mapObjectId}: ${err.message}`)
|
||||||
|
callback(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapObjectRepository = new MapObjectRepository()
|
||||||
|
await (await mapObjectRepository.getById(data.mapObjectId))?.delete()
|
||||||
|
|
||||||
|
return callback(true)
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`Error deleting object ${data.mapObjectId}: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
|
return callback(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
src/events/gameMaster/assetManager/mapObject/update.ts
Normal file
48
src/events/gameMaster/assetManager/mapObject/update.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||||
|
|
||||||
|
type Payload = {
|
||||||
|
id: UUID
|
||||||
|
name: string
|
||||||
|
tags: string[]
|
||||||
|
originX: number
|
||||||
|
originY: number
|
||||||
|
isAnimated: boolean
|
||||||
|
frameRate: number
|
||||||
|
frameWidth: number
|
||||||
|
frameHeight: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class MapObjectUpdateEvent extends BaseEvent {
|
||||||
|
public listen(): void {
|
||||||
|
this.socket.on('gm:mapObject:update', this.handleEvent.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
const mapObjectRepository = new MapObjectRepository()
|
||||||
|
|
||||||
|
const mapObject = await mapObjectRepository.getById(data.id)
|
||||||
|
if (!mapObject) return callback(false)
|
||||||
|
|
||||||
|
await mapObject
|
||||||
|
.setName(data.name)
|
||||||
|
.setTags(data.tags)
|
||||||
|
.setOriginX(data.originX)
|
||||||
|
.setOriginY(data.originY)
|
||||||
|
.setIsAnimated(data.isAnimated)
|
||||||
|
.setFrameRate(data.frameRate)
|
||||||
|
.setFrameWidth(data.frameWidth)
|
||||||
|
.setFrameHeight(data.frameHeight)
|
||||||
|
.save()
|
||||||
|
|
||||||
|
return callback(true)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return callback(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
src/events/gameMaster/assetManager/mapObject/upload.ts
Normal file
54
src/events/gameMaster/assetManager/mapObject/upload.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import fs from 'fs/promises'
|
||||||
|
import { writeFile } from 'node:fs/promises'
|
||||||
|
|
||||||
|
import sharp from 'sharp'
|
||||||
|
|
||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import Storage from '#application/storage'
|
||||||
|
import { MapObject } from '#entities/mapObject'
|
||||||
|
|
||||||
|
interface IObjectData {
|
||||||
|
[key: string]: Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class MapObjectUploadEvent extends BaseEvent {
|
||||||
|
public listen(): void {
|
||||||
|
this.socket.on('gm:mapObject:upload', this.handleEvent.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleEvent(data: IObjectData, callback: (response: boolean) => void): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
const public_folder = Storage.getPublicPath('map_objects')
|
||||||
|
|
||||||
|
// Ensure the folder exists
|
||||||
|
await fs.mkdir(public_folder, { recursive: true })
|
||||||
|
|
||||||
|
const uploadPromises = Object.entries(data).map(async ([key, objectData]) => {
|
||||||
|
// Get image dimensions
|
||||||
|
const metadata = await sharp(objectData).metadata()
|
||||||
|
const width = metadata.width || 0
|
||||||
|
const height = metadata.height || 0
|
||||||
|
|
||||||
|
// Create new map object and save it to database
|
||||||
|
const mapObject = new MapObject()
|
||||||
|
await mapObject.setName('New map object').setTags([]).setOriginX(0).setOriginY(0).setFrameWidth(width).setFrameHeight(height).save()
|
||||||
|
|
||||||
|
// Save image to disk
|
||||||
|
const uuid = mapObject.getId()
|
||||||
|
const filename = `${uuid}.png`
|
||||||
|
const finalFilePath = Storage.getPublicPath('map_objects', filename)
|
||||||
|
await writeFile(finalFilePath, objectData)
|
||||||
|
|
||||||
|
this.logger.info('gm:mapObject:upload', `Object ${key} uploaded with id ${uuid}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
await Promise.all(uploadPromises)
|
||||||
|
return callback(true)
|
||||||
|
} catch (error: any) {
|
||||||
|
this.logger.error('gm:mapObject:upload error', error.message)
|
||||||
|
return callback(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,32 +0,0 @@
|
|||||||
import { Object } from '@prisma/client'
|
|
||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
import ObjectRepository from '#repositories/objectRepository'
|
|
||||||
|
|
||||||
interface IPayload {}
|
|
||||||
|
|
||||||
export default class ObjectListEvent {
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
|
||||||
this.socket.on('gm:object:list', this.handleEvent.bind(this))
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: Object[]) => void): Promise<void> {
|
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback([])
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback([])
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all objects
|
|
||||||
const objects = await ObjectRepository.getAll()
|
|
||||||
callback(objects)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
import fs from 'fs'
|
|
||||||
|
|
||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import { gameLogger, gameMasterLogger } from '#application/logger'
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import Storage from '#application/storage'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
interface IPayload {
|
|
||||||
object: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class ObjectRemoveEvent {
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
|
||||||
this.socket.on('gm:object:remove', this.handleEvent.bind(this))
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await prisma.object.delete({
|
|
||||||
where: {
|
|
||||||
id: data.object
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// get root path
|
|
||||||
const public_folder = Storage.getPublicPath('objects')
|
|
||||||
|
|
||||||
// remove the tile from the disk
|
|
||||||
const finalFilePath = Storage.getPublicPath('objects', data.object + '.png')
|
|
||||||
fs.unlink(finalFilePath, (err) => {
|
|
||||||
if (err) {
|
|
||||||
gameMasterLogger.error(`Error deleting object ${data.object}: ${err.message}`)
|
|
||||||
callback(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(true)
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
gameLogger.error(`Error deleting object ${data.object}: ${error instanceof Error ? error.message : String(error)}`)
|
|
||||||
callback(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
type Payload = {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
tags: string[]
|
|
||||||
originX: number
|
|
||||||
originY: number
|
|
||||||
isAnimated: boolean
|
|
||||||
frameRate: number
|
|
||||||
frameWidth: number
|
|
||||||
frameHeight: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class ObjectUpdateEvent {
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
|
||||||
this.socket.on('gm:object:update', this.handleEvent.bind(this))
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const object = await prisma.object.update({
|
|
||||||
where: {
|
|
||||||
id: data.id
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
name: data.name,
|
|
||||||
tags: data.tags,
|
|
||||||
originX: data.originX,
|
|
||||||
originY: data.originY,
|
|
||||||
isAnimated: data.isAnimated,
|
|
||||||
frameRate: data.frameRate,
|
|
||||||
frameWidth: data.frameWidth,
|
|
||||||
frameHeight: data.frameHeight
|
|
||||||
}
|
|
||||||
})
|
|
||||||
callback(true)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
callback(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
import fs from 'fs/promises'
|
|
||||||
import { writeFile } from 'node:fs/promises'
|
|
||||||
|
|
||||||
import sharp from 'sharp'
|
|
||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import Storage from '#application/storage'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
interface IObjectData {
|
|
||||||
[key: string]: Buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class ObjectUploadEvent {
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
|
||||||
this.socket.on('gm:object:upload', this.handleEvent.bind(this))
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleEvent(data: IObjectData, callback: (response: boolean) => void): Promise<void> {
|
|
||||||
try {
|
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
const public_folder = Storage.getPublicPath('objects')
|
|
||||||
|
|
||||||
// Ensure the folder exists
|
|
||||||
await fs.mkdir(public_folder, { recursive: true })
|
|
||||||
|
|
||||||
const uploadPromises = Object.entries(data).map(async ([key, objectData]) => {
|
|
||||||
// Get image dimensions
|
|
||||||
const metadata = await sharp(objectData).metadata()
|
|
||||||
const width = metadata.width || 0
|
|
||||||
const height = metadata.height || 0
|
|
||||||
|
|
||||||
const object = await prisma.object.create({
|
|
||||||
data: {
|
|
||||||
name: key,
|
|
||||||
tags: [],
|
|
||||||
originX: 0,
|
|
||||||
originY: 0,
|
|
||||||
frameWidth: width,
|
|
||||||
frameHeight: height
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const uuid = object.id
|
|
||||||
const filename = `${uuid}.png`
|
|
||||||
const finalFilePath = Storage.getPublicPath('objects', filename)
|
|
||||||
await writeFile(finalFilePath, objectData)
|
|
||||||
|
|
||||||
gameMasterLogger.info('gm:object:upload', `Object ${key} uploaded with id ${uuid}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
await Promise.all(uploadPromises)
|
|
||||||
|
|
||||||
callback(true)
|
|
||||||
} catch (error: any) {
|
|
||||||
gameMasterLogger.error('gm:object:upload error', error.message)
|
|
||||||
callback(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +1,39 @@
|
|||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import type { Prisma } from '@prisma/client'
|
import { Sprite } from '#entities/sprite'
|
||||||
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
interface CopyPayload {
|
interface CopyPayload {
|
||||||
id: string
|
id: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class SpriteCopyEvent {
|
export default class SpriteCopyEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:sprite:copy', this.handleEvent.bind(this))
|
this.socket.on('gm:sprite:copy', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(payload: CopyPayload, callback: (success: boolean) => void): Promise<void> {
|
private async handleEvent(payload: CopyPayload, callback: (success: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!(await this.validateGameMasterAccess())) {
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
const spriteRepository = new SpriteRepository()
|
||||||
|
const sourceSprite = await spriteRepository.getById(payload.id)
|
||||||
|
|
||||||
|
if (!sourceSprite) {
|
||||||
|
this.logger.error('gm:sprite:copy error', 'Source sprite not found')
|
||||||
return callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sourceSprite = await prisma.sprite.findUnique({
|
// Populate source sprite with spriteActions
|
||||||
where: { id: payload.id },
|
await spriteRepository.getEntityManager().populate(sourceSprite, ['spriteActions'])
|
||||||
include: {
|
|
||||||
spriteActions: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!sourceSprite) {
|
const newSprite = new Sprite()
|
||||||
throw new Error('Source sprite not found')
|
await newSprite.setName(`${sourceSprite.getName()} (Copy)`).setSpriteActions(sourceSprite.getSpriteActions()).save()
|
||||||
}
|
|
||||||
|
|
||||||
const newSprite = await prisma.sprite.create({
|
return callback(true)
|
||||||
data: {
|
|
||||||
name: `${sourceSprite.name} (Copy)`,
|
|
||||||
spriteActions: {
|
|
||||||
create: sourceSprite.spriteActions.map((action) => ({
|
|
||||||
action: action.action,
|
|
||||||
sprites: action.sprites as Prisma.InputJsonValue,
|
|
||||||
originX: action.originX,
|
|
||||||
originY: action.originY,
|
|
||||||
isAnimated: action.isAnimated,
|
|
||||||
isLooping: action.isLooping,
|
|
||||||
frameWidth: action.frameWidth,
|
|
||||||
frameHeight: action.frameHeight,
|
|
||||||
frameRate: action.frameRate
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
callback(true)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.handleError(error, payload.id, callback)
|
this.logger.error(`Error copying sprite:`, String(error))
|
||||||
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async validateGameMasterAccess(): Promise<boolean> {
|
|
||||||
const character = await CharacterRepository.getById(this.socket.characterId!)
|
|
||||||
return character?.role === 'gm'
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleError(error: unknown, spriteId: string, callback: (success: boolean) => void): void {
|
|
||||||
gameMasterLogger.error(`Error copying sprite ${spriteId}: ${this.getErrorMessage(error)}`)
|
|
||||||
callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
private getErrorMessage(error: unknown): string {
|
|
||||||
return error instanceof Error ? error.message : String(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,51 +1,36 @@
|
|||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
|
|
||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import Storage from '#application/storage'
|
import Storage from '#application/storage'
|
||||||
import { TSocket } from '#application/types'
|
import { Sprite } from '#entities/sprite'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
export default class SpriteCreateEvent {
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
|
export default class SpriteCreateEvent extends BaseEvent {
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:sprite:create', this.handleEvent.bind(this))
|
this.socket.on('gm:sprite:create', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const character = await characterRepository.getById(this.socket.characterId!)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
const public_folder = Storage.getPublicPath('sprites')
|
const public_folder = Storage.getPublicPath('sprites')
|
||||||
|
|
||||||
// Ensure the folder exists
|
// Ensure the folder exists
|
||||||
await fs.mkdir(public_folder, { recursive: true })
|
await fs.mkdir(public_folder, { recursive: true })
|
||||||
|
|
||||||
const sprite = await prisma.sprite.create({
|
const sprite = new Sprite()
|
||||||
data: {
|
await sprite.setName('New sprite').save()
|
||||||
name: 'New sprite'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const uuid = sprite.id
|
const uuid = sprite.id
|
||||||
|
|
||||||
// Create folder with uuid
|
// Create folder with uuid
|
||||||
const sprite_folder = Storage.getPublicPath('sprites', uuid)
|
const sprite_folder = Storage.getPublicPath('sprites', uuid)
|
||||||
await fs.mkdir(sprite_folder, { recursive: true })
|
await fs.mkdir(sprite_folder, { recursive: true })
|
||||||
|
|
||||||
callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating sprite:', error)
|
console.error('Error creating sprite:', error)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,46 +1,33 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
|
||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import Storage from '#application/storage'
|
import Storage from '#application/storage'
|
||||||
import { TSocket } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: string
|
id: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GMSpriteDeleteEvent {
|
export default class GMSpriteDeleteEvent extends BaseEvent {
|
||||||
private readonly public_folder: string
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {
|
|
||||||
this.public_folder = Storage.getPublicPath('sprites')
|
|
||||||
}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:sprite:delete', this.handleEvent.bind(this))
|
this.socket.on('gm:sprite:delete', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
||||||
const character = await CharacterRepository.getById(this.socket.characterId!)
|
|
||||||
if (character?.role !== 'gm') {
|
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.deleteSpriteFolder(data.id)
|
if (!(await this.isCharacterGM())) return
|
||||||
await this.deleteSpriteFromDatabase(data.id)
|
|
||||||
|
|
||||||
gameMasterLogger.info(`Sprite ${data.id} deleted.`)
|
await this.deleteSpriteFolder(data.id)
|
||||||
callback(true)
|
|
||||||
|
const spriteRepository = new SpriteRepository()
|
||||||
|
await (await spriteRepository.getById(data.id))?.delete()
|
||||||
|
|
||||||
|
this.logger.info(`Sprite ${data.id} deleted.`)
|
||||||
|
return callback(true)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
gameMasterLogger.error('gm:sprite:delete error', error.message)
|
this.logger.error('gm:sprite:delete error', error.message)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,12 +38,4 @@ export default class GMSpriteDeleteEvent {
|
|||||||
await fs.promises.rmdir(finalFilePath, { recursive: true })
|
await fs.promises.rmdir(finalFilePath, { recursive: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async deleteSpriteFromDatabase(spriteId: string): Promise<void> {
|
|
||||||
await prisma.sprite.delete({
|
|
||||||
where: {
|
|
||||||
id: spriteId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,27 @@
|
|||||||
import { Sprite } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { Server } from 'socket.io'
|
import { Sprite } from '#entities/sprite'
|
||||||
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
import SpriteRepository from '#repositories/spriteRepository'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
export default class SpriteListEvent {
|
export default class SpriteListEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:sprite:list', this.handleEvent.bind(this))
|
this.socket.on('gm:sprite:list', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: any, callback: (response: Sprite[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: Sprite[]) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId!)
|
try {
|
||||||
if (!character) return callback([])
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
// Get all sprites
|
||||||
|
const spriteRepository = new SpriteRepository()
|
||||||
|
const sprites = await spriteRepository.getAll()
|
||||||
|
await spriteRepository.getEntityManager().populate(sprites, ['spriteActions'])
|
||||||
|
|
||||||
|
return callback(sprites)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:sprite:list error', error)
|
||||||
return callback([])
|
return callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all sprites
|
|
||||||
const sprites = await SpriteRepository.getAll()
|
|
||||||
callback(sprites)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import { writeFile, mkdir } from 'node:fs/promises'
|
import { writeFile, mkdir } from 'node:fs/promises'
|
||||||
|
|
||||||
import sharp from 'sharp'
|
import sharp from 'sharp'
|
||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import type { Prisma, SpriteAction } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import Storage from '#application/storage'
|
import Storage from '#application/storage'
|
||||||
import { TSocket } from '#application/types'
|
import { SpriteAction } from '#entities/spriteAction'
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const ISOMETRIC_CONFIG = {
|
const ISOMETRIC_CONFIG = {
|
||||||
@ -41,7 +37,7 @@ interface SpriteActionInput extends Omit<SpriteAction, 'id' | 'spriteId' | 'fram
|
|||||||
interface UpdatePayload {
|
interface UpdatePayload {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
spriteActions: Prisma.JsonValue
|
spriteActions: SpriteAction[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ProcessedSpriteAction extends SpriteActionInput {
|
interface ProcessedSpriteAction extends SpriteActionInput {
|
||||||
@ -62,21 +58,14 @@ interface SpriteAnalysis {
|
|||||||
contentBounds: ContentBounds
|
contentBounds: ContentBounds
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class SpriteUpdateEvent {
|
export default class SpriteUpdateEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:sprite:update', this.handleEvent.bind(this))
|
this.socket.on('gm:sprite:update', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(payload: UpdatePayload, callback: (success: boolean) => void): Promise<void> {
|
private async handleEvent(payload: UpdatePayload, callback: (success: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!(await this.validateGameMasterAccess())) {
|
if (!(await this.isCharacterGM())) return
|
||||||
return callback(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedActions = this.validateSpriteActions(payload.spriteActions)
|
const parsedActions = this.validateSpriteActions(payload.spriteActions)
|
||||||
|
|
||||||
@ -111,11 +100,6 @@ export default class SpriteUpdateEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async validateGameMasterAccess(): Promise<boolean> {
|
|
||||||
const character = await CharacterRepository.getById(this.socket.characterId!)
|
|
||||||
return character?.role === 'gm'
|
|
||||||
}
|
|
||||||
|
|
||||||
private validateSpriteActions(actions: Prisma.JsonValue): SpriteActionInput[] {
|
private validateSpriteActions(actions: Prisma.JsonValue): SpriteActionInput[] {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(JSON.stringify(actions)) as SpriteActionInput[]
|
const parsed = JSON.parse(JSON.stringify(actions)) as SpriteActionInput[]
|
||||||
@ -375,6 +359,8 @@ export default class SpriteUpdateEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await (await SpriteRepository.getById(id))?.setName(name).setSpriteActions(actions).update()
|
||||||
}
|
}
|
||||||
|
|
||||||
private mapActionToDatabase(action: ProcessedSpriteAction) {
|
private mapActionToDatabase(action: ProcessedSpriteAction) {
|
||||||
@ -392,7 +378,7 @@ export default class SpriteUpdateEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleError(error: unknown, spriteId: string, callback: (success: boolean) => void): void {
|
private handleError(error: unknown, spriteId: string, callback: (success: boolean) => void): void {
|
||||||
gameMasterLogger.error(`Error updating sprite ${spriteId}: ${this.getErrorMessage(error)}`)
|
this.logger.error(`Error updating sprite ${spriteId}: ${this.getErrorMessage(error)}`)
|
||||||
callback(false)
|
callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,58 +1,36 @@
|
|||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
|
|
||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import Storage from '#application/storage'
|
import Storage from '#application/storage'
|
||||||
import { TSocket } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
import TileRepository from '#repositories/tileRepository'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: string
|
id: UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GMTileDeleteEvent {
|
export default class GMTileDeleteEvent extends BaseEvent {
|
||||||
private readonly public_folder: string
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {
|
|
||||||
this.public_folder = Storage.getPublicPath('tiles')
|
|
||||||
}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:tile:delete', this.handleEvent.bind(this))
|
this.socket.on('gm:tile:delete', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gameMasterLogger.info(`Deleting tile ${data.id}`)
|
if (!(await this.isCharacterGM())) return
|
||||||
await this.deleteTileFromDatabase(data.id)
|
|
||||||
|
this.logger.info(`Deleting tile ${data.id}`)
|
||||||
|
|
||||||
await this.deleteTileFile(data.id)
|
await this.deleteTileFile(data.id)
|
||||||
|
|
||||||
gameMasterLogger.info(`Tile ${data.id} deleted successfully.`)
|
const tileRepository = new TileRepository()
|
||||||
callback(true)
|
await (await tileRepository.getById(data.id))?.delete()
|
||||||
} catch (error: any) {
|
|
||||||
gameMasterLogger.error('gm:tile:delete error', error.message)
|
|
||||||
callback(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async deleteTileFromDatabase(tileId: string): Promise<void> {
|
this.logger.info(`Tile ${data.id} deleted successfully.`)
|
||||||
await prisma.tile.delete({
|
return callback(true)
|
||||||
where: {
|
} catch (error: unknown) {
|
||||||
id: tileId
|
this.logger.error('gm:tile:delete error', error)
|
||||||
}
|
return callback(false)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async deleteTileFile(tileId: string): Promise<void> {
|
private async deleteTileFile(tileId: string): Promise<void> {
|
||||||
@ -63,7 +41,7 @@ export default class GMTileDeleteEvent {
|
|||||||
if (error.code !== 'ENOENT') {
|
if (error.code !== 'ENOENT') {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
gameMasterLogger.warn(`File ${finalFilePath} does not exist.`)
|
this.logger.warn(`File ${finalFilePath} does not exist.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,25 @@
|
|||||||
import { Tile } from '@prisma/client'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { Server } from 'socket.io'
|
import { Tile } from '#entities/tile'
|
||||||
|
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
import TileRepository from '#repositories/tileRepository'
|
import TileRepository from '#repositories/tileRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
export default class TileListEvent {
|
export default class TileListEven extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:tile:list', this.handleEvent.bind(this))
|
this.socket.on('gm:tile:list', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: any, callback: (response: Tile[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: Tile[]) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
try {
|
||||||
if (!character) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
// Get all tiles
|
||||||
return
|
const tileRepository = new TileRepository()
|
||||||
|
const tiles = await tileRepository.getAll()
|
||||||
|
return callback(tiles)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:tile:list error', error)
|
||||||
|
return callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all tiles
|
|
||||||
const tiles = await TileRepository.getAll()
|
|
||||||
callback(tiles)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,48 +1,32 @@
|
|||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import prisma from '#application/prisma'
|
import TileRepository from '#repositories/tileRepository'
|
||||||
import { TSocket } from '#application/types'
|
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: string
|
id: UUID
|
||||||
name: string
|
name: string
|
||||||
tags: string[]
|
tags: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class TileUpdateEvent {
|
export default class TileUpdateEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:tile:update', this.handleEvent.bind(this))
|
this.socket.on('gm:tile:update', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const Tile = await prisma.tile.update({
|
if (!(await this.isCharacterGM())) return
|
||||||
where: {
|
|
||||||
id: data.id
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
name: data.name,
|
|
||||||
tags: data.tags
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
callback(true)
|
const tileRepository = new TileRepository()
|
||||||
|
|
||||||
|
const tile = await tileRepository.getById(data.id)
|
||||||
|
if (!tile) return callback(false)
|
||||||
|
|
||||||
|
await tile.setName(data.name).setTags(data.tags).save()
|
||||||
|
|
||||||
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
return callback(false)
|
||||||
callback(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,22 @@
|
|||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import { writeFile } from 'node:fs/promises'
|
import { writeFile } from 'node:fs/promises'
|
||||||
|
|
||||||
import { Server } from 'socket.io'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
|
||||||
import { gameMasterLogger } from '#application/logger'
|
|
||||||
import prisma from '#application/prisma'
|
|
||||||
import Storage from '#application/storage'
|
import Storage from '#application/storage'
|
||||||
import { TSocket } from '#application/types'
|
import { Tile } from '#entities/tile'
|
||||||
import characterRepository from '#repositories/characterRepository'
|
|
||||||
|
|
||||||
interface ITileData {
|
interface ITileData {
|
||||||
[key: string]: Buffer
|
[key: string]: Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class TileUploadEvent {
|
export default class TileUploadEvent extends BaseEvent {
|
||||||
constructor(
|
|
||||||
private readonly io: Server,
|
|
||||||
private readonly socket: TSocket
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('gm:tile:upload', this.handleEvent.bind(this))
|
this.socket.on('gm:tile:upload', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: ITileData, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: ITileData, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
if (!(await this.isCharacterGM())) return
|
||||||
if (!character) return callback(false)
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const public_folder = Storage.getPublicPath('tiles')
|
const public_folder = Storage.getPublicPath('tiles')
|
||||||
|
|
||||||
@ -38,12 +24,9 @@ export default class TileUploadEvent {
|
|||||||
await fs.mkdir(public_folder, { recursive: true })
|
await fs.mkdir(public_folder, { recursive: true })
|
||||||
|
|
||||||
const uploadPromises = Object.entries(data).map(async ([key, tileData]) => {
|
const uploadPromises = Object.entries(data).map(async ([key, tileData]) => {
|
||||||
const tile = await prisma.tile.create({
|
const tile = new Tile()
|
||||||
data: {
|
await tile.setName('New tile').save()
|
||||||
name: 'New tile'
|
const uuid = tile.getId()
|
||||||
}
|
|
||||||
})
|
|
||||||
const uuid = tile.id
|
|
||||||
const filename = `${uuid}.png`
|
const filename = `${uuid}.png`
|
||||||
const finalFilePath = Storage.getPublicPath('tiles', filename)
|
const finalFilePath = Storage.getPublicPath('tiles', filename)
|
||||||
await writeFile(finalFilePath, tileData)
|
await writeFile(finalFilePath, tileData)
|
||||||
@ -51,10 +34,10 @@ export default class TileUploadEvent {
|
|||||||
|
|
||||||
await Promise.all(uploadPromises)
|
await Promise.all(uploadPromises)
|
||||||
|
|
||||||
callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
gameMasterLogger.error('Error uploading tile:', error)
|
this.logger.error('Error uploading tile:', error)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
src/events/gameMaster/mapEditor/create.ts
Normal file
40
src/events/gameMaster/mapEditor/create.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import MapRepository from '#repositories/mapRepository'
|
||||||
|
|
||||||
|
type Payload = {
|
||||||
|
name: string
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class MapCreateEvent extends BaseEvent {
|
||||||
|
public listen(): void {
|
||||||
|
this.socket.on('gm:map:create', this.handleEvent.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleEvent(data: Payload, callback: (response: Map[]) => void): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
this.logger.info(`User ${(await this.getCharacter())!.getId()} has created a new map via map editor.`)
|
||||||
|
|
||||||
|
const map = new Map()
|
||||||
|
await map
|
||||||
|
.setName(data.name)
|
||||||
|
.setWidth(data.width)
|
||||||
|
.setHeight(data.height)
|
||||||
|
.setTiles(Array.from({ length: data.height }, () => Array.from({ length: data.width }, () => 'blank_tile')))
|
||||||
|
.save()
|
||||||
|
|
||||||
|
const mapRepository = new MapRepository()
|
||||||
|
const mapList = await mapRepository.getAll()
|
||||||
|
|
||||||
|
return callback(mapList)
|
||||||
|
} catch (error: any) {
|
||||||
|
this.logger.error('gm:map:create error', error.message)
|
||||||
|
this.socket.emit('notification', { message: 'Failed to create map.' })
|
||||||
|
return callback([])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
src/events/gameMaster/mapEditor/delete.ts
Normal file
30
src/events/gameMaster/mapEditor/delete.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import MapRepository from '#repositories/mapRepository'
|
||||||
|
|
||||||
|
type Payload = {
|
||||||
|
mapId: UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class MapDeleteEvent extends BaseEvent {
|
||||||
|
public listen(): void {
|
||||||
|
this.socket.on('gm:map:delete', this.handleEvent.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.logger.info(`Deleting map ${data.mapId}`)
|
||||||
|
|
||||||
|
const mapRepository = new MapRepository()
|
||||||
|
await (await mapRepository.getById(data.mapId))?.delete()
|
||||||
|
|
||||||
|
this.logger.info(`Map ${data.mapId} deleted successfully.`)
|
||||||
|
return callback(true)
|
||||||
|
} catch (error: unknown) {
|
||||||
|
this.logger.error('gm:map:delete error', error)
|
||||||
|
return callback(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
src/events/gameMaster/mapEditor/list.ts
Normal file
27
src/events/gameMaster/mapEditor/list.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import MapRepository from '#repositories/mapRepository'
|
||||||
|
|
||||||
|
interface IPayload {}
|
||||||
|
|
||||||
|
export default class MapListEvent extends BaseEvent {
|
||||||
|
public listen(): void {
|
||||||
|
this.socket.on('gm:map:list', this.handleEvent.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleEvent(data: IPayload, callback: (response: Map[]) => void): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
this.logger.info(`User ${(await this.getCharacter())!.getId()} has listed maps via map editor.`)
|
||||||
|
|
||||||
|
const mapRepository = new MapRepository()
|
||||||
|
const maps = await mapRepository.getAll()
|
||||||
|
|
||||||
|
return callback(maps)
|
||||||
|
} catch (error: any) {
|
||||||
|
this.logger.error('gm:map:list error', error.message)
|
||||||
|
return callback([])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user