def loadArea(area: str): global state state.sqlCursor.execute(AREA_BY_NAME, {"area": area}) areaId = state.sqlCursor.fetchone() if areaId is None: tfprint("Area not found in database: {0}".format(area)) return state.sqlCursor.execute(MONSTERS_BY_AREA, {"areaId": areaId.id}) monsters = {} while True: monster = state.sqlCursor.fetchone() if monster is None: break monsters[monster.name] = Monster( monster.id, monster.name, monster.shortname, monster.spells, monster.skills, monster.killcount, monster.wikiexp if monster.killcount == 0 else "{0}k".format(monster.exp), monster.room_id, ) state = state._replace(areaId=areaId.id, area=area, monsters=monsters) tfprint("Loaded {0} monsters for area {1}".format(len(monsters), area))
def setup(): tfeval("/def -mglob -agGL -p10 -q -t'∴party *' bcproxy_party = " + "/python_call party.triggerPartyMsg \%-1") for x in range(1, 5): for y in range(1, 5): tfeval( "/def -i -q -b'{0}' = /python_call party.changeTargetPlace {1} {2}" .format(PLACE_KEYBINDS[y][x], x, y)) tfeval("/def -i -ag -c0 -p20 -mregexp -t`" + "^\\\|(.)(([1-3?])\\\.([1-3?]) )?" # idle, y, x + "([+]?[A-Za-z ]+) " # name {12} + "([a-z]+\\\|?[0-9]?)? +" # state + "([0-9]+)\\\( *([0-9]+)\\\) +" # hp / maxhp + "(([0-9]+)\\\( *([0-9]+)\\\) +" # sp / maxsp + "([0-9]+)\\\( *([0-9]+)\\\)|.+) +" # ep / maxep + "\\\| .+ \\\| .+ \\\|\$" # level + exp + "` party_pss = /python_call party.pssParse " + '{ "idle": "\%P1", "y": "\%P3", "x": "\%P4", ' + '"name": "\%P5", ' + '"state": "\%P6", ' + '"hp": "\%P7", "maxhp": "\%P8", ' + '"spepstring": "\%P9", ' + '"sp": "\%P10", "maxsp": "\%P11", ' + '"ep": "\%P12", "maxep": "\%P13" }' + "") tfeval( "/def -i -F -ag -p20 -msimple -t`" + ",-----------------------------------------------------------------------------." + "` party_pss_start = /python_call party.pssStart") tfeval( "/def -i -F -ag -c0 -p20 -msimple -t`" + "\\\`-----------------------------------------------------------------------------'" + "` party_pss_end = /python_call party.pssEnd") tfprint("Loaded party.py")
def setup(): global state conn = Client(MOBINFO_SOCKET_FILE, "AF_UNIX") sqlConnection = psycopg2.connect("dbname=batmud user=risto") sqlCursor = sqlConnection.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) state = state._replace(conn=conn, sqlConnection=sqlConnection, sqlCursor=sqlCursor) cmds: Sequence[str] = [ "/def -p10 -mglob -t`∴room *` " + "mobinfo_room = /python_call mobinfo.room \$[textencode({-1})]", "/def -p10 -F -mglob -t`" + "spec_skill: You take a close look at * in comparison to yourself." + "` mobinfo_shortname = /python_call mobinfo.shortname \%*", "/def -p10 -F -mglob -t`* is DEAD, R.I.P.` " + "mobinfo_is_dead = /python_call mobinfo.isDead \%-L3", "/def -agGL -msimple -t`" + "Astounding! You can see things no one else can see, such as pk_trigger_starts.`" + " party_kills_start = /python_call mobinfo.pkillsStart", ] # this command is too difficult to get through tfeval as string tfeval("/load ~/bat/bcproxy-tf-scripts/mobinfo.tf") for cmd in cmds: tfprint(cmd) tfeval(cmd) tfprint("Loaded mobinfo.py")
def setup(): cmds: Sequence[str] = [ "/def t = /python_call party.changeTargetName \%*", "/def f = /python_call ginfo.finger \%*", "/def pginfo = /python_call party.ginfo", "/def -i -q -b'^[z' = @cast stop", "/def -i -q -b'^[x' = @party prots", "/def -i -q -b'^[c' = @show effects", "/def -i -q -b'^[ ' = /python_call party.manualPs", "/def -i -q -b'^[v' = /python_call resists.reportLast", "/def key_f2 = @int", "/def key_f3 = @wis", "/def key_f4 = @spr", "/def key_f5 = @asphy", "/def -i -F -msimple -ag -t`You feel your staff touching your mind.` gag_staff_ceremony", "/def -i -F -msimple -ag -t`You surreptitiously conceal your spell casting.` gag_conceal", "/def -i -F -p10 -msimple -ag -t`spec_spell: Power flows from your staff to the spell.` gag_staff_cheapen", "/def -i -F -p10 -msimple -ag -t`spec_spell: Your fine choice of components lowers the effort of the spell.` gag_power_regs", "/def -i -F -p10 -mglob -ag -t`spec_spell: You pull out * which bursts into a zillion technicolour sparkles!` gag_acid", "/def -i -F -p10 -msimple -ag -t`spec_spell: Your knowledge in elemental powers helps you to save the reagent for further use.` gag_reagent_save", ] for cmd in cmds: tfeval(cmd) tfeval("/python_load caster") setupCaster( CATEGORY_BINDS, SPELLS_FOR_CATEGORY, SPELL_BINDS, PARTY_REPORT_SPELLS, PARTY_REPORT_SPELL_TYPES, ) tfprint("Loaded blaster.py")
def setup(): cmds: Sequence[str] = [ "/def t = /python_call party.changeTargetName \%*", "/def f = /python_call ginfo.finger \%*", "/def pginfo = /python_call party.ginfo", "/def -i -q -b'^[z' = @cast stop", "/def -i -q -b'^[x' = @party prots", "/def -i -q -b'^[c' = @show effects", "/def -i -q -b'^[ ' = /python_call party.manualPs", "/def key_f2 = @ch heal", "/def key_f3 = @ch wis", "/def key_f4 = @ch spr", ] for cmd in cmds: tfeval(cmd) tfeval("/python_load caster") setupCaster( CATEGORY_BINDS, SPELLS_FOR_CATEGORY, SPELL_BINDS, PARTY_REPORT_SPELLS, PARTY_REPORT_SPELL_TYPES, ) tfprint("Loaded blaster.py")
def setup(): for i, msg in enumerate(MESSAGES): tfeval("/def -i -F -p10 -msimple -t`{1}` shrine_message_{0}".format( i, msg) + " = /substitute \%* ({0}/{1})".format(i, len(MESSAGES) - 1)) tfprint("Loaded shrine.py")
def toggleManualMinions(s: str): global state if state.manualMinions: tfprint("Manual minions disabled") state = state._replace(manualMinions=False) else: tfprint("Manual minions enabled") state = state._replace(manualMinions=True)
def setup(): CONN.send("testing connection") eval( "/def -mglob -q -p10 -t'chan_party: *' chat_party = /python_call chat.trigger \%-1" ) eval( "/def -mglob -q -p10 -t'chan_tell: *' chat_tell = /python_call chat.trigger \%-1" ) tfprint("Loaded chat.py")
def hidden(s: str): global state country = state.country if state.country is not None else "unknown country" msg = "{0}: hidden, {1}".format(s, country) if state.partyReport: tfeval("@party report {0}".format(msg)) else: tfprint(msg) cleanup()
def end(s: str): global state state = state._replace(background=s) tfeval("/undef ginfo_guild") if state.partyReport: tfeval("@party report {0}".format(toString())) else: tfprint(toString()) cleanup()
def setup(): for i, msg in enumerate(AURAS): tfeval("/def -i -F -p10 -msimple -t`{1}` channeller_supply_{0}".format( i, msg) + " = /substitute \%* ({0}/{1})".format(i, len(AURAS) - 1)) tfeval("/def -i -F -ag -p10 -msimple " + "-t`You take a deep breath and close your eyes.` " + "channeller_gag_supply_start") tfprint("Loaded channeller.py")
def setup(): for i, msg in enumerate(CHARGES): tfeval( "/def -i -F -p10 -msimple -t`{1}` druid_staff_charge_{0}".format(i, msg) + " = /substitute \%* ({0}/{1})".format(i, len(CHARGES) - 1) ) tfeval( "/def -i -F -ag -p10 -msimple " + "-t`spec_spell: You sense power flowing into your Staff of Druids.` " + "druid_charge_staff_done = @ch spr;sensecharge staff" ) tfprint("Loaded druid.py")
def setup(): cmds = [ "/def -i -p10 -c0 -ag -mglob -t`Guild information for *` ginfo_start = /python_call ginfo.start \%-3", "/def -i -p10 -c0 -ag -mglob -t`Background: *` ginfo_end = /python_call ginfo.end \%-1", "/def -i -p10 -c0 -ag -mglob -t`* has chosen to hide their guild information.` ginfo_hidden = /python_call ginfo.hidden \%1", "/def -i -p10 -c0 -ag -mglob -t`No such player (*).` ginfo_no_such_player", "/def -i -p10 -c0 -ag -mglob -t`* does not seem to have any guild information (offline).` ginfo_hidden2 = /python_call ginfo.hidden \%1", "/def ginfo = /python_call ginfo.ginfo \%*", "/def giwho = /python_call ginfo.who \%*", "/def pwho = /python_call ginfo.who party \%*", ] for cmd in cmds: tfeval(cmd) tfprint("Loaded ginfo.py")
def setup(): cmds: Sequence[str] = [ "/def -i -F -p10 -mglob -t`spec_spell: You watch with self-pride as your *` spell_hits = /python_call resists.hits \%-7", "/def -i -F -p10 -c0 -mglob -t`spec_spell: * screams in pain.` resist_scream = /python_call resists.scream \%-L3", "/def -i -F -p10 -c0 -mglob -t`spec_spell: * writhes in agony.` resist_writhe = /python_call resists.writhe \%-L3", "/def -i -F -p10 -c0 -mglob -t`spec_spell: * shudders from the force of the attack.` resist_shudder = /python_call resists.shudder \%-L7", "/def -i -F -p10 -c0 -mglob -t`spec_spell: * grunts from the pain.` resist_grunt = /python_call resists.grunt \%-L4", "/def -i -F -p10 -c0 -mglob -t`spec_spell: * winces a little from the pain.` resist_wince = /python_call resists.wince \%-L6", "/def -i -F -p10 -c0 -mglob -t`spec_spell: * shrugs off the attack.` resist_shrug = /python_call resists.shrug \%-L4", "/def -i -F -p10 -msimple -t`Astounding! You can see things no one else can see, such as pk_trigger_starts.` resist_reset = /python_call resists.reset", ] for cmd in cmds: tfeval(cmd) tfprint("Loaded resists.py")
def end(s: str): global state if state.currentMobInfo is None: return monster = monsterFromIndex(state.currentMobInfo.i) if monster is not None: id = monster.id name = monster.name shortname = state.currentMobInfo.shortname tfprint("Updating monster {0} {1} shortname to {2}".format(id, name, shortname)) state.sqlCursor.execute( MONSTER_SHORTNAME_UPDATE, {"monsterId": id, "shortname": shortname}, ) state.sqlConnection.commit() state = state._replace(currentMobInfo=None, currentLookLines=[])
def insertMonster(name: str): global state # monster not found from area, let's check if it's in db without area if state.areaId is not None and state.area is not None: tfprint( "Adding monster {0} to area {1} {2}".format(name, state.areaId, state.area) ) state.sqlCursor.execute( MONSTER_INSERT, { "areaId": state.areaId, "name": name, "roomId": state.room, }, ) state.sqlConnection.commit() loadArea(state.area)
def setup(): cmds: Sequence[str] = [ "/def -i -agGL -p10 -msimple -t`Dunk dunk` heartbeat = /python_call heartbeat.heartbeat", "/def -i -F -p10 -mregexp -t`" + "^H:(-?[0-9]+)/(-?[0-9]+) \\\[([+-]?[0-9]*)\\\] " + "S:(-?[0-9]+)/(-?[0-9]+) \\\[([+-]?[0-9]*)\\\] " + "E:(-?[0-9]+)/(-?[0-9]+) \\\[([+-]?[0-9]*)\\\] " + "\\\\\$:(-?[0-9]+) \\\[[+-]?[0-9]*\\\] " + "exp:(-?[0-9]+) \\\[[+-]?[0-9]*\\\]\$" + "` sc_update = /python_call heartbeat.tick \%P6", ] for cmd in cmds: tfprint(cmd) tfeval(cmd) tfprint("Loaded heartbeat.py")
def hits(mobAndSpell: str): global state splitted = mobAndSpell.split(" hits ") if len(splitted) == 2: spellname = splitted[0] mobname = splitted[1].strip(".") spell = getSpellByName(spellname) if spell is not None: state = state._replace(previousMob=mobname, previousSpell=spell) tfeval("/edit -c100 resist_scream") tfeval("/edit -c100 resist_writhe") tfeval("/edit -c100 resist_shudder") tfeval("/edit -c100 resist_grunt") tfeval("/edit -c100 resist_wince") tfeval("/edit -c100 resist_shrug") else: tfprint("Unknown resist string: {0}".format(mobAndSpell))
def setup( categoryBinds: CategoryBinds, spellsForCategory: SpellsForCategory, spellBinds: SpellBinds, partyReportSpells: PartyReportSpells, partyReportSpellTypes: PartyReportSpellTypes, ): global state state = state._replace( categoryBinds=categoryBinds, spellsForCategory=spellsForCategory, spellBinds=spellBinds, partyReportSpells=partyReportSpells, partyReportSpellTypes=partyReportSpellTypes, ) cmds: Sequence[str] = [ "/def -i -F -msimple -ag -t`You start chanting.` spell_start = " + "/python_call caster.castStart", "/def -i -F -msimple -agGL -t`∴cast_cancelled` cast_cancelled = " + "/python_call caster.castStop", "/def -i -F -msimple -ag -t`You are done with the chant.` gag_spell_done", "/def -i -F -msimple -ag -t`You skillfully cast the spell with haste.` gag_haste", "/def -i -F -msimple -ag -t`You skillfully cast the spell with greater haste.` gag_ghaste", "/def -i -F -mglob -t`You are now targetting *` set_target = " + "/python_call caster.setTarget \%-4", "/def -i -F -mglob -t`You are now target-healing *` set_target_heal = " + "/python_call caster.setTarget \%-4", ] for cmd in cmds: tfeval(cmd) for key, category, explanation in flatten(state.categoryBinds): tfeval("/def -i -q -b`{0}` = /python_call caster.changeCategory {1}". format(key, category.value)) for key, spellBindId, atTarget in spellBinds: if atTarget: tfeval( "/def -i -q -b`{0}` = /python_call caster.castSpellWithTarget {1}" .format(key, spellBindId)) else: tfeval( "/def -i -q -b`{0}` = /python_call caster.castSpellWithoutTarget {1}" .format(key, spellBindId)) tfprint("Loaded caster.py")
def updateMonster(id: int, name: str): global state # monster not found from area, let's check if it's in db without area if state.areaId is not None and state.area is not None: tfprint( "Updating monster {0} {1} to area {2} {3}".format( id, name, state.areaId, state.area ) ) state.sqlCursor.execute( MONSTER_AREA_UPDATE, { "areaId": state.areaId, "monsterId": id, "name": name, "roomId": state.room, }, ) state.sqlConnection.commit() loadArea(state.area)
def updateExp(s: str): global state s = s.strip("| ") s = s.rstrip("| \n") s = s[5:] # remove timestamp parts = s.split(": ", 1) try: exp = int(parts[0]) name = parts[1] if name in state.monsters: monster = state.monsters[name] state.sqlCursor.execute(KILL_SELECT, {"monsterId": monster.id, "exp": exp}) killExists = state.sqlCursor.fetchone() if killExists is None: state.sqlCursor.execute( KILL_INSERT, {"monsterId": monster.id, "exp": exp} ) state.sqlConnection.commit() tfprint( "Kill added: {0} {1}, {2} exp".format(monster.id, monster.name, exp) ) if monster.shortname is None and state.isDeadShortname is not None: tfprint( "Updating monster {0} {1} shortname to {2}".format( monster.id, name, state.isDeadShortname ) ) state.sqlCursor.execute( MONSTER_SHORTNAME_UPDATE, {"monsterId": monster.id, "shortname": state.isDeadShortname}, ) state = state._replace(isDeadShortname=None, isDeadTimestamp=None) state.sqlConnection.commit() except (ValueError, IndexError): # tf.err("error parsing kill line") return 1
def cons(s: str): global state [i, name] = s.split(" ", 1) try: state = state._replace(currentMobInfo=CurrentMobInfo(int(i), None)) tfeval("@consider {0}".format(name)) except: tfprint(s) tfprint(i) tfprint(name) return
def setup(): for key, direction in WALK_BINDS: eval("/def -i -q -b'{0}' = @{1}".format(key, direction)) tfprint("Loaded walking.py")
def printState(s: str): global state tfprint(str(state))
def setTarget(target: str): global state state = state._replace(target=target[:-1].lower()) tfprint("target {0}".format(state.target))
def castStop(args): global state state = state._replace(currentSpell=None) tfprint("@{Cbgrgb110}@{BCrgb511} ---- CAST STOPPED ---- @{n}")
def castStart(args): global state cur: str = state.currentSpell if state.currentSpell != None else "" tfprint("@{Cbgrgb110}@{BCrgb151} ---- CAST STARTED " + cur + " ---- @{n}")