=begin CSCA Currency System version: 1.1.0 (Released: May 3, 2013) Created by: Casper Gaming (https://www.caspergaming.com/) Compatibility: Made for RPGVXAce IMPORTANT: ALL CSCA Scripts should be compatible with each other unless otherwise noted. FFEATURES Creates a currency system that allows you to easily set up and use as many currencies as your game needs. SETUP Set up required. Instructions below. ================================================================================ UPDATES version 1.0.1 - Added support for CSCA Extra Stats version 1.0.2 - Fixed bug with the gold window not updating currency when called from message window. version 1.0.3 - Added support for CSCA Difficulty System. Paste that script ABOVE this one. version 1.1.0 - Fixed bug that caused currency window to activate when non-moneypouch items were used. ================================================================================ CREDIT and TERMS: Please visit https://www.caspergaming.com/terms-of-use/ for terms of use and credit guidelines =end module CSCA module CURRENCY CURRENCIES = [] #============================================================================== # ** Important Script Calls #============================================================================== # All script calls use the currency symbol to reference a currency. #------------------------------------------------------------------------------ # switch_currency(currency) # Used to change the current currency to [currency]. # # get_current_currency # Returns the current currency's symbol. For use in event conditional branches. # # exchange_currency(currency1, currency2, amount) # Exchanges the [amount] of [currency1] for [currency2]. Takes into consideration # currency values. For example if 100 of currency 1 (value of 1), for # currency 2 (value of 2), the result will be 200 of currency 2 gained. # # iv_exchange_currency(currency1, currency2, amount1, amount2) # Exchanges currencies, ignoring their value. Simply removes [amount1] from # [currency1] and adds [amount2] to [currency2]. # # gain_currency(currency, amount) # Gains [amount] of [currency]. # # lose_currency(currency, amount) # Loses [amount] of [currency]. # # discover_currency(currency[, boolean]) # Sets the [currency]'s discovered status to [boolean] (aka true or false). # Including the boolean parameter is optional; if not specified, true is assumed. #============================================================================== # ** Note Tags Guide #============================================================================== # # This tag goes in an item's note box. When this item is selected from the item # menu, it will open a new window with all the discovered currencies and amounts # listed. # # # This tag goes in an enemy's note box. This determines which currency the # enemy drops. Replace x with the currency symbol for the currency you want to # drop. This tag is required for all enemies. # # # This tag goes in an item's note box. This determines which currency a shop # will sell the item for if you don't force the shop to use a specific currency. # Replace x with a currency symbol. This tag is required for all items, weapons, # and armors. #============================================================================== # ** Default Event Command Notes #============================================================================== # The change gold event command will only affect the currency in use. To change # amounts of other currencies, use the script calls above. # # You can force a shop to use a specific currency by controlling the variables # set below. Otherwise, the shop will use whatever currency the item has tagged. # More information below. #============================================================================== # ** Begin Setup #============================================================================== ALLOW_CHANGE = true # Allow player to change currencies from pouch? CHANGE_TEXT = "Currency changed to:" # Text to display when changing currency. Vocab_ObtainGold = "%s %s found!" # Text shown for battle gold drop. Overwrites Vocab::ObtainGold HEADER = "Currency Exchange" # Header text shown at top of Currency Exchange. CUR_VAR = 21 # Variable. In game, set to a currency ID to force a shop to only # use that currency. Set the variable to a negative number to turn # off currency forcing. SELL_CUR_VAR = 22 # Variable. In game, set to a currency ID to force a shop to # only buy items from the player in that currency. Set the variable # to a negative number to turn off sell currency forcing. SELL_PERC = 23 # Variable. In game, change this variable to a value between # 0-100 to change the shop sellback % to that value. #======================== # CURRENCY SETUP #======================== # EXAMPLE #--------- #CURRENCIES[x] = { # where the 'x' is the currency id. #:name => "Gold", # The name of the currency. String. #:currency_unit => "G", # The currency unit shown next to the amount. #:icon => 361, # The icon associated with the currency. #:color => Color.new(207,181,59), # The color of the currency's text in RGBA #:amount => 100, # The amount the player starts with of this currency. #:max => 99999999, # The max amount of this currency the player can have. #:value => 1, # The value of the currency. Lower number = less valuable #:discovered => true, # true/false, determines whether to show the currency to the player. #:desc => "Gold is a currency primarily reserved for royalty.", # Short description of the currency. #:sym => :g # Currency symbol. Used in script calls to refer to this currency. #} CURRENCIES[0] = { :name => "Gold", :currency_unit => "G", :icon => 361, :color => Color.new(207,181,59), :amount => 100, :max => 99999999, :value => 4, :discovered => true, :desc => "Gold is a currency primarily reserved for royalty.", :sym => :g } CURRENCIES[1] = { :name => "Silver", :currency_unit => "S", :icon => 549, :color => Color.new(230,232,250), :amount => 399, :max => 99999999, :value => 2, :discovered => true, :desc => "A rare metal, silver is not often used as currency.", :sym => :s } CURRENCIES[2] = { :name => "Copper", :currency_unit => "C", :icon => 548, :color => Color.new(184,115,51), :amount => 800, :max => 99999999, :value => 1, :discovered => true, :desc => "Copper is the money of the peasant.", :sym => :c } #============================================================================== # ** End Setup #============================================================================== end end $imported = {} if $imported.nil? $imported["CSCA-CurrencySystem"] = true #============================================================================== # ** Vocab #------------------------------------------------------------------------------ # Alters the currency unit method and ObtainGold constant. #Aliases: currency_unit #============================================================================== module Vocab ObtainGold = CSCA::CURRENCY::Vocab_ObtainGold #-------------------------------------------------------------------------- # Alias Method; currency_unit #-------------------------------------------------------------------------- class <= 0 ? @data[index] : nil end #-------------------------------------------------------------------------- # Create Item List #-------------------------------------------------------------------------- def make_item_list @data = $game_party.currencies.select {|item| include?(item)} end #-------------------------------------------------------------------------- # Include item in list? #-------------------------------------------------------------------------- def include?(item) item[:discovered] end #-------------------------------------------------------------------------- # Draw Item #-------------------------------------------------------------------------- def draw_item(index) item = @data[index] if item rect = item_rect(index) rect.width -= 4 draw_currencies(item, rect.x, rect.y) end end #-------------------------------------------------------------------------- # Draw currency #-------------------------------------------------------------------------- def draw_currencies(currency, x, y) draw_icon(currency[:icon], x, y) change_color(system_color) draw_text(x+24, y, 172, line_height, currency[:name] + ":") change_color(currency[:color]) draw_text(x+24, y, 172, line_height, currency[:amount], 2) end #-------------------------------------------------------------------------- # Refresh #-------------------------------------------------------------------------- def refresh make_item_list create_contents draw_all_items end #-------------------------------------------------------------------------- # Update Help Text #-------------------------------------------------------------------------- def update_help @help_window.set_text(item[:desc]) end #-------------------------------------------------------------------------- # Frame Update #-------------------------------------------------------------------------- def update super update_help if self.active end end #============================================================================== # ** Window_ShopBuy #------------------------------------------------------------------------------ # Changes price text based on currency of item. #Aliases: initialize, price, enable? #Overwrites: draw_item, money= #============================================================================== class Window_ShopBuy < Window_Selectable attr_accessor :currency attr_accessor :gold_window #-------------------------------------------------------------------------- # Alias Method; Object Initialization #-------------------------------------------------------------------------- alias :csca_cs_init :initialize def initialize(*args) csca_cs_init(*args) @currency = nil end #-------------------------------------------------------------------------- # Alias method; Get Price of Item #-------------------------------------------------------------------------- alias :csca_cs_price :price def price(item) item_price = csca_cs_price(item) return item_price if @currency.nil? if item_currency(item) != @currency modifier = (item_currency(item)[:value].to_f/@currency[:value]) item_price *= modifier end return item_price.to_i end #-------------------------------------------------------------------------- # Alias method; Display in Enabled State? #-------------------------------------------------------------------------- alias :csca_cs_enable? :enable? def enable?(item) csca_cs_enable?(item) && csca_currency_affordable?(item) end #-------------------------------------------------------------------------- # Other currency affordable? #-------------------------------------------------------------------------- def csca_currency_affordable?(item) price(item) <= get_currency_used(item)[:amount] end #-------------------------------------------------------------------------- # Overwrite Method; 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 draw_price(rect, item, 2) end #-------------------------------------------------------------------------- # Overwrite method; Make @money infinite to avoid overwriting other methods. #-------------------------------------------------------------------------- def money=(money) @money = 999999999999999999 refresh end #-------------------------------------------------------------------------- # Draw item price #-------------------------------------------------------------------------- def draw_price(rect, item, align) color = get_currency_used(item)[:color] cur_unit = get_currency_used(item)[:currency_unit] change_color(color) rect.width -= 12 draw_text(rect, price(item).to_s, align) rect.width += 12 change_color(system_color) draw_text(rect, cur_unit, align) end #-------------------------------------------------------------------------- # Get item currency #-------------------------------------------------------------------------- def item_currency(item) $game_party.get_csca_cs_currency(item.currency_symbol) end #-------------------------------------------------------------------------- # Determine currency in use #-------------------------------------------------------------------------- def get_currency_used(item) @currency.nil? ? item_currency(item) : @currency end #-------------------------------------------------------------------------- # Alias Method; Update Gold Window #-------------------------------------------------------------------------- alias :csca_cs_update_help :update_help def update_help csca_cs_update_help if @gold_window @gold_window.set_currency(get_currency_used(@data[index])) end end end #============================================================================== # ** Window_ShopSell #------------------------------------------------------------------------------ # Added handling for different currencies #Aliases: initialize #============================================================================== class Window_ShopSell < Window_ItemList attr_accessor :gold_window attr_reader :currency #-------------------------------------------------------------------------- # Alias Method; Object Initialization #-------------------------------------------------------------------------- alias :csca_cs_init :initialize def initialize(*args) csca_cs_init(*args) @currency = $game_party.current_currency end #-------------------------------------------------------------------------- # Set currency #-------------------------------------------------------------------------- def set_currency(currency) @currency = currency @gold_window.set_currency(@currency) end end #============================================================================== # ** Window_ShopNumber #------------------------------------------------------------------------------ # Added handling for multiple currencies. #Aliases: initialize #============================================================================== class Window_ShopNumber < Window_Selectable #-------------------------------------------------------------------------- # Alias Method; Object Initialization #-------------------------------------------------------------------------- alias :csca_cs_init :initialize def initialize(*args) csca_cs_init(*args) @currency = $game_party.current_currency end #-------------------------------------------------------------------------- # Overwrite Method; Draw Total Price #-------------------------------------------------------------------------- def draw_total_price width = contents_width - 8 draw_currency_value(@price * @number, @currency_unit, 4, price_y, width, @currency) end #-------------------------------------------------------------------------- # Set currency #-------------------------------------------------------------------------- def set_currency(currency) @currency = currency refresh end end #============================================================================== # ** Scene_ItemBase #------------------------------------------------------------------------------ # Special handling for moneypouch item. #Aliases: use_item #============================================================================== class Scene_ItemBase < Scene_MenuBase #-------------------------------------------------------------------------- # Alias Method; Use Item #-------------------------------------------------------------------------- alias :csca_cs_use_item :use_item def use_item csca_cs_use_item check_moneypouch if item.is_a?(RPG::Item) end #-------------------------------------------------------------------------- # Open Currency Window #-------------------------------------------------------------------------- def open_currency_window @item_window.unselect @item_window.close @currency_window.show @currency_window.activate end #-------------------------------------------------------------------------- # Exit Currency Window #-------------------------------------------------------------------------- def exit_currency_window @item_window.select_last @item_window.open @currency_window.hide @currency_window.deactivate end #-------------------------------------------------------------------------- # Handling if item is moneypouch #-------------------------------------------------------------------------- def check_moneypouch if item.csca_money_pouch? @currency_window.refresh open_currency_window end end end #============================================================================== # ** Scene_Item #------------------------------------------------------------------------------ # Creates currency window. #Aliases: start #============================================================================== class Scene_Item < Scene_ItemBase #-------------------------------------------------------------------------- # Alias Method; Start Processing #-------------------------------------------------------------------------- alias :csca_cs_start :start def start csca_cs_start csca_create_currency_window csca_create_notification_window end #-------------------------------------------------------------------------- # Create Currency Window #-------------------------------------------------------------------------- def csca_create_currency_window @currency_window = CSCA_Window_CurrencyDisplay.new(@item_window.x, @item_window.y, @item_window.width, @item_window.height) @currency_window.set_handler(:ok, method(:change_currency)) @currency_window.set_handler(:cancel, method(:exit_currency_window)) @currency_window.help_window = @help_window @currency_window.hide end #-------------------------------------------------------------------------- # Create Notification Window #-------------------------------------------------------------------------- def csca_create_notification_window @currency_changed_window = CSCA_Window_CurrencyChangeNotify.new @currency_changed_window.currency_window = @currency_window @currency_changed_window.hide end #-------------------------------------------------------------------------- # Change currency #-------------------------------------------------------------------------- def change_currency if CSCA::CURRENCY::ALLOW_CHANGE $game_party.switch_currency(@currency_window.item[:sym]) @currency_changed_window.refresh @currency_changed_window.show else exit_currency_window end end end #============================================================================== # ** Scene_Shop #------------------------------------------------------------------------------ # Adds support for multiple currencies #Aliases: prepare, create_buy_window, on_buy_ok, create_sell_window, # activate_sell_window, on_sell_ok #Overwrites: do_buy, selling_price, do_sell #============================================================================== class Scene_Shop < Scene_MenuBase #-------------------------------------------------------------------------- # Alias Method; Prepare #-------------------------------------------------------------------------- alias :csca_cs_prepare :prepare def prepare(goods, purchase_only) csca_cs_prepare(goods, purchase_only) csca_prepare_currency end #-------------------------------------------------------------------------- # Prepare Currency #-------------------------------------------------------------------------- def csca_prepare_currency @currency = nil @sell_currency = $game_party.current_currency @currency = $game_party.currencies[$game_variables[CSCA::CURRENCY::CUR_VAR]] unless $game_variables[CSCA::CURRENCY::CUR_VAR] < 0 @sell_currency = $game_party.currencies[$game_variables[CSCA::CURRENCY::SELL_CUR_VAR]] unless $game_variables[CSCA::CURRENCY::SELL_CUR_VAR] < 0 end #-------------------------------------------------------------------------- # Alias Method; set buy window currency #-------------------------------------------------------------------------- alias :csca_cs_buy_window :create_buy_window def create_buy_window csca_cs_buy_window @buy_window.gold_window = @gold_window end #-------------------------------------------------------------------------- # Alias method; Create Sell Window #-------------------------------------------------------------------------- alias :csca_cs_sell_window :create_sell_window def create_sell_window csca_cs_sell_window @sell_window.gold_window = @gold_window end #-------------------------------------------------------------------------- # Alias Method; Activate Purchase Window #-------------------------------------------------------------------------- alias :csca_cs_activate_buy :activate_buy_window def activate_buy_window @buy_window.currency = @currency csca_cs_activate_buy end #-------------------------------------------------------------------------- # Alias Method; Activate Sell Window #-------------------------------------------------------------------------- alias :csca_cs_activate_sell :activate_sell_window def activate_sell_window csca_cs_activate_sell @sell_window.set_currency(@sell_currency) end #-------------------------------------------------------------------------- # Alias Method; Buy [OK] #-------------------------------------------------------------------------- alias :csca_cs_buy_ok :on_buy_ok def on_buy_ok csca_cs_buy_ok @number_window.set_currency(@gold_window.currency) end #-------------------------------------------------------------------------- # Alias Method; Sell [OK] #-------------------------------------------------------------------------- alias :csca_cs_sell_ok :on_sell_ok def on_sell_ok @number_window.set_currency(@sell_currency) @buy_window.currency = @sell_currency csca_cs_sell_ok end #-------------------------------------------------------------------------- # Overwrite Method; Execute Purchase #-------------------------------------------------------------------------- def do_buy(number) $game_party.lose_currency(@gold_window.currency, number * buying_price) $game_party.gain_item(@item, number) csca_es_adjust_stats(:buy, number) if $imported["CSCA-ExtraStats"] end #-------------------------------------------------------------------------- # Overwrite Method; Execute Sale #-------------------------------------------------------------------------- def do_sell(number) $game_party.gain_currency(@gold_window.currency, number * selling_price) $game_party.lose_item(@item, number) csca_es_adjust_stats(:sell, number) if $imported["CSCA-ExtraStats"] end #-------------------------------------------------------------------------- # Overwrite Method; Get Sale Price #-------------------------------------------------------------------------- def selling_price (@buy_window.price(@item) * ($game_variables[CSCA::CURRENCY::SELL_PERC].to_f/100)).to_i end end #============================================================================== # ** RPG::BaseItem #------------------------------------------------------------------------------ # Get currency for items/enemies #============================================================================== class RPG::BaseItem #-------------------------------------------------------------------------- # Get currency symbol #-------------------------------------------------------------------------- def currency_symbol @note =~ //i ? $1.to_sym : "" end end #============================================================================== # ** RPG::Item #------------------------------------------------------------------------------ # Checks for moneypouch note tag. #============================================================================== class RPG::Item < RPG::UsableItem #-------------------------------------------------------------------------- # Item is moneypouch? #-------------------------------------------------------------------------- def csca_money_pouch? @note =~ //i end end