Glavenfyre
02-07-2011, 03:47 PM
Someone wanted a cman calculator on lnet the other day. I didn't write the whole calculator because I don't feel like working with gtk right now, but I did write a small script to parse the all of the cman info into a giant hash. Here it is if anyone can make use of it.
Here's a sample of echo cmans["Combat Movement"].inspect:
{:hostile=>"No", :stam=>"None.", :reqs=>"None", :cmp=>{"1"=>{"Squares"=>"2", "Semis"=>"3", "Pures"=>"4"}, "2"=>{"Squares"=>"3", "Semis"=>"4", "Pures"=>"6"}, "3"=>{"Squares"=>"4", "Semis"=>"6", "Pures"=>"8"}, "4"=>{"Squares"=>"5", "Semis"=>"7", "Pures"=>"10"}, "5"=>{"Squares"=>"6", "Semis"=>"9", "Pures"=>"12"}}, :desc=>"+2 per rank to physical DS.", :classes=>["Warriors", "Rogues", "Wizards", "Clerics", "Empaths", "Sorcerers", "Rangers", "Bards", "Savants", "Monks", "Paladins"], :prereqs=>"None", :mnem=>"cmovement"}
before_dying {DownstreamHook.remove("cmans")}
cmds = Array.new
cmans = Hash.new
name = String.new
cman_process = proc { |server_string|
if server_string =~ /^Skill Name: ([A-Za-z ]+)/
name = server_string.match(/Skill Name: ([A-Za-z ]+)/).captures.to_s.strip
cmans[name] = Hash.new
nil
elsif server_string =~ /^Mnemonic: ([a-z]+)/
cmans[name][:mnem] = server_string.match(/Mnemonic: ([a-z]+)/).captures.to_s.strip
nil
elsif server_string =~ /^Hostile: (Yes|No)/
cmans[name][:hostile] = server_string.match(/Hostile: (Yes|No)/).captures.to_s.strip
nil
elsif server_string =~ /^Stamina Cost: (.*?)$/
cmans[name][:stam] = server_string.match(/^Stamina Cost: (.*?)$/).captures.to_s.strip
nil
elsif server_string =~ /^Other Requirements: (.*?)$/
cmans[name][:reqs] = server_string.match(/^Other Requirements: (.*?)$/).captures.to_s.strip
nil
elsif server_string =~ /^Available to:/
classes = server_string.scan(/Warriors|Rogues|Wizards|Clerics|Empaths|Sorcerers| Rangers|Bards|Savants|Monks|Paladins/).captures
cmans[name][:classes] = classes
nil
elsif server_string =~ /^ Rank (\d)+/
rank = server_string.match(/^ Rank (\d)+/).captures.to_s
cmans[name][:cmp] ||= Hash.new
cmans[name][:cmp][rank] ||= Hash.new
server_string = server_string.gsub(/\(|\)/, "")
#server_string.scan(/\(Squares\) \d+|\(Pures\) \d+|\(Semis\) \d+/).each {|type|
server_string.scan(/Squares \d+|Pures \d+|Semis \d+/).each {|type|
cmans[name][:cmp][rank][type.split[0]] = type.split[1]
}
nil
elsif server_string =~ /^Prerequisites:|^CMP Cost/
nil
elsif server_string =~ /^ /
cmans[name][:prereqs] = server_string.strip
nil
elsif server_string =~ /^Description: (.*?)$/
cmans[name][:desc] = server_string.match(/^Description: (.*?)$/).captures.to_s.strip
nil
elsif server_string =~ /^Rank/
cmans[name][:desc] += "\r\n#{server_string}"
nil
else
server_string
end
}
t = Time.now.to_f
put "cman list all"
while Time.now.to_f - t <= 1
line = get?
tmp = line.match(/\(([a-z]+)\)/).captures.to_s
cmds.push(tmp) if tmp and tmp != ""
sleep 0.01
end
cmds.each {|cmd|
name = String.new
DownstreamHook.add("cmans", cman_process)
dothistimeout "cman help #{cmd}", 3, /Description:/
DownstreamHook.remove("cmans")
}
Here's a sample of echo cmans["Combat Movement"].inspect:
{:hostile=>"No", :stam=>"None.", :reqs=>"None", :cmp=>{"1"=>{"Squares"=>"2", "Semis"=>"3", "Pures"=>"4"}, "2"=>{"Squares"=>"3", "Semis"=>"4", "Pures"=>"6"}, "3"=>{"Squares"=>"4", "Semis"=>"6", "Pures"=>"8"}, "4"=>{"Squares"=>"5", "Semis"=>"7", "Pures"=>"10"}, "5"=>{"Squares"=>"6", "Semis"=>"9", "Pures"=>"12"}}, :desc=>"+2 per rank to physical DS.", :classes=>["Warriors", "Rogues", "Wizards", "Clerics", "Empaths", "Sorcerers", "Rangers", "Bards", "Savants", "Monks", "Paladins"], :prereqs=>"None", :mnem=>"cmovement"}
before_dying {DownstreamHook.remove("cmans")}
cmds = Array.new
cmans = Hash.new
name = String.new
cman_process = proc { |server_string|
if server_string =~ /^Skill Name: ([A-Za-z ]+)/
name = server_string.match(/Skill Name: ([A-Za-z ]+)/).captures.to_s.strip
cmans[name] = Hash.new
nil
elsif server_string =~ /^Mnemonic: ([a-z]+)/
cmans[name][:mnem] = server_string.match(/Mnemonic: ([a-z]+)/).captures.to_s.strip
nil
elsif server_string =~ /^Hostile: (Yes|No)/
cmans[name][:hostile] = server_string.match(/Hostile: (Yes|No)/).captures.to_s.strip
nil
elsif server_string =~ /^Stamina Cost: (.*?)$/
cmans[name][:stam] = server_string.match(/^Stamina Cost: (.*?)$/).captures.to_s.strip
nil
elsif server_string =~ /^Other Requirements: (.*?)$/
cmans[name][:reqs] = server_string.match(/^Other Requirements: (.*?)$/).captures.to_s.strip
nil
elsif server_string =~ /^Available to:/
classes = server_string.scan(/Warriors|Rogues|Wizards|Clerics|Empaths|Sorcerers| Rangers|Bards|Savants|Monks|Paladins/).captures
cmans[name][:classes] = classes
nil
elsif server_string =~ /^ Rank (\d)+/
rank = server_string.match(/^ Rank (\d)+/).captures.to_s
cmans[name][:cmp] ||= Hash.new
cmans[name][:cmp][rank] ||= Hash.new
server_string = server_string.gsub(/\(|\)/, "")
#server_string.scan(/\(Squares\) \d+|\(Pures\) \d+|\(Semis\) \d+/).each {|type|
server_string.scan(/Squares \d+|Pures \d+|Semis \d+/).each {|type|
cmans[name][:cmp][rank][type.split[0]] = type.split[1]
}
nil
elsif server_string =~ /^Prerequisites:|^CMP Cost/
nil
elsif server_string =~ /^ /
cmans[name][:prereqs] = server_string.strip
nil
elsif server_string =~ /^Description: (.*?)$/
cmans[name][:desc] = server_string.match(/^Description: (.*?)$/).captures.to_s.strip
nil
elsif server_string =~ /^Rank/
cmans[name][:desc] += "\r\n#{server_string}"
nil
else
server_string
end
}
t = Time.now.to_f
put "cman list all"
while Time.now.to_f - t <= 1
line = get?
tmp = line.match(/\(([a-z]+)\)/).captures.to_s
cmds.push(tmp) if tmp and tmp != ""
sleep 0.01
end
cmds.each {|cmd|
name = String.new
DownstreamHook.add("cmans", cman_process)
dothistimeout "cman help #{cmd}", 3, /Description:/
DownstreamHook.remove("cmans")
}