/// /// /// class ActionFollow extends Action { public static check = new Rulebook("Check Follow"); public static carry = new Rulebook("Carry out Follow"); public constructor (actor : Thing, ...nouns : Array) { super(actor, ...nouns); this.requiresNoun = true; this.requiresVisibility = false; } public getCommandText () { return "follow " + this.getNoun(0).getPrintedName(); } public static isCloseEnough (actor : Person, stalked : Thing) { let cRoom = actor.getRoom(); let tRoom = stalked.getRoom(); if (cRoom instanceof RoomRandom && tRoom instanceof RoomRandom) { let distance = tRoom.getDistanceTo(cRoom); if (distance == 1 || distance < (actor.getStat(Attributes.Intelligence)/2)) { return true; } } return false; } public checkFollowClose = ActionFollow.check.createAndAddRule({ name : "Follow - Is the stalked close enough?", code : (rulebook) => { let action = rulebook.noun; let actor = action.actor; let stalked = action.getNoun(0); let cRoom = actor.getRoom(); let tRoom = stalked.getRoom(); if (ActionFollow.isCloseEnough(actor, stalked)) { let direction = cRoom.getAStarBestDirectionTo(tRoom); return new ActionGo(actor, direction); } else { action.stop(); } } }) } Elements.HyperlinkHandler.HyperlinkingRulebook.addRule(new Rule( { name : "Hyperlink - Follow", firstPriority : Rule.PRIORITY_HIGHEST, code : (rulebook : RulebookRunner) => { let thing = rulebook.noun; if (thing instanceof Person && thing.getRoom() != WorldState.player.getRoom() && ActionFollow.isCloseEnough(WorldState.player, thing)) { Elements.HyperlinkHandler.addAvailableAction("Follow", new ActionFollow(WorldState.player, thing)); } } } ));