LeonMMS

LM² - Forge

Aug 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.33 KB | None | 0 0
  1. #       LM² - Forge
  2. #       Data 29/08/17
  3. #   Criado por LeonMM
  4. # RECIPE[id] = [[it_type, it_id, item_qty],[mat_*_type, mat_*_id, mat_*_qty], ...]
  5. # id = id da receita, contando apartir do zero
  6. # it_type: Tipo de item a ser gerado. *
  7. # it_id: Id do item gerado no database.
  8. # it_qty: Quantidade do item a ser gerado.
  9. # mat_*_type: Tipo de item a ser usado. *
  10. # mat_*_id: Id do item usado no database.
  11. # mat_*_qty: Quantidade necessária para usar.
  12. # * = 0 para itens, 1 para armas, 2 para armaduras.
  13. # Para adicionar mais requisitos, basta adicionar uma virgula
  14. #após, e colocar mais um conjunto dentro de chaves, no máximo 4
  15. #itens podem ser usados.
  16. module LMM_Forge
  17.   WTITLE = "Forja"
  18.   CREATE = "Forjar"
  19.  
  20.   RECIPES = []
  21.   RECIPES[0] = [[1, 1, 3], [0, 3, 2], [1, 4, 2]]              
  22.   RECIPES[1] = [[0, 5, 1], [0, 4, 3]]
  23.   RECIPES[2] = [[0, 13, 1], [0, 13, 2], [0, 12, 2], [0, 11, 1]]
  24.   RECIPES[3] = [[0, 25, 1], [0, 25, 2], [0, 25, 2], [0, 25, 1], [0, 25, 2]]
  25.   RECIPES[4] = [[0, 2, 1], [0, 1, 3]]
  26.   RECIPES[5] = [[0, 7, 1], [0, 1, 3], [0, 4, 3]]
  27.   RECIPES[6] = [[0, 2, 1], [0, 1, 3]]
  28.  
  29.   MAT_X_POS = [7,7,82,82]
  30.   MAT_Y_POS = [55,91,55,91]
  31.  
  32.   NCOLOR = Color.new(195,0,0)
  33.   PCOLOR = Color.new(0,195,0)
  34. end
  35. # Janela de Forja
  36. class Forge_Window < Window_Base
  37.   include LMM_Forge
  38.   def initialize
  39.     super(480, 125, 182, 152)
  40.     self.contents = Bitmap.new(width - 32, height - 32)
  41.     self.visible = self.active = false
  42.     draw_title(WTITLE)
  43.     draw_help
  44.     @create_bt = Button.new(self, 102, 25, CREATE) { create }
  45.     #self.contents.font.size = 10
  46.     @bg = RPG::Cache.picture('Crafting')
  47.     @dragable = true
  48.     @closable = true
  49.   end
  50.   def trigger
  51.     super
  52.     $windows[:forge_list].trigger
  53.   end
  54.   def on_close
  55.     super
  56.     $windows[:forge_list].on_close
  57.   end
  58.   def refresh
  59.     self.contents.clear
  60.     recipe = RECIPES[$windows[:forge_list].recipeS]
  61.     self.contents.font.color = normal_color
  62.     self.contents.blt(0, 0, @bg, Rect.new(0, 0, @bg.width, @bg.height))
  63.     recicon = RPG::Cache.icon(help_return(recipe,0).icon_name)
  64.     self.contents.blt(7,7, recicon, Rect.new(0, 0, 24, 24), 255)
  65.     desc = help_return(recipe,0).name
  66.     self.contents.draw_text(34, 12, 150,16, " X "+ recipe[0][2].to_s)
  67.     self.contents.draw_text(7, 32, 150,16, desc)
  68.     self.contents.font.color = check_ing ? PCOLOR : NCOLOR
  69.     check_ing ? @create_bt.show : @create_bt.hide
  70.     for i in 1..recipe.size-1
  71.       recicon = RPG::Cache.icon(help_return(recipe,i).icon_name)
  72.       self.contents.blt(MAT_X_POS[i-1],MAT_Y_POS[i-1], recicon, Rect.new(0, 0, 24, 24), 255)
  73.       text = "#{number_return(recipe,i)} / #{recipe[i][2].to_s} "
  74.       self.contents.draw_text(MAT_X_POS[i-1]+26,MAT_Y_POS[i-1], 48, 20, text,1)          
  75.     end      
  76.   end
  77.   def update
  78.     super
  79.     create_help if in_area?(0,16)
  80.   end
  81.   def create_help
  82.     recipel = RECIPES[$windows[:forge_list].recipeS]
  83.     if in_area?(21, 21, 26, 26) and $mouse.object == nil
  84.       show_help(help_return(recipel,0))
  85.     elsif in_area?(21, 70, 26, 26) and recipel.size > 1 and $mouse.object == nil
  86.       show_help(help_return(recipel,1))
  87.     elsif in_area?(21, 107, 26, 26) and recipel.size > 2 and $mouse.object == nil
  88.       show_help(help_return(recipel,2))
  89.     elsif in_area?(97, 70, 26, 26) and recipel.size > 3 and $mouse.object == nil
  90.       show_help(help_return(recipel,3))
  91.     elsif in_area?(97, 107, 26, 26) and recipel.size > 4 and $mouse.object == nil
  92.       show_help(help_return(recipel,4))
  93.     else
  94.       hide_help
  95.     end
  96.   end
  97.   def create
  98.     recipe = RECIPES[$windows[:forge_list].recipeS]
  99.     case recipe[0][0]
  100.       when 0
  101.         $game_party.gain_item(recipe[0][1], recipe[0][2])
  102.       when 1
  103.         $game_party.gain_weapon(recipe[0][1], recipe[0][2])
  104.       when 2
  105.         $game_party.gain_armor(recipe[0][1], recipe[0][2])
  106.     end
  107.     for i in 1...recipe.size
  108.       case recipe[i][0]
  109.         when 0
  110.           $game_party.lose_item(recipe[i][1], recipe[i][2])                      
  111.         when 1
  112.           $game_party.lose_weapon(recipe[i][1], recipe[i][2])
  113.         when 2
  114.           $game_party.lose_armor(recipe[i][1], recipe[i][2])
  115.       end
  116.     end
  117.     refresh
  118.     $windows[:forge_list].refresh
  119.   end
  120.   def help_return(recipe,pos)
  121.     case recipe[pos][0]
  122.       when 0  
  123.         return $data_items[recipe[pos][1]]
  124.       when 1
  125.         return $data_weapons[recipe[pos][1]]      
  126.       when 2        
  127.         return $data_armors[recipe[pos][1]]    
  128.     end      
  129.   end
  130.   def number_return(recipe,pos)
  131.     case recipe[pos][0]
  132.       when 0  
  133.         return $game_party.item_number(recipe[pos][1])
  134.       when 1
  135.         return $game_party.weapon_number(recipe[pos][1])    
  136.       when 2        
  137.         return $game_party.armor_number(recipe[pos][1])  
  138.     end      
  139.   end  
  140.   def check_ing
  141.     recipe = RECIPES[$windows[:forge_list].recipeS]
  142.     for i in 1..recipe.size-1
  143.       case recipe[i][0]
  144.       when 0
  145.         unless $game_party.item_number(recipe[i][1]) >= recipe[i][2]
  146.           return false
  147.         end  
  148.       when 1
  149.         unless $game_party.weapon_number(recipe[i][1]) >= recipe[i][2]
  150.           return false
  151.         end        
  152.       when 2
  153.         unless $game_party.armor_number(recipe[i][1]) >= recipe[i][2]
  154.           return false
  155.         end        
  156.       end      
  157.     end
  158.     return true
  159.   end  
  160. end
Add Comment
Please, Sign In to add comment