UNPKG

ggejs

Version:

A powerful Node.js module for interacting with the server of Goodgame Empire & Goodgame Empire: Four Kingdoms

67 lines (59 loc) 2.19 kB
const BasicMessage = require("./BasicMessage"); const {getSpyLog} = require("../../commands/bsd"); const EmpireError = require("../../tools/EmpireError"); const Localize = require("../../tools/Localize"); class SpyNPCMessage extends BasicMessage { /** @type{BaseClient}*/ #client; /** @type {SpyLog | undefined} */ _spyLog = undefined; constructor(client, data) { super(client, data); this.#client = client; } /** @return {boolean}*/ get isSuccessful() { return this.successType === 0 || this.successType === 3; } /** @return {boolean}*/ get isAttacking() { return this.successType === 0 || this.successType === 2; } parseMetaData(client, metaArray) { this.subType = parseInt(metaArray[0]); this.successType = parseInt(metaArray[1]); this.ownerId = parseInt(metaArray[3]); this.areaName = metaArray[4]; const metaArray2 = metaArray[2].split("#"); this.areaType = parseInt(metaArray2[0]); this.kingdomId = parseInt(metaArray2[1]); this.initSubject(client, Localize.text(client, "dialog_attack_spyInfo")); this.setSenderToAreaName(this.areaName, this.areaType, this.kingdomId) } /** * @param {BaseClient} client * @param {string} spyTypeName * @protected */ initSubject(client, spyTypeName) { let val; if (this.isSuccessful) { val = Localize.text(client, "dialog_spyLog_success"); } else if (this.isAttacking) { val = Localize.text(client, "dialog_spyLog_failure"); } else { val = Localize.text(client, "dialog_spyLog_keptAway"); } this.subject = Localize.text(client, "value_assign_colon", spyTypeName, val); } async getSpyLog() { try { if (this._spyLog !== undefined) return this._spyLog; this._spyLog = await getSpyLog(this.#client, this.messageId); return this._spyLog; } catch (e) { throw new EmpireError(this.#client, e); } } } module.exports = SpyNPCMessage;