From: Christian Heller Date: Mon, 7 Dec 2020 05:35:27 +0000 (+0100) Subject: Spawn hats from BottleDeposit, add HatRemixer. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/static/bar%20baz.html?a=commitdiff_plain;h=4d2cf315344ec4a376ffb3f49f02674e4b5facb6;p=plomrogue2 Spawn hats from BottleDeposit, add HatRemixer. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 0228c69..a36f9e6 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -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' diff --git a/plomrogue/game.py b/plomrogue/game.py index 0fc4867..5e206b9 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -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))) diff --git a/plomrogue/parser.py b/plomrogue/parser.py index 140637b..302733d 100644 --- a/plomrogue/parser.py +++ b/plomrogue/parser.py @@ -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), ' diff --git a/plomrogue/tasks.py b/plomrogue/tasks.py index 9fccbc3..8337132 100644 --- a/plomrogue/tasks.py +++ b/plomrogue/tasks.py @@ -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 diff --git a/plomrogue/things.py b/plomrogue/things.py index 2c12cf2..32d7854 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -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): diff --git a/rogue_chat.py b/rogue_chat.py index 7882013..8e4fd1b 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -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']: