X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/form?a=blobdiff_plain;f=plomrogue%2Fcommands.py;h=8ea4ff34a738615c53b65f9349f905e483d39169;hb=71ffa4676857da80edebbbfca6e2910d929ee3a5;hp=daa43576cd7181ed4e285e3a389abf7dce0b5bbd;hpb=f68b1eccb0f22fc29e9fb612f65ce9c8b52023c3;p=plomrogue2 diff --git a/plomrogue/commands.py b/plomrogue/commands.py index daa4357..8ea4ff3 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -36,27 +36,28 @@ def cmd_SPAWN_POINT(game, big_yx, little_yx): cmd_SPAWN_POINT.argtypes = 'yx_tuple yx_tuple:nonneg' def cmd_LOGIN(game, nick, connection_id): + nick = nick.strip() + if len(nick) == 0: + raise GameError('empty name') for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]: raise GameError('name already in use') if game.get_player(connection_id): raise GameError('cannot log in twice') - t = game.thing_types['Player'](game) - t.position = game.spawn_point - game.things += [t] # TODO refactor into Thing.__init__? + t = game.add_thing('Player', game.spawn_point) + t.name = nick t.thing_char = game.get_next_player_char() game.sessions[connection_id] = { 'thing_id': t.id_, 'status': 'player' } + game.io.send('PLAYER_ID %s' % t.id_, connection_id) game.io.send('LOGIN_OK', connection_id) - t.name = nick game.io.send('CHAT ' + quote(t.name + ' entered the map.')) - game.io.send('PLAYER_ID %s' % t.id_, connection_id) for s in [s for s in game.things if s.type_ == 'SpawnPoint' and s.name == t.name]: t.position = s.position break - game.changed = True + # game.changed = True # handled by game.add_thing cmd_LOGIN.argtypes = 'string' def cmd_BECOME_ADMIN(game, password, connection_id): @@ -84,6 +85,7 @@ def cmd_SET_TILE_CONTROL(game, yx, control_char, connection_id): map_control = game.get_map(big_yx, 'control') map_control[little_yx] = control_char game.changed = True + game.record_fov_change((big_yx, little_yx)) cmd_SET_TILE_CONTROL.argtypes = 'yx_tuple:nonneg char' def cmd_THING_PROTECTION(game, thing_id, protection_char, connection_id): @@ -96,7 +98,9 @@ def cmd_THING_PROTECTION(game, thing_id, protection_char, connection_id): if not t: raise GameError('thing of ID %s not found' % thing_id) t.protection = protection_char - #game.changed = True + game.changed = True + # FIXME: pseudo-FOV-change actually + game.record_fov_change(t.position) cmd_THING_PROTECTION.argtypes = 'int:pos char' def cmd_SET_MAP_CONTROL_PASSWORD(game, tile_class, password, connection_id): @@ -112,6 +116,9 @@ def cmd_SET_MAP_CONTROL_PASSWORD(game, tile_class, password, connection_id): cmd_SET_MAP_CONTROL_PASSWORD.argtypes = 'char string' def cmd_NICK(game, nick, connection_id): + nick = nick.strip() + if len(nick) == 0: + raise GameError('empty name') for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]: raise GameError('name already in use') t = game.get_player(connection_id) @@ -121,6 +128,8 @@ def cmd_NICK(game, nick, connection_id): t.name = nick game.io.send('CHAT ' + quote(old_nick + ' renamed themselves to ' + nick)) game.changed = True + # FIXME: pseudo-FOV-change actually + game.record_fov_change(t.position) cmd_NICK.argtypes = 'string' def cmd_GET_GAMESTATE(game, connection_id): @@ -167,6 +176,8 @@ def cmd_ANNOTATE(game, yx, msg, pw, connection_id): if big_yx not in game.annotations: game.annotations[big_yx] = {} game.annotations[big_yx][little_yx] = msg + # FIXME: pseudo-FOV-change actually + game.record_fov_change([big_yx, little_yx]) game.changed = True cmd_ANNOTATE.argtypes = 'yx_tuple:nonneg string string' @@ -185,6 +196,8 @@ def cmd_PORTAL(game, yx, msg, pw, connection_id): if big_yx not in game.portals: game.portals[big_yx] = {} game.portals[big_yx][little_yx] = msg + # FIXME: pseudo-FOV-change actually + game.record_fov_change([big_yx, little_yx]) game.changed = True cmd_PORTAL.argtypes = 'yx_tuple:nonneg string string' @@ -192,14 +205,14 @@ def cmd_GOD_ANNOTATE(game, big_yx, little_yx, msg): if big_yx not in game.annotations: game.annotations[big_yx] = {} game.annotations[big_yx][little_yx] = msg - game.changed = True + #game.changed = True cmd_GOD_ANNOTATE.argtypes = 'yx_tuple yx_tuple:nonneg string' def cmd_GOD_PORTAL(game, big_yx, little_yx, msg): if big_yx not in game.portals: game.portals[big_yx] = {} game.portals[big_yx][little_yx] = msg - game.changed = True + #game.changed = True cmd_GOD_PORTAL.argtypes = 'yx_tuple yx_tuple:nonneg string' def cmd_MAP_LINE(game, big_yx, y, line): @@ -228,16 +241,8 @@ def cmd_THING(game, big_yx, little_yx, thing_type, thing_id): if thing_type not in game.thing_types: raise GameError('illegal thing type %s' % thing_type) _ = game.get_map(big_yx) - t_old = None - if thing_id > 0: - t_old = game.get_thing(thing_id) - t_new = game.thing_types[thing_type](game, id_=thing_id, position=(big_yx, - little_yx)) - if t_old: - game.things[game.things.index(t_old)] = t_new - else: - game.things += [t_new] - game.changed = True + game.add_thing(thing_type, (big_yx, little_yx), id_=thing_id) + # game.changed = True handled by add_thing cmd_THING.argtypes = 'yx_tuple yx_tuple:nonneg string:thing_type int:nonneg' def cmd_THING_NAME(game, thing_id, name, pw, connection_id): @@ -246,9 +251,11 @@ def cmd_THING_NAME(game, thing_id, name, pw, connection_id): if not t: raise GameError('thing of ID %s not found' % thing_id) if not game.can_do_thing_with_pw(t, pw): - raise GameError('wrong password for tile') + raise GameError('wrong password for thing') t.name = name game.changed = True + # FIXME: pseudo-FOV-change actually + game.record_fov_change(t.position) cmd_THING_NAME.argtypes = 'int:pos string string' def cmd_GOD_THING_NAME(game, thing_id, name): @@ -313,3 +320,38 @@ def cmd_THING_INSTALLED(game, thing_id): raise GameError('thing of ID %s not installable' % thing_id) t.install() cmd_THING_INSTALLED.argtypes = 'int:pos' + +def cmd_PLAYER_FACE(game, face, connection_id): + t = game.get_player(connection_id) + if not t: + raise GameError('can only draw face when already logged in') + if len(face) != 18: + raise GameError('wrong face string length') + game.faces[t.name] = face + game.changed = True + # FIXME: pseudo-FOV-change actually + game.record_fov_change(t.position) +cmd_PLAYER_FACE.argtypes = 'string' + +def cmd_GOD_PLAYER_FACE(game, name, face): + if len(face) != 18: + raise GameError('wrong face string length') + game.faces[name] = face +cmd_GOD_PLAYER_FACE.argtypes = 'string string' + +def cmd_GOD_PLAYER_HAT(game, name, hat): + if len(hat) != 18: + raise GameError('wrong hat string length') + game.hats[name] = hat +cmd_GOD_PLAYER_HAT.argtypes = 'string string' + +def cmd_THING_HAT_DESIGN(game, thing_id, design): + if len(design) != 18: + 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'