LeonMMS

LM² - Crafting v2

Aug 21st, 2017
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.98 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.   # Adicone abaixo este código:
  8.   # $game_craft         = Game_Craft.new
  9.   # Procure por:
  10.   # Marshal.dump($game_player, file)
  11.   # Adicone abaixo este código:
  12.   # Marshal.dump($game_craft, file)
  13.   # Procure por:
  14.   # $game_player        = Marshal.load(file)
  15.   # Adicone 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/ Máx 8.
  20.   RECIPE_VIEW = 8
  21.   #QUANTIDADE DE RECEITAS
  22.   RECIPE_Q = 9
  23.   #  Configuração de Receitas
  24.   # RECIPE[id] = [dif , [it_type, it_id, item_qty],[mat_*_type, mat_*_id, mat_*_qty], ...]
  25.   # dif = dificuldade da receita, 0 = fácil, 1 = médio, 2 = difícil
  26.   # id = id da receita, contando apartir do zero
  27.   # it_type: Tipo de item a ser gerado. *
  28.   # it_id: Id do item gerado no database.
  29.   # it_qty: Quantidade do item a ser gerado.
  30.   # mat_*_type: Tipo de item a ser usado. *
  31.   # mat_*_id: Id do item usado no database.
  32.   # mat_*_qty: Quantidade necessária para usar.
  33.   # * = 0 para itens, 1 para armas, 2 para armaduras.
  34.   # Para adicionar mais requisitos, basta adicionar uma vigula
  35.   #após, e colocar mais um conjunto dentro de chaves, no máximo 4
  36.   #itens podem ser usados.
  37.   RECIPES = []
  38.   RECIPES[0] = [0, [1, 1, 3], [0, 3, 2], [1, 4, 2]]              
  39.   RECIPES[1] = [1, [0, 10, 1], [0, 13, 2]]
  40.   RECIPES[4] = [2, [0, 10, 1], [0, 13, 2], [0, 12, 2], [0, 11, 1]]
  41.   RECIPES[8] = [0, [0, 1, 1], [0, 3, 2], [0, 4, 2], [0, 5, 2], [0, 6, 2]]
  42.   # Alterar a fonte dos textos da janela de requerimentos.
  43.   REQ_FONT = "Franklin Gothic Medium"
  44.   REQ_SIZE = 19
  45.   # Alterar o termo da imagem da receita
  46.   # (Ao lado do termo deve ir o número id da receita: 0,1...)
  47.   REC_TERM = "Recipe_"
  48.   # As imagens devem estar na pasta Window_Craft, dentro da pasta
  49.   #pictures do seu projeto
  50.   # Alterar termos da Dificuldade da Receita
  51.   DIF_TERM = ["Fácil", "Médio", "Difícil"]
  52.   # Nível Máximo de Crafting
  53.   MAX_LEVEL = 10
  54.   # Base para Cálculo da Experiência Necessária
  55.   BASE_EXP = 25
  56.   # Taxa de Acerto por Nível e Dificuldade
  57.   # (Quantidade por Dificuldade = Nivel Máximo + 1)
  58.   ACC_RATE = []
  59.   ACC_RATE[0] = [30,35,40,45,50,65,75,80,85,95,100]
  60.   ACC_RATE[1] = [20,25,30,35,45,50,65,70,80,90,100]
  61.   ACC_RATE[2] = [5,15,20,25,30,35,45,55,65,75,85]
  62.   # Exp ganha
  63.   EXP_ERRO = 5
  64.   EXP_ACERTO = [10, 15, 20]
  65.   # Para ativar alguma receita, deve se usar o código abaixo
  66.   #  $game_craft.recipes[id] = true
  67.   # id = id da receita
  68.   # (Para desativar alguma receita, basta mudar true para false)
  69. end
  70.  
  71. # NÃO EDITE A PARTIR DAQUI SEM CONHECIMENTO PRÉVIO
  72.  
  73. class Game_Craft  
  74.   attr_accessor :recipes
  75.   attr_accessor :level
  76.   attr_accessor :exp
  77.   attr_accessor :next_exp
  78.   def initialize
  79.     @recipes = []
  80.     for i in 0..LMM_Craft::RECIPE_Q - 1
  81.       @recipes.push(false)
  82.     end  
  83.     @level = 0
  84.     @exp = 0
  85.     @exp_list = Array.new(LMM_Craft::MAX_LEVEL+1)
  86.     make_exp_list
  87.     @next_exp = @exp_list[@level+1]
  88.   end  
  89.   def make_exp_list
  90.     @maxexp = 0
  91.     @exp_list[0] = 0
  92.     @exp_list[1] = LMM_Craft::BASE_EXP
  93.     for i in 2..LMM_Craft::MAX_LEVEL
  94.       if i == LMM_Craft::MAX_LEVEL
  95.         @exp_list[i] = 0
  96.       else
  97.         @exp_list[i] = LMM_Craft::BASE_EXP + @exp_list[i-1] + @exp_list[i-2]
  98.       end
  99.       @maxexp += @exp_list[i]
  100.     end
  101.   end
  102.   def add_exp(exp)
  103.     @exp += exp
  104.     if @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
  105.       @level += 1
  106.       @next_exp = @exp_list[@level+1]
  107.       @exp = 0
  108.     end  
  109.   end  
  110. end  
  111.  
  112. class Scene_Crafting
  113.   include LMM_Craft
  114.   def main
  115.     @fundo = Spriteset_Map.new
  116.     @black = Sprite.new
  117.     @black.bitmap = Bitmap.new(640, 480)
  118.     @black.bitmap.fill_rect(Rect.new(0,0,640,480), Color.new(0,0,0,75))
  119.     @black.z = 15
  120.     opt = []
  121.     for i in 0..RECIPE_Q - 1
  122.       opt.push("")
  123.     end  
  124.     @command_window = Window_Command.new(192, opt )
  125.     @command_window.index = 0
  126.     @command_window.visible = false
  127.     @BG = Sprite.new
  128.     @BG.bitmap = RPG::Cache.picture("Window_Craft/Base_window")
  129.     @BG.z = 16    
  130.     @Sel = Sprite.new
  131.     @Sel.bitmap = RPG::Cache.picture("Window_Craft/Marker")
  132.     @Sel.x = 16
  133.     @Sel.y = 55 + (@command_window.index * 39)
  134.     @Sel.z = 17
  135.     @LVL = Sprite.new
  136.     @LVL.bitmap = Bitmap.new(20,25)
  137.     @LVL.x = 62; @LVL.y = 377; @LVL.z = 18
  138.     @LVL.bitmap.font.name = REQ_FONT
  139.     @LVL.bitmap.font.size = REQ_SIZE
  140.     @LVL.bitmap.font.color = Color.new(0, 0, 0, 255)  
  141.     @LVL.bitmap.clear
  142.     @LVL.bitmap.draw_text(0, 0, 20, 25, $game_craft.level.to_s,1)
  143.     @TEXT = Sprite.new
  144.     @TEXT.bitmap = Bitmap.new(198,25)
  145.     @TEXT.x = 362; @TEXT.y = 377; @TEXT.z = 18
  146.     @TEXT.bitmap.font.name = REQ_FONT
  147.     @TEXT.bitmap.font.size = REQ_SIZE
  148.     @TEXT.bitmap.font.color = Color.new(0, 0, 0, 255)  
  149.     @TEXT.bitmap.clear
  150.     @TEXT.bitmap.draw_text(0, 0, 198, 25, "Aguardando!",1)
  151.     @LVLBAR = Sprite.new
  152.     @LVLBAR.bitmap = Bitmap.new(202,9)
  153.     @LVLBAR.x = 83; @LVLBAR.y = 385; @LVLBAR.z = 18
  154.     @LVLBARIMG = RPG::Cache.picture("Window_Craft/Exp_Bar")
  155.     @LVLBARRECT = Rect.new(0,0, @LVLBARIMG.width * $game_craft.exp / $game_craft.next_exp, @LVLBARIMG.height)
  156.     @LVLBAR.bitmap.clear
  157.     @LVLBAR.bitmap.blt(0,0, @LVLBARIMG, @LVLBARRECT)
  158.     @RequireWin = Require_Win.new
  159.     @Confirm = Sprite.new
  160.     if $game_craft.recipes[@command_window.index] == true
  161.       if check_ing
  162.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOn")
  163.       else
  164.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOff")
  165.       end  
  166.     else
  167.       @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmNoR")
  168.     end  
  169.     @Confirm.x = 371
  170.     @Confirm.y = 294
  171.     @Confirm.z = 17
  172.     @Recipes = [Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new,Sprite.new]
  173.     for i in 0 .. RECIPE_VIEW - 1
  174.       if $game_craft.recipes[i] == true
  175.         @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/"+REC_TERM+(i).to_s)
  176.       else
  177.         @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/Norecipe")
  178.       end
  179.         @Recipes[i].x = 22
  180.         @Recipes[i].y = 61 + (i * 39)
  181.         @Recipes[i].z = 17
  182.     end
  183.     Graphics.transition
  184.     loop do
  185.       Graphics.update
  186.       Input.update
  187.       update
  188.       if $scene != self
  189.         break
  190.       end
  191.     end
  192.     Graphics.freeze
  193.     @command_window.dispose
  194.     @fundo.dispose
  195.     @black.dispose
  196.     @BG.dispose
  197.     @Sel.dispose
  198.     @LVL.dispose
  199.     @TEXT.dispose
  200.     @LVLBAR.dispose
  201.     @RequireWin.dispose
  202.     @Confirm.dispose
  203.     for i in 0 .. @Recipes.size - 1
  204.       @Recipes[i].dispose
  205.     end  
  206.     if $scene.is_a?(Scene_Title)
  207.       Graphics.transition
  208.       Graphics.freeze
  209.     end
  210.   end
  211.  
  212.   def update
  213.     @fundo.update
  214.     @black.update
  215.     @BG.update
  216.     @command_window.update
  217.     @RequireWin.update
  218.     if @command_window.index >= RECIPE_VIEW
  219.       @cmw_in = RECIPE_VIEW - 1
  220.       for i in 0 .. RECIPE_VIEW - 1
  221.         if $game_craft.recipes[@command_window.index - (RECIPE_VIEW - 1) + i] == true
  222.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/"+REC_TERM+(@command_window.index - (RECIPE_VIEW - 1) + i).to_s)
  223.         else
  224.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/Norecipe")
  225.         end
  226.       end      
  227.     else
  228.       @cmw_in = @command_window.index
  229.       for i in 0 .. RECIPE_VIEW - 1
  230.         if $game_craft.recipes[i] == true
  231.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/"+REC_TERM+(i).to_s)
  232.         else
  233.           @Recipes[i].bitmap = RPG::Cache.picture("Window_Craft/Norecipe")
  234.         end
  235.       end        
  236.     end  
  237.     @Sel.y = 55 + (@cmw_in * 39)
  238.     if $game_craft.recipes[@command_window.index] == true
  239.       @RequireWin.rec_id(RECIPES[@command_window.index])
  240.       if check_ing
  241.         update_command
  242.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOn")
  243.       else
  244.         @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmOff")
  245.       end  
  246.     else
  247.       @RequireWin.rec_id(nil)
  248.       @Confirm.bitmap = RPG::Cache.picture("Window_Craft/ConfirmNoR")
  249.     end    
  250.     if Input.trigger?(Input::B)
  251.       $game_system.se_play($data_system.cancel_se)
  252.       #Altere aqui caso deseje retornar em outra cena.
  253.       $scene = Scene_Map.new
  254.       return
  255.     end
  256.   end
  257.   def update_command
  258.     if Input.trigger?(Input::C)
  259.       $game_system.se_play($data_system.equip_se)
  260.       @try = rand(100) + 1
  261.       if(@try <= ACC_RATE[RECIPES[@command_window.index][0]][$game_craft.level])
  262.         case RECIPES[@command_window.index][1][0]
  263.           when 0
  264.             $game_party.gain_item(RECIPES[@command_window.index][1][1], RECIPES[@command_window.index][0][2])
  265.           when 1
  266.             $game_party.gain_weapon(RECIPES[@command_window.index][1][1], RECIPES[@command_window.index][0][2])
  267.           when 2
  268.             $game_party.gain_armor(RECIPES[@command_window.index][1][1], RECIPES[@command_window.index][0][2])
  269.         end
  270.         $game_craft.add_exp(EXP_ACERTO[RECIPES[@command_window.index][0]])
  271.         @TEXT.bitmap.font.color = Color.new(0, 150, 0, 255)  
  272.         @TEXT.bitmap.clear
  273.         @TEXT.bitmap.draw_text(0, 0, 198, 25, "Item Criado!",1)        
  274.       else
  275.         $game_craft.add_exp(EXP_ERRO)
  276.         @TEXT.bitmap.font.color = Color.new(255, 0, 0, 255)  
  277.         @TEXT.bitmap.clear
  278.         @TEXT.bitmap.draw_text(0, 0, 198, 25, "Falha ao criar Item!",1)
  279.       end  
  280.       for i in 2...RECIPES[@command_window.index].size
  281.         case RECIPES[@command_window.index][i][0]
  282.           when 0
  283.             $game_party.lose_item(RECIPES[@command_window.index][i][1], RECIPES[@command_window.index][i][2])                      
  284.           when 1
  285.             $game_party.lose_weapon(RECIPES[@command_window.index][i][1], RECIPES[@command_window.index][i][2])
  286.           when 2
  287.             $game_party.lose_armor(RECIPES[@command_window.index][i][1], RECIPES[@command_window.index][i][2])
  288.         end
  289.       end
  290.       @LVLBARRECT = Rect.new(0,0, @LVLBARIMG.width * $game_craft.exp / $game_craft.next_exp, @LVLBARIMG.height)
  291.       @LVLBAR.bitmap.clear
  292.       @LVLBAR.bitmap.blt(0,0, @LVLBARIMG, @LVLBARRECT)
  293.       @LVL.bitmap.clear
  294.       @LVL.bitmap.draw_text(0, 0, 20, 25, $game_craft.level.to_s,1)
  295.     end
  296.   end
  297.   def check_ing
  298.     for i in 2..RECIPES[@command_window.index].size-1
  299.       case RECIPES[@command_window.index][i][0]
  300.       when 0
  301.         unless $game_party.item_number(RECIPES[@command_window.index][i][1]) >= RECIPES[@command_window.index][i][2]
  302.           return false
  303.         end  
  304.       when 1
  305.         unless $game_party.weapon_number(RECIPES[@command_window.index][i][1]) >= RECIPES[@command_window.index][i][2]
  306.           return false
  307.         end        
  308.       when 2
  309.         unless $game_party.armor_number(RECIPES[@command_window.index][i][1]) >= RECIPES[@command_window.index][i][2]
  310.           return false
  311.         end        
  312.       end      
  313.     end
  314.     return true
  315.   end
  316. end
  317.  
  318. class Require_Win < Sprite
  319.   include LMM_Craft
  320.   def initialize
  321.     super
  322.     self.bitmap = Bitmap.new(268,253)
  323.     self.x = 329;self.y = 38;self.z = 18
  324.     @rec_id = nil
  325.     self.bitmap.font.name = REQ_FONT
  326.     self.bitmap.font.size = REQ_SIZE
  327.     self.bitmap.font.color = Color.new(0, 0, 0, 255)    
  328.     update
  329.   end  
  330.   def rec_id(id)
  331.     @rec_id = id
  332.   end  
  333.   def update
  334.     super
  335.     self.bitmap.clear
  336.     if @rec_id != nil
  337.       for i in 2..@rec_id.size-1
  338.         case @rec_id[i][0]
  339.         when 0
  340.           maticon = RPG::Cache.icon($data_items[@rec_id[i][1]].icon_name)
  341.           self.bitmap.blt(6, 97 + ((i - 2) * 42), maticon, Rect.new(0, 0, 24, 24), 255)          
  342.           text = $data_items[@rec_id[i][1]].name
  343.           self.bitmap.draw_text(39, 99 + ((i - 2) * 42), 154, 20, text,0)          
  344.           text2 = "#{@rec_id[i][2].to_s} / #{$game_party.item_number(@rec_id[i][1])}"
  345.           self.bitmap.draw_text(190, 99 + ((i - 2) * 42), 76, 20, text2,1)          
  346.         when 1
  347.           maticon = RPG::Cache.icon($data_weapons[@rec_id[i][1]].icon_name)
  348.           self.bitmap.blt(6, 97 + ((i - 2) * 42), maticon, Rect.new(0, 0, 24, 24), 255)          
  349.           text = $data_weapons[@rec_id[i][1]].name
  350.           self.bitmap.draw_text(39, 99 + ((i - 2) * 42), 154, 20, text,0)          
  351.           text2 = "#{@rec_id[i][2].to_s} / #{$game_party.weapon_number(@rec_id[i][1])}"
  352.           self.bitmap.draw_text(190, 99 + ((i - 2) * 42), 76, 20, text2,1)            
  353.         when 2
  354.           maticon = RPG::Cache.icon($data_armors[@rec_id[i][1]].icon_name)
  355.           self.bitmap.blt(6, 97 + ((i - 2) * 42), maticon, Rect.new(0, 0, 24, 24), 255)          
  356.           text = $data_armors[@rec_id[i][1]].name
  357.           self.bitmap.draw_text(39, 99 + ((i - 2) * 42), 154, 20, text,0)          
  358.           text2 = "#{@rec_id[i][2].to_s} / #{$game_party.armor_number(@rec_id[i][1])}"
  359.           self.bitmap.draw_text(190, 99+ ((i - 2) * 42), 76, 20, text2,1)            
  360.         end
  361.       end
  362.       case @rec_id[1][0]
  363.       when 0  
  364.         resulticon = RPG::Cache.icon($data_items[@rec_id[1][1]].icon_name)
  365.         self.bitmap.blt(13, 11, resulticon, Rect.new(0, 0, 24, 24), 255)
  366.         desc = $data_items[@rec_id[1][1]].name
  367.       when 1
  368.         resulticon = RPG::Cache.icon($data_weapons[@rec_id[1][1]].icon_name)
  369.         self.bitmap.blt(13, 11, resulticon, Rect.new(0, 0, 24, 24), 255)
  370.         desc = $data_weapons[@rec_id[1][1]].name        
  371.       when 2        
  372.         resulticon = RPG::Cache.icon($data_armors[@rec_id[1][1]].icon_name)
  373.         self.bitmap.blt(13, 11, resulticon, Rect.new(0, 0, 24, 24), 255)
  374.         desc = $data_armors[@rec_id[1][1]].name      
  375.       end            
  376.       self.bitmap.draw_text(51, 12, 214,16, desc + (" X "+ @rec_id[1][2].to_s) + (" | " + DIF_TERM[@rec_id[0]]) + (" | " +ACC_RATE[@rec_id[0]][$game_craft.level].to_s + "%"),1)    
  377.     end
  378.   end
  379. end
Add Comment
Please, Sign In to add comment