From 39597946cad074aabcee643024746fe389db5f1b Mon Sep 17 00:00:00 2001 From: seraphinush-gaming Date: Wed, 27 Nov 2019 01:17:56 +0900 Subject: [PATCH 1/3] Added submodule sysmsg --- README.md | 1 + index.js | 1 + lib/sysmsg.js | 43 +++++++++++++++++++++++++++++++++++++++++++ manifest.json | 10 ++++++---- module.json | 2 +- 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 lib/sysmsg.js diff --git a/README.md b/README.md index 1c939c1..eb067e6 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ # Documentation - Submodule `me`: [here](doc/me.md) +- Submodule `sysmsg`: [here](doc/sysmsg.md) - Submodule `contract`: [here](doc/contract.md) - Submodule `inventory`: [here](doc/inventory.md) diff --git a/index.js b/index.js index e91af6e..075d83a 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ class TeraGameState extends EventEmitter { // Now initialize default submodules this.installHooks(); this.initialize('me'); + this.initialize('sysmsg'); } destructor() { diff --git a/lib/sysmsg.js b/lib/sysmsg.js new file mode 100644 index 0000000..95905c7 --- /dev/null +++ b/lib/sysmsg.js @@ -0,0 +1,43 @@ +const EventEmitter = require('events'); + +class Sysmsg extends EventEmitter { + + constructor(parent) { + super(); + this.setMaxListeners(0); + + this.parent = parent; + + this.reset(); + this.installHooks(); + } + + destructor() { + this.reset(); + this.parent = undefined; + } + + installHook(name, version, cb) { + return this.parent.mod.hook(name, version, { order: -10000, filter: { fake: null, modified: null, silenced: null } }, cb); + } + + installHooks() { + this.parent.on('leave_game', () => { this.reset(); }); + + this.installHook('S_SYSTEM_MESSAGE', 1, (event) => { + let msg = this.parent.mod.parseSystemMessage(event.message); + this.id = msg.id; + this.tokens = msg.tokens; + + this.emit('update', msg.id, msg.tokens); + }); + } + + reset() { + this.id = null; + this.tokens = null; + } + +} + +module.exports = Sysmsg; diff --git a/manifest.json b/manifest.json index b5b4211..19c389f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,10 @@ { "files": { - "index.js": "527db5686384eddb8df0e48d295460d44190d9f45b7edc8900686c7fd7d67122", - "module.json": "6f969d093fa5e024757824bd2814073378be4ebfdf41dfdfbd50db34f285fcc1", + "index.js": "7dc29d6ac31a2593f7e3cfa4afa576a5e188262bea7231a0c76f589358a99f5d", + "module.json": "4f61176eb40b7f496ad9464e941ca9c3c1764f04dbd6ca283f327715ed5fdbff", "lib/me.js": "1d449ce3808cae2b514ac507ef6e84e168baa479c04e0dbec5c47cb01351beb4", - "lib/contract.js": "297bbff8c8887754f6e50a4fdffb2c1444aa9a7d8f5ef02941d43ad374117b58", + "lib/sysmsg.js": "9bb9e8c1837a6cf09814a3c65c869cb8c0e1a42a0bd748942634814f8310823e", + "lib/contract.js": "297bbff8c8887754f6e50a4fdffb2c1444aa9a7d8f5ef02941d43ad374117b58", "lib/inventory.js": "812d51305f0bee923cec6da210becf44a4af684a62c47d6aeaea499867b45a61" }, "defs": { @@ -26,6 +27,7 @@ "S_REJECT_CONTRACT": "event", "S_CANCEL_CONTRACT": "event", "S_INVEN_USERDATA": [1, 2], - "S_ITEMLIST": [2, 3] + "S_ITEMLIST": [2, 3], + "S_SYSTEM_MESSAGE": 1 } } diff --git a/module.json b/module.json index b407acf..55f975c 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "name": "tera-game-state", "author": "Caali", "description": "Tracks the game's current state and provides a high-level API for developers to base their mods on.", - "version": "1.0", + "version": "1.1", "servers": ["https://raw.githubusercontent.com/tera-toolbox/tera-game-state/master/"], "dependencies": { "tera-game-state-helper": "https://raw.githubusercontent.com/tera-toolbox/tera-game-state-helper/master/module.json" From 85edb09ab15a9b04d984297fb5cbb8247a3f0712 Mon Sep 17 00:00:00 2001 From: seraph Date: Wed, 27 Nov 2019 01:18:28 +0900 Subject: [PATCH 2/3] Added doc for sysmsg --- doc/sysmsg.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 doc/sysmsg.md diff --git a/doc/sysmsg.md b/doc/sysmsg.md new file mode 100644 index 0000000..3399b27 --- /dev/null +++ b/doc/sysmsg.md @@ -0,0 +1,13 @@ +# sysmsg +Submodule representing the incoming system message. Accessible through `mod.game.sysmsg`. + +**You need to specifically request this submodule during your module's initialization by calling `mod.game.initialize`!** + +# Functions +None + +# Events +## update +- Emitted when a new system messages arrives on `S_SYSTEM_MESSAGE`. +- Exemplary usage: `mod.game.sysmsg.on('update', (id, tokens) => { ... })` +- Parameters: `id` is id of the system message, and `tokens` is the tokens associated with the system message \ No newline at end of file From f08ed4cec5174406469b4c8594036606f7aa3074 Mon Sep 17 00:00:00 2001 From: seraph Date: Wed, 27 Nov 2019 01:19:22 +0900 Subject: [PATCH 3/3] Updated sysmsg doc --- doc/sysmsg.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/sysmsg.md b/doc/sysmsg.md index 3399b27..9fb3334 100644 --- a/doc/sysmsg.md +++ b/doc/sysmsg.md @@ -1,8 +1,6 @@ # sysmsg Submodule representing the incoming system message. Accessible through `mod.game.sysmsg`. -**You need to specifically request this submodule during your module's initialization by calling `mod.game.initialize`!** - # Functions None