module.exports = class Linkshell { constructor() { this.id = 0; this.name = "a small shell"; this.type = "item"; this.keywords = ["shell", "linkshell"]; this.resetDelay = 12000000; this.filename = "linkshell.js"; this.isOpen = false; this.owner = ""; this.linkshellId = 0; this.itemExpires = 0; } mud_reset(time) { this.itemExpires = time + this.resetDelay; } mud_tick(time) { if(time >= this.itemExpires) { this.mud_reset(time); } } mud_getDescription() { var desc = "A small opalecent spiral shell."; if(!this.isOpen) { desc += " The opening looks to be sealed shut."; } else { desc += " It looks like it is full of pearls. You could probably {hint}take{/hint} one out."; } return desc; } get(room, mobile, input) { return this.take(room, mobile, input); } take(room, mobile, input) { var command = input.join(" "); switch(command) { case "pearl": return this.mud_takePearl(room, mobile); break; } } open(room, mobile, input) { var command = input.join(" "); switch(command) { case "linkshell": case "shell": if(this.owner == "") { libs.Output.toMobile(mobile.id, "You press hard against the seal and crack it open."); libs.Output.toRoom(room.id, mobile.name + " cracks open the linkshell.", mobile); this.owner = mobile.name; this.isOpen = true; this.linkshellId = mobile.name + (new Date().getTime()); } else { libs.Output.toMobile(mobile.id, "The shell is already open."); } return true; break; } } mud_takePearl(room, mobile) { if(this.isOpen) { libs.Output.toMobile(mobile.id, "You pull out a pearl."); libs.Output.toRoom(room.id, mobile.name + " pulls a pearl out of a linkshell.", mobile); var pearl = builder.mud_spawnItem("Linkpearl"); pearl.belongsTo = this.linkshellId; world.mud_addItemToMobile(mobile.id, pearl.id); return true; } else { libs.Output.toMobile(mobile.id, "The shell is sealed, you would have to {hint}open{/hint} it."); return true; } } mud_saveItem() { var dataToSave = {}; dataToSave.isOpen = this.isOpen; dataToSave.owner = this.owner; dataToSave.linkshellId = this.linkshellId; return dataToSave; } mud_loadItem(itemData) { for(var dataIndex in itemData) { if(this.hasOwnProperty(dataIndex)) { this[dataIndex] = itemData[dataIndex]; } } } }