From a5c941cbb084d094be1d21c46b8ab09328a5b77d Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Mon, 30 Dec 2024 01:37:49 +0100 Subject: [PATCH] Added note, added new init migration --- ...26153149.ts => Migration20241229234130.ts} | 6 +-- package-lock.json | 43 +++++++++++++++++-- src/entities/character.ts | 6 +-- src/events/character/connect.ts | 2 + 4 files changed, 48 insertions(+), 9 deletions(-) rename migrations/{Migration20241226153149.ts => Migration20241229234130.ts} (94%) diff --git a/migrations/Migration20241226153149.ts b/migrations/Migration20241229234130.ts similarity index 94% rename from migrations/Migration20241226153149.ts rename to migrations/Migration20241229234130.ts index 2c7bbed..5e9a33d 100644 --- a/migrations/Migration20241226153149.ts +++ b/migrations/Migration20241229234130.ts @@ -1,6 +1,6 @@ import { Migration } from '@mikro-orm/migrations'; -export class Migration20241226153149 extends Migration { +export class Migration20241229234130 extends Migration { override async up(): Promise { 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;`); @@ -33,7 +33,7 @@ export class Migration20241226153149 extends Migration { this.addSql(`create table \`zone\` (\`id\` int unsigned not null auto_increment primary key, \`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) default character set utf8mb4 engine = InnoDB;`); - this.addSql(`create table \`character\` (\`id\` int unsigned not null auto_increment primary key, \`user_id\` int unsigned not null, \`name\` varchar(255) not null, \`online\` tinyint(1) not null default false, \`role\` varchar(255) not null default 'player', \`zone_id\` int unsigned null, \`position_x\` int not null default 0, \`position_y\` int not null default 0, \`rotation\` int not null default 0, \`character_type_id\` int unsigned null, \`character_hair_id\` int unsigned 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) default character set utf8mb4 engine = InnoDB;`); + this.addSql(`create table \`character\` (\`id\` int unsigned not null auto_increment primary key, \`user_id\` int unsigned not null, \`name\` varchar(255) not null, \`online\` tinyint(1) not null default false, \`role\` varchar(255) not null default 'player', \`zone_id\` int unsigned 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\` int unsigned null, \`character_hair_id\` int unsigned 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) 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 unique \`character_name_unique\`(\`name\`);`); this.addSql(`alter table \`character\` add index \`character_zone_id_index\`(\`zone_id\`);`); @@ -77,7 +77,7 @@ export class Migration20241226153149 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;`); this.addSql(`alter table \`character\` add constraint \`character_user_id_foreign\` foreign key (\`user_id\`) references \`user\` (\`id\`) on update cascade;`); - this.addSql(`alter table \`character\` add constraint \`character_zone_id_foreign\` foreign key (\`zone_id\`) references \`zone\` (\`id\`) on update cascade on delete set null;`); + 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_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;`); diff --git a/package-lock.json b/package-lock.json index ca05886..11b830f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3085,9 +3085,9 @@ } }, "node_modules/es-abstract": { - "version": "1.23.7", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.23.7.tgz", - "integrity": "sha512-OygGC8kIcDhXX+6yAZRGLqwi2CmEXCbLQixeGUgYeR+Qwlppqmo7DIDr8XibtEBZp+fJcoYpoatp5qwLMEdcqQ==", + "version": "1.23.8", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.23.8.tgz", + "integrity": "sha512-lfab8IzDn6EpI1ibZakcgS6WsfEBiB+43cuJo+wgylx1xKXf+Sp+YR3vFuQwC/u3sxYwV8Cxe3B0DpVUu/WiJQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3126,8 +3126,10 @@ "object-inspect": "^1.13.3", "object-keys": "^1.1.1", "object.assign": "^4.1.7", + "own-keys": "^1.0.0", "regexp.prototype.flags": "^1.5.3", "safe-array-concat": "^1.1.3", + "safe-push-apply": "^1.0.0", "safe-regex-test": "^1.1.0", "string.prototype.trim": "^1.2.10", "string.prototype.trimend": "^1.0.9", @@ -5729,6 +5731,24 @@ "node": ">= 0.8.0" } }, + "node_modules/own-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/own-keys/-/own-keys-1.0.0.tgz", + "integrity": "sha512-HcuIjzpjrUbqZPGzWHVg95Bc2Y37KoY5n66QQyEGMzrIWVKHsgHcv8/Aq5Cu3qFUQJzMSPVP8MD3oaFoaME1lg==", + "dev": true, + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.2.6", + "object-keys": "^1.1.1", + "safe-push-apply": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -6294,6 +6314,23 @@ ], "license": "MIT" }, + "node_modules/safe-push-apply": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/safe-push-apply/-/safe-push-apply-1.0.0.tgz", + "integrity": "sha512-iKE9w/Z7xCzUMIZqdBsp6pEQvwuEebH4vdpjcDWnyzaI6yl6O9FHvVpmGelvEHNsoY6wGblkxR6Zty/h00WiSA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "isarray": "^2.0.5" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/safe-regex-test": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.1.0.tgz", diff --git a/src/entities/character.ts b/src/entities/character.ts index 71ab275..66946ab 100644 --- a/src/entities/character.ts +++ b/src/entities/character.ts @@ -31,8 +31,8 @@ export class Character extends BaseEntity { chats = new Collection(this) // Position - @ManyToOne(() => Zone, { nullable: true }) - zone?: Zone + @ManyToOne() + zone!: Zone @Property() positionX = 0 @@ -139,7 +139,7 @@ export class Character extends BaseEntity { return this.chats } - setZone(zone: Zone | undefined) { + setZone(zone: Zone) { this.zone = zone return this } diff --git a/src/events/character/connect.ts b/src/events/character/connect.ts index fd1622f..f8744b3 100644 --- a/src/events/character/connect.ts +++ b/src/events/character/connect.ts @@ -55,6 +55,8 @@ export default class CharacterConnectEvent extends BaseEvent { // Emit character connect event callback({ character }) + + // @TODO: Teleport character into zone } catch (error) { this.handleError('Failed to connect character', error) }