Advertisement
mrbubble

Tactics Ogre PSP Crafting System

Jul 25th, 2012
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 71.27 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Tactics Ogre PSP Crafting System ++                        v1.5 (7/29/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. # Thanks:
  7. #     Mithran, regexp references
  8. #--------------------------------------------------------------------------
  9. # This item crafting script is modeled after the crafting system implemented
  10. # in the PSP remake of Tactics Ogre: Let Us Cling Together. It's a very
  11. # simple crafting system with a very simple GUI which I also used as
  12. # a model.
  13. #
  14. # Players must have recipe books in their inventory when entering the
  15. # crafting scene. Any recipe books owned by the player will be displayed
  16. # in a list. When a recipe book is selected, all possible items, armors,
  17. # and weapons in the recipe book will be listed and you will be able to
  18. # craft them provided that the player has the necessary ingredients.
  19. #
  20. # Newly added features include being able set a crafting gold fee for
  21. # item crafted and adding a Tool requirement to craft items. Tools
  22. # are not consumed when used in the crafting process.
  23. #--------------------------------------------------------------------------
  24. #   ++ Changelog ++
  25. #--------------------------------------------------------------------------
  26. # v1.5 : You can now change the recipebook pictures directory.
  27. #      : You can now assign sound effects for crafted items.
  28. #      : Slight code efficiency update. (7/29/2012)
  29. # v1.4 : Added the option to use images as recipebook covers.
  30. #      : New Notetag for recipebooks added.
  31. #      : New option in customization module for book images. (7/27/2012)
  32. # v1.3 : Colon between type and ID no longer needed.
  33. #      : Updated comments to reflect changes.
  34. #      : Tool regexp updated. (7/27/2012)
  35. # v1.2 : You can now change the Gold icon in the customization module.
  36. #      : You can now change the name of Gold in windows. (7/27/2012)
  37. # v1.1 : Fixed issue with long item names getting cut off in windows.
  38. #      : Confirm window removed.
  39. #      : Quantity selection window implemented.
  40. #      : Crafting Gold fee implemented.
  41. #      : Crafting tool requirement implemented.
  42. #      : New options added in customization module. (7/26/2012)
  43. # v1.0 : Initial release. (7/25/2012)
  44. #--------------------------------------------------------------------------
  45. #   ++ Installation ++
  46. #--------------------------------------------------------------------------
  47. # Install this script in the Materials section in your project's
  48. # script editor.
  49. #==============================================================================
  50. #   ++ TO Crafting Notetags ++
  51. #==============================================================================
  52. # Note: Some tags are given shorter tags for typing convenience. You only
  53. #       need to use one <tag> from a given group for a notebox.
  54. #       Use common sense.
  55. #
  56. # The following Notetags are for Items, Weapons, and Armors only:
  57. #
  58. # <recipebook>
  59. # setting
  60. # setting
  61. # </recipebook>
  62. #   This tag allows you define a recipe book. You can add as many
  63. #   settings between the <recipebook> tags as you like. Only items with
  64. #   this tag will appear in the recipes window in the crafting scene.
  65. #   The following settings are available:
  66. #
  67. #     item: id
  68. #     item: id, id, id ...
  69. #     i: id
  70. #     i: id, id, id ...
  71. #       This setting defines the items that can be crafted from the
  72. #       recipe book where id is the Item ID number found in your database.
  73. #       You can list multiple id numbers on the same line separated by commas.
  74. #       This setting can be used multiple times within the <recipebook> tags.
  75. #
  76. #     weapon: id
  77. #     weapon: id, id, id ...
  78. #     w: id
  79. #     w: id, id, id ...
  80. #       This setting defines the weapons that can be crafted from the
  81. #       recipe book where id is the Weapon ID number found in your database.
  82. #       You can list multiple id numbers on the same line separated by commas.
  83. #       This setting can be used multiple times within the <recipebook> tags.
  84. #      
  85. #     armor: id
  86. #     armor: id, id, id ...
  87. #     armour: id
  88. #     armour: id, id, id ...
  89. #     a: id
  90. #     a: id, id, id ...
  91. #       This setting defines the armors that can be crafted from the
  92. #       recipe book where id is the Armor ID number found in your database.
  93. #       You can list multiple id numbers on the same line separated by commas.
  94. #       This setting can be used multiple times within the <recipebook> tags.
  95. #
  96. #     picture: filename
  97. #     pic: filename
  98. #     cover: filename
  99. #       This setting defines the image used to represent the recipe book
  100. #       in the crafting scene where filename is the name of a picture
  101. #       located in the Graphics/Pictures/ folder of your project. Do
  102. #       not include the filename's extension. Recommended picture
  103. #       resolutions are [width: 248, height: 320] for default resolutions
  104. #       and [width: 296, height: 384] for 480x640 resolutions.
  105. #  
  106. # <ingredients>
  107. # setting
  108. # setting
  109. # </ingredients>
  110. #   This tag allows you define the ingredients required to craft an item.
  111. #   You can add as many settings between the <ingredients> tags as you like.
  112. #   If an item, weapon, or armor has no ingredients, you can still craft it.
  113. #   The following settings are available:
  114. #
  115. #     item: id
  116. #     item: id xN
  117. #     i: id
  118. #     i: id xN
  119. #       This setting defines the item ingredients required to craft the
  120. #       item, weapon, or armor where id is the Item ID number found in
  121. #       your database. xN is total number of that ingredient required if
  122. #       it is included after the id number where N is a whole number
  123. #       (ex. x2, x3, x4, etc.). If xN is not included, the script will
  124. #       automatically assume x1. You can list multiple id numbers on the
  125. #       same line separated by commas. This setting can be used multiple
  126. #       times within the <ingredients> tags.
  127. #
  128. #     weapon: id
  129. #     weapon: id xN
  130. #     w: id
  131. #     w: id xN
  132. #       This setting defines the weapon ingredients required to craft the
  133. #       item, weapon, or armor where id is the Weapon ID number found in
  134. #       your database. xN is total number of that ingredient required if
  135. #       it is included after the id number where N is a whole number
  136. #       (ex. x2, x3, x4, etc.). If xN is not included, the script will
  137. #       automatically assume x1. You can list multiple id numbers on the
  138. #       same line separated by commas. This setting can be used multiple
  139. #       times within the <ingredients> tags.
  140. #
  141. #     armor: id
  142. #     armor: id xN
  143. #     armour: id
  144. #     armour: id xN
  145. #     a: id
  146. #     a: id xN
  147. #       This setting defines the armor ingredients required to craft the
  148. #       item, weapon, or armor where id is the Weapon ID number found in
  149. #       your database. xN is total number of that ingredient required if
  150. #       it is included after the id number where N is a whole number
  151. #       (ex. x2, x3, x4, etc.). If xN is not included, the script will
  152. #       automatically assume x1. You can list multiple id numbers on the
  153. #       same line separated by commas. This setting can be used multiple
  154. #       times within the <ingredients> tags.
  155. #
  156. #     fee: amount
  157. #     gold: amount
  158. #       This setting defines the amount of Gold required to craft
  159. #       the item, armor, or weapon where amount is any amount of gold.
  160. #       If this setting is omitted, it will use the default fee defined
  161. #       in the customization module.
  162. #
  163. #     tool: item id
  164. #     tool: i id
  165. #     tool: weapon id
  166. #     tool: w id
  167. #     tool: armor id
  168. #     tool: armour id
  169. #     tool: a id
  170. #       This setting defines the tools required to craft the item, weapon,
  171. #       or armor where id is the item, weapon, or armor ID number found in
  172. #       your database. Tools are not consumed in the crafting process.
  173. #       This setting can be used multiple times within the <ingredients>
  174. #       tags.
  175. #    
  176. #     se: filename, volume, pitch
  177. #       This settings defines the custom sound effect played when the
  178. #       item is crafted. filename is a sound effect filename found in
  179. #       the Audio/SE/ folder. volume is a value between 0~100. pitch is
  180. #       a value between 50~150. If this setting is omitted, the default
  181. #       crafting sound effect defined in the customization module will
  182. #       play instead.
  183. #      
  184. # Here are some examples of proper <recipebook> tags and <ingredients> tags:
  185. #
  186. #     <recipebook>
  187. #     weapon: 1, 2, 7, 8, 13, 14, 19, 20
  188. #     weapon: 25, 37, 38
  189. #     armor: 1, 2, 3, 4, 5
  190. #     item: 40
  191. #     </recipebook>
  192. #
  193. # It is important to know that Note boxes have iffy word wrap distinction.
  194. # If a line is too long and overflows into the next line, that next line
  195. # might be treated as a new line in the Note box. To stay on the safe side,
  196. # if you have a long list of ids for a single item type setting, you
  197. # should start the next line with the similar type setting. See the
  198. # "weapon:" settings in this example tag.
  199. #
  200. #     <ingredients>
  201. #     item: 29 x3
  202. #     item: 30 x2
  203. #     item: 31
  204. #     </ingredients>
  205. #
  206. # Each ingredient id must be on its own line, unlike the recipebook tag.
  207. # More than 6 ingredients are possible, but the Required Ingredients
  208. # window will not display more than 6. The last setting tag "item: 31" does
  209. # not have an "xN" multiplier which means the script will automatically
  210. # assume "x1".
  211. #
  212. #     <ingredients>
  213. #     fee: 30
  214. #     se: Bell3, 80, 100
  215. #     tool: item 40
  216. #     item: 21
  217. #     item: 22 x2
  218. #     </ingredients>
  219. #
  220. # This tag is an example of how to use the "fee" and "tool" setting tags.
  221. # Item ID 40 is required to craft the item, but it will not be consumed.
  222. # Each item crafted costs 30 gold. The sound effect Bell3 will play
  223. # when the item is crafted.
  224. #
  225. #==============================================================================
  226. #   ++ TO Crafting Script Calls ++
  227. #==============================================================================
  228. # The following Script Calls are meant to be used in "Script..." event
  229. # commands found under Tab 3 when creating a new event.
  230. #
  231. # open_tocrafting_shop
  232. #   This script call opens up the Tactics Ogre Crafting scene.
  233. #
  234. #--------------------------------------------------------------------------
  235. #   ++ FAQ ++
  236. #--------------------------------------------------------------------------
  237. # --Why am I allowed to craft items that have no required ingredients?
  238. #
  239. #     This was done on purpose to ease game development. I assumed that
  240. #     when people finalize a game, they will have an appropriate list of
  241. #     ingredients for each craftable item defined by then.
  242. #
  243. # --Can an item/armor/weapon have a <recipebook> tag AND an <ingredients>
  244. #   tag?
  245. #  
  246. #     Yes.
  247. #
  248. # --Can the "Required Ingredients" window display more than 6 ingredients?
  249. #
  250. #     Currently, no.
  251. #      
  252. # --Can items have more than 6 different required ingredients?
  253. #    
  254. #     Yes, but the player won't be able to see the required ingredients
  255. #     beyond the first 6. If there is a demand for displaying more than
  256. #     6, I can implement it.
  257. #
  258. # --Why isn't "Success Rate" also implemented in this script from
  259. #   Tactics Ogre PSP?
  260. #
  261. #     Because I think Success Rate on crafting in single-player games
  262. #     is annoying and pointless due to save and load. But if there is
  263. #     demand for it, I can implement it.
  264. #--------------------------------------------------------------------------
  265. #   ++ Compatibility ++
  266. #--------------------------------------------------------------------------
  267. # This script aliases the following default VXA methods:
  268. #
  269. #     DataManager#load_database
  270. #    
  271. # There are no default method overwrites.
  272. #
  273. # Requests for compatibility with other scripts are welcome.
  274. #--------------------------------------------------------------------------
  275. #   ++ Terms and Conditions ++
  276. #--------------------------------------------------------------------------
  277. # Please do not repost this script elsewhere without permission.
  278. # Free for non-commercial use. For commercial use, contact me first.
  279. #
  280. # Newest versions of this script can be found at
  281. #                                           http://mrbubblewand.wordpress.com/
  282. #==============================================================================
  283.  
  284. $imported ||= {}
  285. $imported["BubsTOCrafting"] = true
  286.  
  287. #==========================================================================
  288. # ++ START OF USER CUSTOMIZATION MODULE ++
  289. #==========================================================================
  290. module Bubs
  291.   #==========================================================================
  292.   # ++ TO Crafting Settings
  293.   #==========================================================================
  294.   module TOCrafting
  295.   #--------------------------------------------------------------------------
  296.   #   Ingredients List Display Settings
  297.   #--------------------------------------------------------------------------
  298.   INGREDIENTS_HEADER_TEXT = "Required Ingredients" # Header text
  299.   NOT_ENOUGH_INGREDIENTS_COLOR = 10 # Windowskin color index, default 10 (red)
  300.  
  301.   #--------------------------------------------------------------------------
  302.   #   Tools Window Display Settings
  303.   #--------------------------------------------------------------------------
  304.   TOOL_AVAILABLE_TEXT = "Available"
  305.   TOOL_AVAILABLE_TEXT_COLOR = 3 # Windowskin color index, default 3 (green)
  306.   TOOL_UNAVAILABLE_TEXT = "Unavailable"
  307.   TOOL_UNAVAILABLE_TEXT_COLOR = 10 # Windowskin color index, default 10 (red)
  308.  
  309.   #--------------------------------------------------------------------------
  310.   #   Faded Requirement Not Met Display Settings
  311.   #--------------------------------------------------------------------------
  312.   # true  : Ingredient quantity and Tool requirement text will be faded
  313.   #         out like the item name if the requirement isn't met
  314.   # false : Ingredient quantity and Tool requirement text will not be faded
  315.   FADED_REQUIREMENT_QUANTITY = false
  316.  
  317.   #--------------------------------------------------------------------------
  318.   #   Crafting Fee Default Markdown/Markup Rate
  319.   #--------------------------------------------------------------------------
  320.   # If a "fee: amount" setting is not included in an <ingredients> tag,
  321.   # it will use the item's Price in the database by default. This setting
  322.   # allows you to automatically increase or decrease that item, armor
  323.   # or weapon price by a specified rate where 100.0 is normal price and
  324.   # 0.0 is free.
  325.   CRAFTING_FEE_PRICE_RATE = 0.0
  326.   #--------------------------------------------------------------------------
  327.   #   Gold Window Settings
  328.   #--------------------------------------------------------------------------
  329.   # true  : Gold window appears in crafting scene
  330.   # false : Gold crafting fees appear in ingredients list, no gold window
  331.   USE_GOLD_WINDOW = true
  332.   GOLD_WINDOW_ICON_INDEX = 361 # Icon Index number
  333.   GOLD_WINDOW_TEXT = "Gold"
  334.  
  335.   #--------------------------------------------------------------------------
  336.   #   Crafting Result Header Text
  337.   #--------------------------------------------------------------------------
  338.   RESULT_WINDOW_HEADER_TEXT = "You Received"
  339.  
  340.   #--------------------------------------------------------------------------
  341.   #   Stretch Recipebook Pictures Setting
  342.   #--------------------------------------------------------------------------
  343.   # Recommended width and height for book covers images:
  344.   #
  345.   #     width: 248, height: 320 (default resolutions)
  346.   #     width: 296, height: 384 (480x640 resolutions)
  347.   #
  348.   # true  : Book cover pics are stretched to fit the contents of the window.
  349.   # false : Book cover pics are drawn normally.
  350.   STRETCH_RECIPEBOOK_PICTURES = false
  351.   #--------------------------------------------------------------------------
  352.   #   Recipebook Images Folder Directory
  353.   #--------------------------------------------------------------------------
  354.   # Project folder where recipebook pictures are located.
  355.   #
  356.   # Default: "Graphics/Pictures/"
  357.   RECIPEBOOK_PICTURES_DIRECTORY = "Graphics/Pictures/"
  358.  
  359.   #--------------------------------------------------------------------------
  360.   #   Default Crafting Result Sound Effect
  361.   #--------------------------------------------------------------------------
  362.   #                     "filename", Volume, Pitch
  363.   CRAFTING_RESULT_SE = [   "Bell2",     80,   100]
  364.  
  365.   end # module TOCrafting
  366. end # module Bubs
  367.  
  368. #==========================================================================
  369. # ++ END OF USER CUSTOMIZATION MODULE ++
  370. #==========================================================================
  371.  
  372.  
  373. #==============================================================================
  374. # ++ Sound
  375. #==============================================================================
  376. module Sound
  377.   #--------------------------------------------------------------------------
  378.   # new method : play_tocrafting_result
  379.   #--------------------------------------------------------------------------
  380.   def self.play_tocrafting_result
  381.     filename = Bubs::TOCrafting::CRAFTING_RESULT_SE[0]
  382.     volume = Bubs::TOCrafting::CRAFTING_RESULT_SE[1]
  383.     pitch = Bubs::TOCrafting::CRAFTING_RESULT_SE[2]
  384.     Audio.se_play("/Audio/SE/" + filename, volume, pitch)
  385.   end
  386.  
  387.   #--------------------------------------------------------------------------
  388.   # new method : play_custom_tocrafting_result
  389.   #--------------------------------------------------------------------------
  390.   def self.play_custom_tocrafting_result(filename, volume, pitch)
  391.     Audio.se_play("/Audio/SE/" + filename, volume, pitch)
  392.   end
  393. end # module Sound
  394.  
  395.  
  396. #==============================================================================
  397. # ++ Cache
  398. #==============================================================================
  399. module Cache
  400.   #--------------------------------------------------------------------------
  401.   # new method : recipebook_cover
  402.   #--------------------------------------------------------------------------
  403.   def self.recipebook_cover(filename)
  404.     load_bitmap(Bubs::TOCrafting::RECIPEBOOK_PICTURES_DIRECTORY, filename)
  405.   end
  406. end
  407.  
  408.  
  409. #==========================================================================
  410. # ++ Bubs::Regexp
  411. #==========================================================================
  412. module Bubs
  413.   module Regexp
  414.     RECIPEBOOK_START_TAG = /<RECIPE[_\s]?BOOK>/i
  415.     RECIPEBOOK_END_TAG = /<\/RECIPE[_\s]?BOOK>/i
  416.     RECIPEBOOK_OBJ_TAG = /(\w+):\s*(\d+(?:\s*,\s*\d+)*)/i
  417.     RECIPEBOOK_COVER_TAG = /(?:PICTURE|PIC|COVER):\s*(\w+)/i
  418.  
  419.     INGREDIENT_START_TAG = /<INGREDIENTS?>/i
  420.     INGREDIENT_END_TAG = /<\/INGREDIENTS?>/i
  421.     INGREDIENT_OBJ_TAG = /(\w+):\s*[×x]?(\d+)\s*[×x]?(\d+)?/i
  422.    
  423.     REQUIRED_TOOLS_TAG = /TOOLS?:\s*(\w+)\s*(\d+)/i
  424.     CRAFTING_CUSTOM_SE_TAG = /SE:\s*(\w+)\s*,\s*(\d+)\s*,\s*(\d+)/i
  425.   end # module Regexp
  426. end # module Bubs
  427.  
  428.  
  429. #==========================================================================
  430. # ++ DataManager
  431. #==========================================================================
  432. module DataManager
  433.   #--------------------------------------------------------------------------
  434.   # alias : load_database
  435.   #--------------------------------------------------------------------------
  436.   class << self; alias load_database_bubs_tocrafting load_database; end
  437.   def self.load_database
  438.     load_database_bubs_tocrafting # alias
  439.     load_notetags_bubs_tocrafting
  440.   end
  441.  
  442.   #--------------------------------------------------------------------------
  443.   # new method : load_notetags_bubs_tocrafting
  444.   #--------------------------------------------------------------------------
  445.   def self.load_notetags_bubs_tocrafting
  446.     groups = [$data_items, $data_weapons, $data_armors]
  447.     for group in groups
  448.       for obj in group
  449.         next if obj.nil?
  450.         obj.load_notetags_bubs_tocrafting
  451.       end # for obj
  452.     end # for group
  453.   end # def
  454.  
  455. end # module DataManager
  456.  
  457.  
  458. #==========================================================================
  459. # ++ RPG::BaseItem
  460. #==========================================================================
  461. class RPG::BaseItem
  462.   #--------------------------------------------------------------------------
  463.   # public instance variables
  464.   #--------------------------------------------------------------------------
  465.   attr_accessor :recipe_list
  466.   attr_accessor :ingredient_list
  467.   attr_accessor :tocrafting_tools
  468.   attr_accessor :tocrafting_gold_fee
  469.   attr_accessor :tocrafting_bookcover
  470.   attr_accessor :tocrafting_se
  471.   #--------------------------------------------------------------------------
  472.   # common cache : load_notetags_bubs_tocrafting
  473.   #--------------------------------------------------------------------------
  474.   def load_notetags_bubs_tocrafting
  475.     @recipe_list = []
  476.     @ingredient_list = []
  477.     @tocrafting_tools = []
  478.     @tocrafting_gold_fee = self.price
  479.     @tocrafting_bookcover = ""
  480.     @tocrafting_se = []
  481.  
  482.     load_notetags_default_fee_bubs_tocrafting
  483.    
  484.     recipe_tag = false
  485.     ingredient_tag = false
  486.    
  487.     self.note.split(/[\r\n]+/).each { |line|
  488.       case line
  489.       when Bubs::Regexp::RECIPEBOOK_START_TAG
  490.         recipe_tag = true
  491.       when Bubs::Regexp::RECIPEBOOK_END_TAG
  492.         recipe_tag = false
  493.        
  494.       when Bubs::Regexp::INGREDIENT_START_TAG
  495.         ingredient_tag = true
  496.       when Bubs::Regexp::INGREDIENT_END_TAG
  497.         ingredient_tag = false
  498.      
  499.       when Bubs::Regexp::CRAFTING_CUSTOM_SE_TAG
  500.         next unless ingredient_tag
  501.         @tocrafting_se = [$1, $2.to_i, $3.to_i]
  502.        
  503.       when Bubs::Regexp::RECIPEBOOK_COVER_TAG
  504.         next unless recipe_tag
  505.         @tocrafting_bookcover = $1
  506.        
  507.       when Bubs::Regexp::REQUIRED_TOOLS_TAG
  508.         next unless ingredient_tag
  509.         load_notetags_tools_bubs_tocrafting(line)
  510.        
  511.       else
  512.         load_notetags_recipelist_bubs_tocrafting(line) if recipe_tag
  513.         load_notetags_ingredients_bubs_tocrafting(line) if ingredient_tag
  514.       end # case
  515.     } # self.note.split
  516.     @recipe_list.compact!
  517.     @ingredient_list.compact!
  518.     @tocrafting_tools.compact!
  519.   end # load_notetags_bubs_tocrafting
  520.  
  521.   #--------------------------------------------------------------------------
  522.   # common cache : load_notetags_default_fee_bubs_tocrafting
  523.   #--------------------------------------------------------------------------
  524.   def load_notetags_default_fee_bubs_tocrafting
  525.     rate = Bubs::TOCrafting::CRAFTING_FEE_PRICE_RATE
  526.     @tocrafting_gold_fee = (@tocrafting_gold_fee * (rate * 0.01)).to_i
  527.   end
  528.  
  529.   #--------------------------------------------------------------------------
  530.   # common cache : load_notetags_recipelist_bubs_tocrafting
  531.   #--------------------------------------------------------------------------
  532.   def load_notetags_recipelist_bubs_tocrafting(line)
  533.     return unless line =~ Bubs::Regexp::RECIPEBOOK_OBJ_TAG ? true : false
  534.     match = $~.clone
  535.     id_array = match[2].scan(/\d+/)
  536.    
  537.     case match[1].upcase
  538.     when "I", "ITEM"
  539.       for id in id_array
  540.         @recipe_list.push( $data_items[id.to_i] )
  541.       end
  542.      
  543.     when "W", "WEAPON", "WEP"
  544.       for id in id_array
  545.         @recipe_list.push( $data_weapons[id.to_i] )
  546.       end
  547.      
  548.     when "A", "ARMOR", "ARMOUR", "ARM"
  549.       for id in id_array
  550.         @recipe_list.push( $data_armors[id.to_i] )
  551.       end # for
  552.      
  553.     end # case
  554.   end # def load_notetags_recipelist_bubs_tocrafting
  555.  
  556.   #--------------------------------------------------------------------------
  557.   # common cache : load_notetags_ingredients_bubs_tocrafting
  558.   #--------------------------------------------------------------------------
  559.   def load_notetags_ingredients_bubs_tocrafting(line)
  560.     return unless line =~ Bubs::Regexp::INGREDIENT_OBJ_TAG ? true : false
  561.     amount = $3 ? $3.to_i : 1
  562.    
  563.     case $1.upcase
  564.     when "I", "ITEM"
  565.       amount.times do @ingredient_list.push( $data_items[$2.to_i] ) end
  566.      
  567.     when "W", "WEAPON", "WEP"
  568.       amount.times do @ingredient_list.push( $data_weapons[$2.to_i] ) end
  569.      
  570.     when "A", "ARMOR", "ARMOUR", "ARM"
  571.       amount.times do @ingredient_list.push( $data_armors[$2.to_i] ) end
  572.    
  573.     when "FEE", "GOLD"
  574.       @tocrafting_gold_fee = $2.to_i
  575.      
  576.     end # case $1.upcase
  577.   end # def load_notetags_ingredients_bubs_tocrafting
  578.  
  579.   #--------------------------------------------------------------------------
  580.   # common cache : load_notetags_tools_bubs_tocrafting
  581.   #--------------------------------------------------------------------------
  582.   def load_notetags_tools_bubs_tocrafting(line)
  583.     line =~ Bubs::Regexp::REQUIRED_TOOLS_TAG
  584.      
  585.     case $1.upcase
  586.     when "I", "ITEM"
  587.       @tocrafting_tools.push( $data_items[$2.to_i] )
  588.      
  589.     when "W", "WEAPON", "WEP"
  590.       @tocrafting_tools.push( $data_weapons[$2.to_i] )
  591.      
  592.     when "A", "ARMOR", "ARMOUR", "ARM"
  593.       @tocrafting_tools.push( $data_armors[$2.to_i] )
  594.      
  595.     end # case
  596.   end # def load_notetags_tools_bubs_tocrafting
  597.    
  598.   #--------------------------------------------------------------------------
  599.   # new method : recipebook?
  600.   #--------------------------------------------------------------------------
  601.   def recipebook?
  602.     return false unless self.is_a?(RPG::UsableItem) || self.is_a?(RPG::EquipItem)
  603.     return !@recipe_list.empty?
  604.   end
  605. end # class RPG::BaseItem
  606.  
  607.  
  608. #==============================================================================
  609. # ++ Window_TOCraftingRecipeList
  610. #==============================================================================
  611. class Window_TOCraftingRecipeList < Window_ItemList
  612.   #--------------------------------------------------------------------------
  613.   # public instance variables
  614.   #--------------------------------------------------------------------------
  615.   attr_reader :info_window
  616.   attr_reader :header_window
  617.   attr_reader :cover_window
  618.   #--------------------------------------------------------------------------
  619.   # initialize
  620.   #--------------------------------------------------------------------------
  621.   def initialize(x, y, height)
  622.     super(x, y, window_width, height)
  623.   end
  624.  
  625.   #--------------------------------------------------------------------------
  626.   # window_width
  627.   #--------------------------------------------------------------------------
  628.   def window_width
  629.     Graphics.width / 2
  630.   end
  631.  
  632.   #--------------------------------------------------------------------------
  633.   # current_item_enabled?           # Get Activation State of Selection Item
  634.   #--------------------------------------------------------------------------
  635.   def current_item_enabled?
  636.     enable?(@data[index])
  637.   end
  638.  
  639.   #--------------------------------------------------------------------------
  640.   # enable?                               # Display in Enabled State?
  641.   #--------------------------------------------------------------------------
  642.   def enable?(item)
  643.     return false if item.nil?
  644.     return true
  645.   end
  646.  
  647.   #--------------------------------------------------------------------------
  648.   # col_max
  649.   #--------------------------------------------------------------------------
  650.   def col_max
  651.     return 1
  652.   end
  653.  
  654.   #--------------------------------------------------------------------------
  655.   # include?                              # Include in Item List?
  656.   #--------------------------------------------------------------------------
  657.   def include?(item)
  658.     return false if item.nil?
  659.     return true if item.recipebook?
  660.     return false
  661.   end
  662.  
  663.   #--------------------------------------------------------------------------
  664.   # draw_item
  665.   #--------------------------------------------------------------------------
  666.   def draw_item(index)
  667.     item = @data[index]
  668.     if item
  669.       rect = item_rect(index)
  670.       rect.width -= 4
  671.       draw_item_name(item, rect.x, rect.y, enable?(item), rect.width - 24)
  672.     end
  673.   end
  674.  
  675.   #--------------------------------------------------------------------------
  676.   # info_window=
  677.   #--------------------------------------------------------------------------
  678.   def info_window=(info_window)
  679.     @info_window = info_window
  680.     call_update_help
  681.   end
  682.  
  683.   #--------------------------------------------------------------------------
  684.   # header_window=
  685.   #--------------------------------------------------------------------------
  686.   def header_window=(header_window)
  687.     @header_window = header_window
  688.   end
  689.  
  690.   #--------------------------------------------------------------------------
  691.   # cover_window=
  692.   #--------------------------------------------------------------------------
  693.   def cover_window=(cover_window)
  694.     @cover_window = cover_window
  695.   end
  696.  
  697.   #--------------------------------------------------------------------------
  698.   # update_help
  699.   #--------------------------------------------------------------------------
  700.   def update_help
  701.     @help_window.set_item(item) if @help_window
  702.     @info_window.item = item if @info_window
  703.     @header_window.item = item if @header_window
  704.     @cover_window.item = item if @cover_window
  705.   end
  706.  
  707. end # Window_TOCraftingRecipeList
  708.  
  709.  
  710. #==============================================================================
  711. # ++ Window_TOCraftingItemListHeader
  712. #==============================================================================
  713. class Window_TOCraftingItemListHeader < Window_Base
  714.   #--------------------------------------------------------------------------
  715.   # initialize
  716.   #--------------------------------------------------------------------------
  717.   def initialize(x, y)
  718.     super(x, y, window_width, window_height)
  719.     @item = nil
  720.   end
  721.  
  722.   #--------------------------------------------------------------------------
  723.   # window_width
  724.   #--------------------------------------------------------------------------
  725.   def window_width
  726.     Graphics.width / 2
  727.   end
  728.  
  729.   #--------------------------------------------------------------------------
  730.   # window_height
  731.   #--------------------------------------------------------------------------
  732.   def window_height
  733.     fitting_height(1)
  734.   end
  735.  
  736.   #--------------------------------------------------------------------------
  737.   # item=                                   # Set window header item
  738.   #--------------------------------------------------------------------------
  739.   def item=(item)
  740.     @item = item
  741.   end
  742.  
  743.   #--------------------------------------------------------------------------
  744.   # refresh
  745.   #--------------------------------------------------------------------------
  746.   def refresh
  747.     contents.clear
  748.     draw_itemlist_header_item(0, 0)
  749.   end
  750.  
  751.   #--------------------------------------------------------------------------
  752.   # draw_itemlist_header_item
  753.   #--------------------------------------------------------------------------
  754.   def draw_itemlist_header_item(x, y)
  755.     return unless @item
  756.     draw_item_name(@item, x, y, true, contents.width - 28)
  757.   end
  758.  
  759. end # class Window_TOCraftingItemListHeader
  760.  
  761.  
  762. #==============================================================================
  763. # ++ Window_TOCraftingItemList
  764. #==============================================================================
  765.  
  766. class Window_TOCraftingItemList < Window_ItemList
  767.   #--------------------------------------------------------------------------
  768.   # initialize
  769.   #--------------------------------------------------------------------------
  770.   def initialize(x, y, height)
  771.     super(x, y, window_width, height)
  772.     @item = nil
  773.   end
  774.  
  775.   #--------------------------------------------------------------------------
  776.   # window_width
  777.   #--------------------------------------------------------------------------
  778.   def window_width
  779.     Graphics.width / 2
  780.   end
  781.  
  782.   #--------------------------------------------------------------------------
  783.   # col_max
  784.   #--------------------------------------------------------------------------
  785.   def col_max
  786.     return 1
  787.   end
  788.  
  789.   #--------------------------------------------------------------------------
  790.   # item=
  791.   #--------------------------------------------------------------------------
  792.   def item=(item)
  793.     @item = item
  794.     refresh
  795.   end
  796.  
  797.   #--------------------------------------------------------------------------
  798.   # info_window=
  799.   #--------------------------------------------------------------------------
  800.   def info_window=(info_window)
  801.     @info_window = info_window
  802.     call_update_help
  803.   end
  804.  
  805.   #--------------------------------------------------------------------------
  806.   # gold_window=
  807.   #--------------------------------------------------------------------------
  808.   def gold_window=(gold_window)
  809.     @gold_window = gold_window
  810.     call_update_help
  811.   end
  812.  
  813.   #--------------------------------------------------------------------------
  814.   # current_item_enabled?           # Get Activation State of Selection Item
  815.   #--------------------------------------------------------------------------
  816.   def current_item_enabled?
  817.     enable?(@data[index])
  818.   end
  819.  
  820.   #--------------------------------------------------------------------------
  821.   # enable?                               # Display in Enabled State?
  822.   #--------------------------------------------------------------------------
  823.   def enable?(item)
  824.     return false if item.nil?
  825.     return false if item.tocrafting_gold_fee > $game_party.gold
  826.     return false if $game_party.item_max?(item)
  827.     return false unless have_tools?(item)
  828.     return true if item.ingredient_list.empty?
  829.     return have_ingredients?(item)
  830.   end
  831.  
  832.   #--------------------------------------------------------------------------
  833.   # have_ingredients?                            
  834.   #--------------------------------------------------------------------------
  835.   def have_ingredients?(item)
  836.     item.ingredient_list.uniq.each do |ingredient|
  837.       party_amount = $game_party.item_number(ingredient)
  838.       required_amount = item.ingredient_list.count(ingredient)
  839.       return false if party_amount < required_amount  
  840.     end # do
  841.     return true
  842.   end
  843.  
  844.   #--------------------------------------------------------------------------
  845.   # have_tools?                            
  846.   #--------------------------------------------------------------------------
  847.   def have_tools?(item)
  848.     item.tocrafting_tools.uniq.each do |tool|
  849.       return false if !$game_party.has_item?(tool)
  850.     end
  851.     return true
  852.   end
  853.  
  854.   #--------------------------------------------------------------------------
  855.   # include?                              # Include in Item List?
  856.   #--------------------------------------------------------------------------
  857.   def include?(item)
  858.     return false if item.nil?
  859.     return true
  860.   end
  861.  
  862.   #--------------------------------------------------------------------------
  863.   # make_item_list
  864.   #--------------------------------------------------------------------------
  865.   def make_item_list
  866.     @data = @item.recipe_list.each { |item| include?(item) } if @item
  867.   end
  868.  
  869.   #--------------------------------------------------------------------------
  870.   # update_help
  871.   #--------------------------------------------------------------------------
  872.   def update_help
  873.     @help_window.set_item(item) if @help_window
  874.     @info_window.item = item if @info_window
  875.     @gold_window.item = item if @gold_window
  876.   end
  877.  
  878.   #--------------------------------------------------------------------------
  879.   # update_open
  880.   #--------------------------------------------------------------------------
  881.   def update_open
  882.     self.openness += 24
  883.     @opening = false if open?
  884.   end
  885.  
  886. end # class Window_TOCraftingItemList
  887.  
  888.  
  889. #==============================================================================
  890. # ++ Window_TOCraftingInfo
  891. #==============================================================================
  892. class Window_TOCraftingInfo < Window_Base
  893.   #--------------------------------------------------------------------------
  894.   # public instance variables
  895.   #--------------------------------------------------------------------------
  896.   attr_accessor :number
  897.   #--------------------------------------------------------------------------
  898.   # initialize
  899.   #--------------------------------------------------------------------------
  900.   def initialize(x, y, width, height)
  901.     super(x, y, width, height)
  902.     @item = nil
  903.     @number = 1
  904.     refresh
  905.   end
  906.  
  907.   #--------------------------------------------------------------------------
  908.   # refresh
  909.   #--------------------------------------------------------------------------
  910.   def refresh
  911.     contents.clear
  912.     return unless @item
  913.     draw_required_ingredients_text(4, 0)
  914.     draw_ingredients(4, line_height * 1)
  915.   end
  916.  
  917.   #--------------------------------------------------------------------------
  918.   # item=                                        # Set Item
  919.   #--------------------------------------------------------------------------
  920.   def item=(item)
  921.     @item = item
  922.     refresh
  923.   end
  924.   #--------------------------------------------------------------------------
  925.   # ingredients
  926.   #--------------------------------------------------------------------------
  927.   def ingredients
  928.     @item.ingredient_list
  929.   end
  930.  
  931.   #--------------------------------------------------------------------------
  932.   # tools
  933.   #--------------------------------------------------------------------------
  934.   def tools
  935.     @item.tocrafting_tools
  936.   end
  937.  
  938.   #--------------------------------------------------------------------------
  939.   # draw_required_ingredients_text
  940.   #--------------------------------------------------------------------------
  941.   def draw_required_ingredients_text(x, y)
  942.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  943.     change_color(system_color)
  944.     draw_text(rect, Bubs::TOCrafting::INGREDIENTS_HEADER_TEXT)
  945.   end
  946.  
  947.   #--------------------------------------------------------------------------
  948.   # draw_ingredients
  949.   #--------------------------------------------------------------------------
  950.   def draw_ingredients(x, y)
  951.     return unless @item
  952.     i = 0
  953.     # draw gold info
  954.     if !Bubs::TOCrafting::USE_GOLD_WINDOW && @item.tocrafting_gold_fee > 0
  955.       draw_gold_info(@item, x, y)
  956.       i += 1
  957.     end
  958.    
  959.     # draw tool info
  960.     tools.uniq.each do |item|
  961.       draw_tools_info(item, x, y + line_height * (i * 2))
  962.       i += 1
  963.     end
  964.    
  965.     # draw ingredient info
  966.     ingredients.uniq.each do |item|
  967.       draw_ingredient_info(item, x, y + line_height * (i * 2))
  968.       i += 1
  969.     end # do
  970.   end
  971.    
  972.   #--------------------------------------------------------------------------
  973.   # required_amount
  974.   #--------------------------------------------------------------------------
  975.   def required_amount(item)
  976.     ingredients.count(item) * @number
  977.   end
  978.  
  979.   #--------------------------------------------------------------------------
  980.   # party_amount
  981.   #--------------------------------------------------------------------------
  982.   def party_amount(item)
  983.     $game_party.item_number(item)
  984.   end
  985.  
  986.   #--------------------------------------------------------------------------
  987.   # crafting_fee
  988.   #--------------------------------------------------------------------------
  989.   def crafting_fee
  990.     @item.tocrafting_gold_fee
  991.   end
  992.  
  993.   #--------------------------------------------------------------------------
  994.   # party_gold
  995.   #--------------------------------------------------------------------------
  996.   def party_gold
  997.     $game_party.gold
  998.   end
  999.  
  1000.   #--------------------------------------------------------------------------
  1001.   # currency_unit
  1002.   #--------------------------------------------------------------------------
  1003.   def currency_unit
  1004.     Vocab::currency_unit
  1005.   end
  1006.  
  1007.   #--------------------------------------------------------------------------
  1008.   # draw_tools_info
  1009.   #--------------------------------------------------------------------------
  1010.   def draw_tools_info(item, x, y)
  1011.     enabled = $game_party.has_item?(item)
  1012.     width = contents.width - 4 - x
  1013.    
  1014.     draw_item_name(item, x, y, enabled, width)
  1015.     draw_tool_availability_text(item, x, y, enabled)
  1016.   end
  1017.  
  1018.   #--------------------------------------------------------------------------
  1019.   # draw_tool_availability_text
  1020.   #--------------------------------------------------------------------------
  1021.   def draw_tool_availability_text(item, x, y, enabled)
  1022.     rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
  1023.     if enabled
  1024.       change_color(text_color(Bubs::TOCrafting::TOOL_AVAILABLE_TEXT_COLOR))
  1025.       draw_text(rect, Bubs::TOCrafting::TOOL_AVAILABLE_TEXT, 2)
  1026.     else
  1027.       change_color(text_color(Bubs::TOCrafting::TOOL_UNAVAILABLE_TEXT_COLOR))
  1028.       draw_text(rect, Bubs::TOCrafting::TOOL_UNAVAILABLE_TEXT, 2)
  1029.     end
  1030.   end
  1031.  
  1032.   #--------------------------------------------------------------------------
  1033.   # draw_ingredient_info
  1034.   #--------------------------------------------------------------------------
  1035.   def draw_ingredient_info(item, x, y)
  1036.     enabled = party_amount(item) >= required_amount(item)
  1037.     width = contents.width - 4 - x
  1038.    
  1039.     draw_item_name(item, x, y, enabled, width)
  1040.     not_enough_ingredients_color unless enabled    
  1041.     rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
  1042.     draw_text(rect, sprintf("×%2d/%2d", required_amount(item), party_amount(item)), 2)
  1043.   end
  1044.  
  1045.   #--------------------------------------------------------------------------
  1046.   # draw_gold_info
  1047.   #--------------------------------------------------------------------------
  1048.   def draw_gold_info(item, x, y)
  1049.     return if item.nil?
  1050.     enabled = party_gold >= crafting_fee
  1051.     cx = text_size(currency_unit).width
  1052.     width = contents.width - 4 - x
  1053.    
  1054.     draw_gold_name(x, y, enabled)
  1055.    
  1056.     change_color(system_color)
  1057.     draw_text(x, y + line_height, width, line_height, currency_unit, 2)
  1058.     change_color(normal_color)
  1059.    
  1060.     not_enough_ingredients_color unless enabled
  1061.     text = sprintf("%8d/%8d", crafting_fee * @number, party_gold)
  1062.     draw_text(x, y + line_height, width - cx - 2, line_height, text, 2)
  1063.   end
  1064.  
  1065.   #--------------------------------------------------------------------------
  1066.   # draw_gold_name
  1067.   #--------------------------------------------------------------------------
  1068.   def draw_gold_name(x, y, enabled = true)
  1069.     draw_icon(Bubs::TOCrafting::GOLD_WINDOW_ICON_INDEX, x, y, enabled)
  1070.     change_color(normal_color, enabled)
  1071.     draw_text(x + 24, y, width, line_height, Bubs::TOCrafting::GOLD_WINDOW_TEXT)
  1072.   end
  1073.  
  1074.   #--------------------------------------------------------------------------
  1075.   # not_enough_ingredients_color
  1076.   #--------------------------------------------------------------------------
  1077.   def not_enough_ingredients_color
  1078.     enabled = !Bubs::TOCrafting::FADED_REQUIREMENT_QUANTITY
  1079.     color_index = Bubs::TOCrafting::NOT_ENOUGH_INGREDIENTS_COLOR
  1080.     change_color(text_color(color_index), enabled)
  1081.   end
  1082.  
  1083. end # class Window_TOCraftingInfo
  1084.  
  1085.  
  1086. #==============================================================================
  1087. # ++ Window_TOCraftingResult
  1088. #==============================================================================
  1089. class Window_TOCraftingResult < Window_Selectable
  1090.   #--------------------------------------------------------------------------
  1091.   # initialize
  1092.   #--------------------------------------------------------------------------
  1093.   def initialize(x, y)
  1094.     @item = nil
  1095.     @number = 0
  1096.     super(x, y, window_width,window_height)
  1097.   end
  1098.  
  1099.   #--------------------------------------------------------------------------
  1100.   # window_width
  1101.   #--------------------------------------------------------------------------
  1102.   def window_width
  1103.     Graphics.width / 2
  1104.   end
  1105.  
  1106.   #--------------------------------------------------------------------------
  1107.   # window_height
  1108.   #--------------------------------------------------------------------------
  1109.   def window_height
  1110.     fitting_height(2)
  1111.   end
  1112.  
  1113.   #--------------------------------------------------------------------------
  1114.   # set
  1115.   #--------------------------------------------------------------------------
  1116.   def set(item, number)
  1117.     @item = item
  1118.     @number = number
  1119.   end
  1120.  
  1121.   #--------------------------------------------------------------------------
  1122.   # refresh
  1123.   #--------------------------------------------------------------------------
  1124.   def refresh
  1125.     contents.clear
  1126.     draw_result_header_text(4, 0)
  1127.     draw_result_item(4, line_height)
  1128.   end
  1129.  
  1130.   #--------------------------------------------------------------------------
  1131.   # draw_result_header_text
  1132.   #--------------------------------------------------------------------------
  1133.   def draw_result_header_text(x, y)
  1134.     return unless @item
  1135.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  1136.     change_color(system_color)
  1137.     draw_text(rect, Bubs::TOCrafting::RESULT_WINDOW_HEADER_TEXT, 1)
  1138.   end
  1139.  
  1140.   #--------------------------------------------------------------------------
  1141.   # draw_result_item
  1142.   #--------------------------------------------------------------------------
  1143.   def draw_result_item(x, y)
  1144.     return unless @item
  1145.     draw_item_name(@item, x, y, true)
  1146.     draw_item_amount(x, y, @number)
  1147.   end
  1148.  
  1149.   #--------------------------------------------------------------------------
  1150.   # draw_item_amount
  1151.   #--------------------------------------------------------------------------
  1152.   def draw_item_amount(x, y, number)
  1153.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  1154.     draw_text(rect, sprintf("×%2d", number), 2)
  1155.   end
  1156.  
  1157. end # class Window_TOCraftingResult
  1158.  
  1159.  
  1160. #==============================================================================
  1161. # ++ Window_TOCraftingGold
  1162. #==============================================================================
  1163. class Window_TOCraftingGold < Window_Base
  1164.   #--------------------------------------------------------------------------
  1165.   # public instance variables
  1166.   #--------------------------------------------------------------------------
  1167.   attr_accessor :number
  1168.   #--------------------------------------------------------------------------
  1169.   # initialize
  1170.   #--------------------------------------------------------------------------
  1171.   def initialize
  1172.     super(0, 0, window_width, fitting_height(2))
  1173.     @item = nil
  1174.     @number = 1
  1175.     refresh
  1176.   end
  1177.  
  1178.   #--------------------------------------------------------------------------
  1179.   # window_width
  1180.   #--------------------------------------------------------------------------
  1181.   def window_width
  1182.     return Graphics.width / 2
  1183.   end
  1184.  
  1185.   #--------------------------------------------------------------------------
  1186.   # item=
  1187.   #--------------------------------------------------------------------------
  1188.   def item=(item)
  1189.     @item = item
  1190.     refresh
  1191.   end
  1192.  
  1193.   #--------------------------------------------------------------------------
  1194.   # refresh
  1195.   #--------------------------------------------------------------------------
  1196.   def refresh
  1197.     contents.clear
  1198.     draw_gold_info(4, 0)
  1199.   end
  1200.  
  1201.   #--------------------------------------------------------------------------
  1202.   # currency_unit
  1203.   #--------------------------------------------------------------------------
  1204.   def currency_unit
  1205.     Vocab::currency_unit
  1206.   end
  1207.  
  1208.   #--------------------------------------------------------------------------
  1209.   # open
  1210.   #--------------------------------------------------------------------------
  1211.   def open
  1212.     refresh
  1213.     super
  1214.   end
  1215.  
  1216.   #--------------------------------------------------------------------------
  1217.   # crafting_fee
  1218.   #--------------------------------------------------------------------------
  1219.   def crafting_fee
  1220.     @item.tocrafting_gold_fee
  1221.   end
  1222.  
  1223.   #--------------------------------------------------------------------------
  1224.   # party_gold
  1225.   #--------------------------------------------------------------------------
  1226.   def party_gold
  1227.     $game_party.gold
  1228.   end
  1229.  
  1230.   #--------------------------------------------------------------------------
  1231.   # draw_gold_info
  1232.   #--------------------------------------------------------------------------
  1233.   def draw_gold_info(x, y)
  1234.     return if @item.nil?
  1235.     enabled = party_gold >= crafting_fee
  1236.     cx = text_size(currency_unit).width
  1237.     width = contents.width - 4 - x
  1238.    
  1239.     draw_gold_name(x, y, enabled)
  1240.    
  1241.     change_color(system_color)
  1242.     draw_text(x, y + line_height, width, line_height, currency_unit, 2)
  1243.     change_color(normal_color)
  1244.    
  1245.     not_enough_ingredients_color unless enabled
  1246.     text = sprintf("%8d/%8d", crafting_fee * @number, party_gold)
  1247.     draw_text(x, y + line_height, width - cx - 2, line_height, text, 2)
  1248.   end
  1249.  
  1250.   #--------------------------------------------------------------------------
  1251.   # draw_gold_name
  1252.   #--------------------------------------------------------------------------
  1253.   def draw_gold_name(x, y, enabled = true)
  1254.     draw_icon(Bubs::TOCrafting::GOLD_WINDOW_ICON_INDEX, x, y, enabled)
  1255.     change_color(normal_color, enabled)
  1256.     draw_text(x + 24, y, width, line_height, Bubs::TOCrafting::GOLD_WINDOW_TEXT)
  1257.   end
  1258.  
  1259.   #--------------------------------------------------------------------------
  1260.   # not_enough_ingredients_color
  1261.   #--------------------------------------------------------------------------
  1262.   def not_enough_ingredients_color
  1263.     enabled = !Bubs::TOCrafting::FADED_REQUIREMENT_QUANTITY
  1264.     color_index = Bubs::TOCrafting::NOT_ENOUGH_INGREDIENTS_COLOR
  1265.     change_color(text_color(color_index), enabled)
  1266.   end
  1267. end # class Window_TOCraftingGold
  1268.  
  1269.  
  1270. #==============================================================================
  1271. # ++ Window_TOCraftingNumber
  1272. #==============================================================================
  1273. class Window_TOCraftingNumber < Window_Selectable
  1274.   #--------------------------------------------------------------------------
  1275.   # public instance variables
  1276.   #--------------------------------------------------------------------------
  1277.   attr_accessor   :number                   # quantity entered
  1278.   attr_reader     :item
  1279.   #--------------------------------------------------------------------------
  1280.   # initialize
  1281.   #--------------------------------------------------------------------------
  1282.   def initialize(x, y, height)
  1283.     super(x, y, window_width, height)
  1284.     @item = nil
  1285.     @info_window = nil
  1286.     @max = 1
  1287.     @price = 0
  1288.     @number = 1
  1289.     @currency_unit = Vocab::currency_unit
  1290.   end
  1291.  
  1292.   #--------------------------------------------------------------------------
  1293.   # window_width
  1294.   #--------------------------------------------------------------------------
  1295.   def window_width
  1296.     return Graphics.width / 2
  1297.   end
  1298.  
  1299.   #--------------------------------------------------------------------------
  1300.   # info_window=
  1301.   #--------------------------------------------------------------------------
  1302.   def info_window=(info_window)
  1303.     @info_window = info_window
  1304.   end
  1305.  
  1306.   #--------------------------------------------------------------------------
  1307.   # gold_window=
  1308.   #--------------------------------------------------------------------------
  1309.   def gold_window=(gold_window)
  1310.     @gold_window = gold_window
  1311.   end
  1312.  
  1313.   #--------------------------------------------------------------------------
  1314.   # set
  1315.   #--------------------------------------------------------------------------
  1316.   def set(item, max, price, currency_unit = nil)
  1317.     @item = item
  1318.     @max = max
  1319.     @price = price
  1320.     @currency_unit = currency_unit if currency_unit
  1321.     @number = 1
  1322.     refresh
  1323.   end
  1324.  
  1325.   #--------------------------------------------------------------------------
  1326.   # currency_unit
  1327.   #--------------------------------------------------------------------------
  1328.   def currency_unit=(currency_unit)
  1329.     @currency_unit = currency_unit
  1330.     refresh
  1331.   end
  1332.  
  1333.   #--------------------------------------------------------------------------
  1334.   # refresh
  1335.   #--------------------------------------------------------------------------
  1336.   def refresh
  1337.     contents.clear
  1338.     draw_item_name(@item, 0, item_y)
  1339.     draw_number
  1340.     #draw_total_price
  1341.     update_info_window
  1342.     update_gold_window
  1343.   end
  1344.  
  1345.   #--------------------------------------------------------------------------
  1346.   # draw_number
  1347.   #--------------------------------------------------------------------------
  1348.   def draw_number
  1349.     change_color(normal_color)
  1350.     draw_text(cursor_x - 28, item_y, 22, line_height, "×")
  1351.     draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
  1352.   end
  1353.  
  1354.   #--------------------------------------------------------------------------
  1355.   # draw_total_price
  1356.   #--------------------------------------------------------------------------
  1357.   def draw_total_price
  1358.     return if @item.nil?
  1359.     return if @item.tocrafting_gold_fee == 0
  1360.     width = contents_width - 8
  1361.     draw_currency_value(@price * @number, @currency_unit, 4, price_y, width)
  1362.   end
  1363.  
  1364.   #--------------------------------------------------------------------------
  1365.   # item_y                        # Y Coordinate of Item Name Display Line
  1366.   #--------------------------------------------------------------------------
  1367.   def item_y
  1368.     contents_height / 2 - line_height * 3 / 2
  1369.   end
  1370.  
  1371.   #--------------------------------------------------------------------------
  1372.   # price_y                       # Y Coordinate of Price Display Line
  1373.   #--------------------------------------------------------------------------
  1374.   def price_y
  1375.     contents_height / 2 + line_height / 2
  1376.   end
  1377.  
  1378.   #--------------------------------------------------------------------------
  1379.   # cursor_width
  1380.   #--------------------------------------------------------------------------
  1381.   def cursor_width
  1382.     figures * 10 + 12
  1383.   end
  1384.  
  1385.   #--------------------------------------------------------------------------
  1386.   # cursor_x                      # Get X Coordinate of Cursor
  1387.   #--------------------------------------------------------------------------
  1388.   def cursor_x
  1389.     contents_width - cursor_width - 4
  1390.   end
  1391.  
  1392.   #--------------------------------------------------------------------------
  1393.   # figures              # Get Maximum Number of Digits for Quantity Display
  1394.   #--------------------------------------------------------------------------
  1395.   def figures
  1396.     return 2
  1397.   end
  1398.  
  1399.   #--------------------------------------------------------------------------
  1400.   # update                        # Frame Update
  1401.   #--------------------------------------------------------------------------
  1402.   def update
  1403.     super
  1404.     if active
  1405.       last_number = @number
  1406.       update_number
  1407.       if @number != last_number
  1408.         Sound.play_cursor
  1409.         refresh
  1410.       end
  1411.     end
  1412.   end
  1413.  
  1414.   #--------------------------------------------------------------------------
  1415.   # update_number                         # Update Quantity
  1416.   #--------------------------------------------------------------------------
  1417.   def update_number
  1418.     change_number(1)   if Input.repeat?(:RIGHT)
  1419.     change_number(-1)  if Input.repeat?(:LEFT)
  1420.     change_number(10)  if Input.repeat?(:UP)
  1421.     change_number(-10) if Input.repeat?(:DOWN)
  1422.   end
  1423.  
  1424.   #--------------------------------------------------------------------------
  1425.   # change_number
  1426.   #--------------------------------------------------------------------------
  1427.   def change_number(amount)
  1428.     @number = [[@number + amount, @max].min, 1].max
  1429.   end
  1430.  
  1431.   #--------------------------------------------------------------------------
  1432.   # update_cursor
  1433.   #--------------------------------------------------------------------------
  1434.   def update_cursor
  1435.     cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
  1436.   end
  1437.  
  1438.   #--------------------------------------------------------------------------
  1439.   # update_info_window
  1440.   #--------------------------------------------------------------------------
  1441.   def update_info_window
  1442.     @info_window.number = @number
  1443.     @info_window.refresh
  1444.   end
  1445.  
  1446.   #--------------------------------------------------------------------------
  1447.   # update_gold_window
  1448.   #--------------------------------------------------------------------------
  1449.   def update_gold_window
  1450.     @gold_window.number = @number
  1451.     @gold_window.refresh
  1452.   end
  1453.  
  1454. end # class Window_TOCraftingNumber
  1455.  
  1456.  
  1457. #==============================================================================
  1458. # ++ Window_TOCraftingCover
  1459. #==============================================================================
  1460. class Window_TOCraftingCover < Window_Base
  1461.   #--------------------------------------------------------------------------
  1462.   # refresh
  1463.   #--------------------------------------------------------------------------
  1464.   def refresh
  1465.     contents.clear
  1466.     draw_bookcover(0, 0)
  1467.   end
  1468.  
  1469.   #--------------------------------------------------------------------------
  1470.   # item=
  1471.   #--------------------------------------------------------------------------
  1472.   def item=(item)
  1473.     @item = item
  1474.     refresh
  1475.   end
  1476.  
  1477.   #--------------------------------------------------------------------------
  1478.   # draw_bookcover
  1479.   #--------------------------------------------------------------------------
  1480.   def draw_bookcover(x, y)
  1481.     return unless @item
  1482.     bitmap = Cache.recipebook_cover(@item.tocrafting_bookcover)
  1483.     rect = Rect.new(0, 0, contents.width, contents.height)
  1484.     if Bubs::TOCrafting::STRETCH_RECIPEBOOK_PICTURES
  1485.       contents.stretch_blt(rect, bitmap, bitmap.rect)
  1486.     else
  1487.       contents.blt(x, y, bitmap, rect)
  1488.     end
  1489.     bitmap.dispose
  1490.   end
  1491.  
  1492. end # class Window_TOCraftingCover
  1493.  
  1494.  
  1495. #==============================================================================
  1496. # ++ Game_Interpreter
  1497. #==============================================================================
  1498. class Game_Interpreter
  1499.   #--------------------------------------------------------------------------
  1500.   # new method : open_tocrafting_shop
  1501.   #--------------------------------------------------------------------------
  1502.   def open_tocrafting_shop
  1503.     SceneManager.call(Scene_TOCrafting)
  1504.   end
  1505. end
  1506.  
  1507.  
  1508. #==============================================================================
  1509. # ++ Scene_TOCrafting
  1510. #==============================================================================
  1511. class Scene_TOCrafting < Scene_MenuBase
  1512.   #--------------------------------------------------------------------------
  1513.   # start
  1514.   #--------------------------------------------------------------------------
  1515.   def start
  1516.     super
  1517.     create_help_window
  1518.     create_gold_window
  1519.     create_cover_window
  1520.     create_info_window
  1521.     create_itemlist_header_window
  1522.     create_itemlist_window
  1523.     create_recipelist_window
  1524.     create_number_window
  1525.     create_result_window
  1526.   end
  1527.  
  1528.   #--------------------------------------------------------------------------
  1529.   # create_gold_window
  1530.   #--------------------------------------------------------------------------
  1531.   def create_gold_window
  1532.     @gold_window = Window_TOCraftingGold.new
  1533.     @gold_window.viewport = @viewport
  1534.     @gold_window.hide.close
  1535.     @gold_window.x = 0
  1536.     @gold_window.y = Graphics.height - @gold_window.height
  1537.   end
  1538.  
  1539.   #--------------------------------------------------------------------------
  1540.   # create_number_window
  1541.   #--------------------------------------------------------------------------
  1542.   def create_number_window
  1543.     wx = 0
  1544.     wy = @itemlist_header_window.y + @itemlist_header_window.height
  1545.     wh = Graphics.height - wy
  1546.     wh = wh - @gold_window.height if gold_window?
  1547.     @number_window = Window_TOCraftingNumber.new(wx, wy, wh)
  1548.     @number_window.viewport = @viewport
  1549.     @number_window.info_window = @info_window
  1550.     @number_window.gold_window = @gold_window
  1551.     @number_window.hide.close
  1552.     @number_window.set_handler(:ok,     method(:on_number_ok))
  1553.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  1554.   end
  1555.  
  1556.   #--------------------------------------------------------------------------
  1557.   # on_number_ok
  1558.   #--------------------------------------------------------------------------
  1559.   def on_number_ok
  1560.     @number_window.close.hide
  1561.     @number_window.number
  1562.     do_crafting(@item, @number_window.number)
  1563.     @result_window.set(@item, @number_window.number)
  1564.     @result_window.show.open.activate
  1565.     @itemlist_window.show.open
  1566.  
  1567.     @gold_window.number = @info_window.number = 1
  1568.     refresh
  1569.     @result_window.show.open.activate
  1570.   end
  1571.  
  1572.   #--------------------------------------------------------------------------
  1573.   # on_number_cancel
  1574.   #--------------------------------------------------------------------------
  1575.   def on_number_cancel
  1576.     @number_window.close.hide
  1577.     @gold_window.number = @info_window.number = 1
  1578.     @itemlist_window.show.open.activate
  1579.   end
  1580.  
  1581.   #--------------------------------------------------------------------------
  1582.   # create_recipelist_window
  1583.   #--------------------------------------------------------------------------
  1584.   def create_recipelist_window
  1585.     wx = 0
  1586.     wy = @help_window.height
  1587.     wh = Graphics.height - wy
  1588.     @recipelist_window = Window_TOCraftingRecipeList.new(wx, wy, wh)
  1589.     @recipelist_window.viewport = @viewport
  1590.     @recipelist_window.help_window = @help_window
  1591.     @recipelist_window.info_window = @info_window
  1592.     @recipelist_window.header_window = @itemlist_header_window
  1593.     @recipelist_window.cover_window = @cover_window
  1594.     @recipelist_window.set_handler(:ok,     method(:on_recipelist_ok))
  1595.     @recipelist_window.set_handler(:cancel, method(:on_recipelist_cancel))
  1596.     @recipelist_window.refresh
  1597.     @recipelist_window.show.activate.select(0)
  1598.   end
  1599.   #--------------------------------------------------------------------------
  1600.   # on_recipelist_ok
  1601.   #--------------------------------------------------------------------------
  1602.   def on_recipelist_ok
  1603.     @recipelist_window.close
  1604.     @itemlist_window.item = @recipelist_window.item
  1605.     @gold_window.show.open if gold_window?
  1606.     @cover_window.hide
  1607.     @info_window.show
  1608.     activate_itemlist_window
  1609.   end
  1610.  
  1611.   #--------------------------------------------------------------------------
  1612.   # on_recipelist_cancel
  1613.   #--------------------------------------------------------------------------
  1614.   def on_recipelist_cancel
  1615.     refresh
  1616.     return_scene
  1617.   end
  1618.  
  1619.   #--------------------------------------------------------------------------
  1620.   # activate_recipelist_window
  1621.   #--------------------------------------------------------------------------
  1622.   def activate_recipelist_window
  1623.     refresh
  1624.     @recipelist_window.show.open.activate
  1625.   end
  1626.  
  1627.   #--------------------------------------------------------------------------
  1628.   # create_itemlist_window
  1629.   #--------------------------------------------------------------------------
  1630.   def create_itemlist_window
  1631.     wx = 0
  1632.     wy = @help_window.height + @itemlist_header_window.height
  1633.     wh = Graphics.height - wy
  1634.     wh = wh - @gold_window.height if gold_window?
  1635.     @itemlist_window = Window_TOCraftingItemList.new(wx, wy, wh)
  1636.     @itemlist_window.viewport = @viewport
  1637.     @itemlist_window.help_window = @help_window
  1638.     @itemlist_window.info_window = @info_window
  1639.     @itemlist_window.gold_window = @gold_window
  1640.     @itemlist_window.hide
  1641.     @itemlist_window.close
  1642.     @itemlist_window.set_handler(:ok,     method(:on_itemlist_ok))
  1643.     @itemlist_window.set_handler(:cancel, method(:on_itemlist_cancel))
  1644.     @itemlist_window.refresh
  1645.   end
  1646.  
  1647.   #--------------------------------------------------------------------------
  1648.   # on_itemlist_ok
  1649.   #--------------------------------------------------------------------------
  1650.   def on_itemlist_ok
  1651.     @item = @itemlist_window.item
  1652.     @itemlist_window.close.hide
  1653.     @number_window.set(@item, max_craft, crafting_fee)
  1654.     @number_window.show.open.activate
  1655.   end
  1656.  
  1657.   #--------------------------------------------------------------------------
  1658.   # on_itemlist_cancel
  1659.   #--------------------------------------------------------------------------
  1660.   def on_itemlist_cancel
  1661.     @itemlist_window.close
  1662.     @itemlist_header_window.close
  1663.     @gold_window.close.hide if gold_window?
  1664.     @info_window.hide
  1665.     @cover_window.show
  1666.     activate_recipelist_window
  1667.   end
  1668.  
  1669.   #--------------------------------------------------------------------------
  1670.   # activate_itemlist_window
  1671.   #--------------------------------------------------------------------------
  1672.   def activate_itemlist_window
  1673.     refresh
  1674.     @itemlist_header_window.show.open
  1675.     @itemlist_window.show.open.activate.select(0)
  1676.   end
  1677.  
  1678.   #--------------------------------------------------------------------------
  1679.   # create_number_window
  1680.   #--------------------------------------------------------------------------
  1681.   def create_number_window
  1682.     wx = 0
  1683.     wy = @itemlist_header_window.y + @itemlist_header_window.height
  1684.     wh = Graphics.height - wy
  1685.     wh = wh - @gold_window.height if gold_window?
  1686.     @number_window = Window_TOCraftingNumber.new(wx, wy, wh)
  1687.     @number_window.viewport = @viewport
  1688.     @number_window.info_window = @info_window
  1689.     @number_window.gold_window = @gold_window
  1690.     @number_window.hide.close
  1691.     @number_window.set_handler(:ok,     method(:on_number_ok))
  1692.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  1693.   end
  1694.  
  1695.   #--------------------------------------------------------------------------
  1696.   # on_number_ok
  1697.   #--------------------------------------------------------------------------
  1698.   def on_number_ok
  1699.     @number_window.close.hide
  1700.     @number_window.number
  1701.     do_crafting(@item, @number_window.number)
  1702.     @result_window.set(@item, @number_window.number)
  1703.     @result_window.show.open.activate
  1704.     @itemlist_window.show.open
  1705.  
  1706.     @gold_window.number = @info_window.number = 1
  1707.     refresh
  1708.     @result_window.show.open.activate
  1709.   end
  1710.  
  1711.   #--------------------------------------------------------------------------
  1712.   # on_number_cancel
  1713.   #--------------------------------------------------------------------------
  1714.   def on_number_cancel
  1715.     @number_window.close.hide
  1716.     @gold_window.number = @info_window.number = 1
  1717.     @itemlist_window.show.open.activate
  1718.   end
  1719.  
  1720.   #--------------------------------------------------------------------------
  1721.   # create_result_window
  1722.   #--------------------------------------------------------------------------
  1723.   def create_result_window
  1724.     wx = Graphics.width / 4
  1725.     wy = 0
  1726.     @result_window = Window_TOCraftingResult.new(wx, wy)
  1727.     @result_window.y = (Graphics.height / 2) - (@result_window.height / 2)
  1728.     @result_window.viewport = @viewport
  1729.     @result_window.hide.close
  1730.     @result_window.set_handler(:ok,     method(:on_result_ok))
  1731.     @result_window.refresh
  1732.   end
  1733.  
  1734.   #--------------------------------------------------------------------------
  1735.   # on_result_ok
  1736.   #--------------------------------------------------------------------------
  1737.   def on_result_ok
  1738.     @result_window.close.hide
  1739.     @itemlist_window.activate
  1740.   end
  1741.  
  1742.   #--------------------------------------------------------------------------
  1743.   # create_itemlist_header_window
  1744.   #--------------------------------------------------------------------------
  1745.   def create_itemlist_header_window
  1746.     wx = 0
  1747.     wy = @help_window.height
  1748.     @itemlist_header_window = Window_TOCraftingItemListHeader.new(wx, wy)
  1749.     @itemlist_header_window.viewport = @viewport
  1750.     @itemlist_header_window.hide
  1751.     @itemlist_header_window.close
  1752.     @itemlist_header_window.refresh
  1753.   end
  1754.  
  1755.   #--------------------------------------------------------------------------
  1756.   # create_cover_window
  1757.   #--------------------------------------------------------------------------
  1758.   def create_cover_window
  1759.     wx = Graphics.width / 2
  1760.     wy = @help_window.height
  1761.     wh = Graphics.height - @help_window.height
  1762.     ww = Graphics.width - wx
  1763.     @cover_window = Window_TOCraftingCover.new(wx, wy, ww, wh)
  1764.     @cover_window.viewport = @viewport
  1765.     @cover_window.refresh
  1766.     @cover_window.show
  1767.   end
  1768.  
  1769.   #--------------------------------------------------------------------------
  1770.   # create_info_window
  1771.   #--------------------------------------------------------------------------
  1772.   def create_info_window
  1773.     wx = Graphics.width / 2
  1774.     wy = @help_window.height
  1775.     ww = Graphics.width - wx
  1776.     wh = Graphics.height - @help_window.height
  1777.     @info_window = Window_TOCraftingInfo.new(wx, wy, ww, wh)
  1778.     @info_window.viewport = @viewport
  1779.     @info_window.hide
  1780.     @info_window.refresh
  1781.   end
  1782.  
  1783.   #--------------------------------------------------------------------------
  1784.   # refresh
  1785.   #--------------------------------------------------------------------------
  1786.   def refresh
  1787.     @info_window.refresh
  1788.     @help_window.refresh
  1789.     @itemlist_window.refresh
  1790.     @recipelist_window.refresh
  1791.     @result_window.refresh
  1792.     @itemlist_header_window.refresh
  1793.     @gold_window.refresh
  1794.   end
  1795.  
  1796.   #--------------------------------------------------------------------------
  1797.   # do_crafting
  1798.   #--------------------------------------------------------------------------
  1799.   def do_crafting(item, number)
  1800.     return unless item
  1801.     play_crafting_se(item)
  1802.     lose_ingredients(item, number)
  1803.     pay_crafting_fee(item, number)
  1804.     gain_crafted_item(item, number)
  1805.   end
  1806.  
  1807.   #--------------------------------------------------------------------------
  1808.   # play_crafting_se
  1809.   #--------------------------------------------------------------------------
  1810.   def play_crafting_se(item)
  1811.     if item.tocrafting_se.empty?
  1812.       Sound.play_tocrafting_result
  1813.     else
  1814.       se = item.tocrafting_se
  1815.       Sound.play_custom_tocrafting_result(se[0], se[1], se[2])
  1816.     end
  1817.   end
  1818.  
  1819.   #--------------------------------------------------------------------------
  1820.   # lose_ingredients
  1821.   #--------------------------------------------------------------------------
  1822.   def lose_ingredients(item, number)
  1823.     item.ingredient_list.each do |ingredient|
  1824.       $game_party.lose_item(ingredient, number)
  1825.     end
  1826.   end
  1827.  
  1828.   #--------------------------------------------------------------------------
  1829.   # pay_crafting_fee
  1830.   #--------------------------------------------------------------------------
  1831.   def pay_crafting_fee(item, number)
  1832.     $game_party.lose_gold(item.tocrafting_gold_fee * number)
  1833.   end
  1834.  
  1835.   #--------------------------------------------------------------------------
  1836.   # gain_crafted_item
  1837.   #--------------------------------------------------------------------------
  1838.   def gain_crafted_item(item, number)
  1839.     $game_party.gain_item(item, number)
  1840.   end
  1841.  
  1842.   #--------------------------------------------------------------------------
  1843.   # crafting_fee
  1844.   #--------------------------------------------------------------------------
  1845.   def crafting_fee
  1846.     @item.tocrafting_gold_fee
  1847.   end
  1848.  
  1849.   #--------------------------------------------------------------------------
  1850.   # gold_window?
  1851.   #--------------------------------------------------------------------------
  1852.   def gold_window?
  1853.     Bubs::TOCrafting::USE_GOLD_WINDOW
  1854.   end
  1855.  
  1856.   #--------------------------------------------------------------------------
  1857.   # party_gold
  1858.   #--------------------------------------------------------------------------
  1859.   def party_gold
  1860.     $game_party.gold
  1861.   end
  1862.  
  1863.   #--------------------------------------------------------------------------
  1864.   # max_craft
  1865.   #--------------------------------------------------------------------------
  1866.   def max_craft
  1867.     max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
  1868.     max = crafting_fee == 0 ? max : [max, party_gold / crafting_fee].min
  1869.     for ingredient in @item.ingredient_list.uniq.each
  1870.       break if max == 0
  1871.       count = @item.ingredient_list.count(ingredient)
  1872.       temp_max = 0
  1873.       for i in 1..max
  1874.         break if (i * count) > $game_party.item_number(ingredient)
  1875.         temp_max += 1
  1876.       end # for
  1877.       max = temp_max if max > temp_max
  1878.     end # for
  1879.     return max
  1880.   end
  1881.  
  1882. end # class Scene_TOCrafting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement