def setupCommands(self): CommandsPlugin = self.dependencies[0] if self.Call_AI_Command not in CommandsPlugin.__commands__: CommandsPlugin.__commands__.append(self.Call_AI_Command) GeneralEvent.on('command={}'.format(self.Call_AI_Command.lower()), self.Play4) self.logger.debug("FindFour AI Call Command set. Command : %s", self.Call_AI_Command)
def __init__(self): super(Commands, self).__init__() self.logger = logging.getLogger(TIMELINE_LOGGER) GeneralEvent.on('before-message', self) GeneralEvent.on('after-message-muted', self.deMute) self.setup() self.logger.debug("Player Commands Active!")
def __init__(self): super(FindFourAI, self).__init__() self.logger = logging.getLogger(TIMELINE_LOGGER) self.Bots = {} self.AICreatedDefer = self.setupAI() self.setupCommands() self.logger.debug("FindFour AI Active!") self.logger.debug("Please ensure you have dassets.swf active!") GeneralEvent.on('onEngine', self.attachBotToServer)
def Play4(self, client, params): if client['room'].ext_id is not 220: return engine = client.engine if engine not in self.Bots: return client.send('sm', client['id'], "Sorry, bot is not available in this server!") AI = self.Bots[engine]['bot'] if self.Bots[engine]['playing'] is not None: return client.send( 'sm', AI['id'], "Sorry, am currently playing with {}".format( self.Bots[engine]['playing']['nickname'])) try: difficulty = int(params[0]) except: difficulty = 2 # default if difficulty > self.Bots[engine]['difficulty'] or difficulty < 1: difficulty = self.Bots[engine]['difficulty'] # maximum client.send( 'sm', AI['id'], "Let's play! Difficulty level set to {}".format(difficulty)) sleep(3) client.send('sm', AI['id'], "Finding a board to play...") AvailableBoard = self.getFourBoard(engine) if AvailableBoard is None: return client.send('sm', AI['id'], "Sorry, no boards are available to play! :(") self.Bots[engine]['playing'] = client AI.penguin.difficulty = difficulty GeneralEvent.on( 'Table-Left-{}-{}'.format(client['id'], AvailableBoard.table), self.ClientLeft) client.send('zaf', AvailableBoard.table) # make sure you have dote's assets Event.call('JoinTable-{}'.format(AvailableBoard.table), AI, AvailableBoard.table) AI['room'].send( 'sm', AI['id'], "FindFour: {} V/S {}, difficulty: {}, started!".format( AI['nickname'], client['nickname'], difficulty)) AI['game'].joinGame(AI)
def onCommand(command, protocol=AS3_PROTOCOL, function=None): command_ext = 'command[{}]={}'.format(protocol, command) commandPlugin = [i for i in PLUGIN_OBJECTS if isinstance(i, Commands)][-1] commandPlugin.__commands__.append( command) if command not in commandPlugin.__commands__ else None return GeneralEvent.on(command_ext, function=function)
def setup(self): GeneralEvent.on('command=jr', self.JoinRoomByExtId)