123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- class Builder {
- help(room, mobile, input) {
- if(input.join(" ").trim().length == 0) {
- libs.Output.toMobile(mobile.id, "Builder commands:");
- libs.Output.toMobile(mobile.id, "reload, spawn, locate, summon, derez, see, warp");
- return false;
- }
- var topic = input.join(" ").trim();
- switch(topic) {
- case "builder":
- libs.Output.toMobile(mobile.id, "As a builder, you have some tremendous access to the server instance. You can control what is spawned, you can see the exceptions thrown, and you can reload elements like rooms, mobiles and items.\r\n");
- libs.Output.toMobile(mobile.id, "But being a builder means more than that. It means your job is to provide a fun and rewarding experience for the players. Every thing you do should be considered with the welfare of the players in mind. \"Will this be fun?\" \"Will someone be upset by this?\" \"Who benefits and who loses by this change?\"\r\n");
- libs.Output.toMobile(mobile.id, "Your responsibilities as a builder are to the health and code-quality of the server, but also to the health and quality of play that the users here will experience. Use your power wisely to maximize fun, and your players will love you for it.");
- return true;
- case "reload":
- libs.Output.toMobile(mobile.id, "* reload room [RoomName] - reloads a specific room");
- libs.Output.toMobile(mobile.id, "* reload item [ItemName] - reloads a specific item");
- libs.Output.toMobile(mobile.id, "* reload mobile [MobileName] - reloads a specific mobile");
- return true;
- case "spawn":
- libs.Output.toMobile(mobile.id, "* spawn room [RoomName] - spawns a specific room");
- libs.Output.toMobile(mobile.id, "* spawn item [ItemName] - spawns instance of this item in your inventory");
- libs.Output.toMobile(mobile.id, "* spawn mobile [MobileName] - spawns instance of this mobile in the current room");
- return true;
- case "derez":
- libs.Output.toMobile(mobile.id, "* derez item [itemKeyword] - deletes instance of this item in your inventory");
- libs.Output.toMobile(mobile.id, "* derez mobile [itemKeyword] - deletes instance of this mobile in the current room");
- return true;
- case "see":
- libs.Output.toMobile(mobile.id, "* see room - displays the internal data of the current room");
- libs.Output.toMobile(mobile.id, "* see item [itemKeyword] - displays the internal data of an item");
- libs.Output.toMobile(mobile.id, "* see mobile [mobileKeyword]- displays the internal data of a mobile");
- return true;
- case "warp":
- libs.Output.toMobile(mobile.id, "* warp [RoomName] - warp your character to a specific room");
- return true;
- case "locate":
- libs.Output.toMobile(mobile.id, "* locate item [ItemName]- list out all item instances");
- libs.Output.toMobile(mobile.id, "* locate mobile [MobileName]- list out all mobile instances");
- libs.Output.toMobile(mobile.id, "* locate all- list out all instances and where they are");
- return true;
- case "locate":
- libs.Output.toMobile(mobile.id, "* summon item [ItemInstanceId]- remove the item from it's current location and place it in your inventory");
- libs.Output.toMobile(mobile.id, "* summon mobile [MobileInstanceId]- remove the mobile from it's current location and place it in your current room");
- return true;
- }
- }
- reload(room, mobile, input) {
- switch(input[0]) {
- case "room":
- return this.mud_reloadRoom(room, mobile, input);
- case "item":
- return this.mud_reloadItem(room, mobile, input);
- case "mobile":
- return this.mud_reloadMobile(room, mobile, input);
- default:
- return this.help(room, mobile, ["reload"]);
- }
- }
- mud_reloadRoom(room, mobile, input) {
- input.shift();
- var roomName = input.join(" ").trim();
- libs.Output.toMobile(mobile.id, "Preparing to reload room " + roomName);
- try {
- delete require.cache[require.resolve(config.worldDataPath +'/rooms')];
- rooms = require(config.worldDataPath +'/rooms');
- var targetRoom = world.mud_getRoom(roomName);
- var fileName = (new rooms[roomName]()).filename;
- delete require.cache[require.resolve(config.worldDataPath +'/rooms/' + fileName)];
- rooms[roomName] = require(config.worldDataPath +'/rooms/' + fileName);
- var tempRoom = new rooms[roomName]();
- if(targetRoom != null) {
- tempRoom.items = targetRoom.items;
- tempRoom.mobiles = targetRoom.mobiles;
- }
- session.rooms[roomName] = tempRoom;
- libs.Output.toMobile(mobile.id, "Room " + roomName + " reloaded.");
- libs.Output.toRoom(roomName, "The room briefly fades from reality and then snaps back to focus.", mobile);
- libs.Output.toServer("Room " + roomName + " reloaded.\n");
- } catch(error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload room " + roomName + ".\n");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- mud_reloadItem(room, mobile, input) {
- input.shift();
- var itemName = input.join(" ").trim();
- libs.Output.toMobile(mobile.id, "Preparing to reload item " + itemName);
- try {
- delete require.cache[require.resolve(config.worldDataPath +'/items')];
- items = require(config.worldDataPath +'/items');
- var fileName = (new items[itemName]()).filename;
- delete require.cache[require.resolve(config.worldDataPath +'/items/' + fileName)];
- items[itemName] = require(config.worldDataPath +'/items/' + fileName);
- for(var itemIndex in session.items) {
- var itemInstance = session.items[itemIndex];
- if(itemInstance.constructor.name == itemName) {
- libs.Output.toMobile(mobile.id, "Replacing " + itemName + " instance " + itemInstance.id + ".");
- var tempItem = new items[itemName]();
- tempItem.id = itemInstance.id;
- session.items[tempItem.id] = tempItem;
- }
- }
- libs.Output.toMobile(mobile.id, "Item " + itemName + " reloaded.");
- libs.Output.toServer("Item " + itemName + " reloaded.\n");
- } catch (error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload item "+itemName+".\n");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- mud_reloadMobile(room, mobile, input) {
- input.shift();
- var mobileName = input.join(" ").trim();
- libs.Output.toMobile(mobile.id, "Preparing to reload mobile " + mobileName);
- try {
- delete require.cache[require.resolve(config.worldDataPath +'/mobiles')];
- mobiles = require(config.worldDataPath +'/mobiles');
- var fileName = (new mobiles[mobileName]()).filename;
- delete require.cache[require.resolve(config.worldDataPath +'/mobiles/' + fileName)];
- mobiles[mobileName] = require(config.worldDataPath +'/mobiles/' + fileName);
- for(var index in session.mobiles) {
- var mobileInstance = session.mobiles[index];
- if(mobileInstance.constructor.name == mobileName) {
- var tempMobile = new mobiles[mobileName]();
- libs.Output.toMobile(mobile.id, "Replacing " + mobileName + " instance " + mobileInstance.id + ".");
- for (var property in mobileInstance) {
- if (mobileInstance.hasOwnProperty(property)) {
- tempMobile[property] = mobileInstance[property];
- }
- }
- if(tempMobile.hasOwnProperty('login')) {
- tempMobile.login.player = tempMobile;
- }
- session.mobiles[tempMobile.id] = tempMobile;
- libs.Output.toMobile(tempMobile.id, "You feel your whole body vibrate slightly as your reality changes.");
- }
- }
- libs.Output.toMobile(mobile.id, "Mobile " + mobileName + " reloaded.");
- libs.Output.toServer("Mobile " + mobileName + " reloaded.");
- } catch (error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload mobile "+mobileName+".");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- spawn(room, mobile, input) {
- var type = input[0];
- switch(type) {
- case "room":
- input.shift();
- var roomName = input.join(" ").trim();
- libs.Output.toMobile(mobile.id, "Spawning room " + roomName + ".");
- this.mud_spawnRoom(roomName).id;
- return true;
- case "item":
- input.shift();
- var itemName = input.join(" ").trim();
- libs.Output.toMobile(mobile.id, "Spawning item " + itemName + " in inventory.");
- world.mud_addItemToMobile(mobile.id, this.mud_spawnItem(itemName).id);
- return true;
- case "mobile":
- input.shift();
- var mobileName = input.join(" ").trim();
- libs.Output.toMobile(mobile.id, "Spawning mobile " + mobileName + ".");
- world.mud_addMobileToRoom(mobile.roomId, this.mud_spawnMobile(mobileName).id);
- return true;
- default:
- this.help(room, mobile, ["spawn"]);
- return true;
- }
- }
- mud_spawnItem(itemName) {
- var tempItem = new items[itemName]();
- tempItem.id = session.itemIds++;
- session.items[tempItem.id] = tempItem;
- return tempItem;
- }
- mud_spawnMobile(mobileName) {
- var tempMobile = new mobiles[mobileName]();
- tempMobile.id = session.mobileIds++;
- session.mobiles[tempMobile.id] = tempMobile;
- return tempMobile;
- }
- mud_spawnRoom(roomName) {
- var tempRoom = new rooms[roomName]();
- session.rooms[tempRoom.id] = tempRoom;
- return tempRoom;
- }
- see(room, mobile, input) {
- switch(input.shift()) {
- case "room":
- this.mud_seeRoom(room, mobile, input);
- return true;
- case "item":
- this.mud_seeItem(room, mobile, input);
- return true;
- case "mobile":
- this.mud_seeMobile(room, mobile, input);
- return true;
- default:
- this.help(room, mobile, ["see"]);
- return true;
- }
- }
- mud_seeRoom(room, mobile, input) {
- libs.Output.toMobile(mobile.id, "Peering behind the veil:");
- libs.Output.toMobile(mobile.id, JSON.stringify(room, null, "\t").replace(/\n/g, "\r\n"));
- }
- mud_seeItem(room, mobile, input) {
- libs.Output.toMobile(mobile.id, "Peering behind the veil:");
- var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
- if(inventoryItem != null) {
- libs.Output.toMobile(mobile.id, JSON.stringify(inventoryItem, null, "\t").replace(/\n/g, "\r\n"));
- return true;
- }
- var roomItem = libs.Utilities.getSpecific(input.join(" "), room.items, session.items);
- if(roomItem != null) {
- libs.Output.toMobile(mobile.id, JSON.stringify(roomItem, null, "\t").replace(/\n/g, "\r\n"));
- return true;
- }
- libs.Output.toMobile(mobile.id, "That is not a valid item.");
- return true;
- }
- mud_seeMobile(room, mobile, input) {
- libs.Output.toMobile(mobile.id, "Peering behind the veil:");
- var roomMobile = libs.Utilities.getSpecific(input.join(" "), room.mobiles, session.mobiles);
- if(roomMobile != null) {
- var tempRoomMobile = Object.assign({}, roomMobile);
- if(tempRoomMobile.hasOwnProperty('socket')) {
- tempRoomMobile.socket = "[socket]";
- }
- if(tempRoomMobile.hasOwnProperty('login')) {
- tempRoomMobile.login = "[login]";
- }
- libs.Output.toMobile(mobile.id, JSON.stringify(tempRoomMobile, null, "\t").replace(/\n/g, "\r\n"));
- return true;
- } else if (input.length == 0) {
- var tempRoomMobile = Object.assign({}, mobile);
- if(tempRoomMobile.hasOwnProperty('socket')) {
- tempRoomMobile.socket = "[socket]";
- }
- if(tempRoomMobile.hasOwnProperty('login')) {
- tempRoomMobile.login = "[login]";
- }
- libs.Output.toMobile(mobile.id, JSON.stringify(tempRoomMobile, null, "\t").replace(/\n/g, "\r\n"));
- return true;
- }
- libs.Output.toMobile(mobile.id, "That is not a valid mobile.");
- return true;
-
- }
- warp(room, mobile, input) {
- if(input.length == 0) {
- this.help(room, mobile, ["warp"]);
- return true;
- }
- var roomName = input.shift().trim();
- if(session.rooms[roomName] != null) {
- world.mud_moveMobileFromRoom(mobile.roomId, mobile.id);
- world.mud_moveMobileToRoom(roomName, mobile.id);
- return true;
- }
- libs.Output.toMobile(mobile.id, "That is not a valid room to warp to.");
- return true;
- }
- derez(room, mobile, input) {
- switch(input.shift()) {
- case "item":
- this.mud_derezItem(room, mobile, input);
- return true;
- case "mobile":
- this.mud_derezMobile(room, mobile, input);
- return true;
- default:
- this.help(room, mobile, ["derez"]);
- return true;
- }
- }
- mud_derezItem(room, mobile, input) {
- var roomItem = libs.Utilities.getSpecific(input.join(" "), room.items, session.items);
- if(roomItem != null) {
- libs.Output.toRoom(room.id, roomItem.mud_getName() + " dissolves into nothingness.");
- world.mud_removeItemFromRoom(room.id, roomItem.id);
- world.mud_destroyItem(roomItem.id);
- return true;
- }
- var mobileItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
- if(mobileItem != null) {
- libs.Output.toRoom(room.id, mobileItem.mud_getName() + " dissolves into nothingness.");
- world.mud_removeItemFromMobile(mobile.id, mobileItem.id);
- world.mud_destroyItem(mobileItem.id);
- return true;
- }
- libs.Output.toMobile(mobile.id, "That isn't here.");
- return true;
- }
- mud_derezMobile(room, mobile, input) {
- var roomMobile = libs.Utilities.getSpecific(input.join(" "), room.mobiles, session.mobiles);
- if(roomMobile != null) {
- for(var itemIdIndex in roomMobile.items) {
- var otherItem = world.mud_getItem(roomMobile.items[itemIdIndex]);
- libs.Output.toRoom(room.id, otherItem.mud_getName() + " dissolves into nothingness.");
- world.mud_removeItemFromMobile(roomMobile.id, otherItem.id);
- world.mud_destroyItem(otherItem.id);
- }
- libs.Output.toRoom(room.id, roomMobile.name + " dissolves into nothingness.");
- world.mud_removeMobileFromRoom(room.id, roomMobile.id);
- world.mud_destroyMobile(roomMobile.id);
- return true;
- }
- libs.Output.toMobile(mobile.id, "That isn't here.");
- return true;
- }
- locate(room, mobile, input) {
- switch(input.shift()) {
- case "item":
- this.mud_locateItem(room, mobile, input);
- return true;
- case "mobile":
- this.mud_locateMobile(room, mobile, input);
- return true;
- case "all":
- this.mud_listAll(room, mobile, input);
- return true;
- default:
- this.help(room, mobile, ["locate"]);
- return true;
- }
- }
- mud_locateItem(room, mobile, input) {
- var itemName = input.shift();
- var instances = [];
- for(var roomName in session.rooms) {
- var otherRoom = session.rooms[roomName];
- for(var itemIdIndex in otherRoom.items) {
- var otherItem = world.mud_getItem(otherRoom.items[itemIdIndex]);
- if(itemName == otherItem.constructor.name) {
- libs.Output.toMobile(mobile.id, "Instance " + otherItem.id + " in " + otherRoom.id);
- instances.push(otherItem.id);
- }
- }
- }
- for(var mobileId in session.mobiles) {
- var otherMobile = session.mobiles[mobileId];
- for(var itemIdIndex in otherMobile.items) {
- var otherItem = world.mud_getItem(otherMobile.items[itemIdIndex]);
- if(itemName == otherItem.constructor.name) {
- libs.Output.toMobile(mobile.id, "Instance " + otherItem.id + " held by " + otherMobile.constructor.name + ":" + otherMobile.id);
- instances.push(otherItem.id);
- }
- }
- }
- for(var itemId in session.items) {
- var otherItem = session.items[itemId];
- if(itemName == otherItem.constructor.name && instances.indexOf(otherItem.id) == -1) {
- libs.Output.toMobile(mobile.id, "Instance " + otherItem.id + " is lost.");
- instances.push(otherMobile.id);
- }
- }
- if(instances.length == 0) {
- libs.Output.toMobile(mobile.id, "There are no " + itemName + " item instances.");
- }
- }
- mud_locateMobile(room, mobile, input) {
- var mobileName = input.shift();
- var instances = [];
- for(var roomName in session.rooms) {
- var otherRoom = session.rooms[roomName];
- for(var mobileIdIndex in otherRoom.mobiles) {
- var otherMobile = world.mud_getMobile(otherRoom.mobiles[mobileIdIndex]);
- if(mobileName == otherMobile.constructor.name) {
- libs.Output.toMobile(mobile.id, "Instance " + otherMobile.id + " in " + otherRoom.id);
- instances.push(otherMobile.id);
- }
- }
- }
-
- for(var mobileId in session.mobiles) {
- var otherMobile = session.mobiles[mobileId];
- if(mobileName == otherMobile.constructor.name && instances.indexOf(otherMobile.id) == -1) {
- libs.Output.toMobile(mobile.id, "Instance " + otherMobile.id + " is lost.");
- instances.push(otherMobile.id);
- }
- }
- if(instances.length == 0) {
- libs.Output.toMobile(mobile.id, "There are no " + mobileName + " mobile instances.");
- }
- }
- mud_listAll(room, mobile, input) {
- var itemInstances = [];
- for(var roomName in session.rooms) {
- var otherRoom = session.rooms[roomName];
- for(var itemIdIndex in otherRoom.items) {
- var otherItem = world.mud_getItem(otherRoom.items[itemIdIndex]);
- libs.Output.toMobile(mobile.id, otherItem.constructor.name + ":" + otherItem.id + " in " + otherRoom.id);
- itemInstances.push(otherItem.id);
-
- }
- }
- for(var mobileId in session.mobiles) {
- var otherMobile = session.mobiles[mobileId];
- for(var itemIdIndex in otherMobile.items) {
- var otherItem = world.mud_getItem(otherMobile.items[itemIdIndex]);
-
- libs.Output.toMobile(mobile.id, otherItem.constructor.name + ":" + otherItem.id + " held by " + otherMobile.constructor.name + ":" + otherMobile.id);
- itemInstances.push(otherItem.id);
- }
- }
- for(var itemId in session.items) {
- var otherItem = session.items[itemId];
- if(itemInstances.indexOf(otherItem.id) == -1) {
- libs.Output.toMobile(mobile.id, otherItem.constructor.name + ":" + otherItem.id + " is lost.");
- itemInstances.push(otherMobile.id);
- }
- }
- var mobileInstances = [];
- for(var roomName in session.rooms) {
- var otherRoom = session.rooms[roomName];
- for(var mobileIdIndex in otherRoom.mobiles) {
- var otherMobile = world.mud_getMobile(otherRoom.mobiles[mobileIdIndex]);
- libs.Output.toMobile(mobile.id, otherMobile.constructor.name + ":" + otherMobile.id + " in " + otherRoom.id);
- mobileInstances.push(otherMobile.id);
- }
- }
-
- for(var mobileId in session.mobiles) {
- var otherMobile = session.mobiles[mobileId];
- if(mobileInstances.indexOf(otherMobile.id) == -1) {
- libs.Output.toMobile(mobile.id, otherMobile.constructor.name + ":" + otherMobile.id + " is lost.");
- mobileInstances.push(otherMobile.id);
- }
- }
- }
- summon(room, mobile, input) {
- switch(input.shift()) {
- case "item":
- this.mud_summonItem(room, mobile, input);
- return true;
- case "mobile":
- this.mud_summonMobile(room, mobile, input);
- return true;
- default:
- this.help(room, mobile, ["summon"]);
- return true;
- }
- }
- mud_summonItem(room, mobile, input) {
- var itemInstance = parseInt(input.shift());
- var item = world.mud_getItem(itemInstance);
- if(item == null) {
- libs.Output.toMobile(mobile.id, "That is not a valid item instance.");
- return;
- }
- for(var roomName in session.rooms) {
- var otherRoom = session.rooms[roomName];
- if(otherRoom.items.indexOf(itemInstance) != -1) {
- world.mud_removeItemFromRoom(otherRoom.id, itemInstance);
- libs.Output.toRoom(otherRoom.id, "A pocket dimension opens up and swallows " + item.mud_getName() + ".",);
- }
- }
- for(var mobileId in session.mobiles) {
- var otherMobile = session.mobiles[mobileId];
- if(otherMobile.items.indexOf(itemInstance) != -1) {
- world.mud_removeItemFromMobile(otherMobile.id, itemInstance);
- libs.Output.toMobile(otherMobile.id, "A portal to a pocket dimension opens briefly and swallows " + item.mud_getName() + ".");
- }
- }
- world.mud_addItemToMobile(mobile.id, itemInstance);
- libs.Output.toMobile(mobile.id, "A portal to a pocket dimension opens and you get " + item.mud_getName() + ".");
- }
- mud_summonMobile(room, mobile, input) {
- var mobileInstance = parseInt(input.shift());
- var targetMobile = world.mud_getMobile(mobileInstance);
- if(targetMobile == null) {
- libs.Output.toMobile(mobile.id, "That is not a valid mobile instance.");
- return;
- }
- for(var roomName in session.rooms) {
- var otherRoom = session.rooms[roomName];
- if(otherRoom.mobiles.indexOf(mobileInstance) != -1) {
- world.mud_removeMobileFromRoom(otherRoom.id, mobileInstance);
- libs.Output.toRoom(otherRoom.id, "A pocket dimension opens up and swallows " + targetMobile.mud_getName() + ".");
- }
- }
- world.mud_addMobileToRoom(room.id, mobileInstance);
- libs.Output.toRoom(room.id, "A pocket dimension opens up and dumps " + targetMobile.mud_getName() + " here.");
- }
- }
- module.exports = new Builder();
|