Advertisement
Guest User

Calestian's Multiple Currencies

a guest
Feb 19th, 2015
2,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.98 KB | None | 0 0
  1. #===========================================================================
  2. #    Author:   Calestian
  3. #    Name:     Multiple Currencies
  4. #    Created:  02-08-2015
  5. #    Version:  1.1
  6. #---------------------------------------------------------------------------
  7. #                       VERSION HISTORY
  8. #
  9. #    v1.0 - Initial Release
  10. #    v1.1 - Bug fix: gain_gold and lose_gold argument fix
  11. #---------------------------------------------------------------------------
  12. #                       DESCRIPTION
  13. #    
  14. #    User can set more than one different currencies.
  15. #
  16. #    There is a new Menu tab displaying all set currencies.
  17. #
  18. #    Shops can use only one currency.
  19. #
  20. #    Note: It is possible to set different shops to use different currencies.
  21. #---------------------------------------------------------------------------
  22. #                       LICENSE INFO
  23. #
  24. #    Free for commercial & non-commerical use as long as credit is given to
  25. #    Calestian.
  26. #---------------------------------------------------------------------------
  27. #                       How to Use
  28. #
  29. #    - Change Currencies in the module below to enter the icons and
  30. #      the starting value of each currency.
  31. #
  32. #    - To apply a currency to a shop, in the event window, before
  33. #      Shop Processing, add a scripted command (Advanced Tab):
  34. #      currency(Currency_ID)
  35. #      Currency_ID is taken from the module.
  36. #    
  37. #      Note: If a currency isn't set in the event window, the default
  38. #            currency is Currency_ID = 0
  39. #
  40. #    - To apply a currency gain or lose, in the event window, add
  41. #      a scripted command (Advanced Tab):
  42. #      add_currency(amount, Currency_ID) to apply a currency gain
  43. #      add_currency(-amount, Currency_ID) to apply a currency loss
  44. #  
  45. #      Example: In the event window, after a Battle Processing event
  46. #               add the scripted command: $game_party.gain_gold(100, 2)
  47. #               This will give the player 100 of Currency #2 after the
  48. #               Battle Processing event is finished.
  49. #===========================================================================
  50.  
  51. #===========================================================================
  52. # *** Editable Region
  53. #===========================================================================
  54. module Clstn_Currencies
  55.  
  56.   Currencies = {
  57.      
  58.     0  => [361, 0],
  59.     1  => [362, 0],
  60.     2  => [363, 0],
  61.     3  => [364, 0],
  62.     4  => [365, 0],
  63.     5  => [366, 0],
  64.     6  => [367, 0],
  65.     7  => [368, 0],
  66.     8  => [369, 0],
  67.     9  => [370, 0],
  68.     10 => [371, 0]
  69.  
  70.   }
  71.  
  72. end
  73.  
  74. #===========================================================================
  75. # *** End of Editable Region
  76. #===========================================================================
  77.    
  78. #===========================================================================
  79. # *** Class Window_MenuCommand
  80. #===========================================================================
  81. class Window_MenuCommand < Window_Command
  82.  
  83.   #-------------------------------------------------------------------------
  84.   # * Aliased Methods
  85.   #-------------------------------------------------------------------------
  86.   alias :clstn_add_main_commands_0003 add_main_commands
  87.  
  88.   #-------------------------------------------------------------------------
  89.   # * Method: add_main_commands
  90.   #-------------------------------------------------------------------------
  91.   def add_main_commands
  92.     clstn_add_main_commands_0003
  93.     add_command("Currencies",  :currencies,   main_commands_enabled)
  94.   end
  95.  
  96. end
  97.  
  98. #===========================================================================
  99. # ** Class Scene_Menu
  100. #===========================================================================
  101. class Scene_Menu < Scene_MenuBase
  102.  
  103.   #--------------------------------------------------------------------------
  104.   # * Start
  105.   #--------------------------------------------------------------------------
  106.   def start
  107.     super
  108.     create_command_window
  109.     create_status_window
  110.   end
  111.  
  112.   #-------------------------------------------------------------------------
  113.   # * Aliased Methods
  114.   #-------------------------------------------------------------------------
  115.   alias :clstn_create_command_window_0004 :create_command_window
  116.   alias :clstn_on_personal_ok_0008 :on_personal_ok
  117.  
  118.   #-------------------------------------------------------------------------
  119.   # * Method: create_command_window
  120.   #-------------------------------------------------------------------------
  121.   def create_command_window
  122.     clstn_create_command_window_0004
  123.     @command_window.set_handler(:currencies, method(:command_currencies))
  124.   end
  125.  
  126.    #-------------------------------------------------------------------------
  127.    # * Method: on_personal_ok
  128.    #-------------------------------------------------------------------------
  129.    def on_personal_ok
  130.     case @command_window.current_symbol
  131.     when :currencies
  132.       SceneManager.call(Scene_Currencies)
  133.     end
  134.     clstn_on_personal_ok_0008
  135.    end
  136.  
  137.    #-------------------------------------------------------------------------
  138.    # * Method: command_currencies
  139.    #-------------------------------------------------------------------------
  140.    def command_currencies
  141.       SceneManager.call(Scene_Currencies)
  142.    end
  143.  
  144. end
  145.  
  146. #===========================================================================
  147. # ** Class Scene_Currencies
  148. #===========================================================================
  149. class Scene_Currencies < Scene_MenuBase
  150.  
  151.   #-------------------------------------------------------------------------
  152.   # * Start
  153.   #-------------------------------------------------------------------------
  154.   def start
  155.     super
  156.     create_currencies_window
  157.   end
  158.  
  159.   #-------------------------------------------------------------------------
  160.   # * Method: create_currencies_window
  161.   #-------------------------------------------------------------------------
  162.   def create_currencies_window
  163.     @currencies_window = Window_Currencies.new
  164.     @currencies_window.viewport = @viewport
  165.     @currencies_window.set_handler(:cancel, method(:return_scene))
  166.     @currencies_window.activate
  167.   end
  168.  
  169. end
  170.  
  171. #===========================================================================
  172. # ** Class Window_Currencies
  173. #===========================================================================
  174. class Window_Currencies < Window_Selectable
  175.  
  176.   #-------------------------------------------------------------------------
  177.   # * Initialize
  178.   #-------------------------------------------------------------------------
  179.   def initialize
  180.     super(395, 0, 149, 416)
  181.     refresh
  182.   end
  183.  
  184.   #-------------------------------------------------------------------------
  185.   # * Method: value
  186.   #-------------------------------------------------------------------------
  187.   def value(currency_index = $game_temp.currency_index)
  188.     if currency_index == 0
  189.       $game_party.gold
  190.     else
  191.       $game_party.currency[currency_index]
  192.     end
  193.   end
  194.  
  195.   #-------------------------------------------------------------------------
  196.   # * Method: refresh
  197.   #-------------------------------------------------------------------------
  198.   def refresh
  199.     contents.clear
  200.     change_color(text_color(6))
  201.     draw_text(23, -4, 100, 30,"Currencies")
  202.     draw_horz_line(0, 6)
  203.     draw_horz_line(3, 6)
  204.     i = 0
  205.     Clstn_Currencies::Currencies.each_value { |hash|
  206.       icon_index = hash[0]
  207.       draw_horz_line(37 + (32 * i), 0)
  208.       currency_unit = draw_icon(icon_index, 100, 32 + (32 * i))
  209.       draw_currency_value(value(i), currency_unit, -19, 33 + (32 * i), contents.width - 8)
  210.       i += 1
  211.     }
  212.   end
  213.  
  214.   #-------------------------------------------------------------------------
  215.   # * Method: draw_horz_line
  216.   #-------------------------------------------------------------------------
  217.   def draw_horz_line(dy, color)
  218.     color = text_color(color)
  219.     line_y = dy + line_height - 4
  220.     contents.fill_rect(4, line_y, contents_width - 8, 3, Font.default_out_color)
  221.     contents.fill_rect(5, line_y + 1, contents_width - 10, 1, color)
  222.   end
  223.  
  224. end
  225. #===========================================================================
  226. # ** Class Window_Gold
  227. #===========================================================================
  228. class Window_Gold < Window_Base
  229.  
  230.   #--------------------------------------------------------------------------
  231.   # * Refresh
  232.   #--------------------------------------------------------------------------
  233.   def refresh
  234.     contents.clear
  235.     draw_currency_value(value($game_temp.currency_index), currency_unit($game_temp.currency_index), -10, 0, contents.width - 8)
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # * Get Party Gold
  239.   #--------------------------------------------------------------------------
  240.   def value(currency_index = $game_temp.currency_index)
  241.     if currency_index == 0
  242.       $game_party.gold
  243.     else
  244.       $game_party.currency[currency_index]
  245.     end
  246.   end  
  247.   #--------------------------------------------------------------------------
  248.   # Get Currency Unit
  249.   #--------------------------------------------------------------------------
  250.   def currency_unit(currency_index = $game_temp.currency_index)
  251.     icon_index = Clstn_Currencies::Currencies[currency_index][0]
  252.     currency_unit = draw_icon(icon_index, 115, -1)
  253.   end
  254.  
  255. end
  256.  
  257. #===========================================================================
  258. # ** Class Game_Party
  259. #===========================================================================
  260. class Window_ShopNumber < Window_Selectable
  261.  
  262.   #-------------------------------------------------------------------------
  263.   # * Method: draw_total_price
  264.   #-------------------------------------------------------------------------
  265.   def draw_total_price
  266.     width = contents_width - 8
  267.     icon_index = Clstn_Currencies::Currencies[$game_temp.currency_index][0]
  268.     icon = draw_icon(icon_index, 255, 143)
  269.     draw_currency_value(@price * @number, icon, -15, price_y, width)
  270.   end
  271.  
  272. end
  273. #===========================================================================
  274. # ** Class Game_Party
  275. #===========================================================================
  276. class Game_Party < Game_Unit
  277.   attr_accessor :currency
  278.  
  279.   #-------------------------------------------------------------------------
  280.   # * Initialize
  281.   #-------------------------------------------------------------------------
  282.   def initialize
  283.     @currency = []
  284.     @gold = Clstn_Currencies::Currencies[0][1]
  285.     11.times { |i|
  286.       if i == 0
  287.         @currency[i] = @gold
  288.       else
  289.         @currency[i] = Clstn_Currencies::Currencies[i][1]
  290.       end
  291.     }
  292.     @steps = 0
  293.     @last_item = Game_BaseItem.new
  294.     @menu_actor_id = 0
  295.     @target_actor_id = 0
  296.     @actors = []
  297.     init_all_items
  298.   end
  299.  
  300.   #-------------------------------------------------------------------------
  301.   # * Method: gain_gold
  302.   #-------------------------------------------------------------------------
  303.   def gain_gold(amount, currency_index = $game_temp.currency_index)
  304.     if currency_index != 0
  305.       @currency[currency_index] = [[@currency[currency_index] + amount, 0].max, max_gold].min
  306.     else
  307.       @gold = [[@gold + amount, 0].max, max_gold].min
  308.     end
  309.   end
  310.  
  311.   #-------------------------------------------------------------------------
  312.   # * Method: lose_gold
  313.   #-------------------------------------------------------------------------
  314.   def lose_gold(amount, currency_index = $game_temp.currency_index)
  315.       gain_gold(-amount, currency_index)
  316.   end
  317.  
  318. end
  319.  
  320. #===========================================================================
  321. # ** Class Game_Temp
  322. #===========================================================================
  323. class Game_Temp
  324.   attr_accessor :currency_index
  325.  
  326.   #--------------------------------------------------------------------------
  327.   # * Aliased Methods
  328.   #--------------------------------------------------------------------------
  329.   alias :clstn_initialize_0005 initialize
  330.  
  331.   #--------------------------------------------------------------------------
  332.   # * Initialize
  333.   #--------------------------------------------------------------------------
  334.   def initialize
  335.     @currency_index = 0
  336.     clstn_initialize_0005
  337.   end
  338.  
  339. end
  340.  
  341. #===========================================================================
  342. # ** Class Game_Temp
  343. #===========================================================================
  344. class Game_Interpreter
  345.  
  346.   #--------------------------------------------------------------------------
  347.   # * Method: add_currency
  348.   #--------------------------------------------------------------------------
  349.   def add_currency(amount, currency_index)
  350.     $game_party.gain_gold(amount, currency_index)
  351.   end
  352.  
  353.   #--------------------------------------------------------------------------
  354.   # * Method: currency
  355.   #--------------------------------------------------------------------------
  356.   def currency(currency_index)
  357.     $game_temp.currency_index = currency_index
  358.   end
  359.  
  360. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement