Advertisement
MrTrivel

MrTS_Gamblers_Forge

Jun 5th, 2014
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.15 KB | None | 0 0
  1. # )--------------------------------------------------(
  2. # )--     Author:     Mr Trivel                    --(
  3. # )--     Name:       Gambler's Forge              --(
  4. # )--     Created:    2014-06-05                   --(
  5. # )--     Version:    1.01                         --(
  6. # )--------------------------------------------------(
  7. # )--     Requires:   None                         --(
  8. # )--------------------------------------------------(
  9. # )--    Version changes:                          --(
  10. # )-- 1.01 - Items with <No Forge> note tag, are   --(
  11. # )--        now not listed in the forge.          --(
  12. # )--------------------------------------------------(
  13. # )--             Description                      --(
  14. # )-- Use 4 items to get 1 random item from item   --(
  15. # )-- tables.                                      --(
  16. # )--------------------------------------------------(
  17. # )-- For all people who want to gamble their      --(
  18. # )-- useless items away or want to try and get    --(
  19. # )-- something useful can now use Gambler's       --(
  20. # )-- Forge for that!                              --(
  21. # )--------------------------------------------------(
  22. # )--             Instructions                     --(
  23. # )--  Call the Gambler's Forge scene by using:    --(
  24. # )-- SceneManager.call(MrTS_Scene_Gamblers_Forge) --(
  25. # )--                                              --(
  26. # )-- If you don't want an item to be forgeable,   --(
  27. # )-- add <No Forge> in that item's note box.      --(
  28. # )-- <No Forge> <Noforge> <noforge> <no forge>    --(
  29. # )--------------------------------------------------(
  30. # )--             LICENSE INFO                     --(
  31. # )--http://mrtrivelvx.wordpress.com/terms-of-use/ --(
  32. # )--------------------------------------------------(
  33.  
  34. module MrTS
  35.   module MrTS_Gambler_Forge
  36.    
  37.     # )-----------------------------------------------(
  38.     # )--  Feel free to customize for your needs    --(
  39.     # )--     2 means 2nd item in the database      --(
  40.     # )-----------------------------------------------(
  41.     # )--  Item rewards - what Items can player get --(
  42.     # )-----------------------------------------------(
  43.     ITEM_REWARDS   =  [
  44.                       2, 3
  45.                       ]
  46.     # )--------------------------------------------------(
  47.     # )-- Weapon rewards - what Weapons can player get --(
  48.     # )--------------------------------------------------(
  49.     WEAPON_REWARDS =  [
  50.                       2, 3
  51.                       ]
  52.     # )------------------------------------------------(
  53.     # )-- Armor rewards - what Armors can player get --(
  54.     # )------------------------------------------------(
  55.     ARMOR_REWARDS  =  [
  56.                       2, 3 #2, 3, 4, 5, 6, 7, 8, 9, 10, 11
  57.                       ]
  58.    
  59.     # )---------------------------------------------(
  60.     # )--  How long reward pop up stays on screen --(
  61.     # )---------------------------------------------(
  62.     POP_UP_TIME = 120 # 60 = 1 second
  63.    
  64.     # )----------------(
  65.     # )--  Text list --(
  66.     # )----------------(
  67.     TEXT_LIST = [
  68.                 "Forge",
  69.                 "Add Item",
  70.                 "Remove All",
  71.                 "Leave",
  72.                 "Welcome to Gambler's Forge!"
  73.                 ]
  74.    
  75.     # )----------------------------------------(
  76.     # )--  Preferably don't edit down below  --(
  77.     # )----------------------------------------(
  78.                      
  79.   end
  80. end
  81.  
  82.  
  83. # )--------------------------------------(
  84. # )--  Class: MrTS_Scene_Mystic_Forge  --(
  85. # )--------------------------------------(
  86. class MrTS_Scene_Gamblers_Forge < Scene_Base
  87.  
  88.   # )---------------------(
  89.   # )--  Method: start  --(
  90.   # )---------------------(
  91.   def start
  92.     create_background
  93.     create_main_viewport
  94.     create_all_windows
  95.     @timer_started = false
  96.     @timer = 0
  97.   end
  98.  
  99.   # )---------------------------------(
  100.   # )--  Method: create_background  --(
  101.   # )---------------------------------(
  102.   def create_background
  103.     @background_sprite = Sprite.new
  104.     @background_sprite.bitmap = SceneManager.background_bitmap
  105.     @background_sprite.color.set(16, 16, 16, 128)
  106.   end
  107.  
  108.   # )----------------------(
  109.   # )--  Method: update  --(
  110.   # )----------------------(
  111.   def update
  112.     super
  113.     @timer += 1 if @timer_started
  114.     if @timer > MrTS::MrTS_Gambler_Forge::POP_UP_TIME
  115.       @reward_window.close
  116.       @timer_started = false
  117.       @timer = 0
  118.     end
  119.   end
  120.  
  121.   # )-------------------------(
  122.   # )--  Method: terminate  --(
  123.   # )-------------------------(
  124.   def terminate
  125.     super
  126.     dispose_all_windows
  127.     dispose_background
  128.   end
  129.  
  130.   # )----------------------------------(
  131.   # )--  Method: dispose_background  --(
  132.   # )----------------------------------(
  133.   def dispose_background
  134.     @background_sprite.dispose
  135.   end
  136.  
  137.   # )----------------------------------(
  138.   # )--  Method: create_all_windows  --(
  139.   # )----------------------------------(
  140.   def create_all_windows
  141.     create_mystic_forge_window
  142.     create_items_taken_window
  143.     create_command_window
  144.     create_item_list_window
  145.     create_reward_window
  146.   end
  147.  
  148.   # )--------------------(
  149.   # )--  Method: item  --(
  150.   # )--------------------(
  151.   def item
  152.     @item_list.item
  153.   end
  154.  
  155.   # )------------------------------------------(
  156.   # )--  Method: create_mystic_forge_window  --(
  157.   # )------------------------------------------(
  158.   def create_mystic_forge_window
  159.     @welcome_window = MrTS_Mystic_Forge_Window.new
  160.   end
  161.  
  162.   # )-----------------------------------------(
  163.   # )--  Method: create_items_taken_window  --(
  164.   # )-----------------------------------------(
  165.   def create_items_taken_window
  166.     @taken_window = MrTS_Items_Taken_Window.new
  167.   end
  168.  
  169.   # )---------------------------------------(
  170.   # )--  Method: create_item_list_window  --(
  171.   # )---------------------------------------(
  172.   def create_item_list_window
  173.     @item_list = MrTS_Mystic_Forge_Item_List_Window.new(@command_window, @taken_window.y + @taken_window.height)
  174.     @item_list.set_handler(:ok    , method(:item_ok))
  175.     @item_list.set_handler(:cancel, method(:item_back))
  176.   end
  177.  
  178.   # )-----------------------(
  179.   # )--  Method: item_ok  --(
  180.   # )-----------------------(
  181.   def item_ok
  182.     $game_party.last_item.object = item
  183.     @taken_window.add_item(item)
  184.     @item_list.activate
  185.     @item_list.select_last
  186.     @item_list.refresh
  187.   end
  188.  
  189.   # )-------------------------(
  190.   # )--  Method: item_back  --(
  191.   # )-------------------------(
  192.   def item_back
  193.     @item_list.unselect
  194.     @command_window.activate
  195.   end  
  196.  
  197.   # )-------------------------------------(
  198.   # )--  Method: create_command_window  --(
  199.   # )-------------------------------------(
  200.   def create_command_window
  201.     @command_window = MrTS_Command_Window_MF.new
  202.     @command_window.set_handler(:forge, method(:forge))
  203.     @command_window.set_handler(:additem, method(:additem))
  204.     @command_window.set_handler(:restart, method(:restart))
  205.     @command_window.set_handler(:quit, method(:return_scene))
  206.     @command_window.set_handler(:cancel, method(:command_back))
  207.   end
  208.  
  209.   # )---------------------(
  210.   # )--  Method: forge  --(
  211.   # )---------------------(
  212.   def forge
  213.     if @taken_window.can_forge?
  214.       @taken_window.destroy_items
  215.       @reward_window.give_reward
  216.       @item_list.refresh
  217.       @timer_started = true
  218.     end
  219.     @command_window.activate
  220.   end
  221.  
  222.   # )----------------------------(
  223.   # )--  Method: command_back  --(
  224.   # )----------------------------(
  225.   def command_back
  226.     @taken_window.return_items
  227.     @item_list.refresh
  228.     return_scene
  229.   end
  230.  
  231.   # )-----------------------(
  232.   # )--  Method: additem  --(
  233.   # )-----------------------(
  234.   def additem
  235.     @item_list.activate
  236.     @item_list.select_last
  237.   end
  238.  
  239.   # )-----------------------(
  240.   # )--  Method: restart  --(
  241.   # )-----------------------(
  242.   def restart
  243.     @taken_window.return_items
  244.     @command_window.activate
  245.     @item_list.refresh
  246.   end
  247.  
  248.   # )------------------------------------(
  249.   # )--  Method: create_reward_window  --(
  250.   # )------------------------------------(
  251.   def create_reward_window
  252.     @reward_window = MrTS_Mystic_Forge_Reward_Window.new
  253.   end
  254.  
  255.   # )-----------------------------------(
  256.   # )--  Method: dispose_all_windows  --(
  257.   # )-----------------------------------(
  258.   def dispose_all_windows
  259.     @welcome_window.dispose
  260.     @taken_window.dispose
  261.     @command_window.dispose
  262.     @item_list.dispose
  263.     @reward_window.dispose
  264.   end
  265. end # End of MrTS_Scene_Mystic_Forge
  266.  
  267. # )----------------------------------------------(
  268. # )--  Class: MrTS_Mystic_Forge_Reward_Window  --(
  269. # )----------------------------------------------(
  270. class MrTS_Mystic_Forge_Reward_Window < Window_Base
  271.  
  272.   # )--------------------------(
  273.   # )--  Method: initialize  --(
  274.   # )--------------------------(
  275.   def initialize
  276.     dw = 172 + standard_padding*2
  277.     dh = line_height + standard_padding*2
  278.     dx = Graphics.width/2 - dw/2
  279.     dy = Graphics.height/2 - dh/2
  280.     super(dx, dy, dw, dh)
  281.     self.openness = 0
  282.   end
  283.  
  284.   # )---------------------------(
  285.   # )--  Method: give_reward  --(
  286.   # )---------------------------(
  287.   def give_reward
  288.     loot_table = rand(3)
  289.     case loot_table
  290.     when 0
  291.       item = $data_items[MrTS::MrTS_Gambler_Forge::ITEM_REWARDS[rand(MrTS::MrTS_Gambler_Forge::ITEM_REWARDS.size)]]
  292.     when 1
  293.       item = $data_weapons[MrTS::MrTS_Gambler_Forge::WEAPON_REWARDS[rand(MrTS::MrTS_Gambler_Forge::WEAPON_REWARDS.size)]]  
  294.     when 2
  295.       item = $data_armors[MrTS::MrTS_Gambler_Forge::ARMOR_REWARDS[rand(MrTS::MrTS_Gambler_Forge::ARMOR_REWARDS.size)]]
  296.     end
  297.     open
  298.     create_contents
  299.     draw_item_name(item, 0, 0)
  300.     $game_party.gain_item(item, 1)
  301.   end
  302. end # end of MrTS_Mystic_Forge_Reward_Window
  303.  
  304. # )-------------------------------------------------(
  305. # )--  Class: MrTS_Mystic_Forge_Item_List_Window  --(
  306. # )-------------------------------------------------(
  307. class MrTS_Mystic_Forge_Item_List_Window < Window_Selectable
  308.  
  309.   # )--------------------------(
  310.   # )--  Method: initialize  --(
  311.   # )--------------------------(
  312.   def initialize (command_window, y)
  313.     super(0, y, Graphics.width, Graphics.height - y - command_window.height)
  314.     @data = []
  315.     refresh
  316.   end
  317.  
  318.   # )-----------------------(
  319.   # )--  Method: col_max  --(
  320.   # )-----------------------(
  321.   def col_max
  322.     return 2
  323.   end
  324.  
  325.   # )------------------------(
  326.   # )--  Method: item_max  --(
  327.   # )------------------------(
  328.   def item_max
  329.     return @data ? @data.size : 1
  330.   end
  331.  
  332.   # )--------------------(
  333.   # )--  Method: item  --(
  334.   # )--------------------(
  335.   def item
  336.     @data && index >= 0 ? @data[index] : nil
  337.   end
  338.  
  339.   # )-----------------------(
  340.   # )--  Method: refresh  --(
  341.   # )-----------------------(
  342.   def refresh
  343.     make_data
  344.     create_contents
  345.     draw_all_items
  346.   end
  347.  
  348.   # )---------------------------(
  349.   # )--  Method: select_last  --(
  350.   # )---------------------------(
  351.   def select_last
  352.     select(@data.index($game_party.last_item.object) || 0)
  353.   end
  354.  
  355.   # )-------------------------(
  356.   # )--  Method: make_data  --(
  357.   # )-------------------------(
  358.   def make_data
  359.     @data = $game_party.all_items.select {|item| include?(item) }
  360.     @data.push(nil) if include?(nil)
  361.   end
  362.  
  363.   # )-------------------------(
  364.   # )--  Method: draw_item  --(
  365.   # )-------------------------(
  366.   def draw_item(index)
  367.     item = @data[index]
  368.     if item
  369.       rect = item_rect(index)
  370.       rect.width -= 4
  371.       draw_item_name(item, rect.x, rect.y, true)
  372.       draw_item_number(rect, item)
  373.     end
  374.   end
  375.  
  376.   # )--------------------------------(
  377.   # )--  Method: draw_item_number  --(
  378.   # )--------------------------------(
  379.   def draw_item_number(rect, item)
  380.     draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  381.   end
  382.  
  383.   # )------------------------------(
  384.   # )--  Method: can_be_listed?  --(
  385.   # )------------------------------(
  386.   def can_be_listed?(item)
  387.     item.note[/(<[n-nN-N]o\s*[f-fF-F]orge>)/]
  388.     if $1
  389.       false
  390.     else
  391.       true
  392.     end
  393.   end
  394.  
  395.   # )------------------------(
  396.   # )--  Method: include?  --(
  397.   # )------------------------(
  398.   def include?(item)
  399.     if (item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor) ||
  400.       (item.is_a?(RPG::Item) && !item.key_item?)) && can_be_listed?(item)
  401.       true
  402.     else
  403.       false
  404.     end
  405.   end
  406. end # end of MrTS_Mystic_Forge_Item_List_Window
  407.  
  408.  
  409. # )-------------------------------------(
  410. # )--  Class: MrTS_Command_Window_MF  --(
  411. # )-------------------------------------(
  412. class MrTS_Command_Window_MF < Window_HorzCommand
  413.   # )--------------------------(
  414.   # )--  Method: initialize  --(
  415.   # )--------------------------(
  416.   def initialize
  417.     super(0, Graphics.height - line_height - standard_padding*2)
  418.   end
  419.  
  420.   # )---------------------------------(
  421.   # )--  Method: make_command_list  --(
  422.   # )---------------------------------(
  423.   def make_command_list
  424.     add_command(MrTS::MrTS_Gambler_Forge::TEXT_LIST[0], :forge)
  425.     add_command(MrTS::MrTS_Gambler_Forge::TEXT_LIST[1], :additem)
  426.     add_command(MrTS::MrTS_Gambler_Forge::TEXT_LIST[2], :restart)
  427.     add_command(MrTS::MrTS_Gambler_Forge::TEXT_LIST[3], :quit)
  428.   end
  429.  
  430.   # )----------------------------(
  431.   # )--  Method: window_width  --(
  432.   # )----------------------------(
  433.   def window_width
  434.     Graphics.width
  435.   end
  436.  
  437.   # )-----------------------(
  438.   # )--  Method: col_max  --(
  439.   # )-----------------------(
  440.   def col_max
  441.     return 4
  442.   end
  443.  
  444. end # end of MrTS_Command_Window_MF
  445.  
  446.  
  447. # )---------------------------------------(
  448. # )--  Class: MrTS_Mystic_Forge_Window  --(
  449. # )---------------------------------------(
  450. class MrTS_Mystic_Forge_Window < Window_Base
  451.  
  452.   # )--------------------------(
  453.   # )--  Method: initialize  --(
  454.   # )--------------------------(
  455.   def initialize
  456.     super(0, 0, Graphics.width, line_height + standard_padding*2)
  457.     draw_welcome_message
  458.   end
  459.  
  460.   # )------------------------------------(
  461.   # )--  Method: draw_welcome_message  --(
  462.   # )------------------------------------(
  463.   def draw_welcome_message
  464.     contents.clear
  465.     text = MrTS::MrTS_Gambler_Forge::TEXT_LIST[4]
  466.     draw_text(contents.width/2 - text_size(text).width/2, 0, contents.width, line_height, text)
  467.   end
  468. end # end of MrTS_Mystic_Forge_Window
  469.  
  470.  
  471. # )---------------------------------------(
  472. # )--  Class: MrTS_Items_Taken_Window  --(
  473. # )---------------------------------------(
  474. class MrTS_Items_Taken_Window < Window_Base
  475.  
  476.   # )--------------------------(
  477.   # )--  Method: initialize  --(
  478.   # )--------------------------(
  479.   def initialize
  480.     super(0, line_height + standard_padding*2, Graphics.width, line_height*2 + standard_padding * 4)
  481.     @item = []
  482.     refresh
  483.   end
  484.  
  485.   # )-----------------------(
  486.   # )--  Method: refresh  --(
  487.   # )-----------------------(
  488.   def refresh
  489.     contents.clear
  490.     create_contents
  491.     draw_items    
  492.   end
  493.  
  494.   # )--------------------------(
  495.   # )--  Method: draw_items  --(
  496.   # )--------------------------(
  497.   def draw_items
  498.     item_no = 0
  499.    
  500.     while item_no < 4
  501.       item = @item[item_no]
  502.       dx = contents.width/2 * (item_no%2)
  503.       dy = (contents.height - line_height) * (item_no/2)
  504.       draw_icon(16, dx, dy)
  505.       if item
  506.         draw_item_name(item, dx, dy)
  507.       end
  508.       item_no += 1
  509.     end
  510.   end
  511.  
  512.   # )--------------------------(
  513.   # )--  Method: can_forge?  --(
  514.   # )--------------------------(
  515.   def can_forge?
  516.     if @item.length == 4
  517.       true
  518.     else
  519.       false
  520.     end
  521.   end
  522.  
  523.   # )------------------------(
  524.   # )--  Method: add_item  --(
  525.   # )------------------------(
  526.   def add_item(item)
  527.     if item && @item.length < 4
  528.       $game_party.lose_item(item, 1)
  529.       @item.push(item)
  530.       refresh
  531.     end
  532.   end
  533.  
  534.   # )-----------------------------(
  535.   # )--  Method: destroy_items  --(
  536.   # )-----------------------------(
  537.   def destroy_items
  538.     @item = []
  539.     refresh
  540.   end
  541.  
  542.   # )----------------------------(
  543.   # )--  Method: return_items  --(
  544.   # )----------------------------(
  545.   def return_items
  546.     @item.each do |it|
  547.       $game_party.gain_item(it, 1)
  548.     end
  549.    
  550.     @item = []
  551.     refresh
  552.   end
  553. end # end of MrTS_Items_Taken_Window
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement