require 'libmhsite' require 'libmhstatus' class Mounty def aa(id=nil) puts "aa #{id.inspect}" ResultCdm[act_target(220, id)] end def abandonner(id=nil, dest = nil) puts "abandonner #{id.inspect} "+ (dest ? "sur #{dest}" : 'au sol') # XXX dest = gogo act_target 15, id end alias abandonne abandonner def add puts "add" act_simple 205 end def ade puts "ade" act_simple 207 end def am(n) puts "accel de #{n}pv" @status[:tried_comp] = true act_target(103, 'ai_NbPV' => n.to_s) { |var| if get_text =~ /maximum de (\d+) PV/ max = [$1.to_i, self[:pv]-1].min var['ai_NbPV'] = max if n.to_i > max end } end alias accel am def ap(id=nil) puts "ap #{id.inspect}" act_target 109, id end def apprend_sortilege(id=nil) puts "apprend #{id.inspect}" act_target 8, id end alias apprendre_sortilege apprend_sortilege alias apprendre_sort apprend_sortilege alias apprend_sort apprend_sortilege def attaque(id=nil) puts "attaque #{id.inspect}" act_target 3, id end alias attaquer attaque def bam puts "bulle antimagie" act_simple 227 end def ballu(id=nil) puts "balluchonner #{id.inspect}" act_target 131, 'ai_IdEquipement' => id end alias balluchonner ballu def bidouille(nom, desc, poids=2, sacr_id=nil, persist=false) raise 'bad poids' if poids > 2000 (puts "poids hacked ! waiting 5s.." ; sleep(5)) if not [2, 10, 23, 45, 90, 160, 350, 1200].include? poids act_target(124, {}) { |var| return if not pd = @http_client.post_allowed.first post pd.url, pd.vars.merge('ai_Choix' => '1') return if not pd = @http_client.post_allowed.first var.update 'ai_Poids' => poids.to_s, 'as_NewName' => nom, 'as_Description' => desc pd.vars.update 'ai_Poids' => poids.to_s var.delete 'ai_Persistante' if not persist pd.vars.delete 'ai_Persistante' if not persist act_filter_option pd, 'ai_IdEquipement', sacr_id.to_i.to_s } end def bidouille_tresor(id, nom, desc) end def bs(id=nil) puts "bs #{id.inspect}" @status[:tried_comp] = true act_target 101, id end def ca puts "contreattaque" act_simple 111 end alias contreattaque ca def camou puts "camouflage" @status[:tried_comp] = true act_simple 104 end alias camouflage camou def cdm(id=nil) puts "cdm #{id.inspect}" c = ResultCdm[act_target(116, id)] if c.reussi and respond_to? :monstre_niveau and (not mn = monstre_niveau("#{c.nom} [#{c.age}]") or mn > c.niveau[1] or mn < c.niveau[0]) @monstre_cache["#{c.nom} [#{c.age}]"] = (c.niveau[0] + c.niveau[1]) / 2 save_monstre_cache end c end def cdb(id=nil) puts "cdb #{id.inspect}" act_target 108, id end def charge(id=nil) puts "charge #{id.inspect}" act_target 114, id end alias charger charge def concentration(npa = self[:pa]) puts "concentration de #{npa} pa" act_target 24, 'ai_CoutPA' => npa end alias concentre concentration alias concentrer concentration # sur un lieu, 2PA def creuser puts "creuse" act_simple 503 end alias fouiller creuser def decamouflage puts "decamouflage" act_simple 25 end def decaler_dla(nr) puts "decalage de dla de #{nr} minutes" act_target 23, 'ai_NbMinutes' => nr end def desequipe(id) puts "desequipe #{id.inspect}" equipement nil, false pd = @http_client.post_allowed.first return if not act_filter_option(pd, 'ai_IDObjet', id) pd.vars['as_Action'] = "D\xe9s\xe9quiper" post pd.url, pd.vars pd = @http_client.post_allowed.first post pd.url, pd.vars.merge('ai_IdTarget' => '0') ans = ResultCombat.new get_text, self ans if get_confirm end alias desequiper desequipe # donne npx (total) aux trolls de la liste def don_px(npx, trolls) npx = @status[:pxr] if npx == :all troll, npx = npx, troll if npx.kind_of? ::Array or (not trolls.kind_of? ::Array and npx.to_i > 300 and npx.to_i > troll.to_i) trolls = [trolls] if not trolls.kind_of? ::Array trolls.delete_if { |t| t.to_i == self[:mat] } npx /= trolls.length+1 puts "don de #{npx}px chacun aux troll #{trolls*' + '} + self" use_action 9 @http_client.get_url_allowed << '/mountyhall/MH_Play/Actions/Play_a_DonPX.php' get('Actions/Play_a_DonPX.php') trolls.each { |t| pd = @http_client.post_allowed.first pd.vars.delete_if { |k, v| v.to_s =~ /Changer la R|Faire le DON/i } post pd.url, pd.vars.merge('ai_AddTroll' => t.to_s) } pd = @http_client.post_allowed.first if npx != pd.vars['ai_nbPx'].to_i pd.vars.delete_if { |k, v| v.to_s =~ /Ajouter|Faire le DON/i } post pd.url, pd.vars.merge('ai_nbPx' => npx.to_s) pd = @http_client.post_allowed.first end pd.vars.delete_if { |k, v| v.to_s =~ /Ajouter|Changer la R/i } post pd.url, pd.vars # confirm pd = @http_client.post_allowed.first post pd.url, pd.vars show get_confirm end def don_gg(ngg=nil, troll=nil) troll, ngg = ngg, troll if ngg.to_i > 20000 and ngg.to_i > troll.to_i puts "don de #{ngg}gg au troll #{troll}" act_target 26, 'ai_GGToGive' => ngg, 'ai_TrollToSend' => troll end def equipe(id) puts "equiper #{id.inspect}" equipement nil, false pd = @http_client.post_allowed.first post pd.url, pd.vars.merge('as_Action' => 'Equiper', 'ai_IDObjet' => id.to_s) if not pd = @http_client.post_allowed.first show return end act_filter_option pd, 'ai_IdTarget', id post pd.url, pd.vars ans = ResultCombat.new get_text, self ans if get_confirm end alias equiper equipe def entrainement puts "entrainement" act_simple 5 end def enterre(id=nil) puts "enterre #{id.inspect}" act_target 35, id end alias enterrer enterre def frenesie(id=nil) puts "frenesie #{id.inspect}" act_target 107, id end def goinfre(id=nil) puts "goinfre #{id.inspect}" act_target 16, id end alias goinfrer goinfre def hurle(id=nil) puts "hurle sur #{id.inspect}" act_target 117, id end alias hurler hurle alias he hurle def hypno(id=nil) puts "hypno #{id.inspect}" @status[:tried_sort] = true act_target 202, id end def idt(id=nil) puts "identification de #{id.inspect}" act_target 210, id end def idc(id=nil) puts "id du champi #{id.inspect}" act_target 105, id end def insulte(id=nil) puts "insulte #{id.inspect}" act_target 118, id end alias insulter insulte def invi puts "invisibilite" act_simple 215 end def ldp(what=nil, who=nil) puts "ldp #{what} sur #{who}" act_target 123, 'ai_IdTarget' => who, 'ai_IdEquipement' => what end alias lancer ldp def levite puts "levite" act_simple 233 end alias levitation levite def marquage(target=nil, nom=nil) puts "marquage #{target.inspect} -> #{nom}" act_target 137, 'ai_IdTarget' => target, 'as_Pseudo' => nom end alias marquer marquage alias marque marquage def melange(p1=nil, p2=nil, compo=nil) puts "melange #{p1}+#{p2} #{compo}" h = { 'ai_IDPotion1' => p1, 'ai_IDPotion2' => p2 } h['ai_IDCompo'] = compo if compo act_target(125, h) end alias melanger melange # action: Rechercher/Miner def miner(action, minerai) mi = case minerai.to_s.downcase when 'k', /^ki/; 1 when 'o', /^obs/; 2 when 'w', /^wh?o/; 3 when 'f', /^flas/; 4 when 'm', /^mit/; 5 when 'ps', 'pds', /sang/; 6 when 'r', /cherche/, /miner/; return miner(minerai, action) else raise 'bad minerai' end act = case action.to_s.downcase when /m/; 'Miner' when 'r', /ch/; 'Rechercher' else raise 'bad action' end puts "miner: #{act} #{{1=>'kibrille', 2=>'obsidienne', 3=>'woeepaah', 4=>'flaaschy', 5=>'mithril', 6=>'pierre de sang'}[mi]}" act_target 129, 'as_TypeAction' => act, 'ai_IdTarget' => mi.to_s end # necro [list of compo id] / necro 'monstre regex' # with re, list = petit_equipement.find_all { monstre =~ re and not ballu }.randomize # then each necro location is filled with the first matching id from list (no match => empty slot) def necro(list=nil) if list.kind_of? String list = petit_equipement.map { |id, cp, mt, ql, pos, supl| id.to_i if mt =~ /#{list}/i and not supl =~ /balluchon/i }.compact.sort_by { rand } end list.map! { |l| l.to_s } puts "necromancie #{list.inspect}" act_target(133, {}) { |v| return if not pd = @http_client.post_allowed.first (1..4).each { |i| v["ai_IdCompo#{i}"] = ((list & pd.vars["ai_IdCompo#{i}"]).first || '') } if v.values.find_all { |vv| not vv.empty? }.length < 2 puts "need more compos" break end p v ; sleep 2 } end alias necromancie necro def piege(type='feu') puts "piege" if not type = { 'feu' => 1 }[type] puts "bad piege type" return end #act_simple 115 act_target 115, type end def pistage(mat, type='troll') puts "pistage du #{type} #{mat}" act_target 121, 'ai_IDTarget' => mat, 'as_TypeTarget' => type.to_s.capitalize end alias pister pistage def plante(id=nil) puts "plante #{id.inspect}" act_target 135, 'ai_IDChampi' => id end alias planter plante def projo(id=nil) puts "projectile magique #{id.inspect}" @status[:tried_sort] = true act_target 201, id end def projection(id=nil) puts "projection de #{id.inspect}" act_target 221, id end def ra puts "ra" @status[:tried_comp] = true act_simple 102 end def rafale(id=nil) puts "rafale #{id.inspect}" @status[:tried_sort] = true act_target 204, id end # -1 => raflage def ramasser(id=nil) puts "ramasser #{id.inspect}" act_target 4, id end alias ramasse ramasser def ramasser_champi(id=nil) puts "ramasser champi #{id.inspect}" act_target 7, 'ai_IdChamp' => id end alias ramasse_champi ramasser_champi alias cueillir ramasser_champi alias cueille cueillir def reparation(target, outil='1', sacro='.') puts "repare" act_target(140, 'ai_Choix' => outil, 'ai_Choix2' => target) { |var| pd = @http_client.post_allowed.first var.each { |fld, val| case ret = act_filter_option(pd, fld, val) when ::Array, nil; return ret end } post pd.url, pd.vars var.replace 'ai_IdMateriaux' => sacro } end alias reparer reparation alias repare reparation def retraite(dir='H') puts "retraite" # Nohrdikan oRhykan Mydikan oXhykan Haut Bas dir = dir.upcase dir = dir.reverse if dir[0] == ?+ or dir[0] == ?- dir[0] = ?Z if dir[1] and dir[0] == ?N dir = {'X+' => 'R', 'X-' => 'X', 'Y+' => 'N', 'Y-' => 'M', 'Z+' => 'H', 'Z-' => 'B'}[dir] || dir act_target 138, 'as_direction' => dir end def rotobaffe(tg='.') puts "roto" act_target 142, tg end def sacro(tg='.', pv=20) puts "sacro" act_target 217, 'ai_IDTarget' => tg, 'ai_NbPV' => pv end alias sacrifice sacro def telek(id=nil, x=:ramasser, y=nil) puts "telek #{id.inspect}" act_target(224, {}) { |var| return if not pd = @http_client.post_allowed.first case ret = act_filter_option(pd, 'ai_IdTarget', id) when nil, ::Array; return ret end post pd.url, pd.vars return if not pd = @http_client.post_allowed.first pos = pd.vars['as_NewPos'] case x when :ramasser myx, myy = self[:x], self[:y] if (pos & ["#{myx-1}##{myy}", "#{myx+1}##{myy}", "#{myx}##{myy-1}", "#{myx}##{myy+1}"]).length >= 2 pd.vars.delete 'as_NewPos' var.update 'ab_PickUp' => 1 else x, y = myx, myy pos = pos.sort_by { |pstr| px, py = pstr.split('#').map { |i| i.to_i } (px-x)*(px-x) + (py-y)*(py-y) }.first var.update 'as_NewPos' => pos end when :rand pos = pos[rand(pos.length)] var.update 'as_NewPos' => pos when :force # y = 'x#y' var.update 'as_NewPos' => y else pos = pos.sort_by { |pstr| px, py = pstr.split('#').map { |i| i.to_i } (px-x)*(px-x) + (py-y)*(py-y) }.first var.update 'as_NewPos' => pos end } end def tp(x=nil, y=nil, z=nil) x, y, z = x if x.kind_of? Array act_target(213, {}) { |var| if get_text.split.join(' ') !~ /X .* Entre (-?\d+) et (-?\d+) Y .* Entre (-?\d+) et (-?\d+) N .* Entre (-?\d+) et (-?\d+)/i show return end xmin, xmax, ymin, ymax, zmin, zmax = $~.captures.map { |i| i.to_i } x = [xmax, [x, xmin].max].min y = [ymax, [y, ymin].max].min z = [zmax, [z, zmin].max].min if z > -73 and dist_to_direct([56, 24, z], [x, y, z]) <= 12 puts "tp divert grostrou [#{x} #{y} #{z}]" if (x-56).abs > (y-24).abs x = [42, 70].sort_by { |v| (x > 56) ? -v : v }.find { |v| xmin <= v and v <= xmax } else y = [10, 38].sort_by { |v| (y > 24) ? -v : v }.find { |v| ymin <= v and v <= ymax } end end puts "tp -> [#{x} #{y} #{z}]" var.update 'ai_OrigineX' => x, 'ai_OrigineY' => y, 'ai_OrigineN' => z } end def trolligion(which=:chasse) which = [:mundi, :feu, :froid, :hum, :manger, :blabla, :sombre, :archange, :mouche, :lombric, :chasse, :ragnarok].index(which) || which act_target(40, which) end def use(what=nil, who=nil) puts "use #{what} sur #{who}" act_target 11, 'ai_IdTarget' => who, 'ai_IdEquipement' => what end alias utiliser use def va puts "vision accrue" act_simple 222 end def vampi(id=nil) puts "vampirisme #{id.inspect}" @status[:tried_sort] = true act_target 203, id end def vl(x=nil, y=nil, z=nil) x, y, z = x if x.kind_of? Array and x.length == 3 puts "vl [#{x} #{y} #{z}]" @http_client.cache['/mountyhall/MH_Play/Actions/Play_a_SortResult.php'] = '' ans = act_target 209, 'ai_OrigineX' => x, 'ai_OrigineY' => y, 'ai_OrigineN' => z if ans and ans.reussi v = Vue.new @http_client.cache['/mountyhall/MH_Play/Actions/Play_a_SortResult.php'].each_table { |pos, value| if pos.length == 4 and pos[0, 3] == [[1, 2, 1], [1, 1, 1], [2, 1, 1]] v.feed([[1, 2, 1], [1, 1, 1], [pos[3][0]+3, pos[3][1], pos[3][2]]], value) end } v.monstres.each { |e| e.niveau = monstre_niveau(e.nom) } if respond_to? :monstre_niveau class << ans ; attr_accessor :vue ; end ans.vue = v puts v end ans end def vlc(x=nil, y=nil, z=nil) x, y, z = x if x.kind_of? Array and x.length == 3 puts "vlc [#{x} #{y} #{z}]" if not x ans = act_simple(223) { pd = @http_client.post_allowed.first post pd.url, pd.vars.merge('ai_Choix' => 1) } if ans and ans.reussi v = self[:vue] pvlc = v>34 ? 5 : v>21 ? 4 : v>11 ? 3 : v>5 ? 2 : 1 puts vue(pvlc, 1) end return end @http_client.cache['/mountyhall/MH_Play/Actions/Play_a_SortResult.php'] = '' ans = act_target(223, 'ai_OrigineX' => x, 'ai_OrigineY' => y, 'ai_OrigineN' => z) { pd = @http_client.post_allowed.first post pd.url, pd.vars.merge('ai_Choix' => 2) } if ans and ans.reussi v = Vue.new @http_client.cache['/mountyhall/MH_Play/Actions/Play_a_SortResult.php'].each_table { |pos, value| if pos.length == 5 and pos[0, 4] == [[1, 2, 1], [1, 1, 1], [2, 1, 1], [1, 2, 1]] v.feed([[1, 2, 1], [1, 1, 1], [pos[4][0]+3, pos[4][1], pos[4][2]]], value) end } v.monstres.each { |e| e.niveau = monstre_niveau(e.nom) } if respond_to? :monstre_niveau class << ans ; attr_accessor :vue ; end ans.vue = v puts v end ans end # prix = false to remove def vendre(id=1, prix=100, want_show=true) pd = @http_client.post_allowed.first # check curpage if not pd or not pd.vars['ai_AddEquip'] equipement nil, false @http_client.get_url_allowed << '/mountyhall/MH_Play/Liste_Vente/ListeVente_liste.php' p = get '/mountyhall/MH_Play/Liste_Vente/ListeVente_liste.php' p = get p.parse('a').find { |e| e['href'] =~ /ListeVente_view/ }['href'] show p, true if want_show pd = @http_client.post_allowed.first end if prix return if not act_filter_option pd, 'ai_AddEquip', id puts "vente en liste de #{id.inspect} a #{prix.inspect}gg" post pd.url, pd.vars.merge('ai_Prix' => prix.to_s) else ids = pd.vars.keys id = ids.find { |i| i == "as_Select_#{id}" } || ids.find { |i| i =~ /as_Select_.*#{id}/ } return if not id puts "vire #{id.inspect} de la liste" post pd.url, id => '1', 'as_Action' => "Enlever les tr\xe9sors s\xe9lectionn\xe9s", 'ai_Prix' => '10000', 'ai_IdTarget' => pd.vars['ai_IdTarget'] end show if want_show end alias vend vendre def acheter(troll, list=nil) list = [list] if list and not list.kind_of? Array equipement nil, false go = false get("/mountyhall/MH_Play/Liste_Vente/ListeVente_liste.php").parse.each { |e| next if e.type != 'a' break go = e['href'] if go go = true if e['href'].include? troll.to_s } if go and go != true get go if not list show else pd = @http_client.post_allowed.first pd.vars.delete_if { |k, v| e = k[/as_Select_(\d+)/, 1] and not list.find { |l| e =~ /#{l}/ } } post pd.url, pd.vars ans = ResultCombat.new get_text, self ans if get_confirm end end end alias achat acheter def nommer_mouche(id, nom) mouches vars = {} url = nil get("Mouches/Play_m_rename.php?ai_IDMouche=#{id}").parse.each { |e| case e.type when 'input'; vars[e['name']] = e['value'] when 'form'; url = e['action'] end } get url + '?' + vars.merge('as_Nom'=> nom).map { |k, v| "#{HttpServer.urlenc k}=#{HttpServer.urlenc v}" }.join('&') end # deplacement def pre_move(use_de = false) d "get #{use_de ? 'DE' : 'move'} options" use_action(use_de ? 112 : 1) rescue use_action(1) return if not pd = @http_client.post_allowed.first %w[X Y N].map { |dir| pd.vars["ai_Depl#{dir}"].map { |d| d.to_i } } end def do_move_rel(dx, dy, dn=0) d "move_rel #{dx} #{dy} #{dn}" return if [dx, dy, dn] == [0, 0, 0] pd = @http_client.post_allowed.first post pd.url, pd.vars.merge('ai_DeplX' => dx.to_s, 'ai_DeplY' => dy.to_s, 'ai_DeplN' => dn.to_s) text = get_text ans = ResultCombat.new text, self if text =~ /vous avez .*t.* tu.* par cet effet/i puts "!!! Tu\xe9 par un piege !!! - relogging in" get_confirm logout rescue nil login else ans if get_confirm end end # helpers def act_simple(actnr) use_action actnr if not pd = @http_client.post_allowed.first show return end yield if block_given? get_confirm ans = ResultCombat.new get_text, self ans if get_confirm end def act_target(actnr, target=nil) use_action actnr if not @http_client.post_allowed.first show return end target = { 'ai_IdTarget' => target } if not target.kind_of? ::Hash yield target if block_given? pd = @http_client.post_allowed.first target.each { |fld, val| case ret = act_filter_option(pd, fld, val) when ::Array, nil; return ret end } post pd.url, pd.vars ans = ResultCombat.new get_text, self ans if get_confirm end def act_filter_option(pd, field, target) raise pd.vars.keys.inspect if not field = pd.vars.keys.find { |k| k.downcase == field.downcase } targets = pd.vars[field] if not targets.kind_of? ::Array if target pd.vars.update field => target.to_s target else [] end elsif not target targets.delete_if { |tg| tg.empty? or tg.to_i == -1 } targets elsif targets.include? target.to_s pd.vars.update field => target.to_s target else targets.delete_if { |tg| (tg.to_i == -1 and not target.to_s.include? '-1') or tg.empty? or tg == '0' } targets = targets.sort_by { rand } targets = targets.grep(/#{target}/) return if targets.empty? if targets.length > 1 puts "multiple possible targets: #{targets.inspect}, will use first in 10s" sleep 10 elsif target == '.' puts targets.first end pd.vars.update field => targets.first targets.first end end class ResultCombat attr_reader :reussi, :target, :att, :esq, :deg, :degnoarm, :sr, :jetsr, :mm, :px, :kill, :text, :rm def initialize(text, m = Mounty.lastinstance) puts text, '' @text = [] text.each { |line| @text << line.chomp case line when /^(?:Mais )?vous avez R.*USSI /i; @reussi = true when /^Vous aves attaqu.*\((\d+)\)/i; @target = $1.to_i when /^Votre Jet d'Attaque est de.* (-?\d+)/; @att = $1.to_i when /^Le Jet d'Esquive de votre adversaire est de.* (-?\d+)/i; @esq = $1.to_i when /^Seuil de R.sistance.* (\d+) %/i; @sr = $1.to_i when /^Jet de R.sistance.* (\d+)/i; @jetsr = $1.to_i when /^Vous avez augment. votre Ma.trise Magique de 1 point/i; @mm = $1.to_i when /^Vous lui avez inflig. (\d+) points de d.g.ts/i; @degnoarm ||= 0 ; @degnoarm += $1.to_i if not text.downcase.include? 'son armure le prot' ; @deg ||= 0 ; @deg += $1.to_i end when /^Son armure le prot.ge et il ne perdra que (\d+) points de vie/i; @deg ||= 0 ; @deg += $1.to_i when /^Vous l'avez TU./i; @kill = true # XXX XXX troll vs monstre XXX monstre feminin ? when /^Pour cette action, vous avez gagn. un total de (\d+) PX/i; @px ||= 0 ; @px += $1.to_i when /vous n'avez gagn.* aucun PX/i; @px ||= 0 # XXX # miner when /Vous .tes en X=(-?\d+), Y=(-?\d+), N=(-?\d+)/; @pos = [$1, $2, $3].map { |e| e.to_i } # miner when /Aucun filon de /; @foo = true end } if @sr if @sr > 50 @rm = m[:mm] * 50 / (100 - @sr) else @rm = @sr * m[:mm] / 50 end end end end class ResultCdm attr_reader :reussi, :nom, :age, :id, :famille, :niveau, :pvmax, :att, :esq, :deg, :reg, :arm, :vue, :marquage, :mm, :rm, :natq, :speed, :vlc, :attdist, :dla, :chargement, :indla, :bm, :pouvoir, :blessure, :pv, :portee_pouvoir, :target_str def set_field(field, val) case field.downcase when 'niveau'; fld = '@niveau' when 'points de vie'; fld = '@pvmax' when /^d.s.*attaque/; fld = '@att' when /^d.s.*esquive/; fld = '@esq' when /^d.s.*d.gat/; fld = '@deg' when /^d.s.*r.g.n.ration/; fld = '@reg' when /armure/; fld = '@arm' when /vue/; fld = '@vue' when /ma.trise magique/; fld = '@mm' when /r.sistance magique/; fld = '@rm' when /nombre d'attaques/; fld = '@natq' when /voir le cach./; fld = '@vlc' when /attaque . distance/; fld = '@attdist' when /dur.* tour/; fld = @dla else case field.downcase when /capacit. sp.ciale/; @pouvoir = val when /blessure/ @blessure = val.to_i @pv = [@pvmax[0] * (100-(@blessure+5)) / 100, (@pvmax[1] * (100-(@blessure-5)) + 99)/ 100] when 'dla'; @indla = val when /vitesse de d.placement/; @speed = val when 'chargement'; @chargement = val when 'bonus malus'; @bm = val when /port.e du pouvoir/; @portee_pouvoir = val else puts "CDM: Ignore unknown field #{field.inspect}" end return end instance_variable_set fld, case val when /entre (\d+) et (\d+)/i; [$1.to_i, $2.to_i] when /inf.rieur . (\d+)/i; [0, $1.to_i] when /sup.rieur . (\d+)/i; [$1.to_i, $1.to_i*2] when /.gal . (\d+)/i; [$1.to_i, $1.to_i] when /Beaucoup/i; [3, 12] when /oui/i; true when /non/i; false when /\d+/; val.to_i else puts "CDM: unknown value #{val.inspect} for field #{field.inspect} (#{fld})" ; val end if fld end def self.[](res) new res.text.join("\n") if res.kind_of? ResultCombat end def initialize(text, sendcdm=true) text.sub!(/\n(?=\d+ %)/m, ' ') @rqtext = [] text.each { |line| case line when /vous avez r.*ussi/i @reussi = true @rqtext << line.chomp when /vous avez RAT.* l'utilisation de ce/i break when /^Le Monstre Cibl. fait partie des : (.+?) \((.+) \[(.+)\] (.+ )?- N.(\d+)\)/i @famille, @nom, @age, @marquage, @id = $1, $2, $3, $4, $5.to_i line.sub(@marquage, '') if @marquage @rqtext << line.chomp when /^(.*?) \((\d+)\) a les caract.*ristiques suivantes/i sendcdm = false @nom, @id = $1, $2.to_i when /^(.*?) ?: (.*)/ fld, val = $1, $2 set_field fld, val line[/.gal . /] = "entre #$1 et " if line =~ /ration.*gal . (\d+)/i # bug cdmcoll + cdm4 @rqtext << line.chomp if fld =~ /Niveau|Points de Vie|Blessure|Attaque|Esquive|D.gat|R.g.n.ration|Armure|Vue|Capacit. sp.ciale/i when /sultat de l'utilisation du sortil|votre jet d'am.*lioration est de|Vous n'avez donc pas r.*liorer ce|Vous avez .*galement gagn.* PX pour la r|il ne vous est plus possible d'am.*liorer ce|Vous avez donc r.*ussi .* am.*liorer ce|Vous vous .*tiez concentr|^$/i else p line end } puts "#{@id};#{(@pv[0]+@pv[1])/2};#{(@esq[0]+@esq[1])*7/4};#{(@rm[0]+@rm[1])/2 if @rm};#{(@arm[0]+@arm[1])/2};" if @reussi send_collector if @reussi and sendcdm end def send_collector puts '-- send to cdmcoll --', @rqtext, '--' if $DEBUG req = "http://mountypedia.free.fr/mz/cdmdispatcher.php?cdm=#{HttpServer.urlenc @rqtext.join("\n")}" cdms = HttpClient.new req cdms.referer = 'http://games.mountyhall.com/mountyhall/MH_Play/Actions/Competences/Play_a_Competence16b.php' # headers = { 'User-agent' => 'Mozilla/4.0 (compatible) Greasemonkey', 'Accept' => 'application/atom+xml,application/xml,text/xml' } a = cdms.get req puts a.content.to_s end end end