#!/usr/bin/ruby # args: (any order) # updateall=> maj tous les file_Trolls file_* # refresh=> update le cache # profil => affiche le profil # vue => affiche la vue # nozero => vire les trolls en surface # nogogo => vire les gowaps # notrou => vire les trous # tm => trolls+monstres only # split => affiche separement monstres/trolls/lieux # dmax:4 => distmax 4 # from:f => origin at f (first whose "nom (id)" =~ f) # fichier mountycreds.rb: # def mountycreds # ['login', 'passrestreint'] # end require 'mountycreds' require 'libmhsp' class MHElem attr_accessor :d @@lastx = @@lasty = @@lastn = 1 def to_s if @x == @@lastx and @y == @@lasty and @n == @@lastn s = " (#@id)" # "(1) en 000,000 000: ( else s = "(#@d) en %3d,%3d %3d: (#@id)" % [@x, @y, @n] @@lastx = @x @@lasty = @y @@lastn = @n end if @lvl s << ' ' s << ((defined?(@race) and @race) ? @race[0] : 'l.') s << @lvl.to_s end s << " #@nom" if @nom s << " (#@guilde)" if @guilde s end def <=>(other) [:d, :n, :x, :y, :id].each { |f| diff = ((send(f) || 0) <=> (other.send(f) || 0)) return diff unless diff == 0 } (@cat + @nom) <=> (other.cat + other.nom) end end def show_caracs l, p, pr = mountycreds puts MHInfo.get_generic('Caract', l, pr, $timeout) end def show_profil l, p, pr = mountycreds val = MHInfo.get_spprofil(l, pr, $timeout).chomp.split(';') dla = val.delete_at(7) lbl = %w{mat x y n pv pvmax pa datq desq ddeg dreg vue arm mm rm} val.zip(lbl).each { |v, l| puts "%4s: #{v.to_i}" % l } dla =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/ dla_t = Time.mktime($1, $2, $3, $4, $5, $6) delay = (dla_t - Time.now).to_i puts "dla: #{dla} (#{'-' if delay < 0}#{delay.abs/3600}h#{(delay.abs%3600)/60}m#{delay.abs%60})" end def list_trolls l, p, pr = mountycreds v = MHVueSP.new v.update MHInfo.get_spvue(l, pr, $timeout) v.parse v.calc_dist v.cat['TROLLS'].find { |t| t.id.to_s == l or t.nom == l } list = v.cat['TROLLS'].select { |o| o.misc[1] == '0' } dmax = 500 ; list.delete_if { |e| e.d > dmax rescue false } if dmax = ARGV.inject(500) { |a, e| e =~ /dmax(\d+)/ ? $1.to_i : a } lvlmin = 0 ; list.delete_if { |e| e.lvl < lvlmin rescue false } if lvlmin = ARGV.inject(0) { |a, e| e =~ /lvlmin(\d+)/ ? $1.to_i : a } puts list.map { |o| o.id } end def show_vue l, p, pr = mountycreds v = MHVueSP.new v.update MHInfo.get_spvue(l, pr, $timeout) v.parse if src = ARGV.grep(/^from:/).first src = src.split(':', 2)[1] if src.count(',') == 2 src = src.split(',').map { |c| c.to_i } else src = v.cat.values.flatten.find { |t| "#{t.nom} (#{t.id})" =~ /#{src}/i } src = [src.x, src.y, src.n] end elsif src = v.cat['TROLLS'].find { |t| t.id.to_s == l or t.nom == l } src = [src.x, src.y, src.n] end v.calc_dist src v.cat['LIEUX'].delete_if { |e| e.nom =~ /^Trou de M/ } if ARGV.delete 'notrou' v.cat['MONSTRES'].delete_if { |e| e.nom =~ /^Gowap/ } if ARGV.delete 'nogogo' v.cat['TROLLS'].delete_if { |e| e.n == 0 } if ARGV.delete 'nozero' if ARGV.delete 'split' v.cat elsif ARGV.delete 'tm' { 'TROLLMONSTRES' => v.cat['MONSTRES'] + v.cat['TROLLS'] } else { 'ALL' => v.cat.values.flatten } end.each { |k, v| dmax = nil ; v.delete_if { |e| e.d > dmax rescue false } if dmax = ARGV.inject(500) { |a, e| e =~ /dmax:(\d+)/ ? $1.to_i : a } lvlmin = nil ; v.delete_if { |e| e.lvl < lvlmin rescue false } if lvlmin = ARGV.inject(0) { |a, e| e =~ /lvlmin:(\d+)/ ? $1.to_i : a } puts "#{k}:", v.sort, '' unless v.empty? } end def show_lvl max = ARGV.grep(/\d+/).first rescue '20' puts "lvl #{max}: " + (0...max.to_i).inject { |a, l| a + 10 + 10*l }.to_s end def show_px tlvl = ARGV.grep(/t\d+/).first[1..-1].to_i mlvl = ARGV.grep(/m\d+/).first[1..-1].to_i puts "troll lvl #{tlvl} vs lvl #{mlvl} => #{11 + 3*mlvl - 2*tlvl}px" end def show_listes l, p, pr = mountycreds MHInfo.get_splistesvente(l, p, $timeout).each { |l| troll, prix, id, type, poids, nom, magie, descr = l.split(';') puts "#{troll} - #{prix}gg: [#{id}] #{nom} (#{type}, #{poids}) #{magie}".ljust(70) << descr } end def show_bm l, p, pr = mountycreds MHInfo.get_spbm(l, p, $timeout).each { |l| nom, type, effet, duree = l.split(';') puts "#{nom} - #{type} (#{effet}) #{duree} tours" } end def show_equip nocompo = ARGV.delete('nocompo') l, p, pr = mountycreds MHInfo.get_equip(l, p, $timeout).each { |l| id, equiped, type, idt, nom, qual, carac, poids = l.chomp.split(';') next if type.downcase == 'composant' and nocompo puts "[#{id}] #{"eq#{equiped} " if equiped != '0'}#{nom} #{qual} - #{carac} #{poids}#{'mn' if idt != '0'}" } end begin $timeout = 4*3600 $timeout = 0 if ARGV.delete('update') or ARGV.delete('refresh') $timeout = 24*3600*7 if ARGV.delete 'norefresh' MHInfo.update_cache if ARGV.delete 'updateall' show_vue if ARGV.delete 'vue' list_trolls if ARGV.delete 'listtrolls' show_profil if ARGV.delete 'profil' show_lvl if ARGV.delete 'level' show_px if ARGV.delete 'px' show_caracs if ARGV.delete 'caracs' show_listes if ARGV.delete 'listes' show_bm if ARGV.delete 'bm' show_equip if ARGV.delete 'equip' ARGV.delete_if { |a| a.include? ':' } # raise "argument inconnu" unless ARGV.empty? rescue Object => e puts "Erreur: #{e.class} #{e} #{e.message}", e.backtrace puts "Usage: ./mh_sp.rb updateall | vue [update] | profil [update] | level [] | px m t" end