Advertisement
LeonMMS

LM² - Crafting

Jul 10th, 2017
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.60 KB | None | 0 0
  1. # LM² - Crafting
  2. # Desenvlvido por LeonMM
  3. module LMM_Craft
  4.   #  Instalação:
  5.   # Procure por:
  6.   # $game_player        = Game_Player.new
  7.   # Adicione abaixo este código:
  8.   # $game_craft         = Game_Craft.new
  9.   # Procure por:
  10.   # Marshal.dump($game_player, file)
  11.   # Adicione abaixo este código:
  12.   # Marshal.dump($game_craft, file)
  13.   # Procure por:
  14.   # $game_player        = Marshal.load(file)
  15.   # Adicione abaixo este código:
  16.   # $game_craft         = Marshal.load(file)
  17.   #(Você pode acha-los respectivamente em Scene_Title, Scene_Save
  18.   #e Scene_Load)
  19.   #Quantidade de receitas visíveis na tela.
  20.   RECIPE_VIEW = 8
  21.   #QUANTIDADE DE RECEITAS
  22.   RECIPE_Q = 9
  23.   #  Configuração de Receitas
  24.   # RECIPE[id] = [[it_type, it_id, item_qty],[mat_*_type, mat_*_id, mat_*_qty], ...]
  25.   # id = id da receita, contando apartir do zero
  26.   # it_type: Tipo de item a ser gerado. *
  27.   # it_id: Id do item gerado no database.
  28.   # it_qty: Quantidade do item a ser gerado.
  29.   # mat_*_type: Tipo de item a ser usado. *
  30.   # mat_*_id: Id do item usado no database.
  31.   # mat_*_qty: Quantidade necessária para usar.
  32.   # * = 0 para itens, 1 para armas, 2 para armaduras.
  33.   # Para adicionar mais requisitos, basta adicionar uma virgula
  34.   #após, e colocar mais um conjunto dentro de chaves, no máximo 4
  35.   #itens podem ser usados.
  36.   RECIPES = []
  37.   RECIPES[0] = [[1, 1, 3], [0, 3, 2], [1, 4, 2]]              
  38.   RECIPES[1] = [[0, 10, 1], [0, 13, 2]]
  39.   RECIPES[4] = [[0, 10, 1], [0, 13, 2], [0, 12, 2], [0, 11, 1]]
  40.   RECIPES[8] = [[0, 1, 1], [0, 3, 2], [0, 4, 2], [0, 5, 2], [0, 6, 2]]
  41.   # Alterar a fonte dos textos da janela de requerimentos.
  42.   REQ_FONT = "Franklin Gothic Medium"
  43.   REQ_SIZE = 19
  44.   # Alterar o termo da imagem da receita
  45.   # (Ao lado do termo deve ir o número id da receita: 0,1...)
  46.   REC_TERM = "Recipe_"
  47.   # As imagens devem estar na pasta Window_Craft, dentro da pasta
  48.   #pictures do seu projeto
  49.   # Para ativar alguma receita, deve se usar o código abaixo
  50.   #  $game_craft.recipes[id] = true
  51.   # id = id da receita
  52.   # (Para desativar alguma receita, basta mudar true para false)
  53. end
  54.  
  55. # NÃO EDITE A PARTIR DAQUI SEM CONHECIMENTO PRÉVIO
  56.  
  57. class Game_Craft  
  58.   attr_accessor :recipes
  59.   def initialize
  60.     @recipes = []
  61.     for i in 0..LMM_Craft::RECIPE_Q - 1
  62.       @recipes.push(false)
  63.     end  
  64.   end  
  65. end  
  66.  
  67. class Scene_Crafting
  68.   include LMM_Craft
  69.   def main
  70.     @fundo = Spriteset_Map.new
  71.     @black = Sprite.new
  72.     @black.bitmap = Bitmap.new(640, 480)
  73.     @black.bitmap.fill_rect(Rect.new(0,0,640,480), Color.new(0,0,0,75))
  74.     @black.z = 15
  75.     opt = []
  76.     for i in 0..RECIPE_Q - 1
  77.       opt.push("")
  78.     end  
  79.     @command_window = Window_Command.new(192, opt )
  80.     @command_window.index = 0
  81.     @command_window.visible = false
  82.     @BG = Sprite.new
  83.     @BG.bitmap = RPG::Cache.picture("Window_Craft/Base_window")
  84.     @BG.z = 16    
  85.     @Sel = Sprite.new
  86.     @Sel.bitmap = RPG::Cache.picture("Window_Craft/Marker")
  87.     @Sel.x = 16
  88.     @Sel.y = 55 + (@command_window.index * 39)
  89.     @Sel.z = 17
  90.     @RequireWin = Require_Win.new
  91.     @Confirm = Sprite.new
  92.     if $game_craft.recipes[@command_window.index] == true
  93.       if check_ing
  94.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOn")
  95.       else
  96.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOff")
  97.       end  
  98.     else
  99.       @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmNoR")
  100.     end  
  101.     @Confirm.x = 371
  102.     @Confirm.y = 294
  103.     @Confirm.z = 17
  104.     @Recipes = [Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new]
  105.     for i in 0 .. RECIPE_VIEW - 1
  106.       if $game_craft.recipes[i] == true
  107.         @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/"+REC_TERM+(i).to_s)
  108.       else
  109.         @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/Norecipe")
  110.       end
  111.         @Recipes[i].x = 22
  112.         @Recipes[i].y = 61 + (i * 39)
  113.         @Recipes[i].z = 17
  114.     end
  115.     Graphics.transition
  116.     loop do
  117.       Graphics.update
  118.       Input.update
  119.       update
  120.       if $scene != self
  121.         break
  122.       end
  123.     end
  124.     Graphics.freeze
  125.     @command_window.dispose
  126.     @fundo.dispose
  127.     @black.dispose
  128.     @BG.dispose
  129.     @Sel.dispose
  130.     @RequireWin.dispose
  131.     @Confirm.dispose
  132.     for i in 0 .. @Recipes.size - 1
  133.       @Recipes[i].dispose
  134.     end  
  135.     if $scene.is_a?(Scene_Title)
  136.       Graphics.transition
  137.       Graphics.freeze
  138.     end
  139.   end
  140.  
  141.   def update
  142.     @fundo.update
  143.     @black.update
  144.     @BG.update
  145.     @command_window.update
  146.     @RequireWin.update
  147.     if @command_window.index >= RECIPE_VIEW
  148.       @cmw_in = RECIPE_VIEW - 1
  149.       for i in 0 .. RECIPE_VIEW - 1
  150.         if $game_craft.recipes[@command_window.index - (RECIPE_VIEW - 1) + i] == true
  151.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/"+REC_TERM+(@command_window.index - (RECIPE_VIEW - 1) + i).to_s)
  152.         else
  153.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/Norecipe")
  154.         end
  155.       end      
  156.     else
  157.       @cmw_in = @command_window.index
  158.       for i in 0 .. RECIPE_VIEW - 1
  159.         if $game_craft.recipes[i] == true
  160.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/"+REC_TERM+(i).to_s)
  161.         else
  162.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/Norecipe")
  163.         end
  164.       end        
  165.     end  
  166.     @Sel.y = 55 + (@cmw_in * 39)
  167.     if $game_craft.recipes[@command_window.index] == true
  168.       @RequireWin.rec_id(RECIPES[@command_window.index])
  169.       if check_ing
  170.         update_command
  171.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOn")
  172.       else
  173.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOff")
  174.       end  
  175.     else
  176.       @RequireWin.rec_id(nil)
  177.       @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmNoR")
  178.     end    
  179.     if Input.trigger?(Input::B)
  180.       $game_system.se_play($data_system.cancel_se)
  181.       #Altere aqui caso deseje retornar em outra cena.
  182.       $scene = Scene_Map.new
  183.       return
  184.     end
  185.   end
  186.   def update_command
  187.     if Input.trigger?(Input::C)
  188.       $game_system.se_play($data_system.equip_se)
  189.       case RECIPES[@command_window.index][0][0]
  190.         when 0
  191.           $game_party.gain_item(RECIPES[@command_window.index][0][1], RECIPES[@command_window.index][0][2])
  192.         when 1
  193.           $game_party.gain_weapon(RECIPES[@command_window.index][0][1], RECIPES[@command_window.index][0][2])
  194.         when 2
  195.           $game_party.gain_armor(RECIPES[@command_window.index][0][1], RECIPES[@command_window.index][0][2])
  196.       end
  197.       for i in 1...RECIPES[@command_window.index].size
  198.         case RECIPES[@command_window.index][i][0]
  199.           when 0
  200.             $game_party.lose_item(RECIPES[@command_window.index][i][1], RECIPES[@command_window.index][i][2])                      
  201.           when 1
  202.             $game_party.lose_weapon(RECIPES[@command_window.index][i][1], RECIPES[@command_window.index][i][2])
  203.           when 2
  204.             $game_party.lose_armor(RECIPES[@command_window.index][i][1], RECIPES[@command_window.index][i][2])
  205.         end
  206.       end
  207.     end
  208.   end
  209.   def check_ing
  210.     for i in 1..RECIPES[@command_window.index].size-1
  211.       case RECIPES[@command_window.index][i][0]
  212.       when 0
  213.         unless $game_party.item_number(RECIPES[@command_window.index][i][1]) >= RECIPES[@command_window.index][i][2]
  214.           return false
  215.         end  
  216.       when 1
  217.         unless $game_party.weapon_number(RECIPES[@command_window.index][i][1]) >= RECIPES[@command_window.index][i][2]
  218.           return false
  219.         end        
  220.       when 2
  221.         unless $game_party.armor_number(RECIPES[@command_window.index][i][1]) >= RECIPES[@command_window.index][i][2]
  222.           return false
  223.         end        
  224.       end      
  225.     end
  226.     return true
  227.   end
  228. end
  229.  
  230. class Require_Win < Sprite
  231.   include LMM_Craft
  232.   def initialize
  233.     super
  234.     self.bitmap = Bitmap.new(268,253)
  235.     self.x = 329;self.y = 38;self.z = 18
  236.     @rec_id = nil
  237.     self.bitmap.font.name = REQ_FONT
  238.     self.bitmap.font.size = REQ_SIZE
  239.     self.bitmap.font.color = Color.new(0, 0, 0, 255)    
  240.     update
  241.   end  
  242.   def rec_id(id)
  243.     @rec_id = id
  244.   end  
  245.   def update
  246.     super
  247.     self.bitmap.clear
  248.     if @rec_id != nil
  249.       for i in 1..@rec_id.size-1
  250.         case @rec_id[i][0]
  251.         when 0
  252.           maticon = RPG::Cache.icon($data_items[@rec_id[i][1]].icon_name)
  253.           self.bitmap.blt(6, 97 + ((i - 1) * 42), maticon, Rect.new(0, 0, 24, 24), 255)          
  254.           text = $data_items[@rec_id[i][1]].name
  255.           self.bitmap.draw_text(39, 100+ ((i - 1) * 42), 154, 20, text,0)          
  256.           text2 = "#{@rec_id[i][2].to_s} / #{$game_party.item_number(@rec_id[i][1])}"
  257.           self.bitmap.draw_text(190, 99+ ((i - 1) * 42), 76, 20, text2,1)          
  258.         when 1
  259.           maticon = RPG::Cache.icon($data_weapons[@rec_id[i][1]].icon_name)
  260.           self.bitmap.blt(6, 97 + ((i - 1) * 42), maticon, Rect.new(0, 0, 24, 24), 255)          
  261.           text = $data_weapons[@rec_id[i][1]].name
  262.           self.bitmap.draw_text(39, 100+ ((i - 1) * 42), 154, 20, text,0)          
  263.           text2 = "#{@rec_id[i][2].to_s} / #{$game_party.weapon_number(@rec_id[i][1])}"
  264.           self.bitmap.draw_text(190, 99+ ((i - 1) * 42), 76, 20, text2,1)            
  265.         when 2
  266.           maticon = RPG::Cache.icon($data_armors[@rec_id[i][1]].icon_name)
  267.           self.bitmap.blt(6, 97 + ((i - 1) * 42), maticon, Rect.new(0, 0, 24, 24), 255)          
  268.           text = $data_armors[@rec_id[i][1]].name
  269.           self.bitmap.draw_text(39, 100+ ((i - 1) * 42), 154, 20, text,0)          
  270.           text2 = "#{@rec_id[i][2].to_s} / #{$game_party.armor_number(@rec_id[i][1])}"
  271.           self.bitmap.draw_text(190, 99+ ((i - 1) * 42), 76, 20, text2,1)            
  272.         end
  273.       end
  274.       case @rec_id[0][0]
  275.       when 0  
  276.         resulticon = RPG::Cache.icon($data_items[@rec_id[0][1]].icon_name)
  277.         self.bitmap.blt(13, 11, resulticon, Rect.new(0, 0, 24, 24), 255)
  278.         desc = $data_items[@rec_id[0][1]].name
  279.       when 1
  280.         resulticon = RPG::Cache.icon($data_weapons[@rec_id[0][1]].icon_name)
  281.         self.bitmap.blt(13, 11, resulticon, Rect.new(0, 0, 24, 24), 255)
  282.         desc = $data_weapons[@rec_id[0][1]].name        
  283.       when 2        
  284.         resulticon = RPG::Cache.icon($data_armors[@rec_id[0][1]].icon_name)
  285.         self.bitmap.blt(13, 11, resulticon, Rect.new(0, 0, 24, 24), 255)
  286.         desc = $data_armors[@rec_id[0][1]].name      
  287.       end            
  288.       self.bitmap.draw_text(51, 12, 214,16, desc + (" X "+ @rec_id[0][2].to_s),1)    
  289.     end
  290.   end
  291. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement