Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ++ Tactics Ogre PSP Crafting System ++ v1.5 (7/29/12)
- #==============================================================================
- # Script by:
- # Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
- # Thanks:
- # Mithran, regexp references
- #--------------------------------------------------------------------------
- # This item crafting script is modeled after the crafting system implemented
- # in the PSP remake of Tactics Ogre: Let Us Cling Together. It's a very
- # simple crafting system with a very simple GUI which I also used as
- # a model.
- #
- # Players must have recipe books in their inventory when entering the
- # crafting scene. Any recipe books owned by the player will be displayed
- # in a list. When a recipe book is selected, all possible items, armors,
- # and weapons in the recipe book will be listed and you will be able to
- # craft them provided that the player has the necessary ingredients.
- #
- # Newly added features include being able set a crafting gold fee for
- # item crafted and adding a Tool requirement to craft items. Tools
- # are not consumed when used in the crafting process.
- #--------------------------------------------------------------------------
- # ++ Changelog ++
- #--------------------------------------------------------------------------
- # v1.5 : You can now change the recipebook pictures directory.
- # : You can now assign sound effects for crafted items.
- # : Slight code efficiency update. (7/29/2012)
- # v1.4 : Added the option to use images as recipebook covers.
- # : New Notetag for recipebooks added.
- # : New option in customization module for book images. (7/27/2012)
- # v1.3 : Colon between type and ID no longer needed.
- # : Updated comments to reflect changes.
- # : Tool regexp updated. (7/27/2012)
- # v1.2 : You can now change the Gold icon in the customization module.
- # : You can now change the name of Gold in windows. (7/27/2012)
- # v1.1 : Fixed issue with long item names getting cut off in windows.
- # : Confirm window removed.
- # : Quantity selection window implemented.
- # : Crafting Gold fee implemented.
- # : Crafting tool requirement implemented.
- # : New options added in customization module. (7/26/2012)
- # v1.0 : Initial release. (7/25/2012)
- #--------------------------------------------------------------------------
- # ++ Installation ++
- #--------------------------------------------------------------------------
- # Install this script in the Materials section in your project's
- # script editor.
- #==============================================================================
- # ++ TO Crafting Notetags ++
- #==============================================================================
- # Note: Some tags are given shorter tags for typing convenience. You only
- # need to use one <tag> from a given group for a notebox.
- # Use common sense.
- #
- # The following Notetags are for Items, Weapons, and Armors only:
- #
- # <recipebook>
- # setting
- # setting
- # </recipebook>
- # This tag allows you define a recipe book. You can add as many
- # settings between the <recipebook> tags as you like. Only items with
- # this tag will appear in the recipes window in the crafting scene.
- # The following settings are available:
- #
- # item: id
- # item: id, id, id ...
- # i: id
- # i: id, id, id ...
- # This setting defines the items that can be crafted from the
- # recipe book where id is the Item ID number found in your database.
- # You can list multiple id numbers on the same line separated by commas.
- # This setting can be used multiple times within the <recipebook> tags.
- #
- # weapon: id
- # weapon: id, id, id ...
- # w: id
- # w: id, id, id ...
- # This setting defines the weapons that can be crafted from the
- # recipe book where id is the Weapon ID number found in your database.
- # You can list multiple id numbers on the same line separated by commas.
- # This setting can be used multiple times within the <recipebook> tags.
- #
- # armor: id
- # armor: id, id, id ...
- # armour: id
- # armour: id, id, id ...
- # a: id
- # a: id, id, id ...
- # This setting defines the armors that can be crafted from the
- # recipe book where id is the Armor ID number found in your database.
- # You can list multiple id numbers on the same line separated by commas.
- # This setting can be used multiple times within the <recipebook> tags.
- #
- # picture: filename
- # pic: filename
- # cover: filename
- # This setting defines the image used to represent the recipe book
- # in the crafting scene where filename is the name of a picture
- # located in the Graphics/Pictures/ folder of your project. Do
- # not include the filename's extension. Recommended picture
- # resolutions are [width: 248, height: 320] for default resolutions
- # and [width: 296, height: 384] for 480x640 resolutions.
- #
- # <ingredients>
- # setting
- # setting
- # </ingredients>
- # This tag allows you define the ingredients required to craft an item.
- # You can add as many settings between the <ingredients> tags as you like.
- # If an item, weapon, or armor has no ingredients, you can still craft it.
- # The following settings are available:
- #
- # item: id
- # item: id xN
- # i: id
- # i: id xN
- # This setting defines the item ingredients required to craft the
- # item, weapon, or armor where id is the Item ID number found in
- # your database. xN is total number of that ingredient required if
- # it is included after the id number where N is a whole number
- # (ex. x2, x3, x4, etc.). If xN is not included, the script will
- # automatically assume x1. You can list multiple id numbers on the
- # same line separated by commas. This setting can be used multiple
- # times within the <ingredients> tags.
- #
- # weapon: id
- # weapon: id xN
- # w: id
- # w: id xN
- # This setting defines the weapon ingredients required to craft the
- # item, weapon, or armor where id is the Weapon ID number found in
- # your database. xN is total number of that ingredient required if
- # it is included after the id number where N is a whole number
- # (ex. x2, x3, x4, etc.). If xN is not included, the script will
- # automatically assume x1. You can list multiple id numbers on the
- # same line separated by commas. This setting can be used multiple
- # times within the <ingredients> tags.
- #
- # armor: id
- # armor: id xN
- # armour: id
- # armour: id xN
- # a: id
- # a: id xN
- # This setting defines the armor ingredients required to craft the
- # item, weapon, or armor where id is the Weapon ID number found in
- # your database. xN is total number of that ingredient required if
- # it is included after the id number where N is a whole number
- # (ex. x2, x3, x4, etc.). If xN is not included, the script will
- # automatically assume x1. You can list multiple id numbers on the
- # same line separated by commas. This setting can be used multiple
- # times within the <ingredients> tags.
- #
- # fee: amount
- # gold: amount
- # This setting defines the amount of Gold required to craft
- # the item, armor, or weapon where amount is any amount of gold.
- # If this setting is omitted, it will use the default fee defined
- # in the customization module.
- #
- # tool: item id
- # tool: i id
- # tool: weapon id
- # tool: w id
- # tool: armor id
- # tool: armour id
- # tool: a id
- # This setting defines the tools required to craft the item, weapon,
- # or armor where id is the item, weapon, or armor ID number found in
- # your database. Tools are not consumed in the crafting process.
- # This setting can be used multiple times within the <ingredients>
- # tags.
- #
- # se: filename, volume, pitch
- # This settings defines the custom sound effect played when the
- # item is crafted. filename is a sound effect filename found in
- # the Audio/SE/ folder. volume is a value between 0~100. pitch is
- # a value between 50~150. If this setting is omitted, the default
- # crafting sound effect defined in the customization module will
- # play instead.
- #
- # Here are some examples of proper <recipebook> tags and <ingredients> tags:
- #
- # <recipebook>
- # weapon: 1, 2, 7, 8, 13, 14, 19, 20
- # weapon: 25, 37, 38
- # armor: 1, 2, 3, 4, 5
- # item: 40
- # </recipebook>
- #
- # It is important to know that Note boxes have iffy word wrap distinction.
- # If a line is too long and overflows into the next line, that next line
- # might be treated as a new line in the Note box. To stay on the safe side,
- # if you have a long list of ids for a single item type setting, you
- # should start the next line with the similar type setting. See the
- # "weapon:" settings in this example tag.
- #
- # <ingredients>
- # item: 29 x3
- # item: 30 x2
- # item: 31
- # </ingredients>
- #
- # Each ingredient id must be on its own line, unlike the recipebook tag.
- # More than 6 ingredients are possible, but the Required Ingredients
- # window will not display more than 6. The last setting tag "item: 31" does
- # not have an "xN" multiplier which means the script will automatically
- # assume "x1".
- #
- # <ingredients>
- # fee: 30
- # se: Bell3, 80, 100
- # tool: item 40
- # item: 21
- # item: 22 x2
- # </ingredients>
- #
- # This tag is an example of how to use the "fee" and "tool" setting tags.
- # Item ID 40 is required to craft the item, but it will not be consumed.
- # Each item crafted costs 30 gold. The sound effect Bell3 will play
- # when the item is crafted.
- #
- #==============================================================================
- # ++ TO Crafting Script Calls ++
- #==============================================================================
- # The following Script Calls are meant to be used in "Script..." event
- # commands found under Tab 3 when creating a new event.
- #
- # open_tocrafting_shop
- # This script call opens up the Tactics Ogre Crafting scene.
- #
- #--------------------------------------------------------------------------
- # ++ FAQ ++
- #--------------------------------------------------------------------------
- # --Why am I allowed to craft items that have no required ingredients?
- #
- # This was done on purpose to ease game development. I assumed that
- # when people finalize a game, they will have an appropriate list of
- # ingredients for each craftable item defined by then.
- #
- # --Can an item/armor/weapon have a <recipebook> tag AND an <ingredients>
- # tag?
- #
- # Yes.
- #
- # --Can the "Required Ingredients" window display more than 6 ingredients?
- #
- # Currently, no.
- #
- # --Can items have more than 6 different required ingredients?
- #
- # Yes, but the player won't be able to see the required ingredients
- # beyond the first 6. If there is a demand for displaying more than
- # 6, I can implement it.
- #
- # --Why isn't "Success Rate" also implemented in this script from
- # Tactics Ogre PSP?
- #
- # Because I think Success Rate on crafting in single-player games
- # is annoying and pointless due to save and load. But if there is
- # demand for it, I can implement it.
- #--------------------------------------------------------------------------
- # ++ Compatibility ++
- #--------------------------------------------------------------------------
- # This script aliases the following default VXA methods:
- #
- # DataManager#load_database
- #
- # There are no default method overwrites.
- #
- # Requests for compatibility with other scripts are welcome.
- #--------------------------------------------------------------------------
- # ++ Terms and Conditions ++
- #--------------------------------------------------------------------------
- # Please do not repost this script elsewhere without permission.
- # Free for non-commercial use. For commercial use, contact me first.
- #
- # Newest versions of this script can be found at
- # http://mrbubblewand.wordpress.com/
- #==============================================================================
- $imported ||= {}
- $imported["BubsTOCrafting"] = true
- #==========================================================================
- # ++ START OF USER CUSTOMIZATION MODULE ++
- #==========================================================================
- module Bubs
- #==========================================================================
- # ++ TO Crafting Settings
- #==========================================================================
- module TOCrafting
- #--------------------------------------------------------------------------
- # Ingredients List Display Settings
- #--------------------------------------------------------------------------
- INGREDIENTS_HEADER_TEXT = "Required Ingredients" # Header text
- NOT_ENOUGH_INGREDIENTS_COLOR = 10 # Windowskin color index, default 10 (red)
- #--------------------------------------------------------------------------
- # Tools Window Display Settings
- #--------------------------------------------------------------------------
- TOOL_AVAILABLE_TEXT = "Available"
- TOOL_AVAILABLE_TEXT_COLOR = 3 # Windowskin color index, default 3 (green)
- TOOL_UNAVAILABLE_TEXT = "Unavailable"
- TOOL_UNAVAILABLE_TEXT_COLOR = 10 # Windowskin color index, default 10 (red)
- #--------------------------------------------------------------------------
- # Faded Requirement Not Met Display Settings
- #--------------------------------------------------------------------------
- # true : Ingredient quantity and Tool requirement text will be faded
- # out like the item name if the requirement isn't met
- # false : Ingredient quantity and Tool requirement text will not be faded
- FADED_REQUIREMENT_QUANTITY = false
- #--------------------------------------------------------------------------
- # Crafting Fee Default Markdown/Markup Rate
- #--------------------------------------------------------------------------
- # If a "fee: amount" setting is not included in an <ingredients> tag,
- # it will use the item's Price in the database by default. This setting
- # allows you to automatically increase or decrease that item, armor
- # or weapon price by a specified rate where 100.0 is normal price and
- # 0.0 is free.
- CRAFTING_FEE_PRICE_RATE = 0.0
- #--------------------------------------------------------------------------
- # Gold Window Settings
- #--------------------------------------------------------------------------
- # true : Gold window appears in crafting scene
- # false : Gold crafting fees appear in ingredients list, no gold window
- USE_GOLD_WINDOW = true
- GOLD_WINDOW_ICON_INDEX = 361 # Icon Index number
- GOLD_WINDOW_TEXT = "Gold"
- #--------------------------------------------------------------------------
- # Crafting Result Header Text
- #--------------------------------------------------------------------------
- RESULT_WINDOW_HEADER_TEXT = "You Received"
- #--------------------------------------------------------------------------
- # Stretch Recipebook Pictures Setting
- #--------------------------------------------------------------------------
- # Recommended width and height for book covers images:
- #
- # width: 248, height: 320 (default resolutions)
- # width: 296, height: 384 (480x640 resolutions)
- #
- # true : Book cover pics are stretched to fit the contents of the window.
- # false : Book cover pics are drawn normally.
- STRETCH_RECIPEBOOK_PICTURES = false
- #--------------------------------------------------------------------------
- # Recipebook Images Folder Directory
- #--------------------------------------------------------------------------
- # Project folder where recipebook pictures are located.
- #
- # Default: "Graphics/Pictures/"
- RECIPEBOOK_PICTURES_DIRECTORY = "Graphics/Pictures/"
- #--------------------------------------------------------------------------
- # Default Crafting Result Sound Effect
- #--------------------------------------------------------------------------
- # "filename", Volume, Pitch
- CRAFTING_RESULT_SE = [ "Bell2", 80, 100]
- end # module TOCrafting
- end # module Bubs
- #==========================================================================
- # ++ END OF USER CUSTOMIZATION MODULE ++
- #==========================================================================
- #==============================================================================
- # ++ Sound
- #==============================================================================
- module Sound
- #--------------------------------------------------------------------------
- # new method : play_tocrafting_result
- #--------------------------------------------------------------------------
- def self.play_tocrafting_result
- filename = Bubs::TOCrafting::CRAFTING_RESULT_SE[0]
- volume = Bubs::TOCrafting::CRAFTING_RESULT_SE[1]
- pitch = Bubs::TOCrafting::CRAFTING_RESULT_SE[2]
- Audio.se_play("/Audio/SE/" + filename, volume, pitch)
- end
- #--------------------------------------------------------------------------
- # new method : play_custom_tocrafting_result
- #--------------------------------------------------------------------------
- def self.play_custom_tocrafting_result(filename, volume, pitch)
- Audio.se_play("/Audio/SE/" + filename, volume, pitch)
- end
- end # module Sound
- #==============================================================================
- # ++ Cache
- #==============================================================================
- module Cache
- #--------------------------------------------------------------------------
- # new method : recipebook_cover
- #--------------------------------------------------------------------------
- def self.recipebook_cover(filename)
- load_bitmap(Bubs::TOCrafting::RECIPEBOOK_PICTURES_DIRECTORY, filename)
- end
- end
- #==========================================================================
- # ++ Bubs::Regexp
- #==========================================================================
- module Bubs
- module Regexp
- RECIPEBOOK_START_TAG = /<RECIPE[_\s]?BOOK>/i
- RECIPEBOOK_END_TAG = /<\/RECIPE[_\s]?BOOK>/i
- RECIPEBOOK_OBJ_TAG = /(\w+):\s*(\d+(?:\s*,\s*\d+)*)/i
- RECIPEBOOK_COVER_TAG = /(?:PICTURE|PIC|COVER):\s*(\w+)/i
- INGREDIENT_START_TAG = /<INGREDIENTS?>/i
- INGREDIENT_END_TAG = /<\/INGREDIENTS?>/i
- INGREDIENT_OBJ_TAG = /(\w+):\s*[×x]?(\d+)\s*[×x]?(\d+)?/i
- REQUIRED_TOOLS_TAG = /TOOLS?:\s*(\w+)\s*(\d+)/i
- CRAFTING_CUSTOM_SE_TAG = /SE:\s*(\w+)\s*,\s*(\d+)\s*,\s*(\d+)/i
- end # module Regexp
- end # module Bubs
- #==========================================================================
- # ++ DataManager
- #==========================================================================
- module DataManager
- #--------------------------------------------------------------------------
- # alias : load_database
- #--------------------------------------------------------------------------
- class << self; alias load_database_bubs_tocrafting load_database; end
- def self.load_database
- load_database_bubs_tocrafting # alias
- load_notetags_bubs_tocrafting
- end
- #--------------------------------------------------------------------------
- # new method : load_notetags_bubs_tocrafting
- #--------------------------------------------------------------------------
- def self.load_notetags_bubs_tocrafting
- groups = [$data_items, $data_weapons, $data_armors]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.load_notetags_bubs_tocrafting
- end # for obj
- end # for group
- end # def
- end # module DataManager
- #==========================================================================
- # ++ RPG::BaseItem
- #==========================================================================
- class RPG::BaseItem
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_accessor :recipe_list
- attr_accessor :ingredient_list
- attr_accessor :tocrafting_tools
- attr_accessor :tocrafting_gold_fee
- attr_accessor :tocrafting_bookcover
- attr_accessor :tocrafting_se
- #--------------------------------------------------------------------------
- # common cache : load_notetags_bubs_tocrafting
- #--------------------------------------------------------------------------
- def load_notetags_bubs_tocrafting
- @recipe_list = []
- @ingredient_list = []
- @tocrafting_tools = []
- @tocrafting_gold_fee = self.price
- @tocrafting_bookcover = ""
- @tocrafting_se = []
- load_notetags_default_fee_bubs_tocrafting
- recipe_tag = false
- ingredient_tag = false
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when Bubs::Regexp::RECIPEBOOK_START_TAG
- recipe_tag = true
- when Bubs::Regexp::RECIPEBOOK_END_TAG
- recipe_tag = false
- when Bubs::Regexp::INGREDIENT_START_TAG
- ingredient_tag = true
- when Bubs::Regexp::INGREDIENT_END_TAG
- ingredient_tag = false
- when Bubs::Regexp::CRAFTING_CUSTOM_SE_TAG
- next unless ingredient_tag
- @tocrafting_se = [$1, $2.to_i, $3.to_i]
- when Bubs::Regexp::RECIPEBOOK_COVER_TAG
- next unless recipe_tag
- @tocrafting_bookcover = $1
- when Bubs::Regexp::REQUIRED_TOOLS_TAG
- next unless ingredient_tag
- load_notetags_tools_bubs_tocrafting(line)
- else
- load_notetags_recipelist_bubs_tocrafting(line) if recipe_tag
- load_notetags_ingredients_bubs_tocrafting(line) if ingredient_tag
- end # case
- } # self.note.split
- @recipe_list.compact!
- @ingredient_list.compact!
- @tocrafting_tools.compact!
- end # load_notetags_bubs_tocrafting
- #--------------------------------------------------------------------------
- # common cache : load_notetags_default_fee_bubs_tocrafting
- #--------------------------------------------------------------------------
- def load_notetags_default_fee_bubs_tocrafting
- rate = Bubs::TOCrafting::CRAFTING_FEE_PRICE_RATE
- @tocrafting_gold_fee = (@tocrafting_gold_fee * (rate * 0.01)).to_i
- end
- #--------------------------------------------------------------------------
- # common cache : load_notetags_recipelist_bubs_tocrafting
- #--------------------------------------------------------------------------
- def load_notetags_recipelist_bubs_tocrafting(line)
- return unless line =~ Bubs::Regexp::RECIPEBOOK_OBJ_TAG ? true : false
- match = $~.clone
- id_array = match[2].scan(/\d+/)
- case match[1].upcase
- when "I", "ITEM"
- for id in id_array
- @recipe_list.push( $data_items[id.to_i] )
- end
- when "W", "WEAPON", "WEP"
- for id in id_array
- @recipe_list.push( $data_weapons[id.to_i] )
- end
- when "A", "ARMOR", "ARMOUR", "ARM"
- for id in id_array
- @recipe_list.push( $data_armors[id.to_i] )
- end # for
- end # case
- end # def load_notetags_recipelist_bubs_tocrafting
- #--------------------------------------------------------------------------
- # common cache : load_notetags_ingredients_bubs_tocrafting
- #--------------------------------------------------------------------------
- def load_notetags_ingredients_bubs_tocrafting(line)
- return unless line =~ Bubs::Regexp::INGREDIENT_OBJ_TAG ? true : false
- amount = $3 ? $3.to_i : 1
- case $1.upcase
- when "I", "ITEM"
- amount.times do @ingredient_list.push( $data_items[$2.to_i] ) end
- when "W", "WEAPON", "WEP"
- amount.times do @ingredient_list.push( $data_weapons[$2.to_i] ) end
- when "A", "ARMOR", "ARMOUR", "ARM"
- amount.times do @ingredient_list.push( $data_armors[$2.to_i] ) end
- when "FEE", "GOLD"
- @tocrafting_gold_fee = $2.to_i
- end # case $1.upcase
- end # def load_notetags_ingredients_bubs_tocrafting
- #--------------------------------------------------------------------------
- # common cache : load_notetags_tools_bubs_tocrafting
- #--------------------------------------------------------------------------
- def load_notetags_tools_bubs_tocrafting(line)
- line =~ Bubs::Regexp::REQUIRED_TOOLS_TAG
- case $1.upcase
- when "I", "ITEM"
- @tocrafting_tools.push( $data_items[$2.to_i] )
- when "W", "WEAPON", "WEP"
- @tocrafting_tools.push( $data_weapons[$2.to_i] )
- when "A", "ARMOR", "ARMOUR", "ARM"
- @tocrafting_tools.push( $data_armors[$2.to_i] )
- end # case
- end # def load_notetags_tools_bubs_tocrafting
- #--------------------------------------------------------------------------
- # new method : recipebook?
- #--------------------------------------------------------------------------
- def recipebook?
- return false unless self.is_a?(RPG::UsableItem) || self.is_a?(RPG::EquipItem)
- return !@recipe_list.empty?
- end
- end # class RPG::BaseItem
- #==============================================================================
- # ++ Window_TOCraftingRecipeList
- #==============================================================================
- class Window_TOCraftingRecipeList < Window_ItemList
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_reader :info_window
- attr_reader :header_window
- attr_reader :cover_window
- #--------------------------------------------------------------------------
- # initialize
- #--------------------------------------------------------------------------
- def initialize(x, y, height)
- super(x, y, window_width, height)
- end
- #--------------------------------------------------------------------------
- # window_width
- #--------------------------------------------------------------------------
- def window_width
- Graphics.width / 2
- end
- #--------------------------------------------------------------------------
- # current_item_enabled? # Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # enable? # Display in Enabled State?
- #--------------------------------------------------------------------------
- def enable?(item)
- return false if item.nil?
- return true
- end
- #--------------------------------------------------------------------------
- # col_max
- #--------------------------------------------------------------------------
- def col_max
- return 1
- end
- #--------------------------------------------------------------------------
- # include? # Include in Item List?
- #--------------------------------------------------------------------------
- def include?(item)
- return false if item.nil?
- return true if item.recipebook?
- return false
- end
- #--------------------------------------------------------------------------
- # draw_item
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(item, rect.x, rect.y, enable?(item), rect.width - 24)
- end
- end
- #--------------------------------------------------------------------------
- # info_window=
- #--------------------------------------------------------------------------
- def info_window=(info_window)
- @info_window = info_window
- call_update_help
- end
- #--------------------------------------------------------------------------
- # header_window=
- #--------------------------------------------------------------------------
- def header_window=(header_window)
- @header_window = header_window
- end
- #--------------------------------------------------------------------------
- # cover_window=
- #--------------------------------------------------------------------------
- def cover_window=(cover_window)
- @cover_window = cover_window
- end
- #--------------------------------------------------------------------------
- # update_help
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item) if @help_window
- @info_window.item = item if @info_window
- @header_window.item = item if @header_window
- @cover_window.item = item if @cover_window
- end
- end # Window_TOCraftingRecipeList
- #==============================================================================
- # ++ Window_TOCraftingItemListHeader
- #==============================================================================
- class Window_TOCraftingItemListHeader < Window_Base
- #--------------------------------------------------------------------------
- # initialize
- #--------------------------------------------------------------------------
- def initialize(x, y)
- super(x, y, window_width, window_height)
- @item = nil
- end
- #--------------------------------------------------------------------------
- # window_width
- #--------------------------------------------------------------------------
- def window_width
- Graphics.width / 2
- end
- #--------------------------------------------------------------------------
- # window_height
- #--------------------------------------------------------------------------
- def window_height
- fitting_height(1)
- end
- #--------------------------------------------------------------------------
- # item= # Set window header item
- #--------------------------------------------------------------------------
- def item=(item)
- @item = item
- end
- #--------------------------------------------------------------------------
- # refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_itemlist_header_item(0, 0)
- end
- #--------------------------------------------------------------------------
- # draw_itemlist_header_item
- #--------------------------------------------------------------------------
- def draw_itemlist_header_item(x, y)
- return unless @item
- draw_item_name(@item, x, y, true, contents.width - 28)
- end
- end # class Window_TOCraftingItemListHeader
- #==============================================================================
- # ++ Window_TOCraftingItemList
- #==============================================================================
- class Window_TOCraftingItemList < Window_ItemList
- #--------------------------------------------------------------------------
- # initialize
- #--------------------------------------------------------------------------
- def initialize(x, y, height)
- super(x, y, window_width, height)
- @item = nil
- end
- #--------------------------------------------------------------------------
- # window_width
- #--------------------------------------------------------------------------
- def window_width
- Graphics.width / 2
- end
- #--------------------------------------------------------------------------
- # col_max
- #--------------------------------------------------------------------------
- def col_max
- return 1
- end
- #--------------------------------------------------------------------------
- # item=
- #--------------------------------------------------------------------------
- def item=(item)
- @item = item
- refresh
- end
- #--------------------------------------------------------------------------
- # info_window=
- #--------------------------------------------------------------------------
- def info_window=(info_window)
- @info_window = info_window
- call_update_help
- end
- #--------------------------------------------------------------------------
- # gold_window=
- #--------------------------------------------------------------------------
- def gold_window=(gold_window)
- @gold_window = gold_window
- call_update_help
- end
- #--------------------------------------------------------------------------
- # current_item_enabled? # Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # enable? # Display in Enabled State?
- #--------------------------------------------------------------------------
- def enable?(item)
- return false if item.nil?
- return false if item.tocrafting_gold_fee > $game_party.gold
- return false if $game_party.item_max?(item)
- return false unless have_tools?(item)
- return true if item.ingredient_list.empty?
- return have_ingredients?(item)
- end
- #--------------------------------------------------------------------------
- # have_ingredients?
- #--------------------------------------------------------------------------
- def have_ingredients?(item)
- item.ingredient_list.uniq.each do |ingredient|
- party_amount = $game_party.item_number(ingredient)
- required_amount = item.ingredient_list.count(ingredient)
- return false if party_amount < required_amount
- end # do
- return true
- end
- #--------------------------------------------------------------------------
- # have_tools?
- #--------------------------------------------------------------------------
- def have_tools?(item)
- item.tocrafting_tools.uniq.each do |tool|
- return false if !$game_party.has_item?(tool)
- end
- return true
- end
- #--------------------------------------------------------------------------
- # include? # Include in Item List?
- #--------------------------------------------------------------------------
- def include?(item)
- return false if item.nil?
- return true
- end
- #--------------------------------------------------------------------------
- # make_item_list
- #--------------------------------------------------------------------------
- def make_item_list
- @data = @item.recipe_list.each { |item| include?(item) } if @item
- end
- #--------------------------------------------------------------------------
- # update_help
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item) if @help_window
- @info_window.item = item if @info_window
- @gold_window.item = item if @gold_window
- end
- #--------------------------------------------------------------------------
- # update_open
- #--------------------------------------------------------------------------
- def update_open
- self.openness += 24
- @opening = false if open?
- end
- end # class Window_TOCraftingItemList
- #==============================================================================
- # ++ Window_TOCraftingInfo
- #==============================================================================
- class Window_TOCraftingInfo < Window_Base
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_accessor :number
- #--------------------------------------------------------------------------
- # initialize
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super(x, y, width, height)
- @item = nil
- @number = 1
- refresh
- end
- #--------------------------------------------------------------------------
- # refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- return unless @item
- draw_required_ingredients_text(4, 0)
- draw_ingredients(4, line_height * 1)
- end
- #--------------------------------------------------------------------------
- # item= # Set Item
- #--------------------------------------------------------------------------
- def item=(item)
- @item = item
- refresh
- end
- #--------------------------------------------------------------------------
- # ingredients
- #--------------------------------------------------------------------------
- def ingredients
- @item.ingredient_list
- end
- #--------------------------------------------------------------------------
- # tools
- #--------------------------------------------------------------------------
- def tools
- @item.tocrafting_tools
- end
- #--------------------------------------------------------------------------
- # draw_required_ingredients_text
- #--------------------------------------------------------------------------
- def draw_required_ingredients_text(x, y)
- rect = Rect.new(x, y, contents.width - 4 - x, line_height)
- change_color(system_color)
- draw_text(rect, Bubs::TOCrafting::INGREDIENTS_HEADER_TEXT)
- end
- #--------------------------------------------------------------------------
- # draw_ingredients
- #--------------------------------------------------------------------------
- def draw_ingredients(x, y)
- return unless @item
- i = 0
- # draw gold info
- if !Bubs::TOCrafting::USE_GOLD_WINDOW && @item.tocrafting_gold_fee > 0
- draw_gold_info(@item, x, y)
- i += 1
- end
- # draw tool info
- tools.uniq.each do |item|
- draw_tools_info(item, x, y + line_height * (i * 2))
- i += 1
- end
- # draw ingredient info
- ingredients.uniq.each do |item|
- draw_ingredient_info(item, x, y + line_height * (i * 2))
- i += 1
- end # do
- end
- #--------------------------------------------------------------------------
- # required_amount
- #--------------------------------------------------------------------------
- def required_amount(item)
- ingredients.count(item) * @number
- end
- #--------------------------------------------------------------------------
- # party_amount
- #--------------------------------------------------------------------------
- def party_amount(item)
- $game_party.item_number(item)
- end
- #--------------------------------------------------------------------------
- # crafting_fee
- #--------------------------------------------------------------------------
- def crafting_fee
- @item.tocrafting_gold_fee
- end
- #--------------------------------------------------------------------------
- # party_gold
- #--------------------------------------------------------------------------
- def party_gold
- $game_party.gold
- end
- #--------------------------------------------------------------------------
- # currency_unit
- #--------------------------------------------------------------------------
- def currency_unit
- Vocab::currency_unit
- end
- #--------------------------------------------------------------------------
- # draw_tools_info
- #--------------------------------------------------------------------------
- def draw_tools_info(item, x, y)
- enabled = $game_party.has_item?(item)
- width = contents.width - 4 - x
- draw_item_name(item, x, y, enabled, width)
- draw_tool_availability_text(item, x, y, enabled)
- end
- #--------------------------------------------------------------------------
- # draw_tool_availability_text
- #--------------------------------------------------------------------------
- def draw_tool_availability_text(item, x, y, enabled)
- rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
- if enabled
- change_color(text_color(Bubs::TOCrafting::TOOL_AVAILABLE_TEXT_COLOR))
- draw_text(rect, Bubs::TOCrafting::TOOL_AVAILABLE_TEXT, 2)
- else
- change_color(text_color(Bubs::TOCrafting::TOOL_UNAVAILABLE_TEXT_COLOR))
- draw_text(rect, Bubs::TOCrafting::TOOL_UNAVAILABLE_TEXT, 2)
- end
- end
- #--------------------------------------------------------------------------
- # draw_ingredient_info
- #--------------------------------------------------------------------------
- def draw_ingredient_info(item, x, y)
- enabled = party_amount(item) >= required_amount(item)
- width = contents.width - 4 - x
- draw_item_name(item, x, y, enabled, width)
- not_enough_ingredients_color unless enabled
- rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
- draw_text(rect, sprintf("×%2d/%2d", required_amount(item), party_amount(item)), 2)
- end
- #--------------------------------------------------------------------------
- # draw_gold_info
- #--------------------------------------------------------------------------
- def draw_gold_info(item, x, y)
- return if item.nil?
- enabled = party_gold >= crafting_fee
- cx = text_size(currency_unit).width
- width = contents.width - 4 - x
- draw_gold_name(x, y, enabled)
- change_color(system_color)
- draw_text(x, y + line_height, width, line_height, currency_unit, 2)
- change_color(normal_color)
- not_enough_ingredients_color unless enabled
- text = sprintf("%8d/%8d", crafting_fee * @number, party_gold)
- draw_text(x, y + line_height, width - cx - 2, line_height, text, 2)
- end
- #--------------------------------------------------------------------------
- # draw_gold_name
- #--------------------------------------------------------------------------
- def draw_gold_name(x, y, enabled = true)
- draw_icon(Bubs::TOCrafting::GOLD_WINDOW_ICON_INDEX, x, y, enabled)
- change_color(normal_color, enabled)
- draw_text(x + 24, y, width, line_height, Bubs::TOCrafting::GOLD_WINDOW_TEXT)
- end
- #--------------------------------------------------------------------------
- # not_enough_ingredients_color
- #--------------------------------------------------------------------------
- def not_enough_ingredients_color
- enabled = !Bubs::TOCrafting::FADED_REQUIREMENT_QUANTITY
- color_index = Bubs::TOCrafting::NOT_ENOUGH_INGREDIENTS_COLOR
- change_color(text_color(color_index), enabled)
- end
- end # class Window_TOCraftingInfo
- #==============================================================================
- # ++ Window_TOCraftingResult
- #==============================================================================
- class Window_TOCraftingResult < Window_Selectable
- #--------------------------------------------------------------------------
- # initialize
- #--------------------------------------------------------------------------
- def initialize(x, y)
- @item = nil
- @number = 0
- super(x, y, window_width,window_height)
- end
- #--------------------------------------------------------------------------
- # window_width
- #--------------------------------------------------------------------------
- def window_width
- Graphics.width / 2
- end
- #--------------------------------------------------------------------------
- # window_height
- #--------------------------------------------------------------------------
- def window_height
- fitting_height(2)
- end
- #--------------------------------------------------------------------------
- # set
- #--------------------------------------------------------------------------
- def set(item, number)
- @item = item
- @number = number
- end
- #--------------------------------------------------------------------------
- # refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_result_header_text(4, 0)
- draw_result_item(4, line_height)
- end
- #--------------------------------------------------------------------------
- # draw_result_header_text
- #--------------------------------------------------------------------------
- def draw_result_header_text(x, y)
- return unless @item
- rect = Rect.new(x, y, contents.width - 4 - x, line_height)
- change_color(system_color)
- draw_text(rect, Bubs::TOCrafting::RESULT_WINDOW_HEADER_TEXT, 1)
- end
- #--------------------------------------------------------------------------
- # draw_result_item
- #--------------------------------------------------------------------------
- def draw_result_item(x, y)
- return unless @item
- draw_item_name(@item, x, y, true)
- draw_item_amount(x, y, @number)
- end
- #--------------------------------------------------------------------------
- # draw_item_amount
- #--------------------------------------------------------------------------
- def draw_item_amount(x, y, number)
- rect = Rect.new(x, y, contents.width - 4 - x, line_height)
- draw_text(rect, sprintf("×%2d", number), 2)
- end
- end # class Window_TOCraftingResult
- #==============================================================================
- # ++ Window_TOCraftingGold
- #==============================================================================
- class Window_TOCraftingGold < Window_Base
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_accessor :number
- #--------------------------------------------------------------------------
- # initialize
- #--------------------------------------------------------------------------
- def initialize
- super(0, 0, window_width, fitting_height(2))
- @item = nil
- @number = 1
- refresh
- end
- #--------------------------------------------------------------------------
- # window_width
- #--------------------------------------------------------------------------
- def window_width
- return Graphics.width / 2
- end
- #--------------------------------------------------------------------------
- # item=
- #--------------------------------------------------------------------------
- def item=(item)
- @item = item
- refresh
- end
- #--------------------------------------------------------------------------
- # refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_gold_info(4, 0)
- end
- #--------------------------------------------------------------------------
- # currency_unit
- #--------------------------------------------------------------------------
- def currency_unit
- Vocab::currency_unit
- end
- #--------------------------------------------------------------------------
- # open
- #--------------------------------------------------------------------------
- def open
- refresh
- super
- end
- #--------------------------------------------------------------------------
- # crafting_fee
- #--------------------------------------------------------------------------
- def crafting_fee
- @item.tocrafting_gold_fee
- end
- #--------------------------------------------------------------------------
- # party_gold
- #--------------------------------------------------------------------------
- def party_gold
- $game_party.gold
- end
- #--------------------------------------------------------------------------
- # draw_gold_info
- #--------------------------------------------------------------------------
- def draw_gold_info(x, y)
- return if @item.nil?
- enabled = party_gold >= crafting_fee
- cx = text_size(currency_unit).width
- width = contents.width - 4 - x
- draw_gold_name(x, y, enabled)
- change_color(system_color)
- draw_text(x, y + line_height, width, line_height, currency_unit, 2)
- change_color(normal_color)
- not_enough_ingredients_color unless enabled
- text = sprintf("%8d/%8d", crafting_fee * @number, party_gold)
- draw_text(x, y + line_height, width - cx - 2, line_height, text, 2)
- end
- #--------------------------------------------------------------------------
- # draw_gold_name
- #--------------------------------------------------------------------------
- def draw_gold_name(x, y, enabled = true)
- draw_icon(Bubs::TOCrafting::GOLD_WINDOW_ICON_INDEX, x, y, enabled)
- change_color(normal_color, enabled)
- draw_text(x + 24, y, width, line_height, Bubs::TOCrafting::GOLD_WINDOW_TEXT)
- end
- #--------------------------------------------------------------------------
- # not_enough_ingredients_color
- #--------------------------------------------------------------------------
- def not_enough_ingredients_color
- enabled = !Bubs::TOCrafting::FADED_REQUIREMENT_QUANTITY
- color_index = Bubs::TOCrafting::NOT_ENOUGH_INGREDIENTS_COLOR
- change_color(text_color(color_index), enabled)
- end
- end # class Window_TOCraftingGold
- #==============================================================================
- # ++ Window_TOCraftingNumber
- #==============================================================================
- class Window_TOCraftingNumber < Window_Selectable
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_accessor :number # quantity entered
- attr_reader :item
- #--------------------------------------------------------------------------
- # initialize
- #--------------------------------------------------------------------------
- def initialize(x, y, height)
- super(x, y, window_width, height)
- @item = nil
- @info_window = nil
- @max = 1
- @price = 0
- @number = 1
- @currency_unit = Vocab::currency_unit
- end
- #--------------------------------------------------------------------------
- # window_width
- #--------------------------------------------------------------------------
- def window_width
- return Graphics.width / 2
- end
- #--------------------------------------------------------------------------
- # info_window=
- #--------------------------------------------------------------------------
- def info_window=(info_window)
- @info_window = info_window
- end
- #--------------------------------------------------------------------------
- # gold_window=
- #--------------------------------------------------------------------------
- def gold_window=(gold_window)
- @gold_window = gold_window
- end
- #--------------------------------------------------------------------------
- # set
- #--------------------------------------------------------------------------
- def set(item, max, price, currency_unit = nil)
- @item = item
- @max = max
- @price = price
- @currency_unit = currency_unit if currency_unit
- @number = 1
- refresh
- end
- #--------------------------------------------------------------------------
- # currency_unit
- #--------------------------------------------------------------------------
- def currency_unit=(currency_unit)
- @currency_unit = currency_unit
- refresh
- end
- #--------------------------------------------------------------------------
- # refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_item_name(@item, 0, item_y)
- draw_number
- #draw_total_price
- update_info_window
- update_gold_window
- end
- #--------------------------------------------------------------------------
- # draw_number
- #--------------------------------------------------------------------------
- def draw_number
- change_color(normal_color)
- draw_text(cursor_x - 28, item_y, 22, line_height, "×")
- draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
- end
- #--------------------------------------------------------------------------
- # draw_total_price
- #--------------------------------------------------------------------------
- def draw_total_price
- return if @item.nil?
- return if @item.tocrafting_gold_fee == 0
- width = contents_width - 8
- draw_currency_value(@price * @number, @currency_unit, 4, price_y, width)
- end
- #--------------------------------------------------------------------------
- # item_y # Y Coordinate of Item Name Display Line
- #--------------------------------------------------------------------------
- def item_y
- contents_height / 2 - line_height * 3 / 2
- end
- #--------------------------------------------------------------------------
- # price_y # Y Coordinate of Price Display Line
- #--------------------------------------------------------------------------
- def price_y
- contents_height / 2 + line_height / 2
- end
- #--------------------------------------------------------------------------
- # cursor_width
- #--------------------------------------------------------------------------
- def cursor_width
- figures * 10 + 12
- end
- #--------------------------------------------------------------------------
- # cursor_x # Get X Coordinate of Cursor
- #--------------------------------------------------------------------------
- def cursor_x
- contents_width - cursor_width - 4
- end
- #--------------------------------------------------------------------------
- # figures # Get Maximum Number of Digits for Quantity Display
- #--------------------------------------------------------------------------
- def figures
- return 2
- end
- #--------------------------------------------------------------------------
- # update # Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- if active
- last_number = @number
- update_number
- if @number != last_number
- Sound.play_cursor
- refresh
- end
- end
- end
- #--------------------------------------------------------------------------
- # update_number # Update Quantity
- #--------------------------------------------------------------------------
- def update_number
- change_number(1) if Input.repeat?(:RIGHT)
- change_number(-1) if Input.repeat?(:LEFT)
- change_number(10) if Input.repeat?(:UP)
- change_number(-10) if Input.repeat?(:DOWN)
- end
- #--------------------------------------------------------------------------
- # change_number
- #--------------------------------------------------------------------------
- def change_number(amount)
- @number = [[@number + amount, @max].min, 1].max
- end
- #--------------------------------------------------------------------------
- # update_cursor
- #--------------------------------------------------------------------------
- def update_cursor
- cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
- end
- #--------------------------------------------------------------------------
- # update_info_window
- #--------------------------------------------------------------------------
- def update_info_window
- @info_window.number = @number
- @info_window.refresh
- end
- #--------------------------------------------------------------------------
- # update_gold_window
- #--------------------------------------------------------------------------
- def update_gold_window
- @gold_window.number = @number
- @gold_window.refresh
- end
- end # class Window_TOCraftingNumber
- #==============================================================================
- # ++ Window_TOCraftingCover
- #==============================================================================
- class Window_TOCraftingCover < Window_Base
- #--------------------------------------------------------------------------
- # refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_bookcover(0, 0)
- end
- #--------------------------------------------------------------------------
- # item=
- #--------------------------------------------------------------------------
- def item=(item)
- @item = item
- refresh
- end
- #--------------------------------------------------------------------------
- # draw_bookcover
- #--------------------------------------------------------------------------
- def draw_bookcover(x, y)
- return unless @item
- bitmap = Cache.recipebook_cover(@item.tocrafting_bookcover)
- rect = Rect.new(0, 0, contents.width, contents.height)
- if Bubs::TOCrafting::STRETCH_RECIPEBOOK_PICTURES
- contents.stretch_blt(rect, bitmap, bitmap.rect)
- else
- contents.blt(x, y, bitmap, rect)
- end
- bitmap.dispose
- end
- end # class Window_TOCraftingCover
- #==============================================================================
- # ++ Game_Interpreter
- #==============================================================================
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # new method : open_tocrafting_shop
- #--------------------------------------------------------------------------
- def open_tocrafting_shop
- SceneManager.call(Scene_TOCrafting)
- end
- end
- #==============================================================================
- # ++ Scene_TOCrafting
- #==============================================================================
- class Scene_TOCrafting < Scene_MenuBase
- #--------------------------------------------------------------------------
- # start
- #--------------------------------------------------------------------------
- def start
- super
- create_help_window
- create_gold_window
- create_cover_window
- create_info_window
- create_itemlist_header_window
- create_itemlist_window
- create_recipelist_window
- create_number_window
- create_result_window
- end
- #--------------------------------------------------------------------------
- # create_gold_window
- #--------------------------------------------------------------------------
- def create_gold_window
- @gold_window = Window_TOCraftingGold.new
- @gold_window.viewport = @viewport
- @gold_window.hide.close
- @gold_window.x = 0
- @gold_window.y = Graphics.height - @gold_window.height
- end
- #--------------------------------------------------------------------------
- # create_number_window
- #--------------------------------------------------------------------------
- def create_number_window
- wx = 0
- wy = @itemlist_header_window.y + @itemlist_header_window.height
- wh = Graphics.height - wy
- wh = wh - @gold_window.height if gold_window?
- @number_window = Window_TOCraftingNumber.new(wx, wy, wh)
- @number_window.viewport = @viewport
- @number_window.info_window = @info_window
- @number_window.gold_window = @gold_window
- @number_window.hide.close
- @number_window.set_handler(:ok, method(:on_number_ok))
- @number_window.set_handler(:cancel, method(:on_number_cancel))
- end
- #--------------------------------------------------------------------------
- # on_number_ok
- #--------------------------------------------------------------------------
- def on_number_ok
- @number_window.close.hide
- @number_window.number
- do_crafting(@item, @number_window.number)
- @result_window.set(@item, @number_window.number)
- @result_window.show.open.activate
- @itemlist_window.show.open
- @gold_window.number = @info_window.number = 1
- refresh
- @result_window.show.open.activate
- end
- #--------------------------------------------------------------------------
- # on_number_cancel
- #--------------------------------------------------------------------------
- def on_number_cancel
- @number_window.close.hide
- @gold_window.number = @info_window.number = 1
- @itemlist_window.show.open.activate
- end
- #--------------------------------------------------------------------------
- # create_recipelist_window
- #--------------------------------------------------------------------------
- def create_recipelist_window
- wx = 0
- wy = @help_window.height
- wh = Graphics.height - wy
- @recipelist_window = Window_TOCraftingRecipeList.new(wx, wy, wh)
- @recipelist_window.viewport = @viewport
- @recipelist_window.help_window = @help_window
- @recipelist_window.info_window = @info_window
- @recipelist_window.header_window = @itemlist_header_window
- @recipelist_window.cover_window = @cover_window
- @recipelist_window.set_handler(:ok, method(:on_recipelist_ok))
- @recipelist_window.set_handler(:cancel, method(:on_recipelist_cancel))
- @recipelist_window.refresh
- @recipelist_window.show.activate.select(0)
- end
- #--------------------------------------------------------------------------
- # on_recipelist_ok
- #--------------------------------------------------------------------------
- def on_recipelist_ok
- @recipelist_window.close
- @itemlist_window.item = @recipelist_window.item
- @gold_window.show.open if gold_window?
- @cover_window.hide
- @info_window.show
- activate_itemlist_window
- end
- #--------------------------------------------------------------------------
- # on_recipelist_cancel
- #--------------------------------------------------------------------------
- def on_recipelist_cancel
- refresh
- return_scene
- end
- #--------------------------------------------------------------------------
- # activate_recipelist_window
- #--------------------------------------------------------------------------
- def activate_recipelist_window
- refresh
- @recipelist_window.show.open.activate
- end
- #--------------------------------------------------------------------------
- # create_itemlist_window
- #--------------------------------------------------------------------------
- def create_itemlist_window
- wx = 0
- wy = @help_window.height + @itemlist_header_window.height
- wh = Graphics.height - wy
- wh = wh - @gold_window.height if gold_window?
- @itemlist_window = Window_TOCraftingItemList.new(wx, wy, wh)
- @itemlist_window.viewport = @viewport
- @itemlist_window.help_window = @help_window
- @itemlist_window.info_window = @info_window
- @itemlist_window.gold_window = @gold_window
- @itemlist_window.hide
- @itemlist_window.close
- @itemlist_window.set_handler(:ok, method(:on_itemlist_ok))
- @itemlist_window.set_handler(:cancel, method(:on_itemlist_cancel))
- @itemlist_window.refresh
- end
- #--------------------------------------------------------------------------
- # on_itemlist_ok
- #--------------------------------------------------------------------------
- def on_itemlist_ok
- @item = @itemlist_window.item
- @itemlist_window.close.hide
- @number_window.set(@item, max_craft, crafting_fee)
- @number_window.show.open.activate
- end
- #--------------------------------------------------------------------------
- # on_itemlist_cancel
- #--------------------------------------------------------------------------
- def on_itemlist_cancel
- @itemlist_window.close
- @itemlist_header_window.close
- @gold_window.close.hide if gold_window?
- @info_window.hide
- @cover_window.show
- activate_recipelist_window
- end
- #--------------------------------------------------------------------------
- # activate_itemlist_window
- #--------------------------------------------------------------------------
- def activate_itemlist_window
- refresh
- @itemlist_header_window.show.open
- @itemlist_window.show.open.activate.select(0)
- end
- #--------------------------------------------------------------------------
- # create_number_window
- #--------------------------------------------------------------------------
- def create_number_window
- wx = 0
- wy = @itemlist_header_window.y + @itemlist_header_window.height
- wh = Graphics.height - wy
- wh = wh - @gold_window.height if gold_window?
- @number_window = Window_TOCraftingNumber.new(wx, wy, wh)
- @number_window.viewport = @viewport
- @number_window.info_window = @info_window
- @number_window.gold_window = @gold_window
- @number_window.hide.close
- @number_window.set_handler(:ok, method(:on_number_ok))
- @number_window.set_handler(:cancel, method(:on_number_cancel))
- end
- #--------------------------------------------------------------------------
- # on_number_ok
- #--------------------------------------------------------------------------
- def on_number_ok
- @number_window.close.hide
- @number_window.number
- do_crafting(@item, @number_window.number)
- @result_window.set(@item, @number_window.number)
- @result_window.show.open.activate
- @itemlist_window.show.open
- @gold_window.number = @info_window.number = 1
- refresh
- @result_window.show.open.activate
- end
- #--------------------------------------------------------------------------
- # on_number_cancel
- #--------------------------------------------------------------------------
- def on_number_cancel
- @number_window.close.hide
- @gold_window.number = @info_window.number = 1
- @itemlist_window.show.open.activate
- end
- #--------------------------------------------------------------------------
- # create_result_window
- #--------------------------------------------------------------------------
- def create_result_window
- wx = Graphics.width / 4
- wy = 0
- @result_window = Window_TOCraftingResult.new(wx, wy)
- @result_window.y = (Graphics.height / 2) - (@result_window.height / 2)
- @result_window.viewport = @viewport
- @result_window.hide.close
- @result_window.set_handler(:ok, method(:on_result_ok))
- @result_window.refresh
- end
- #--------------------------------------------------------------------------
- # on_result_ok
- #--------------------------------------------------------------------------
- def on_result_ok
- @result_window.close.hide
- @itemlist_window.activate
- end
- #--------------------------------------------------------------------------
- # create_itemlist_header_window
- #--------------------------------------------------------------------------
- def create_itemlist_header_window
- wx = 0
- wy = @help_window.height
- @itemlist_header_window = Window_TOCraftingItemListHeader.new(wx, wy)
- @itemlist_header_window.viewport = @viewport
- @itemlist_header_window.hide
- @itemlist_header_window.close
- @itemlist_header_window.refresh
- end
- #--------------------------------------------------------------------------
- # create_cover_window
- #--------------------------------------------------------------------------
- def create_cover_window
- wx = Graphics.width / 2
- wy = @help_window.height
- wh = Graphics.height - @help_window.height
- ww = Graphics.width - wx
- @cover_window = Window_TOCraftingCover.new(wx, wy, ww, wh)
- @cover_window.viewport = @viewport
- @cover_window.refresh
- @cover_window.show
- end
- #--------------------------------------------------------------------------
- # create_info_window
- #--------------------------------------------------------------------------
- def create_info_window
- wx = Graphics.width / 2
- wy = @help_window.height
- ww = Graphics.width - wx
- wh = Graphics.height - @help_window.height
- @info_window = Window_TOCraftingInfo.new(wx, wy, ww, wh)
- @info_window.viewport = @viewport
- @info_window.hide
- @info_window.refresh
- end
- #--------------------------------------------------------------------------
- # refresh
- #--------------------------------------------------------------------------
- def refresh
- @info_window.refresh
- @help_window.refresh
- @itemlist_window.refresh
- @recipelist_window.refresh
- @result_window.refresh
- @itemlist_header_window.refresh
- @gold_window.refresh
- end
- #--------------------------------------------------------------------------
- # do_crafting
- #--------------------------------------------------------------------------
- def do_crafting(item, number)
- return unless item
- play_crafting_se(item)
- lose_ingredients(item, number)
- pay_crafting_fee(item, number)
- gain_crafted_item(item, number)
- end
- #--------------------------------------------------------------------------
- # play_crafting_se
- #--------------------------------------------------------------------------
- def play_crafting_se(item)
- if item.tocrafting_se.empty?
- Sound.play_tocrafting_result
- else
- se = item.tocrafting_se
- Sound.play_custom_tocrafting_result(se[0], se[1], se[2])
- end
- end
- #--------------------------------------------------------------------------
- # lose_ingredients
- #--------------------------------------------------------------------------
- def lose_ingredients(item, number)
- item.ingredient_list.each do |ingredient|
- $game_party.lose_item(ingredient, number)
- end
- end
- #--------------------------------------------------------------------------
- # pay_crafting_fee
- #--------------------------------------------------------------------------
- def pay_crafting_fee(item, number)
- $game_party.lose_gold(item.tocrafting_gold_fee * number)
- end
- #--------------------------------------------------------------------------
- # gain_crafted_item
- #--------------------------------------------------------------------------
- def gain_crafted_item(item, number)
- $game_party.gain_item(item, number)
- end
- #--------------------------------------------------------------------------
- # crafting_fee
- #--------------------------------------------------------------------------
- def crafting_fee
- @item.tocrafting_gold_fee
- end
- #--------------------------------------------------------------------------
- # gold_window?
- #--------------------------------------------------------------------------
- def gold_window?
- Bubs::TOCrafting::USE_GOLD_WINDOW
- end
- #--------------------------------------------------------------------------
- # party_gold
- #--------------------------------------------------------------------------
- def party_gold
- $game_party.gold
- end
- #--------------------------------------------------------------------------
- # max_craft
- #--------------------------------------------------------------------------
- def max_craft
- max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
- max = crafting_fee == 0 ? max : [max, party_gold / crafting_fee].min
- for ingredient in @item.ingredient_list.uniq.each
- break if max == 0
- count = @item.ingredient_list.count(ingredient)
- temp_max = 0
- for i in 1..max
- break if (i * count) > $game_party.item_number(ingredient)
- temp_max += 1
- end # for
- max = temp_max if max > temp_max
- end # for
- return max
- end
- end # class Scene_TOCrafting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement