I have attempted to create a shop, this shop is going to use a specific currency. I wanted to understand the way the shop classes, scenes, windows and such worked so I attempted to go out and create my own. I am no where near it though. Thus I need your help.
Note: This script is based of, Tsukihime,
http://dl.dropboxusercontent.com/u/23043573/RPG%20Maker/RMVXA%20Scripts/Shop_Manager.txtCouple of issues:
- put @inventory.inspect will give me [[#<ClassObject>, #<ClassObject>]] instead of the items.
- when calling the scene to init the shop, I get an error on make_item_list, stating that .each doesn't exist. essentially it cant walk through an empty array.
This script composes of a series of classes that extend the parent, thus to reduce the need to re-write everything, but also allowing me to over ride, or use specific parent methods.
This script, for the time being is called as such:
## Create your items
$kc_shop.create_master_inventory(1, 1, 1, 10) #id (unique), #item_type, #item_id, #price
$kc_shop.create_master_inventory(2, 1, 2, 10) #id (unique), #item_type, #item_id, #price
## Open the shop window
GS.call_shop(GS.setup($kc_shop.get_inv)) #call the shop while passing the master inventory list to the shop window.
There are things that I am missing in the main script and some naming issues have arisen, I understand that. How ever The main issue I am trying to solve, aside from those out lined in the list above is why I am getting: undefined each for Nil:NilClass.
Its obvious to me, The inventory list is not being passed to the window, yet I assumed I took care of that in the GS.call_shop() method.
Note: This script is documented, how ever not deeply, near the end there is no documentation. I have created my own object for dealing with items called: Game_Guild_ShopObject
module GS
def self.setup(goods, purchase_only = false)
shop = Game_Guild_Shop.new(goods, purchase_only)
end
def self.call_shop(shop)
SceneManager.call(Scene_Guild_Shop)
SceneManager.scene.prepare(shop)
end
end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
# Create a new object called $kc_shop.
#==============================================================================
class << DataManager
#--------------------------------------------------------------------------
# * Create Game Objects
#--------------------------------------------------------------------------
alias kalacious_guild_shop_game_objects create_game_objects
def create_game_objects
kalacious_guild_shop_game_objects
$kc_shop = Game_Guild_ShopSetup.new
end
end
#==============================================================================
# ** Game_Guild_ShopSetup
#------------------------------------------------------------------------------
# Helps to set up the core shop it's self.
#==============================================================================
class Game_Guild_ShopSetup
attr_accessor :inventory_list
#--------------------------------------------------------------------------
# * Set up an empty array of inventory items
#--------------------------------------------------------------------------
def initialize
@inventory_list = []
end
#--------------------------------------------------------------------------
# * Create a master inventory list.
#--------------------------------------------------------------------------
def create_master_inventory(id, item_type, item_id, item_price)
inventory = make_inventory(id, item_type, item_id, item_price)
@inventory_list.push(inventory)
end
#--------------------------------------------------------------------------
# * Retieve the object.
#--------------------------------------------------------------------------
def get_inv
return @inventory_list
end
#--------------------------------------------------------------------------
# * Make the inventory.
#--------------------------------------------------------------------------
private
def make_inventory(id, item_type, item_id, item_price)
inventory = Game_Guild_ShopObject.new(id, item_type, item_id, item_price)
return inventory
end
end
#==============================================================================
# ** Game_Guild_ShopObject
#------------------------------------------------------------------------------
# This class is a wrapper for how the shops object stores the data about
# the items in the shop.
#==============================================================================
class Game_Guild_ShopObject
attr_reader :id
attr_reader :item_type
attr_reader :item_id
attr_reader :item_price
#--------------------------------------------------------------------------
# * Set up the objects
#--------------------------------------------------------------------------
def intialize(id, item_type, item_id, item_price)
@id = id
@item_type = item_type
@item_id = item_id
@item_price = item_price
end
#--------------------------------------------------------------------------
# * Return the $data_item, $data_weapons or $data_armor based on the id and
# the type.
#--------------------------------------------------------------------------
def guild_shop_item
return $data_items[@item_id] if @item_type == 0
return $data_weapons[@item_id] if @item_type == 1
return $data_armor[@item_id] if @item_type == 2
end
#--------------------------------------------------------------------------
# * Return the price.
#--------------------------------------------------------------------------
def get_guild_shop_price
return @price
end
end
#==============================================================================
# ** Game_Game_Shop
#------------------------------------------------------------------------------
# This class is responsible for dealing with the inventory of a guild shop.
# That is, we deal with the abillity to purchase only, the inventory, in
# regards to adding and deleting items and the abillity to, or the need for,
# the shop to be refreshed.
#==============================================================================
class Game_Guild_Shop
attr_reader :purchase_only
attr_reader :inventory
attr_accessor :refresh
#--------------------------------------------------------------------------
# * Set up the core shop.
#--------------------------------------------------------------------------
def initialize(goods, purchase_only = false)
@purchase_only = purchase_only
@inventory = goods
@refresh = false
end
#--------------------------------------------------------------------------
# * Return the inventory.
#--------------------------------------------------------------------------
def get_guild_shop_inventory
return @inventory
end
#--------------------------------------------------------------------------
# * Add a new item.
#--------------------------------------------------------------------------
def add_item(item)
@inventory.push(item) unless @inventory.include? (item)
end
#--------------------------------------------------------------------------
# * Delete an item based on id.
#--------------------------------------------------------------------------
def delete_item(item_id)
@inventory.delete_at(item_id-1)
end
end
class Window_Guild_Shop_Buy < Window_ShopBuy
def get_current_item
@inventory[item]
end
def make_item_list
@data = []
@items = {}
@price = {}
@inventory.each do |inventory|
item = inventory.item
@data.push(item)
@items[item] = inventory
@prive[item] = inventory.price
end
end
end
class Scene_Guild_Shop < Scene_Shop
def prepare(goods, purchase_only = false)
super
@inventory = goods
@purcahse_only = purchase_only
end
def create_buy_window
wy = @dummy_window.y
wh = @dummy_window.height
@buy_window = Window_Guild_Shop_Buy.new(0, wy, wh, @goods)
@buy_window.viewport = @viewport
@buy_window.help_window = @help_window
@buy_window.status_window = @status_window
@buy_window.hide
@buy_window.set_handler(:ok, method(:on_buy_ok))
@buy_window.set_handler(:cancel, method(:on_buy_cancel))
end
end