home · contact · privacy
Add BottleDeposit thing that spawns MusicPlayers for returned Bottles.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 3 Dec 2020 05:17:43 +0000 (06:17 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 3 Dec 2020 05:17:43 +0000 (06:17 +0100)
plomrogue/tasks.py
plomrogue/things.py
rogue_chat.py

index eca94003d6c8a5a52e3b6f15d13464f188c17d86..423758d8f5959ec7ebec088abfa18d7800d28bc1 100644 (file)
@@ -103,8 +103,20 @@ class Task_DROP(Task):
     def check(self):
         if not self.thing.carrying:
             raise PlayError('nothing to drop')
+        if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
+            for t in [t for t in self.thing.game.things
+                      if t.type_ == 'BottleDeposit'
+                      and t.position == self.thing.position]:
+                raise PlayError('cannot drop full bottle into bottle deposit')
 
     def do(self):
+        if self.thing.carrying.type_ == 'Bottle' and not self.thing.carrying.full:
+            for t in [t for t in self.thing.game.things
+                      if t.type_ == 'BottleDeposit'
+                      and t.position == self.thing.position]:
+                t.accept()
+                self.thing.game.things.remove(self.thing.carrying)
+                break
         self.thing.carrying = None
 
 
index 67a3807fc939b88df98716d61392065d2511e496..30cd2bfe104fdd2a36836b87a401f6d33cc555f2 100644 (file)
@@ -158,7 +158,6 @@ class Thing_MusicPlayer(Thing):
     symbol_hint = 'R'
     commandable = True
     portable = True
-    playlist = []
     repeat = True
     next_song_start = datetime.datetime.now()
     playlist_index = 0
@@ -167,6 +166,7 @@ class Thing_MusicPlayer(Thing):
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         self.next_song_start = datetime.datetime.now()
+        self.playlist = []
 
     def proceed(self):
         if (not self.playing) or len(self.playlist) == 0:
@@ -250,6 +250,30 @@ class Thing_MusicPlayer(Thing):
 
 
 
+class Thing_BottleDeposit(Thing):
+    bottle_counter = 0
+    symbol_hint = 'O'
+
+    def proceed(self):
+        if self.bottle_counter >= 3:
+            self.bottle_counter = 0
+            t = self.game.thing_types['MusicPlayer'](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!')
+            self.game.changed = True
+
+    def accept(self):
+        self.bottle_counter += 1
+        self.sound('BOTTLE DEPOSITOR',
+                   'thanks for this empty bottle – deposit %s more for a gift!' %
+                   (3 - self.bottle_counter))
+
+
+
+
 class ThingAnimate(Thing):
     blocking = True
     drunk = 0
index cb3080d0caa3d315f01f76c80c4d457492c81d11..4509d33a73dc1d01a294524edafa21dd4800ca13 100755 (executable)
@@ -19,7 +19,8 @@ from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
 from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner,
                               Thing_SpawnPoint, Thing_SpawnPointSpawner,
                               Thing_Door, Thing_DoorSpawner, Thing_Bottle,
-                              Thing_BottleSpawner, Thing_MusicPlayer)
+                              Thing_BottleSpawner, Thing_BottleDeposit,
+                              Thing_MusicPlayer)
 
 from plomrogue.config import config
 game = Game(config['savefile'])
@@ -73,6 +74,7 @@ game.register_thing_type(Thing_Door)
 game.register_thing_type(Thing_DoorSpawner)
 game.register_thing_type(Thing_Bottle)
 game.register_thing_type(Thing_BottleSpawner)
+game.register_thing_type(Thing_BottleDeposit)
 game.register_thing_type(Thing_MusicPlayer)
 game.read_savefile()
 game.io.start_loop()