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.thing_char = game.get_next_player_char()
game.sessions[connection_id] = {
'thing_id': t.id_,
t.position = s.position
break
game.changed = True
- game.changed_fovs = True
cmd_LOGIN.argtypes = 'string'
def cmd_BECOME_ADMIN(game, password, connection_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.add_thing(thing_type, (big_yx, little_yx), id_=thing_id)
game.changed = True
- game.changed_fovs = True
cmd_THING.argtypes = 'yx_tuple yx_tuple:nonneg string:thing_type int:nonneg'
def cmd_THING_NAME(game, thing_id, name, pw, connection_id):
return '/O O\\' + '| oo |' + '\\>--</'
return None
+ def remove_thing(self, t):
+ self.things.remove(t)
+ self.changed_fovs = True
+
+ def add_thing(self, type_, position, id_=0):
+ t_old = None
+ if id_ > 0:
+ t_old = self.get_thing(id_)
+ t = self.thing_types[type_](self, id_=id_, position=position)
+ if t_old:
+ self.things[self.things.index(t_old)] = t
+ else:
+ self.things += [t]
+ self.changed_fovs = True
+ return t
+
def send_gamestate(self, connection_id=None):
"""Send out game state data relevant to clients."""
t = self.get_player(connection_id)
if hasattr(t, 'name'):
self.io.send('CHAT ' + quote(t.name + ' left the map.'))
- self.things.remove(t)
- self.changed_fovs = True
+ self.remove_thing(t)
to_delete += [connection_id]
for connection_id in to_delete:
del self.sessions[connection_id]
if t.type_ == 'BottleDeposit'
and t.position == self.thing.position]:
t.accept()
- self.thing.game.things.remove(self.thing.carrying)
- self.thing.game.changed_fovs = True
+ self.thing.game.remove_thing(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)
- self.thing.game.changed_fovs = True
break
self.thing.carrying = None
def do(self):
if self.thing.name in self.thing.game.hats:
- t = self.thing.game.thing_types['Hat'](self.thing.game,
- position=self.thing.position)
- self.thing.game.things += [t]
+ t = self.thing.game.add_thing('Hat', self.thing.position)
t.design = self.thing.game.hats[self.thing.name]
del self.thing.game.hats[self.thing.name]
self.thing.send_msg('CHAT "You drop your hat."')
- self.game.changed_fovs = True # thing addition
for remixer in [t for t in self.thing.game.things
if t.type_ == 'HatRemixer'
and t.position == self.thing.position]:
for t in [t for t in self.game.things
if t != self and t.position == self.position]:
return
- t = self.game.thing_types[self.child_type](self.game,
- position=self.position)
- self.game.things += [t]
+ self.game.add_thing(self.child_type, self.position)
self.game.changed = True
- self.game.changed_fovs = True
if self.bottle_counter >= 3:
self.bottle_counter = 0
choice = random.choice(['MusicPlayer', 'Hat'])
- t = self.game.thing_types[choice](self.game, position=self.position)
- self.game.things += [t]
+ self.game.add_thing(choice, self.position)
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!'
msg += 'pick it up and then use "(un-)wear" on it!'
self.sound('BOTTLE DEPOSITOR', msg)
self.game.changed = True
- self.game.changed_fovs = True
def accept(self):
self.bottle_counter += 1