#==============================================================================
# ** Crafting System
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1.1
# 2006-10-17
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- (2006-09-06)
# Version 1.1 ------------------------------------------------- (2006-10-17)
# - Update : Made Crafting Scene Child Class to Scene Base
#------------------------------------------------------------------------------
# * Requirements :
#
# Scene_Base
#------------------------------------------------------------------------------
# * Description :
#
# This script was designed to allow you to combine items, weapons and armors
# to make new items, weapons and armors. You have the ability to "uncraft"
# items as well, to get all your items back from merging an item together.
#
# As the developer, you can control the words for each group of crafting,
# prices and payoffs for crafting and uncrafting, and the recipes themselves.
#
# You may have more customized shops allowing only 1 or 2 of the crafting
# and / or uncrafing sub-classes (items, weapons and armors). During game
# play, you can give your player "recipes" to unlock the ability to craft
# the item, or give them from the ability from the start.
#------------------------------------------------------------------------------
# * Instructions :
#
# Place The Script Below the SDK and Above Main.
# To Customize your recipes, refer to the customization instructions.
# To allow player to learn recipes, change crafting shop types, refer to
# syntax.
#------------------------------------------------------------------------------
# * Customization :
#
# Setting Up Words (Refer to Crafting::Words)
# - Crafting = 'Craft Word'
# - Uncrafting = 'Uncrafting Word'
# - Item_Crafting = 'Item Crafting Word'
# - Weapon_Crafting = 'Weapon Crafting Word'
# - Armor_Crafting = 'Armor Crafting Word'
# - Item_Uncrafting = 'Item Uncrafting Word'
# - Weapon_Uncrafting = 'Weapon Uncrafting Word'
# - Armor_Uncrafting = 'Armor Uncrafting Word'
#
# Seting Up Prices and Payoffs (Positive = Price ; Negative = Payoff)
# - Crafting_Item_Cost_Payoff = { item_id => n, ... }
# - Crafting_Weapon_Cost_Payoff = { weapon_id => n, ... }
# - Crafting_Armor_Cost_Payoff = { armor_id => n, ... }
# - Uncrafting_Item_Cost_Payoff = { item_id => n, ... }
# - Uncrafting_Weapon_Cost_Payoff = { weapon_id => n, ... }
# - Uncrafting_Armor_Cost_Payoff = { armor_id => n, ... }
#
# Setting Up Recipes (Item Types - 0 : Item ; 1 : Weapon ; 2 : Armor)
# - Item_Recipes = {id => {item type => {type_id => n, ...}, ...}, ...}
# - Weapon_Recipes = {id => {item type => {type_id => n, ...}, ...}, ...}
# - Armor_Recipes = {id => {item type => {type_id => n, ...}, ...}, ...}
#------------------------------------------------------------------------------
# * Syntax :
#
# Opening Crafting Scene
# - $scene = Scene_Crafting.new
#
# Learn Recipes
# - $game_crafting.learn_item_recipe(item_id)
# - $game_crafting.learn_weapon_recipe(weapon_id)
# - $game_crafting.learn_armor_recipe(armor_id)
#
# Forget Recipe (Can also use to hide recipes)
# - $game_crafting.forget_item_recipe(item_id)
# - $game_crafting.forget_weapon_recipe(weapon_id)
# - $game_crafting.forget_armor_recipe(armor_id)
#
# Enabling Item Types (True - Enabled ; False = Disabled)
# (Main Commands)
# - $game_crafting.enable_crafting = true or false
# - $game_crafting.enable_uncrafting = true or false
# (Sub-Crafting Commands)
# - $game_crafting.enable_item_crafting = true or false
# - $game_crafting.enable_weapon_crafting = true or false
# - $game_crafting.enable_armor_crafting = true or false
# (Sub-Uncrafting Commands)
# - $game_crafting.enable_item_crafting = true or false
# - $game_crafting.enable_weapon_crafting = true or false
# - $game_crafting.enable_armor_crafting = true or false
#
# Known Recipes (Returns an array of object ids that can be un/crafted)
# - $game_crafting.item_recipes
# - $game_crafting.weapon_recipes
# - $game_crafting.armor_recipes
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Crafting System', 'SephirothSpawn', 1.1, '2006-10-17')
#------------------------------------------------------------------------------
# * Scene Base Test
#------------------------------------------------------------------------------
unless SDK.state('Scene Base')
# Print Error
p 'Scene Base Not Found. Crafting System Disabled.'
# Disable Encounter Control
SDK.disable('Crafting System')
end
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state('Crafting System')
#==============================================================================
# ** Crafting
#==============================================================================
module Crafting
#==========================================================================
# ** Words
#==========================================================================
module Words
Crafting = 'Craft'
Uncrafting = 'Uncrafting'
Item_Crafting = 'Item Crafting'
Weapon_Crafting = 'Weapon Smithing'
Armor_Crafting = 'Armor Smithing'
Item_Uncrafting = 'Item Uncrafting'
Weapon_Uncrafting = 'Weapon Uncrafting'
Armor_Uncrafting = 'Armor Uncrafting'
end
#--------------------------------------------------------------------------
# * Crafting Prices & Pay Offs
#
# ~ item / weapon / armor id => price / payoff
#
# Positive Values Are Gained, Negative Values Are Lost
# (Positive = Price, Negative = Payoff)
#--------------------------------------------------------------------------
Crafting_Item_Cost_Payoff = {
2 => 500, 3 => 2000, 4 => 5500, 5 => 10000, 6 => 18000, 9 => 750, 10 => 2400,
11 => 6000, 12 => 13000, 14 => 20000, 15 => 20000, 17 => 2500, 18 => 6000,
19 => 8500, 20 => 11500, 21 => 16000, 24 => 10000, 25 => 25000
}
Crafting_Weapon_Cost_Payoff = {
11 => 250, 12 => 800
}
Crafting_Armor_Cost_Payoff = {}
Uncrafting_Item_Cost_Payoff = {}
Uncrafting_Weapon_Cost_Payoff = {}
Uncrafting_Armor_Cost_Payoff = {}
#--------------------------------------------------------------------------
# * Item Types
#
# ~ 0 : Item ; 1 : Weapon ; 2 : Armor
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Item Recipes
#
# ~ product_item = { item_type => { item_id => n, ...}, ... }
#--------------------------------------------------------------------------
Item_Recipes = {
# Renew Potions 2-6
2 => { 0 => { 1 => 3 } },
3 => { 0 => { 1 => 2, 2 => 2 } },
4 => { 0 => { 2 => 4, 3 => 1 } },
5 => { 0 => { 2 => 3, 3 => 3, 4 => 2 } },
6 => { 0 => { 2 => 3, 3 => 3, 4 => 3, 5 => 1 } },
# Phoenix Downs 2-5
9 => { 0 => { 1 => 1, 8 => 3 } },
10 => { 0 => { 8 => 2, 9 => 2 } },
11 => { 0 => { 9 => 3, 10 => 2 } },
12 => { 0 => { 9 => 3, 10 => 3, 11 => 2 } },
# Seeds (Crystal, Burning)
14 => { 0 => { 38 => 25, 39 => 10 } },
15 => { 0 => { 38 => 10, 39 => 25 } },
# Ethers 1-5
17 => { 0 => { 1 => 5, 8 => 1 } },
18 => { 0 => { 2 => 5, 8 => 1 } },
19 => { 0 => { 2 => 5, 9 => 2 } },
20 => { 0 => { 3 => 5, 9 => 2 } },
21 => { 0 => { 3 => 8, 10 => 2 } },
# Tents 2-3
24 => { 0 => { 23 => 2 } },
25 => { 0 => { 23 => 2, 24 => 1 } }
}
#--------------------------------------------------------------------------
# * Weapon Recipes
#
# ~ product_item = { item_type => { item_id => n, ...}, ... }
#--------------------------------------------------------------------------
Weapon_Recipes = {}
#--------------------------------------------------------------------------
# * Armor Recipes
#
# ~ product_item = { item_type => { item_id => n, ...}, ... }
#--------------------------------------------------------------------------
Armor_Recipes = {}
#--------------------------------------------------------------------------
# * Can Craft Item Test
#--------------------------------------------------------------------------
def self.can_craft_item?(item_id)
# If Cost / Payoff Set
if Crafting_Item_Cost_Payoff.has_key?(item_id)
if (cost = Crafting_Item_Cost_Payoff[item_id]) > 0
return false if $game_party.gold < cost
end
end
# Checks For Required Items
if Item_Recipes.has_key?(item_id)
return false unless self.can_craft?(Item_Recipes[item_id])
end
return true
end
#--------------------------------------------------------------------------
# * Can Craft Weapon Test
#--------------------------------------------------------------------------
def self.can_craft_weapon?(weapon_id)
# If Cost / Payoff Set
if Crafting_Weapon_Cost_Payoff.has_key?(weapon_id)
if (cost = Crafting_Weapon_Cost_Payoff[weapon_id]) > 0
return false if $game_party.gold < cost
end
end
# Checks For Required Items
if Weapon_Recipes.has_key?(weapon_id)
return self.can_craft?(Weapon_Recipes[weapon_id])
end
return true
end
#--------------------------------------------------------------------------
# * Can Craft Armor Test
#--------------------------------------------------------------------------
def self.can_craft_armor?(armor_id)
# If Cost / Payoff Set
if Crafting_Armor_Cost_Payoff.has_key?(armor_id)
if (cost = Crafting_Armor_Cost_Payoff[armor_id]) > 0
return false if $game_party.gold < cost
end
end
# Checks For Required Items
if Armor_Recipes.has_key?(armor_id)
return self.can_craft?(Armor_Recipes[armor_id])
end
return true
end
#--------------------------------------------------------------------------
# * Can Craft Test
#--------------------------------------------------------------------------
def self.can_craft?(items_list)
# Test All Item Types
items_list.each do |item_type, item_numbers|
# If Item Type
if item_type == 0
# Test All Item Numbers
item_numbers.each do |item_id, n|
# Return Cannot Craft if Requirement Not Met
return false if $game_party.item_number(item_id) < n
end
end
# If Weapon Type
if item_type == 1
# Test All Item Numbers
item_numbers.each do |weapon_id, n|
# Return Cannot Craft if Requirement Not Met
return false if $game_party.weapon_number(weapon_id) < n
end
end
# If Armor Type
if item_type == 2
# Test All Item Numbers
item_numbers.each do |armor_id, n|
# Return Cannot Craft if Requirement Not Met
return false if $game_party.armor_number(armor_id) < n
end
end
end
# Return Can, if all Requirements Met
return true
end
#--------------------------------------------------------------------------
# * Can Uncraft Item
#--------------------------------------------------------------------------
def self.can_uncraft_item?(item_id)
# Test For Item
return false unless $game_party.item_number(item_id) > 0
# If Cost / Payoff Set
if Uncrafting_Item_Cost_Payoff.has_key?(item_id)
if (cost = Uncrafting_Item_Cost_Payoff[item_id]) > 0
return false if $game_party.gold < cost
end
end
# Return Can
return true
end
#--------------------------------------------------------------------------
# * Can Uncraft Weapon
#--------------------------------------------------------------------------
def self.can_uncraft_weapon?(weapon_id)
# Test For Item
return false unless $game_party.weapon_number(weapon_id) > 0
# If Cost / Payoff Set
if Uncrafting_Weapon_Cost_Payoff.has_key?(weapon_id)
if (cost = Uncrafting_Weapon_Cost_Payoff[weapon_id]) > 0
return false if $game_party.gold < cost
end
end
# Return Can
return true
end
#--------------------------------------------------------------------------
# * Can Uncraft Armor
#--------------------------------------------------------------------------
def self.can_uncraft_armor?(armor_id)
# Test For Item
return false unless $game_party.armor_number(armor_id) > 0
# If Cost / Payoff Set
if Uncrafting_Armor_Cost_Payoff.has_key?(armor_id)
if (cost = Uncrafting_Armor_Cost_Payoff[armor_id]) > 0
return false if $game_party.gold < cost
end
end
# Return Can
return true
end
#--------------------------------------------------------------------------
# * Craft Item
#--------------------------------------------------------------------------
def self.craft_item(item_id)
# If Cost / Payoff Set
if Crafting_Item_Cost_Payoff.has_key?(item_id)
$game_party.lose_gold(Crafting_Item_Cost_Payoff[item_id])
end
# Gain Item
$game_party.gain_item(item_id, 1)
# Use Requirements
if Item_Recipes.has_key?(item_id)
self.use_crafting_items(Item_Recipes[item_id])
end
end
#--------------------------------------------------------------------------
# * Craft Weapon
#--------------------------------------------------------------------------
def self.craft_weapon(weapon_id)
# If Cost / Payoff Set
if Crafting_Weapon_Cost_Payoff.has_key?(weapon_id)
$game_party.lose_gold(Crafting_Weapon_Cost_Payoff[weapon_id])
end
# Gain Weapon
$game_party.gain_weapon(weapon_id, 1)
# Use Requirements
if Weapon_Recipes.has_key?(weapon_id)
self.use_crafting_items(Weapon_Recipes[weapon_id])
end
end
#--------------------------------------------------------------------------
# * Craft Armor
#--------------------------------------------------------------------------
def self.craft_armor(armor_id)
# If Cost / Payoff Set
if Crafting_Armor_Cost_Payoff.has_key?(armor_id)
$game_party.lose_gold(Crafting_Armor_Cost_Payoff[armor_id])
end
# Gain Armor
$game_party.gain_armor(armor_id, 1)
# Use Requirements
if Armor_Recipes.has_key?(armor_id)
self.use_crafting_items(Armor_Recipes[armor_id])
end
end
#--------------------------------------------------------------------------
# * Use Requirements
#--------------------------------------------------------------------------
def self.use_crafting_items(items_list)
# Passes Through All Item Types
items_list.each do |item_type, item_numbers|
# If Item Type
if item_type == 0
# Lose Item Requirements
item_numbers.each { |item_id, n| $game_party.lose_item(item_id, n) }
end
# If Weapon Type
if item_type == 1
# Lose Weapon Requirements
item_numbers.each { |weapon_id, n| $game_party.lose_weapon(
weapon_id, n) }
end
# If Armor Type
if item_type == 2
# Lose Armor Requirements
item_numbers.each { |armor_id, n| $game_party.lose_armor(
armor_id, n) }
end
end
end
#--------------------------------------------------------------------------
# * Craft Item
#--------------------------------------------------------------------------
def self.uncraft_item(item_id)
# If Cost / Payoff Set
if Uncrafting_Item_Cost_Payoff.has_key?(item_id)
$game_party.lose_gold(Uncrafting_Item_Cost_Payoff[item_id])
end
# Lose Item
$game_party.lose_item(item_id, 1)
# Get Requirements
if Item_Recipes.has_key?(item_id)
self.gain_crafting_items(Item_Recipes[item_id])
end
end
#--------------------------------------------------------------------------
# * Craft Weapon
#--------------------------------------------------------------------------
def self.uncraft_weapon(weapon_id)
# If Cost / Payoff Set
if Uncrafting_Weapon_Cost_Payoff.has_key?(weapon_id)
$game_party.lose_gold(Uncrafting_Weapon_Cost_Payoff[weapon_id])
end
# Lose Weapon
$game_party.lose_weapon(weapon_id, 1)
# Get Requirements
if Weapon_Recipes.has_key?(weapon_id)
self.gain_crafting_items(Weapon_Recipes[weapon_id])
end
end
#--------------------------------------------------------------------------
# * Craft Armor
#--------------------------------------------------------------------------
def self.uncraft_armor(armor_id)
# If Cost / Payoff Set
if Uncrafting_Armor_Cost_Payoff.has_key?(armor_id)
$game_party.lose_gold(Uncrafting_Armor_Cost_Payoff[armor_id])
end
# Lose Armor
$game_party.lose_armor(armor_id, 1)
# Get Requirements
if Armor_Recipes.has_key?(armor_id)
self.gain_crafting_items(Armor_Recipes[armor_id])
end
end
#--------------------------------------------------------------------------
# * Gain Crafting Requirements
#--------------------------------------------------------------------------
def self.gain_crafting_items(items_list)
# Passes Through All Item Types
items_list.each do |item_type, item_numbers|
# If Item Type
if item_type == 0
# Gain Item Requirements
item_numbers.each { |item_id, n| $game_party.gain_item(item_id, n) }
end
# If Weapon Type
if item_type == 1
# Gain Weapon Requirements
item_numbers.each { |weapon_id, n| $game_party.gain_weapon(
weapon_id, n) }
end
# If Armor Type
if item_type == 2
# Gain Armor Requirements
item_numbers.each { |armor_id, n| $game_party.gain_armor(
armor_id, n) }
end
end
end
#--------------------------------------------------------------------------
# * Get Requirements
#--------------------------------------------------------------------------
def self.get_item_requirements(item_id)
if Item_Recipes.has_key?(item_id)
return self.get_requirements(Item_Recipes[item_id])
end
return []
end
#--------------------------------------------------------------------------
# * Get Requirements
#--------------------------------------------------------------------------
def self.get_armor_requirements(weapon_id)
if Weapon_Recipes.has_key?(weapon_id)
return self.get_requirements(Weapon_Recipes[item_id])
end
return []
end
#--------------------------------------------------------------------------
# * Get Weapon Requirements
#--------------------------------------------------------------------------
def self.get_weapon_requirements(armor_id)
if Armor_Recipes.has_key?(armor_id)
return self.get_requirements(Armor_Recipes[armor_id])
end
return []
end
#--------------------------------------------------------------------------
# * Get Requirements
#--------------------------------------------------------------------------
def self.get_requirements(item_list)
items = []
item_list.each do |item_type, item_numbers|
if item_type == 0
item_numbers.each do |item_id, n|
items << [$data_items[item_id], n,
$game_party.item_number(item_id)]
end
end
if item_type == 1
item_numbers.each do |weapon_id, n|
items << [$data_weapons[weapon_id], n,
$game_party.weapon_number(weapon_id)]
end
end
if item_type == 2
item_numbers.each do |armor_id, n|
items << [$data_armors[armor_id], n,
$game_party.armor_number(armor_id)]
end
end
end
return items
end
end
#==============================================================================
# ** Game_Crafting
#==============================================================================
class Game_Crafting
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :item_recipes
attr_reader :weapon_recipes
attr_reader :armor_recipes
attr_accessor :enable_crafting
attr_accessor :enable_item_crafting
attr_accessor :enable_weapon_crafting
attr_accessor :enable_armor_crafting
attr_accessor :enable_uncrafting
attr_accessor :enable_item_uncrafting
attr_accessor :enable_weapon_uncrafting
attr_accessor :enable_armor_uncrafting
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Sets Up Recipe List
@item_recipes, @weapon_recipes, @armor_recipes = [], [], []
# Sets Up Crafting Shop Commands
@enable_crafting = true
@enable_item_crafting = true
@enable_weapon_crafting = true
@enable_armor_crafting = true
@enable_uncrafting = true
@enable_item_uncrafting = true
@enable_weapon_uncrafting = true
@enable_armor_uncrafting = true
end
#--------------------------------------------------------------------------
# * Learn Item Recipe
#--------------------------------------------------------------------------
def learn_item_recipe(item_id)
if Crafting::Item_Recipes.has_key?(item_id)
@item_recipes << item_id unless @item_recipes.include?(item_id)
end
end
#--------------------------------------------------------------------------
# * Forget Item Recipe
#--------------------------------------------------------------------------
def forget_item_recipe(item_id)
if @item_recipes.has_key?(item_id)
@item_recipes.delete(item_id)
end
end
#--------------------------------------------------------------------------
# * Learn Weapon Recipe
#--------------------------------------------------------------------------
def learn_weapon_recipe(weapon_id)
if Crafting::Weapon_Recipes.has_key?(weapon_id)
@weapon_recipes << weapon_id unless @weapon_recipes.include?(weapon_id)
end
end
#--------------------------------------------------------------------------
# * Forget Weapon Recipe
#--------------------------------------------------------------------------
def forget_weapon_recipe(weapon_id)
if @weapon_recipes.has_key?(weapon_id)
@weapon_recipes.delete(weapon_id)
end
end
#--------------------------------------------------------------------------
# * Learn Armor Recipe
#--------------------------------------------------------------------------
def learn_armor_recipe(armor_id)
if Crafting::Armor_Recipes.has_key?(armor_id)
@armor_recipes << armor_id unless @armor_recipes.include?(armor_id)
end
end
#--------------------------------------------------------------------------
# * Forget Armor Recipe
#--------------------------------------------------------------------------
def forget_armor_recipe(armor_id)
if @armor_recipes.has_key?(armor_id)
@armor_recipes.delete(armor_id)
end
end
#--------------------------------------------------------------------------
# * Main Crafting Commands
#--------------------------------------------------------------------------
def main_commands
commands = []
commands << Crafting::Words::Crafting if @enable_crafting
commands << Crafting::Words::Uncrafting if @enable_uncrafting
commands << 'Exit'
return commands
end
#--------------------------------------------------------------------------
# * Crafting Commands
#--------------------------------------------------------------------------
def crafting_commands
commands = []
commands << Crafting::Words::Item_Crafting if @enable_item_crafting
commands << Crafting::Words::Weapon_Crafting if @enable_weapon_crafting
commands << Crafting::Words::Armor_Crafting if @enable_armor_crafting
commands << 'Back'
return commands
end
#--------------------------------------------------------------------------
# * Unrafting Commands
#--------------------------------------------------------------------------
def uncrafting_commands
commands = []
commands << Crafting::Words::Item_Uncrafting if @enable_item_uncrafting
commands << Crafting::Words::Weapon_Uncrafting if @enable_weapon_uncrafting
commands << Crafting::Words::Armor_Uncrafting if @enable_armor_uncrafting
commands << 'Back'
return commands
end
end
#==============================================================================
# ** Window_CraftRecipe
#==============================================================================
class Window_CraftRecipe < Window_Selectable
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :item_type
attr_reader :crafting
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(- 240, 96, 240, 32)
self.active = false
end
#--------------------------------------------------------------------------
# * Item ID
#--------------------------------------------------------------------------
def item_id
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh(item_type, crafting = true)
# Deletes Window Contents if Present
unless self.contents.nil?
self.contents.dispose
end
# Stores Item Type and Crafting Flag
@item_type, @crafting = item_type, crafting
# Branch Point By Item Type
case item_type
when 0 # Items
@data = $game_crafting.item_recipes.dup
when 1 # Weapons
@data = $game_crafting.weapon_recipes.dup
when 2 # Armors
@data = $game_crafting.armor_recipes.dup
end
# Sets Item Max
@item_max = @data.size + 1
# Resets Window Height
self.height = [@item_max * 32 + 32, 352].min
# Sets Up Window Contents and Draws Data
self.contents = Bitmap.new(width - 32, @item_max * 32)
for i in 0...@data.size
draw_item(i)
end
# Draws Back Text
self.contents.font.color = system_color
self.contents.draw_text(0, @item_max * 32 - 32, contents.width, 32,
'Back', 1)
# Resets Index
self.index = 0
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
# Collects Item ID
item_id = @data[index]
# Branch Point By Item Type
case @item_type
when 0 # Items
# Sets Font Color Depending On Ability to Craft
if @crafting
if Crafting.can_craft_item?(item_id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
else
if Crafting.can_uncraft_item?(item_id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
end
# Collects Item Info
item = $data_items[item_id]
n = $game_party.item_number(item_id)
when 1 # Weapons
# Sets Font Color Depending On Ability to Craft
if @crafting
if Crafting.can_craft_weapon?(item_id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
else
if Crafting.can_craft_weapon?(item_id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
end
# Collects Item Info
item = $data_weapons[item_id]
n = $game_party.weapon_number(item_id)
when 2 # Armors
# Sets Font Color Depending On Ability to Craft
if @crafting
if Crafting.can_craft_armor?(item_id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
else
if Crafting.can_uncraft_armor?(item_id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
end
# Collects Item Info
item = $data_armors[item_id]
n = $game_party.armor_number(item_id)
end
# Draws Icon
icon = RPG::Cache.icon(item.icon_name)
self.contents.blt(4, index * 32 + 4, icon,
Rect.new(0, 0, 24, 24), self.contents.font.color.alpha)
# Draws Item Name
self.contents.draw_text(32, index * 32, contents.width - 32, 32,
item.name)
# Draws Number Owned
self.contents.draw_text(- 4, index * 32, contents.width, 32, n.to_s, 2)
end
end
#==============================================================================
# ** Window_CraftRequirements
#==============================================================================
class Window_CraftRequirements < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(640, 96, 352, 352)
self.contents = Bitmap.new(width - 32, height - 32)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh(item_type, item_id, crafting = true)
self.contents.clear
if item_id.nil?
self.contents.font.color = system_color
self.contents.draw_text(0, 0, contents.width, 24, 'Back', 1)
return
end
# Collects Item Data
item = item_type == 0 ? $data_items[item_id] : item_type == 1 ?
$data_weapons[item_id] : $data_armors[item_id]
item_type_name = item_type == 0 ? 'Item' : item_type == 1 ?
'Weapon' : 'Armor'
# Draws Item Name and Description
self.contents.font.color = normal_color
icon = RPG::Cache.icon(item.icon_name)
self.contents.blt(4, 4, icon, Rect.new(0, 0, 24, 24))
self.contents.draw_text(28, 4, contents.width - 28, 24, item.name)
self.contents.draw_text(4, 32, contents.width - 4, 24, item.description)
# Draws Cost and Payoff
self.contents.font.color = system_color
self.contents.draw_text(8, 56, contents.width - 8, 24, 'Cost:')
self.contents.draw_text(8, 80, contents.width - 8, 24, 'Payoff:')
self.contents.font.color = normal_color
cost = nil
payoff = nil
case item_type
when 0
if crafting
if Crafting::Crafting_Item_Cost_Payoff.has_key?(item_id)
if (n = Crafting::Crafting_Item_Cost_Payoff[item_id]) > 0
cost, payoff = n, 0
else
cost, payoff = 0, n
end
end
else
if Crafting::Uncrafting_Item_Cost_Payoff.has_key?(item_id)
if (n = Crafting::Uncrafting_Item_Cost_Payoff[item_id]) > 0
cost, payoff = n, 0
else
cost, payoff = 0, n
end
end
end
when 1
if crafting
if Crafting::Crafting_Weapon_Cost_Payoff.has_key?(item_id)
if (n = Crafting::Crafting_Weapon_Cost_Payoff[item_id]) > 0
cost, payoff = n, 0
else
cost, payoff = 0, n
end
end
else
if Crafting::Uncrafting_Weapon_Cost_Payoff.has_key?(item_id)
if (n = Crafting::Uncrafting_Weapon_Cost_Payoff[item_id]) > 0
cost, payoff = n, 0
else
cost, payoff = 0, n
end
end
end
when 2
if crafting
if Crafting::Crafting_Armor_Cost_Payoff.has_key?(item_id)
if (n = Crafting::Crafting_Armor_Cost_Payoff[item_id]) > 0
cost, payoff = n, 0
else
cost, payoff = 0, n
end
end
else
if Crafting::Uncrafting_Armor_Cost_Payoff.has_key?(item_id)
if (n = Crafting::Uncrafting_Armor_Cost_Payoff[item_id]) > 0
cost, payoff = n, 0
else
cost, payoff = 0, n
end
end
end
end
self.contents.draw_text(-8, 56, contents.width, 24,
(cost.nil? ? 'Free' : cost.to_s), 2)
self.contents.draw_text(-8, 80, contents.width, 24,
(payoff.nil? ? 'None' : payoff.to_s), 2)
# Draws Requirements or Items Given Off
self.contents.font.color = system_color
self.contents.draw_text(0, 104, contents.width, 24, 'Items ' +
(crafting ? 'Required' : 'Given Off'), 1)
self.contents.font.color = normal_color
# Collects Recipe Items
items = item_type == 0 ? Crafting.get_item_requirements(item_id) :
item_type == 1 ? Crafting.get_weapon_requirements(item_id) :
Crafting.get_armor_requirements(item_id)
# Draws All Item Requirements
if items.empty?
self.contents.draw_text(4, 128, contents.width, 24, 'None')
return
end
# Draws Each Item Data
for i in 0...items.size
x = i % 2 * contents.width / 2 + 4
y = i / 2 * 24 + 128
item_data = items[i]
icon = RPG::Cache.icon(item_data[0].icon_name)
self.contents.font.color = item_data[2] >= item_data[1] ?
normal_color : disabled_color
self.contents.blt(x + 4, y, icon, Rect.new(0, 0, 24, 24),
contents.font.color.alpha)
self.contents.draw_text(x + 32, y, contents.width / 2 - 84, 24,
item_data[0].name)
self.contents.draw_text(x + contents.width / 2 - 52, y, 48, 24,
"#{item_data[2]} / #{item_data[1]}", 2)
end
end
end
#==============================================================================
# ** Scene_Crafting
#==============================================================================
class Scene_Crafting < Scene_Base
#--------------------------------------------------------------------------
# * Main Processing : Spriteset Initialization
#--------------------------------------------------------------------------
def main_spriteset
# Sets Up Spriteset
@spriteset = Spriteset_Map.new
end
#--------------------------------------------------------------------------
# * Main Processing : Window Initialization
#--------------------------------------------------------------------------
def main_window
# Sets Up Help Window
@help_window = Window_Help.new
@help_window.width = 608
@help_window.contents = Bitmap.new(576, 32)
@help_window.set_text('Welcome. What would you like to do?', 1)
@help_window.x = 16
@help_window.y = - 64
# Sets Up Main Command
@main_command = Window_Command.new(240, $game_crafting.main_commands)
@main_command.x = - 240
@main_command.y = 96
# Sets Up Crafting Command
@craft_command = Window_Command.new(240, $game_crafting.crafting_commands)
@craft_command.x = - 240
@craft_command.y = 96
@craft_command.active = false
# Sets Up Reverse Crafting Command
@uncraft_command = Window_Command.new(240,
$game_crafting.uncrafting_commands)
@uncraft_command.x = - 240
@uncraft_command.y = 96
@uncraft_command.active = false
# Sets Up Blank Recipe List Window
@recipe_list = Window_CraftRecipe.new
# Sets Up Crafting Requirements Window
@crafting_requirements = Window_CraftRequirements.new
# Sets Up Confirmation Command
@confirmation_command = Window_Command.new(160, ['Yes', 'No'])
@confirmation_command.x = 240
@confirmation_command.y = 192
@confirmation_command.z = 250
@confirmation_command.visible = @confirmation_command.active = false
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update Map
$game_map.update
$game_system.map_interpreter.update
$game_screen.update
$game_system.update
# Branch Scene Update
if @main_command.active
update_main_command
elsif @craft_command.active
update_craft_command
elsif @uncraft_command.active
update_uncraft_command
elsif @recipe_list.active
update_recipe_list
elsif @confirmation_command.active
update_confirmation_command
else
update_exit
end
end
#--------------------------------------------------------------------------
# * Frame Update : Main Command
#--------------------------------------------------------------------------
def update_main_command
# Move Windows
@help_window.y += 10 if @help_window.y < 16
@main_command.x += 32 if @main_command.x < 16
@craft_command.x -= 32 if @craft_command.x > - 240
@uncraft_command.x -= 32 if @uncraft_command.x > - 240
@recipe_list.x -= 32 if @recipe_list.x > - 240
@crafting_requirements.x += 46 if @crafting_requirements.x < 640
# If B Button is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turn Off Main Command
@main_command.active = false
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Turn Off Main Command
@main_command.active = false
# Collects Command
c = $game_crafting.main_commands[@main_command.index]
# Sets Help Text
unless c == 'Back'
@help_window.set_text("What would you like to #{c}?", 1)
end
# If Craft command
if c == Crafting::Words::Crafting
# Turn On Crafting Window
@craft_command.active = true
return
end
# If Uncraft command
if c == Crafting::Words::Uncrafting
# Turn On Uncrafting Window
@uncraft_command.active = true
return
end
end
end
#--------------------------------------------------------------------------
# * Frame Update : Craft Command
#--------------------------------------------------------------------------
def update_craft_command
# Move Windows
@help_window.y += 10 if @help_window.y < 16
@main_command.x -= 32 if @main_command.x > - 240
@craft_command.x += 32 if @craft_command.x < 16
@uncraft_command.x -= 32 if @uncraft_command.x > - 240
@recipe_list.x -= 32 if @recipe_list.x > - 240
@crafting_requirements.x += 46 if @crafting_requirements.x < 640
# If B Button is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turns off Craft Command
@craft_command.active = false
# Turn On Main Command
@main_command.active = true
# Sets Help Text
@help_window.set_text('Welcome. What would you like to do?', 1)
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Turn Off Craft Command
@craft_command.active = false
# Brach Point By Command
case c = $game_crafting.crafting_commands[@craft_command.index]
when 'Back'
# Turn Main Command One
@main_command.active = true
return
when Crafting::Words::Item_Crafting
item_type = 0
when Crafting::Words::Weapon_Crafting
item_type = 1
when Crafting::Words::Armor_Crafting
item_type = 2
end
# Refresh Recipe List
@recipe_list.refresh(item_type)
# Turns On Recipe List
@recipe_list.active = true
# Refresh Crafing Requirements
@crafting_requirements.refresh(@recipe_list.item_type,
@recipe_list.item_id, @recipe_list.crafting)
# Sets Help Text
@help_window.set_text("What would you like to #{c}?", 1)
end
end
#--------------------------------------------------------------------------
# * Frame Update : Uncraft Command
#--------------------------------------------------------------------------
def update_uncraft_command
# Move Windows
@help_window.y += 10 if @help_window.y < 16
@main_command.x -= 32 if @main_command.x > - 240
@craft_command.x -= 32 if @craft_command.x > - 240
@uncraft_command.x += 32 if @uncraft_command.x < 16
@recipe_list.x -= 32 if @recipe_list.x > - 240
@crafting_requirements.x += 46 if @crafting_requirements.x < 640
# If B Button is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turns off Uncraft Command
@uncraft_command.active = false
# Turn On Main Command
@main_command.active = true
# Sets Help Text
@help_window.set_text('Welcome. What would you like to do?', 1)
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Turn Off Unraft Command
@uncraft_command.active = false
# Brach Point By Command
case c = $game_crafting.uncrafting_commands[@uncraft_command.index]
when 'Back'
# Turn Main Command One
@main_command.active = true
return
when Crafting::Words::Item_Uncrafting
item_type = 0
when Crafting::Words::Weapon_Uncrafting
item_type = 1
when Crafting::Words::Armor_Uncrafting
item_type = 2
end
# Refresh Recipe List
@recipe_list.refresh(item_type, false)
# Turns On Recipe List
@recipe_list.active = true
# Refresh Crafing Requirements
@crafting_requirements.refresh(@recipe_list.item_type,
@recipe_list.item_id, @recipe_list.crafting)
# Sets Help Text
@help_window.set_text("What would you like to #{c}?", 1)
end
end
#--------------------------------------------------------------------------
# * Frame Update : Recipe List
#--------------------------------------------------------------------------
def update_recipe_list
# Move Windows
@help_window.y += 10 if @help_window.y < 16
@main_command.x -= 32 if @main_command.x > - 240
@craft_command.x -= 32 if @craft_command.x > - 240
@uncraft_command.x -= 32 if @uncraft_command.x > - 240
@recipe_list.x += 32 if @recipe_list.x < 16
@crafting_requirements.x -= 46 if @crafting_requirements.x > 272
# If Up or Down is Pressed
if Input.repeat?(Input::DOWN) || Input.repeat?(Input::UP)
# Refresh Crafing Requirements
@crafting_requirements.refresh(@recipe_list.item_type,
@recipe_list.item_id, @recipe_list.crafting)
end
# If B Button is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turns off Recipe Command
@recipe_list.active = false
# Turn On Last Active Command
@recipe_list.crafting ? @craft_command.active = true :
@uncraft_command.active = true
c = @recipe_list.crafting ? Crafting::Words::Crafting :
Crafting::Words::Uncrafting
# Sets Help Text
@help_window.set_text("What would you like to #{c}?", 1)
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# If Back
if @recipe_list.item_id.nil?
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Turns off Recipe Command
@recipe_list.active = false
# Turn On Last Active Command
@recipe_list.crafting ? @craft_command.active = true :
@uncraft_command.active = true
return
end
# If Crafting
if @recipe_list.crafting
# Branch Point By Item Type (Test For Can Craft)
case @recipe_list.item_type
when 0 # Items
cc = Crafting.can_craft_item?(@recipe_list.item_id)
when 1 # Weapons
cc = Crafting.can_craft_weapon?(@recipe_list.item_id)
when 2 # Armors
cc = Crafting.can_craft_armor?(@recipe_list.item_id)
end
# If Uncrafting
else
# Branch Point By Item Type
case @recipe_list.item_type
when 0 # Items
cc = Crafting.can_uncraft_item?(@recipe_list.item_id)
when 1 # Weapons
cc = Crafting.can_uncraft_weapon?(@recipe_list.item_id)
when 2 # Armors
cc = Crafting.can_uncraft_armor?(@recipe_list.item_id)
end
end
# If Cannot Craft
unless cc
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
# If Crafting
if @recipe_list.crafting
# Sets Help Window
@help_window.set_text('This Item Cannot be ' +
Crafting::Words::Crafting, 1)
# If Uncrafting
else
# Sets Help Window
@help_window.set_text('This Item Cannot be ' +
Crafting::Words::Uncrafting, 1)
end
return
end
# Turn Off Recipe List Window
@recipe_list.active = false
# Turn on Confirmation Window
@confirmation_command.visible = @confirmation_command.active = true
@confirmation_command.index = 0
# Set Help Text
@help_window.set_text('Are You Sure?', 1)
return
end
end
#--------------------------------------------------------------------------
# * Frame Update : Confirmation
#--------------------------------------------------------------------------
def update_confirmation_command
# Move Windows
@help_window.y += 10 if @help_window.y < 16
@main_command.x -= 32 if @main_command.x > - 240
@craft_command.x -= 32 if @craft_command.x > - 240
@uncraft_command.x -= 32 if @uncraft_command.x > - 240
@recipe_list.x += 32 if @recipe_list.x < 16
@crafting_requirements.x -= 46 if @crafting_requirements.x > 272
# If B Button is Pressed or No is Selected
if Input.trigger?(Input::B) || Input.trigger?(Input::C) &&
@confirmation_command.index == 1
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turns Off Confirmation Command
@confirmation_command.visible = @confirmation_command.active = false
# Turns On Recipe Command
@recipe_list.active = true
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# If Crafting Item
if @recipe_list.crafting
# Branch Point By Item Type
case @recipe_list.item_type
when 0 # Items
cc = Crafting.craft_item(@recipe_list.item_id)
when 1 # Weapons
cc = Crafting.craft_weapon(@recipe_list.item_id)
when 2 # Armors
cc = Crafting.craft_armor(@recipe_list.item_id)
end
# If Uncrating
else
# Branch Point By Item Type
case @recipe_list.item_type
when 0 # Items
cc = Crafting.uncraft_item(@recipe_list.item_id)
when 1 # Weapons
cc = Crafting.uncraft_weapon(@recipe_list.item_id)
when 2 # Armors
cc = Crafting.uncraft_armor(@recipe_list.item_id)
end
end
# Refresh Recipe List Window
@recipe_list.refresh(@recipe_list.item_type, @recipe_list.crafting)
# Refresh Crafing Requirements
@crafting_requirements.refresh(@recipe_list.item_type,
@recipe_list.item_id, @recipe_list.crafting)
# Turns Off Confirmation Command
@confirmation_command.visible = @confirmation_command.active = false
# Turns On Recipe Command
@recipe_list.active = true
# Set Help Text
case @recipe_list.item_type
when 0 ; text = 'Item'
when 1 ; text = 'Weapon'
when 2 ; text = 'Armor'
end
text += ' Successfully '
text += (@recipe_list.crafting ? Crafting::Words::Crafting :
Crafting::Words::Uncrafting)
@help_window.set_text(text, 1)
return
end
end
#--------------------------------------------------------------------------
# * Frame Update : Exit
#--------------------------------------------------------------------------
def update_exit
# Fade Out All Windows
@help_window.y -= 10 if @help_window.y > - 64
@main_command.x -= 32 if @main_command.x > - 240
@craft_command.x -= 32 if @craft_command.x > - 240
@uncraft_command.x -= 32 if @uncraft_command.x > - 240
@recipe_list.x -= 32 if @recipe_list.x > - 240
@crafting_requirements.x += 46 if @crafting_requirements.x < 640
# If Windows Finished Moving
if @help_window.y == - 64
# Switch to Map
$scene = Scene_Map.new
end
end
end
#==============================================================================
# ** Scene_Title
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_crafting_scnttl_cng command_new_game
#--------------------------------------------------------------------------
# * Command : New Game
#--------------------------------------------------------------------------
def command_new_game
# Original Command New Game
seph_crafting_scnttl_cng
# Creates Crafting Game Data
$game_crafting = Game_Crafting.new
end
end
#==============================================================================
# ** Scene_Save
#==============================================================================
class Scene_Save
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_crafting_scnsave_wd write_data
#--------------------------------------------------------------------------
# * Command : New Game
#--------------------------------------------------------------------------
def write_data(file)
# Original Write Data
seph_crafting_scnsave_wd(file)
# Saves Crafting Data
Marshal.dump($game_crafting, file)
end
end
#==============================================================================
# ** Scene_Load
#==============================================================================
class Scene_Load
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_crafting_scnload_rd read_data
#--------------------------------------------------------------------------
# * Command : New Game
#--------------------------------------------------------------------------
def read_data(file)
# Original Write Data
seph_crafting_scnload_rd(file)
# Loads Crafting Data
$game_crafting = Marshal.load(file)
end
end
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end