From 80b6be9545812304bed7cf2a25434ef5f08a25c3 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 27 Nov 2020 02:05:57 +0100 Subject: [PATCH] Add Thing spawner. --- plomrogue/tasks.py | 6 ++++-- plomrogue/things.py | 15 +++++++++++++++ rogue_chat.py | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plomrogue/tasks.py b/plomrogue/tasks.py index 558b178..a7bcf37 100644 --- a/plomrogue/tasks.py +++ b/plomrogue/tasks.py @@ -87,7 +87,8 @@ class Task_PICK_UP(Task): raise PlayError('already carrying something') nothing_to_pick_up = True for t in [t for t in self.thing.game.things - if t != self.thing and t.position == self.thing.position and + if t.portable + and t != self.thing and t.position == self.thing.position and t.type_ != 'Player']: nothing_to_pick_up = False break @@ -96,7 +97,8 @@ class Task_PICK_UP(Task): def do(self): to_pick_up = [t for t in self.thing.game.things - if t != self.thing and t.position == self.thing.position][0] + if t.portable + and t != self.thing and t.position == self.thing.position][0] self.thing.carrying = to_pick_up diff --git a/plomrogue/things.py b/plomrogue/things.py index 1618ee6..ca53e87 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -18,6 +18,7 @@ class ThingBase: class Thing(ThingBase): blocking = False + portable = False protection = '.' def __init__(self, *args, **kwargs): @@ -38,6 +39,20 @@ class Thing(ThingBase): class Thing_Item(Thing): symbol_hint = 'i' + portable = True + + + +class Thing_Spawner(Thing): + symbol_hint = 'S' + + def proceed(self): + for t in [t for t in self.game.things + if t != self and t.position == self.position]: + return + t = self.game.thing_types['Item'](self.game, position=self.position) + self.game.things += [t] + self.game.changed = True diff --git a/rogue_chat.py b/rogue_chat.py index 5c5e657..1d9e4cb 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -12,7 +12,7 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN cmd_SET_MAP_CONTROL_PASSWORD, cmd_SPAWN_POINT) from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP, Task_DROP, Task_FLATTEN_SURROUNDINGS) -from plomrogue.things import Thing_Player, Thing_Item +from plomrogue.things import Thing_Player, Thing_Item, Thing_Spawner from plomrogue.config import config game = Game(config['savefile']) @@ -52,6 +52,7 @@ game.register_task(Task_PICK_UP) game.register_task(Task_DROP) game.register_thing_type(Thing_Player) game.register_thing_type(Thing_Item) +game.register_thing_type(Thing_Spawner) game.read_savefile() game.io.start_loop() for port in config['servers']: -- 2.30.2