import socket
import threading
from plomrogue.parser import ArgError, Parser
-from plomrogue.commands import cmd_MAP, cmd_THING_TYPE, cmd_THING_POS
+from plomrogue.commands import cmd_MAP, cmd_THING_POS
from plomrogue.game import Game, WorldBase
from plomrogue.mapping import MapBase
from plomrogue.io import PlomSocket
self.to_update['turn'] = True
self.to_update['map'] = True
+def cmd_THING_TYPE(game, i, type_):
+ t = game.world.get_thing(i)
+ t.type_ = type_
+cmd_THING_TYPE.argtypes = 'int:nonneg string'
+
class Game:
cmd_MAP.argtypes = 'yx_tuple:pos'
def cmd_THING_TYPE(game, i, type_):
- t = game.world.get_thing(i)
- t.type_ = type_
-cmd_THING_TYPE.argtypes = 'int:nonneg string'
+ t_old = game.world.get_thing(i)
+ t_new = game.thing_types[type_](game.world, i)
+ #attr_names_of_old = [name for name in dir(t_old) where name[:2] != '__']
+ #attr_names_of_new = [name for name in dir(t_new) where name[:2] != '__']
+ #class_new = type(t_new)
+ #for attr_name in [v for v in attr_names_of_old if v in attr_names_of_new]:
+ # if hasattr(class_new, attr_name):
+ # attr_new = getattr(class_new, attr_name)
+ # if type(attr_new) == property and attr_new.fset is None:
+ # continue # ignore read-only properties on t_new
+ # attr_old = getattr(t_old, attr_name)
+ # attr_new = getattr(t_new, attr_name)
+ # if type(attr_old) != type(attr_new):
+ # continue
+ # setattr(t_new, attr_name, attr_old)
+ t_new.position = t_old.position
+ t_old_index = game.world.things.index(t_old)
+ game.world.things[t_old_index] = t_new
+cmd_THING_TYPE.argtypes = 'int:nonneg string:thingtype'
def cmd_THING_POS(game, i, yx):
t = game.world.get_thing(i)
from plomrogue.parser import Parser
from plomrogue.io import GameIO
from plomrogue.misc import quote, stringify_yx
-from plomrogue.things import Thing
+from plomrogue.things import Thing, ThingMonster, ThingHuman
self.map_[pos] = '#'
continue
self.map_[pos] = random.choice(('.', '.', '.', '.', 'x'))
- player = self.game.thing_type(self, 0)
- player.type_ = 'human'
+ player = self.game.thing_types['human'](self, 0)
player.position = [random.randint(0, yx[0] -1),
random.randint(0, yx[1] - 1)]
- npc = self.game.thing_type(self, 1)
- npc.type_ = 'monster'
+ npc = self.game.thing_types['monster'](self, 1)
npc.position = [random.randint(0, yx[0] -1),
random.randint(0, yx[1] -1)]
self.things = [player, npc]
self.world_type = World
self.world = self.world_type(self)
self.thing_type = Thing
+ self.thing_types = {'human': ThingHuman, 'monster': ThingMonster}
def get_string_options(self, string_option_type):
if string_option_type == 'direction':
return self.world.map_.get_directions()
+ elif string_option_type == 'thingtype':
+ return list(self.thing_types.keys())
return None
def send_gamestate(self, connection_id=None):
class ThingBase:
+ type_ = '?'
- def __init__(self, world, id_, type_='?', position=[0,0]):
+ def __init__(self, world, id_, position=[0,0]):
self.world = world
self.id_ = id_
- self.type_ = type_
self.position = position
if stencil[thing.position] == '.':
visible_things += [thing]
return visible_things
+
+
+
+class ThingHuman(Thing):
+ type_ = 'human'
+
+
+
+class ThingMonster(Thing):
+ type_ = 'monster'