Advertisement
Guest User

Calestian's Multiple Currencies

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