123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- module.exports = class Leafhopper {
- constructor() {
- this.id = 0;
- this.name = "a leafhopper";
- this.description = "A tiny insect that resembles a green leaf. It's difficult to hold on to it without {hint}squishing{/hint} it.";
- this.type = "item";
- this.keywords = ["insect", "grasshopper", "leafhopper", "bug"];
- this.resetDelay = 30000;
- this.itemExpires = 0;
- this.filename = "leafhopper.js";
- this.heldBy = -1;
- this.inRoom = "Void1";
- }
- mud_reset(time) {
- this.itemExpires = time + this.resetDelay;
- if(this.heldBy != -1) {
- var mobile = world.mud_getMobile(this.heldBy);
- if(mobile != null && mobile != {}) {
- libs.Output.toMobile(mobile.id, "The grasshopper squirms in your hand and tries to hop away.");
- if(parseInt(Math.random() * 4) == 0) {
- libs.Output.toMobile(mobile.id, "The grasshopper jumps free!");
- libs.Output.toRoom(mobile.roomId, "A tiny bug hops out of " + mobile.name + "'s hands!", mobile);
- this.heldBy = -1;
- this.inRoom = mobile.roomId;
- world.mud_removeItemFromMobile(mobile.id, this.id);
- world.mud_addItemToRoom(mobile.roomId, this.id);
- }
- }
- } else {
- var room = world.mud_getRoom(this.inRoom);
- if(room != null && room != {}) {
- libs.Output.toRoom(room.id, "A tiny leafhopper jumps around.");
- if(parseInt(Math.random() * 4) == 0 && room.mobiles.length > 0) {
- console.log(room.mobiles);
- var randomMobileId = parseInt(Math.random() * room.mobiles.length);
- console.log("jumping to mobile: " + randomMobileId);
- var mobile = world.mud_getMobile(randomMobileId);
- libs.Output.toMobile(mobile.id, "A tiny grasshopper jumps onto you.");
- libs.Output.toRoom(mobile.roomId, "A tiny bug hops into " + mobile.name + "'s hands!", mobile);
- world.mud_addItemToMobile(mobile.id, this.id);
- world.mud_removeItemFromRoom(room.id, this.id);
- this.heldBy = mobile.id;
- this.inRoom = 0;
- }
- }
- }
- }
- mud_tick(time) {
- if(time >= this.itemExpires) {
- this.mud_reset(time);
- }
- }
- get(room, mobile, input) {
- if(this.keywords.indexOf(input.join(" ")) != -1) {
- this.heldBy = mobile.id;
- return false;
- }
- }
- drop(room, mobile, input) {
- if(this.keywords.indexOf(input.join(" ")) != -1) {
- this.inRoom = mobile.roomId;
- this.heldBy = -1;
- return false;
- }
- }
- squish(room, mobile, input) {
- var inventoryItem = libs.Utilities.getSpecific(input[0], mobile.items, session.items);
- if(inventoryItem != null) {
- if(this != inventoryItem) {
- return false;
- }
- libs.Output.toMobile(mobile.id, "You slap your hands together and squish the tiny leafhopper.");
- libs.Output.toRoom(room.id, mobile.name + " slaps their hands together and squishes a bug.", mobile);
- if(this.heldBy != -1) {
- world.mud_removeItemFromMobile(mobile.id, this.id);
- } else if (this.inRoom != -1) {
- world.mud_removeItemFromRoom(room.id, this.id);
- }
-
- world.mud_destroyItem(this.id);
- return true;
- }
- }
- mud_saveItem() {
- var dataToSave = {};
- dataToSave.heldBy = this.heldBy;
- return dataToSave;
- }
- mud_loadItem(itemData) {
- for(var dataIndex in itemData) {
- if(this.hasOwnProperty(dataIndex)) {
- this[dataIndex] = itemData[dataIndex];
- }
- }
- }
- }
|