Black_Mage icon

Lune Item Grid - Size Upgrade Addon - RMVXA Script

Black_Mage | PRO | 03/19/23 03:10:16 PM UTC (Edited) | 0 ⭐ | 8375 👁️ | Never ⏰ | []
Ruby |

11.28 KB

|

Source Code

|

0 👍

/

0 👎

#==============================================================================
# Lune Item Grid - Size Upgrade Addon Script by Black Mage
# For: RPG Maker VX Ace
# (Commissioned by LucaBicono)
#
# This script is an addon for Lune Item Grid script by Raizen, which can be 
# found on the link below:
# https://forums.rpgmakerweb.com/index.php?threads/lune-item-grid.37399/
#
# This script add a function to increase the size of the grid inventory after
# the game is started. Do note that if you tried to decrease the grid size 
# instead, an error will occured because I have no plan to implement that.
#
# Use the following script call to change the grid size:
# $game_party.party_grid_upgrade(x,y)
#
# License: CC-BY 3.0
# Feel free to use this addon for any kind of project you might have as long as
# you abide by the terms of the original Lune Item Grid script.
#
# Find more of my works at:
# https://burningwizard.wordpress.com/
#==============================================================================
 
#==============================================================================
# Changelog
#==============================================================================
# Version 1.0
#   - Initial version.
#==============================================================================
 
#------------------------------------------------------------------------------
# * Beyond this is the sacred land of code. You need programming qualification
#   to delve deeper, or it'll cause many unnecessary problems. Proceed at your
#   own risk.
#------------------------------------------------------------------------------
 
#==============================================================================
# Make the grid become upgradable
#==============================================================================
class Game_System
  attr_accessor :lune_grid_size
  alias b_grid_addon_init initialize
  def initialize
    b_grid_addon_init; @lune_grid_size = Lune_Item_Grid::Grid_Size
  end
end
 
class Game_Party < Game_Unit
  def party_grid_upgrade(x,y)
    old_size = $game_system.lune_grid_size
    old_party_grid = @party_grid.dup
    $game_system.lune_grid_size = [x,y]
    @party_grid = Array.new(x - 1)
    for n in 0..@party_grid.size
      @party_grid[n] = Array.new(y, 0)
    end
    old_party_grid.each_with_index do |obj1, i| 
      obj1.each_with_index do |obj2, j|
        @party_grid[i][j] = obj2
      end
    end
  end
end
#==============================================================================
 
#==============================================================================
# Adjusting the script to follow new upgraded size.
#==============================================================================
class Game_Party < Game_Unit
  def remove_item(item)
    return false if item == nil
    if item.is_a?(RPG::Item)
      @item_type = 1
    elsif item.is_a?(RPG::Weapon)
      @item_type = 2
    else
      @item_type = 3
    end
    item_size = get_item_size(item)
 
    if @item_grid_x == -1
      max_x = $game_system.lune_grid_size[0] - 1
      max_y = $game_system.lune_grid_size[1] - 1
      item_found = false
      item_remove_x = -1
      item_remove_y = -1
      for y in 0..max_y
        for x in 0..max_x
          next unless @party_grid.is_a?(Array)
          if @party_grid[x][y][0] == @item_type && @party_grid[x][y][1] == item.id
            item_found = true 
            item_remove_x = x
            item_remove_y = y
          end
          break if item_found
        end
        break if item_found
      end 
      return unless item_found
    else
      item_remove_x = @item_grid_x
      item_remove_y = @item_grid_y
    end
    for x in item_remove_x..(item_size[0] + item_remove_x - 1)
      for y in item_remove_y..(item_size[1] + item_remove_y - 1)
        @party_grid[x][y] = 0
      end
    end
  end
  
  def check_grid_available(item, add = true)
    return false if item == nil
    max_x = $game_system.lune_grid_size[0] - 1
    max_y = $game_system.lune_grid_size[1] - 1
    item_size = get_item_size(item)
    space_for_item = false
    for y in 0..max_y
      for x in 0..max_x
        space_for_item = check_for_item_space(x, y, item_size[0], item_size[1])
        break if space_for_item
      end
      break if space_for_item
    end 
    return false unless space_for_item
    return true unless add
    if item.is_a?(RPG::Item)
      @item_type = 1
    elsif item.is_a?(RPG::Weapon)
      @item_type = 2
    else
      @item_type = 3
    end
    for x3 in x..(item_size[0] + x - 1)
      for y3 in y..(item_size[1] + y - 1)
        @party_grid[x3][y3] = [@item_type, item.id, x, y, item_size[0], item_size[1]]
      end
    end
    return true
  end
end
 
class Scene_Item < Scene_ItemBase
  def cursor_left?
    @item_window.index % $game_system.lune_grid_size[0] < $game_system.lune_grid_size[0]/2
  end
end
 
class Window_Grid_ItemList < Window_ItemList
  def select_last
    inndex = @data.index($game_party.last_item.object) || 0
    if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
      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]
      select(inndex)
      return
    end
    select(@data.index($game_party.last_item.object) || 0)
  end
  
  def col_max
    if @size_item_move
      return $game_system.lune_grid_size[0] + 1 - (@size_item_move[0] / Item_Size[0])
    end 
    return $game_system.lune_grid_size[0]
  end
  
  def item_width
    return @size_item_move[0] if @size_item_move != nil
    if  $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]].is_a?(Array)
      $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][4] * Item_Size[0]
    else
      Item_Size[0]
    end
  end
  
  def item_height
    return @size_item_move[1] if @size_item_move != nil
    if $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]].is_a?(Array)
      $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][5] * Item_Size[1]
    else
      Item_Size[1]
    end
  end
 
  def item_max
    if @size_item_move
      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]))
    end 
    $game_system.lune_grid_size[0]*$game_system.lune_grid_size[1]
  end
 
  def make_item_list
    for n in 0..$game_system.lune_grid_size[1] - 1
      for i in 0..$game_system.lune_grid_size[0] - 1
        if $game_party.party_grid[i][n] == 0 || $game_party.party_grid[i][n][2] != i || $game_party.party_grid[i][n][3] != n
          @data << nil 
        else
          case $game_party.party_grid[i][n][0]
          when 1
            @data << $data_items[$game_party.party_grid[i][n][1]]
          when 2
            @data << $data_weapons[$game_party.party_grid[i][n][1]] 
          when 3
            @data << $data_armors[$game_party.party_grid[i][n][1]]
          end  
        end
      end
    end
  end
 
  def cursor_down(wrap = false)
    if @size_item_move
      super(true)
      return
    end
    correction = 1
    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)
    inndex = (index + col_max * correction) % item_max
    if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
      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]
      select(inndex)
      return
    end
    select((index + col_max * correction) % item_max)
  end
 
  def cursor_up(wrap = false)
    if @size_item_move
      super(true)
      return
    end
    inndex = (index - col_max + item_max) % item_max
    if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
      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]
      select(inndex)
      return
    end
    select((index - col_max) % item_max)
  end
  
  def cursor_right(wrap = false)
    if @size_item_move
      super(true)
      return
    end
    correction = 1
    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)
    inndex = (index + correction) % item_max
    if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
      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]
      select(inndex)
      return
    end
    select((index + correction) % item_max)
  end
 
  def cursor_left(wrap = false)
    if @size_item_move
      super(true)
      return
    end
    inndex = (index - 1 + item_max) % item_max
    if  $game_party.party_grid[inndex % $game_system.lune_grid_size[0]][inndex / $game_system.lune_grid_size[0]].is_a?(Array)
      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]
      select(inndex)
      return
    end
    select((index - 1 + item_max) % item_max)
  end  
 
  def selected_item
    return false unless $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]].is_a?(Array)
    case $game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][0]
      when 1
        return $data_items[$game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][1]]
      when 2
        return $data_weapons[$game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][1]]
      when 3
        return $data_armors[$game_party.party_grid[@index % $game_system.lune_grid_size[0]][@index / $game_system.lune_grid_size[0]][1]]
    end
  end
 
end
#==============================================================================

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎