#===============================================================================
# ** Code Fixes by Eduardo Moura ;)
#----------------------------------
# Module Brew by Wazakindjes
# - Version 1.0 (15.12.07)
# Edit of Module Craft by Prexus
# - Version 2.0 (31.12.06
#-------------------------------------------------------------------------------
# Credits to Wazakindjes for the Brewing edit.
# Credits to Prexus for the module.
#-------------------------------------------------------------------------------
# This is the primary module of the WazaBrew script. Be sure to read the
# instructions to learn how to create new recipes. Do not change any of the
# constants in the DO NOT TOUCH section.
#===============================================================================
module Brew
#=============================================================================
# CONSTANTS :: DO NOT TOUCH
#=============================================================================
ITEM = 0
NOT_CONSUMED = false; CONSUMED = true;
#=============================================================================
# CONSTANTS :: PLEASE TOUCH THESE.. BABY!
#=============================================================================
SHOW_RESULT = true # Show result made window
SHOW_LIST_ICONS = true # Show icons in recipe list
SHOW_RESULT_ICON = true # Show icons in result window
SHOW_COMPONENT_ICONS = true # Show icons in component window
#=============================================================================
# RECIPES :: Follow Instructions
#-----------------------------------------------------------------------------
# FORMAT :
# {'NAME' => 'RECIPE NAME AS STRING',
# 'TYPE' => 'Brew',
# 'RESULT' => [ITEM, ID, VALUE],
# 'COMPONENTS' => [
# [ITEM, ID, VALUE, CONSUMED?],
# [ITEM, ID, VALUE, CONSUMED?],
# ...
# ]
# }
#-----------------------------------------------------------------------------
# To setup a recipe, follow the example below:
#-----------------------------------------------------------------------------
# {'NAME' => 'Silver Potion',
# 'TYPE' => 'Brew',
# 'RESULT' => [ITEM, 1, 1],
# 'COMPONENTS' => [
# [ITEM, 1, 1, CONSUMED],
# [ITEM, 2, 1, CONSUMED],
# [ITEM, 3, 1, NOT_CONSUMED]
# ]
# } # End Recipe [ITEM, 1, 1]
#=============================================================================
RECIPES = [
{'NAME' => 'Silver Potion',
'TYPE' => 'Brew',
'RESULT' => [ITEM, 3, 1],
'COMPONENTS' => [
[ITEM, 2, 1, CONSUMED],
[ITEM, 1, 1, CONSUMED]
]
},
{'NAME' => 'Golden Potion',
'TYPE' => 'Brew',
'RESULT' => [ITEM, 6, 1],
'COMPONENTS' => [
[ITEM, 4, 1, CONSUMED],
[ITEM, 5, 1, CONSUMED]
]
}
]
#=============================================================================
# Brew Methods
#-----------------------------------------------------------------------------
# valid_recipe? : name
# Checks if the recipe name given exists in the recipe data store.
#=============================================================================
def self.valid_recipe?(name)
for recipe in RECIPES
return true if name == recipe['NAME']
end
return false
end
#=============================================================================
# Brew Methods
#-----------------------------------------------------------------------------
# can_make? : name
# Checks if the recipe is possible to make. First finds if the recipe given is
# valid, then checks if there are enough components in your inventory.
#=============================================================================
def self.can_make?(name)
return false unless self.valid_recipe?(name)
for r in RECIPES
next unless name == r['NAME']
recipe = r
end
return false unless recipe
for component in recipe['COMPONENTS']
case component[0]
when 0 # ITEM
return false unless $game_party.item_number(component[1]) >= component[2]
end
end
return true
end
#=============================================================================
# Brew Methods
#-----------------------------------------------------------------------------
# get_recipe : name
# Returns the hash object containing the data information for the recipe if
# the recipe is valid. Else returns nil.
#=============================================================================
def self.get_recipe(name)
return nil unless self.valid_recipe?(name)
for recipe in RECIPES
return recipe if recipe['NAME'] == name
end
return nil
end
end
#===============================================================================
# Scene Brew
#-------------------------------------------------------------------------------
# This is the main interface for the brewing system. You can run it by using
# the callscript command '$scene = Brew::Scene_Brew.new('Brew')' or by adding it to your own
# code in the same manner.
#===============================================================================
class Scene_Brew
def initialize(type = nil)
@type = type
end
#-----------------------------------------------------------------------------
def main
@recipe_list = Window_RecipeList.new(@type)
@result_info = Window_ResultInfo.new(@recipe_list.data)
@result_comp = Window_ResultComponents.new(@recipe_list.data)
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
Graphics.freeze
@recipe_list.dispose
@result_info.dispose
@result_comp.dispose
end
#-----------------------------------------------------------------------------
def update
if @result_window == nil || @result_window.disposed?
@recipe_list.update
@result_info.update(@recipe_list.data)
@result_comp.update(@recipe_list.data)
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
if @result_window != nil
@result_window.dispose if !@result_window.disposed?
return if !@result_window.disposed?
end
if brew(@recipe_list.data)
$game_system.se_play($data_system.decision_se)
else
$game_system.se_play($data_system.buzzer_se)
end
@recipe_list.refresh
@result_info.refresh
@result_comp.refresh
return
end
end
#-----------------------------------------------------------------------------
def brew(recipe)
return false unless Brew.can_make?(recipe)
recipe = Brew.get_recipe(@recipe_list.data)
if Brew::SHOW_RESULT
if @result_window
@result_window.dispose
@result_window = nil
end
@result_window = Window_Base.new(0, 0, 256, 64)
@result_window.contents = Bitmap.new(224, 32)
@result_window.x = 320 - @result_window.width / 2
@result_window.y = 240 - @result_window.height / 2
@result_window.z = 9998
@result_window.contents.draw_text(4, 0, 224, 32,
"#{$data_items[recipe['RESULT'][1]].name} made!", 1)
end
for component in recipe['COMPONENTS']
case component[0]
when 0 # Item
$game_party.lose_item(component[1], component[2]) if component[3]
end
end
case recipe['RESULT'][0]
when 0 # Item
$game_party.gain_item(recipe['RESULT'][1], recipe['RESULT'][2])
end
return true
end
end
#===============================================================================
# Window RecipeList
#-------------------------------------------------------------------------------
# This is a standard command window which shows all the recipes known by the
# party. They will appear in White if you have the proper reagents to combine
# or grey otherwise.
#===============================================================================
class Window_RecipeList < Window_Selectable
def initialize(type)
super(0, 0, 224, 480)
self.contents = Bitmap.new(width - 32, height - 32)
@data = []
@type = type
refresh
end
#-----------------------------------------------------------------------------
def data
return @data[self.index]
end
#-----------------------------------------------------------------------------
def refresh
self.contents.clear
@data = []
for recipe in $game_party.recipes
if @type
next unless Brew.get_recipe(recipe)['TYPE'] == @type
end
@data.push(recipe) if Brew.valid_recipe?(recipe)
end
@item_max = @data.size
self.index = [[self.index, 0].max, @item_max].min
for i in 0..@data.size
data = @data[i]
next unless data
x = (Brew::SHOW_LIST_ICONS ? 32 : 4)
recipe = Brew.get_recipe(data)
if Brew::SHOW_LIST_ICONS
case recipe['RESULT'][0]
when 0 # ITEM
bitmap = RPG::Cache.icon($data_items[recipe['RESULT'][1]].icon_name)
self.contents.blt(4, i * 32 + 4, bitmap, Rect.new(0, 0, 24, 24))
text = $data_items[recipe['RESULT'][1]].name
cw = contents.text_size(text).width
self.contents.draw_text(4+32,i*32 + 4,cw,32,text)
end
end
end
end
end
#===============================================================================
# Window ResultInfo
#-------------------------------------------------------------------------------
# This window displays all the information regarding the resulting item.
#===============================================================================
class Window_ResultInfo < Window_Base
def initialize(recipe)
super(224, 0, 640-224, 272)
self.contents = Bitmap.new(width - 32, height - 32)
@recipe = recipe
refresh
end
#-----------------------------------------------------------------------------
def refresh
self.contents.clear
recipe = Brew.get_recipe(@recipe)
return unless recipe
case recipe['RESULT'][0]
when 0 # ITEM
item = $data_items[recipe['RESULT'][1]]
return unless item
if Brew::SHOW_RESULT_ICON
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(4, 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.draw_text(32, 0, self.contents.width - 36, 32, item.name.to_s)
else
self.contents.draw_text(4, 0, self.contents.width - 8, 32, item.name.to_s)
end
self.contents.draw_text(4, 0, self.contents.width - 8, 32, "#{item.price} #{$data_system.words.gold}", 2)
if item.recover_hp_rate != 0
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "HP: #{item.recover_hp_rate}%")
elsif item.recover_hp != 0
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "HP: #{item.recover_hp}")
end
if item.recover_sp_rate != 0
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "SP: #{item.recover_sp_rate}%", 1)
elsif item.recover_sp != 0
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "SP: #{item.recover_sp}", 1)
end
self.contents.draw_text(4, 80, self.contents.width - 8, 32, "Hit%: #{item.hit}")
self.contents.draw_text(4, 80, self.contents.width - 8, 32, "Variance: #{item.variance}", 2)
case item.parameter_type
when 1
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "Max HP: +#{item.parameter_points}", 2)
when 2
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "Max SP: +#{item.parameter_points}", 2)
when 3
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "STR: +#{item.parameter_points}", 2)
when 4
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "DEX: +#{item.parameter_points}", 2)
when 5
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "AGI: +#{item.parameter_points}", 2)
when 6
self.contents.draw_text(4, 48, self.contents.width - 8, 32, "INT: +#{item.parameter_points}", 2)
end
state_text = 'State + '
for state in item.plus_state_set
state_text += ', ' unless state == item.plus_state_set.first
state_text += $data_states[state].name
end
self.contents.draw_text(4, 112, self.contents.width - 8, 32, "#{state_text}")
state_text = 'State - '
for state in item.minus_state_set
state_text += ', ' unless state == item.minus_state_set.first
state_text += $data_states[state].name
end
self.contents.draw_text(4, 144, self.contents.width - 8, 32, "#{state_text}")
end
end
#-----------------------------------------------------------------------------
def update(recipe)
super()
return unless recipe != @recipe
@recipe = recipe
refresh
end
end
#===============================================================================
# Window ResultComponents
#-------------------------------------------------------------------------------
# This window displays all the components required for the combination, as well
# as the amount you have and the amount required of each. If an item has a *
# after the name, it will not be consumed in the combination.
#===============================================================================
class Window_ResultComponents < Window_Base
def initialize(recipe)
super(224, 272, 640-224, 208)
self.contents = Bitmap.new(width - 32, height - 32)
@recipe = recipe
refresh
end
#-----------------------------------------------------------------------------
def refresh
self.contents.clear
recipe = Brew.get_recipe(@recipe)
return unless recipe
i = 0
for component in recipe['COMPONENTS']
case component[0]
when 0 # ITEM
item = $data_items[component[1]]
number = $game_party.item_number(component[1])
end
next unless item
text = "#{item.name}"
text += ' (*)' unless component[3]
x = (Brew::SHOW_COMPONENT_ICONS ? 32 : 4)
if Brew::SHOW_COMPONENT_ICONS
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(4, i * 32 + 4, bitmap, Rect.new(0, 0, 24, 24))
end
self.contents.draw_text(x, i * 32, self.contents.width - x - 4, 32, "#{text}")
self.contents.draw_text(x, i * 32, self.contents.width - x - 4, 32, "#{number}/#{component[2]}", 2)
i += 1
end
end
#-----------------------------------------------------------------------------
def update(recipe)
super()
return unless recipe != @recipe
@recipe = recipe
refresh
end
end
#===============================================================================
# Game_Party
#-------------------------------------------------------------------------------
# This is a small edit of the original Game_Party class to add recognition for
# recipes. It also adds the methods below:
# add_recipe() : name
# - this will teach the party the recipe, if it's valid. name is the name
# of the recipe.
# remove_recipe() : name
# - this will force the party to forget the recipe, if it's known. name is
# the name of the recipe.
# have_recipe() : name
# - this will return true or false, depending on if the party knows the
# recipe. Primary used in the can_make? method of the Brew module.
# learn_trade() : name
# - this will enable the use of the Brew skill.
#===============================================================================
class Game_Party
attr_reader :recipes
attr_reader :trade_skills
#-----------------------------------------------------------------------------
alias wazabrew_g_party_initialize initialize
#-----------------------------------------------------------------------------
def initialize
wazabrew_g_party_initialize
@recipes = []
@trade_skills = Hash.new(0)
end
#-----------------------------------------------------------------------------
def add_recipe(name)
@recipes.push(name) if Brew.valid_recipe?(name) and !have_recipe(name)
end
#-----------------------------------------------------------------------------
def remove_recipe(name)
@recipes.delete(name)
end
#-----------------------------------------------------------------------------
def have_recipe(name)
return @recipes.include?(name)
end
#-----------------------------------------------------------------------------
def learn_trade(name)
@trade_skills[name] = 1
end
end