DasKyu

Untitled

Feb 16th, 2021
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.61 KB | None | 0 0
  1. class Banner
  2.   attr_reader :name
  3.   attr_reader :rewards
  4.   attr_reader :stars
  5.   attr_reader :bg
  6.   attr_reader :script
  7.   attr_reader :description
  8.  
  9.   def initialize(name, rewards, stars, bg, url, descr)
  10.     @name        = name
  11.     @rewards     = rewards
  12.     @stars       = stars
  13.     @bg          = bg
  14.     @script      = pbDownloadToString(url)
  15.     @description = descr
  16.   end
  17. end
  18.  
  19. class PokemonGlobalMetadata #Añade la variable global gachaCoins
  20.   attr_reader :gachaCoins
  21.   alias gacha_initialize initialize
  22.   def initialize
  23.     gacha_initialize
  24.     @gachaCoins ||= 0
  25.   end
  26.  
  27.   def gachaCoins=(value)
  28.     @gachaCoins ||= 0 if !@gachaCoins
  29.     @gachaCoins = value
  30.   end
  31. end
  32.  
  33. ################################################################################
  34. # MÉTODOS PARA EL GACHA
  35. ################################################################################
  36. def getGachaLineChunks(value,width) #Divide un texto en varias líneas en función de PADX
  37.   regex = [/<[cC].*>/,/<\/[cC].*>/,/<[bB]>/,/<\/[bB]>/,/<[iI]>/,/<\/[iI]>/,
  38.   /<[uU]>/,/<\/[uU]>/,/<[sS]>/,/<\/[sS]>/,/<outln>/,/<\/outln>/,/<outln2>/,
  39.   /<\/outln2>/,/<fn=\d+>/,/<\/fn>/,/<fs=\d+>/,/<\/fs>/,/<[oO]=\d*>/,/<\/[oO]>/,
  40.   /<ac>/,/<\/ac>/,/<al>/,/<\/al>/,/<ar>/,/<\/ar>/]
  41.   bitmap = Bitmap.new(Graphics.width,Graphics.height)
  42.   pbSetSystemFont(bitmap)
  43.   totalwidth = 0 #Anchura total de la línea actual
  44.   count = 0 #Línea actual
  45.  
  46.   #Color, bold, italic, underlined, struck, outline, thickoutline, font,
  47.   #fontsize, opacity, centered, left-centered,righ-centered
  48.   regs=["","","","","","","","","","","","",""]
  49.   ret=[""] #Array con todas las líneas del texto.
  50.  
  51.   value = value.clone
  52.   value.gsub!(/\[Bb]/,"<c2=6546675A>")
  53.   value.gsub!(/\[Rr]/,"<c2=043C675A>")
  54.  
  55.   text = []
  56.   while value[/.*\n/] != nil
  57.     val = value.slice!(/.*\n/)
  58.     text.push(val)
  59.   end
  60.   text.push(value)
  61.  
  62.   #Análisis de todas las palabras del texto línea por línea
  63.   text.each{|line|
  64.     words = line.split
  65.     aux = []
  66.     words.each_index{|i|
  67.       if words[i][/\w+<.*>/] != nil
  68.         val = words[i].slice!(/<.*>/)
  69.         aux.push(words[i])
  70.         aux.push(val)
  71.       elsif words[i][/<.*>\w+/] != nil
  72.         val = words[i].slice!(/<.*>/)
  73.         aux.push(val)
  74.         aux.push(words[i])
  75.       else
  76.         aux.push(words[i])
  77.       end
  78.     }
  79.     words = aux
  80.     init = "" #Expresiones de apertura Ej: <fs=X>
  81.     ending = "" #Expresiones de cierre Ej: </fs>
  82.    
  83.     words.each{|word|
  84.         word+= " " #Añade un espacio entre palabras.
  85.         init = "" #Expresiones de apertura Ej: <fs=X>
  86.         ending = "" #Expresiones de cierre Ej: </fs>
  87.        
  88.         #Detecta comandos especiales y los activa en regs hasta que encuentra
  89.         #el de cierre.
  90.         regex.each_index{|index|
  91.           aux = word.slice!(regex[index])
  92.           if aux != nil
  93.             if index % 2 != 0 #Comando de cierre
  94.               regs[((index+1)/2)-1]=""
  95.               ending += aux
  96.               if index == 14 #</fn>
  97.                 pbSetSystemFont(bitmap)
  98.               elsif index == 3 #</b>
  99.                 bitmap.font.bold = false
  100.               elsif index == 5 #</i>
  101.                 bitmap.font.italic = false
  102.               end
  103.             else #Comando de apertura
  104.               regs[index/2] = aux
  105.               init += aux
  106.               if index == 14 #<fn=X>
  107.                 bitmap.font.name = aux.gsub(/fn=/){""}
  108.               elsif index == 2 #<b>
  109.                 bitmap.font.bold = true
  110.               elsif index == 4 #<i>
  111.                 bitmap.font.italic = true
  112.               end
  113.             end
  114.           end
  115.         }
  116.        
  117.         #En word solo queda la palabra neta sin comandos especiales. Se mide
  118.         #cuanto ocupa en bitmap y se añade a totalwidth. En función de ello
  119.         #se realiza un salto de línea o no.
  120.         wordwidth = bitmap.text_size(word).width
  121.         totalwidth += wordwidth
  122.         if totalwidth > width
  123.           count += 1
  124.           ret.push("")
  125.           regs.each{|reg|
  126.             ret[count]+=reg
  127.           }
  128.           ret[count]+= word + ending
  129.           totalwidth = wordwidth
  130.         else
  131.           ret[count] += (init + word + ending)
  132.         end
  133.       }
  134.       count += 1
  135.       ret.push("")
  136.       regs.each{|reg|
  137.         ret[count]+=reg
  138.         }
  139.       ret[count]+=ending
  140.       totalwidth = 0
  141.     }
  142.   return ret
  143. end
  144.  
  145. def gachaponRead(string)
  146.   while string[/((system)|(Win32API.new)|(eval)|(pbDownloadToString)|(Marshal)|(Zlib))(.*\n*)/]!=nil
  147.     string[/((system)|(Win32API.new)|(eval)|(pbDownloadToString)|(Marshal)|(Zlib))(.*\n*)/] = ""
  148.   end
  149.   eval(string)
  150. end
Advertisement
Add Comment
Please, Sign In to add comment