def start_round_delayed(self): self.announcer = Announcer() self.announcer.server = self.server self.announcer.irc_announcement = False self.announcer.action = 'Round starting' self.announcer.abort_message = 'round aborted.' self.announcer.message = "{time}" self.announcer.message_long = "Round starting in {time} seconds." self.announcer.time_left = self.round_delay self.announcer.reason = '1' self.announcer.action_func = self.start_round self.announcer.action_func_args = [] self.announcer.announce()
class TDMServer(TeamServer): team_class = TDMTeam connection_class = TDMConnection allow_join_when_locked = True destroy_empty_teams = False locked_teams = True auto_balance = True round_delay = 20 round_active = False suppress_damage = True max_score = 25 announcer = None def get_mode(self, event): return 'Team Deathmatch' def on_load(self): super(TDMServer, self).on_load() self.create_team('Red') self.create_team('Blue') self.loop.call_later(5.0, self.start_round_delayed) def give_reward(self, team): for m in team.members: self.silent_give_item(m.connection, generate_item(0, m.connection.entity)) # give items silently to players without broadcasting it to everyone def silent_give_item(self, connection, item): packet = ServerUpdate() packet.reset() action = PickupAction() action.entity_id = connection.entity_id action.item_data = item packet.pickups.append(action) connection.send_packet(packet) def declare_winner(self, team): if self.round_active: self.round_active = False self.suppress_damage = True message = 'Team "%s" has reached %s kills and won the round!' message = message % (team.name, self.max_score) print(message) self.server.send_chat(message) self.give_reward(team) self.loop.call_later(5.0, self.start_round_delayed) def set_max_score(self, score): self.max_score = score message = 'Team Deathmatch score max set to %s' % score self.server.send_chat(message) return message def get_scores(self): scores = [] for name, t in self.teams.items(): scores.append('%s %sK %sD' % (t.name, t.kills, t.deaths)) return 'Score: ' + ' - '.join(scores) def start_round(self): for name, t in self.teams.items(): t.reset_stats() self.auto_rebalance_teams() self.round_active = True self.suppress_damage = False message = 'Team Deathmatch! first team to %s kills wins.' % \ self.max_score print(message) self.server.send_chat(message) def start_round_delayed(self): self.announcer = Announcer() self.announcer.server = self.server self.announcer.irc_announcement = False self.announcer.action = 'Round starting' self.announcer.abort_message = 'round aborted.' self.announcer.message = "{time}" self.announcer.message_long = "Round starting in {time} seconds." self.announcer.time_left = self.round_delay self.announcer.reason = '1' self.announcer.action_func = self.start_round self.announcer.action_func_args = [] self.announcer.announce()