Dynamic Currencies

4 de setembro de 2012

Dynamic Currencies é um script que foi concebido por SephirothSpawn para simular várias moedas e taxas de câmbios opcionais, em um jogo do RPG Maker XP. Com ele, você pode selecionar os valores monetários iniciais, bem como modificar seus valores durante o jogo.

A apresentação deste script parece mais um texto de Economia heheheh!

Você tem a opção de usar moedas “Dynamic”, onde o seu grupo vai carregar mais de uma moeda, ou uma a forma não-dinâmica, onde o registro de apenas uma moeda será realizada em um tempo. Nesta forma, quando a moeda é trocada, sua antiga moeda será automaticamente convertida para a nova moeda, baseada na taxa de câmbio atual.

Também tem a opção deixar o script afetando apenas os drops de gold dos monstros, bem como preços das lojas, onde o preço normal é multiplicado pelo valor da moeda. Isto pode ser útil para prevenir que o jogador ir para a batalha em uma zona de alto valor, a fim de abusar nos drops e ao comprar e vender itens.

Como o “Value” Funciona

Lower Value significa que a moeda vale menos. Um valor de 0,5 significaria que a cada 2 de alguma moeda específica vale 1 da moeda básica.

Fórmula Para Conversões

Indo de N da moeda A com valor X para a moeda B com valor Y:

currency_b = (value_x / 1.0) / (value_y / 1.0) * N

Instruções

Você precisa do SDK para usar este script. Coloque o código do Dynamic Currencies abaixo dele e acima do “Main”.

Para personalize suas moedas, consulte as instruções de personalização nos comentários do script. Consulte a lista de sintaxe para mais instruções.

#==============================================================================
# ** Dynamic Currencies
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2006-09-10
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to simulate multiple currencies and optional
#   exchange rates. You may select starting currency values as well as modify
#   their values during game play. You have the option to use "Dynamic"
#   currencies, where your party will carry more than one currency, or a
#   non-dynamic form, where the record of only one currency will be held at a
#   time. In this form, when currency is exchanged, your old currency will
#   automatically be converted to the new currency with their current exchange
#   rates. 
#
#   You also have the option of affect monster gold drops, as well as
#   shop prices, where the normal price is multipled by the currency value.
#   This prevents people to battle in a high valued zone in order to abuse
#   monster drops, as well as buying and selling to gain gold.
#
#   ** How the "Value" Works. **
#
#   Lower Value means that the currency is worth less. A value of 0.5 would
#   mean that every 2 of that specific currency is 1 of the basic currency.
#
#   ** Formula For Conversions:
#
#   Going From N Currency A with Value X to Currency B with Value Y
#
#     currency_b = (value_x / 1.0) / (value_y / 1.0) * N
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#   To Customize your currencies, refer to the customization instructions.
#   Refer to syntax listing for further instructions.
#------------------------------------------------------------------------------
# * Customization :
#
#   Setting Currency Starting Values (0 as currency name for default gold)
#    - Exchange_Rates = {'currency_name' => value, ...}
#
#   Setting Dynamic Currency Flag (See Description)
#    - Dynamic = ture (DYNAMIC) or false (NON-DYNAMIC)
#
#   Affect Monster Drops
#    - Affect_Monster_Drops = true (ON) or false (OFF)
#
#   Affect Shop Values
#    - Affect_Shop_Values = true (ON) or false (OFF)
#------------------------------------------------------------------------------
# * Syntax :
#
#   Reading or Modifing Currency Values
#    - $game_currencies.exchange_rates['currency_name']
#
#   Switching Current Currency
#    - $game_currencies.switch_currency('currency_name')
#
#   Reading Currency Exchange Rate (NOT VALUE)
#    - $game_currencies.exchange_rate('currency_name')
#
#   Retrieving Current Currency Name
#    - $game_currencies.currency_name
#
#   Retrieving Number of Certain Currency Saved (Dynamic Use Only)
#    - $game_party.currency_number('currency_name')
#
#   Exchanging From Currency A to B (Dynamic Use Only)
#    - $game_party.exchange_currency('currency_a', 'currency_b', amount)
#
#   * At any time, 0 as a 'currency_name' will reflect the default RMXP gold.
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Dynamic Currencies', 'SephirothSpawn', 1, '2006-09-10')

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state('Dynamic Currencies')

#==============================================================================
# ** Dynamic_Currencies
#==============================================================================

module Dynamic_Currencies
  #--------------------------------------------------------------------------
  # * Exchange Rates
  #
  #  ~ Exchange_Rates = { currency_name => value , ...}
  #
  # ** Formula For Conversions:
  #
  #    Going From N Currency A with Value X to Currency B with Value Y
  #
  #    (value_x / 1.0) / (value_y / 1.0) * N
  #
  # ** Lower the value use more money, Higher value use less money.
  # ** These are only starting values, as you can change them mid-game
  #--------------------------------------------------------------------------
  Exchange_Rates = {
    0           => 1.0,
    'Dyn Cur A' => 1.4,
    'Dyn Cur B' => 0.75,
    'Dyn Cur C' => 0.50
  }
  #--------------------------------------------------------------------------
  # * Dynamic
  #
  #  ~ When True
  #    When you switch from currency a to b, a is saved and all b currency
  #    is pulled from the memory. This allows the actors to hold more than
  #    one type of currency at a time.
  #
  #  ~ When False
  #    When you switch from currency a to b all a will be turned to b, 
  #    leaving no record for the a amount.
  #--------------------------------------------------------------------------
  Dynamic = false
  #--------------------------------------------------------------------------
  # * Affect Monster Drops
  #
  #  ~ When True
  #    Monsters gold drops will be multipled by the current currency value
  #
  #  ~ When False
  #    Monsters gold dropws will remain unaffected
  #--------------------------------------------------------------------------
  Affect_Monster_Drops = true
  #--------------------------------------------------------------------------
  # * Affect Shop Values
  #
  #  ~ When True
  #    Shop prices will bemultipled by the current currency value
  #
  #  ~ When False
  #    Shop prices will remain unaffected
  #--------------------------------------------------------------------------
  Affect_Shop_Values = true
end

#==============================================================================
# ** Game_Currencies
#==============================================================================

class Game_Currencies
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :current_currency
  attr_accessor :exchange_rates
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Sets Starting Exchange Rates
    @exchange_rates = Dynamic_Currencies::Exchange_Rates.dup
    # Sets Current Currency Flag
    @current_currency = 0
  end
  #--------------------------------------------------------------------------
  # * Switch Currency
  #--------------------------------------------------------------------------
  def switch_currency(currency_name)
    # Stop if same currency
    return if @current_currency == currency_name
    # Switch Currency In Party
    $game_party.switch_currency(currency_name)
    # Switch Current Currency Flag
    @current_currency = currency_name
    # Switch Currency Name
    $data_system.words.gold = currency_name
  end
  #--------------------------------------------------------------------------
  # * Exchange Rate
  #--------------------------------------------------------------------------
  def exchange_rate(currency_name = @current_currency)
    # Sets Default Currency Value if not specified
    unless @exchange_rates.has_key?(currency_name)
      @exchange_rates[currency_name] = 1.0
    end
    # Return Currency Value
    return @exchange_rates[currency_name] / 1.0
  end
  #--------------------------------------------------------------------------
  # * Currency Name
  #--------------------------------------------------------------------------
  def currency_name
    if @current_currency == 0
      return load_data("Data/System.rxdata").words.gold
    end
    return @current_currency
  end
end

#==============================================================================
# ** Game_Party
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_dyncur_gmprty_init initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Original Initialization
    seph_dyncur_gmprty_init
    # Saves Currency Counter (Used For Dynamic Currencies)
    @dynamic_currencies = {}
  end
  #--------------------------------------------------------------------------
  # * Currency Number
  #--------------------------------------------------------------------------
  def currency_number(currency = 0)
    # If Current Currency
    return @gold if currency == @current_currency
    # Sets Currency to 0 if none saved
    unless @dynamic_currencies.has_key?(currency)
      @dynamic_currencies[currency] = 0 
    end
    # Returns Currency Value
    return @dynamic_currencies[currency]
  end
  #--------------------------------------------------------------------------
  # * Switch Currency
  #--------------------------------------------------------------------------
  def switch_currency(new_currency = 0)
    # If Dynamic Currencies
    if Dynamic_Currencies::Dynamic
      # Saves Current Currency
      if @dynamic_currencies.has_key?($game_currencies.current_currency)
        @dynamic_currencies[$game_currencies.current_currency] += @gold
      else
        @dynamic_currencies[$game_currencies.current_currency] = @gold
      end
      # Switches to New Currency
      @gold = currency_number(new_currency)
    # If Non-Dynamic Currencies
    else
      # Collect Current Currency Exchage Rate
      c_rate = $game_currencies.exchange_rate
      n_rate = $game_currencies.exchange_rate(new_currency)
      # Switch Gold
      @gold = Integer(@gold * c_rate / n_rate)
    end
  end
  #--------------------------------------------------------------------------
  # * Exchange Currency
  #--------------------------------------------------------------------------
  def exchange_currency(currency_a, currency_b, amount = nil)
    # Returning If Same Currency Or Non-Dynamic Currencies
    return if currency_a == currency_b || !Dynamic_Currencies::Dynamic
    # If Amount is Nil (ALL)
    if amount.nil?
      # Get All Currency A Value
      amount = currency_number(currency_a)
    end
    # Return if amount of currency a is 0
    return if amount == 0
    # Cap Amount if greater than amount saved
    amount = [amount, currency_number(currency_a)].min
    # Collects Exchange Rates
    a_rate = $game_currencies.exchange_rate(currency_a)
    b_rate = $game_currencies.exchange_rate(currency_b)
    # Start Currency B Counter if none exist
    unless @dynamic_currencies.has_key?(currency_b)
      @dynamic_currencies[currency_b] = 0 
    end
    # Subtracts Currency A Amount
    @dynamic_currencies[currency_a] -= amount
    # Increased Currency B Amount
    @dynamic_currencies[currency_b] += (amount * a_rate / b_rate)
    # If Either Currency is Active Currency, effect current gold count
    if currency_a == @current_currency
      @gold -= amount
    elsif currency_b == @current_currency
      @gold += (amount * a_rate / b_rate)
    end
  end
end

#==============================================================================
# ** Game_Enemy
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Get Gold
  #--------------------------------------------------------------------------
  alias seph_dyncur_gmeny_gold gold
  def gold
    # Collect Original Gold Value
    n = seph_dyncur_gmeny_gold
    # If Dynamic Enemy Gold Drops
    if Dynamic_Currencies::Affect_Monster_Drops
      # Calulate Currency Drop
      n = Integer(n * $game_currencies.exchange_rate)
    end
    # Return Gold Drop
    return n
  end
end

#==============================================================================
# ** RPG::Item
#==============================================================================

class RPG::Item
  #--------------------------------------------------------------------------
  # * Price
  #--------------------------------------------------------------------------
  if @seph_dyncur_price.nil?
    alias seph_dyncur_rpgi_price price
    @seph_dyncur_price = true
  end
  def price
    # Collect Original Price
    n = seph_dyncur_rpgi_price
    return n if $game_currencies.nil?
    # If Dynamic Shop Prices
    if Dynamic_Currencies::Affect_Shop_Values
      # Calulate Shop Price
      n = Integer(n * $game_currencies.exchange_rate)
    end
    # Return Shop Price
    return n
  end
end

#==============================================================================
# ** RPG::Weapon
#==============================================================================

class RPG::Weapon
  #--------------------------------------------------------------------------
  # * Price
  #--------------------------------------------------------------------------
  alias seph_dyncur_rpgw_price price
  def price
    # Collect Original Price
    n = seph_dyncur_rpgw_price
    return n if $game_currencies.nil?
    # If Dynamic Shop Prices
    if Dynamic_Currencies::Affect_Shop_Values
      # Calulate Shop Price
      n = Integer(n * $game_currencies.exchange_rate)
    end
    # Return Shop Price
    return n
  end
end

#==============================================================================
# ** RPG::Armor
#==============================================================================

class RPG::Armor
  #--------------------------------------------------------------------------
  # * Price
  #--------------------------------------------------------------------------
  alias seph_dyncur_rpga_price price
  def price
    # Collect Original Price
    n = seph_dyncur_rpga_price
    return n if $game_currencies.nil?
    # If Dynamic Shop Prices
    if Dynamic_Currencies::Affect_Shop_Values
      # Calulate Shop Price
      n = Integer(n * $game_currencies.exchange_rate)
    end
    # Return Shop Price
    return n
  end
end


#==============================================================================
# ** Scene_Title
#==============================================================================

class Scene_Title
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_dyncur_scnttl_cng command_new_game
  #--------------------------------------------------------------------------
  # * Command : New Game
  #--------------------------------------------------------------------------
  def command_new_game
    # Original Command New Game
    seph_dyncur_scnttl_cng
    # Creates Game Currencies Game Data
    $game_currencies = Game_Currencies.new
  end
end

#==============================================================================
# ** Scene_Save
#==============================================================================

class Scene_Save
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_gmlngs_scnsave_wd write_data
  #--------------------------------------------------------------------------
  # * Command : New Game
  #--------------------------------------------------------------------------
  def write_data(file)
    # Original Write Data
    seph_gmlngs_scnsave_wd(file)
    # Saves Game Currencies Data
    Marshal.dump($game_currencies, file)
  end
end

#==============================================================================
# ** Scene_Load
#==============================================================================

class Scene_Load
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_dyncur_scnload_rd read_data
  #--------------------------------------------------------------------------
  # * Command : New Game
  #--------------------------------------------------------------------------
  def read_data(file)
    # Original Write Data
    seph_dyncur_scnload_rd(file)
    # Loads Game Currencies Data
    $game_currencies = Marshal.load(file)
    # Switches Gold Name
    $data_system.words.gold = $game_currencies.currency_name
  end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Clique aqui e saiba como. Obrigado!

Deixe um comentário

Inscreva-se na nossa newsletter!