Advertisement
Black_Mage

Lune Item Grid - Size Upgrade Addon - RMVXA Script

Mar 18th, 2023 (edited)
1,427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.28 KB | Source Code | 0 0
  1. #==============================================================================
  2. # Lune Item Grid - Size Upgrade Addon Script by Black Mage
  3. # For: RPG Maker VX Ace
  4. # (Commissioned by LucaBicono)
  5. #
  6. # This script is an addon for Lune Item Grid script by Raizen, which can be
  7. # found on the link below:
  8. # https://forums.rpgmakerweb.com/index.php?threads/lune-item-grid.37399/
  9. #
  10. # This script add a function to increase the size of the grid inventory after
  11. # the game is started. Do note that if you tried to decrease the grid size
  12. # instead, an error will occured because I have no plan to implement that.
  13. #
  14. # Use the following script call to change the grid size:
  15. # $game_party.party_grid_upgrade(x,y)
  16. #
  17. # License: CC-BY 3.0
  18. # Feel free to use this addon for any kind of project you might have as long as
  19. # you abide by the terms of the original Lune Item Grid script.
  20. #
  21. # Find more of my works at:
  22. # https://burningwizard.wordpress.com/
  23. #==============================================================================
  24.  
  25. #==============================================================================
  26. # Changelog
  27. #==============================================================================
  28. # Version 1.0
  29. #   - Initial version.
  30. #==============================================================================
  31.  
  32. #------------------------------------------------------------------------------
  33. # * Beyond this is the sacred land of code. You need programming qualification
  34. #   to delve deeper, or it'll cause many unnecessary problems. Proceed at your
  35. #   own risk.
  36. #------------------------------------------------------------------------------
  37.  
  38. #==============================================================================
  39. # Make the grid become upgradable
  40. #==============================================================================
  41. class Game_System
  42.   attr_accessor :lune_grid_size
  43.   alias b_grid_addon_init initialize
  44.   def initialize
  45.     b_grid_addon_init; @lune_grid_size = Lune_Item_Grid::Grid_Size
  46.   end
  47. end
  48.  
  49. class Game_Party < Game_Unit
  50.   def party_grid_upgrade(x,y)
  51.     old_size = $game_system.lune_grid_size
  52.     old_party_grid = @party_grid.dup
  53.     $game_system.lune_grid_size = [x,y]
  54.     @party_grid = Array.new(x - 1)
  55.     for n in 0..@party_grid.size
  56.       @party_grid[n] = Array.new(y, 0)
  57.     end
  58.     old_party_grid.each_with_index do |obj1, i|
  59.       obj1.each_with_index do |obj2, j|
  60.         @party_grid[i][j] = obj2
  61.       end
  62.     end
  63.   end
  64. end
  65. #==============================================================================
  66.  
  67. #==============================================================================
  68. # Adjusting the script to follow new upgraded size.
  69. #==============================================================================
  70. class Game_Party < Game_Unit
  71.   def remove_item(item)
  72.     return false if item == nil
  73.     if item.is_a?(RPG::Item)
  74.       @item_type = 1
  75.     elsif item.is_a?(RPG::Weapon)
  76.       @item_type = 2
  77.     else
  78.       @item_type = 3
  79.     end
  80.     item_size = get_item_size(item)
  81.  
  82.     if @item_grid_x == -1
  83.       max_x = $game_system.lune_grid_size[0] - 1
  84.       max_y = $game_system.lune_grid_size[1] - 1
  85.       item_found = false
  86.       item_remove_x = -1
  87.       item_remove_y = -1
  88.       for y in 0..max_y
  89.         for x in 0..max_x
  90.           next unless @party_grid.is_a?(Array)
  91.           if @party_grid[x][y][0] == @item_type && @party_grid[x][y][1] == item.id
  92.             item_found = true
  93.             item_remove_x = x
  94.             item_remove_y = y
  95.           end
  96.           break if item_found
  97.         end
  98.         break if item_found
  99.       end
  100.       return unless item_found
  101.     else
  102.       item_remove_x = @item_grid_x
  103.       item_remove_y = @item_grid_y
  104.     end
  105.     for x in item_remove_x..(item_size[0] + item_remove_x - 1)
  106.       for y in item_remove_y..(item_size[1] + item_remove_y - 1)
  107.         @party_grid[x][y] = 0
  108.       end
  109.     end
  110.   end
  111.  
  112.   def check_grid_available(item, add = true)
  113.     return false if item == nil
  114.     max_x = $game_system.lune_grid_size[0] - 1
  115.     max_y = $game_system.lune_grid_size[1] - 1
  116.     item_size = get_item_size(item)
  117.     space_for_item = false
  118.     for y in 0..max_y
  119.       for x in 0..max_x
  120.         space_for_item = check_for_item_space(x, y, item_size[0], item_size[1])
  121.         break if space_for_item
  122.       end
  123.       break if space_for_item
  124.     end
  125.     return false unless space_for_item
  126.     return true unless add
  127.     if item.is_a?(RPG::Item)
  128.       @item_type = 1
  129.     elsif item.is_a?(RPG::Weapon)
  130.       @item_type = 2
  131.     else
  132.       @item_type = 3
  133.     end
  134.     for x3 in x..(item_size[0] + x - 1)
  135.       for y3 in y..(item_size[1] + y - 1)
  136.         @party_grid[x3][y3] = [@item_type, item.id, x, y, item_size[0], item_size[1]]
  137.       end
  138.     end
  139.     return true
  140.   end
  141. end
  142.  
  143. class Scene_Item < Scene_ItemBase
  144.   def cursor_left?
  145.     @item_window.index % $game_system.lune_grid_size[0] < $game_system.lune_grid_size[0]/2
  146.   end
  147. end
  148.  
  149. class Window_Grid_ItemList < Window_ItemList
  150.   def select_last
  151.     inndex = @data.index($game_party.last_item.object) || 0
  152.     if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
  153.       inndex = $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][2] + $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][3] * $game_system.lune_grid_size[0]
  154.       select(inndex)
  155.       return
  156.     end
  157.     select(@data.index($game_party.last_item.object) || 0)
  158.   end
  159.  
  160.   def col_max
  161.     if @size_item_move
  162.       return $game_system.lune_grid_size[0] + 1 - (@size_item_move[0] / Item_Size[0])
  163.     end
  164.     return $game_system.lune_grid_size[0]
  165.   end
  166.  
  167.   def item_width
  168.     return @size_item_move[0] if @size_item_move != nil
  169.     if  $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]].is_a?(Array)
  170.       $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][4] * Item_Size[0]
  171.     else
  172.       Item_Size[0]
  173.     end
  174.   end
  175.  
  176.   def item_height
  177.     return @size_item_move[1] if @size_item_move != nil
  178.     if $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]].is_a?(Array)
  179.       $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][5] * Item_Size[1]
  180.     else
  181.       Item_Size[1]
  182.     end
  183.   end
  184.  
  185.   def item_max
  186.     if @size_item_move
  187.       return ($game_system.lune_grid_size[0] + 1 - (@size_item_move[0] / Item_Size[0]))*($game_system.lune_grid_size[1] + 1 - (@size_item_move[1] / Item_Size[1]))
  188.     end
  189.     $game_system.lune_grid_size[0]*$game_system.lune_grid_size[1]
  190.   end
  191.  
  192.   def make_item_list
  193.     for n in 0..$game_system.lune_grid_size[1] - 1
  194.       for i in 0..$game_system.lune_grid_size[0] - 1
  195.         if $game_party.party_grid[i][n] == 0 || $game_party.party_grid[i][n][2] != i || $game_party.party_grid[i][n][3] != n
  196.           @data << nil
  197.         else
  198.           case $game_party.party_grid[i][n][0]
  199.           when 1
  200.             @data << $data_items[$game_party.party_grid[i][n][1]]
  201.           when 2
  202.             @data << $data_weapons[$game_party.party_grid[i][n][1]]
  203.           when 3
  204.             @data << $data_armors[$game_party.party_grid[i][n][1]]
  205.           end  
  206.         end
  207.       end
  208.     end
  209.   end
  210.  
  211.   def cursor_down(wrap = false)
  212.     if @size_item_move
  213.       super(true)
  214.       return
  215.     end
  216.     correction = 1
  217.     correction = $game_party.party_grid[index % $game_system.lune_grid_size[0]][index / $game_system.lune_grid_size[0]][5] if $game_party.party_grid[index % $game_system.lune_grid_size[0]][index / $game_system.lune_grid_size[0]].is_a?(Array)
  218.     inndex = (index + col_max * correction) % item_max
  219.     if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
  220.       inndex = $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][2] + $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][3] * $game_system.lune_grid_size[0]
  221.       select(inndex)
  222.       return
  223.     end
  224.     select((index + col_max * correction) % item_max)
  225.   end
  226.  
  227.   def cursor_up(wrap = false)
  228.     if @size_item_move
  229.       super(true)
  230.       return
  231.     end
  232.     inndex = (index - col_max + item_max) % item_max
  233.     if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
  234.       inndex = $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][2] + $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][3] * $game_system.lune_grid_size[0]
  235.       select(inndex)
  236.       return
  237.     end
  238.     select((index - col_max) % item_max)
  239.   end
  240.  
  241.   def cursor_right(wrap = false)
  242.     if @size_item_move
  243.       super(true)
  244.       return
  245.     end
  246.     correction = 1
  247.     correction = $game_party.party_grid[index % $game_system.lune_grid_size[0]][index / $game_system.lune_grid_size[0]][4] if $game_party.party_grid[index % $game_system.lune_grid_size[0]][index / $game_system.lune_grid_size[0]].is_a?(Array)
  248.     inndex = (index + correction) % item_max
  249.     if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
  250.       inndex = $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][2] + $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][3] * $game_system.lune_grid_size[0]
  251.       select(inndex)
  252.       return
  253.     end
  254.     select((index + correction) % item_max)
  255.   end
  256.  
  257.   def cursor_left(wrap = false)
  258.     if @size_item_move
  259.       super(true)
  260.       return
  261.     end
  262.     inndex = (index - 1 + item_max) % item_max
  263.     if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
  264.       inndex = $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][2] + $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]][3] * $game_system.lune_grid_size[0]
  265.       select(inndex)
  266.       return
  267.     end
  268.     select((index - 1 + item_max) % item_max)
  269.   end  
  270.  
  271.   def selected_item
  272.     return false unless $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]].is_a?(Array)
  273.     case $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][0]
  274.       when 1
  275.         return $data_items[$game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][1]]
  276.       when 2
  277.         return $data_weapons[$game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][1]]
  278.       when 3
  279.         return $data_armors[$game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][1]]
  280.     end
  281.   end
  282.  
  283. end
  284. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement