Advertisement
Raizen

Lune Item Grid

Mar 3rd, 2015
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 31.70 KB | None | 0 0
  1. #=======================================================
  2. # Autor: Raizen
  3. #         Lune Item Grid
  4. # Comunidade : www.centrorpg.com
  5. # Adiciona a função de grid para os itens, tal função é encontrado por exemplo
  6. # em Diablo 2 e 3, Resident Evil e muitos outros jogos.
  7. #=======================================================
  8. $imported ||= {}
  9. $imported[:Lune_Item_Grid] = true
  10.  
  11.  
  12. #=======================================================
  13. #-------------------------------------------------------
  14. #------------- Utilizando o Script! --------------------
  15. #-------------------------------------------------------
  16. #=======================================================
  17.  
  18. # Para configurar os itens do grid, utilize o bloco de notas no database,
  19. # Um item que tem uma imagem especifica utilize a seguinte tag no database.
  20. #<grid_pic nome_da_imagem>
  21.  
  22. # Aonde nome_da_imagem é o nome da imagem dentro da pasta Graphics/Item_Grid do
  23. # seu projeto, esse será a imagem do item, caso não tenha essa tag no item
  24. # A imagem será automaticamente o ícone do database.
  25.  
  26. #-------------------------------------------------------
  27.  
  28. # Para alterar o tamanho do item (lembrando que o tamanho padrão é 1x1,
  29. # Basta colocar uma tag nos itens desse modo
  30. # <item_size WxH>
  31.  
  32. #Aonde W é a largura do item e H a altura, por exemplo um item 2x3 ficaria desse modo
  33. # <item_size 2x3>
  34.  
  35. #-------------------------------------------------------
  36.  
  37. # Para um item ficar impossibilitado de jogar, adicionar essa tag a ele
  38. # <key_item>
  39.  
  40. #-------------------------------------------------------
  41.  
  42. # Para verificar se há espaço no grid utilize a aba condições
  43. # Script e use o seguinte comando
  44. # Script: space_on_grid?(type, id)
  45. # aonde o type é o tipo de item
  46. # 1 = itens, 2 = armas, 3 = armaduras
  47. # e id o id do database
  48. # Muito útil para caso precise que o personagem tenha certo item,
  49. # exemplo de utilização : space_on_grid?(1, 10)
  50.  
  51.  
  52.  
  53.  
  54. module Lune_Item_Grid
  55. #-------------------------------------------------------
  56. #------------- Vocabulário --------------------
  57. #-------------------------------------------------------
  58. Use = 'Use' #Usar o item
  59. Move = 'Move' #Mover o item
  60. Throw = 'Throw' #JOgar fora o item
  61.  
  62.  
  63. # Tamanho dos itens do grid em pixels [x, y]
  64. Item_Size = [24, 24]
  65.  
  66. # Tamanho do grid [x, y]
  67. Grid_Size = [16, 12]
  68.  
  69. # Imagem da grid de itens, coloque Image = '' para que utilize window padrão
  70. Image = 'Item_Grid'
  71.  
  72. # Correção da posição do Grid, para efeitos de encaixe na imagem
  73. Grid_Position_X = - 6
  74. Grid_Position_Y = - 8
  75.  
  76. end
  77. # Aqui começa o script.
  78. #=======================================================
  79. #==============================================================================
  80. # ** Game_Interpreter
  81. #------------------------------------------------------------------------------
  82. #  Um interpretador para executar os comandos de evento. Esta classe é usada
  83. # internamente pelas classes Game_Map, Game_Troop e Game_Event.
  84. #==============================================================================
  85.  
  86. class Game_Interpreter
  87.   def space_on_grid?(type, id)
  88.     case type
  89.     when 1
  90.       return $game_party.check_grid_available($data_items[id])
  91.     when 2
  92.       return $game_party.check_grid_available($data_weapons[id])
  93.     when 3
  94.       return $game_party.check_grid_available($data_armors[id])
  95.     end
  96.   end
  97. end
  98.  
  99. #==============================================================================
  100. # ** Game_Party
  101. #------------------------------------------------------------------------------
  102. #  Esta classe gerencia o grupo. Contém informações sobre dinheiro, itens.
  103. # A instância desta classe é referenciada por $game_party.
  104. #==============================================================================
  105.  
  106. class Game_Party < Game_Unit
  107. alias :lune_item_grid_initialize :initialize
  108. alias :lune_grid_gain_item :gain_item
  109. attr_accessor :item_grid_x
  110. attr_accessor :item_grid_y
  111. attr_reader :party_grid
  112.   #--------------------------------------------------------------------------
  113.   # * Inicialização do objeto
  114.   #--------------------------------------------------------------------------
  115.   def initialize
  116.     lune_item_grid_initialize
  117.     @item_grid_x = - 1
  118.     @item_grid_y = - 1
  119.     @party_grid = Array.new(Lune_Item_Grid::Grid_Size[0] - 1)
  120.     for n in 0..@party_grid.size
  121.       @party_grid[n] = Array.new(Lune_Item_Grid::Grid_Size[1], 0)
  122.     end
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # * Acrescentar item (redução)
  126.   #     item          : item
  127.   #     amount        : quantia alterada
  128.   #     include_equip : incluir itens equipados
  129.   #--------------------------------------------------------------------------
  130.   def gain_item(item, amount, include_equip = false)
  131.     while amount > 0
  132.       lune_grid_gain_item(item, 1, include_equip = false) if check_grid_available(item)
  133.       amount -= 1
  134.     end
  135.     if amount < 0
  136.       lune_grid_gain_item(item, amount, include_equip = false)
  137.       amount.abs.times {remove_item(item)}
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Acrescentar item no grid
  142.   #     item          : item
  143.   #--------------------------------------------------------------------------
  144.   def add_item_grid(item)
  145.     item_size = get_item_size(item)
  146.     if item.is_a?(RPG::Item)
  147.       @item_type = 1
  148.     elsif item.is_a?(RPG::Weapon)
  149.       @item_type = 2
  150.     else
  151.       @item_type = 3
  152.     end
  153.     for x3 in @item_grid_x..(item_size[0] + @item_grid_x - 1)
  154.       for y3 in @item_grid_y..(item_size[1] + @item_grid_y - 1)
  155.         @party_grid[x3][y3] = [@item_type, item.id, @item_grid_x, @item_grid_y, item_size[0], item_size[1]]
  156.       end
  157.     end
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # * Remover item do grid
  161.   #     item          : item
  162.   #--------------------------------------------------------------------------
  163.   def remove_item(item)
  164.     return false if item == nil
  165.     if item.is_a?(RPG::Item)
  166.       @item_type = 1
  167.     elsif item.is_a?(RPG::Weapon)
  168.       @item_type = 2
  169.     else
  170.       @item_type = 3
  171.     end
  172.     item_size = get_item_size(item)
  173.  
  174.     if @item_grid_x == -1
  175.       max_x = Lune_Item_Grid::Grid_Size[0] - 1
  176.       max_y = Lune_Item_Grid::Grid_Size[1] - 1
  177.       item_found = false
  178.       item_remove_x = -1
  179.       item_remove_y = -1
  180.       for y in 0..max_y
  181.         for x in 0..max_x
  182.           next unless @party_grid.is_a?(Array)
  183.           if @party_grid[x][y][0] == @item_type && @party_grid[x][y][1] == item.id
  184.             item_found = true
  185.             item_remove_x = x
  186.             item_remove_y = y
  187.           end
  188.           break if item_found
  189.         end
  190.         break if item_found
  191.       end
  192.       return unless item_found
  193.     else
  194.       item_remove_x = @item_grid_x
  195.       item_remove_y = @item_grid_y
  196.     end
  197.     for x in item_remove_x..(item_size[0] + item_remove_x - 1)
  198.       for y in item_remove_y..(item_size[1] + item_remove_y - 1)
  199.         @party_grid[x][y] = 0
  200.       end
  201.     end
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Verificar se há espaço no grid
  205.   #     item          : item
  206.   #--------------------------------------------------------------------------
  207.   def check_grid_available(item, add = true)
  208.     return false if item == nil
  209.     max_x = Lune_Item_Grid::Grid_Size[0] - 1
  210.     max_y = Lune_Item_Grid::Grid_Size[1] - 1
  211.     item_size = get_item_size(item)
  212.     space_for_item = false
  213.     for y in 0..max_y
  214.       for x in 0..max_x
  215.         space_for_item = check_for_item_space(x, y, item_size[0], item_size[1])
  216.         break if space_for_item
  217.       end
  218.       break if space_for_item
  219.     end
  220.     return false unless space_for_item
  221.     return true unless add
  222.     if item.is_a?(RPG::Item)
  223.       @item_type = 1
  224.     elsif item.is_a?(RPG::Weapon)
  225.       @item_type = 2
  226.     else
  227.       @item_type = 3
  228.     end
  229.     for x3 in x..(item_size[0] + x - 1)
  230.       for y3 in y..(item_size[1] + y - 1)
  231.         @party_grid[x3][y3] = [@item_type, item.id, x, y, item_size[0], item_size[1]]
  232.       end
  233.     end
  234.     return true
  235.   end
  236.   #--------------------------------------------------------------------------
  237.   # * Obter tamanho do item
  238.   #     item          : item
  239.   #--------------------------------------------------------------------------
  240.   def get_item_size(item)
  241.     return [1, 1] unless item
  242.       if item.note != ""
  243.       for count in 0..item.note.size
  244.         if item.note[count...count + 10] == "<item_size"
  245.           item_x = item.note[count + 11].to_i
  246.           item_y = item.note[count + 13].to_i
  247.         end
  248.       end
  249.     end
  250.     item_x = 1 unless item_x
  251.     item_y = 1 unless item_y
  252.     return [item_x, item_y]
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * Verificar espaço no grid
  256.   #--------------------------------------------------------------------------
  257.   def check_for_item_space(x, y, x2, y2)
  258.     for x3 in x..(x2 + x - 1)
  259.       for y3 in y..(y2 + y - 1)
  260.         return false if @party_grid[x3] == nil || @party_grid[x3][y3] != 0
  261.       end
  262.     end
  263.     return true
  264.   end
  265. end
  266.  
  267.  
  268. #==============================================================================
  269. # ** Scene_Item
  270. #------------------------------------------------------------------------------
  271. #  Esta classe executa o processamento da tela de item.
  272. #==============================================================================
  273.  
  274. class Scene_Item < Scene_ItemBase
  275.   #--------------------------------------------------------------------------
  276.   # * Inicialização do processo
  277.   #--------------------------------------------------------------------------
  278.   def start
  279.     super
  280.     create_help_window
  281.     create_category_window
  282.     create_item_window
  283.     create_back_sprite
  284.     create_use_window
  285.     @item_used = false
  286.     @category_window.opacity = 0 unless Lune_Item_Grid::Image == ''
  287.     @category_window.contents_opacity = 0
  288.     @help_window.opacity = 0 unless Lune_Item_Grid::Image == ''
  289.     @category_window.deactivate
  290.     @item_window.select(0)
  291.     @item_window.activate
  292.     wy = @category_window.y + @category_window.height
  293.     wh = Graphics.height - wy
  294.     @dummy_item_window = Window_Base.new(0, wy, Graphics.width, wh)
  295.     @dummy_item_window.opacity = 0 unless Lune_Item_Grid::Image == ''
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   # * Definição de cursor na coluna da esquerda
  299.   #--------------------------------------------------------------------------
  300.   def cursor_left?
  301.     @item_window.index % Lune_Item_Grid::Grid_Size[0] < Lune_Item_Grid::Grid_Size[0]/2
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # * Criação da janela de itens
  305.   #--------------------------------------------------------------------------
  306.   def create_item_window
  307.     wy = @category_window.y + @category_window.height
  308.     wh = Graphics.height - wy
  309.     @item_window = Window_Grid_ItemList.new(0, wy, Graphics.width, wh + 20)
  310.     @item_window.viewport = @viewport
  311.     @item_window.help_window = @help_window
  312.     @item_window.set_handler(:ok,     method(:on_item_ok))
  313.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  314.     @category_window.item_window = @item_window
  315.     @item_window.x += Lune_Item_Grid::Grid_Position_X
  316.     @item_window.y += Lune_Item_Grid::Grid_Position_Y
  317.     @item_window.opacity = 0
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # * Criando Imagem de fundo
  321.   #--------------------------------------------------------------------------
  322.   def create_back_sprite
  323.     @back_sprite_grid = Sprite.new
  324.     @back_sprite_grid.bitmap = Cache.item_grid(Lune_Item_Grid::Image)
  325.   end
  326.   def create_use_window
  327.     @use_item = Window_Item_Grid_Use.new
  328.     @use_item.set_handler(:new_game, method(:command_use))
  329.     @use_item.set_handler(:continue, method(:command_move))
  330.     @use_item.set_handler(:shutdown, method(:command_release))
  331.   end
  332.   #--------------------------------------------------------------------------
  333.   # * Cancelamento de ação
  334.   #--------------------------------------------------------------------------
  335.   def on_actor_cancel
  336.     super
  337.     @item_window.index = @old_index if @old_index
  338.     @item_used = false
  339.   end
  340.   #--------------------------------------------------------------------------
  341.   # * Cancelamento da janela de itens
  342.   #--------------------------------------------------------------------------
  343.   def on_item_cancel
  344.     if @on_move
  345.       $game_party.add_item_grid(@item_old)
  346.       @item_window.set_on_move(nil, false)
  347.       @on_move = false
  348.     end
  349.     @item_window.unselect
  350.     return_scene
  351.   end
  352.   #--------------------------------------------------------------------------
  353.   # * Usando um item
  354.   #--------------------------------------------------------------------------
  355.   def use_item
  356.     $game_party.item_grid_x = @item_window.current_col
  357.     $game_party.item_grid_y = @item_window.current_row  
  358.     super
  359.     @item_used = true
  360.     @item_window.dispose
  361.     create_item_window
  362.     $game_party.item_grid_x = $game_party.item_grid_y = -1
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * Comando de utilização
  366.   #--------------------------------------------------------------------------
  367.   def command_use
  368.     @use_item.close
  369.     if item.is_a?(RPG::Item)
  370.       @old_index = @item_window.index
  371.       determine_item
  372.     else
  373.       Sound.play_buzzer
  374.       @item_window.activate
  375.     end
  376.   end
  377.   #--------------------------------------------------------------------------
  378.   # * Definição de itens disponíveis para uso
  379.   #--------------------------------------------------------------------------
  380.   def item_usable?
  381.     user.usable?(item) && item_effects_valid? && !@item_used
  382.   end
  383.   #--------------------------------------------------------------------------
  384.   # * Comando de movimento do item
  385.   #--------------------------------------------------------------------------
  386.   def command_move
  387.     @item_old = @item_window.selected_item
  388.     $game_party.item_grid_x = @item_window.current_col
  389.     $game_party.item_grid_y = @item_window.current_row
  390.     @item_window.set_on_move(item, true)
  391.     $game_party.remove_item(@item_old)
  392.     @on_move = true
  393.     @use_item.close
  394.     @item_window.activate
  395.     @item_window.index = 0
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   # * Comando de dipose do item
  399.   #--------------------------------------------------------------------------
  400.   def command_release
  401.     return unless @item_window.selected_item
  402.     old_index = @item_window.index
  403.     @item_old = @item_window.selected_item
  404.     if @item_old.note.include?("<key_item>")
  405.       Sound.play_buzzer
  406.       @use_item.close
  407.       @item_window.activate  
  408.       return
  409.     end
  410.     $game_party.item_grid_x = @item_window.current_col
  411.     $game_party.item_grid_y = @item_window.current_row
  412.     $game_party.gain_item(@item_old, -1, true)
  413.     $game_party.item_grid_x = $game_party.item_grid_y = -1
  414.     @item_window.dispose
  415.     create_item_window
  416.     @use_item.close
  417.     @item_window.activate  
  418.     @item_window.index = old_index
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # * Comando de seleção do item
  422.   #--------------------------------------------------------------------------
  423.   def on_item_ok
  424.     if @on_move
  425.       if @item_window.check_for_space
  426.         $game_party.item_grid_x = @item_window.current_col
  427.         $game_party.item_grid_y = @item_window.current_row
  428.         $game_party.add_item_grid(@item_old)
  429.         $game_party.item_grid_x = $game_party.item_grid_y = -1
  430.         @item_window.dispose
  431.         create_item_window
  432.         @item_window.activate
  433.         @item_window.set_on_move(nil, false)
  434.         @on_move = false
  435.       else
  436.         Sound.play_buzzer
  437.         @item_window.activate
  438.       end
  439.       return
  440.     end
  441.     if item == nil
  442.       @item_window.activate
  443.       return
  444.     end
  445.     if @use_item.close?
  446.       @use_item.open
  447.       @use_item.activate
  448.     else
  449.       determine_item
  450.     end
  451.   end
  452.   #--------------------------------------------------------------------------
  453.   # * Método de atualização
  454.   #--------------------------------------------------------------------------
  455.   def update
  456.     super
  457.     if Input.trigger?(:B) and !@use_item.close?
  458.       Sound.play_cancel
  459.       @use_item.close
  460.       @item_window.activate
  461.     end
  462.   end
  463. end
  464.  
  465.  
  466.  
  467.  
  468. #==============================================================================
  469. # ** Window_ItemList
  470. #------------------------------------------------------------------------------
  471. #  Esta janela exibe a lista de itens possuidos na tela de itens.
  472. #==============================================================================
  473.  
  474. class Window_Grid_ItemList < Window_ItemList
  475. include Lune_Item_Grid
  476.   #--------------------------------------------------------------------------
  477.   # * Inicialização do processo
  478.   #--------------------------------------------------------------------------
  479.   def initialize(*args)
  480.     @index = 0
  481.     set_on_move(nil, false)
  482.     super(*args)
  483.   end
  484.   #--------------------------------------------------------------------------
  485.   # * Verificar espaço
  486.   #--------------------------------------------------------------------------
  487.   def check_for_space
  488.     $game_party.check_for_item_space(current_col, current_row, @size_item_move[0]/Item_Size[0], @size_item_move[1]/Item_Size[1])
  489.   end
  490.   #--------------------------------------------------------------------------
  491.   # * Coluna atual
  492.   #--------------------------------------------------------------------------
  493.   def current_col
  494.     index % col_max
  495.   end
  496.   #--------------------------------------------------------------------------
  497.   # * Linha atual
  498.   #--------------------------------------------------------------------------
  499.   def current_row
  500.     index / col_max
  501.   end
  502.   #--------------------------------------------------------------------------
  503.   # * Selecionado comando de mover
  504.   #--------------------------------------------------------------------------
  505.   def set_on_move(item, on_move)
  506.     if on_move
  507.       @size_item_move = [item_width, item_height]
  508.     else
  509.       @size_item_move = nil
  510.     end
  511.     @on_move = on_move
  512.   end
  513.   #--------------------------------------------------------------------------
  514.   # * Retorno à seleção anterior
  515.   #--------------------------------------------------------------------------
  516.   def select_last
  517.     inndex = @data.index($game_party.last_item.object) || 0
  518.     if  $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]].is_a?(Array)
  519.       inndex = $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][2] + $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][3] * Grid_Size[0]
  520.       select(inndex)
  521.       return
  522.     end
  523.     select(@data.index($game_party.last_item.object) || 0)
  524.   end
  525.   #--------------------------------------------------------------------------
  526.   # * Aquisição do número de colunas
  527.   #--------------------------------------------------------------------------
  528.   def col_max
  529.     if @size_item_move
  530.       return Grid_Size[0] + 1 - (@size_item_move[0] / Item_Size[0])
  531.     end
  532.     return Grid_Size[0]
  533.   end
  534.   #--------------------------------------------------------------------------
  535.   # * Aquisição do espaçamento entre os itens
  536.   #--------------------------------------------------------------------------
  537.   def spacing
  538.     return 0
  539.   end
  540.   #--------------------------------------------------------------------------
  541.   # * Inclusão do item na lista
  542.   #     item : item
  543.   #--------------------------------------------------------------------------
  544.   def include?(item)
  545.     true
  546.   end
  547.   #--------------------------------------------------------------------------
  548.   # * Aquisição do retangulo para desenhar o item
  549.   #     index : índice do item
  550.   #--------------------------------------------------------------------------
  551.   def item_rect(index)
  552.     @index = index
  553.     rect = Rect.new
  554.     rect.width = item_width
  555.     rect.height = item_height
  556.     rect.x = index % col_max * (Item_Size[0] + spacing)
  557.     rect.y = index / col_max * Item_Size[1]
  558.     rect
  559.   end
  560.   #--------------------------------------------------------------------------
  561.   # * Aquisição de largura do item
  562.   #--------------------------------------------------------------------------
  563.   def item_width
  564.     return @size_item_move[0] if @size_item_move != nil
  565.     if  $game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]].is_a?(Array)
  566.       $game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]][4] * Item_Size[0]
  567.     else
  568.       Item_Size[0]
  569.     end
  570.   end
  571.   #--------------------------------------------------------------------------
  572.   # * Aquisição de altura do item
  573.   #--------------------------------------------------------------------------
  574.   def item_height
  575.     return @size_item_move[1] if @size_item_move != nil
  576.     if  $game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]].is_a?(Array)
  577.       $game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]][5] * Item_Size[1]
  578.     else
  579.       Item_Size[1]
  580.     end
  581.   end
  582.   #--------------------------------------------------------------------------
  583.   # * Aquisição do número máximo de itens
  584.   #--------------------------------------------------------------------------
  585.   def item_max
  586.     if @size_item_move
  587.       return (Grid_Size[0] + 1 - (@size_item_move[0] / Item_Size[0]))*(Grid_Size[1] + 1 - (@size_item_move[1] / Item_Size[1]))
  588.     end
  589.     Grid_Size[0]*Grid_Size[1]
  590.   end
  591.   #--------------------------------------------------------------------------
  592.   # * Desenho de um item
  593.   #     index : índice do item
  594.   #--------------------------------------------------------------------------
  595.   def draw_item(index)
  596.     item = @data[index]
  597.     if item
  598.       rect = item_rect(index)
  599.       rect.width -= 4
  600.       if item.note.include?("<grid_pic")
  601.         for count in 0..item.note.size
  602.           if item.note[count...count + 9] == "<grid_pic"
  603.             count2 = 0
  604.             count2 += 1 until item.note[count2 + count + 10] == ">"
  605.             draw_grid_item(item.note[(count + 10)..(count + count2 + 9)], rect.x, rect.y)
  606.           end
  607.         end
  608.       else
  609.         draw_icon(item.icon_index, rect.x, rect.y, enable?(item))
  610.       end
  611.       #draw_item_number(rect, item)
  612.     end
  613.   end
  614.   #--------------------------------------------------------------------------
  615.   # * Desenho de ícones
  616.   #     icon_index : índice do ícone
  617.   #     x          : coordenada X
  618.   #     y          : coordenada Y
  619.   #     enabled    : habilitar flag, translucido quando false
  620.   #--------------------------------------------------------------------------
  621.   def draw_grid_item(item_name, x, y)
  622.     bitmap = Cache.item_grid(item_name)
  623.     rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  624.     contents.blt(x, y, bitmap, rect,  255)
  625.   end
  626.   #--------------------------------------------------------------------------
  627.   # * Criação da lista de itens
  628.   #--------------------------------------------------------------------------
  629.   def make_item_list
  630.     for n in 0..Grid_Size[1] - 1
  631.       for i in 0..Grid_Size[0] - 1
  632.         if $game_party.party_grid[i][n] == 0 || $game_party.party_grid[i][n][2] != i || $game_party.party_grid[i][n][3] != n
  633.           @data << nil
  634.         else
  635.           case $game_party.party_grid[i][n][0]
  636.           when 1
  637.             @data << $data_items[$game_party.party_grid[i][n][1]]
  638.           when 2
  639.             @data << $data_weapons[$game_party.party_grid[i][n][1]]
  640.           when 3
  641.             @data << $data_armors[$game_party.party_grid[i][n][1]]
  642.           end  
  643.         end
  644.       end
  645.     end
  646.   end
  647.   #--------------------------------------------------------------------------
  648.   # * Movimento do cursor para baixo
  649.   #     wrap : cursor retornar a primeira ou ultima posição
  650.   #--------------------------------------------------------------------------
  651.   def cursor_down(wrap = false)
  652.     if @size_item_move
  653.       super(true)
  654.       return
  655.     end
  656.     correction = 1
  657.     correction = $game_party.party_grid[index % Grid_Size[0]][index / Grid_Size[0]][5] if $game_party.party_grid[index % Grid_Size[0]][index / Grid_Size[0]].is_a?(Array)
  658.     inndex = (index + col_max * correction) % item_max
  659.     if  $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]].is_a?(Array)
  660.       inndex = $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][2] + $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][3] * Grid_Size[0]
  661.       select(inndex)
  662.       return
  663.     end
  664.     select((index + col_max * correction) % item_max)
  665.   end
  666.   #--------------------------------------------------------------------------
  667.   # * Movimento do cursor para cima
  668.   #     wrap : cursor retornar a primeira ou ultima posição
  669.   #--------------------------------------------------------------------------
  670.   def cursor_up(wrap = false)
  671.     if @size_item_move
  672.       super(true)
  673.       return
  674.     end
  675.     inndex = (index - col_max + item_max) % item_max
  676.     if  $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]].is_a?(Array)
  677.       inndex = $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][2] + $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][3] * Grid_Size[0]
  678.       select(inndex)
  679.       return
  680.     end
  681.     select((index - col_max) % item_max)
  682.   end
  683.   #--------------------------------------------------------------------------
  684.   # * Movimento do cursor para direita
  685.   #     wrap : cursor retornar a primeira ou ultima posição
  686.   #--------------------------------------------------------------------------
  687.   def cursor_right(wrap = false)
  688.     if @size_item_move
  689.       super(true)
  690.       return
  691.     end
  692.     correction = 1
  693.     correction = $game_party.party_grid[index % Grid_Size[0]][index / Grid_Size[0]][4] if $game_party.party_grid[index % Grid_Size[0]][index / Grid_Size[0]].is_a?(Array)
  694.     inndex = (index + correction) % item_max
  695.     if  $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]].is_a?(Array)
  696.       inndex = $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][2] + $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][3] * Grid_Size[0]
  697.       select(inndex)
  698.       return
  699.     end
  700.     select((index + correction) % item_max)
  701.   end
  702.   #--------------------------------------------------------------------------
  703.   # * Movimento do cursor para esquerda
  704.   #     wrap : cursor retornar a primeira ou ultima posição
  705.   #--------------------------------------------------------------------------
  706.   def cursor_left(wrap = false)
  707.     if @size_item_move
  708.       super(true)
  709.       return
  710.     end
  711.     inndex = (index - 1 + item_max) % item_max
  712.     if  $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]].is_a?(Array)
  713.       inndex = $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][2] + $game_party.party_grid[inndex % Grid_Size[0]][inndex / Grid_Size[0]][3] * Grid_Size[0]
  714.       select(inndex)
  715.       return
  716.     end
  717.     select((index - 1 + item_max) % item_max)
  718.   end  
  719.   #--------------------------------------------------------------------------
  720.   # * Movimento do cursor uma página abaixo
  721.   #--------------------------------------------------------------------------
  722.   def cursor_pagedown
  723.   end
  724.   #--------------------------------------------------------------------------
  725.   # * Movimento do cursor uma página acima
  726.   #--------------------------------------------------------------------------
  727.   def cursor_pageup
  728.   end
  729.   #--------------------------------------------------------------------------
  730.   # * Confirmação de visibilidade do cursor
  731.   #--------------------------------------------------------------------------
  732.   def ensure_cursor_visible
  733.   end
  734.   def selected_item
  735.     return false unless $game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]].is_a?(Array)
  736.     case $game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]][0]
  737.       when 1
  738.         return $data_items[$game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]][1]]
  739.       when 2
  740.         return $data_weapons[$game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]][1]]
  741.       when 3
  742.         return $data_armors[$game_party.party_grid[@index % Grid_Size[0]][@index / Grid_Size[0]][1]]
  743.     end
  744.   end
  745.   #--------------------------------------------------------------------------
  746.   # * Definição de habilitação do item
  747.   #     item : item
  748.   #--------------------------------------------------------------------------
  749.   def enable?(item)
  750.     true
  751.   end
  752. end
  753.  
  754. module Cache
  755.   #--------------------------------------------------------------------------
  756.   # * Carregamento dos gráficos de itens
  757.   #     filename : nome do arquivo
  758.   #--------------------------------------------------------------------------
  759.   def self.item_grid(filename)
  760.     load_bitmap("Graphics/Item_Grid/", filename)
  761.   end
  762. end
  763.  
  764.  
  765. #==============================================================================
  766. # ** Window_MenuStatus
  767. #------------------------------------------------------------------------------
  768. #  Esta janela exibe os parâmetros dos membros do grupo na tela de menu.
  769. #==============================================================================
  770.  
  771. class Window_Item_Grid_Use < Window_Command
  772. include Lune_Item_Grid
  773.   #--------------------------------------------------------------------------
  774.   # * Inicialização do objeto
  775.   #--------------------------------------------------------------------------
  776.   def initialize
  777.     super(0, 0)
  778.     self.z = 9999
  779.     self.x = (Graphics.width / 2) - (window_width / 2)
  780.     self.y = Graphics.height / 2
  781.     self.openness = 0
  782.   end
  783.   #--------------------------------------------------------------------------
  784.   # * Aquisição da largura da janela
  785.   #--------------------------------------------------------------------------
  786.   def window_width
  787.     return 160
  788.   end
  789.   #--------------------------------------------------------------------------
  790.   # * Criação da lista de comandos
  791.   #--------------------------------------------------------------------------
  792.   def make_command_list
  793.     add_main_commands
  794.  
  795.   end
  796.   #--------------------------------------------------------------------------
  797.   # * Adição dos comandos principais
  798.   #--------------------------------------------------------------------------
  799.   def add_main_commands
  800.     add_command(Use,   :new_game,   true)
  801.     add_command(Move,  :continue,  true)
  802.     add_command(Throw,  :shutdown,  true)
  803.   end
  804.  
  805. end
  806. #==============================================================================
  807. # ** Game_Actor
  808. #------------------------------------------------------------------------------
  809. #  Esta classe gerencia os heróis. Ela é utilizada internamente pela classe
  810. # Game_Actors ($game_actors). A instância desta classe é referenciada
  811. # pela classe Game_Party ($game_party).
  812. #==============================================================================
  813.  
  814. class Game_Actor < Game_Battler
  815.   #--------------------------------------------------------------------------
  816.   # * Trocar item com membro do grupo
  817.   #     new_item : item removido do grupo
  818.   #     old_item : item devolvido ao grupo
  819.   #--------------------------------------------------------------------------
  820.   def trade_item_with_party(new_item, old_item)
  821.     return false if new_item && !$game_party.has_item?(new_item)
  822.     if !old_item || $game_party.check_grid_available(old_item, false)
  823.       $game_party.gain_item(old_item, 1)
  824.       $game_party.lose_item(new_item, 1)
  825.     else
  826.       return false
  827.     end
  828.     return true
  829.   end
  830. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement