Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # CARDGAME CARDSHOP
- # Author: pencilcase27
- # Version: v1.01
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # v1.00 - Script released
- # v1.01 - Changed the way inventory is handled
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Description
- #
- # This script is an addon to my CardGame Skill/Battle System. It allows to set
- # up card shops that have a limited amount of cards for sale.
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Script Calls
- #
- # open_card_shop(shop_ID, purchase_only)
- # Opens the given shop. purchase_only can be either true or false.
- #
- # reset_shop(id)
- # Resets the given shops inventory.
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Note Tags
- #
- # <card price: x>
- # Add this tag to skills to set up their buing price.
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- module PC27
- module CardShop
- #-------------------------------------------------------------------------------
- #
- # Options
- #
- #-------------------------------------------------------------------------------
- # For how much of the original value do you want to sell cards?
- SELL_PRICE = 0.5
- # When you sold a card, do you want to add it to the shops inventory?
- STORE_SOLD_CARDS = true
- # Each shop can hava a short text displayed.
- SHOP_TEXT = {
- 1 => "RED Shop",
- 2 => "BLUE Shop",
- }
- # Options for this text.
- SHOP_TEXT_SIZE = 48
- SHOP_TEXT_BOLD = false
- SHOP_TEXT_ITALIC = true
- # Initial inventory of each shop. -1 means that the card can be bought as
- # many times as you want.
- SHOPS_CONTENT = {
- 1 => { 3 => 4,
- 4 => 6,
- 10 => 2,
- 5 => -1,
- 9 => -1, },
- 2 => { 6 => 6,
- 7 => 7,
- 8 => 8,
- 9 => 9,
- 10 => 10, },
- }
- #-------------------------------------------------------------------------------
- #
- # End Options
- #
- #-------------------------------------------------------------------------------
- end #CG
- end #PC27
- ################################################################################
- # Start of script #
- ################################################################################
- $imported = {} if $imported.nil?
- $imported["PC27: CardShop"] = true
- class RPG::UsableItem < RPG::BaseItem
- attr_accessor :card_price
- #-----------------------------------------------------------------------------
- # Add card attributes
- #-----------------------------------------------------------------------------
- alias load_notetags_pc27_cardgame_skill_shop load_notetags_pc27_cardgame_skill
- def load_notetags_pc27_cardgame_skill
- load_notetags_pc27_cardgame_skill_shop
- @card_price = 0
- self.note.split(/[\r\n]+/).each { |line|
- if /<card[ -_]price: +(?<pnr>\d+)>/i =~ line
- @card_price = pnr.to_i
- end
- }
- end
- end
- module DataManager
- class << self
- alias pc27_cardshop_data_manager_create_game_objects create_game_objects
- alias pc27_cardshop_data_manager_make_save_contents make_save_contents
- alias pc27_cardshop_data_manager_extract_save_contents extract_save_contents
- end
- def self.create_game_objects
- pc27_cardshop_data_manager_create_game_objects
- dummy = Marshal.load(Marshal.dump(PC27::CardShop::SHOPS_CONTENT))
- $game_card_shops = dummy
- end
- def self.make_save_contents
- contents = pc27_cardshop_data_manager_make_save_contents
- contents[:card_shops] = $game_card_shops
- contents
- end
- def self.extract_save_contents(contents)
- pc27_cardshop_data_manager_extract_save_contents(contents)
- if contents[:card_shops]
- $game_card_shops = contents[:card_shops]
- else
- dummy = Marshal.load(Marshal.dump(PC27::CardShop::SHOPS_CONTENT))
- $game_card_shops = dummy
- end
- end
- end
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * CardShop Processing
- #--------------------------------------------------------------------------
- def open_card_shop(shop_ID, purchase_only)
- return if $game_party.in_battle
- SceneManager.call(Scene_CardShop)
- SceneManager.scene.prepare(shop_ID, purchase_only)
- Fiber.yield
- end
- def reset_shop(id)
- $game_card_shops[id] = {}
- PC27::CardShop::SHOPS_CONTENT[id].each_key { |key|
- $game_card_shops[id][key] = PC27::CardShop::SHOPS_CONTENT[id][key]
- }
- end
- end
- class Scene_CardShop < Scene_MenuBase
- include PC27::CardShop
- #--------------------------------------------------------------------------
- # * Prepare
- #--------------------------------------------------------------------------
- def prepare(id, purchase_only)
- @id = id
- @purchase_only = purchase_only
- end
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- create_help_window
- create_gold_window
- create_command_window
- create_buy_window
- create_sell_window
- end
- def create_background
- super
- return unless SHOP_TEXT[@id]
- text = SHOP_TEXT[@id]
- width = Graphics.width - 210
- height = Graphics.height * 0.5
- @background_sprite.bitmap.font.size = SHOP_TEXT_SIZE
- @background_sprite.bitmap.font.italic = SHOP_TEXT_ITALIC
- @background_sprite.bitmap.font.bold = SHOP_TEXT_BOLD
- @background_sprite.bitmap.draw_text(0, 0, width, height, text, 1)
- end
- #--------------------------------------------------------------------------
- # * Create CardHelp Window
- #--------------------------------------------------------------------------
- def create_help_window
- @help_window = Window_CardHelp.new
- @help_window.viewport = @viewport
- end
- #--------------------------------------------------------------------------
- # * Create Gold Window
- #--------------------------------------------------------------------------
- def create_gold_window
- @gold_window = Window_Gold.new
- @gold_window.viewport = @viewport
- @gold_window.x = Graphics.width - @gold_window.width
- @gold_window.y = Graphics.height - @gold_window.height
- end
- #--------------------------------------------------------------------------
- # * Create Command Window
- #--------------------------------------------------------------------------
- def create_command_window
- @command_window = Window_ShopCommand.new(@gold_window.x, @purchase_only)
- @command_window.viewport = @viewport
- @command_window.y = Graphics.height - @command_window.height
- @command_window.set_handler(:buy, method(:command_buy))
- @command_window.set_handler(:sell, method(:command_sell))
- @command_window.set_handler(:cancel, method(:return_scene))
- end
- #--------------------------------------------------------------------------
- # * Create Purchase Window
- #--------------------------------------------------------------------------
- def create_buy_window
- wh = Graphics.height - @command_window.height
- @buy_window = Window_CardShopBuy.new(0, 0, wh, @id)
- @buy_window.viewport = @viewport
- @buy_window.help_window = @help_window
- @buy_window.hide
- @buy_window.set_handler(:ok, method(:on_buy_ok))
- @buy_window.set_handler(:cancel, method(:on_buy_cancel))
- end
- #--------------------------------------------------------------------------
- # * Create Sell Window
- #--------------------------------------------------------------------------
- def create_sell_window
- h = Graphics.height - @command_window.height
- @sell_window = Window_CardShopSell.new(0, 0, Graphics.width * 0.5, h)
- @sell_window.viewport = @viewport
- @sell_window.help_window = @help_window
- @sell_window.hide
- @sell_window.set_handler(:ok, method(:on_sell_ok))
- @sell_window.set_handler(:cancel, method(:on_sell_cancel))
- end
- #--------------------------------------------------------------------------
- # * Activate Purchase Window
- #--------------------------------------------------------------------------
- def activate_buy_window
- @help_window.draw_card_pic(@buy_window.item)
- @buy_window.refresh
- @buy_window.show.activate
- end
- #--------------------------------------------------------------------------
- # * Activate Sell Window
- #--------------------------------------------------------------------------
- def activate_sell_window
- @help_window.draw_card_pic(@sell_window.item)
- @sell_window.refresh
- @sell_window.show.activate
- end
- #--------------------------------------------------------------------------
- # * [Buy] Command
- #--------------------------------------------------------------------------
- def command_buy
- activate_buy_window
- end
- #--------------------------------------------------------------------------
- # * [Sell] Command
- #--------------------------------------------------------------------------
- def command_sell
- activate_sell_window
- end
- #--------------------------------------------------------------------------
- # * Buy [OK]
- #--------------------------------------------------------------------------
- def on_buy_ok
- @item = @buy_window.item
- $game_party.lose_gold(@item.card_price)
- $game_party.coll.push(@item)
- @buy_window.remove_card(@item.id)
- @buy_window.activate
- @gold_window.refresh
- end
- #--------------------------------------------------------------------------
- # * Buy [Cancel]
- #--------------------------------------------------------------------------
- def on_buy_cancel
- @command_window.activate
- @buy_window.hide
- @help_window.draw_card_pic(nil)
- end
- #--------------------------------------------------------------------------
- # * Sell [OK]
- #--------------------------------------------------------------------------
- def on_sell_ok
- @item = @sell_window.item
- for i in (0...$game_party.coll.length)
- if $game_party.coll[i].id == @item.id
- $game_party.coll.delete_at(i)
- break
- end
- end
- add_card(@item.id) if STORE_SOLD_CARDS
- $game_party.gain_gold((@item.card_price * SELL_PRICE).round)
- @sell_window.refresh
- @sell_window.activate
- @gold_window.refresh
- end
- def add_card(card_id)
- if $game_card_shops[@id].has_key?(card_id)
- $game_card_shops[@id][card_id] += 1 unless $game_card_shops[@id][card_id] == -1
- else
- $game_card_shops[@id][card_id] = 1
- end
- end
- #--------------------------------------------------------------------------
- # * Sell [Cancel]
- #--------------------------------------------------------------------------
- def on_sell_cancel
- @command_window.activate
- @sell_window.hide
- @help_window.draw_card_pic(nil)
- end
- end
- class Window_CardShopBuy < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, height, shop_ID)
- super(x, y, window_width, height)
- @shop_ID = shop_ID
- refresh
- select(0)
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return Graphics.width - 210
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 1
- end
- #--------------------------------------------------------------------------
- # * Get Item
- #--------------------------------------------------------------------------
- def item
- @data[index]
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # * Display in Enabled State?
- #--------------------------------------------------------------------------
- def enable?(item)
- item && item.card_price <= $game_party.gold
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- #--------------------------------------------------------------------------
- # * Create Item List
- #--------------------------------------------------------------------------
- def make_item_list
- @stock = {}
- @data = []
- $game_card_shops[@shop_ID].each_key do |key|
- next if $game_card_shops[@shop_ID][key] == 0
- @data.push($data_skills[key])
- @stock[key] = $game_card_shops[@shop_ID][key]
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- rect = item_rect(index)
- draw_item_name(item, rect.x, rect.y, enable?(item))
- rect.width -= 4
- text = item.card_price.to_s
- draw_text(rect, text, 2)
- rect.x += rect.width * 0.7
- amount = (@stock[item.id] == -1 ? "" : "x" + @stock[item.id].to_s)
- draw_text(rect, amount, 0)
- end
- #--------------------------------------------------------------------------
- # * Update Cards
- #--------------------------------------------------------------------------
- def remove_card(id)
- $game_card_shops[@shop_ID][id] -= 1 if $game_card_shops[@shop_ID][id] > 0
- refresh
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item) if @help_window
- end
- end
- class Window_CardShopSell < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super(x, y, window_width, height)
- refresh
- select(0)
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return Graphics.width - 210
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 1
- end
- #--------------------------------------------------------------------------
- # * Get Item
- #--------------------------------------------------------------------------
- def item
- @data[index]
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # * Display in Enabled State?
- #--------------------------------------------------------------------------
- def enable?(item)
- item && item.card_price > 0
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- #--------------------------------------------------------------------------
- # * Create Item List
- #--------------------------------------------------------------------------
- def make_item_list
- $game_party.coll.sort! { |a,b| a.card_id <=> b.card_id }
- @stock = {}
- @data = []
- @price = {}
- $game_party.coll.each do |card|
- if @data.include?(card)
- @stock[card] += 1
- else
- @data.push(card)
- @stock[card] = 1
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- rect = item_rect(index)
- draw_item_name(item, rect.x, rect.y, enable?(item))
- rect.width -= 4
- text = (item.card_price * PC27::CardShop::SELL_PRICE).round.to_s
- draw_text(rect, text, 2)
- rect.x += rect.width * 0.7
- text = "x" + @stock[item].to_s
- draw_text(rect, text, 0)
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item) if @help_window
- end
- end
- ################################################################################
- # End of script #
- ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement