home · contact · privacy
Spawn hats from BottleDeposit, add HatRemixer.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 7 Dec 2020 05:35:27 +0000 (06:35 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 7 Dec 2020 05:35:27 +0000 (06:35 +0100)
plomrogue/commands.py
plomrogue/game.py
plomrogue/parser.py
plomrogue/tasks.py
plomrogue/things.py
rogue_chat.py

index 0228c69de5cede80930cb3104d8e14bf9df53073..a36f9e6a5a8cc51a6aee35118f2b909dd9f305cd 100644 (file)
@@ -331,3 +331,14 @@ cmd_GOD_PLAYER_FACE.argtypes = 'string string'
 def cmd_GOD_PLAYER_HAT(game, name, hat):
     game.hats[name] = hat
 cmd_GOD_PLAYER_HAT.argtypes = 'string string'
+
+def cmd_THING_HAT_DESIGN(game, thing_id, design):
+    if len(design) != 9:
+        raise GameError('hat design of wrong length')
+    t = game.get_thing(thing_id)
+    if not t:
+        raise GameError('thing of ID %s not found' % thing_id)
+    if t.type_ != 'Hat':
+        raise GameError('thing of ID %s not a hat' % thing_id)
+    t.design = design
+cmd_THING_HAT_DESIGN.argtypes = 'int:pos string'
index 0fc486796232a1e5c95f102847e5ea59147eb2ba..5e206b9c8c289155a59aa7700dd9306ea4e05e79 100755 (executable)
@@ -403,6 +403,9 @@ class Game(GameBase):
                     write(f, 'THING_INSTALLED %s' % t.id_)
                 if t.type_ == 'Door' and t.blocking:
                     write(f, 'THING_DOOR_CLOSED %s' % t.id_)
+                elif t.type_ == 'Hat':
+                    write(f, 'THING_HAT_DESIGN %s %s' % (t.id_,
+                                                         quote(t.design)))
                 elif t.type_ == 'MusicPlayer':
                     write(f, 'THING_MUSICPLAYER_SETTINGS %s %s %s %s' %
                           (t.id_, int(t.playing), t.playlist_index, int(t.repeat)))
index 140637b468aea0982462a9e3a697690ee24c676d..302733d0322a69c9592276b94239b626debcb4c3 100644 (file)
@@ -84,7 +84,7 @@ class Parser:
         import string
         msg = msg.replace('\n', ' ')  # Inserted by some tablet keyboards.
         legal_chars = string.digits + string.ascii_letters +\
-            string.punctuation + ' ' + 'ÄäÖöÜüߧ' + 'éèáàô' + '–'
+            string.punctuation + ' ' + 'ÄäÖöÜüߧ' + 'éèáàô' + '–'
         for c in msg:
             if not c in legal_chars:
                 raise ArgError('Command/message contains illegal character(s), '
index 9fccbc33450f2c50fe5caf6269d0ba171bc7e644..8337132f58f77450df3d27e5a20f155d9692b407 100644 (file)
@@ -122,6 +122,12 @@ class Task_DROP(Task):
                 t.accept()
                 self.thing.game.things.remove(self.thing.carrying)
                 break
+        elif self.thing.carrying.type_ == 'Hat':
+            for t in [t for t in self.thing.game.things
+                      if t.type_ == 'HatRemixer'
+                      and t.position == self.thing.position]:
+                t.accept(self.thing.carrying)
+                break
         self.thing.carrying = None
 
 
index 2c12cf283e41cc5b788d37c35d1fabe23225ba17..32d7854732029bd0fc2ef2946dae9ecaebf006d7 100644 (file)
@@ -1,5 +1,6 @@
 from plomrogue.errors import GameError, PlayError
 from plomrogue.mapping import YX
+import random
 
 
 
@@ -170,9 +171,17 @@ class Thing_Hat(Thing):
 
 
 
-class Thing_HatSpawner(ThingSpawner):
-    child_type = 'Hat'
+class Thing_HatRemixer(Thing):
+    symbol_hint = 'H'
 
+    def accept(self, hat):
+        import string
+        new_design = ''
+        legal_chars = string.ascii_letters + string.digits + string.punctuation + ' '
+        for i in range(9):
+            new_design += random.choice(list(legal_chars))
+        hat.design = new_design
+        self.sound('HAT REMIXER', 'remixing a hat …')
 
 
 
@@ -289,12 +298,15 @@ class Thing_BottleDeposit(Thing):
     def proceed(self):
         if self.bottle_counter >= 3:
             self.bottle_counter = 0
-            t = self.game.thing_types['MusicPlayer'](self.game,
-                                                     position=self.position)
+            choice = random.choice(['MusicPlayer', 'Hat'])
+            t = self.game.thing_types[choice](self.game, position=self.position)
             self.game.things += [t]
-            self.sound('BOTTLE DEPOSITOR',
-                       'here is a gift as a reward for ecological consciousness –'
-                       'use "command thing" on it to learn more!')
+            msg = 'here is a gift as a reward for ecological consciousness –'
+            if choice == 'MusicPlayer':
+                msg += 'pick it up and then use "command thing" on it!'
+            elif choice == 'Hat':
+                msg += 'pick it up and then use "(un-)wear" on it!'
+            self.sound('BOTTLE DEPOSITOR', msg)
             self.game.changed = True
 
     def accept(self):
index 7882013af3f539838648e373f105ce66178e3bc8..8e4fd1bc366c8a2fc0acb2c6e0a081e7dd633e13 100755 (executable)
@@ -10,7 +10,7 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN
                                 cmd_GOD_THING_NAME, cmd_THING_DOOR_CLOSED,
                                 cmd_GOD_THING_PROTECTION, cmd_THING_PROTECTION,
                                 cmd_SET_MAP_CONTROL_PASSWORD, cmd_SPAWN_POINT,
-                                cmd_THING_MUSICPLAYER_SETTINGS,
+                                cmd_THING_MUSICPLAYER_SETTINGS, cmd_THING_HAT_DESIGN,
                                 cmd_THING_MUSICPLAYER_PLAYLIST_ITEM,
                                 cmd_THING_BOTTLE_EMPTY, cmd_PLAYER_FACE,
                                 cmd_GOD_PLAYER_FACE, cmd_GOD_PLAYER_HAT)
@@ -22,7 +22,7 @@ from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner,
                               Thing_SpawnPoint, Thing_SpawnPointSpawner,
                               Thing_Door, Thing_DoorSpawner, Thing_Bottle,
                               Thing_BottleSpawner, Thing_BottleDeposit,
-                              Thing_MusicPlayer, Thing_Hat, Thing_HatSpawner)
+                              Thing_MusicPlayer, Thing_Hat, Thing_HatRemixer)
 
 from plomrogue.config import config
 game = Game(config['savefile'])
@@ -61,6 +61,7 @@ game.register_command(cmd_THING_BOTTLE_EMPTY)
 game.register_command(cmd_PLAYER_FACE)
 game.register_command(cmd_GOD_PLAYER_FACE)
 game.register_command(cmd_GOD_PLAYER_HAT)
+game.register_command(cmd_THING_HAT_DESIGN)
 game.register_task(Task_WAIT)
 game.register_task(Task_MOVE)
 game.register_task(Task_WRITE)
@@ -84,7 +85,7 @@ game.register_thing_type(Thing_BottleSpawner)
 game.register_thing_type(Thing_BottleDeposit)
 game.register_thing_type(Thing_MusicPlayer)
 game.register_thing_type(Thing_Hat)
-game.register_thing_type(Thing_HatSpawner)
+game.register_thing_type(Thing_HatRemixer)
 game.read_savefile()
 game.io.start_loop()
 for port in config['servers']: