Compare commits
35 Commits
feature/#2
...
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 |
@ -3,6 +3,6 @@
|
|||||||
"semi": false,
|
"semi": false,
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"printWidth": 300,
|
"printWidth": 200,
|
||||||
"trailingComma": "none"
|
"trailingComma": "none"
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { Migration } from '@mikro-orm/migrations';
|
import { Migration } from '@mikro-orm/migrations';
|
||||||
|
|
||||||
export class Migration20250103003053 extends Migration {
|
export class Migration20250106170204 extends Migration {
|
||||||
|
|
||||||
override async up(): Promise<void> {
|
override async up(): Promise<void> {
|
||||||
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\` (\`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;`);
|
||||||
@ -23,7 +23,7 @@ export class Migration20250103003053 extends Migration {
|
|||||||
|
|
||||||
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;`);
|
@ -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,
|
||||||
|
152
package-lock.json
generated
152
package-lock.json
generated
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "noxious-server",
|
"name": "nq-server",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
@ -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",
|
||||||
@ -3760,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"
|
||||||
@ -3811,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": {
|
||||||
@ -4051,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"
|
||||||
@ -4083,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",
|
||||||
@ -4467,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"
|
||||||
@ -4627,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"
|
||||||
@ -5215,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"
|
||||||
@ -5981,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": {
|
||||||
@ -6142,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": {
|
||||||
@ -6165,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": {
|
||||||
@ -6479,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",
|
||||||
|
@ -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()
|
||||||
|
@ -14,7 +14,8 @@ export abstract class BaseEvent {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
protected async getCharacter(): Promise<Character | null> {
|
protected async getCharacter(): Promise<Character | null> {
|
||||||
return CharacterRepository.getById(this.socket.characterId!)
|
const characterRepository = new CharacterRepository()
|
||||||
|
return characterRepository.getById(this.socket.characterId!)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async isCharacterGM(): Promise<boolean> {
|
protected async isCharacterGM(): Promise<boolean> {
|
||||||
|
@ -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'
|
||||||
@ -10,7 +9,7 @@ class Database {
|
|||||||
|
|
||||||
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)
|
||||||
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}`)
|
||||||
@ -18,8 +17,8 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getEntityManager(): EntityManager {
|
public static getORM(): MikroORM {
|
||||||
return Database.orm.em.fork()
|
return this.orm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,13 +9,13 @@ 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 { Map } from '#entities/map'
|
|
||||||
import { MapEffect } from '#entities/mapEffect'
|
|
||||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||||
import MapRepository from '#repositories/mapRepository'
|
import MapRepository from '#repositories/mapRepository'
|
||||||
@ -24,6 +24,10 @@ import MapRepository from '#repositories/mapRepository'
|
|||||||
// 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()
|
||||||
@ -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> {
|
||||||
@ -247,9 +258,9 @@ export default class InitCommand extends BaseCommand {
|
|||||||
.setUser(user)
|
.setUser(user)
|
||||||
.setName('root')
|
.setName('root')
|
||||||
.setRole('gm')
|
.setRole('gm')
|
||||||
.setMap((await MapRepository.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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import { BaseCommand } from '#application/base/baseCommand'
|
import { BaseCommand } from '#application/base/baseCommand'
|
||||||
import MapManager from '#managers/mapManager'
|
import MapManager from '#managers/mapManager'
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
58
src/entities/base/mapEffect.ts
Normal file
58
src/entities/base/mapEffect.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 { Map } from '#entities/map'
|
||||||
|
|
||||||
|
export class BaseMapEffect extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
map!: Map
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
effect!: string
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
strength!: number
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setMap(map: Map) {
|
||||||
|
this.map = map
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMap() {
|
||||||
|
return this.map
|
||||||
|
}
|
||||||
|
|
||||||
|
setEffect(effect: string) {
|
||||||
|
this.effect = effect
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getEffect() {
|
||||||
|
return this.effect
|
||||||
|
}
|
||||||
|
|
||||||
|
setStrength(strength: number) {
|
||||||
|
this.strength = strength
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getStrength() {
|
||||||
|
return this.strength
|
||||||
|
}
|
||||||
|
}
|
84
src/entities/base/mapEventTile.ts
Normal file
84
src/entities/base/mapEventTile.ts
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Entity, Enum, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { MapEventTileType } from '#application/enums'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
||||||
|
|
||||||
|
export class BaseMapEventTile extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
map!: Map
|
||||||
|
|
||||||
|
@Enum(() => MapEventTileType)
|
||||||
|
type!: MapEventTileType
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
positionX!: number
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
positionY!: number
|
||||||
|
|
||||||
|
@OneToOne(() => MapEventTileTeleport, (teleport) => teleport.mapEventTile, { eager: true })
|
||||||
|
teleport?: MapEventTileTeleport
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setMap(map: Map) {
|
||||||
|
this.map = map
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMap() {
|
||||||
|
return this.map
|
||||||
|
}
|
||||||
|
|
||||||
|
setType(type: MapEventTileType) {
|
||||||
|
this.type = type
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getType() {
|
||||||
|
return this.type
|
||||||
|
}
|
||||||
|
|
||||||
|
setPositionX(positionX: number) {
|
||||||
|
this.positionX = positionX
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPositionX() {
|
||||||
|
return this.positionX
|
||||||
|
}
|
||||||
|
|
||||||
|
setPositionY(positionY: number) {
|
||||||
|
this.positionY = positionY
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPositionY() {
|
||||||
|
return this.positionY
|
||||||
|
}
|
||||||
|
|
||||||
|
setTeleport(teleport: MapEventTileTeleport) {
|
||||||
|
this.teleport = teleport
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getTeleport() {
|
||||||
|
return this.teleport
|
||||||
|
}
|
||||||
|
}
|
83
src/entities/base/mapEventTileTeleport.ts
Normal file
83
src/entities/base/mapEventTileTeleport.ts
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
|
import { Entity, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||||
|
|
||||||
|
import { BaseEntity } from '#application/base/baseEntity'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
|
import { Map } from '#entities/map'
|
||||||
|
import { MapEventTile } from '#entities/mapEventTile'
|
||||||
|
|
||||||
|
|
||||||
|
export class BaseMapEventTileTeleport extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@OneToOne({ deleteRule: 'cascade' })
|
||||||
|
mapEventTile!: MapEventTile
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade', eager: true })
|
||||||
|
toMap!: Map
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
toRotation!: number
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
toPositionX!: number
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
toPositionY!: number
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setMapEventTile(mapEventTile: MapEventTile) {
|
||||||
|
this.mapEventTile = mapEventTile
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMapEventTile() {
|
||||||
|
return this.mapEventTile
|
||||||
|
}
|
||||||
|
|
||||||
|
setToMap(toMap: Map) {
|
||||||
|
this.toMap = toMap
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getToMap() {
|
||||||
|
return this.toMap
|
||||||
|
}
|
||||||
|
|
||||||
|
setToRotation(toRotation: number) {
|
||||||
|
this.toRotation = toRotation
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getToRotation() {
|
||||||
|
return this.toRotation
|
||||||
|
}
|
||||||
|
|
||||||
|
setToPositionX(toPositionX: number) {
|
||||||
|
this.toPositionX = toPositionX
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getToPositionX() {
|
||||||
|
return this.toPositionX
|
||||||
|
}
|
||||||
|
|
||||||
|
setToPositionY(toPositionY: number) {
|
||||||
|
this.toPositionY = toPositionY
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getToPositionY() {
|
||||||
|
return this.toPositionY
|
||||||
|
}
|
||||||
|
}
|
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
|
||||||
|
}
|
||||||
|
}
|
97
src/entities/base/placedMapObject.ts
Normal file
97
src/entities/base/placedMapObject.ts
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
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 { Map } from '#entities/map'
|
||||||
|
import { MapObject } from '#entities/mapObject'
|
||||||
|
|
||||||
|
//@TODO : Rename mapObject
|
||||||
|
|
||||||
|
export class BasePlacedMapObject extends BaseEntity {
|
||||||
|
@PrimaryKey()
|
||||||
|
id = randomUUID()
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade' })
|
||||||
|
map!: Map
|
||||||
|
|
||||||
|
@ManyToOne({ deleteRule: 'cascade', eager: true })
|
||||||
|
mapObject!: MapObject
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
depth = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
isRotated = false
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
positionX = 0
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
positionY = 0
|
||||||
|
|
||||||
|
setId(id: UUID) {
|
||||||
|
this.id = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
setMap(map: Map) {
|
||||||
|
this.map = map
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMap() {
|
||||||
|
return this.map
|
||||||
|
}
|
||||||
|
|
||||||
|
setMapObject(mapObject: MapObject) {
|
||||||
|
this.mapObject = mapObject
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getMapObject() {
|
||||||
|
return this.mapObject
|
||||||
|
}
|
||||||
|
|
||||||
|
setDepth(depth: number) {
|
||||||
|
this.depth = depth
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getDepth() {
|
||||||
|
return this.depth
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsRotated(isRotated: boolean) {
|
||||||
|
this.isRotated = isRotated
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getIsRotated() {
|
||||||
|
return this.isRotated
|
||||||
|
}
|
||||||
|
|
||||||
|
setPositionX(positionX: number) {
|
||||||
|
this.positionX = positionX
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPositionX() {
|
||||||
|
return this.positionX
|
||||||
|
}
|
||||||
|
|
||||||
|
setPositionY(positionY: number) {
|
||||||
|
this.positionY = positionY
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getPositionY() {
|
||||||
|
return this.positionY
|
||||||
|
}
|
||||||
|
}
|
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 { Map } from './map'
|
|
||||||
|
|
||||||
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()
|
|
||||||
map!: Map // @TODO: Update to spawn point when current map 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
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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,109 +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
|
|
||||||
|
|
||||||
@ManyToOne({ 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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 { Map } from './map'
|
|
||||||
|
|
||||||
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' })
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,184 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseMap } from '#entities/base/map'
|
||||||
|
|
||||||
import { Character } from './character'
|
|
||||||
import { Chat } from './chat'
|
|
||||||
import { MapEffect } from './mapEffect'
|
|
||||||
import { MapEventTile } from './mapEventTile'
|
|
||||||
import { MapEventTileTeleport } from './mapEventTileTeleport'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
import { PlacedMapObject } from '#entities/placedMapObject'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Map extends BaseEntity {
|
export class Map extends BaseMap {}
|
||||||
@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)
|
|
||||||
mapEffects = new Collection<MapEffect>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => MapEventTile, (tile) => tile.map)
|
|
||||||
mapEventTiles = new Collection<MapEventTile>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => MapEventTileTeleport, (teleport) => teleport.toMap)
|
|
||||||
mapEventTileTeleports = new Collection<MapEventTileTeleport>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => PlacedMapObject, (object) => object.map)
|
|
||||||
placedMapObjects = new Collection<PlacedMapObject>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => Character, (character) => character.map)
|
|
||||||
characters = new Collection<Character>(this)
|
|
||||||
|
|
||||||
@OneToMany(() => Chat, (chat) => chat.map)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
setMapEventTileTeleports(mapEventTileTeleports: Collection<MapEventTileTeleport>) {
|
|
||||||
this.mapEventTileTeleports = mapEventTileTeleports
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMapEventTileTeleports() {
|
|
||||||
return this.mapEventTileTeleports
|
|
||||||
}
|
|
||||||
|
|
||||||
setPlacedMapObjects(placedMapObjects: Collection<PlacedMapObject>) {
|
|
||||||
this.placedMapObjects = placedMapObjects
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPlacedMapObjects() {
|
|
||||||
return this.placedMapObjects
|
|
||||||
}
|
|
||||||
|
|
||||||
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,59 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseMapEffect } from '#entities/base/mapEffect'
|
||||||
|
|
||||||
import { Map } from './map'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class MapEffect extends BaseEntity {
|
export class MapEffect extends BaseMapEffect {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
map!: Map
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
effect!: string
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
strength!: number
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setMap(map: Map) {
|
|
||||||
this.map = map
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMap() {
|
|
||||||
return this.map
|
|
||||||
}
|
|
||||||
|
|
||||||
setEffect(effect: string) {
|
|
||||||
this.effect = effect
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getEffect() {
|
|
||||||
return this.effect
|
|
||||||
}
|
|
||||||
|
|
||||||
setStrength(strength: number) {
|
|
||||||
this.strength = strength
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getStrength() {
|
|
||||||
return this.strength
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,85 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, Enum, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseMapEventTile } from '#entities/base/mapEventTile'
|
||||||
|
|
||||||
import { Map } from './map'
|
|
||||||
import { MapEventTileTeleport } from './mapEventTileTeleport'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { MapEventTileType } from '#application/enums'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class MapEventTile extends BaseEntity {
|
export class MapEventTile extends BaseMapEventTile {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
map!: Map
|
|
||||||
|
|
||||||
@Enum(() => MapEventTileType)
|
|
||||||
type!: MapEventTileType
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
positionX!: number
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
positionY!: number
|
|
||||||
|
|
||||||
@OneToOne(() => MapEventTileTeleport, (teleport) => teleport.mapEventTile)
|
|
||||||
teleport?: MapEventTileTeleport
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setMap(map: Map) {
|
|
||||||
this.map = map
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMap() {
|
|
||||||
return this.map
|
|
||||||
}
|
|
||||||
|
|
||||||
setType(type: MapEventTileType) {
|
|
||||||
this.type = type
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getType() {
|
|
||||||
return this.type
|
|
||||||
}
|
|
||||||
|
|
||||||
setPositionX(positionX: number) {
|
|
||||||
this.positionX = positionX
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPositionX() {
|
|
||||||
return this.positionX
|
|
||||||
}
|
|
||||||
|
|
||||||
setPositionY(positionY: number) {
|
|
||||||
this.positionY = positionY
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPositionY() {
|
|
||||||
return this.positionY
|
|
||||||
}
|
|
||||||
|
|
||||||
setTeleport(teleport: MapEventTileTeleport) {
|
|
||||||
this.teleport = teleport
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getTeleport() {
|
|
||||||
return this.teleport
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,84 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseMapEventTileTeleport } from '#entities/base/mapEventTileTeleport'
|
||||||
|
|
||||||
import { Map } from './map'
|
|
||||||
import { MapEventTile } from './mapEventTile'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class MapEventTileTeleport extends BaseEntity {
|
export class MapEventTileTeleport extends BaseMapEventTileTeleport {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@OneToOne({ deleteRule: 'cascade' })
|
|
||||||
mapEventTile!: MapEventTile
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
toMap!: Map
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
toRotation!: number
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
toPositionX!: number
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
toPositionY!: number
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setMapEventTile(mapEventTile: MapEventTile) {
|
|
||||||
this.mapEventTile = mapEventTile
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMapEventTile() {
|
|
||||||
return this.mapEventTile
|
|
||||||
}
|
|
||||||
|
|
||||||
setToMap(toMap: Map) {
|
|
||||||
this.toMap = toMap
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getToMap() {
|
|
||||||
return this.toMap
|
|
||||||
}
|
|
||||||
|
|
||||||
setToRotation(toRotation: number) {
|
|
||||||
this.toRotation = toRotation
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getToRotation() {
|
|
||||||
return this.toRotation
|
|
||||||
}
|
|
||||||
|
|
||||||
setToPositionX(toPositionX: number) {
|
|
||||||
this.toPositionX = toPositionX
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getToPositionX() {
|
|
||||||
return this.toPositionX
|
|
||||||
}
|
|
||||||
|
|
||||||
setToPositionY(toPositionY: number) {
|
|
||||||
this.toPositionY = toPositionY
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getToPositionY() {
|
|
||||||
return this.toPositionY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,141 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BaseMapObject } from '#entities/base/mapObject'
|
||||||
|
|
||||||
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({ 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,97 +1,6 @@
|
|||||||
import { randomUUID } from 'node:crypto'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
import { BasePlacedMapObject } from '#entities/base/placedMapObject'
|
||||||
|
|
||||||
import { Map } from './map'
|
|
||||||
|
|
||||||
import { BaseEntity } from '#application/base/baseEntity'
|
|
||||||
import { UUID } from '#application/types'
|
|
||||||
import { MapObject } from '#entities/mapObject'
|
|
||||||
|
|
||||||
//@TODO : Rename mapObject
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class PlacedMapObject extends BaseEntity {
|
export class PlacedMapObject extends BasePlacedMapObject {}
|
||||||
@PrimaryKey()
|
|
||||||
id = randomUUID()
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
map!: Map
|
|
||||||
|
|
||||||
@ManyToOne({ deleteRule: 'cascade' })
|
|
||||||
mapObject!: MapObject
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
depth = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
isRotated = false
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
positionX = 0
|
|
||||||
|
|
||||||
@Property()
|
|
||||||
positionY = 0
|
|
||||||
|
|
||||||
setId(id: UUID) {
|
|
||||||
this.id = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getId() {
|
|
||||||
return this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
setMap(map: Map) {
|
|
||||||
this.map = map
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMap() {
|
|
||||||
return this.map
|
|
||||||
}
|
|
||||||
|
|
||||||
setMapObject(mapObject: MapObject) {
|
|
||||||
this.mapObject = mapObject
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getMapObject() {
|
|
||||||
return this.mapObject
|
|
||||||
}
|
|
||||||
|
|
||||||
setDepth(depth: number) {
|
|
||||||
this.depth = depth
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getDepth() {
|
|
||||||
return this.depth
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsRotated(isRotated: boolean) {
|
|
||||||
this.isRotated = isRotated
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsRotated() {
|
|
||||||
return this.isRotated
|
|
||||||
}
|
|
||||||
|
|
||||||
setPositionX(positionX: number) {
|
|
||||||
this.positionX = positionX
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPositionX() {
|
|
||||||
return this.positionX
|
|
||||||
}
|
|
||||||
|
|
||||||
setPositionY(positionY: number) {
|
|
||||||
this.positionY = positionY
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
getPositionY() {
|
|
||||||
return this.positionY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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,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 {}
|
||||||
|
|
||||||
@ -12,8 +11,9 @@ 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> {
|
||||||
try {
|
try {
|
||||||
const items: CharacterHair[] = await characterHairRepository.getAllSelectable()
|
const characterHairRepository = new CharacterHairRepository()
|
||||||
await Database.getEntityManager().populate(items, ['sprite'])
|
const items: CharacterHair[] = await characterHairRepository.getAllSelectable(['sprite'])
|
||||||
|
|
||||||
return callback(items)
|
return callback(items)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('character:hair:list error', error)
|
this.logger.error('character:hair:list error', error)
|
||||||
|
@ -11,6 +11,9 @@ 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))
|
||||||
}
|
}
|
||||||
@ -22,20 +25,23 @@ export default class CharacterConnectEvent extends BaseEvent {
|
|||||||
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
|
||||||
@ -58,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) => MapManager.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 UserRepository from '#repositories/userRepository'
|
|
||||||
import MapRepository from '#repositories/mapRepository'
|
import MapRepository from '#repositories/mapRepository'
|
||||||
|
import UserRepository from '#repositories/userRepository'
|
||||||
|
|
||||||
export default class CharacterCreateEvent extends BaseEvent {
|
export default class CharacterCreateEvent extends BaseEvent {
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
@ -17,27 +17,31 @@ 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 map = await MapRepository.getFirst()
|
const map = await mapRepository.getFirst()
|
||||||
|
|
||||||
const newCharacter = new Character()
|
const newCharacter = new Character()
|
||||||
await newCharacter.setName(data.name).setUser(user).setMap(map!).save()
|
await newCharacter.setName(data.name).setUser(user).setMap(map!).save()
|
||||||
|
@ -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 { Map } from '#entities/map'
|
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
import CharacterRepository from '#repositories/characterRepository'
|
||||||
|
|
||||||
type TypePayload = {
|
type TypePayload = {
|
||||||
@ -19,8 +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 {
|
||||||
await (await CharacterRepository.getByUserAndId(this.socket.userId!, data.characterId))?.delete()
|
const characterRepository = new CharacterRepository()
|
||||||
const characters: Character[] = await CharacterRepository.getByUserId(this.socket.userId!)
|
await (await characterRepository.getByUserAndId(this.socket.userId!, data.characterId))?.delete()
|
||||||
|
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) {
|
||||||
|
@ -9,7 +9,12 @@ export default class CharacterListEvent extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent(data: any): Promise<void> {
|
private async handleEvent(data: any): Promise<void> {
|
||||||
try {
|
try {
|
||||||
let characters: Character[] = await CharacterRepository.getByUserId(this.socket.userId!, ['characterType', 'characterHair'])
|
const characterRepository = new CharacterRepository()
|
||||||
|
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) {
|
||||||
this.logger.error('character:list error', error.message)
|
this.logger.error('character:list error', error.message)
|
||||||
|
@ -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)
|
||||||
|
@ -16,21 +16,15 @@ 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 mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
// Check if command is teleport
|
||||||
if (!mapCharacter) {
|
|
||||||
this.logger.error('chat:message error', 'Character not found')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const character = mapCharacter.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) {
|
||||||
@ -53,7 +47,8 @@ export default class TeleportCommandEvent extends BaseEvent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const map = await MapRepository.getById(mapId)
|
const mapRepository = new MapRepository()
|
||||||
|
const map = await mapRepository.getById(mapId)
|
||||||
if (!map) {
|
if (!map) {
|
||||||
this.socket.emit('notification', {
|
this.socket.emit('notification', {
|
||||||
title: 'Server message',
|
title: 'Server message',
|
||||||
|
@ -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) {
|
||||||
|
@ -26,7 +26,8 @@ export default class ChatMessageEvent extends BaseEvent {
|
|||||||
|
|
||||||
const character = mapCharacter.character
|
const character = mapCharacter.character
|
||||||
|
|
||||||
const map = await MapRepository.getById(character.map.id)
|
const mapRepository = new MapRepository()
|
||||||
|
const map = await mapRepository.getById(character.map.id)
|
||||||
if (!map) {
|
if (!map) {
|
||||||
this.logger.error('chat:message error', 'Map not found')
|
this.logger.error('chat:message error', 'Map not found')
|
||||||
return callback(false)
|
return callback(false)
|
||||||
|
@ -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,6 +1,6 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
id: UUID
|
id: UUID
|
||||||
|
@ -1,6 +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'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -13,7 +13,10 @@ export default class characterHairListEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
const characterHairRepository = new CharacterHairRepository()
|
||||||
const items = await characterHairRepository.getAll()
|
const items = await characterHairRepository.getAll()
|
||||||
|
await characterHairRepository.getEntityManager().populate(items, ['sprite'])
|
||||||
|
|
||||||
return callback(items)
|
return callback(items)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('gm:characterHair:list error', error)
|
this.logger.error('gm:characterHair:list error', error)
|
||||||
|
@ -2,7 +2,6 @@ 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 = {
|
||||||
@ -22,14 +21,15 @@ export default class CharacterHairUpdateEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
const sprite = await SpriteRepository.getById(data.spriteId)
|
const spriteRepository = new SpriteRepository()
|
||||||
const characterHair = await CharacterHairRepository.getById(data.id)
|
const sprite = await spriteRepository.getById(data.spriteId)
|
||||||
|
if (!sprite) return callback(false)
|
||||||
|
|
||||||
if (!characterHair) {
|
const characterHairRepository = new CharacterHairRepository()
|
||||||
return callback(false)
|
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!).update()
|
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,6 +1,6 @@
|
|||||||
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||||
import { BaseEvent } from '#application/base/baseEvent'
|
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
id: UUID
|
id: UUID
|
||||||
@ -15,7 +15,8 @@ export default class CharacterTypeDeleteEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
const characterType = await CharacterTypeRepository.getById(data.id)
|
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()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
|
||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { CharacterType } from '#entities/characterType'
|
import { CharacterType } from '#entities/characterType'
|
||||||
|
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -13,7 +13,10 @@ export default class CharacterTypeListEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
const items = await CharacterTypeRepository.getAll()
|
const characterTypeRepository = new CharacterTypeRepository()
|
||||||
|
const items = await characterTypeRepository.getAll()
|
||||||
|
await characterTypeRepository.getEntityManager().populate(items, ['sprite'])
|
||||||
|
|
||||||
return callback(items)
|
return callback(items)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('gm:characterType:list error', error)
|
this.logger.error('gm:characterType:list error', error)
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import ObjectRepository from '#repositories/mapObjectRepository'
|
|
||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import { MapObject } from '#entities/mapObject'
|
import { MapObject } from '#entities/mapObject'
|
||||||
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -10,10 +10,17 @@ export default class MapObjectListEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {
|
||||||
if (!(await this.isCharacterGM())) return
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
// get all objects
|
// Get all map objects
|
||||||
const objects = await ObjectRepository.getAll()
|
const mapObjectRepository = new MapObjectRepository()
|
||||||
return callback(objects)
|
const mapObjects = await mapObjectRepository.getAll()
|
||||||
|
|
||||||
|
return callback(mapObjects)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:mapObject:list error', error)
|
||||||
|
return callback([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import Storage from '#application/storage'
|
|
||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
import MapObjectRepository from '#repositories/mapObjectRepository'
|
import Storage from '#application/storage'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
mapObjectId: UUID
|
mapObjectId: UUID
|
||||||
@ -14,9 +15,8 @@ export default class MapObjectRemoveEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||||
if (!(await this.isCharacterGM())) return
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
// remove the tile from the disk
|
// remove the tile from the disk
|
||||||
const finalFilePath = Storage.getPublicPath('map_objects', data.mapObjectId + '.png')
|
const finalFilePath = Storage.getPublicPath('map_objects', data.mapObjectId + '.png')
|
||||||
fs.unlink(finalFilePath, async (err) => {
|
fs.unlink(finalFilePath, async (err) => {
|
||||||
@ -26,7 +26,8 @@ export default class MapObjectRemoveEvent extends BaseEvent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await (await MapObjectRepository.getById(data.mapObjectId))?.delete()
|
const mapObjectRepository = new MapObjectRepository()
|
||||||
|
await (await mapObjectRepository.getById(data.mapObjectId))?.delete()
|
||||||
|
|
||||||
return callback(true)
|
return callback(true)
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { UUID } from '#application/types'
|
|
||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { UUID } from '#application/types'
|
||||||
import MapObjectRepository from '#repositories/mapObjectRepository'
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
@ -23,7 +23,9 @@ export default class MapObjectUpdateEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
const mapObject = await MapObjectRepository.getById(data.id)
|
const mapObjectRepository = new MapObjectRepository()
|
||||||
|
|
||||||
|
const mapObject = await mapObjectRepository.getById(data.id)
|
||||||
if (!mapObject) return callback(false)
|
if (!mapObject) return callback(false)
|
||||||
|
|
||||||
await mapObject
|
await mapObject
|
||||||
@ -35,7 +37,7 @@ export default class MapObjectUpdateEvent extends BaseEvent {
|
|||||||
.setFrameRate(data.frameRate)
|
.setFrameRate(data.frameRate)
|
||||||
.setFrameWidth(data.frameWidth)
|
.setFrameWidth(data.frameWidth)
|
||||||
.setFrameHeight(data.frameHeight)
|
.setFrameHeight(data.frameHeight)
|
||||||
.update()
|
.save()
|
||||||
|
|
||||||
return callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -2,8 +2,9 @@ import fs from 'fs/promises'
|
|||||||
import { writeFile } from 'node:fs/promises'
|
import { writeFile } from 'node:fs/promises'
|
||||||
|
|
||||||
import sharp from 'sharp'
|
import sharp from 'sharp'
|
||||||
import Storage from '#application/storage'
|
|
||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import Storage from '#application/storage'
|
||||||
import { MapObject } from '#entities/mapObject'
|
import { MapObject } from '#entities/mapObject'
|
||||||
|
|
||||||
interface IObjectData {
|
interface IObjectData {
|
||||||
@ -32,7 +33,7 @@ export default class MapObjectUploadEvent extends BaseEvent {
|
|||||||
|
|
||||||
// Create new map object and save it to database
|
// Create new map object and save it to database
|
||||||
const mapObject = new MapObject()
|
const mapObject = new MapObject()
|
||||||
await mapObject.setName(key).setTags([]).setOriginX(0).setOriginY(0).setFrameWidth(width).setFrameHeight(height).save()
|
await mapObject.setName('New map object').setTags([]).setOriginX(0).setOriginY(0).setFrameWidth(width).setFrameHeight(height).save()
|
||||||
|
|
||||||
// Save image to disk
|
// Save image to disk
|
||||||
const uuid = mapObject.getId()
|
const uuid = mapObject.getId()
|
||||||
|
@ -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 { Sprite } from '#entities/sprite'
|
import { Sprite } from '#entities/sprite'
|
||||||
import CharacterRepository from '#repositories/characterRepository'
|
|
||||||
import SpriteRepository from '#repositories/spriteRepository'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
|
|
||||||
interface CopyPayload {
|
interface CopyPayload {
|
||||||
@ -17,19 +16,24 @@ export default class SpriteCopyEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
const sourceSprite = await SpriteRepository.getById(payload.id)
|
const spriteRepository = new SpriteRepository()
|
||||||
|
const sourceSprite = await spriteRepository.getById(payload.id)
|
||||||
|
|
||||||
if (!sourceSprite) {
|
if (!sourceSprite) {
|
||||||
throw new Error('Source sprite not found')
|
this.logger.error('gm:sprite:copy error', 'Source sprite not found')
|
||||||
|
return callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Populate source sprite with spriteActions
|
||||||
|
await spriteRepository.getEntityManager().populate(sourceSprite, ['spriteActions'])
|
||||||
|
|
||||||
const newSprite = new Sprite()
|
const newSprite = new Sprite()
|
||||||
await newSprite.setName(`${sourceSprite.getName()} (Copy)`).setSpriteActions(sourceSprite.getSpriteActions()).save()
|
await newSprite.setName(`${sourceSprite.getName()} (Copy)`).setSpriteActions(sourceSprite.getSpriteActions()).save()
|
||||||
|
|
||||||
callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error copying sprite:`, String(error))
|
this.logger.error(`Error copying sprite:`, String(error))
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,19 @@ export default class GMSpriteDeleteEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
||||||
if (!(await this.isCharacterGM())) return
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
await this.deleteSpriteFolder(data.id)
|
await this.deleteSpriteFolder(data.id)
|
||||||
await (await SpriteRepository.getById(data.id))?.delete()
|
|
||||||
|
const spriteRepository = new SpriteRepository()
|
||||||
|
await (await spriteRepository.getById(data.id))?.delete()
|
||||||
|
|
||||||
this.logger.info(`Sprite ${data.id} deleted.`)
|
this.logger.info(`Sprite ${data.id} deleted.`)
|
||||||
callback(true)
|
return callback(true)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error('gm:sprite:delete error', error.message)
|
this.logger.error('gm:sprite:delete error', error.message)
|
||||||
callback(false)
|
return callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Sprite } from '@prisma/client'
|
|
||||||
|
|
||||||
import { BaseEvent } from '#application/base/baseEvent'
|
import { BaseEvent } from '#application/base/baseEvent'
|
||||||
|
import { Sprite } from '#entities/sprite'
|
||||||
import SpriteRepository from '#repositories/spriteRepository'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
@ -11,10 +10,18 @@ export default class SpriteListEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: Sprite[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: Sprite[]) => void): Promise<void> {
|
||||||
if (!(await this.isCharacterGM())) return
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
// get all sprites
|
// Get all sprites
|
||||||
const sprites = await SpriteRepository.getAll()
|
const spriteRepository = new SpriteRepository()
|
||||||
callback(sprites)
|
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([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,15 @@ export default class GMTileDeleteEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
||||||
if (!(await this.isCharacterGM())) return
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
this.logger.info(`Deleting tile ${data.id}`)
|
this.logger.info(`Deleting tile ${data.id}`)
|
||||||
|
|
||||||
await this.deleteTileFile(data.id)
|
await this.deleteTileFile(data.id)
|
||||||
await (await TileRepository.getById(data.id))?.delete()
|
|
||||||
|
const tileRepository = new TileRepository()
|
||||||
|
await (await tileRepository.getById(data.id))?.delete()
|
||||||
|
|
||||||
this.logger.info(`Tile ${data.id} deleted successfully.`)
|
this.logger.info(`Tile ${data.id} deleted successfully.`)
|
||||||
return callback(true)
|
return callback(true)
|
||||||
|
@ -10,10 +10,16 @@ export default class TileListEven extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: IPayload, callback: (response: Tile[]) => void): Promise<void> {
|
private async handleEvent(data: IPayload, callback: (response: Tile[]) => void): Promise<void> {
|
||||||
if (!(await this.isCharacterGM())) return
|
try {
|
||||||
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
// get all tiles
|
// Get all tiles
|
||||||
const tiles = await TileRepository.getAll()
|
const tileRepository = new TileRepository()
|
||||||
return callback(tiles)
|
const tiles = await tileRepository.getAll()
|
||||||
|
return callback(tiles)
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('gm:tile:list error', error)
|
||||||
|
return callback([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,16 @@ export default class TileUpdateEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||||
if (!(await this.isCharacterGM())) return
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tile = await TileRepository.getById(data.id)
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
|
const tileRepository = new TileRepository()
|
||||||
|
|
||||||
|
const tile = await tileRepository.getById(data.id)
|
||||||
if (!tile) return callback(false)
|
if (!tile) return callback(false)
|
||||||
|
|
||||||
await tile.setName(data.name).setTags(data.tags).update()
|
await tile.setName(data.name).setTags(data.tags).save()
|
||||||
|
|
||||||
return callback(true)
|
return callback(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return callback(false)
|
return callback(false)
|
||||||
|
@ -27,7 +27,9 @@ export default class MapCreateEvent extends BaseEvent {
|
|||||||
.setTiles(Array.from({ length: data.height }, () => Array.from({ length: data.width }, () => 'blank_tile')))
|
.setTiles(Array.from({ length: data.height }, () => Array.from({ length: data.width }, () => 'blank_tile')))
|
||||||
.save()
|
.save()
|
||||||
|
|
||||||
const mapList = await MapRepository.getAll()
|
const mapRepository = new MapRepository()
|
||||||
|
const mapList = await mapRepository.getAll()
|
||||||
|
|
||||||
return callback(mapList)
|
return callback(mapList)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error('gm:map:create error', error.message)
|
this.logger.error('gm:map:create error', error.message)
|
||||||
|
@ -17,7 +17,8 @@ export default class MapDeleteEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
this.logger.info(`Deleting map ${data.mapId}`)
|
this.logger.info(`Deleting map ${data.mapId}`)
|
||||||
|
|
||||||
await (await MapRepository.getById(data.mapId))?.delete()
|
const mapRepository = new MapRepository()
|
||||||
|
await (await mapRepository.getById(data.mapId))?.delete()
|
||||||
|
|
||||||
this.logger.info(`Map ${data.mapId} deleted successfully.`)
|
this.logger.info(`Map ${data.mapId} deleted successfully.`)
|
||||||
return callback(true)
|
return callback(true)
|
||||||
|
@ -13,9 +13,11 @@ export default class MapListEvent extends BaseEvent {
|
|||||||
try {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
this.logger.info(`User ${(await this.getCharacter())!.getId()} has created a new map via map editor.`)
|
this.logger.info(`User ${(await this.getCharacter())!.getId()} has listed maps via map editor.`)
|
||||||
|
|
||||||
|
const mapRepository = new MapRepository()
|
||||||
|
const maps = await mapRepository.getAll()
|
||||||
|
|
||||||
const maps = await MapRepository.getAll()
|
|
||||||
return callback(maps)
|
return callback(maps)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error('gm:map:list error', error.message)
|
this.logger.error('gm:map:list error', error.message)
|
||||||
|
@ -2,7 +2,6 @@ import { BaseEvent } from '#application/base/baseEvent'
|
|||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import { Map } from '#entities/map'
|
import { Map } from '#entities/map'
|
||||||
import MapRepository from '#repositories/mapRepository'
|
import MapRepository from '#repositories/mapRepository'
|
||||||
import Database from '#application/database'
|
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
mapId: UUID
|
mapId: UUID
|
||||||
@ -24,17 +23,15 @@ export default class MapRequestEvent extends BaseEvent {
|
|||||||
return callback(null)
|
return callback(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
const map = await MapRepository.getById(data.mapId)
|
const mapRepository = new MapRepository()
|
||||||
|
const map = await mapRepository.getById(data.mapId)
|
||||||
|
await mapRepository.getEntityManager().populate(map!, mapRepository.POPULATE_MAP_EDITOR as any)
|
||||||
|
|
||||||
if (!map) {
|
if (!map) {
|
||||||
this.logger.info(`User ${(await this.getCharacter())!.getId()} tried to request map ${data.mapId} but it does not exist.`)
|
this.logger.info(`User ${(await this.getCharacter())!.getId()} tried to request map ${data.mapId} but it does not exist.`)
|
||||||
return callback(null)
|
return callback(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(map)
|
|
||||||
await Database.getEntityManager().populate(map, ['mapEventTiles', 'placedMapObjects'])
|
|
||||||
|
|
||||||
return callback(map)
|
return callback(map)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error('gm:map:request error', error.message)
|
this.logger.error('gm:map:request error', error.message)
|
||||||
|
@ -5,9 +5,9 @@ import { Map } from '#entities/map'
|
|||||||
import { MapEffect } from '#entities/mapEffect'
|
import { MapEffect } from '#entities/mapEffect'
|
||||||
import { MapEventTile } from '#entities/mapEventTile'
|
import { MapEventTile } from '#entities/mapEventTile'
|
||||||
import { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
import { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
||||||
|
import { PlacedMapObject } from '#entities/placedMapObject'
|
||||||
import mapManager from '#managers/mapManager'
|
import mapManager from '#managers/mapManager'
|
||||||
import MapRepository from '#repositories/mapRepository'
|
import MapRepository from '#repositories/mapRepository'
|
||||||
import { PlacedMapObject } from '#entities/placedMapObject'
|
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
mapId: UUID
|
mapId: UUID
|
||||||
@ -21,16 +21,13 @@ interface IPayload {
|
|||||||
positionX: number
|
positionX: number
|
||||||
positionY: number
|
positionY: number
|
||||||
teleport?: {
|
teleport?: {
|
||||||
toMapId: UUID
|
toMap: Map
|
||||||
toPositionX: number
|
toPositionX: number
|
||||||
toPositionY: number
|
toPositionY: number
|
||||||
toRotation: number
|
toRotation: number
|
||||||
}
|
}
|
||||||
}[]
|
}[]
|
||||||
mapEffects: {
|
mapEffects: MapEffect[]
|
||||||
effect: string
|
|
||||||
strength: number
|
|
||||||
}[]
|
|
||||||
placedMapObjects: PlacedMapObject[]
|
placedMapObjects: PlacedMapObject[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,13 +48,16 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
return callback(null)
|
return callback(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
let map = await MapRepository.getById(data.mapId)
|
const mapRepository = new MapRepository()
|
||||||
|
let map = await mapRepository.getById(data.mapId)
|
||||||
|
|
||||||
if (!map) {
|
if (!map) {
|
||||||
this.logger.info(`User ${character!.getId()} tried to update map ${data.mapId} but it does not exist.`)
|
this.logger.info(`User ${character!.getId()} tried to update map ${data.mapId} but it does not exist.`)
|
||||||
return callback(null)
|
return callback(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await mapRepository.getEntityManager().populate(map, mapRepository.POPULATE_MAP_EDITOR as any)
|
||||||
|
|
||||||
// Validation logic remains the same
|
// Validation logic remains the same
|
||||||
if (data.tiles.length > data.height) {
|
if (data.tiles.length > data.height) {
|
||||||
data.tiles = data.tiles.slice(0, data.height)
|
data.tiles = data.tiles.slice(0, data.height)
|
||||||
@ -69,13 +69,12 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.mapEventTiles = data.mapEventTiles.filter((tile) => tile.positionX >= 0 && tile.positionX < data.width && tile.positionY >= 0 && tile.positionY < data.height)
|
data.mapEventTiles = data.mapEventTiles.filter((tile) => tile.positionX >= 0 && tile.positionX < data.width && tile.positionY >= 0 && tile.positionY < data.height)
|
||||||
|
|
||||||
data.placedMapObjects = data.placedMapObjects.filter((obj) => obj.positionX >= 0 && obj.positionX < data.width && obj.positionY >= 0 && obj.positionY < data.height)
|
data.placedMapObjects = data.placedMapObjects.filter((obj) => obj.positionX >= 0 && obj.positionX < data.width && obj.positionY >= 0 && obj.positionY < data.height)
|
||||||
|
|
||||||
// Clear existing collections
|
// Clear existing collections
|
||||||
map.mapEventTiles.removeAll()
|
map.getMapEventTiles().removeAll()
|
||||||
map.placedMapObjects.removeAll()
|
map.getPlacedMapObjects().removeAll()
|
||||||
map.mapEffects.removeAll()
|
map.getMapEffects().removeAll()
|
||||||
|
|
||||||
// Create and add new map event tiles
|
// Create and add new map event tiles
|
||||||
for (const tile of data.mapEventTiles) {
|
for (const tile of data.mapEventTiles) {
|
||||||
@ -83,7 +82,7 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
|
|
||||||
if (tile.teleport) {
|
if (tile.teleport) {
|
||||||
const teleport = new MapEventTileTeleport()
|
const teleport = new MapEventTileTeleport()
|
||||||
.setToMap((await MapRepository.getById(tile.teleport.toMapId))!)
|
.setToMap((await mapRepository.getById(tile.teleport.toMap.id))!)
|
||||||
.setToPositionX(tile.teleport.toPositionX)
|
.setToPositionX(tile.teleport.toPositionX)
|
||||||
.setToPositionY(tile.teleport.toPositionY)
|
.setToPositionY(tile.teleport.toPositionY)
|
||||||
.setToRotation(tile.teleport.toRotation)
|
.setToRotation(tile.teleport.toRotation)
|
||||||
@ -96,21 +95,32 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
|
|
||||||
// Create and add new map objects
|
// Create and add new map objects
|
||||||
for (const object of data.placedMapObjects) {
|
for (const object of data.placedMapObjects) {
|
||||||
const mapObject = new PlacedMapObject().setMapObject(object.mapObject).setDepth(object.depth).setIsRotated(object.isRotated).setPositionX(object.positionX).setPositionY(object.positionY).setMap(map)
|
const mapObject = new PlacedMapObject()
|
||||||
|
.setMapObject(object.mapObject)
|
||||||
|
.setDepth(object.depth)
|
||||||
|
.setIsRotated(object.isRotated)
|
||||||
|
.setPositionX(object.positionX)
|
||||||
|
.setPositionY(object.positionY)
|
||||||
|
.setMap(map)
|
||||||
|
|
||||||
map.placedMapObjects.add(mapObject)
|
map.placedMapObjects.add(mapObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and add new map effects
|
// Create and add new map effects
|
||||||
for (const effect of data.mapEffects) {
|
for (const effect of data.mapEffects) {
|
||||||
const mapEffect = new MapEffect().setEffect(effect.effect).setStrength(effect.strength).setMap(map)
|
const mapEffect = new MapEffect().setEffect(effect.effect).setStrength(effect.strength).setMap(map)
|
||||||
|
|
||||||
map.mapEffects.add(mapEffect)
|
map.mapEffects.add(mapEffect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(map.getPlacedMapObjects().count())
|
||||||
|
|
||||||
// Update map properties
|
// Update map properties
|
||||||
await map.setName(data.name).setWidth(data.width).setHeight(data.height).setTiles(data.tiles).setPvp(data.pvp).setUpdatedAt(new Date()).update()
|
await map.setName(data.name).setWidth(data.width).setHeight(data.height).setTiles(data.tiles).setPvp(data.pvp).setUpdatedAt(new Date()).save()
|
||||||
|
|
||||||
// Reload map from database to get fresh data
|
// Reload map from database to get fresh data
|
||||||
map = await MapRepository.getById(data.mapId)
|
map = await mapRepository.getById(data.mapId)
|
||||||
|
await mapRepository.getEntityManager().populate(map!, mapRepository.POPULATE_MAP_EDITOR as any)
|
||||||
|
|
||||||
if (!map) {
|
if (!map) {
|
||||||
this.logger.info(`User ${character!.getId()} tried to update map ${data.mapId} but it does not exist after update.`)
|
this.logger.info(`User ${character!.getId()} tried to update map ${data.mapId} but it does not exist after update.`)
|
||||||
@ -123,7 +133,7 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
|
|
||||||
return callback(map)
|
return callback(map)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`gm:mapObject:update error: ${error instanceof Error ? error.message : String(error)}`)
|
this.emitError(`gm:map:update error: ${error instanceof Error ? error.message + error.stack : String(error)}`)
|
||||||
return callback(null)
|
return callback(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,15 @@ export default class LoginEvent extends BaseEvent {
|
|||||||
this.socket.on('login', this.handleEvent.bind(this))
|
this.socket.on('login', this.handleEvent.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleEvent(): void {
|
private async handleEvent() {
|
||||||
try {
|
try {
|
||||||
if (!this.socket.userId) {
|
if (!this.socket.userId) {
|
||||||
this.logger.warn('Login attempt without user data')
|
this.logger.warn('Login attempt without user data')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.socket.emit('logged_in', { user: UserRepository.getById(this.socket.userId) })
|
const userRepository = new UserRepository()
|
||||||
|
this.socket.emit('logged_in', { user: userRepository.getById(this.socket.userId) })
|
||||||
this.logger.info(`User logged in: ${this.socket.userId}`)
|
this.logger.info(`User logged in: ${this.socket.userId}`)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error('login error: ' + error.message)
|
this.logger.error('login error: ' + error.message)
|
||||||
|
@ -2,13 +2,12 @@ import { BaseEvent } from '#application/base/baseEvent'
|
|||||||
import { MapEventTileWithTeleport } from '#application/types'
|
import { MapEventTileWithTeleport } from '#application/types'
|
||||||
import MapManager from '#managers/mapManager'
|
import MapManager from '#managers/mapManager'
|
||||||
import MapCharacter from '#models/mapCharacter'
|
import MapCharacter from '#models/mapCharacter'
|
||||||
import mapEventTileRepository from '#repositories/mapEventTileRepository'
|
import MapEventTileRepository from '#repositories/mapEventTileRepository'
|
||||||
import CharacterService from '#services/characterService'
|
import CharacterService from '#services/characterService'
|
||||||
import MapEventTileService from '#services/mapEventTileService'
|
import TeleportService from '#services/teleportService'
|
||||||
|
|
||||||
export default class CharacterMove extends BaseEvent {
|
export default class CharacterMove extends BaseEvent {
|
||||||
private readonly characterService = CharacterService
|
private readonly characterService = CharacterService
|
||||||
private readonly mapEventTileService = MapEventTileService
|
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
this.socket.on('map:character:move', this.handleEvent.bind(this))
|
this.socket.on('map:character:move', this.handleEvent.bind(this))
|
||||||
@ -16,7 +15,7 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
|
|
||||||
private async handleEvent({ positionX, positionY }: { positionX: number; positionY: number }): Promise<void> {
|
private async handleEvent({ positionX, positionY }: { positionX: number; positionY: number }): Promise<void> {
|
||||||
const mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
const mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
||||||
if (!mapCharacter?.character) {
|
if (!mapCharacter?.getCharacter()) {
|
||||||
this.logger.error('map:character:move error: Character not found or not initialized')
|
this.logger.error('map:character:move error: Character not found or not initialized')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -40,7 +39,7 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async moveAlongPath(mapCharacter: MapCharacter, path: Array<{ x: number; y: number }>): Promise<void> {
|
private async moveAlongPath(mapCharacter: MapCharacter, path: Array<{ x: number; y: number }>): Promise<void> {
|
||||||
const { character } = mapCharacter
|
const character = mapCharacter.getCharacter()
|
||||||
|
|
||||||
for (let i = 0; i < path.length - 1; i++) {
|
for (let i = 0; i < path.length - 1; i++) {
|
||||||
if (!mapCharacter.isMoving || mapCharacter.currentPath !== path) {
|
if (!mapCharacter.isMoving || mapCharacter.currentPath !== path) {
|
||||||
@ -48,9 +47,10 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [start, end] = [path[i], path[i + 1]]
|
const [start, end] = [path[i], path[i + 1]]
|
||||||
character.rotation = CharacterService.calculateRotation(start.x, start.y, end.x, end.y)
|
character.setRotation(CharacterService.calculateRotation(start.x, start.y, end.x, end.y))
|
||||||
|
|
||||||
const mapEventTile = await mapEventTileRepository.getEventTileByMapIdAndPosition(character.map.id, Math.floor(end.x), Math.floor(end.y))
|
const mapEventTileRepository = new MapEventTileRepository()
|
||||||
|
const mapEventTile = await mapEventTileRepository.getEventTileByMapIdAndPosition(character.getMap().getId(), Math.floor(end.x), Math.floor(end.y))
|
||||||
|
|
||||||
if (mapEventTile?.type === 'BLOCK') break
|
if (mapEventTile?.type === 'BLOCK') break
|
||||||
if (mapEventTile?.type === 'TELEPORT' && mapEventTile.teleport) {
|
if (mapEventTile?.type === 'TELEPORT' && mapEventTile.teleport) {
|
||||||
@ -59,15 +59,14 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update position first
|
// Update position first
|
||||||
character.positionX = end.x
|
character.setPositionX(end.x).setPositionY(end.y)
|
||||||
character.positionY = end.y
|
|
||||||
|
|
||||||
// Then emit with the same properties
|
// Then emit with the same properties
|
||||||
this.io.in(character.map.id).emit('map:character:move', {
|
this.io.in(character.map.id).emit('map:character:move', {
|
||||||
characterId: character.id,
|
characterId: character.id,
|
||||||
positionX: character.positionX,
|
positionX: character.getPositionX(),
|
||||||
positionY: character.positionY,
|
positionY: character.getPositionY(),
|
||||||
rotation: character.rotation,
|
rotation: character.getRotation(),
|
||||||
isMoving: true
|
isMoving: true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -80,14 +79,13 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleMapEventTile(mapEventTile: MapEventTileWithTeleport): Promise<void> {
|
private async handleMapEventTile(mapEventTile: MapEventTileWithTeleport): Promise<void> {
|
||||||
const mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
if (mapEventTile.getTeleport()) {
|
||||||
if (!mapCharacter) {
|
await TeleportService.teleportCharacter(this.socket.characterId!, {
|
||||||
this.logger.error('map:character:move error: Character not found')
|
targetMapId: mapEventTile.getTeleport()!.getToMap().getId(),
|
||||||
return
|
targetX: mapEventTile.getTeleport()!.getToPositionX(),
|
||||||
}
|
targetY: mapEventTile.getTeleport()!.getToPositionY(),
|
||||||
|
rotation: mapEventTile.getTeleport()!.getToRotation()
|
||||||
if (mapEventTile.teleport) {
|
})
|
||||||
await this.mapEventTileService.handleTeleport(this.io, this.socket, mapCharacter.character, mapEventTile.teleport)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,108 +0,0 @@
|
|||||||
import { BaseEvent } from '#application/base/baseEvent'
|
|
||||||
import { ZoneEventTileWithTeleport } from '#application/types'
|
|
||||||
import ZoneManager from '#managers/zoneManager'
|
|
||||||
import ZoneCharacter from '#models/zoneCharacter'
|
|
||||||
import zoneEventTileRepository from '#repositories/zoneEventTileRepository'
|
|
||||||
import CharacterService from '#services/characterService'
|
|
||||||
import ZoneEventTileService from '#services/zoneEventTileService'
|
|
||||||
|
|
||||||
export default class CharacterMove extends BaseEvent {
|
|
||||||
private readonly characterService = CharacterService
|
|
||||||
private readonly zoneEventTileService = ZoneEventTileService
|
|
||||||
|
|
||||||
public listen(): void {
|
|
||||||
this.socket.on('zone:character:move', this.handleEvent.bind(this))
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleEvent({ positionX, positionY }: { positionX: number; positionY: number }): Promise<void> {
|
|
||||||
const zoneCharacter = ZoneManager.getCharacterById(this.socket.characterId!)
|
|
||||||
if (!zoneCharacter?.character) {
|
|
||||||
this.logger.error('zone:character:move error: Character not found or not initialized')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// If already moving, cancel current movement and wait for it to fully stop
|
|
||||||
if (zoneCharacter.isMoving) {
|
|
||||||
zoneCharacter.isMoving = false
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
||||||
}
|
|
||||||
|
|
||||||
const path = await this.characterService.calculatePath(zoneCharacter.character, positionX, positionY)
|
|
||||||
if (!path) {
|
|
||||||
this.io.in(zoneCharacter.character.zone.id).emit('zone:character:moveError', 'No valid path found')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start new movement
|
|
||||||
zoneCharacter.isMoving = true
|
|
||||||
zoneCharacter.currentPath = path // Add this property to ZoneCharacter class
|
|
||||||
await this.moveAlongPath(zoneCharacter, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
private async moveAlongPath(zoneCharacter: ZoneCharacter, path: Array<{ x: number; y: number }>): Promise<void> {
|
|
||||||
const { character } = zoneCharacter
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (let i = 0; i < path.length - 1; i++) {
|
|
||||||
if (!zoneCharacter.isMoving || zoneCharacter.currentPath !== path) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const [start, end] = [path[i], path[i + 1]]
|
|
||||||
character.rotation = CharacterService.calculateRotation(start.x, start.y, end.x, end.y)
|
|
||||||
|
|
||||||
const zoneEventTile = await zoneEventTileRepository.getEventTileByZoneIdAndPosition(
|
|
||||||
character.zone.id,
|
|
||||||
Math.floor(end.x),
|
|
||||||
Math.floor(end.y)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (zoneEventTile?.type === 'BLOCK') break
|
|
||||||
if (zoneEventTile?.type === 'TELEPORT' && zoneEventTile.teleport) {
|
|
||||||
await this.handleZoneEventTile(zoneEventTile as ZoneEventTileWithTeleport)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
character.positionX = end.x
|
|
||||||
character.positionY = end.y
|
|
||||||
|
|
||||||
this.io.in(character.zone.id).emit('zone:character:move', {
|
|
||||||
characterId: character.id,
|
|
||||||
positionX: character.positionX,
|
|
||||||
positionY: character.positionY,
|
|
||||||
rotation: character.rotation,
|
|
||||||
isMoving: true
|
|
||||||
})
|
|
||||||
|
|
||||||
await this.characterService.applyMovementDelay()
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (zoneCharacter.isMoving && zoneCharacter.currentPath === path) {
|
|
||||||
this.finalizeMovement(zoneCharacter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleZoneEventTile(zoneEventTile: ZoneEventTileWithTeleport): Promise<void> {
|
|
||||||
const zoneCharacter = ZoneManager.getCharacterById(this.socket.characterId!)
|
|
||||||
if (!zoneCharacter) {
|
|
||||||
this.logger.error('zone:character:move error: Character not found')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zoneEventTile.teleport) {
|
|
||||||
await this.zoneEventTileService.handleTeleport(this.io, this.socket, zoneCharacter.character, zoneEventTile.teleport)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private finalizeMovement(zoneCharacter: ZoneCharacter): void {
|
|
||||||
zoneCharacter.isMoving = false
|
|
||||||
this.io.in(zoneCharacter.character.zone.id).emit('zone:character:move', {
|
|
||||||
characterId: zoneCharacter.character.id,
|
|
||||||
positionX: zoneCharacter.character.positionX,
|
|
||||||
positionY: zoneCharacter.character.positionY,
|
|
||||||
rotation: zoneCharacter.character.rotation,
|
|
||||||
isMoving: false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,11 +6,15 @@ import { BaseController } from '#application/base/baseController'
|
|||||||
import Database from '#application/database'
|
import Database from '#application/database'
|
||||||
import Storage from '#application/storage'
|
import Storage from '#application/storage'
|
||||||
import { AssetData, UUID } from '#application/types'
|
import { AssetData, UUID } from '#application/types'
|
||||||
|
import MapRepository from '#repositories/mapRepository'
|
||||||
import SpriteRepository from '#repositories/spriteRepository'
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
import TileRepository from '#repositories/tileRepository'
|
import TileRepository from '#repositories/tileRepository'
|
||||||
import MapRepository from '#repositories/mapRepository'
|
|
||||||
|
|
||||||
export class AssetsController extends BaseController {
|
export class AssetsController extends BaseController {
|
||||||
|
private readonly mapRepository = new MapRepository()
|
||||||
|
private readonly spriteRepository = new SpriteRepository()
|
||||||
|
private readonly tileRepository = new TileRepository()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List tiles
|
* List tiles
|
||||||
* @param req
|
* @param req
|
||||||
@ -18,7 +22,7 @@ export class AssetsController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
public async listTiles(req: Request, res: Response) {
|
public async listTiles(req: Request, res: Response) {
|
||||||
const assets: AssetData[] = []
|
const assets: AssetData[] = []
|
||||||
const tiles = await TileRepository.getAll()
|
const tiles = await this.tileRepository.getAll()
|
||||||
|
|
||||||
for (const tile of tiles) {
|
for (const tile of tiles) {
|
||||||
assets.push({ key: tile.getId(), data: '/assets/tiles/' + tile.getId() + '.png', group: 'tiles', updatedAt: tile.getUpdatedAt() } as AssetData)
|
assets.push({ key: tile.getId(), data: '/assets/tiles/' + tile.getId() + '.png', group: 'tiles', updatedAt: tile.getUpdatedAt() } as AssetData)
|
||||||
@ -39,13 +43,13 @@ export class AssetsController extends BaseController {
|
|||||||
return this.sendError(res, 'Invalid map ID', 400)
|
return this.sendError(res, 'Invalid map ID', 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
const map = await MapRepository.getById(mapId)
|
const map = await this.mapRepository.getById(mapId)
|
||||||
if (!map) {
|
if (!map) {
|
||||||
return this.sendError(res, 'Map not found', 404)
|
return this.sendError(res, 'Map not found', 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
const assets: AssetData[] = []
|
const assets: AssetData[] = []
|
||||||
const tiles = await TileRepository.getByMapId(mapId)
|
const tiles = await this.tileRepository.getByMapId(mapId)
|
||||||
|
|
||||||
for (const tile of tiles) {
|
for (const tile of tiles) {
|
||||||
assets.push({ key: tile.getId(), data: '/assets/tiles/' + tile.getId() + '.png', group: 'tiles', updatedAt: tile.getUpdatedAt() } as AssetData)
|
assets.push({ key: tile.getId(), data: '/assets/tiles/' + tile.getId() + '.png', group: 'tiles', updatedAt: tile.getUpdatedAt() } as AssetData)
|
||||||
@ -66,14 +70,14 @@ export class AssetsController extends BaseController {
|
|||||||
return this.sendError(res, 'Invalid sprite ID', 400)
|
return this.sendError(res, 'Invalid sprite ID', 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sprite = await SpriteRepository.getById(spriteId)
|
const sprite = await this.spriteRepository.getById(spriteId)
|
||||||
if (!sprite) {
|
if (!sprite) {
|
||||||
return this.sendError(res, 'Sprite not found', 404)
|
return this.sendError(res, 'Sprite not found', 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
await Database.getEntityManager().populate(sprite, ['spriteActions'])
|
await this.spriteRepository.getEntityManager().populate(sprite, ['spriteActions'])
|
||||||
|
|
||||||
const assets: AssetData[] = sprite.spriteActions.getItems().map((spriteAction) => ({
|
const assets: AssetData[] = sprite.getSpriteActions().map((spriteAction) => ({
|
||||||
key: sprite.getId() + '-' + spriteAction.getAction(),
|
key: sprite.getId() + '-' + spriteAction.getAction(),
|
||||||
data: '/assets/sprites/' + sprite.getId() + '/' + spriteAction.getAction() + '.png',
|
data: '/assets/sprites/' + sprite.getId() + '/' + spriteAction.getAction() + '.png',
|
||||||
group: spriteAction.getIsAnimated() ? 'sprite_animations' : 'sprites',
|
group: spriteAction.getIsAnimated() ? 'sprite_animations' : 'sprites',
|
||||||
|
@ -16,13 +16,17 @@ interface AvatarOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AvatarController extends BaseController {
|
export class AvatarController extends BaseController {
|
||||||
|
private readonly characterTypeRepository = new CharacterTypeRepository()
|
||||||
|
private readonly characterHairRepository = new CharacterHairRepository()
|
||||||
|
private readonly characterRepository = new CharacterRepository()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get avatar by character
|
* Get avatar by character
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
public async getByName(req: Request, res: Response) {
|
public async getByName(req: Request, res: Response) {
|
||||||
const character = await CharacterRepository.getByName(req.params.characterName)
|
const character = await this.characterRepository.getByName(req.params.characterName)
|
||||||
if (!character?.characterType) {
|
if (!character?.characterType) {
|
||||||
return this.sendError(res, 'Character or character type not found', 404)
|
return this.sendError(res, 'Character or character type not found', 404)
|
||||||
}
|
}
|
||||||
@ -53,7 +57,7 @@ export class AvatarController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
private async generateAvatar(res: Response, options: AvatarOptions) {
|
private async generateAvatar(res: Response, options: AvatarOptions) {
|
||||||
try {
|
try {
|
||||||
const characterType = await CharacterTypeRepository.getById(options.characterTypeId)
|
const characterType = await this.characterTypeRepository.getById(options.characterTypeId)
|
||||||
if (!characterType?.sprite?.id) {
|
if (!characterType?.sprite?.id) {
|
||||||
return this.sendError(res, 'Character type not found', 404)
|
return this.sendError(res, 'Character type not found', 404)
|
||||||
}
|
}
|
||||||
@ -70,7 +74,7 @@ export class AvatarController extends BaseController {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (options.characterHairId) {
|
if (options.characterHairId) {
|
||||||
const characterHair = await CharacterHairRepository.getById(options.characterHairId)
|
const characterHair = await this.characterHairRepository.getById(options.characterHairId)
|
||||||
if (characterHair?.sprite?.id) {
|
if (characterHair?.sprite?.id) {
|
||||||
const hairSpritePath = Storage.getPublicPath('sprites', characterHair.sprite.id, 'front.png')
|
const hairSpritePath = Storage.getPublicPath('sprites', characterHair.sprite.id, 'front.png')
|
||||||
if (fs.existsSync(hairSpritePath)) {
|
if (fs.existsSync(hairSpritePath)) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { Server } from 'socket.io'
|
|
||||||
|
|
||||||
import { CommandRegistry } from '#application/console/commandRegistry'
|
import { CommandRegistry } from '#application/console/commandRegistry'
|
||||||
import { ConsolePrompt } from '#application/console/consolePrompt'
|
import { ConsolePrompt } from '#application/console/consolePrompt'
|
||||||
import { LogReader } from '#application/console/logReader'
|
import { LogReader } from '#application/console/logReader'
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { Server } from 'socket.io'
|
import { Server } from 'socket.io'
|
||||||
|
|
||||||
import Logger, { LoggerType } from '#application/logger'
|
import Logger, { LoggerType } from '#application/logger'
|
||||||
|
import { World } from '#entities/world'
|
||||||
import SocketManager from '#managers/socketManager'
|
import SocketManager from '#managers/socketManager'
|
||||||
import worldRepository from '#repositories/worldRepository'
|
import WorldRepository from '#repositories/worldRepository'
|
||||||
import worldService from '#services/worldService'
|
|
||||||
|
|
||||||
class DateManager {
|
class DateManager {
|
||||||
private static readonly CONFIG = {
|
private static readonly CONFIG = {
|
||||||
@ -47,6 +47,7 @@ class DateManager {
|
|||||||
|
|
||||||
private async loadDate(): Promise<void> {
|
private async loadDate(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
const worldRepository = new WorldRepository()
|
||||||
const world = await worldRepository.getFirst()
|
const world = await worldRepository.getFirst()
|
||||||
this.currentDate = world?.date ?? new Date()
|
this.currentDate = world?.date ?? new Date()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -88,7 +89,12 @@ class DateManager {
|
|||||||
|
|
||||||
private async saveDate(): Promise<void> {
|
private async saveDate(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await worldService.update({ date: this.currentDate })
|
const worldRepository = new WorldRepository()
|
||||||
|
|
||||||
|
let world = await worldRepository.getFirst()
|
||||||
|
if (!world) world = new World()
|
||||||
|
|
||||||
|
await world.setDate(this.currentDate).save()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.handleError('Failed to save date', error)
|
this.handleError('Failed to save date', error)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,10 @@ class MapManager {
|
|||||||
private logger = Logger.type(LoggerType.GAME)
|
private logger = Logger.type(LoggerType.GAME)
|
||||||
|
|
||||||
public async boot(): Promise<void> {
|
public async boot(): Promise<void> {
|
||||||
const maps = await MapRepository.getAll()
|
const mapRepository = new MapRepository()
|
||||||
|
const maps = await mapRepository.getAll()
|
||||||
|
await mapRepository.getEntityManager().populate(maps, mapRepository.POPULATE_ALL as never[])
|
||||||
|
|
||||||
await Promise.all(maps.map((map) => this.loadMap(map)))
|
await Promise.all(maps.map((map) => this.loadMap(map)))
|
||||||
|
|
||||||
this.logger.info(`Map manager loaded with ${Object.keys(this.maps).length} maps`)
|
this.logger.info(`Map manager loaded with ${Object.keys(this.maps).length} maps`)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { Server } from 'socket.io'
|
import { Server } from 'socket.io'
|
||||||
|
|
||||||
import Logger, { LoggerType } from '#application/logger'
|
import Logger, { LoggerType } from '#application/logger'
|
||||||
|
import { World } from '#entities/world'
|
||||||
import SocketManager from '#managers/socketManager'
|
import SocketManager from '#managers/socketManager'
|
||||||
import worldRepository from '#repositories/worldRepository'
|
import WorldRepository from '#repositories/worldRepository'
|
||||||
import worldService from '#services/worldService'
|
|
||||||
|
|
||||||
type WeatherState = {
|
type WeatherState = {
|
||||||
isRainEnabled: boolean
|
isRainEnabled: boolean
|
||||||
@ -59,6 +59,7 @@ class WeatherManager {
|
|||||||
|
|
||||||
private async loadWeather(): Promise<void> {
|
private async loadWeather(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
const worldRepository = new WorldRepository()
|
||||||
const world = await worldRepository.getFirst()
|
const world = await worldRepository.getFirst()
|
||||||
if (world) {
|
if (world) {
|
||||||
this.weatherState = {
|
this.weatherState = {
|
||||||
@ -112,7 +113,17 @@ class WeatherManager {
|
|||||||
|
|
||||||
private async saveWeather(): Promise<void> {
|
private async saveWeather(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await worldService.update(this.weatherState)
|
const worldRepository = new WorldRepository()
|
||||||
|
|
||||||
|
let world = await worldRepository.getFirst()
|
||||||
|
if (!world) world = new World()
|
||||||
|
|
||||||
|
await world
|
||||||
|
.setIsRainEnabled(this.weatherState.isRainEnabled)
|
||||||
|
.setRainPercentage(this.weatherState.rainPercentage)
|
||||||
|
.setIsFogEnabled(this.weatherState.isFogEnabled)
|
||||||
|
.setFogDensity(this.weatherState.fogDensity)
|
||||||
|
.save()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logError('save', error)
|
this.logError('save', error)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import MapCharacter from './mapCharacter'
|
|||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import { Map } from '#entities/map'
|
import { Map } from '#entities/map'
|
||||||
import mapEventTileRepository from '#repositories/mapEventTileRepository'
|
import MapEventTileRepository from '#repositories/mapEventTileRepository'
|
||||||
|
|
||||||
class LoadedMap {
|
class LoadedMap {
|
||||||
private readonly map: Map
|
private readonly map: Map
|
||||||
@ -42,6 +42,7 @@ class LoadedMap {
|
|||||||
public async getGrid(): Promise<number[][]> {
|
public async getGrid(): Promise<number[][]> {
|
||||||
let grid: number[][] = Array.from({ length: this.map.height }, () => Array.from({ length: this.map.width }, () => 0))
|
let grid: number[][] = Array.from({ length: this.map.height }, () => Array.from({ length: this.map.width }, () => 0))
|
||||||
|
|
||||||
|
const mapEventTileRepository = new MapEventTileRepository()
|
||||||
const eventTiles = await mapEventTileRepository.getAll(this.map.id)
|
const eventTiles = await mapEventTileRepository.getAll(this.map.id)
|
||||||
|
|
||||||
// Set the grid values based on the event tiles, these are strings
|
// Set the grid values based on the event tiles, these are strings
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { Server } from 'socket.io'
|
import { Server } from 'socket.io'
|
||||||
|
|
||||||
import { TSocket } from '#application/types'
|
import { TSocket, UUID } from '#application/types'
|
||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import SocketManager from '#managers/socketManager'
|
|
||||||
import MapManager from '#managers/mapManager'
|
import MapManager from '#managers/mapManager'
|
||||||
|
import SocketManager from '#managers/socketManager'
|
||||||
import TeleportService from '#services/teleportService'
|
import TeleportService from '#services/teleportService'
|
||||||
|
|
||||||
class MapCharacter {
|
class MapCharacter {
|
||||||
@ -15,11 +15,15 @@ class MapCharacter {
|
|||||||
this.character = character
|
this.character = character
|
||||||
}
|
}
|
||||||
|
|
||||||
public async savePosition() {
|
public getCharacter(): Character {
|
||||||
await this.character.setPositionX(this.character.positionX).setPositionY(this.character.positionY).setRotation(this.character.rotation).setMap(this.character.map).update()
|
return this.character
|
||||||
}
|
}
|
||||||
|
|
||||||
public async teleport(mapId: number, targetX: number, targetY: number): Promise<void> {
|
public async savePosition() {
|
||||||
|
await this.character.setPositionX(this.character.positionX).setPositionY(this.character.positionY).setRotation(this.character.rotation).setMap(this.character.map).save()
|
||||||
|
}
|
||||||
|
|
||||||
|
public async teleport(mapId: UUID, targetX: number, targetY: number): Promise<void> {
|
||||||
await TeleportService.teleportCharacter(this.character.id, {
|
await TeleportService.teleportCharacter(this.character.id, {
|
||||||
targetMapId: mapId,
|
targetMapId: mapId,
|
||||||
targetX,
|
targetX,
|
||||||
|
@ -5,8 +5,11 @@ import { CharacterHair } from '#entities/characterHair'
|
|||||||
class CharacterHairRepository extends BaseRepository {
|
class CharacterHairRepository extends BaseRepository {
|
||||||
async getFirst() {
|
async getFirst() {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(CharacterHair)
|
const repository = this.getEntityManager().getRepository(CharacterHair)
|
||||||
return await repository.findOne({ id: { $exists: true } })
|
const result = await repository.findOne({ id: { $exists: true } })
|
||||||
|
if (result) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return result
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get first character hair: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get first character hair: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return null
|
return null
|
||||||
@ -15,18 +18,24 @@ class CharacterHairRepository extends BaseRepository {
|
|||||||
|
|
||||||
async getAll(): Promise<CharacterHair[]> {
|
async getAll(): Promise<CharacterHair[]> {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(CharacterHair)
|
const repository = this.getEntityManager().getRepository(CharacterHair)
|
||||||
return await repository.findAll()
|
const results = await repository.findAll()
|
||||||
|
for (const result of results) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return results
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get all character hair: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get all character hair: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllSelectable(): Promise<CharacterHair[]> {
|
async getAllSelectable(populate?: any): Promise<CharacterHair[]> {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(CharacterHair)
|
const repository = this.getEntityManager().getRepository(CharacterHair)
|
||||||
return await repository.find({ isSelectable: true })
|
const results = await repository.find({ isSelectable: true }, { populate })
|
||||||
|
for (const result of results) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return results
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get selectable character hair: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get selectable character hair: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return []
|
return []
|
||||||
@ -35,8 +44,11 @@ class CharacterHairRepository extends BaseRepository {
|
|||||||
|
|
||||||
async getById(id: UUID): Promise<CharacterHair | null> {
|
async getById(id: UUID): Promise<CharacterHair | null> {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(CharacterHair)
|
const repository = this.getEntityManager().getRepository(CharacterHair)
|
||||||
return await repository.findOne({ id })
|
const result = await repository.findOne({ id })
|
||||||
|
if (result) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return result
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get character hair by ID: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get character hair by ID: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return null
|
return null
|
||||||
@ -44,4 +56,4 @@ class CharacterHairRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new CharacterHairRepository()
|
export default CharacterHairRepository
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import { BaseRepository } from '#application/base/baseRepository'
|
import { BaseRepository } from '#application/base/baseRepository'
|
||||||
import { UUID } from '#application/types'
|
import { UUID } from '#application/types'
|
||||||
import { Character } from '#entities/character'
|
import { Character } from '#entities/character'
|
||||||
import { LoadHint, Populate } from '@mikro-orm/core'
|
|
||||||
|
|
||||||
class CharacterRepository extends BaseRepository {
|
class CharacterRepository extends BaseRepository {
|
||||||
async getByUserId(userId: UUID, populate?: LoadHint<Character, '*'>): Promise<Character[]> {
|
async getByUserId(userId: UUID): Promise<Character[]> {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(Character)
|
const repository = this.getEntityManager().getRepository(Character)
|
||||||
return await repository.find({ user: userId }, { populate: populate as Populate<Character> })
|
const results = await repository.find({ user: userId })
|
||||||
|
for (const result of results) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return results
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get character by user ID: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get character by user ID: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return []
|
return []
|
||||||
@ -16,28 +18,37 @@ class CharacterRepository extends BaseRepository {
|
|||||||
|
|
||||||
async getByUserAndId(userId: UUID, characterId: UUID): Promise<Character | null> {
|
async getByUserAndId(userId: UUID, characterId: UUID): Promise<Character | null> {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(Character)
|
const repository = this.getEntityManager().getRepository(Character)
|
||||||
return await repository.findOne({ user: userId, id: characterId })
|
const result = await repository.findOne({ user: userId, id: characterId })
|
||||||
|
if (result) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return result
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get character by user ID and character ID: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get character by user ID and character ID: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getById(id: UUID, populate?: string[]): Promise<Character | null> {
|
async getById(id: UUID, populate?: any): Promise<Character | null> {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(Character)
|
const repository = this.getEntityManager().getRepository(Character)
|
||||||
return await repository.findOne({ id })
|
const result = await repository.findOne({ id }, { populate })
|
||||||
|
if (result) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return result
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get character by ID: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get character by ID: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByName(name: string): Promise<Character | null> {
|
async getByName(name: string, populate?: any): Promise<Character | null> {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(Character)
|
const repository = this.getEntityManager().getRepository(Character)
|
||||||
return await repository.findOne({ name })
|
const result = await repository.findOne({ name }, { populate })
|
||||||
|
if (result) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return result
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get character by name: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get character by name: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return null
|
return null
|
||||||
@ -45,4 +56,4 @@ class CharacterRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new CharacterRepository()
|
export default CharacterRepository
|
||||||
|
@ -5,8 +5,11 @@ import { CharacterType } from '#entities/characterType'
|
|||||||
class CharacterTypeRepository extends BaseRepository {
|
class CharacterTypeRepository extends BaseRepository {
|
||||||
async getFirst() {
|
async getFirst() {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(CharacterType)
|
const repository = this.getEntityManager().getRepository(CharacterType)
|
||||||
return await repository.findOne({ id: { $exists: true } })
|
const result = await repository.findOne({ id: { $exists: true } })
|
||||||
|
if (result) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return result
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get first character type: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get first character type: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return null
|
return null
|
||||||
@ -15,8 +18,11 @@ class CharacterTypeRepository extends BaseRepository {
|
|||||||
|
|
||||||
async getAll() {
|
async getAll() {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(CharacterType)
|
const repository = this.getEntityManager().getRepository(CharacterType)
|
||||||
return await repository.findAll()
|
const results = await repository.findAll()
|
||||||
|
for (const result of results) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return results
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get all character types: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get all character types: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return []
|
return []
|
||||||
@ -25,8 +31,11 @@ class CharacterTypeRepository extends BaseRepository {
|
|||||||
|
|
||||||
async getById(id: UUID) {
|
async getById(id: UUID) {
|
||||||
try {
|
try {
|
||||||
const repository = this.em.getRepository(CharacterType)
|
const repository = this.getEntityManager().getRepository(CharacterType)
|
||||||
return await repository.findOne({ id })
|
const result = await repository.findOne({ id })
|
||||||
|
if (result) result.setEntityManager(this.getEntityManager())
|
||||||
|
|
||||||
|
return result
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to get character type by ID: ${error instanceof Error ? error.message : String(error)}`)
|
this.logger.error(`Failed to get character type by ID: ${error instanceof Error ? error.message : String(error)}`)
|
||||||
return null
|
return null
|
||||||
@ -34,4 +43,4 @@ class CharacterTypeRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new CharacterTypeRepository()
|
export default CharacterTypeRepository
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user