home · contact · privacy
Don't enter command_thing mode when not carrying anything commandable.
[plomrogue2] / rogue_chat.html
index 1b5f39d8f732f631f477b5dec8378349a21e8b4b..2e37e7f3376b2ed24f0600f6a63c1564833e90ba 100644 (file)
@@ -127,7 +127,7 @@ keyboard input/control: <span id="keyboard_control"></span>
 <script>
 "use strict";
 let websocket_location = "wss://plomlompom.com/rogue_chat/";
-//let websocket_location = "ws://localhost:8001/";
+//let websocket_location = "ws://localhost:8000/";
 
 let mode_helps = {
     'play': {
@@ -167,7 +167,7 @@ let mode_helps = {
     'enter_face': {
         'short': 'enter your face',
         'intro': '@ enter face line (enter nothing to abort):',
-        'long': 'Draw your face as ASCII art.  The string you enter must be 9 characters long, and will be divided on display into three lines of three characters each, from top to bottom..'
+        'long': 'Draw your face as ASCII art.  The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom..'
     },
     'write': {
         'short': 'change terrain',
@@ -485,6 +485,7 @@ let server = {
             t.type_ = tokens[2];
             t.protection = tokens[3];
             t.portable = parseInt(tokens[5]);
+            t.commandable = parseInt(tokens[6]);
         } else if (tokens[0] === 'THING_NAME') {
             let t = game.get_thing(tokens[1], false);
             t.name_ = tokens[2];
@@ -506,7 +507,7 @@ let server = {
             game.thing_types[tokens[1]] = tokens[2]
         } else if (tokens[0] === 'THING_CARRYING') {
             let t = game.get_thing(tokens[1], false);
-            t.carrying = true;
+            t.carrying = t = game.get_thing(tokens[2], false);
         } else if (tokens[0] === 'THING_INSTALLED') {
             let t = game.get_thing(tokens[1], false);
             t.installed = true;
@@ -756,17 +757,24 @@ let tui = {
         tui.log_msg('@ finished tile protection drawing.')
     }
     this.tile_draw = false;
+    const player = game.things[game.player_id];
+    if (mode_name == 'command_thing' && (!player.carrying || !player.carrying.commandable)) {
+        this.log_msg('? not carrying anything commandable');
+        terminal.blink_screen();
+        this.switch_mode('play');
+        return;
+    };
     if (mode_name == 'admin_enter' && this.is_admin) {
         mode_name = 'admin';
     } else if (['name_thing', 'admin_thing_protect'].includes(mode_name)) {
-        let player_position = game.things[game.player_id].position;
         let thing_id = null;
         for (let t_id in game.things) {
             if (t_id == game.player_id) {
                 continue;
             }
             let t = game.things[t_id];
-            if (player_position[0] == t.position[0] && player_position[1] == t.position[1]) {
+            if (player.position[0] == t.position[0]
+                && player.position[1] == t.position[1]) {
                 thing_id = t_id;
                 break;
             }
@@ -853,7 +861,10 @@ let tui = {
             }
         };
         if (this.selectables.length == 0) {
-            this.log_msg('none')
+            this.log_msg('none');
+            terminal.blink_screen();
+            this.switch_mode('play');
+            return;
         } else {
             for (let [i, t] of this.selectables.entries()) {
                 this.log_msg(i + ': ' + explorer.get_thing_info(t[1]));
@@ -1345,14 +1356,14 @@ let explorer = {
                      }
                      info_to_cache += " / protection: " + protection + "\n";
                      if (t.hat) {
-                         info_to_cache += t.hat.slice(0, 3) + '\n';
-                         info_to_cache += t.hat.slice(3, 6) + '\n';
-                         info_to_cache += t.hat.slice(6, 9) + '\n';
+                         info_to_cache += t.hat.slice(0, 6) + '\n';
+                         info_to_cache += t.hat.slice(6, 12) + '\n';
+                         info_to_cache += t.hat.slice(12, 18) + '\n';
                      }
                      if (t.face) {
-                         info_to_cache += t.face.slice(0, 3) + '\n';
-                         info_to_cache += t.face.slice(3, 6) + '\n';
-                         info_to_cache += t.face.slice(6, 9) + '\n';
+                         info_to_cache += t.face.slice(0, 6) + '\n';
+                         info_to_cache += t.face.slice(6, 12) + '\n';
+                         info_to_cache += t.face.slice(12, 18) + '\n';
                      }
                  }
             }
@@ -1448,7 +1459,7 @@ tui.inputEl.addEventListener('keydown', (event) => {
         server.send(['LOGIN', tui.inputEl.value]);
         tui.inputEl.value = "";
     } else if (tui.mode.name == 'enter_face' && event.key == 'Enter') {
-        if (tui.inputEl.value.length != 9) {
+        if (tui.inputEl.value.length != 18) {
             tui.log_msg('? wrong input length, aborting');
         } else {
             server.send(['PLAYER_FACE', tui.inputEl.value]);
@@ -1456,10 +1467,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
         tui.inputEl.value = "";
         tui.switch_mode('edit');
     } else if (tui.mode.name == 'command_thing' && event.key == 'Enter') {
-        if (tui.task_action_on('command')) {
-            server.send(['TASK:COMMAND', tui.inputEl.value]);
-            tui.inputEl.value = "";
-        }
+        server.send(['TASK:COMMAND', tui.inputEl.value]);
+        tui.inputEl.value = "";
     } else if (tui.mode.name == 'take_thing' && event.key == 'Enter') {
         const i = parseInt(tui.inputEl.value);
         if (isNaN(i) || i < 0 || i >= tui.selectables.length) {
@@ -1555,7 +1564,7 @@ tui.inputEl.addEventListener('keydown', (event) => {
               server.send(["TASK:DOOR"]);
           } else if (event.key === tui.keys.install && tui.task_action_on('install')) {
               server.send(["TASK:INSTALL"]);
-          } else if (event.key === tui.keys.install && tui.task_action_on('wear')) {
+          } else if (event.key === tui.keys.wear && tui.task_action_on('wear')) {
               server.send(["TASK:WEAR"]);
           } else if (event.key in tui.movement_keys && tui.task_action_on('move')) {
               server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
@@ -1686,13 +1695,16 @@ document.getElementById("teleport").onclick = function() {
     game.teleport();
 };
 for (const move_button of document.querySelectorAll('[id*="_move_"]')) {
+    if (move_button.id.startsWith('key_')) {  // not a move button
+        continue;
+    };
     let direction = move_button.id.split('_')[2].toUpperCase();
     move_button.onclick = function() {
-        if (tui.mode.available_actions.includes("move")
-            || tui.mode.available_actions.includes("move_explorer")) {
+        if (tui.mode.available_actions.includes("move")) {
             server.send(['TASK:MOVE', direction]);
-        } else {
+        } else if (tui.mode.available_actions.includes("move_explorer")) {
             explorer.move(direction);
+            tui.full_refresh();
         };
     };
 };