home · contact · privacy
Add bottle spinning.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 03:08:12 +0000 (04:08 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 03:08:12 +0000 (04:08 +0100)
plomrogue/game.py
plomrogue/tasks.py
plomrogue/things.py
rogue_chat.html
rogue_chat.py
rogue_chat_curses.py

index 31c9f2f61b83f3ceaf50cac640c81417c2e0dcc1..36a76561e21870d66d0e250e2d5a6d1b4de02d20 100755 (executable)
@@ -356,6 +356,7 @@ class Game(GameBase):
                         y_range_end = absolute_position.y + fov_radius
                         x_range_start = absolute_position.x - fov_radius
                         x_range_end = absolute_position.x + fov_radius
+                        # TODO: refactor with SourcedMap.inside?
                         for position in self.changed_tiles:
                             if position.y < y_range_start\
                                or position.y > y_range_end:
index d8d118a78108eb9fce1cad108816ac8509c8dd94..1e6737b64671188b967e42210a6fda8f73b7e3c9 100644 (file)
@@ -1,4 +1,5 @@
 from plomrogue.errors import PlayError, GameError
+from plomrogue.misc import quote
 
 
 
@@ -190,7 +191,6 @@ class Task_COMMAND(Task):
             raise PlayError('cannot command this item type')
 
     def do(self):
-        from plomrogue.misc import quote
         reply_lines = self.thing.carrying.interpret(self.args[0])
         for line in reply_lines:
             self.thing.send_msg('REPLY ' + quote(line))
@@ -249,8 +249,20 @@ class Task_WEAR(Task):
                 remixer.accept(t)
                 break
         else:
-            from plomrogue.misc import quote
             self.thing.game.hats[self.thing.name] = self.thing.carrying.design
             self.thing.game.remove_thing(self.thing.carrying)
             self.thing.carrying = None
             self.thing.send_msg('CHAT "You put on a hat."')
+
+
+
+class Task_SPIN(Task):
+
+    def check(self):
+        if not self.thing.carrying:
+            raise PlayError('holding nothing to spin')
+        if not hasattr(self.thing.carrying, 'spinnable'):
+            raise PlayError('held object not spinnable')
+
+    def do(self):
+        self.thing.carrying.spin()
index 4f802db6e25a9f340a9da02074b219d80502b0ab..7234d8ea395e05ab017fa55796bc32df1f21d94c 100644 (file)
@@ -1,5 +1,6 @@
 from plomrogue.errors import GameError, PlayError
 from plomrogue.mapping import YX
+from plomrogue.misc import quote
 import random
 
 
@@ -40,7 +41,6 @@ class Thing(ThingBase):
 
     def sound(self, name, msg):
         from plomrogue.mapping import DijkstraMap
-        from plomrogue.misc import quote
 
         def lower_msg_by_volume(msg, volume, largest_audible_distance):
             import random
@@ -151,11 +151,32 @@ class Thing_Bottle(Thing):
     portable = True
     full = True
     thing_char = '~'
+    spinnable = True
 
     def empty(self):
         self.thing_char = '_'
         self.full = False
 
+    def spin(self):
+        import random
+        all_players = [t for t in self.game.things if t.type_ == 'Player']
+        # TODO: refactor with ThingPlayer.prepare_multiprocessible_fov_stencil
+        # and ThingPlayer.fov_test
+        fov_map_class = self.game.map_geometry.fov_map_class
+        fov_radius = 12
+        fov = fov_map_class(self.game.things, self.game.maps,
+                            self.position, fov_radius, self.game.get_map)
+        fov.init_terrain()
+        visible_players = []
+        for p in all_players:
+            test_position = fov.target_yx(p.position[0], p.position[1])
+            if fov.inside(test_position) and fov[test_position] == '.':
+                visible_players += [p]
+        if len(visible_players) == 0:
+            self.sound('BOTTLE', 'no visible players in spin range')
+        pick = random.choice(visible_players)
+        self.sound('BOTTLE', 'BOTTLE picks: ' + pick.name)
+
 
 
 class Thing_BottleSpawner(ThingSpawner):
index 1c1fd1a125ddce134471b3cfb8432726e6a6e2ca..9740fff34c7b251509d4e7b40d341fdf98282481 100644 (file)
@@ -59,6 +59,7 @@ keyboard input/control: <span id="keyboard_control"></span>
       <button id="teleport"></button>
       <button id="install"></button>
       <button id="wear"></button>
+      <button id="spin"></button>
     </td>
   </tr>
   <tr>
@@ -99,6 +100,7 @@ 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>spin: <input id="key_spin" type="text" value="S" />
 <li>open/close: <input id="key_door" type="text" value="D" />
 <li>consume: <input id="key_consume" type="text" value="C" />
 <li>install: <input id="key_install" type="text" value="I" />
@@ -253,6 +255,7 @@ let key_descriptions = {
     'consume': 'consume',
     'install': '(un-)install',
     'wear': '(un-)wear',
+    'spin': 'spin',
     'toggle_map_mode': 'toggle map view',
     'toggle_tile_draw': 'toggle protection character drawing',
     'hex_move_upleft': 'up-left',
@@ -693,6 +696,7 @@ let tui = {
       'wear': 'WEAR',
       'command': 'COMMAND',
       'consume': 'INTOXICATE',
+      'spin': 'SPIN',
   },
   offset: [0,0],
   map_lines: [],
@@ -701,7 +705,7 @@ let tui = {
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter",
                                         "command_thing", "take_thing", "drop_thing"]
       this.mode_play.available_actions = ["move", "teleport", "door", "consume",
-                                          "install", "wear"];
+                                          "install", "wear", "spin"];
       this.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
       this.mode_study.available_actions = ["toggle_map_mode", "move_explorer"];
       this.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
@@ -1588,6 +1592,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
               server.send(["TASK:INSTALL"]);
           } else if (event.key === tui.keys.wear && tui.task_action_on('wear')) {
               server.send(["TASK:WEAR"]);
+          } else if (event.key === tui.keys.spin && tui.task_action_on('spin')) {
+              server.send(["TASK:SPIN"]);
           } else if (event.key in tui.movement_keys && tui.task_action_on('move')) {
               server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
           } else if (event.key === tui.keys.teleport) {
@@ -1710,6 +1716,9 @@ document.getElementById("install").onclick = function() {
 document.getElementById("wear").onclick = function() {
     server.send(['TASK:WEAR']);
 };
+document.getElementById("spin").onclick = function() {
+    server.send(['TASK:SPIN']);
+};
 document.getElementById("teleport").onclick = function() {
     game.teleport();
 };
index 8e4fd1bc366c8a2fc0acb2c6e0a081e7dd633e13..818758350c500ff5cf5eaaf914d9d9262442e8da 100755 (executable)
@@ -17,7 +17,7 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN
 from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
                              Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR,
                              Task_INTOXICATE, Task_COMMAND, Task_INSTALL,
-                             Task_WEAR)
+                             Task_WEAR, Task_SPIN)
 from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner,
                               Thing_SpawnPoint, Thing_SpawnPointSpawner,
                               Thing_Door, Thing_DoorSpawner, Thing_Bottle,
@@ -73,6 +73,7 @@ game.register_task(Task_INTOXICATE)
 game.register_task(Task_COMMAND)
 game.register_task(Task_INSTALL)
 game.register_task(Task_WEAR)
+game.register_task(Task_SPIN)
 game.register_thing_type(Thing_Player)
 game.register_thing_type(Thing_Item)
 game.register_thing_type(Thing_ItemSpawner)
index 2d51ce8a7b4b7d07fa7fed786975abead99af7c5..6f136387b33f5353c1216fb13163cdb10da1ba93 100755 (executable)
@@ -463,7 +463,7 @@ class TUI:
                                           "command_thing", "take_thing",
                                           "drop_thing"]
         self.mode_play.available_actions = ["move", "teleport", "door", "consume",
-                                            "install", "wear"]
+                                            "install", "wear", "spin"]
         self.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
         self.mode_study.available_actions = ["toggle_map_mode", "move_explorer"]
         self.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
@@ -513,6 +513,7 @@ class TUI:
             'door': 'D',
             'install': 'I',
             'wear': 'W',
+            'spin': 'S',
             'help': 'h',
             'toggle_map_mode': 'L',
             'toggle_tile_draw': 'm',
@@ -1030,6 +1031,7 @@ class TUI:
             'wear': '(un-)wear',
             'door': 'open/close',
             'consume': 'consume',
+            'spin': 'spin',
         }
 
         action_tasks = {
@@ -1042,6 +1044,7 @@ class TUI:
             'move': 'MOVE',
             'command': 'COMMAND',
             'consume': 'INTOXICATE',
+            'spin': 'SPIN',
         }
 
         curses.curs_set(False)  # hide cursor
@@ -1212,6 +1215,8 @@ class TUI:
                     self.send('TASK:INSTALL')
                 elif key == self.keys['wear'] and task_action_on('wear'):
                     self.send('TASK:WEAR')
+                elif key == self.keys['spin'] and task_action_on('spin'):
+                    self.send('TASK:SPIN')
                 elif key == self.keys['teleport']:
                     player = self.game.get_thing(self.game.player_id)
                     if player.position in self.game.portals: