def CmdUseItem(args, charIndex): from mud.client.playermind import formatMLString from partyWnd import PARTYWND # Check for existance of arguments. if not len(args): receiveGameText(RPG_MSG_GAME_DENIED, "Please specify an item name.\\n") return # Get current character info. if charIndex == None: charIndex = PARTYWND.curIndex charInfo = PARTYWND.charInfos[charIndex] # Join the list with spaces to get the desired item name. itemName = formatMLString(' '.join(args).replace('\\', '\\\\')) itemNameUpper = itemName.upper() # Search for an available item with the desired name in the # chosen characters inventory, exclude cursor item. for itemSlot, itemInfo in charInfo.ITEMS.iteritems(): if itemSlot == RPG_SLOT_CURSOR: continue if itemInfo.NAME.upper() == itemNameUpper: if not itemInfo.REUSETIMER: PARTYWND.mind.perspective.callRemote("PlayerAvatar", "onInvSlotCtrl", charInfo.CHARID, itemSlot) break else: receiveGameText( RPG_MSG_GAME_DENIED, "%s has no %s ready for use.\\n" % (charInfo.NAME, itemName))
def HelpMsg(msg): if not IRC or not len(msg) or CheckMuted(): return name = IRC.nickname sname = name.replace("_", " ") receiveSpeechText( RPG_MSG_SPEECH_HELP, r'Help: <<a:gamelinkcharlink%s>%s</a>> %s\n' % (name, sname, formatMLString(msg))) IRC.msg(IRC_CHANNEL_HELP, msg)
def IRCEmote(lastchannel, emote): if CheckMuted(): return channel = IRC_CHANNEL_OFF_TOPIC if lastchannel in ('M', 'MOM'): channel = IRC_CHANNEL_GLOBAL elif lastchannel in ('H', 'HELP'): channel = IRC_CHANNEL_HELP name = IRC.nickname sname = name.replace("_", " ") receiveSpeechText( RPG_MSG_SPEECH_EMOTE, r'<a:gamelinkcharlink%s>%s</a> %s.\n' % (name, sname, formatMLString(emote))) IRC.ctcpMakeQuery(channel, [('ACTION', emote)])
def IRCTell(nick, msg): if CheckMuted(): return receiveSpeechText( RPG_MSG_SPEECH_TOLD, r'You tell <a:gamelinkcharlink%s>%s</a>, \"%s\"\n' % (nick.replace( ' ', '_'), nick, formatMLString(msg).replace("\\", "\\\\"))) IRC.msg(nick, msg) # # Reset responder cycle index to last resonder. # global CURRENT_RESPONDER_INDEX CURRENT_RESPONDER_INDEX = 0
def action(self, user, channel, msg): """This will get called when the bot sees someone do an action.""" suser = user.split('!', 1)[0] user = suser.replace("_", " ") #print user #self.logger.log("* %s %s" % (user, msg)) #IGNORE! from gui.playerSettings import PLAYERSETTINGS if user.upper() in PLAYERSETTINGS.ignored: return #filters! if channel == IRC_CHANNEL_OFF_TOPIC and not OT_ON: return if channel == IRC_CHANNEL_GLOBAL and not GLOBAL_ON: return if channel == IRC_CHANNEL_HELP and not HELP_ON: return msg = msg.replace("\\", "") receiveSpeechText( RPG_MSG_SPEECH_EMOTE, r'<a:gamelinkcharlink%s>%s</a> %s\n' % (suser, user, formatMLString(msg)))
def CmdPoison(args, charIndex): from mud.client.playermind import formatMLString from partyWnd import PARTYWND validSlots = { 'PRIMARY': RPG_SLOT_PRIMARY, 'SECONDARY': RPG_SLOT_SECONDARY, 'OFFHAND': RPG_SLOT_SECONDARY, 'RANGED': RPG_SLOT_RANGED, 'PETPRIMARY': RPG_SLOT_PET_PRIMARY, 'PETSECONDARY': RPG_SLOT_PET_SECONDARY, 'PETRANGED': RPG_SLOT_PET_RANGED } # Check for existance of arguments. if not len(args): receiveGameText( RPG_MSG_GAME_DENIED, "Please specify a slot to apply a poison to and the poison name. Valid slots for poisoning are %s.\\n" % (', '.join(validSlots))) return if not len(args) > 1: receiveGameText( RPG_MSG_GAME_DENIED, "Please specify a poison name after the slot to apply it to.\\n") return # Get current character info. if charIndex == None: charIndex = PARTYWND.curIndex charInfo = PARTYWND.charInfos[charIndex] # First argument should be the slot, get it. slotName = args[0].upper() # Check if this is a valid slot and get slot identifier. applicationSlot = validSlots.get(slotName) if not applicationSlot: receiveGameText( RPG_MSG_GAME_DENIED, "%s is not a valid slot for poison application. Valid slots are %s.\\n" % (args[0], ', '.join(validSlots))) return # Check if the poison target actually exists. weaponCheck = charInfo.ITEMS.get(applicationSlot) if not weaponCheck: if applicationSlot > RPG_SLOT_PET_BEGIN: if not charInfo.RAPIDMOBINFO.PETNAME: receiveGameText( RPG_MSG_GAME_DENIED, "Can't apply poison, %s has no pet.\\n" % (charInfo.NAME)) else: receiveGameText( RPG_MSG_GAME_DENIED, "Can't apply poison, %s's pet has nothing equipped in this slot.\\n" % (charInfo.NAME)) else: receiveGameText( RPG_MSG_GAME_DENIED, "Can't apply poison, %s has nothing equipped in this slot.\\n" % (charInfo.NAME)) return # Join the list with spaces to get the desired poison name. poisonName = formatMLString(' '.join(args[1:]).replace('\\', '\\\\')) poisonNameUpper = poisonName.upper() # Search for an available poison with the desired name in the # chosen characters inventory, exclude cursor item. for itemSlot, itemInfo in charInfo.ITEMS.iteritems(): if itemSlot == RPG_SLOT_CURSOR: continue if itemInfo.NAME.upper() == poisonNameUpper: # Check if this item is actually a poison. if not itemInfo.ISPOISON: receiveGameText(RPG_MSG_GAME_DENIED, "%s is no poison.\\n" % (poisonName)) return PARTYWND.mind.perspective.callRemote("PlayerAvatar", "onApplyPoison", charInfo.CHARID, itemSlot, applicationSlot) break else: receiveGameText( RPG_MSG_GAME_DENIED, "%s has no %s ready for application.\\n" % (charInfo.NAME, poisonName)) return
def CmdCraft(args, charIndex): from mud.client.playermind import formatMLString, GetMoMClientDBConnection from partyWnd import PARTYWND con = GetMoMClientDBConnection() # Check for existance of arguments. if not len(args): receiveGameText(RPG_MSG_GAME_DENIED, "Please specify a recipe name.\\n") return # Join the list with spaces to get the desired recipe name. recipeName = formatMLString(' '.join(args).replace('\\', '\\\\')) # Do a case-insensitive search for the desired recipe name. # Replace ' with '' for SQL apostropha handling..replace("'", "''") result = con.execute( "SELECT id,name,skillname,skill_level,cost_t_p FROM recipe WHERE LOWER(name) = LOWER(\"%s\") LIMIT 1;" % (recipeName)).fetchone() # If the recipe is not found, print message and return. if not result: receiveGameText( RPG_MSG_GAME_DENIED, '%s is not a valid recipe. Please check the recipe name and try again.\\n' % (recipeName)) return # Extract the tuple from the result. recipeID, recipeName, skillname, skill_level, costTP = result # Get current character info if charIndex == None: charIndex = PARTYWND.curIndex cinfo = PARTYWND.charInfos[charIndex] # Check skill requirements charSkillLevel = cinfo.SKILLS.get(skillname, 0) if charSkillLevel < skill_level: receiveGameText( RPG_MSG_GAME_DENIED, "%s requires a %i skill in <a:Skill%s>%s</a>.\\n" % (cinfo.NAME, skill_level, GetTWikiName(skillname), skillname)) return # Check money requirements if PARTYWND.mind.rootInfo.TIN < costTP: receiveGameText( RPG_MSG_GAME_DENIED, "This <a:Skill%s>%s</a> requires %s.\\n" % (GetTWikiName(skillname), skillname, GenMoneyText(costTP))) return # Check for crafting delays. if skillname.upper() in cinfo.SKILLREUSE: TomeGui.receiveGameTextPersonalized( RPG_MSG_GAME_DENIED, "$src is still cleaning $srchis tools,\\n$srche can use the <a:Skill%s>%s</a> skill again in about %i seconds.\\n" % (GetTWikiName(skillname), skillname, cinfo.SKILLREUSE[skillname.upper()]), cinfo) return # Check for the required craft ingredients # (will be done on server again, in case there was a communication issue or hacking attempt) ingredients = dict(( item_proto_id, count ) for item_proto_id, count in con.execute( "SELECT item_proto_id,count FROM recipe_ingredient WHERE recipe_id=%i AND count!=0" % recipeID).fetchall()) for item in cinfo.ITEMS.itervalues(): for item_proto_id, count in ingredients.iteritems(): if item.PROTOID == item_proto_id: sc = item.STACKCOUNT if not sc: sc = 1 ingredients[item_proto_id] -= sc if ingredients[item_proto_id] <= 0: del ingredients[item_proto_id] break # If all required ingredients have been found, send craft command to server. if not len(ingredients): # Schedule sending of actual crafting command. PARTYWND.mind.perspective.callRemote("PlayerAvatar", "onCraft", charIndex, recipeID) return missing = dict( (con.execute("SELECT name FROM item_proto WHERE id=%i LIMIT 1;" % (protoID)).fetchone()[0], count) for protoID, count in ingredients.iteritems()) receiveGameText( RPG_MSG_GAME_DENIED, "%s lacks %s for this craft.\\n" % (cinfo.NAME, ', '.join("%i <a:Item%s>%s</a>" % (count, GetTWikiName(name), name) for name, count in missing.iteritems())))
def CmdMemo(args, charIndex): from mud.client.playermind import formatMLString receiveGameText(RPG_MSG_GAME_YELLOW, "Memo: %s\\n"% \ (formatMLString(' '.join(args).replace('\\','\\\\'))))
def IRCEmote(lastchannel,emote): if CheckMuted(): return channel = IRC_CHANNEL_OFF_TOPIC if lastchannel in ('M','MOM'): channel = IRC_CHANNEL_GLOBAL elif lastchannel in ('H','HELP'): channel = IRC_CHANNEL_HELP name = IRC.nickname sname = name.replace("_"," ") receiveSpeechText(RPG_MSG_SPEECH_EMOTE,r'<a:gamelinkcharlink%s>%s</a> %s.\n'%(name,sname,formatMLString(emote))) IRC.ctcpMakeQuery(channel, [('ACTION', emote)])
def IRCTell(nick,msg): if CheckMuted(): return receiveSpeechText(RPG_MSG_SPEECH_TOLD,r'You tell <a:gamelinkcharlink%s>%s</a>, \"%s\"\n'%(nick.replace(' ','_'),nick,formatMLString(msg).replace("\\","\\\\"))) IRC.msg(nick, msg) # # Reset responder cycle index to last resonder. # global CURRENT_RESPONDER_INDEX CURRENT_RESPONDER_INDEX = 0
def HelpMsg(msg): if not IRC or not len(msg) or CheckMuted(): return name = IRC.nickname sname = name.replace("_"," ") receiveSpeechText(RPG_MSG_SPEECH_HELP,r'Help: <<a:gamelinkcharlink%s>%s</a>> %s\n'%(name,sname,formatMLString(msg))) IRC.msg(IRC_CHANNEL_HELP, msg)
def action(self, user, channel, msg): """This will get called when the bot sees someone do an action.""" suser = user.split('!', 1)[0] user = suser.replace("_"," ") #print user #self.logger.log("* %s %s" % (user, msg)) #IGNORE! from gui.playerSettings import PLAYERSETTINGS if user.upper() in PLAYERSETTINGS.ignored: return #filters! if channel == IRC_CHANNEL_OFF_TOPIC and not OT_ON: return if channel == IRC_CHANNEL_GLOBAL and not GLOBAL_ON: return if channel == IRC_CHANNEL_HELP and not HELP_ON: return msg = msg.replace("\\","") receiveSpeechText(RPG_MSG_SPEECH_EMOTE,r'<a:gamelinkcharlink%s>%s</a> %s\n'%(suser,user,formatMLString(msg)))
def privmsg(self, user, channel, msg): """This will get called when the bot receives a message.""" if not self.live: return if DISCONNECT: self.sendLine("QUIT :%s" % "Errant IRC connection closed") return #filters! if channel == IRC_CHANNEL_OFF_TOPIC and not OT_ON: return if channel == IRC_CHANNEL_GLOBAL and not GLOBAL_ON: return if channel == IRC_CHANNEL_HELP and not HELP_ON: return # # Clean user name and message. # user = user.split('!', 1)[0] userPretty = user.replace("_"," ") msg = msg.replace("\\","") msg = formatMLString(msg) #ignores from gui.playerSettings import PLAYERSETTINGS if userPretty.upper() in PLAYERSETTINGS.ignored: return if channel.upper() == self.nickname.upper(): # # Check if chat window needs opened. # try: if int(TGEGetGlobal("$pref::gameplay::OpenChatOnTells")): TGECall("PushChatGui") except: TGESetGlobal("$pref::gameplay::OpenChatOnTells", 0) # # Prin tht received message to the player. # receiveSpeechText(RPG_MSG_SPEECH_TELL,r'<a:gamelinkcharlink%s>%s</a> tells you, \"%s\"\n'%(user,userPretty,msg)) # # If it was a /tell and the player is afk, send an auto response. # if PLAYER_IS_AWAY: # # Do not respond with afk message when: # - MoM sent the tell. # - The player sent a tell to his/herself. # - Received message was an afk response. # userUpper = user.upper() if "MOM" != userUpper and channel.upper() != userUpper and not msg.startswith(DEFAULT_AWAY_MSG) and not msg.startswith(CUSTOM_AWAY_PREFIX): receiveSpeechText(RPG_MSG_SPEECH_TOLD, r'You tell <a:gamelinkcharlink%s>%s</a>, \"%s\"\n' % (user,userPretty,formatMLString(AWAY_MSG))) self.msg(user, AWAY_MSG) # # Add the user to the response list. # AddTeller(user) else: if channel == IRC_CHANNEL_GLOBAL: receiveSpeechText(RPG_MSG_SPEECH_GLOBAL,r'MoM: <<a:gamelinkcharlink%s>%s</a>> %s\n'%(user,userPretty,msg)) elif channel == IRC_CHANNEL_HELP: receiveSpeechText(RPG_MSG_SPEECH_HELP,r'Help: <<a:gamelinkcharlink%s>%s</a>> %s\n'%(user,userPretty,msg)) elif channel == IRC_CHANNEL_OFF_TOPIC: receiveSpeechText(RPG_MSG_SPEECH_OT,r'OT: <<a:gamelinkcharlink%s>%s</a>> %s\n'%(user,userPretty,msg))
def privmsg(self, user, channel, msg): """This will get called when the bot receives a message.""" if not self.live: return if DISCONNECT: self.sendLine("QUIT :%s" % "Errant IRC connection closed") return #filters! if channel == IRC_CHANNEL_OFF_TOPIC and not OT_ON: return if channel == IRC_CHANNEL_GLOBAL and not GLOBAL_ON: return if channel == IRC_CHANNEL_HELP and not HELP_ON: return # # Clean user name and message. # user = user.split('!', 1)[0] userPretty = user.replace("_", " ") msg = msg.replace("\\", "") msg = formatMLString(msg) #ignores from gui.playerSettings import PLAYERSETTINGS if userPretty.upper() in PLAYERSETTINGS.ignored: return if channel.upper() == self.nickname.upper(): # # Check if chat window needs opened. # try: if int(TGEGetGlobal("$pref::gameplay::OpenChatOnTells")): TGECall("PushChatGui") except: TGESetGlobal("$pref::gameplay::OpenChatOnTells", 0) # # Prin tht received message to the player. # receiveSpeechText( RPG_MSG_SPEECH_TELL, r'<a:gamelinkcharlink%s>%s</a> tells you, \"%s\"\n' % (user, userPretty, msg)) # # If it was a /tell and the player is afk, send an auto response. # if PLAYER_IS_AWAY: # # Do not respond with afk message when: # - MoM sent the tell. # - The player sent a tell to his/herself. # - Received message was an afk response. # userUpper = user.upper() if "MOM" != userUpper and channel.upper( ) != userUpper and not msg.startswith( DEFAULT_AWAY_MSG) and not msg.startswith( CUSTOM_AWAY_PREFIX): receiveSpeechText( RPG_MSG_SPEECH_TOLD, r'You tell <a:gamelinkcharlink%s>%s</a>, \"%s\"\n' % (user, userPretty, formatMLString(AWAY_MSG))) self.msg(user, AWAY_MSG) # # Add the user to the response list. # AddTeller(user) else: if channel == IRC_CHANNEL_GLOBAL: receiveSpeechText( RPG_MSG_SPEECH_GLOBAL, r'MoM: <<a:gamelinkcharlink%s>%s</a>> %s\n' % (user, userPretty, msg)) elif channel == IRC_CHANNEL_HELP: receiveSpeechText( RPG_MSG_SPEECH_HELP, r'Help: <<a:gamelinkcharlink%s>%s</a>> %s\n' % (user, userPretty, msg)) elif channel == IRC_CHANNEL_OFF_TOPIC: receiveSpeechText( RPG_MSG_SPEECH_OT, r'OT: <<a:gamelinkcharlink%s>%s</a>> %s\n' % (user, userPretty, msg))