home · contact · privacy
Add item picking and dropping.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 13 Nov 2020 23:28:36 +0000 (00:28 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 13 Nov 2020 23:28:36 +0000 (00:28 +0100)
config.json
plomrogue/tasks.py
plomrogue/things.py
rogue_chat.py
rogue_chat_curses.py
rogue_chat_nocanvas_monochrome.html

index d1682c3f3b62d0519c180584b71c03eadc4bb9a6..5bce7746690588755d4ad1d44a72ac59c3c77b31 100644 (file)
@@ -6,6 +6,8 @@
     "switch_to_study": "?",
     "switch_to_edit": "m",
     "flatten": "F",
+    "take_thing": "z",
+    "drop_thing": "u",
     "help": "h",
     "toggle_map_mode": "M",
     "hex_move_upleft": "w",
index e73b174a1fed351c03cf8c22bd791900e4f76cb9..6d1a32a75e65b4a5a7fe74a40634f260e85e4d1c 100644 (file)
@@ -20,7 +20,7 @@ class Task_WAIT(Task):
     todo = 1
 
     def do(self):
-        return 'success'
+        pass
 
 
 
@@ -44,6 +44,8 @@ class Task_MOVE(Task):
 
     def do(self):
         self.thing.position = self.get_move_target()
+        if self.thing.carrying:
+            self.thing.carrying.position = self.thing.position
 
 
 
@@ -75,3 +77,37 @@ class Task_FLATTEN_SURROUNDINGS(Task):
                 if not self.thing.game.can_do_tile_with_pw(yx, self.args[0]):
                     continue
                 self.thing.game.map[yx] = '.'
+
+
+
+class Task_PICK_UP(Task):
+    todo = 1
+
+    def check(self):
+        if self.thing.carrying:
+            raise PlayError('already carrying')
+        nothing_to_pick_up = True
+        for t in [t for t in self.thing.game.things
+                  if t != self.thing and t.position == self.thing.position
+                  and t.type_ != 'Player']:
+            nothing_to_pick_up = False
+            break
+        if nothing_to_pick_up:
+            raise PlayError('nothing to pick up')
+
+    def do(self):
+        to_pick_up = [t for t in self.thing.game.things
+                      if t != self.thing and t.position == self.thing.position][0]
+        self.thing.carrying = to_pick_up
+
+
+
+class Task_DROP(Task):
+    todo = 1
+
+    def check(self):
+        if not self.thing.carrying:
+            raise PlayError('nothing to drop')
+
+    def do(self):
+        self.thing.carrying = None
index d1fc7110b8bba8ca32baeeb1105d69b4c43c880b..b6fe5e15e5e919483962b87f63fdfa4a99a380e5 100644 (file)
@@ -108,3 +108,4 @@ class Thing_Player(ThingAnimate):
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         self.nickname = 'undefined'
+        self.carrying = None
index e25eeacf5e8a9ba4f283c4edffe265d71ea80015..e15ee242e92d71e9c9e3a637e7e989f65f75ac13 100755 (executable)
@@ -7,8 +7,8 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN
                                 cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE,
                                 cmd_TASKS, cmd_MAP_CONTROL_LINE, cmd_MAP_CONTROL_PW,
                                 cmd_GOD_ANNOTATE, cmd_GOD_PORTAL, cmd_THING_TYPES)
-from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE,
-                             Task_FLATTEN_SURROUNDINGS)
+from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
+                             Task_DROP, Task_FLATTEN_SURROUNDINGS)
 from plomrogue.things import Thing_Player, Thing_Stone
 import sys
 
@@ -39,6 +39,8 @@ game.register_task(Task_WAIT)
 game.register_task(Task_MOVE)
 game.register_task(Task_WRITE)
 game.register_task(Task_FLATTEN_SURROUNDINGS)
+game.register_task(Task_PICK_UP)
+game.register_task(Task_DROP)
 game.register_thing_type(Thing_Player)
 game.register_thing_type(Thing_Stone)
 game.read_savefile()
index 0a5ced7a0692c27b9211f9f57e7ac752b29fe447..f69153f1006cb127cf9f25a24bf52e6c2b118330 100755 (executable)
@@ -257,6 +257,8 @@ class TUI:
             'switch_to_study': '?',
             'switch_to_edit': 'm',
             'flatten': 'F',
+            'take_thing': 'z',
+            'drop_thing': 'u',
             'toggle_map_mode': 'M',
             'hex_move_upleft': 'w',
             'hex_move_upright': 'e',
@@ -533,6 +535,10 @@ class TUI:
                 content += "Available actions:\n"
                 if 'MOVE' in self.game.tasks:
                     content += "[%s] – move player\n" % ','.join(self.movement_keys)
+                if 'PICK_UP' in self.game.tasks:
+                    content += "[%s] – take thing under player\n" % self.keys['take_thing']
+                if 'DROP' in self.game.tasks:
+                    content += "[%s] – drop carried thing\n" % self.keys['drop_thing']
                 if 'FLATTEN_SURROUNDINGS' in self.game.tasks:
                     content += "[%s] – flatten player's surroundings\n" % self.keys['flatten']
                 content += 'Other modes available from here:\n'
@@ -721,6 +727,10 @@ class TUI:
                 elif key == self.keys['flatten'] and\
                      'FLATTEN_SURROUNDINGS' in self.game.tasks:
                     self.send('TASK:FLATTEN_SURROUNDINGS ' + quote(self.password))
+                elif key == self.keys['take_thing'] and 'PICK_UP' in self.game.tasks:
+                    self.send('TASK:PICK_UP')
+                elif key == self.keys['drop_thing'] and 'DROP' in self.game.tasks:
+                    self.send('TASK:DROP')
                 elif key in self.movement_keys and 'MOVE' in self.game.tasks:
                     self.send('TASK:MOVE ' + self.movement_keys[key])
             elif self.mode == self.mode_edit:
index d9732dad32cb3d9e28e97fc8036bdcef3f39c335..f978421590815a40877f704e13001bc72631c6e3 100644 (file)
@@ -23,6 +23,8 @@ move down-left (hex grid): <input id="key_hex_move_downleft" type="text" value="
 move left (hex grid): <input id="key_hex_move_left" type="text" value="a" /><br />
 help: <input id="key_help" type="text" value="h" /><br />
 flatten surroundings: <input id="key_flatten" type="text" value="F" /><br />
+take thing under player: <input id="key_take_thing" type="text" value="z" /><br />
+drop carried thing: <input id="key_drop_thing" type="text" value="u" /><br />
 switch to chat mode: <input id="key_switch_to_chat" type="text" value="t" /><br />
 switch to play mode: <input id="key_switch_to_play" type="text" value="p" /><br />
 switch to study mode: <input id="key_switch_to_study" type="text" value="?" /><br />
@@ -537,6 +539,12 @@ let tui = {
           if (game.tasks.includes('MOVE')) {
               content += "[" + movement_keys_desc + "] – move player\n";
           }
+          if (game.tasks.includes('PICK_UP')) {
+              content += "[" + this.keys.take_thing + "] – take thing under player\n";
+          }
+          if (game.tasks.includes('DROP')) {
+              content += "[" + this.keys.drop_thing + "] – drop carried thing\n";
+          }
           if (game.tasks.includes('FLATTEN_SURROUNDINGS')) {
               content += "[" + tui.keys.flatten + "] – flatten player's surroundings\n";
           }
@@ -826,6 +834,12 @@ tui.inputEl.addEventListener('keydown', (event) => {
           } else if (event.key === tui.keys.flatten
                      && game.tasks.includes('FLATTEN_SURROUNDINGS')) {
               server.send(["TASK:FLATTEN_SURROUNDINGS", tui.password]);
+          } else if (event.key === tui.keys.take_thing
+                     && game.tasks.includes('PICK_UP')) {
+              server.send(["TASK:PICK_UP"]);
+          } else if (event.key === tui.keys.drop_thing
+                     && game.tasks.includes('DROP')) {
+              server.send(["TASK:DROP"]);
           } else if (event.key in tui.movement_keys
                      && game.tasks.includes('MOVE')) {
               server.send(['TASK:MOVE', tui.movement_keys[event.key]]);