home · contact · privacy
Spawn hats from BottleDeposit, add HatRemixer.
[plomrogue2] / plomrogue / things.py
index 720adc0ec64f0c432ec0f8e9ecbb3d5ecb29a413..32d7854732029bd0fc2ef2946dae9ecaebf006d7 100644 (file)
@@ -1,5 +1,6 @@
 from plomrogue.errors import GameError, PlayError
 from plomrogue.mapping import YX
+import random
 
 
 
@@ -163,6 +164,27 @@ class Thing_BottleSpawner(ThingSpawner):
 
 
 
+class Thing_Hat(Thing):
+    symbol_hint = 'H'
+    portable = True
+    design = ' X  X ==='
+
+
+
+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 …')
+
+
+
 import datetime
 class Thing_MusicPlayer(Thing):
     symbol_hint = 'R'
@@ -170,7 +192,7 @@ class Thing_MusicPlayer(Thing):
     portable = True
     repeat = True
     next_song_start = datetime.datetime.now()
-    playlist_index = 0
+    playlist_index = -1
     playing = True
 
     def __init__(self, *args, **kwargs):
@@ -182,12 +204,13 @@ class Thing_MusicPlayer(Thing):
         if (not self.playing) or len(self.playlist) == 0:
             return
         if datetime.datetime.now() > self.next_song_start:
-            song_data = self.playlist[self.playlist_index]
             self.playlist_index += 1
             if self.playlist_index == len(self.playlist):
                 self.playlist_index = 0
                 if not self.repeat:
                     self.playing = False
+                    return
+            song_data = self.playlist[self.playlist_index]
             self.next_song_start = datetime.datetime.now() +\
                 datetime.timedelta(seconds=song_data[1])
             self.sound('MUSICPLAYER', song_data[0])
@@ -198,7 +221,7 @@ class Thing_MusicPlayer(Thing):
         if command == 'HELP':
             msg_lines += ['available commands:']
             msg_lines += ['HELP – show this help']
-            msg_lines += ['PLAY – toggle playback on/off']
+            msg_lines += ['ON/OFF – toggle playback on/off']
             msg_lines += ['REWIND – return to start of playlist']
             msg_lines += ['LIST – list programmed songs, durations']
             msg_lines += ['SKIP – to skip to next song']
@@ -217,15 +240,23 @@ class Thing_MusicPlayer(Thing):
                 msg_lines += ['%s %s:%s – %s' % (selector, minutes, seconds, entry[0])]
                 i += 1
             return msg_lines
-        elif command == 'PLAY':
+        elif command == 'ON/OFF':
             self.playing = False if self.playing else True
             self.game.changed = True
             if self.playing:
                 return ['playing']
             else:
                 return ['paused']
+        elif command == 'REMOVE':
+            if len(self.playlist) == 0:
+                return ['playlist already empty']
+            del self.playlist[max(0, self.playlist_index)]
+            self.playlist_index -= 1
+            if self.playlist_index < -1:
+                self.playlist_index = -1
+            return ['removed song']
         elif command == 'REWIND':
-            self.playlist_index = 0
+            self.playlist_index = -1
             self.next_song_start = datetime.datetime.now()
             self.game.changed = True
             return ['back at start of playlist']
@@ -267,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):