home · contact · privacy
Enable selecting specific thing for pick-up.
[plomrogue2] / rogue_chat.html
index ef87c0f5888b8b449680cd22357bd1c5865da2fe..2b104a3fa724996ed9b083aca2ecfd630b42df78 100644 (file)
@@ -51,7 +51,7 @@ keyboard input/control: <span id="keyboard_control"></span>
   <tr>
     <td><button id="switch_to_play"></button></td>
     <td>
-      <button id="take_thing"></button>
+      <button id="switch_to_take_thing"></button>
       <button id="drop_thing"></button>
       <button id="door"></button>
       <button id="consume"></button>
@@ -96,10 +96,10 @@ keyboard input/control: <span id="keyboard_control"></span>
 <li>help: <input id="key_help" type="text" value="h" />
 <li>flatten surroundings: <input id="key_flatten" type="text" value="F" />
 <li>teleport: <input id="key_teleport" type="text" value="p" />
-<li>pick up thing: <input id="key_take_thing" type="text" value="z" />
 <li>drop thing: <input id="key_drop_thing" type="text" value="u" />
 <li>open/close: <input id="key_door" type="text" value="D" />
 <li>consume: <input id="key_consume" type="text" value="C" />
+<li><input id="key_switch_to_take_thing" type="text" value="z" />
 <li><input id="key_switch_to_chat" type="text" value="t" />
 <li><input id="key_switch_to_play" type="text" value="p" />
 <li><input id="key_switch_to_study" type="text" value="?" />
@@ -143,6 +143,10 @@ let mode_helps = {
         'short': 'command thing',
         'long': 'Enter a command to the thing you carry.  Enter nothing to return to play mode.'
     },
+    'take_thing': {
+        'short': 'take thing',
+        'long': 'You see a list of things which you could pick up.  Enter the target thing\'s index, or, to leave, nothing.'
+    },
     'admin_thing_protect': {
         'short': 'change thing protection',
         'long': 'Change protection character for thing here.'
@@ -208,7 +212,6 @@ let key_descriptions = {
     'help': 'help',
     'flatten': 'flatten surroundings',
     'teleport': 'teleport',
-    'take_thing': 'pick up thing',
     'drop_thing': 'drop thing',
     'door': 'open/close',
     'consume': 'consume',
@@ -461,6 +464,7 @@ let server = {
             game.tasks = tokens[1].split(',');
             tui.mode_write.legal = game.tasks.includes('WRITE');
             tui.mode_command_thing.legal = game.tasks.includes('WRITE');
+            tui.mode_take_thing.legal = game.tasks.includes('PICK_UP');
         } else if (tokens[0] === 'THING_TYPE') {
             game.thing_types[tokens[1]] = tokens[2]
         } else if (tokens[0] === 'TERRAIN') {
@@ -621,6 +625,7 @@ let tui = {
   mode_password: new Mode('password', true),
   mode_name_thing: new Mode('name_thing', true, true),
   mode_command_thing: new Mode('command_thing', true),
+  mode_take_thing: new Mode('take_thing', true),
   mode_admin_enter: new Mode('admin_enter', true),
   mode_admin: new Mode('admin'),
   mode_control_pw_pw: new Mode('control_pw_pw', true),
@@ -640,8 +645,8 @@ let tui = {
   init: function() {
       this.mode_chat.available_modes = ["play", "study", "edit", "admin_enter"]
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter",
-                                        "command_thing"]
-      this.mode_play.available_actions = ["move", "take_thing", "drop_thing",
+                                        "command_thing", "take_thing"]
+      this.mode_play.available_actions = ["move", "drop_thing",
                                           "teleport", "door", "consume"];
       this.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
       this.mode_study.available_actions = ["toggle_map_mode", "move_explorer"];
@@ -770,6 +775,25 @@ let tui = {
         }
     } else if (this.mode.is_single_char_entry) {
         this.show_help = true;
+    } else if (this.mode.name == 'take_thing') {
+        this.log_msg("selectable things:");
+        const player = game.things[game.player_id];
+        let selectables = [];
+        for (const t_id in game.things) {
+            const t = game.things[t_id];
+            if (t.position[0] == player.position[0]
+                && t.position[1] == player.position[1]
+                && t != player && t.type_ != 'Player') {
+                selectables.push([t_id, t]);
+            }
+        };
+        if (selectables.length == 0) {
+            this.log_msg('none')
+        } else {
+            for (const t of selectables) {
+                this.log_msg(t[0] + ' ' + explorer.get_thing_info(t[1]));
+            }
+        }
     } else if (this.mode.name == 'command_thing') {
         server.send(['TASK:COMMAND', 'HELP']);
     } else if (this.mode.name == 'admin_enter') {
@@ -1271,18 +1295,11 @@ let explorer = {
             for (let t_id in game.things) {
                  let t = game.things[t_id];
                  if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
-                     let symbol = game.thing_types[t.type_];
+                     info_to_cache += "THING: " + this.get_thing_info(t);
                      let protection = t.protection;
                      if (protection == '.') {
                          protection = 'none';
                      }
-                     info_to_cache += "THING: " + t.type_ + " / " + symbol;
-                     if (t.thing_char) {
-                         info_to_cache += t.thing_char;
-                     };
-                     if (t.name_) {
-                         info_to_cache += " (" + t.name_ + ")";
-                     }
                      info_to_cache += " / protection: " + protection + "\n";
                  }
             }
@@ -1296,6 +1313,17 @@ let explorer = {
         this.info_cached = info_to_cache;
         return this.info_cached;
     },
+    get_thing_info: function(t) {
+        const symbol = game.thing_types[t.type_];
+        let info = t.type_ + " / " + symbol;
+         if (t.thing_char) {
+             info += t.thing_char;
+         };
+         if (t.name_) {
+             info += " (" + t.name_ + ")";
+         }
+        return info;
+    },
     annotate: function(msg) {
         if (msg.length == 0) {
             msg = " ";  // triggers annotation deletion
@@ -1352,6 +1380,14 @@ tui.inputEl.addEventListener('keydown', (event) => {
             server.send(['TASK:COMMAND', tui.inputEl.value]);
             tui.inputEl.value = "";
         }
+    } else if (tui.mode.name == 'take_thing' && event.key == 'Enter') {
+        if (tui.inputEl.value.length == 0) {
+            tui.log_msg('@ aborted');
+        } else {
+            server.send(['TASK:PICK_UP', tui.inputEl.value]);
+        }
+        tui.inputEl.value = "";
+        tui.switch_mode('play');
     } else if (tui.mode.name == 'control_pw_pw' && event.key == 'Enter') {
         if (tui.inputEl.value.length == 0) {
             tui.log_msg('@ aborted');
@@ -1438,8 +1474,6 @@ tui.inputEl.addEventListener('keydown', (event) => {
     } else if (tui.mode.name == 'play') {
           if (tui.mode.mode_switch_on_key(event)) {
               null;
-          } else if (event.key === tui.keys.take_thing && tui.task_action_on('take_thing')) {
-              server.send(["TASK:PICK_UP"]);
           } else if (event.key === tui.keys.drop_thing && tui.task_action_on('drop_thing')) {
               server.send(["TASK:DROP"]);
           } else if (event.key === tui.keys.consume && tui.task_action_on('consume')) {
@@ -1553,11 +1587,8 @@ document.getElementById("toggle_map_mode").onclick = function() {
     tui.toggle_map_mode();
     tui.full_refresh();
 };
-document.getElementById("take_thing").onclick = function() {
-        server.send(['TASK:PICK_UP']);
-};
 document.getElementById("drop_thing").onclick = function() {
-        server.send(['TASK:DROP']);
+    server.send(['TASK:DROP']);
 };
 document.getElementById("flatten").onclick = function() {
     server.send(['TASK:FLATTEN_SURROUNDINGS', tui.password]);