#===============================================================================
# Multiple Crafting Script - v2.3 updated: 10/15/2013
# Based off of Cooking Script v1.0 by GubiD
# ported to VXAce by Venka 08/22/13
#===============================================================================
# - Change Log -
#------------------------------------------------------------------------------
# 10/15/2013 - Fix a bug failed item bug introduced in previous patch.
# Fixed a max level bug (could still get exp after max level)
# Allows you to give custom crafter mastery titles.
# 10/11/2013 - Cleaned up some code.
# Added a random craft time setting to allow for some variance
# in craft times. Also added the ability to speed up the craft
# time in relation to how easy it is for you to make.
# Example: a level 1 recipe should be fast for a level 30 crafter.
# 9/30/2012 - Upgraded to version 2.0. Allows use of items, weapons, armor.
# And you can have multiple crafting skills each with their own
# Levels, Recipes, and Exp.
# 8/23/2013 - Inital port from VX to VXAce
#------------------------------------------------------------------------------
# - Introduction -
#------------------------------------------------------------------------------
# A script that allows the player to craft items. There's a menu to help the
# player keep track of their recipes and items needed to make their items.
# You can have multiple crafts (Cooking, Smithing, Alchemy, etc). Each craft
# has it's own exp, levels and recipes.
#
# When crafting an item, gauge bar will show up. The gauge will change colors
# when you can claim an item. If you press enter when the color changes, then
# you succesfully craft the item. If you do it before the change then you
# consume the ingredients and make nothing (with the option of still earning
# some exp). If you try to claim the item after the gauge's color changes
# back to it's orginal color, then you have waited too long and you can
# recieve a failed item (and the option of some exp).
#
# For example, if you're cooking and you cook for too long then you could
# recieve a burnt item.
#
# NOTE: I took out the menu access in this version since it take more coding
# to try to determine the crafting skill type before opening the scene.
# However, you could make a portable item and give it a common event that
# calls the scene.
# I made a Mortar and Pestle that can be used from the menu for Alchemy.
#
#------------------------------------------------------------------------------
# - Script Calls -
#------------------------------------------------------------------------------
# To call the scene use:
# craft(crafte_id)
# crafte_id = This is the ID set for the craft at Craft_Info
#
# EXAMPLE: craft(1)
# This would call the Craft_Info at ID 1, which is "Cooking". So the
# windows would open and show recipes and info for Cooking.
#
# To teach the player a new recipe use:
# learn_recipe(recipe_id)
# recipe_id is the ID in Recipes.
#
# EXAMPLE: learn_recipe(1)
# This would call the recipe that matches Recipes[1]. Which is the
# Loaf of Bread recipe for cooking. So it will show when the cook book
# is open, but not any other craft books.
#
# To delete a recipe use:
# forget_recipe(recipe_id)
# recipe_id is the ID in Recipes.
# NOTE: It's the same as learn_recipe but it removes the recipe.
#
# To check the current crafting level:
# $craft[craft_id].level - player's level
# $craft[craft_id].exp - player's total craft exp
# $craft[craft_id].change_level(level) - grant or loose levels
# crafte_id = This is the ID set for the craft at Craft_Info
# level = the levels you want to add or loose.
#
# EXAMPLES: $craft[2].level - Checks the Smithing Level
# $craft[3].exp - Checks the total exp earned for Alchemy
# $craft[1].change_level(3) - Would grant 3 levels to Cooking
# NOTE: You can use negative numbers to loose levels.
# $craft[1].change_level(-1) - Would loose 1 level to Cooking
#
#==============================================================================
module Venka; module Crafting
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - General Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Crafting_Time_Max = 1000 # Max craft time (total time)
Crafting_Buffer = 30 # Buffer to activated timer (window for claiming)
Default_Craft_Time = 300 # Default craft time (when to claim item)
Time_Variance = 100 # Varience to craft time, set to 0 to disable
Failure_Exp_Rate = 0.25 # Exp recieved when failed. Ex 0.25 is 25%
Accelerate_Time = true # Craft time gets faster as you out level them
Accelerate_Rate = 0.9 # This is the rate to speed up craft time
# This should be between 0.1 and 0.9
# The lower the number, the faster it speeds up.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Gauge Color Settings -
#----------------------------------------------------------------------------
# You can use window skin color code by simply putting the number (0 - 31)
# OR use RBG Colors by putting (red, blue, green, opacity) 0 - 255 each.
# Examples: Exp_Gauge_Color1 = 27
# Exp_Gauge_Color1 = [10, 100, 215, 100]
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Exp_Gauge_Color1 = [110, 0, 215, 200] # Left side of the exp gauge
Exp_Gauge_Color2 = [180, 150, 255, 230] # Right side of the exp gauge
Craft_Gauge_Color1 = 10 # Left side of the crafting gauge
Craft_Gauge_Color2 = 21 # Right side of the crafting gauge
Claim_Gauge_Color1 = [ 25, 100, 0, 255] # Left side of the claim gauge
Claim_Gauge_Color2 = [ 0, 255, 0, 240] # Right side of the claim gauge
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Sound Settings -
#----------------------------------------------------------------------------
# The file should be one found in the SE folder. Volume is 1 - 100
# Pitch can be 50 - 200
# Use this format: [ "FileName", Volume, Pitch ]
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Start_Scene = ["Book1", 80, 100] # Sound on book open
Success_Sound = ["Item1", 80, 75] # Crafted successfuly
Premature_Sound = ["Disappointment", 80, 100] # Crafted too soon
Failure_Sound = ["Chime1", 80, 50] # Crafted too late
Level_Up_Sound = ["Sound2", 80, 100] # Gained crafting level
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Text Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Craft_Button_Text = "Create" # What the begin crafting button displays
Directions_Msg = "Press 'Enter' when the bar is green" # Instructions Text
Failed_Msg = "You have failed at creating this item." # Fail message
Result_Msg = "You crafted:" # Success Message
Lv_Gain = "Leveled Up!!" # Level up message
Pop_up_Window = true # Use the pop up window
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Font Settings -
#----------------------------------------------------------------------------
# :title_text = the text craft's name in the Title Window.
# :recipe_name = the recipe's name at the top of the detail window
# :recipe_list = font used in the recipe list window
# :header_text = the "Ingredients: Needed/Owned" line in the detail window
# :description = the crafted item's description text.
# :help_text = the text that appears when crafting an item.
#

ther_text = all other text
# :button_text = the Create/Cancel Buttons test
#
# For each text type you need to set up the Fonts, Size, Boldness and Color.
# Use the following format:
# [["Font_Name, Font_Name, etc], Font_Size, Bold?, Color]],
# Font_Name = an array holding font choices. The fist one is your first
# choice to use, but if the player doesn't have that font on their
# computer, it will go through the list until it finds one it can use
# Font_Size = the size font you want to use
# Bold? = this should be true for bold, false to turn bold off
# Color = This is the same format as setting colors for Gauge Color.
# Use [red, blue, green, opacity] or window skin color number.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Fonts = { # Fonts, Size, Bold?, Color
:title_text => [["Sylfaen", "Calibri"], 24, true, 0],
:recipe_name => [["Sylfaen", "Calibri"], 25, true, 14],
:recipe_list => [["Sylfaen", "Calibri"], 24, true, 0],
:header_text => [["Sylfaen", "Calibri"], 24, true, 1],
:description => [["Sylfaen", "Calibri"], 22, false, 0],
:help_text => [["Sylfaen", "Calibri"], 24, false, 17],

ther_text => [["Verdana", "Calibri"], 20, false, 0],
:button_text => [["Verdana", "Calibri"], 24, true, [0, 255, 0, 200]],
} # <- DO NOT REMOVE
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Craft_Info Settings -
#----------------------------------------------------------------------------
# ID => [ [ EXP_Table ], "Craft Name", Max_Lv, Mastered_Text]
# ID is used to identify each craft
# EXP Table has 4 parts just like a class's exp in the database.
# [A, B, C, D]
# A is the base exp needed (this number can be 10 or higher)
# B is the exp tacked on to each level (this can be 0 or higher)
# C is a curve that effects all levels (must be 10 or higher)
# D is another curve that effects high levels mostly (must be 10+)
# Craft Name = name for the craft
# Max_Lv = max level for the craft (1 - 99)
# Mastered_Text = Words that replace the exp gauge when craft is maxed out
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Craft_Info = {
# ID => [ [ EXP_Table ], "Craft Name", Max_Lv, Mastered_Text]
1 => [[ 10, 5, 12, 20], "Cook", 99, "Top Chef"],
2 => [[ 12, 3, 20, 15], "Smith", 99, "Master Smith"],
3 => [[ 10, 0, 10, 10], "Alchemy", 99, "Potion Genius"],
} # <- DO NOT REMOVE
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Recipe Settings -
#----------------------------------------------------------------------------
# Recipe[iD] => { The ID must be a unique number.
# :recipe_type => x
# x = the Craft_Info ID this recipe belongs to.
# If it was 1 then it'd be a cooking recipe, 2 is blacksmith, etc
# :req_level => y
# y = the crafting level needed to make the recipe
# :craft_time => t
# t = time in frames (60 frames = 1 second). This is the time when
# the recipe can claim success. Before the time resaults in lost
# ingredients and no item. After this time results in lost
# ingredients and a failed attempt item is granted.
# NOTE: You can omit this one to use the Default_Craft_Time above
# :earned_exp => exp
# exp = the amount of exp recieved on successful crafting of the item
# :crafted_item => [Type, Item_ID, Amount]
# :failed_item => [Type, Item_ID, Amount]
# :ingredients => [[Type, ItemID, Amount], [Type, ItemID, Amount], ... ]
# Type = 1 for Items
# 2 for Armor
# 3 for Weapons
# Item_ID = item's id in the database
# Amount = the amount of items to reward
#
# NOTE: :ingredients can have multiple entries.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Recipes ||= {}
#--------------------------------------------------------------------------
# - Custom Recipes Start Here -
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# - Food Recipes -
#--------------------------------------------------------------------------
Recipes[1] = { # Loaf of Bread
:recipe_type => 1, # Cooking Recipe
:req_level => 1, # Level required to use this recipe
:craft_time => 200, # Time it takes to make the item
:earned_exp => 3, # Exp gained on success
:crafted_item => [1,20,2], # Makes 2x Loaf of Bread
:failed_item => [1,29,1], # 1x Piece of Charcoal if failed attempt
:ingredients => [ # 2x Eggs, 1x Flour, 1x Fresh Milk
[1, 21, 2], [1, 22, 1], [1, 23, 1],
]} # <- DO NOT REMOVE
Recipes[2] = { # Stew
:recipe_type => 1, # Cooking Recipe
:req_level => 2, # Level required to use this recipe
:craft_time => 250, # Time it takes to make the item
:earned_exp => 5, # Exp gained on success
:crafted_item => [1,24,1], # Makes 1x Stew
:failed_item => [1,31,1], # Omitting failed item. You'd just get no item
:ingredients => [# 2x Meat, 1x Carrot, 1x Bell Pepper, 1x Onioin
[1, 25, 2], [1, 26, 1], [1, 27, 1], [1, 28, 1],
#--------------------------------------------------------------------------
# - Weapon Recipes -
#--------------------------------------------------------------------------
]} # <- DO NOT REMOVE
Recipes[3] = { # Battle Axe
:recipe_type => 2, # Smithing Recipe
:req_level => 1, # Level required to use this recipe
#:craft_time => 300, # Time omitted to use defualt time of 300
:earned_exp => 4, # Exp gained on success
:crafted_item => [3,2,1], # Makes 1x Battle Axe
:failed_item => [1,30,1], # 1x Slag on failed attempt
:ingredients => [# 1x Iron Ore, 1x Wooden Shaft
[1, 33, 1], [1, 35, 1],
#--------------------------------------------------------------------------
# - Armour Recipes -
#--------------------------------------------------------------------------
]} # <- DO NOT REMOVE
Recipes[4] = { # Chain Mail
:recipe_type => 2, # Smithing Recipe
:req_level => 2, # Level required to use this recipe
:craft_time => 400, # Time it takes to make the item
:earned_exp => 5, # Exp gained on success
:crafted_item => [2,31,1], # Makes 1x Chain Mail
:failed_item => [1,30,1], # 1x Slag on failed attempt
:ingredients => [# 2x Iron Ore, 3x Leather Straps
[1, 33, 2], [1, 34, 3],
#--------------------------------------------------------------------------
# - General Itemes Recipes -
#--------------------------------------------------------------------------
]} # <- DO NOT REMOVE
Recipes[5] = { # Full Potion
:recipe_type => 3, # Alchemy Recipe
:req_level => 1, # Level required to use this recipe
:craft_time => 350, # Time it takes to make the item
:earned_exp => 4, # Exp gained on success
:crafted_item => [1, 3,1], # Makes 1x Full Potion
:failed_item => [1,31,1], # 1x Slag on failed attempt
:ingredients => [# 1x Lizard Hearts, 1x Sea Shell
[1, 37, 1], [1, 40, 1],
]} # <- DO NOT REMOVE
Recipes[6] = { # Stimulant
:recipe_type => 3, # Alchemy Recipe
:req_level => 3, # Level required to use this recipe
:craft_time => 500, # Time it takes to make the item
:earned_exp => 7, # Exp gained on success
:crafted_item => [1, 5,1], # Makes 1x Stimulant
:failed_item => [1,31,1], # 1x Slag on failed attempt
:ingredients => [# 1x Bat Wings, 1x Pixie Dust
[1, 38, 1], [1, 39, 1],
]} # <- DO NOT REMOVE
end; end
#==============================================================================
# ¦ DataManager
#==============================================================================
module DataManager
#----------------------------------------------------------------------------
# ? alias methods:
#----------------------------------------------------------------------------
class << self
alias venka_crafting_create_objects create_game_objects
alias venka_crafting_save_contents make_save_contents
alias venka_crafting_extract_contents extract_save_contents
end
#----------------------------------------------------------------------------
# ? alias method: create_game_objects
#----------------------------------------------------------------------------
def self.create_game_objects
venka_crafting_create_objects
$craft = Game_Crafting.new
$recipe = Game_Recipes.new
end
#----------------------------------------------------------------------------
# ? alias method: make_save_contents
#----------------------------------------------------------------------------
def self.make_save_contents
contents = venka_crafting_save_contents
contents[:crafting] = $craft
contents
end
#----------------------------------------------------------------------------
# ? alias method: extract_save_contents
#----------------------------------------------------------------------------
def self.extract_save_contents(contents)
venka_crafting_extract_contents(contents)
$craft = contents[:crafting]
end
end
#==============================================================================
# ¦ Game_Craft_Info
#==============================================================================
class Game_Craft_Info
#----------------------------------------------------------------------------
# ? Public Instance Variables
#----------------------------------------------------------------------------
attr_reader :name, :mastered
attr_reader :level
#----------------------------------------------------------------------------
# ? upgrade method: initialize
#----------------------------------------------------------------------------
def initialize(craft_id)
@craft_id = craft_id
@name = Venka::Crafting::Craft_Info[@craft_id][1]
@max_level = Venka::Crafting::Craft_Info[@craft_id][2]
@mastered = Venka::Crafting::Craft_Info[@craft_id][3]
@level = 1
@exp = {}
@unlocked = false
init_exp
end
#----------------------------------------------------------------------------
# ? new method: exp_for_level
#----------------------------------------------------------------------------
def exp_for_level(level)
lv = level.to_f
basis = Venka::Crafting::Craft_Info[@craft_id][0][0].to_f
extra = Venka::Crafting::Craft_Info[@craft_id][0][1].to_f
acc_a = Venka::Crafting::Craft_Info[@craft_id][0][2].to_f
acc_b = Venka::Crafting::Craft_Info[@craft_id][0][3].to_f
return (basis*((lv-1)**(0.9+acc_a/250))*lv*(lv+1)/(6+lv**2/50/acc_

+(lv-1)*extra).round.to_i
end
#----------------------------------------------------------------------------
# ? new method: init_exp
#----------------------------------------------------------------------------
def init_exp; @exp[@craft_id] = current_level_exp; end
#----------------------------------------------------------------------------
# ? new method: exp related methods
#----------------------------------------------------------------------------
def exp; @exp[@craft_id]; end
def current_level_exp; exp_for_level(@level); end
def next_level_exp; exp_for_level(@level + 1); end
def level_up; @level += 1; end
def level_down; @level -= 1; end
def max_level?; @level >= @max_level; end
#----------------------------------------------------------------------------
# ? new method: change_exp
#----------------------------------------------------------------------------
def change_exp(exp)
@exp[@craft_id] = [exp, 0].max
last_level = @level
level_up while !max_level? && self.exp >= next_level_exp
level_down while self.exp < current_level_exp
end
#----------------------------------------------------------------------------
# ? new method: exp, gain_exp
#----------------------------------------------------------------------------
def exp; @exp[@craft_id]; end
def gain_exp(exp); change_exp(self.exp + exp.to_i); end
#----------------------------------------------------------------------------
# ? new method: change_level
#----------------------------------------------------------------------------
def change_level(level)
@level += level
@level = [[@level, @max_level].min, 1].max
change_exp(exp_for_level(@level))
end
end
#==============================================================================
# ¦ Game_Crafting
#==============================================================================
class Game_Crafting
#----------------------------------------------------------------------------
# ? Public Instance Variables
#----------------------------------------------------------------------------
attr_reader :learned_recipes
#----------------------------------------------------------------------------
# ? upgraded method: initialize
#----------------------------------------------------------------------------
def initialize
@craft = []
end
#----------------------------------------------------------------------------
# ? new method: []
#----------------------------------------------------------------------------
def [](craft_id)
return nil unless Venka::Crafting::Craft_Info[craft_id]
@craft[craft_id] ||= Game_Craft_Info.new(craft_id)
end
#----------------------------------------------------------------------------
# ? new method: learn_recipe
#----------------------------------------------------------------------------
def learn_recipe(recipe_id)
@learned_recipes ||= []
@learned_recipes << recipe_id unless @learned_recipes.include?(recipe_id)
@learned_recipes.sort!
end
#----------------------------------------------------------------------------
# ? new method: forget_recipe
#----------------------------------------------------------------------------
def forget_recipe(recipe_id)
@learned_recipes.delete(recipe_id)
end
end
#==============================================================================
# ¦ Game_Recipe
#==============================================================================
class Game_Recipe
#----------------------------------------------------------------------------
# ? Public Instance Variables
#----------------------------------------------------------------------------
attr_reader :recipe_type, :req_level, :ingredients
attr_reader :craft_time, :earned_exp, :ingredient_amount
#----------------------------------------------------------------------------
# ? upgrade method: initialize
#----------------------------------------------------------------------------
def initialize(recipe_id)
@recipe_id = recipe_id
@recipe = Venka::Crafting::Recipes[@recipe_id]
@recipe_type = @recipe[:recipe_type]
@req_level = @recipe[:req_level]
@earned_exp = @recipe[:earned_exp]
@craft_item = @recipe[:crafted_item]
@fail_item = @recipe[:failed_item]
@components = @recipe[:ingredients]
@ingredients = []
@ingredient_amount = []
get_ingredients
get_ingredient_amount
end
#----------------------------------------------------------------------------
# ? new method: craft_time
#----------------------------------------------------------------------------
def craft_time
time = @recipe[:craft_time] ? @recipe[:craft_time] : Venka::Crafting:

efault_Craft_Time
time += rand(Venka::Crafting::Time_Variance)
if Venka::Crafting::Accelerate_Time
rate = Venka::Crafting::Accelerate_Rate
time = (time * (rate ** $craft[@recipe_type].level)).to_i
end
time = [[time, Venka::Crafting::Crafting_Time_Max].min, 0].max
return time
end
#----------------------------------------------------------------------------
# ? new method: crafted_item, failed_item, crafted_amount, failed_amount
#----------------------------------------------------------------------------
def crafted_item; get_item_info(@craft_item[0], @craft_item[1]); end
def crafted_amount; @craft_item[2]; end
def failed_amount; @fail_item[2]; end
#----------------------------------------------------------------------------
# ? new method: failed_item
#----------------------------------------------------------------------------
def failed_item
get_item_info(@fail_item[0], @fail_item[1]) if @recipe[:failed_item]
end
#----------------------------------------------------------------------------
# ? new method: ingredients
#----------------------------------------------------------------------------
def get_ingredients
for i in 0...@components.size
item = get_item_info(@components
[0], @components[1])
@ingredients << item
end
return @ingredients
end
#----------------------------------------------------------------------------
# ? new method: ingredient_amount
#----------------------------------------------------------------------------
def get_ingredient_amount
for i in 0...@components.size
@ingredient_amount << @components[2]
end
return @ingredient_amount
end
#----------------------------------------------------------------------------
# ? new method: get_item_type
#----------------------------------------------------------------------------
def get_item_info(item_type, item_id)
case item_type
when 1; return $data_items[item_id] # Itme
when 2; return $data_armors[item_id] # Armor
when 3; return $data_weapons[item_id] # Weapon
end
end
end
#==============================================================================
# ¦ Game_Recipes
#==============================================================================
class Game_Recipes
#----------------------------------------------------------------------------
# ? upgraded method: initialize
#----------------------------------------------------------------------------
def initialize
@recipes = []
end
#----------------------------------------------------------------------------
# ? new method: []
#----------------------------------------------------------------------------
def [](recipe_id)
return nil unless Venka::Crafting::Recipes[recipe_id]
@recipes[recipe_id] ||= Game_Recipe.new(recipe_id)
end
end
#==============================================================================
# ¦ Game_Interpreter
#==============================================================================
class Game_Interpreter
#----------------------------------------------------------------------------
# ? new method: craft
#----------------------------------------------------------------------------
def craft(craft_type)
SceneManager.call(Scene_Crafting)
SceneManager.scene.prepare(craft_type)
end
#----------------------------------------------------------------------------
# ? new method: learn_recipe
#----------------------------------------------------------------------------
def learn_recipe(recipe_id)
$craft.learn_recipe(recipe_id)
end
#----------------------------------------------------------------------------
# ? new method: forget_recipe
#----------------------------------------------------------------------------
def forget_recipe(recipe_id)
$craft.forget_recipe(recipe_id)
end
end
#==============================================================================
# ¦ Window_Base
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# ? alias method: process_escape_character - credit LoneWolf (fixes trash symbols)
#--------------------------------------------------------------------------
alias
rocess_normal_character_vxa
rocess_normal_character
def process_normal_character(c, pos)
return unless c >= ' '
process_normal_character_vxa(c, pos)
end
#----------------------------------------------------------------------------
# ? new method: get_color - method detirmines if text color or new color
#----------------------------------------------------------------------------
def get_color(input)
input.is_a?(Integer) ? text_color([[input, 0].max, 31].min) : Color.new(*input)
end
#----------------------------------------------------------------------------
# ? new method: craft_font_color
#----------------------------------------------------------------------------
def craft_font_color(text_type)
f_color = Venka::Crafting::Fonts[text_type][3]
color = f_color.is_a?(Integer) ? text_color(f_color) : Color.new(*f_color)
end
#----------------------------------------------------------------------------
# ? new method: set_font
#----------------------------------------------------------------------------
def set_font(text_type)
font = Venka::Crafting::Fonts[text_type]
contents.font.name = font[0]
contents.font.size = font[1]
contents.font.bold = font[2]
change_color(craft_font_color(text_type), enabled = true)
end
end
#==============================================================================
# ¦ Crafting_Title_Window
#==============================================================================
class Crafting_Title_Window < Window_Base
#----------------------------------------------------------------------------
# ? upgraded method: initialize
#----------------------------------------------------------------------------
def initialize
super(0, 0, Graphics.width, 48)
@craft_id = nil
end
#----------------------------------------------------------------------------
# ? new method: craft
#----------------------------------------------------------------------------
def craft=(craft_id)
return if @craft_id == craft_id
@craft_id = craft_id
@craft = $craft[@craft_id]
@exp = @craft.exp
refresh
end
#----------------------------------------------------------------------------
# ? upgraded method: refresh
#----------------------------------------------------------------------------
def refresh
contents.clear
x = w = contents.width * 0.5
set_font
title_text)
draw_text(0, 0, contents.width * 0.3, line_height, @craft.name)
set_font
other_text)
draw_crafting_gauge(x, 0, w) unless @craft.max_level?
draw_craft_level(x, 0, w)
end
#----------------------------------------------------------------------------
# ? new method: draw_crafting_exp_gauge
#----------------------------------------------------------------------------
def draw_crafting_gauge(x, y, width)
s1 = @craft.exp - @craft.current_level_exp
s2 = @craft.exp_for_level(@craft.level + 1) - @craft.current_level_exp
rate = [s1.to_f/s2, 1.0].min
color1 = get_color(Venka::Crafting::Exp_Gauge_Color1)
color2 = get_color(Venka::Crafting::Exp_Gauge_Color2)
draw_gauge(x, y, width, rate, color1, color2)
color1 = color2 = normal_color
draw_current_and_max_values(x + 80, y, width - 80, s1, s2, color1, color2)
end
#----------------------------------------------------------------------------
# ? new method: draw_craft_level
#----------------------------------------------------------------------------
def draw_craft_level(x, y, w)
if @craft.max_level?
set_font
title_text)
draw_text(x, y, w, line_height, @craft.mastered, 2)
else
set_font
other_text)
draw_text(x, y, w, line_height, "Level: #{@craft.level}")
end
end
#----------------------------------------------------------------------------
# ? upgraded method: update
#----------------------------------------------------------------------------
def update
super
if @exp != $craft[@craft_id].exp
@exp = $craft[@craft_id].exp
refresh
end
end
end
#==============================================================================
# ¦ Recipe_List_Window
#==============================================================================
class Recipe_List_Window < Window_Command
#----------------------------------------------------------------------------
# ? Public Instance Variables
#----------------------------------------------------------------------------
attr_reader :detail_window
#----------------------------------------------------------------------------
# ? upgraded method: initialize
#----------------------------------------------------------------------------
def initialize(x, y)
super(x, y)
@craft_type = nil
@recipes = $craft.learned_recipes
end
#----------------------------------------------------------------------------
# ? new method: craft
#----------------------------------------------------------------------------
def craft=(craft)
return if @craft_type == craft
@craft_type = craft
refresh
end
#----------------------------------------------------------------------------
# ? window_settings
#----------------------------------------------------------------------------
def window_width; return Graphics.width * 0.3; end
def window_height; return Graphics.height - 48; end
#----------------------------------------------------------------------------
# ? upgraded method: update
#----------------------------------------------------------------------------
def update
super
if @detail_window.recipe_id != current_symbol
@detail_window.recipe_id = current_symbol
end
end
#----------------------------------------------------------------------------
# ? upgraded method: make_command_list
#----------------------------------------------------------------------------
def make_command_list
return unless @recipes
@items = []
@recipes.each do |recipe_id|
next unless $recipe[recipe_id].recipe_type == @craft_type
item = $recipe[recipe_id].crafted_item
@items << item
add_command(item.name, recipe_id.to_s.to_sym)
end
end
#----------------------------------------------------------------------------
# ? upgraded method: make_command_list
#----------------------------------------------------------------------------
def draw_item(index)
rect = item_rect_for_text(index)
set_font
recipe_list)
draw_item_name(@items[index], rect.x, rect.y, rect.width) if @items[index]
end
#----------------------------------------------------------------------------
# ? upgraded method: draw_item_name
#----------------------------------------------------------------------------
def draw_item_name(item, x, y, width = contents.width)
return unless item
draw_icon(item.icon_index, x, y)
draw_text(x + 24, y, width, line_height, item.name)
end
#----------------------------------------------------------------------------
# ? new method: detail_window
#----------------------------------------------------------------------------
def detail_window=(detail_window)
@detail_window = detail_window
update
end
end
#==============================================================================
# ¦ Crafting_Details_Window
#==============================================================================
class Crafting_Details_Window < Window_Command; include Venka::Crafting
#----------------------------------------------------------------------------
# ? Public Instance Variables
#----------------------------------------------------------------------------
attr_reader :recipe_id, :started
attr_reader :result_exp, :result_item, :result_level
attr_reader :result_amount, :result_message
#----------------------------------------------------------------------------
# ? upgraded method: initialize
#----------------------------------------------------------------------------
def initialize
super(Graphics.width * 0.3, 48)
@recipe_id = :none
@recipe = []
@max = Crafting_Time_Max
@result_item = nil
@result_message = ""
@started = @success = @failed = @result_level = false
@result_exp = @result_amount = 0
unselect
deactivate
end
#----------------------------------------------------------------------------
# ? window settings
#----------------------------------------------------------------------------
def window_width; Graphics.width * 0.7; end
def window_height; Graphics.height - 48; end
def item_max; return 1; end
#----------------------------------------------------------------------------
# ? new method: craft
#----------------------------------------------------------------------------
def craft=(craft)
return if @craft_type == craft
@craft_type = craft
end
#----------------------------------------------------------------------------
# ? new method: recipe_id
#----------------------------------------------------------------------------
def recipe_id=(recipe_id)
return if @recipe_id == recipe_id
@recipe_id = recipe_id
@recipe = $recipe[@recipe_id.to_s.to_i]
refresh
end
#----------------------------------------------------------------------------
# ? upgraded method: make_command_list
#----------------------------------------------------------------------------
def make_command_list
add_command(Craft_Button_Text, :craft, current_item_enabled?)
end
#----------------------------------------------------------------------------
# ? alias method: item_rect
#----------------------------------------------------------------------------
alias venka_crafting_skill_script_ir item_rect
def item_rect(index)
rect = venka_crafting_skill_script_ir(index)
rect.y = contents.height - line_height
return rect
end
#----------------------------------------------------------------------------
# ? new method: draw_item
#----------------------------------------------------------------------------
def draw_item(index)
w, h = contents.width, line_height
set_font
button_text)
draw_text(0, contents.height - h, w, h, Craft_Button_Text, 1)
end
#----------------------------------------------------------------------------
# ? upgraded method: refresh
#----------------------------------------------------------------------------
def refresh
contents.clear
super
return unless @recipe_id
width, height = contents.width, line_height
draw_recipe_header(0, 0, width, height)
draw_item_description(0, height * 2 + 12, @recipe.crafted_item.description)
draw_ingredients(0, height * 5, width, height)
end
#----------------------------------------------------------------------------
# ? new method: draw_recipe_header
#----------------------------------------------------------------------------
def draw_recipe_header(x, y, w, h)
set_font
recipe_name)
draw_icon(@recipe.crafted_item.icon_index, x, y)
draw_text(x + 24, y, width, line_height, @recipe.crafted_item.name)
text = sprintf("×%2d", $game_party.item_number(@recipe.crafted_item))
set_font
header_text)
draw_text(w-60, y, 60, h, "Lv:")
draw_text(w-30, y + 24, 30, h, "Exp")
draw_text(x, y + line_height, 120, h, "In Possession:")
set_font
other_text)
draw_text(w-60, y, 60, h, @recipe.req_level.to_s, 2)
draw_text(w-135, y + 24, 100, h, @recipe.earned_exp.to_s, 2)
draw_text(x + 120, y + line_height, 50, h, text, 2)
end
#----------------------------------------------------------------------------
# ? new method: draw_item_description
#----------------------------------------------------------------------------
def draw_item_description(x, y, text)
set_font
description)
text = convert_escape_characters(text)
pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
process_character(text.slice!(0, 1), text, pos) until text.empty?
end
#----------------------------------------------------------------------------
# ? new method: draw_ingredients
#----------------------------------------------------------------------------
def draw_ingredients(x, y, width, height)
set_font
header_text)
draw_text(x, y, width * 0.5, height, "Ingredients:")
draw_text(x + (width * 0.5), y, width * 0.5, height, "Needed/Owned", 1)
set_font
other_text)
@ingredients = @recipe.ingredients
@ingredient_count = 0
@required = @recipe.ingredient_amount
for i in 0...@ingredients.size
y += height
owned = $game_party.item_number(@ingredients)
enabled = (owned < @required ? false : @ingredient_count += 1)
draw_item_name(@ingredients, x, y, enabled, width * 0.5 - 20)
draw_text(x + (width * 0.5), y, (width * 0.5), height,
"#{@required}/#{owned}", 1)
end
reset_font_settings
end
#----------------------------------------------------------------------------
# ? upgraded method: draw_item_name
#----------------------------------------------------------------------------
def draw_item_name(item, x, y, enabled = true, width = 172)
return unless item
draw_icon(item.icon_index, x, y)
change_color(craft_font_color
other_text), enabled)
draw_text(x + 24, y, width, line_height, item.name)
end
#----------------------------------------------------------------------------
# ? new method: current_item_enabled?
#----------------------------------------------------------------------------
def current_item_enabled?
return false unless @recipe_id
return false if @recipe.req_level > $craft[@craft_type].level
return false if $game_party.item_number(@recipe.crafted_item) == 99
return false if @ingredient_count != @recipe.ingredients.size
return true
end
#----------------------------------------------------------------------------
# ? new method: start_crafting
#----------------------------------------------------------------------------
def start_crafting
@claim_time = @recipe.craft_time
@elapsed = 0
@buffer = Crafting_Buffer
@result_item = nil
@result_message = ""
@success = @failed = @result_level = false
@result_exp = @result_amount = 0
@started = true
end
#----------------------------------------------------------------------------
# ? upgraded method: update
#----------------------------------------------------------------------------
def update
super
while @started
Graphics.update
Input.update
activate_craft
rewards if Input.trigger?(Input::C)
end
end
#----------------------------------------------------------------------------
# ? new method: activate_craft
#----------------------------------------------------------------------------
def activate_craft
width, height = contents.width, line_height
rate = [@elapsed.to_f / @max, 1.0].min
if @claim_time + @buffer > @elapsed and @elapsed > @claim_time - @buffer
@success = true
gc1 = get_color(Claim_Gauge_Color1)
gc2 = get_color(Claim_Gauge_Color2)
else
if @claim_time + @buffer < @elapsed
@failed = true
end
@success = false
gc1 = get_color(Craft_Gauge_Color1)
gc2 = get_color(Craft_Gauge_Color2)
end
set_font
help_text)
draw_text(0, contents.height - height * 3, width, height, Directions_Msg, 1)
set_font
other_text)
draw_gauge(0, contents.height - 60, width, rate, gc1, gc2)
@elapsed += 1
end
#----------------------------------------------------------------------------
# ? new method: rewards
#----------------------------------------------------------------------------
def rewards
@started = false
level = $craft[@craft_type].level # Check current level
for i in 0...@ingredients.size # Remove ingredients from bags
$game_party.lose_item(@ingredients, @required)
end
# Get exp, items, and pop up message based on success
@success ? success_rewards : failed_rewards
# If crafting level changed, then do pop up message and play sound
if level != $craft[@craft_type].level
RPG::SE.new(*Level_Up_Sound).play
@result_level = true
end
refresh
end
#----------------------------------------------------------------------------
# ? new method: success_rewards
#----------------------------------------------------------------------------
def success_rewards
RPG::SE.new(*Success_Sound).play
@result_exp = @recipe.earned_exp
@result_message = Result_Msg
@result_item = @recipe.crafted_item
@result_amount = @recipe.crafted_amount
$game_party.gain_item(@result_item, @result_amount)
$craft[@craft_type].gain_exp(@result_exp)
end
#----------------------------------------------------------------------------
# ? new method: failed_rewards
#----------------------------------------------------------------------------
def failed_rewards
# Get the right sound file info
sound_file = @failed ? Failure_Sound : Premature_Sound
RPG::SE.new(*sound_file).play
# Deterimine if you get a failure item
@result_item = @failed ? @recipe.failed_item : nil
# Get the right pop up message
@result_message = @result_item ? Result_Msg : Failed_Msg
# Determine if failure exp is allowed
failed_exp = (@recipe.earned_exp * Failure_Exp_Rate).to_i
@result_exp = Failure_Exp_Rate > 0 ? [failed_exp, 1].max : 0
# Give failure exp
$craft[@craft_type].gain_exp(@result_exp) unless @result_exp == 0
@result_amount = @result_item ? @recipe.failed_amount : nil
# Grant failure item if one exsists
$game_party.gain_item(@result_item, @result_amount) if @result_item
end
end
#==============================================================================
# ¦ Crafting_Results_Window
#==============================================================================
class Crafting_Results_Window < Window_Message
#----------------------------------------------------------------------------
# ? Public Instance Variables
#----------------------------------------------------------------------------
attr_reader :detail_window
#----------------------------------------------------------------------------
# ? upgraded method: initialize
#----------------------------------------------------------------------------
def initialize
super
self.x = (Graphics.width - window_width) * 0.5
self.y = (Graphics.height - window_height) * 0.5
@item = nil
@amount = @exp = 0
@message = ""
@leveled = false
self.back_opacity = 220
self.openness = 0
end
#----------------------------------------------------------------------------
# ? window settings
#----------------------------------------------------------------------------
def window_width; Graphics.width * 0.8; end
def window_height; fitting_height(4); end
#----------------------------------------------------------------------------
# ? new method: craft
#----------------------------------------------------------------------------
def craft=(craft)
return if @craft_type == craft
@craft_type = craft
end
#----------------------------------------------------------------------------
# ? new method: detail_window
#----------------------------------------------------------------------------
def detail_window=(detail_window)
@detail_window = detail_window
end
#----------------------------------------------------------------------------
# ? new method: update_info
#----------------------------------------------------------------------------
def update_info
@item = @detail_window.result_item
@amount = @detail_window.result_amount
@exp = @detail_window.result_exp
@message = @detail_window.result_message
@leveled = @detail_window.result_level
refresh
self.open
wait_to_dispose
end
#----------------------------------------------------------------------------
# ? upgraded method: refresh
#----------------------------------------------------------------------------
def refresh
contents.clear
draw_header
set_font
other_text)
draw_items_recieved(line_height, contents.width)
draw_exp_recieved(line_height*2) if @exp > 0
draw_level_up(line_height*3) if @leveled
end
#----------------------------------------------------------------------------
# ? new method: draw_header
#----------------------------------------------------------------------------
def draw_header
set_font
recipe_name)
draw_text(0, 0, contents.width, line_height, "Results", 1)
color = normal_color
contents.fill_rect(0, line_height - 2, contents_width, 1, color)
color.alpha = 90
contents.fill_rect(0, line_height - 1, contents_width, 1, color)
end
#----------------------------------------------------------------------------
# ? new method: draw_items_recieved
#----------------------------------------------------------------------------
def draw_items_recieved(y, width)
case @message
when Venka::Crafting::Result_Msg
draw_text(0, y, 120, line_height, @message)
draw_text(120, y, 40, line_height, "x#{@amount}")
draw_item_name(@item, 160, y, width - 160)
when Venka::Crafting::Failed_Msg
draw_text(0, y, width, line_height, @message, 1)
end
end
#----------------------------------------------------------------------------
# ? upgraded method: draw_item_name
#----------------------------------------------------------------------------
def draw_item_name(item, x, y, width)
draw_icon(item.icon_index, x, y)
draw_text(x + 24, y, width, line_height, item.name)
end
#----------------------------------------------------------------------------
# ? new method: draw_exp_recieved
#----------------------------------------------------------------------------
def draw_exp_recieved(y)
if $craft[@craft_type].max_level?
draw_text(0, y, 120, line_height, "Exp earned: ")
draw_text(120, y, contents.width - 120, line_height, "---")
else
draw_text(0, y, 120, line_height, "Exp earned: ")
draw_text(120, y, contents.width - 120, line_height, @exp.to_s)
end
end
#----------------------------------------------------------------------------
# ? new method: draw_level_up
#----------------------------------------------------------------------------
def draw_level_up(y)
set_font
button_text)
draw_text(0, y, contents.width, line_height, Venka::Crafting::Lv_Gain, 1)
end
#----------------------------------------------------------------------------
# ? new method: wait_to_dispose
#----------------------------------------------------------------------------
def wait_to_dispose
loop do
Graphics.update
Input.update
update
break if Input.trigger?(Input::C)
end
self.close
end
end
#==============================================================================
# ¦ Scene_Crafting
#==============================================================================
class Scene_Crafting < Scene_Base; include Venka::Crafting
#----------------------------------------------------------------------------
# ? new method: prepare
#----------------------------------------------------------------------------
def prepare(craft_type)
@craft_type = craft_type
end
#----------------------------------------------------------------------------
# ? upgraded method: start
#----------------------------------------------------------------------------
def start
super
RPG::SE.new(*Start_Scene).play
create_title_window
create_list_window
create_detail_window
create_result_window
end
#----------------------------------------------------------------------------
# ? new method: create_title_window
#----------------------------------------------------------------------------
def create_title_window
@title_window = Crafting_Title_Window.new
@title_window.viewport = @viewport
@title_window.craft = @craft_type
end
#----------------------------------------------------------------------------
# ? new method: create_list_window
#----------------------------------------------------------------------------
def create_list_window
@list_window = Recipe_List_Window.new(0, @title_window.height)
@list_window.viewport = @viewport
@list_window.craft = @craft_type
@list_window.set_handler
ok, method
to_detail_window))
@list_window.set_handler
cancel, method
return_scene))
end
#----------------------------------------------------------------------------
# ? new method: to_detail_window
#----------------------------------------------------------------------------
def to_detail_window
@detail_window.activate.select(0)
end
#----------------------------------------------------------------------------
# ? new method: create_detail_window
#----------------------------------------------------------------------------
def create_detail_window
@detail_window = Crafting_Details_Window.new
@detail_window.viewport = @viewport
@detail_window.craft = @craft_type
@detail_window.set_handler
craft, method
craft_start))
@detail_window.set_handler
cancel, method
return_to_list))
@list_window.detail_window = @detail_window
end
#----------------------------------------------------------------------------
# ? new method: craft_start
#----------------------------------------------------------------------------
def craft_start
Sound.play_ok
@detail_window.start_crafting
while @detail_window.started
Graphics.update
Input.update
update
end
@result_window.update_info if Pop_up_Window
to_detail_window
end
#----------------------------------------------------------------------------
# ? new method: return_to_list
#----------------------------------------------------------------------------
def return_to_list
Sound.play_cancel
@detail_window.unselect
@list_window.activate
end
#----------------------------------------------------------------------------
# ? new method: create_result_window
#----------------------------------------------------------------------------
def create_result_window
@result_window = Crafting_Results_Window.new
@result_window.viewport = @viewport
@result_window.craft = @craft_type
@result_window.detail_window = @detail_window
end
end