module THEO
module Smith
W_Upgrade_Table = { # <-- Do not touch this at all cost!
# ------------------------------------------------------------------------
# Upgrade tree format.
# ------------------------------------------------------------------------
# ID => [ <-- opening
#
# [{:symbol => num}, icon_index, name, description, sell_price, [[item_id, sum], [item_id, sum]]], # Level 2
# [{:symbol => num}, icon_index, name, description, sell_price], # Level 3
# [ <add more here for the next level> ], # Level 4
#
# ], <-- ending (do not forget to add comma!)
# ------------------------------------------------------------------------
# Just a quick guide won't kill yourself :)
# ------------------------------------------------------------------------
# ID = Weapon ID in database.
#
# {:symbol => num } = Once you've upgrade your weapon, the parameter will
# change whether it's up or down. Use the symbol to
# represent the status. Here's the list:
# ---------------------------------------------------
# :atk = attack || :def = defense
# :mat = magic atk || :mdf = magic defense
# :agi = agility || :luk = luck
# :mhp = Max HP || :mmp = Max MP
# ---------------------------------------------------
# And "num" is a number represent to parameter change
#
# icon_index = Represent as icon index. You may look the icon
# index when you open the icon window dialog box and
# see to the bottom left of that window. Use -1 if you
# don't want to change weapon's icon once upgraded.
#
# name = The new name of upgraded weapon. Leave it blank ("")
# if you wanna keep the original name
#
# description = The new description of upgraded weapon. Leave it
# blank ("") if you wanna keep the original description
#
#===========================================================================
# EDIT (by vFoggy):
# upgrade_price = A list with pairs of item_id and sum of item. Use
# 0 for the item_id for gold price
#
# if you want gold instead of an item then use 0 for the item_id
#===========================================================================
# Here's the example :
# ------------------------------------------------------------------------
1 => [
[{:atk => 2,:luk => 2},-1,"","", 500, [[1, 10], [0, 100]]], # dont forget comma
[{:atk => 2},-1,"Iron Ax","Upgrade version of Hand ax", [[5, 3], [0, 200]]],
[{:atk => 2},-1,"Silver Ax","", [[5, 50], [0, 500], [6, 2]]],
] # dont forget comma
# add more here if it's necessary
# ------------------------------------------------------------------------
}
end
end
class Game_Party < Game_Unit
# New method: checks if item can be upgraded
def upgradable?(price)
price.each do |id, count|
if id == 0
return false if @gold < count
else
return false if item_number($data_items[id]) < count
end
end
return true
end
end
class Window_SmithMenu < Window_Selectable
def enable?(index)
actor = $game_party.members[index]
return false if actor.equips[0].nil?
# EDIT: check if it is enabled
return actor.equips[0].next_weapon_exist? &&
$game_party.upgradable?(actor.equips[0].next_weapon.upgrade_price)
end
end
class Scene_Smith < Scene_MenuBase
def craft_weapon
@confirm.close
@confirm.deactivate
$game_party.gain_item(next_weapon,1)
# EDIT: remove each item that is needed
next_weapon.upgrade_price.each do |id, count|
if id == 0
$game_party.lose_gold(count)
else
$game_party.lose_item($data_items[id], count)
end
end
last_equip = item_to_lose
@notif_smith.show_weapon(last_equip)
actor.change_equip(0,next_weapon)
$game_party.lose_item(last_equip,1)
@menu_actor.update_help
@menu_actor.activate
@menu_actor.refresh
@gold_window.refresh
end
end
class Window_SmithResult < Window_Base
include THEO::Smith
def draw_price_text(rect, price)
y = rect.y
x = rect.x
price.each_with_index do |req, index|
id = req[0]
count = req[1]
draw_text_ex(x, y, count)
x += text_size(count).width
if id == 0
draw_text_ex(x, y, "G ")
x += text_size("G ").width
else
draw_icon($data_items[id].icon_index, x, y, true)
x += 25
end
draw_text_ex(x, y, " + ") unless index == price.length-1
x += text_size(" + ").width
end
end
def draw_next_weapon
ypos = 28
rect = Rect.new(0,ypos,contents.width,line_height)
contents.font.size -= 4
change_color(text_color(Colour::Upgradable))
draw_text(rect,SVocab::Upgradable,2)
change_color(system_color)
draw_text(rect,SVocab::Cost)
rect.x += text_size(SVocab::Cost).width
change_color(normal_color)
# EDIT: draw_price_text instead of draw_text
draw_price_text(rect, @weapon.next_weapon.upgrade_price)
texts = obtain_params_change
ypos += line_height
texts.each do |txt|
draw_text_ex(0,ypos,txt)
ypos += line_height
end
end
end
class RPG::UpgradedWeapon < RPG::Weapon
# EDIT: takes parameter price [[item_id, count], [item_id, count]]
def make_price(price)
item_price = @price
base_price = THEO::Smith::PriceBase
@price = eval(THEO::Smith::PriceTrade)
@upgrade_price = price
end
end
class << DataManager
def init_upgraded_weapons
$upgraded_weapons = {}
THEO::Smith::W_Upgrade_Table.each do |id, table|
table.each_with_index do |data,level|
gen_id = (id*100) + (level+1) # Generated ID
weapon_check = $upgraded_weapons[gen_id]
result = nil
if (level + 1) != 1 && !weapon_check.nil?
result = weapon_check.clone_data
else
result = $data_weapons[id].clone_data
end
result.level = level+2
data[0].each do |param,value|
param_id = THEO::Smith::Key[param]
result.params[param_id] += value
end
if data[1] > -1
result.icon_index = data[1]
end
result.name = data[2].empty? ? result.name : data[2]
result.description = data[3].empty? ? result.description : data[3]
result.ori_id = id
# EDIT: call to make_price
result.make_price(data[-1])
gen_id = (id*100) + (level+2)
result.id = gen_id # Generated ID
$upgraded_weapons[gen_id] = result
end
end
end
end