home · contact · privacy
Improve pick-up listing messages.
[plomrogue2] / rogue_chat.html
index 3c6fe00851e7c8c2454fa49d49de170782c52508..3d17c5a32e172fc8917d3e150827b8bcccec5e37 100644 (file)
@@ -150,7 +150,7 @@ let mode_helps = {
     },
     'take_thing': {
         'short': 'take thing',
-        'intro': '',
+        'intro': 'Pick up a thing in reach by entering its index number.  Enter nothing to abort.',
         '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': {
@@ -664,6 +664,7 @@ let tui = {
   },
   offset: [0,0],
   map_lines: [],
+  selectables: [],
   init: function() {
       this.mode_chat.available_modes = ["play", "study", "edit", "admin_enter"]
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter",
@@ -800,22 +801,38 @@ 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:");
+        this.log_msg("Things in reach for pick-up:");
         const player = game.things[game.player_id];
-        let selectables = [];
+        const y = player.position[0]
+        const x = player.position[1]
+        let select_range = [y.toString() + ':' + x.toString(),
+                            (y + 0).toString() + ':' + (x - 1).toString(),
+                            (y + 0).toString() + ':' + (x + 1).toString(),
+                            (y - 1).toString() + ':' + (x).toString(),
+                            (y + 1).toString() + ':' + (x).toString()];
+        if (game.map_geometry == 'Hex') {
+            if (y % 2) {
+                select_range.push((y - 1).toString() + ':' + (x + 1).toString());
+                select_range.push((y + 1).toString() + ':' + (x + 1).toString());
+            } else {
+                select_range.push((y - 1).toString() + ':' + (x - 1).toString());
+                select_range.push((y + 1).toString() + ':' + (x - 1).toString());
+            }
+        };
+        this.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]
+            if (select_range.includes(t.position[0].toString()
+                                      + ':' + t.position[1].toString())
                 && t != player && t.type_ != 'Player') {
-                selectables.push([t_id, t]);
+                this.selectables.push([t_id, t]);
             }
         };
-        if (selectables.length == 0) {
+        if (this.selectables.length == 0) {
             this.log_msg('none')
         } else {
-            for (const t of selectables) {
-                this.log_msg(t[0] + ' ' + explorer.get_thing_info(t[1]));
+            for (let [i, t] of this.selectables.entries()) {
+                this.log_msg(i + ': ' + explorer.get_thing_info(t[1]));
             }
         }
     } else if (this.mode.name == 'command_thing') {
@@ -1400,7 +1417,12 @@ tui.inputEl.addEventListener('keydown', (event) => {
         if (tui.inputEl.value.length == 0) {
             tui.log_msg('@ aborted');
         } else {
-            server.send(['TASK:PICK_UP', tui.inputEl.value]);
+            const i = parseInt(tui.inputEl.value);
+            if (isNaN(i) || i < 0 || i >= tui.selectables.length) {
+                tui.log_msg('? invalid index, aborted');
+            } else {
+                server.send(['TASK:PICK_UP', tui.selectables[i][0]]);
+            }
         }
         tui.inputEl.value = "";
         tui.switch_mode('play');