module.exports = class PlayerMobile { constructor() { this.id = 0; this.login = null; this.name = ""; this.description = "A player."; this.type = "mobile"; this.roomId = "ZebedeeTemple"; this.filename = "playermobile.js"; this.keywords = []; this.items = []; this.health = 100; this.maxHealth = 100; this.roles = []; this.memory = {}; this.title = "the player"; this.account = 0; this.itemSlots = {}; this.aliases = {}; } mud_sendMessage(source, message) { this.login.sendMessage(message); } mud_addMemory(section, newMemory) { if(!this.memory.hasOwnProperty(section)) { this.memory[section] = []; } this.memory[section].push(memory); } mud_checkMemory(section, memoryToCheck) { if(this.memory.hasOwnProperty(section)) { if(this.memory[section].hasOwnProperty(memory)) { return true; } } return false; } mud_addCurrency(amount) { this.account += amount; } mud_removeCurrency(amount) { this.account -= amount; this.account = Math.max(0, this.account); } mud_tick(time) { if(this.health != this.maxHealth) { this.health++; this.hp(); } } mud_getName() { return "{mobile}" + this.name + "{/mobile}"; } mud_getDescription() { return this.description; } mud_wearInSlot(itemId, slot) { if(this.itemSlots.hasOwnProperty(slot) && this.itemSlots[slot] != null) { return this.itemSlots[slot]; } this.itemSlots[slot] = itemId; } mud_removeSlot(slot) { if(!this.itemSlots.hasOwnProperty(slot) || this.itemSlots[slot] == null) { return false; } this.itemSlots[slot] = null; } mud_hasEquipped(itemName) { for(var index in this.itemSlots) { var slot = this.itemSlots[index]; if(slot != null) { if(world.mud_getItem(slot).constructor.name == itemName) { return true; } } } if(Object.keys(this.itemSlots).length > 0) { var inventoryItem = libs.Utilities.getSpecific(itemName, Object.values(this.itemSlots), session.items); if(inventoryItem != null) { return true; } } return false; } mud_setAlias(aliasKey, instructions) { this.aliases[aliasKey] = instructions; var commands = instructions.split(";"); this[aliasKey] = function() { for(var index in commands) { var command = commands[index]; world.mud_handleInput(this.roomId, this.id, command.split(" ")); } }; } hp(room, mobile, input) { libs.Output.toMobile(mobile.id, "[HP: "+mobile.health+"/" +mobile.maxHealth+"]"); return true; } quit(room, mobile, input) { this.login.logout(); return true; } save(room, mobile, input) { libs.Output.toMobile(mobile.id, "Saving player information."); world.mud_playerSave(this); libs.Output.toMobile(mobile.id, "Saved successfully."); return true; } hint(room, mobile, input) { if(["on", "please"].indexOf(input[0]) != -1) { mobile.hintColor = "FgMagenta"; libs.Output.toMobile(mobile.id, "Enabling hints."); return true; } if (["off"].indexOf(input[0]) != -1) { mobile.hintColor = "Reset"; libs.Output.toMobile(mobile.id, "Disabling hints."); return true; } libs.Output.toMobile(mobile.id, "hint [on|off] - controls highlighting in description text."); return true; } setting(room, mobile, input) { } chpass(room, mobile, input) { var username = mobile.name.toLowerCase(); mobile.password = world.mud_generateHash(username + input.join(" ")); world.mud_playerSave(mobile); libs.Output.toMobile(mobile.id, "Password has been updated!"); return true; } };