#!/usr/bin/ruby class ElGame def send(msg) # Send the text to the sockets response = $telnet.send_and_rec(msg) print response if !$config.opt["vt102_debug"] # Parse the message $vt102.process(response) response = $vt102.row_text(0) # Check to see if we overflowed to the next line. if $vt102.y == 1 && $vt102.x == $vt102.row_text(1).sub(/\s*/, "").length && $vt102.row_text(1) =~ / --More-- \s* $ /x response += $vt102.row_text(1) end # If we see a --More-- or a (# of #) message, we send spaces and grab the whole message as a large chunk to return. if response.sub!(/ --More-- \s* $ /x, "") or response.sub!(/ \(\d+ of \d+\) \s* $ /x, "") response += send(" ") end # For simplicity, collapse all consecutive whitespace into one space. response.sub!(/\s+/, " ") return response end def update_map() level[@dl].update # Update the current dungeon level with info from the VT102 end def check_botl() bota = $vt102.row_text(22) botb = $vt102.row_text(23) if not bota =~ / St:(\d+) \s+ Dx:(\d+) \s+ Co:(\d+) \s+ In:(\d+) \s+ Wi:(\d+) \s+ Ch:(\d+) \s+ (Lawful|Neutral|Chaotic) \s+ (S:(\d+))? /x raise "Unable to parse the following bota: " + bota end @str = $1 @dex = $2 @con = $3 @int = $4 @wis = $5 @cha = $6 # @align = $7 @score = $9 if $8 if not botb =~ / ( Dlvl:\d+ \s+ | Home \s+ \d+ \s+ | End \s+ Game \s+ ) $:(\d+) \s+ HP:(\d+)\(\d+\) \s+ Pw:(\d+)\(\d+\) \s+ AC:(-?\d+) \s+ ( Xp:\d+\/\d+ \s+ | Exp:\d+ \s+ ) (T:(\d+))? /x raise "Unable to parse the following botb: " + botb end dlvl = $1 @gold = $2 @curhp = $3 @maxhp = $4 @curpw = $5 @maxpw = $6 @ac = $7 exp = $8 @turn = $10 if $9 if not dlvl =~ / Dlvl:(\d+) \s+ | Home \s+ (\d+) \s+ | End \s+ Game \s+ /x raise "Unable to parse the following dlvl string: " + dlvl end if $1 @dl = $1 elsif $2 @dl = @level["QuestPortal"] + $1 else @dl = nil end if not exp =~ / Xp:(\d+)\/(\d+) \s+ | Exp:(\d+) \s+ /x raise "Unable to parse the following exp string: " + exp end if $1 and $2 @xl = $1 @exp = $2 else @xl = $3 @exp = nil end end end if __FILE__ == $0 require "../utils/assert.rb" puts "unit test succeeded" end