#=begin
#===============================================================================
# SeM's Final Fantasy IX Synthesis VXA
#
# - v1.1
# By SeMcDun
# Last Update: 05/02/2013
#===============================================================================
# Description;
# A simple crafting script.
#
# How to use;
# Set up a shop variable in the SYNTHESIS module below and fill it with
# objects you want to synth.
# Make sure any objects you include have the necessary synth tags.
# Set your chosen variable to the number of shop you want to use.
# Call the Synthesis scene.
#
#===============================================================================
# Version History;
#
# v1.0
# 2013.01.27 - Completed
#
# v1.1
# 2013.02.05 - Compatibility Update
# Changed variable names
#
#===============================================================================
# Installation;
# -- Paste above Main and below Materials.
#===============================================================================
# Note:
#
#===============================================================================
# Script Calls
#-------------------------------------------------------------------------------
#
#===============================================================================
# Weapon Notetags
#-------------------------------------------------------------------------------
# <synth xy>
# x - Either W, A or I. Weapon Armour or Item
# y - Index of the item.
#
# <synth_cost x>
# x - Gold cost to synth the item.
#
#===============================================================================
# Armour Notetags
#-------------------------------------------------------------------------------
# <synth xy>
# x - Either W, A or I. Weapon Armour or Item
# y - Index of the item.
#
# <synth_cost x>
# x - Gold cost to synth the item.
#
#===============================================================================
# Item Notetags
#-------------------------------------------------------------------------------
# <synth xy>
# x - Either W, A or I. Weapon Armour or Item
# y - Index of the item.
#
# <synth_cost x>
# x - Gold cost to synth the item.
#
#===============================================================================
$imported = {} if $imported.nil?
$imported["SEM-Synthesis"] = true
#===============================================================================
# ■ SEM::SYNTHESIS
#===============================================================================
module SEM
module SYNTHESIS
# Set up shops here
SHOP = []
SHOP[1] = [
["W" , 2],
["I" , 40],
["A", 3],
["I", 2],
["W", 1],
["W", 51],
["I" , 4],
["I" , 5]
]
SHOP[2] = [
["I", 2]
]
# Variable of the shop
SHOP_VARIABLE = 1
# Attack Increase icon
ATTACK_ICON = 131
# Defense Increase icon
DEFENSE_ICON = 139
end
module VOCAB
SYNTHESIS = "Créer objet"
SYNTH_PRICE = "Prix"
SYNTH_FUNDS = "Coût:"
SYNTH_STOCK = "Stock:"
SYNTH_EQUIPPED = "Equipé:"
SYNTH_REQUIRED = "Besoin d'objet:"
SYNTH_ITEM = "Objet"
EXIT_SYNTH = "Sortir"
# When an item is already equipped by an actor
SYNTH_CURRENTLY_EQUIPPED = "Equipé"
end
module REGEXP
module WEAPON
SYNTH = /<(?:SYNTH|synth)[ ]([IWA])(\d+)>/i
SYNTH_COST = /<(?:SYNTH_COST|synth_cost)[ ](\d+)>/i
end
module ARMOUR
SYNTH = /<(?:SYNTH|synth)[ ]([IWA])(\d+)>/i
SYNTH_COST = /<(?:SYNTH_COST|synth_cost)[ ](\d+)>/i
end
module ITEM
SYNTH = /<(?:SYNTH|synth)[ ]([IWA])(\d+)>/i
SYNTH_COST = /<(?:SYNTH_COST|synth_cost)[ ](\d+)>/i
end
end
end
#==============================================================================
# ■ DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias load_database_ssy load_database; end
def self.load_database
load_database_ssy
load_notetags_ssy
end
#--------------------------------------------------------------------------
# new method: load_notetags_ssy
#--------------------------------------------------------------------------
def self.load_notetags_ssy
for weapon in $data_weapons
next if weapon.nil?
weapon.load_weapon_notetags_ssy
end
for armor in $data_armors
next if armor.nil?
armor.load_armor_notetags_ssy
end
for item in $data_items
next if item.nil?
item.load_item_notetags_ssy
end
end
end # DataManager
#==============================================================================
# ■ RPG::Weapon
#==============================================================================
class RPG::Weapon < RPG::EquipItem
attr_accessor :synth_materials
attr_accessor :synth_cost
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
def load_weapon_notetags_ssy
@synth_materials = []
@synth_cost = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
when SEM::REGEXP::WEAPON::SYNTH
itype = $1.to_s
index = $2.to_i
@synth_materials.push(RPG::Weapon::Material.new(itype, index))
when SEM::REGEXP::WEAPON::SYNTH_COST
@synth_cost = $1.to_i
end
}
end
end
#==============================================================================
# ■ RPG::Weapon::Material
#==============================================================================
class RPG::Weapon::Material
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_reader :itype
attr_reader :index
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(itype, index)
@itype = itype
@index = index
end
end # RPG::Weapon::Material
#==============================================================================
# ■ RPG::Armor
#==============================================================================
class RPG::Armor < RPG::EquipItem
attr_accessor :synth_materials
attr_accessor :synth_cost
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
def load_armor_notetags_ssy
@synth_materials = []
@synth_cost = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
when SEM::REGEXP::ARMOUR::SYNTH
itype = $1.to_s
index = $2.to_i
@synth_materials.push(RPG::Armor::Material.new(itype, index))
when SEM::REGEXP::ARMOUR::SYNTH_COST
@synth_cost = $1.to_i
end
}
end
end
#==============================================================================
# ■ RPG::Armor::Material
#==============================================================================
class RPG::Armor::Material
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_reader :itype
attr_reader :index
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(itype, index)
@itype = itype
@index = index
end
end # RPG::Armor::Material
#==============================================================================
# ■ RPG::Item
#==============================================================================
class RPG::Item < RPG::UsableItem
attr_accessor :synth_materials
attr_accessor :synth_cost
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
def load_item_notetags_ssy
@synth_materials = []
@synth_cost = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
when SEM::REGEXP::ITEM::SYNTH
itype = $1.to_s
index = $2.to_i
@synth_materials.push(RPG::Item::Material.new(itype, index))
when SEM::REGEXP::ITEM::SYNTH_COST
@synth_cost = $1.to_i
end
}
end
end
#==============================================================================
# ■ RPG::Item::Material
#==============================================================================
class RPG::Item::Material
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_reader :itype
attr_reader :index
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(itype, index)
@itype = itype
@index = index
end
end # RPG::Item::Material
#===============================================================================
# * Scene_Synthesis
#===============================================================================
class Scene_Synthesis < Scene_Base
attr_accessor :item_window
def start
create_main_viewport
create_items_window
create_info_window
create_actor_window
create_title_window
create_command_window
#@item_window.hide
#@info_window.hide
#@actor_window.hide
#@title_window.hide
@command_window.open
@command_window.activate
@command_window.select(0)
end
def create_command_window
x = (Graphics.width / 2) - 80
y = (Graphics.height / 2) - 38
@command_window = Window_SynthIntro.new(x, y)
@command_window.viewport = Viewport.new
@command_window.viewport.z += 500
@command_window.back_opacity = 255
@command_window.set_handler(:synth, method(:on_intro_ok))
@command_window.set_handler(:exit, method(:on_intro_cancel))
@command_window.set_handler(:cancel, method(:on_intro_cancel))
@command_window.refresh
end
def on_intro_ok
#@item_window.show
#@info_window.show
#@actor_window.show
#@title_window.show
@item_window.activate
@item_window.select(0)
@command_window.close
end
def on_intro_cancel
return_scene
end
def create_title_window
@title_window = Window_ItemTitle.new(0, 0, 300, 48)
end
def create_items_window
@item_window = Window_SynthItems.new(0, 48, 300, Graphics.height - 96 - 32 - 48 - 32)
@item_window.set_handler(:ok, method(:on_item_ok))
@item_window.set_handler(:cancel, method(:on_item_cancel))
@item_window.refresh
end
def on_item_ok
# Because it is active;
# The player HAS enough money
# The player HAS enough of the required items
# Remove the gold
$game_party.lose_gold(@item_window.item.synth_cost)
# Remove the items required
@item_window.item.synth_materials.each do |remove_item|
case remove_item.itype
when "W"
item_name = $data_weapons[remove_item.index]
when "A"
item_name = $data_armors[remove_item.index]
when "I"
item_name = $data_items[remove_item.index]
end
$game_party.lose_item(item_name, 1)
# Removed the gold cost AND removed the items required...
# Add the created item
end
$game_party.gain_item(@item_window.item, 1)
@item_window.refresh
@info_window.refresh(@item_window.item)
@item_window.activate
end
def on_item_cancel
@command_window.open
@command_window.activate
@command_window.select(0)
@item_window.unselect
end
def create_info_window
@info_window = Window_SynthInfo.new(300, 0, 244, Graphics.height - 96 - 32 - 32)
@info_window.refresh(nil)
end
def create_actor_window
@actor_window = Window_SynthActors.new(0, Graphics.height - 96 - 32 - 32, Graphics.width, 96 + 32 + 32)
@actor_window.refresh(nil)
end
alias scene_synthesis_update_ssy update
def update
scene_synthesis_update_ssy
if @this_item != @item_window.item
@this_item = @item_window.item
@item_window.refresh
@info_window.refresh(@item_window.item)
@actor_window.refresh(@item_window.item)
end
end
end
#===============================================================================
# * Window_SynthItems
#===============================================================================
class Window_SynthItems < Window_ItemList
attr_accessor :data
#--------------------------------------------------------------------------
# * Get Digit Count
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# * Display in Enabled State?
#--------------------------------------------------------------------------
def enable?(item)
@got_items = []
# Check if they player has enough money to buy the item
if $game_party.gold >= item.synth_cost
# Get first item
item.synth_materials.each do |mat|
case mat.itype
when "W"
item_name = $data_weapons[mat.index]
when "A"
item_name = $data_armors[mat.index]
when "I"
item_name = $data_items[mat.index]
end
# Got the material... now loop through all items
$game_party.all_items.each do |party_item|
if item_name == party_item
@got_items.push(item_name)
$game_party.lose_item(item_name, 1)
end
end
end
if @got_items.size == item.synth_materials.size
# Same number was found
# True, but return each of the items in got_items
@got_items.each do |return_item|
$game_party.gain_item(return_item, 1)
end
return true
else
@got_items.each do |return_item|
$game_party.gain_item(return_item, 1)
end
return false
end
else
false
end
end
#--------------------------------------------------------------------------
# * Create Item List
#--------------------------------------------------------------------------
def make_item_list
@data = []
# Fill the list with items from the synth shop.
SEM::SYNTHESIS::SHOP[$game_variables[SEM::SYNTHESIS::SHOP_VARIABLE]].each do |item|
# Each item, add it to the data list
case item[0]
when "W"
@data.push($data_weapons[item[1]])
when "A"
@data.push($data_armors[item[1]])
when "I"
@data.push($data_items[item[1]])
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
if item
rect = item_rect(index)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enable?(item))
draw_item_price(rect, item)
end
end
def draw_item_price(rect, item)
draw_text(rect.x, rect.y, rect.width, line_height, item.synth_cost, 2)
end
end
#===============================================================================
# * Window_SynthInfo
#===============================================================================
class Window_SynthInfo < Window_Base
alias window_synthinfo_init_ssy initialize
def initialize(x, y, ww, wh)
window_synthinfo_init_ssy(x, y, ww, wh)
refresh(nil)
end
def refresh(item)
contents.clear
change_color(normal_color)
draw_text(4, 24 * 0, 120, 24, "#{SEM::VOCAB::SYNTH_FUNDS}")
draw_currency_value(value, currency_unit, 8, line_height * 0, contents.width - 8)
change_color(normal_color)
draw_text(4, 24 * 1 + 8, 120, 24, "#{SEM::VOCAB::SYNTH_STOCK}")
draw_text(4, 24 * 1 + 8, 204, 24, $game_party.item_number(item), 2)
draw_text(4, 24 * 2 + 16, 120, 24, "#{SEM::VOCAB::SYNTH_EQUIPPED}")
# Loop through all equipped items
# Any time "item" is found, +1
@equipped_items = 0
$game_party.members.each do |member|
member.equips.each do |equips|
if item
if equips == item
# Item is the same, add 1
@equipped_items += 1
end
end
end
end
draw_text(4, 24 * 2 + 16, 204, 24, @equipped_items, 2)
draw_horz_line(24 * 3 + 24)
contents.font.size -= 4
draw_text(4, 24 * 5, 180, 24, "#{SEM::VOCAB::SYNTH_REQUIRED}")
contents.font.size += 4
@got_items = []
if item
counter = 0
item.synth_materials.each do |mat|
case mat.itype
when "W"
item_name = $data_weapons[mat.index]
icon = $data_weapons[mat.index].icon_index
when "A"
item_name = $data_armors[mat.index]
icon = $data_armors[mat.index].icon_index
when "I"
item_name = $data_items[mat.index]
icon = $data_items[mat.index].icon_index
end
if enable?(item_name)
@got_items.push(item_name)
enabled = true
else
enabled = false
end
draw_item_name(item_name, 4, 24 * (6 + counter), enabled, width = 140)
counter += 1
end
end
# Return Items
@got_items.each do |return_item|
$game_party.gain_item(return_item, 1)
end
end
#--------------------------------------------------------------------------
# * Get Party Gold
#--------------------------------------------------------------------------
def value
$game_party.gold
end
#--------------------------------------------------------------------------
# Get Currency Unit
#--------------------------------------------------------------------------
def currency_unit
Vocab::currency_unit
end
#--------------------------------------------------------------------------
# * Draw Horizontal Line
#--------------------------------------------------------------------------
def draw_horz_line(y)
line_y = y + line_height / 2 - 1
contents.fill_rect(0, line_y, contents_width, 2, line_color)
end
#--------------------------------------------------------------------------
# * Get Color of Horizontal Line
#--------------------------------------------------------------------------
def line_color
color = normal_color
color.alpha = 48
color
end
#--------------------------------------------------------------------------
# * Display in Enabled State?
#--------------------------------------------------------------------------
def enable?(item)
# Maybe get the number of items for the first item into a temp array? Hm
$game_party.all_items.each do |party_item|
if party_item == item
# Found an item, add to @got_items
$game_party.lose_item(item, 1)
return true
end
end
return false
end
end
#===============================================================================
# * Window_SynthActors
#===============================================================================
class Window_SynthActors < Window_Base
def initialize(x, y, ww, wh)
super
end
def refresh(item)
contents.clear
counter = 0
$game_party.members.each do |member|
# Draw face
draw_actor_face(member, counter * ((Graphics.width - 16) / $game_party.members.count), 0, enabled = true)
# If the item is equippable by the actor...
if member.equippable?(item)
case item.etype_id
when 0
draw_icon(SEM::SYNTHESIS::ATTACK_ICON, 16 + counter * ((Graphics.width - 16) / $game_party.members.count), (24*4 + 8))
if member.equips[0] != nil
difference = item.params[2] - member.equips[0].params[2]
else
difference = item.params[2]
end
if difference < 0
# Negative: Draw red
change_color(power_down_color)
elsif difference == 0
# Equal
difference = SEM::VOCAB::SYNTH_CURRENTLY_EQUIPPED
elsif difference > 0
# Positive: Draw green
change_color(power_up_color)
end
draw_text(44 + counter * ((Graphics.width - 16) / $game_party.members.count), (24 * 4) + 8, 70, 24, difference)
change_color(normal_color)
when 1
draw_icon(SEM::SYNTHESIS::DEFENSE_ICON, 16 + counter * ((Graphics.width - 16) / $game_party.members.count), (24*4 + 8))
if member.equips[1] != nil
difference = item.params[3] - member.equips[1].params[3]
else
difference = item.params[3]
end
if difference < 0
# Negative: Draw red
change_color(power_down_color)
elsif difference == 0
# Equal
# Check if it's equipped
if member.equips[1] == item
difference = SEM::VOCAB::SYNTH_CURRENTLY_EQUIPPED
else
difference = 0
end
elsif difference > 0
# Positive: Draw green
change_color(power_up_color)
end
draw_text(44 + counter * ((Graphics.width - 16) / $game_party.members.count), (24 * 4) + 8, 70, 24, difference)
change_color(normal_color)
when 2
draw_icon(SEM::SYNTHESIS::DEFENSE_ICON, 16 + counter * ((Graphics.width - 16) / $game_party.members.count), (24*4 + 8))
if member.equips[2] != nil
difference = item.params[3] - member.equips[2].params[3]
else
difference = item.params[3]
end
if difference < 0
# Negative: Draw red
change_color(power_down_color)
elsif difference == 0
# Equal
if member.equips[2] == item
difference = SEM::VOCAB::SYNTH_CURRENTLY_EQUIPPED
else
difference = 0
end
elsif difference > 0
# Positive: Draw green
change_color(power_up_color)
end
draw_text(44 + counter * ((Graphics.width - 16) / $game_party.members.count), (24 * 4) + 8, 70, 24, difference)
change_color(normal_color)
when 3
draw_icon(SEM::SYNTHESIS::DEFENSE_ICON, 16 + counter * ((Graphics.width - 16) / $game_party.members.count), (24*4 + 8))
if member.equips[3] != nil
difference = item.params[3] - member.equips[3].params[3]
else
difference = item.params[3]
end
if difference < 0
# Negative: Draw red
change_color(power_down_color)
elsif difference == 0
# Equal
if member.equips[3] == item
difference = SEM::VOCAB::SYNTH_CURRENTLY_EQUIPPED
else
difference = 0
end
elsif difference > 0
# Positive: Draw green
change_color(power_up_color)
end
draw_text(44 + counter * ((Graphics.width - 16) / $game_party.members.count), (24 * 4) + 8, 70, 24, difference)
change_color(normal_color)
when 4
draw_icon(SEM::SYNTHESIS::DEFENSE_ICON, 16 + counter * ((Graphics.width - 16) / $game_party.members.count), (24*4 + 8))
if member.equips[4] != nil
difference = item.params[3] - member.equips[4].params[3]
else
difference = item.params[3]
end
if difference < 0
# Negative: Draw red
change_color(power_down_color)
elsif difference == 0
# Equal
if member.equips[4] == item
difference = SEM::VOCAB::SYNTH_CURRENTLY_EQUIPPED
else
difference = 0
end
elsif difference > 0
# Positive: Draw green
change_color(power_up_color)
end
draw_text(44 + counter * ((Graphics.width - 16) / $game_party.members.count), (24 * 4) + 8, 96, 24, difference)
change_color(normal_color)
end
end
counter += 1
end
end
#--------------------------------------------------------------------------
# * Draw Face Graphic
# enabled : Enabled flag. When false, draw semi-transparently.
#--------------------------------------------------------------------------
def draw_face(face_name, face_index, x, y, enabled = true)
bitmap = Cache.face(face_name)
rect = Rect.new((face_index % 4 * 96), face_index / 4 * 96, 96, 96)
contents.blt(x + 15, y, bitmap, rect, enabled ? 255 : translucent_alpha)
bitmap.dispose
end
end
#===============================================================================
# * Window_ItemTitle
#===============================================================================
class Window_ItemTitle < Window_Base
def initialize(x, y, ww, wh)
super
draw_text(4, 0, 120, 24, "#{SEM::VOCAB::SYNTH_ITEM}")
draw_text(0, 0, self.width - 24, 24, "#{SEM::VOCAB::SYNTH_PRICE}", 2)
end
end
#===============================================================================
# * Window_ShopIntro
#===============================================================================
class Window_SynthIntro < Window_Command
alias window_shopintro_init_ssy initialize
def initialize(x, y)
window_shopintro_init_ssy(x, y)
refresh
end
#--------------------------------------------------------------------------
# * Get Window Height
#--------------------------------------------------------------------------
def window_height
fitting_height(2)
end
#--------------------------------------------------------------------------
# * Create Command List
#--------------------------------------------------------------------------
def make_command_list
add_command(SEM::VOCAB::SYNTHESIS, :synth)
add_command(SEM::VOCAB::EXIT_SYNTH, :exit)
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
change_color(normal_color, command_enabled?(index))
draw_text(item_rect_for_text(index), command_name(index), 1)
end
end