Advertisement
TheSixth

Venka's Crafting System + Vlue's Randomization Patch bySixth

Sep 4th, 2015
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 44.63 KB | None | 0 0
  1. #==============================================================================
  2. # Randomization Addon by Venka & Sixth (v.1.1d)                ----------------
  3. # - Go nuts with random crafted items!                         |   Updated:
  4. # REQUIRES Venka's Multiple Crafting Script!                   |  13/09/2014
  5. # REQUIRES Vlue's Weapon/Armor Randomization!                  ----------------
  6. #==============================================================================
  7. #------------------------------------------------------------------------------
  8. # Change Log:
  9. #------------------------------------------------------------------------------
  10. #  13/09/2014 - Removed something that is not needed anymore.
  11. #               Updated the instructions part, as it turns out, placement is
  12. #               important for the Crafting Shop Recipes addon.
  13. #  19/08/2014 - Updated the addon to account for the changes in the main script.
  14. #             - The issue with the Actor Stat Changes Add On is fixed as well.
  15. #  15/08/2014 - Added $imported tag. Mostly for debugging purposes.
  16. #  13/08/2014 - Added some script calls to check the number of the total
  17. #               recipes learned by craft types. Might help with some eventing.
  18. #  10/08/2014 - Restructured the code of the box version of the result window.
  19. #  09/08/2014 - Added color settings for the borders of the boxes.
  20. #               Added stack size limit options.
  21. #               Added shorter script calls to toggle randomization on and off.
  22. #               Added non-boxed version of the result window.
  23. #  08/08/2014 - Initial release.
  24. #------------------------------------------------------------------------------
  25. # Introduction:
  26. #------------------------------------------------------------------------------
  27. #  This script will allow you to craft equips and items with a chance of
  28. #  random attributes on them.
  29. #  This addon makes use of Vlue's Weapon/Armor Randomization to make the
  30. #  boosted item. The result window will scale to it's contents and show off
  31. #  the rarity colors and affixes of the items.
  32. #  The addon also changes the way the result popup window appears to suit
  33. #  the possibility of crafting random items in stacks and show their names.
  34. #  A new option is also available for limiting the maximum size of crafting
  35. #  stacks or the maximum amount of items crafted at once.
  36. #------------------------------------------------------------------------------
  37. # Important Notes:
  38. #------------------------------------------------------------------------------
  39. #  Randomized items cannot be used as components in crafting recipes.
  40. #  You can set if you want weapons, armors or items to be randomized. I'd
  41. #  suggest setting Random_Items to false if you plan on crafted items to be
  42. #  components for other recipes, but the choice is yours.
  43. #
  44. #  Item randomization is different than equip randomization!
  45. #  Items can NOT gain any bonus effects with randomization, but they can be
  46. #  colored and they can get random affix names as well.
  47. #
  48. #  At the moment, failed/prefailed items will not get randomized but it is easy
  49. #  to make them random too. I don't need this function for now, but if anyone is
  50. #  interested in it, I could post the solution to this little "problem" too.
  51. #  Or I could even implement this as an optional function too. But later. :P
  52. #
  53. #  The result popup window is NOT scroll-able! Keep this in mind if you allow
  54. #  crafting in stacks with random items!
  55. #  Limiting the maximum number of items crafted is possible, so use that to
  56. #  prevent the information from being cut vertically.
  57. #  You can also use that to prevent players from crafting excessive amount of
  58. #  items while being 'afk'.
  59. #------------------------------------------------------------------------------
  60. # Instructions:
  61. #------------------------------------------------------------------------------
  62. #  Place this add on below Venka's Crafting Script and below Vlue's Weapon/Armor
  63. #  Randomization but above Main.
  64. #
  65. #  If you are using the 'Actor Stat Changes Add on' for the Crafting Script,
  66. #  place this addon below that one!
  67. #
  68. #  If you are using the 'Shop Recipes Add on' for the Crafting Script,
  69. #  place that addon below Vlue's Randomization script!
  70. #
  71. #  Set up both of the above mentioned scripts to your preference.
  72. #  To set up Venka's Crafting Script, refer to the instructions in that script!
  73. #  To set up Vlue's Randomization Script, refer to the instruction in that script!
  74. #  This addon is plug-and-play. Configure the settings below if needed.
  75. #------------------------------------------------------------------------------
  76. # Script Calls:
  77. #------------------------------------------------------------------------------
  78. #  To switch off the randomization during the game, use the following script calls:
  79. #
  80. #  $craft.rand_weapons = true/false
  81. #  $craft.rand_armor   = true/false
  82. #  $craft.rand_items   = true/false
  83. #  
  84. #  NOTE: When you change the randomization in the game, it will stay the way
  85. #        you set it until you change it again! Keep that in mind while eventing!
  86. #
  87. #  To check for the number of the total recipes (learned), use these script calls
  88. #  in conditional branches:
  89. #
  90. #  $craft.known_recipes_check(ID)  # This will check the number of already
  91. #                                    learned recipes!
  92. #  $craft.total_recipes_check(ID)  # This will check the number of all of the
  93. #                                    recipes from the database of that type!
  94. #                                    
  95. #  Replace 'ID' with your craft ID number.
  96. #
  97. #  Some examples for the default sample craft types:
  98. #  $craft.known_recipes_check(1) >= 4  # This will return true if the player has
  99. #                                        learned 4 or more recipes from the
  100. #                                        craft type of Cooking.
  101. #  $craft.total_recipes_check(3)       # This will get the amount of all of the
  102. #                                        recipes from the craft type of Alchemy.
  103. #                                        The only purpose of ever using this
  104. #                                        call is for displaying it in a message
  105. #                                        or window, I guess.
  106. #  Replacing the 'ID' with 0 will get you the amount of recipes from all craft
  107. #  types at once.
  108. #------------------------------------------------------------------------------
  109. # Extra Tips:
  110. #------------------------------------------------------------------------------
  111. #  For weapons and armors, using this randomized method, you can make a pretty
  112. #  nice crafting system, which rewards timing (aka good crafting).
  113. #  Make the timer window for success something very small.
  114. #  Now make the success reward and the failed/prefailed item rewards the very
  115. #  same item. What will this do? If you press the button in time, you will get
  116. #  a randomized (usually better, right?) item with cool affixes, and if you
  117. #  miss the timing, you will get a normal item without any bonus stats.
  118. #  Because regular items can not gain any bonus effects from randomization,
  119. #  the good timing reward could be more items crafted at once, for example.
  120. #  This is just a suggestion by me.
  121. #------------------------------------------------------------------------------
  122. # Updates In Plan:
  123. #------------------------------------------------------------------------------
  124. #  None at the moment.
  125. #------------------------------------------------------------------------------
  126. # Terms of use:
  127. #------------------------------------------------------------------------------
  128. #  Do whatever you want with this addon.
  129. #  If you, by any chance, credit me for this, you must also credit Venka and Vlue!
  130. #------------------------------------------------------------------------------
  131. # Extra Credits and Thanks:
  132. #------------------------------------------------------------------------------
  133. # Venka - For making the awesome Crafting Script - obviously! :P
  134. #         For giving me tips to make this snippet standalone.
  135. #         For giving me info about the font types used to display the arrow symbols.
  136. #         For enhancing this add-on to a whole new level! Even more!
  137. #         For always being helpful!
  138. # Vlue - For making his Equip Randomizer script - Yay!
  139. #        For giving the basic compatibility patch for this add-on!
  140. #        For making other scripts from which I learned a lot about scaling
  141. #        windows depending on the contents in them.
  142. #        For always being helpful!
  143. # Bloodmorphed - For making me add the colored items function to the popup window.
  144. #                Without him asking, I wouldn't even bothered with it! :P
  145. #==============================================================================
  146. $imported = {} if $imported.nil?
  147. $imported["RandomizationAddon"] = true
  148. ###############################################################################
  149. #
  150. # The "Big" Setup part - edit until you drop!
  151. #
  152. ###############################################################################
  153.  
  154. module Venka
  155.   module Crafting
  156.    
  157.   #----------------------------------------------------------------------------
  158.   # Randomization Settings
  159.   #----------------------------------------------------------------------------
  160.   # You can set which items would you like to be randomized in the crafting
  161.   # scenes here. "True" turns randomization ON, while "false" will turn it OFF.
  162.   # You can change these settings on the go in the game too with the provided
  163.   # script calls at the "Script Calls" section.
  164.   #----------------------------------------------------------------------------
  165.   Random_Weapons = true    # Craft weapons with random attributes
  166.   Random_Armor   = true    # Craft armor with random attributes
  167.   Random_Items   = false   # Craft items with random names and color
  168.  
  169.   #----------------------------------------------------------------------------
  170.   # Craft Stack Limit Settings
  171.   #----------------------------------------------------------------------------
  172.   # You can set the maximum amount of items crafted at once with the settings
  173.   # below. These settings will not affect anything if the 'Craft_Stacks' settings
  174.   # is set to 'false' in the main customization script of Venka's Crafting Script.
  175.   #----------------------------------------------------------------------------
  176.   Max_Crafting   = 10      # Max number of items you can craft in one sitting
  177.                            # This won't stop going over the specified number if
  178.                            # the recipe got more than 1 crafted_item in the settings.
  179.                            # Ex: A recipe giving out 2 potions on success can be
  180.                            # crafted 10 times in a stack with the 'Max_Crafting'
  181.                            # setting set to 10 but the amount of items crafted
  182.                            # in the end will be 20.
  183.                            # Setting this to 'nil' will disable this option.
  184.   Max_Total      = true    # This setting will limit the stack craft entirely.
  185.                            # Setting this to 'false' will produce the same effect
  186.                            # as in the above example with the potion recipe.
  187.                            # Setting it to 'true' will make the max number of
  188.                            # items crafted in one sitting no more than the
  189.                            # 'Max_Crafting' number, regardless of how many items
  190.                            # the recipe gives on success in the recipe settings.
  191.                            # Ex: A recipe giving out 2 potions on success can be
  192.                            # crafted 5 times in a stack if the 'Max_Crafting'
  193.                            # setting is set to 10 and if 'Max_Total' is set to
  194.                            # 'true', so in the end the amount of crafted items
  195.                            # will be 10 at max.
  196.                            # This setting won't affect anything if 'Max_Crafting'
  197.                            # is set to 'nil'.
  198.  
  199.   #----------------------------------------------------------------------------
  200.   # Result Window Appearance Settings
  201.   #----------------------------------------------------------------------------
  202.   # This setting will enable or disable the box version of the result window.
  203.   # Setting it to false will make the result window to the non-boxed version.
  204.   # The boxed version demands more height, while the non-boxed version
  205.   # demands more width to display the information on the screen.
  206.   #----------------------------------------------------------------------------
  207.   Box_Version = true
  208.  
  209.   #----------------------------------------------------------------------------
  210.   # Arrow Settings (used only for the non-boxed version of the result window)
  211.   #----------------------------------------------------------------------------
  212.   # These settings adjust the position and font type of the arrow symbols used
  213.   # in the result popup window.
  214.   # Not many font types can display the arrow symbol, but "Arial" can surely do.
  215.   # Color can be a window skin color number or an array - [Red, Blue, Green, Alpha].
  216.   #----------------------------------------------------------------------------
  217.   #                [[     Font Types Array      ], Size, Bold, Color]
  218.   Fonts[:arrows] = [["Monotype Corsiva", "Arial"],   24, true,    13]  
  219.  
  220.   Arrow_x_Item =   0       # The horizontal offset for the arrow displayed
  221.                            # after the 'Result_Msg' text
  222.   Arrow_x_Exp  =   0       # The horizontal offset for the arrow displayed
  223.                            # after the 'Exp_Earned' text
  224.   Arrow_x_Rec  =   0       # The horizontal offset for the arrow displayed
  225.                            # after the 'Learn_Text' text
  226.  
  227.   #----------------------------------------------------------------------------
  228.   # Box Settings (used only for the boxed version of the result window)
  229.   #----------------------------------------------------------------------------
  230.   # These settings adjust the colors of the boxes and borders in the result window.
  231.   # Setting the alpha to 0 will make them fully transparent/invisible.
  232.   #----------------------------------------------------------------------------
  233.   #----------------------------------------------------------------------------
  234.   # Box Color Settings
  235.   #----------------------------------------------------------------------------
  236.   #                     [  R,  G,  B,  A ] # [Red, Green, Blue, Alpha]
  237.   Results_Box         = [ 22, 88, 88, 150] # The color of the "Result_Msg" Box
  238.   Failed_Box          = [200, 10, 10, 150] # The color of the "Failed_Msg" Box
  239.   Crafted_Items_Box   = [ 88, 88, 44, 150] # The color of the "Crafted Items" Box
  240.   Exp_Text_Box        = [ 22, 22, 88, 150] # The color of the "Exp_Earned" Box
  241.   Level_Up_Box        = [ 22, 88, 44, 150] # The color of the "Lv_Gain" Box
  242.   Recipe_Text_Box     = [ 22, 88, 88, 150] # The color of the "Learn_Text" Box
  243.   Learned_Recipes_Box = [ 22, 88, 22, 150] # The color of the "Learned Recipes" Box
  244.   #----------------------------------------------------------------------------
  245.   # Box Border Color Settings
  246.   #----------------------------------------------------------------------------
  247.   #                   [  R,  G,  B,  A ] # [Red, Green, Blue, Alpha]
  248.   Item_Border_Out   = [200,200,  0, 255] # Outside border color of the "Item" Box.
  249.   Item_Border_In    = [ 22, 22,222, 255] # Inside border color of the "Item" Box.
  250.   Exp_Border_Out    = [  0,200,  0, 255] # Outside border color of the "Exp" Box.
  251.   Exp_Border_In     = [ 22, 22, 22, 255] # Inside border color of the "Exp" Box.
  252.   Recipe_Border_Out = [200, 20, 20, 255] # Outside border color of the "Recipe" Box.
  253.   Recipe_Border_In  = [ 22, 22, 22, 255] # Inside border color of the "Recipe" Box.
  254.  
  255.   end
  256. end
  257.  
  258. ###############################################################################
  259. #
  260. # End of the "Big" Setup part - editing below may lead to flying dragons!
  261. #
  262. ###############################################################################
  263.  
  264. begin
  265.   if AFFIXES
  266.     #==========================================================================
  267.     # ■ Game_Crafting  
  268.     #==========================================================================
  269.     class Game_Crafting
  270.       #------------------------------------------------------------------------
  271.       # ♦ Public Instance Variables
  272.       #------------------------------------------------------------------------
  273.       attr_accessor    :rand_weapons, :rand_armor, :rand_items
  274.       attr_reader      :known_recipes_check,       :total_recipes_check
  275.       #------------------------------------------------------------------------
  276.       # ● alias method: initialize
  277.       #------------------------------------------------------------------------
  278.       alias sixth_stored_variables_ini initialize
  279.       def initialize
  280.         sixth_stored_variables_ini
  281.         @rand_weapons = Venka::Crafting::Random_Weapons
  282.         @rand_armor = Venka::Crafting::Random_Armor
  283.         @rand_items = Venka::Crafting::Random_Items
  284.       end
  285.       #------------------------------------------------------------------------
  286.       # ● new method: known_recipe_check
  287.       #------------------------------------------------------------------------
  288.       def known_recipes_check(type)
  289.         return if type == nil
  290.         total = []
  291.         Venka::Crafting::Craft_Info.each_key do |craft_id|
  292.           print "Craft ID: "; p craft_id
  293.           total[craft_id] = 0
  294.           $craft.known_recipes.each do |recipe_id|
  295.             print "recipe ID: "; p recipe_id
  296.             next unless ($recipe[recipe_id].recipe_type == craft_id && $recipe[recipe_id].recipe_type == type) || ($recipe[recipe_id].recipe_type == craft_id && type == 0)
  297.             p "Adding to the total"
  298.             total[craft_id] += 1
  299.           end
  300.         end
  301.         print "Final totals: "; p total
  302.         grand_total = total.compact.inject{|sum, x| sum + x }
  303.         print "Grand Total: "; p grand_total
  304.       end
  305.       #------------------------------------------------------------------------
  306.       # ● new method: total_recipe_check
  307.       #------------------------------------------------------------------------
  308.       def total_recipes_check(type)
  309.         return if type == nil
  310.         total = []
  311.         Venka::Crafting::Craft_Info.each_key do |craft_id|
  312.           print "Craft ID: "; p craft_id
  313.           total[craft_id] = 0
  314.           Venka::Crafting::Recipes.each_key do |recipe_id|
  315.             print "recipe ID: "; p recipe_id
  316.             next unless ($recipe[recipe_id].recipe_type == craft_id && $recipe[recipe_id].recipe_type == type) || ($recipe[recipe_id].recipe_type == craft_id && type == 0)
  317.             p "Adding to the total"
  318.             total[craft_id] += 1
  319.           end
  320.         end
  321.         print "Final totals: "; p total
  322.         grand_total = total.compact.inject{|sum, x| sum + x }
  323.         print "Grand Total: "; p grand_total
  324.       end
  325.     end
  326.     #==========================================================================
  327.     # ■ Crafting_Details_Window
  328.     #==========================================================================
  329.     class Crafting_Details_Window
  330.       #------------------------------------------------------------------------
  331.       # ○ new method: draw_ingredients
  332.       #------------------------------------------------------------------------
  333.       alias sixth_max_items_crafted draw_ingredients
  334.       def draw_ingredients
  335.         sixth_max_items_crafted
  336.         @max = [@max, Venka::Crafting::Max_Crafting].min if Venka::Crafting::Max_Crafting != nil
  337.         @max = @max / @recipe.crafted_amount if Venka::Crafting::Max_Total && Venka::Crafting::Max_Crafting != nil
  338.       end
  339.       #------------------------------------------------------------------------
  340.       # ○ new method: get_random_item
  341.       #------------------------------------------------------------------------
  342.       def get_random_item
  343.         item = []
  344.         @result_amount.times do |i|
  345.           if @recipe.crafted_item.is_a?(RPG::Weapon) && $craft.rand_weapons
  346.             item[i] = $game_party.add_weapon(@recipe.crafted_item.id, 1)
  347.           elsif @recipe.crafted_item.is_a?(RPG::Armor) && $craft.rand_armor
  348.             item[i] = $game_party.add_armor(@recipe.crafted_item.id, 1)
  349.           elsif @recipe.crafted_item.is_a?(RPG::Item) && $craft.rand_items
  350.             item[i] = $game_party.add_item(@recipe.crafted_item.id, 1)
  351.           end
  352.         end
  353.         $game_party.gain_item(@recipe.crafted_item, @result_amount) if item == []
  354.         item = (item == []) ? @recipe.crafted_item : item
  355.         return item
  356.       end
  357.       #------------------------------------------------------------------------
  358.       # ● overwrite method: success_rewards
  359.       #------------------------------------------------------------------------
  360.       def success_rewards
  361.         RPG::SE.new(*Success_Sound).play
  362.         unless SceneManager.scene_is?(Scene_Shop)
  363.           @result_exp     = @recipe.earned_exp * @number
  364.           @result_message = Result_Msg
  365.           $craft[@craft_id].gain_exp(@result_exp) if SceneManager.scene_is?(Scene_Crafting)
  366.         end
  367.         @result_amount  = @recipe.crafted_amount * @number
  368.         @result_item    = get_random_item
  369.       end
  370.     end
  371.   end  
  372.   if Venka::Crafting::Box_Version
  373.   #==============================================================================
  374.   # ■ Crafting_Results_Window
  375.   #==============================================================================
  376.   class Crafting_Results_Window < Window_Base
  377.     #----------------------------------------------------------------------------
  378.     # ○ new method: font_height
  379.     #----------------------------------------------------------------------------
  380.     def font_height
  381.       [contents.font.size, 24].max
  382.     end
  383.     #----------------------------------------------------------------------------
  384.     # ○ overwrite method: refresh
  385.     #----------------------------------------------------------------------------
  386.     def refresh
  387.       contents.clear
  388.       return if $craft.results == []
  389.       result_info
  390.       resize_window
  391.       draw_box_item
  392.       draw_header
  393.       draw_items_received
  394.       draw_box_exp         if @exp > 0
  395.       draw_exp_received    if @exp > 0
  396.       draw_level_up        if @leveled
  397.       draw_box_recipe      if @learned
  398.       draw_new_recipes     if @learned
  399.       wait_to_close
  400.       #$craft.clear_results
  401.     end
  402.     #----------------------------------------------------------------------------
  403.     # ○ overwrite method: win_width
  404.     #----------------------------------------------------------------------------
  405.     def win_width
  406.       set_font(:other_text)
  407.       # Checking the first box width with every possible conditions
  408.       case @message
  409.       when Venka::Crafting::Result_Msg
  410.         items = @item.is_a?(Array) ? @item.size : 1
  411.         widthi = 0
  412.         if @item.is_a?(Array)
  413.           @item.each do |item|
  414.             size   = text_size(item.name).width
  415.             widthi = size if size > widthi  
  416.             text = item.name
  417.           end
  418.         else
  419.           widthi = text_size(@item.name).width
  420.         end
  421.         if widthi < text_size(Venka::Crafting::Result_Msg).width
  422.           widthi = text_size(Venka::Crafting::Result_Msg).width
  423.         end
  424.         @width111 = widthi + text_size(" x#{@amount}").width + 14
  425.       when Venka::Crafting::Failed_Msg
  426.         @width111 = text_size(Venka::Crafting::Failed_Msg).width + 7
  427.       end
  428.       # Checking the second box with every possible conditions
  429.       if $craft[@craft_id].max_level?
  430.         text = Venka::Crafting::Max_Exp
  431.       else
  432.         text = Venka::Crafting::Exp_Earned + " #{@exp} Exp!"
  433.       end
  434.       width_xp = text_size(text).width
  435.       set_font(:button_text)
  436.       text2 = Venka::Crafting::Lv_Gain
  437.       width_lvl = text_size(text2).width
  438.       set_font(:other_text)
  439.       if @leveled
  440.         @width112 = [width_xp, width_lvl].max - 6
  441.       else
  442.         @width112 = text_size(text).width - 6
  443.       end
  444.       @width112 = 0 if @exp == 0
  445.       # Checking the third box with every possible conditions
  446.       if @learned && @learned != []
  447.         if @learned
  448.           widthr = 0
  449.           @learned.each do |recipe_id|
  450.             recipe = $recipe[recipe_id]
  451.             size   = text_size(recipe.display_name).width
  452.             widthr = size if size > widthr
  453.           end
  454.           if widthr < text_size(Venka::Crafting::Learn_Text).width
  455.             widthr = text_size(Venka::Crafting::Learn_Text).width
  456.           end
  457.           @width113 = widthr + 32
  458.           width113 = @width113 - 18
  459.         end
  460.       else
  461.         @width113 = 0
  462.         width113 = 0
  463.       end
  464.       # Calculating the final width of the window
  465.       return ([[[@width111, @width112].max, width113].max + 120, Graphics.width].min)
  466.     end
  467.     #----------------------------------------------------------------------------
  468.     # ○ overwrite method: win_height
  469.     #----------------------------------------------------------------------------
  470.     def win_height
  471.       h1 = Venka::Crafting::Fonts[:recipe_name][1] + standard_padding * 2
  472.       h2 = [Venka::Crafting::Fonts[:other_text][1], 24].max
  473.       set_font(:other_text)
  474.       height = h1 + h2
  475.       # Adding to height depending on the fisrt box height
  476.       if @message == Venka::Crafting::Result_Msg
  477.         items = @item.is_a?(Array) ? @item.size : 1
  478.         height += h2 * items
  479.       elsif @message == Venka::Crafting::Failed_Msg
  480.         height += -7
  481.       end
  482.       # Adding height if leveled
  483.       if @leveled
  484.         height += h2 + 7
  485.       end
  486.       # Adding height depending on the third box height
  487.       if @learned && @learned != []
  488.         height2 = 0
  489.         if @learned
  490.           @learned.each do |recipe_id|
  491.             recipe = $recipe[recipe_id]
  492.           end
  493.           height2 = h2 * @learned.size
  494.         end
  495.         height += height2 + h2 + 17
  496.       end
  497.       height -= 34 if @exp == 0
  498.       # Adding constant height needed
  499.       return height += 53
  500.     end
  501.     #----------------------------------------------------------------------------
  502.     # ○ new method: draw_box_frames
  503.     #----------------------------------------------------------------------------
  504.     def draw_box_frames(x, y, width, height, color1, color2, header = 0)
  505.       # top line - horizontal
  506.       contents.fill_rect(x - 15, y, width + 30, 1, color1)
  507.       contents.fill_rect(x - 14, y + 1, width + 28, 2, color2)
  508.       # adjust height if header box is used
  509.       height += header + ((header > 0) ? 8 : 3)
  510.       if header > 0
  511.         # middle line - horizontal
  512.         contents.fill_rect(x - 14, y + header + 3, width + 28, 2, color2)
  513.         contents.fill_rect(x - 15, y + header + 5, width + 30, 1, color1)
  514.         contents.fill_rect(x - 14, y + header + 6, width + 28, 2, color2)
  515.       end
  516.       # bottom line - horizontal
  517.       contents.fill_rect(x - 15, y + height + 2, width + 30, 1, color1)
  518.       contents.fill_rect(x - 14, y + height, width + 28, 2, color2)
  519.       # left line - vertical
  520.       contents.fill_rect(x - 15, y, 1, height + 2, color1)
  521.       contents.fill_rect(x - 14, y + 1, 2, height, color2)
  522.       # right line - vertical
  523.       contents.fill_rect(x + width + 14, y, 1, height + 2, color1)
  524.       contents.fill_rect(x + width + 12, y + 1, 2, height, color2)
  525.     end
  526.     #----------------------------------------------------------------------------
  527.     # ○ new method: draw_box_item
  528.     #----------------------------------------------------------------------------
  529.     def draw_box_item
  530.       header_height = [[Venka::Crafting::Fonts[:recipe_name][1], 26].max, 26].min
  531.       set_font(:other_text)
  532.       color1 = Color.new(*Venka::Crafting::Item_Border_Out)
  533.       color2 = Color.new(*Venka::Crafting::Item_Border_In)
  534.       color_result = Color.new(*Venka::Crafting::Results_Box)
  535.       color_failed = Color.new(*Venka::Crafting::Failed_Box)
  536.       color_items = Color.new(*Venka::Crafting::Crafted_Items_Box)
  537.       @width111 += 18
  538.       x = (contents_width - @width111) / 2
  539.       case @message
  540.       when Venka::Crafting::Result_Msg
  541.         items = @item.is_a?(Array) ? @item.size : 1
  542.         box_height = (font_height * items) + 2
  543.         # filler message
  544.         contents.fill_rect(x - 12, 30, @width111 + 24, header_height, color_result)
  545.         # filler item
  546.         contents.fill_rect(x - 12, 61, @width111 + 24, box_height, color_items)
  547.         draw_box_frames(x, 27, @width111, box_height, color1, color2, header_height)
  548.       when Venka::Crafting::Failed_Msg
  549.         # filler message
  550.         contents.fill_rect(x - 12, 30, @width111 + 24, header_height, color_failed)
  551.         draw_box_frames(x, 27, @width111, header_height, color1, color2)
  552.       end
  553.     end
  554.     #----------------------------------------------------------------------------
  555.     # ○ overwrite method: draw_header
  556.     #----------------------------------------------------------------------------
  557.     def draw_header
  558.       set_font(:recipe_name)
  559.       height = contents.font.size
  560.       draw_text(0, 0, contents.width, height, Venka::Crafting::Results_Text, 1)
  561.       @y = height
  562.       color = normal_color
  563.       contents.fill_rect(0, height - 2, contents_width, 1, color)
  564.       color.alpha = 90
  565.       contents.fill_rect(0, height - 1, contents_width, 1, color)
  566.       set_font(:other_text)
  567.       case @message
  568.       when Venka::Crafting::Result_Msg
  569.         draw_text(0, @y + 6, contents.width, font_height, @message, 1)
  570.         @y += 32
  571.       when Venka::Crafting::Failed_Msg
  572.         @y += 1
  573.       end
  574.       @y += 5
  575.     end
  576.     #----------------------------------------------------------------------------
  577.     # ○ overwrite method: draw_items_received
  578.     #----------------------------------------------------------------------------
  579.     def draw_items_received
  580.       set_font(:other_text)
  581.       case @message
  582.       when Venka::Crafting::Result_Msg
  583.         @item.is_a?(Array) ? @item.each {|item| draw_item(item)} : draw_item(@item, @amount)
  584.       when Venka::Crafting::Failed_Msg
  585.         draw_text(0, @y, contents.width, font_height, @message, 1)
  586.         @y += font_height
  587.       end
  588.     end
  589.     #----------------------------------------------------------------------------
  590.     # ○ new method: draw_item
  591.     #----------------------------------------------------------------------------
  592.     def draw_item(item, amount = 1)
  593.       set_font(:other_text)
  594.       text = item.name + " x#{amount}"
  595.       item_width = text_size(text).width + 30
  596.       x1 = (contents.width - text_size(item.name).width) / 2 - 27
  597.       if $imported[:MAIcon_Hue]
  598.         draw_icon_with_hue(item.icon_index, item.icon_hue, x1, @y)
  599.       else
  600.         draw_icon(item.icon_index, x1, @y)
  601.       end
  602.       change_color(item.color)
  603.       draw_text(-5, @y, contents.width + 10, font_height, item.name, 1)
  604.       set_font(:other_text)
  605.       x2 = contents.width - ((contents.width - text_size(item.name).width) / 2 ) + 1
  606.       draw_text(x2, @y, contents.width + 10, font_height, " x#{amount}")
  607.       @y += font_height
  608.     end
  609.     #----------------------------------------------------------------------------
  610.     # ○ new method: draw_box_exp
  611.     #----------------------------------------------------------------------------
  612.     def draw_box_exp
  613.       set_font(:other_text)
  614.       color1 = Color.new(*Venka::Crafting::Exp_Border_Out)
  615.       color2 = Color.new(*Venka::Crafting::Exp_Border_In)
  616.       color_exp = Color.new(*Venka::Crafting::Exp_Text_Box)
  617.       color_level = Color.new(*Venka::Crafting::Level_Up_Box)
  618.       @width112 += 12
  619.       x = (contents_width - @width112) / 2
  620.       h2 = [[font_height, 26].max, 26].min
  621.       # filler exp message
  622.       contents.fill_rect(x - 12, @y + 9, @width112 + 24, h2, color_exp)
  623.       if @leveled && Venka::Crafting::Level_Up_Box
  624.         h = [[Venka::Crafting::Fonts[:button_text][1], 26].max, 26].min
  625.         # filler lvl message
  626.         contents.fill_rect(x - 12, @y + h + 14, @width112 + 24, h, color_level)
  627.         draw_box_frames(x, @y + 6, @width112, h2, color1, color2, h)
  628.       else
  629.         draw_box_frames(x, @y + 6, @width112, h2, color1, color2)
  630.       end
  631.     end
  632.     #----------------------------------------------------------------------------
  633.     # ○ overwrite method: draw_exp_received
  634.     #----------------------------------------------------------------------------
  635.     def draw_exp_received
  636.       set_font(:other_text)
  637.       @y += 10
  638.       if $craft[@craft_id].max_level?
  639.         text = Venka::Crafting::Max_Exp
  640.       else
  641.         text = Venka::Crafting::Exp_Earned + " #{@exp} Exp!"
  642.       end
  643.       draw_text(- 5, @y, contents.width + 10, font_height, text, 1)
  644.       @y += font_height
  645.     end
  646.     #----------------------------------------------------------------------------
  647.     # ○ new method: draw_level_up
  648.     #----------------------------------------------------------------------------
  649.     def draw_level_up
  650.       set_font(:button_text)
  651.       height = contents.font.size
  652.       draw_text(0, @y + 6, contents.width, height, Venka::Crafting::Lv_Gain, 1)
  653.       @y += height
  654.     end
  655.     #----------------------------------------------------------------------------
  656.     # ○ new method: draw_box_recipe
  657.     #----------------------------------------------------------------------------
  658.     def draw_box_recipe
  659.       set_font(:other_text)
  660.       color1 = Color.new(*Venka::Crafting::Recipe_Border_Out)
  661.       color2 = Color.new(*Venka::Crafting::Recipe_Border_In)
  662.       color_recipe = Color.new(*Venka::Crafting::Learned_Recipes_Box)
  663.       color_text = Color.new(*Venka::Crafting::Recipe_Text_Box)
  664.       @width113 += 18
  665.       x = (contents_width - @width113) / 2
  666.       return unless @learned && @learned != []
  667.       h = (@learned.size * font_height) + 2
  668.       h2 = [[font_height, 26].max, 26].min
  669.       # filler recipe message
  670.       contents.fill_rect(x - 3, @y + 16, @width113 + 6, h2, color_text)
  671.       # filler recipes
  672.       contents.fill_rect(x - 3, @y + h2 + 21, @width113 + 6, h, color_recipe)
  673.       draw_box_frames(x + 9, @y + 13, @width113 - 18, h, color1, color2, h2)
  674.     end
  675.     #----------------------------------------------------------------------------
  676.     # ○ overwrite method: draw_new_recipes
  677.     #----------------------------------------------------------------------------
  678.     def draw_new_recipes
  679.       @y += 48
  680.       set_font(:other_text)
  681.       prefix = Venka::Crafting::Learn_Text
  682.       draw_text(-5, @y - 31, contents.width + 10, font_height, prefix, 1) if @learned && @learned != []
  683.       @learned.each do |recipe_id|
  684.         recipe = $recipe[recipe_id]
  685.         name_width = text_size(recipe.display_name).width + 5
  686.         x = (contents.width - name_width - 25) / 2
  687.         if $imported[:MAIcon_Hue]
  688.           draw_icon_with_hue(recipe.crafted_item.icon_index, @item.icon_hue, x, @y)
  689.         else
  690.           draw_icon(recipe.crafted_item.icon_index, x, @y)
  691.         end
  692.         draw_text(x + 25, @y, contents.width + 10, font_height, recipe.display_name)
  693.         @y += font_height
  694.       end
  695.     end
  696.     #----------------------------------------------------------------------------
  697.     # ○ new method: draw_arrow (!!not used for now!!)
  698.     #----------------------------------------------------------------------------
  699.     def draw_arrow(x, y, width, height)
  700.       set_font(:arrows)
  701.       draw_text(0, y, contents.width, height, "→", 1)
  702.       set_font(:other_text)
  703.     end
  704.   end
  705.  
  706.   else
  707.  
  708.   #==============================================================================
  709.   # ■ Crafting_Results_Window
  710.   #==============================================================================
  711.   class Crafting_Results_Window < Window_Base
  712.     #----------------------------------------------------------------------------
  713.     # ○ new method: font_height
  714.     #----------------------------------------------------------------------------
  715.     def font_height
  716.       [contents.font.size, 24].max
  717.     end
  718.     #----------------------------------------------------------------------------
  719.     # ○ overwrite method: win_width
  720.     # ----------------------------------------------------------------------------
  721.     def win_width
  722.       set_font(:other_text)
  723.       # Items crafted width
  724.       width = 0
  725.       if @message == Venka::Crafting::Result_Msg
  726.         if @item.is_a?(Array)
  727.           @item.each do |item|
  728.             size   = text_size(item.name).width
  729.             width = size if size > width      
  730.           end
  731.           text = @message + "x#{@amount}"
  732.         else
  733.           text = @message + "x#{@amount}" + @item.name
  734.         end
  735.         width1 = text_size(text).width + 50 + standard_padding * 2 + 10
  736.         width1 += width if @item.is_a?(Array)
  737.       else
  738.         width1 = text_size(@message).width + 10 + standard_padding * 2
  739.       end
  740.       # Recipes learned width
  741.       width2 = 50 + standard_padding * 2
  742.       if @learned
  743.         @learned.each do |recipe_id|
  744.           recipe = $recipe[recipe_id]
  745.           size   = text_size(recipe.display_name).width
  746.           width  = size if size > width      
  747.         end
  748.         width2 += text_size(Venka::Crafting::Learn_Text).width + width
  749.       end
  750.       # Exp message & level up width
  751.       if $craft[@craft_id].max_level?
  752.         text = Venka::Crafting::Max_Exp
  753.       else
  754.         text = Venka::Crafting::Exp_Earned + " #{@exp} Exp!"
  755.       end
  756.       width_xp = text_size(text).width
  757.       set_font(:button_text)
  758.       text2 = Venka::Crafting::Lv_Gain
  759.       width_lvl = text_size(text2).width
  760.       set_font(:other_text)
  761.       if @leveled
  762.         width3 = [width_xp, width_lvl].max + 50
  763.       else
  764.         width3 = text_size(text).width + 50
  765.       end
  766.       width3 = 0 if @exp == 0
  767.       return ([[[width1, width2].max, width3].max + 30, Graphics.width].min)
  768.     end
  769.     #----------------------------------------------------------------------------
  770.     # ○ new method: win_height
  771.     #----------------------------------------------------------------------------
  772.     def win_height
  773.       h1 = Venka::Crafting::Fonts[:recipe_name][1] + standard_padding * 2
  774.       h2 = [Venka::Crafting::Fonts[:other_text][1], 24].max
  775.       height = h1 + h2 + (h2 * (@learned ? @learned.size : 0)) + 3
  776.       height += [Venka::Crafting::Fonts[:button_text][1], 24].max + 4 if @leveled
  777.       items = @item.is_a?(Array) ? @item.size : 1
  778.       height += h2 * items
  779.       height -= h2 if @exp == 0
  780.       return height
  781.     end
  782.     #----------------------------------------------------------------------------
  783.     # ○ overwrite method: draw_items_received
  784.     #----------------------------------------------------------------------------
  785.     def draw_items_received
  786.       set_font(:other_text)
  787.       case @message
  788.       when Venka::Crafting::Result_Msg
  789.         items = @item.is_a?(Array) ? @item.size : 1
  790.         h1 = font_height * items
  791.         x = text_size(@message).width + text_size("→").width + 20
  792.         color = normal_color
  793.         contents.fill_rect(x, @y + 1, 1, h1, color)
  794.         color.alpha = 90
  795.         contents.fill_rect(x + 1, @y + 1, 1, h1, color)
  796.         @item.is_a?(Array) ? @item.each {|item| draw_item(item)} : draw_item(@item, @amount)
  797.         draw_text(0, @y/2, contents.width, font_height, @message)
  798.         x = text_size(@message).width + 5
  799.         draw_arrow(x + Venka::Crafting::Arrow_x_Item, @y/2, text_size("→").width + 15, font_height)
  800.         if @exp > 0
  801.           color = normal_color
  802.           contents.fill_rect(0, @y + 2, contents_width, 1, color)
  803.           color.alpha = 90
  804.           contents.fill_rect(0, @y + 3, contents_width, 1, color)
  805.         end
  806.         @y += font_height - (font_height - 3)
  807.       when Venka::Crafting::Failed_Msg
  808.         draw_text(0, @y, contents.width, font_height, @message, 1)
  809.         @y += font_height
  810.         if @exp > 0
  811.           color = normal_color
  812.           contents.fill_rect(0, @y + 2, contents_width, 1, color)
  813.           color.alpha = 90
  814.           contents.fill_rect(0, @y + 3, contents_width, 1, color)
  815.         end
  816.         @y += font_height - (font_height - 3)
  817.       end
  818.     end
  819.     #----------------------------------------------------------------------------
  820.     # ○ new method: draw_item
  821.     #----------------------------------------------------------------------------
  822.     def draw_item(item, amount = 1)
  823.       set_font(:other_text)
  824.       x = 0
  825.       x += text_size(@message).width + 5
  826.       x += text_size("→").width + 15
  827.       width = contents.width - x
  828.       text = item.name + " x#{amount}"
  829.       item_width = text_size(text).width + 40
  830.       x = x + (width - item_width) * 0.5 + 5
  831.       if $imported[:MAIcon_Hue]
  832.         draw_icon_with_hue(item.icon_index, item.icon_hue, x, @y)
  833.       else
  834.         draw_icon(item.icon_index, x, @y)
  835.       end
  836.       x += 25
  837.       change_color(item.color)
  838.       draw_text(x, @y, contents.width - x, font_height, item.name)
  839.       set_font(:other_text)
  840.       x += text_size(item.name).width + 5
  841.       draw_text(x, @y, contents.width - x, font_height, " x#{amount}")
  842.       @y += font_height
  843.     end
  844.     #----------------------------------------------------------------------------
  845.     # ○ overwrite method: draw_exp_received
  846.     #----------------------------------------------------------------------------
  847.     def draw_exp_received
  848.       set_font(:other_text)
  849.       text = $craft[@craft_id].max_level? ? Venka::Crafting::Max_Exp : "#{@exp} Exp"
  850.       total_text = Venka::Crafting::Exp_Earned + "→" + text
  851.       text_width = text_size(total_text).width + 25
  852.       x = (contents.width - text_width) * 0.5
  853.       draw_text(x, @y, contents.width, font_height, Venka::Crafting::Exp_Earned)
  854.       x += text_size(Venka::Crafting::Exp_Earned).width + 5
  855.       draw_arrow(x + Venka::Crafting::Arrow_x_Exp, @y, text_size("→").width + 15, font_height)
  856.       x += text_size("→").width + 15
  857.       draw_text(x, @y, contents.width, font_height, text)
  858.       @y += font_height
  859.     end
  860.     #----------------------------------------------------------------------------
  861.     # ○ overwrite method: draw_level_up
  862.     #----------------------------------------------------------------------------
  863.     def draw_level_up
  864.       set_font(:button_text)
  865.       height = contents.font.size
  866.       draw_text(0, @y, contents.width, height, Venka::Crafting::Lv_Gain, 1)
  867.       @y += height
  868.       if @learned && @learned != []
  869.       color = normal_color
  870.       contents.fill_rect(0, @y + 2, contents_width, 1, color)
  871.       color.alpha = 90
  872.       contents.fill_rect(0, @y + 3, contents_width, 1, color)
  873.       @y += font_height - (font_height - 4)
  874.       end
  875.     end
  876.     #----------------------------------------------------------------------------
  877.     # ○ overwrite method: draw_new_recipes
  878.     #----------------------------------------------------------------------------
  879.     def draw_new_recipes
  880.       set_font(:other_text)
  881.       prefix = Venka::Crafting::Learn_Text
  882.       widthr = 0
  883.       @learned.each do |recipe_id|
  884.         recipe = $recipe[recipe_id]
  885.         size   = text_size(recipe.display_name).width
  886.         widthr  = size if size > widthr
  887.         widthrx = contents.width - widthr
  888.         x = 0
  889.         x += text_size(prefix).width + 5
  890.         x += text_size("→").width + 15
  891.         width = contents.width - x + 10
  892.         widthx = contents.width - width + 19
  893.         iconx = (width - text_size(recipe.display_name).width) / 2 + widthx - 28
  894.         if $imported[:MAIcon_Hue]
  895.           draw_icon_with_hue(recipe.crafted_item.icon_index, @item.icon_hue, iconx, @y)
  896.         else
  897.           draw_icon(recipe.crafted_item.icon_index, iconx, @y)
  898.         end
  899.         draw_text(widthx - 5, @y, width + 10, font_height, recipe.display_name, 1)
  900.         @y += font_height
  901.       end
  902.       h2 = font_height * @learned.size + 6
  903.       x2 = text_size(prefix).width + 5 + text_size("→").width + 15
  904.       y2 = @y - font_height * @learned.size
  905.       if @learned && @learned != []
  906.         color = normal_color
  907.         contents.fill_rect(x2 + Venka::Crafting::Arrow_x_Rec, y2 + 1, 1, h2, color)
  908.         color.alpha = 90
  909.         contents.fill_rect(x2 + 1 + Venka::Crafting::Arrow_x_Rec, y2 + 1, 1, h2, color)
  910.       end
  911.       x = text_size(prefix).width + 5
  912.       y1 = @y - font_height/2 - (@learned.size * font_height)/2
  913.       draw_text(0, y1, contents.width, font_height, prefix) if @learned && @learned != []
  914.       draw_arrow(x + Venka::Crafting::Arrow_x_Rec, y1, text_size("→").width + 15, font_height) if @learned && @learned != []
  915.     end
  916.     #----------------------------------------------------------------------------
  917.     # ○ new method: draw_arrow
  918.     #----------------------------------------------------------------------------
  919.     def draw_arrow(x, y, width, height)
  920.       set_font(:arrows)
  921.       draw_text(x, y, width, height, "→", 1)
  922.       set_font(:other_text)
  923.     end  
  924.   end
  925.  
  926. end
  927.  
  928. rescue
  929.   msgbox("The Randomization Addon for the crafting script requires that you use Vlue's Weapon/Armor Randomization Script!")
  930. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement