Advertisement
Raizen

Untitled

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