; Color runebook: 0x455
; Contkind del rune: WZQC
; Es un tipo MPF
; Poner el contpos 0 0
; Las runas van de 1 a ocho
; las hojas de 1 a 2
;En %MiRuneBook debemos tener el ID de nuestro Libro de Runas
; esto se hace automaticamente en el init.txt


set %KeHoja %1
set %KeRuna %2

set %retryrecall 0

IntentoAbrirRune:
gosub abrirlibro
 for %tmp 1 60
   {
     wait 1
     if #CONTKIND = WZQC
       goto abiertobien
  }
set %retryrecall %retryrecall + 1
; Si no lo conseguimos abrir, mal rollo
if %retryrecall > 3
 {
; Decimos que tire logs
  set  %TiraLogs SI
  exit
 }
goto IntentoAbrirRune

abiertobien:
set %anteriorx #charposx
set %anteriory #charposy
gosub clickruna %KeHoja %KeRuna
wait 17s

if  %anteriorx = #charposx
   {
      if  %anteriory = #charposy
        {
          goto IntentoAbrirRune
        }
    }
;Si llegamos aqui, se supone que hicimos el viaje bien

exit

sub abrirlibro
    set %bcklobjectid   #lobjectid
     set %bcklobjecttype #lobjecttype    
     set #lobjectid      %MiRuneBook
     set #lobjecttype   MPF
     wait 3
     Event Macro %LastObject     
     wait 4
    ; Recuperamos lastobject
     set #lobjectid      %bcklobjectid  
     set #lobjecttype    %bcklobjecttype
return


sub clickruna
;%1 Hoja del libro de runas: 1 o 2
;%2 Numero de la runa dentro de esa pagina: De 1 a 8
;%3,%4 posiciones x e y donde hay ke pinchar

;Para calcular la x:  161*hoja - 32
 set %3 161 * %1
 set %3 %3 - 32
;Para calcular la y:  106*(runa - 1)/7 + 69
 set %4 %2 - 1
 set %4 %4 * 106
 set %4 %4 / 7
 set %4 %4 + 69
 click %3 %4
return

