class Scene_Making < Scene_Base
#--------------------------------------------------------------------------
# ● 開始処理
#--------------------------------------------------------------------------
def start
super
create_menu_background
@help_window = Window_Help.new
@buy_window = Window_MakeList.new(0, 56)
@buy_window.active = true
@buy_window.help_window = @help_window
@status_window = Window_MakeStatus.new(272, 56)
end
#--------------------------------------------------------------------------
# ● 終了処理
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@help_window.dispose
@buy_window.dispose
@status_window.dispose
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
super
update_menu_background
@status_window.item = @buy_window.item
@status_window.item_index = @buy_window.index
@help_window.update
@buy_window.update
@status_window.update
if Input.trigger?(Input::C)
if @buy_window.item.can_making?
$game_party.gain_item(@buy_window.item, 1)
for material in @buy_window.item.need_materials
$game_party.lose_item(material[0], material[1])
end
RPG::SE.new("").play#音效
case @buy_window.item
when RPG::Item
#~ p @buy_window.item.id, $game_system.maked_items[@buy_window.item.id]
$game_system.maked_items[@buy_window.item.id] += 1
when RPG::Weapon
$game_system.maked_weapons[@buy_window.item.id] += 1
when RPG::Armor
$game_system.maked_armors[@buy_window.item.id] += 1
end
@buy_window.refresh
@status_window.refresh
else
Sound.play_buzzer
end
elsif Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
end
end
end
class Window_MakeList < Window_Selectable
#--------------------------------------------------------------------------
# ● オブジェクト初期化
# x : ウィンドウの X 座標
# y : ウィンドウの Y 座標
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, 272, 360)
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● アイテムの取得
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
def making_goods
i = 0
for item in ($data_items + $data_weapons + $data_armors).compact
if item.need_materials != nil
@data.push(item)
i += 1
end
end
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
@data = []
making_goods
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# ● 項目の描画
# index : 項目番号
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
number = $game_party.item_number(item)
enabled = item.can_making?
rect = item_rect(index)
self.contents.clear_rect(rect)
draw_item_name(item, rect.x, rect.y, enabled)
rect.width -= 4
end
#--------------------------------------------------------------------------
# ● ヘルプテキスト更新
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(item == nil ? "" : item.description)
end
end
class Window_MakeStatus < Window_Base
attr_accessor:item_index
#--------------------------------------------------------------------------
# ● オブジェクト初期化
# x : ウィンドウの X 座標
# y : ウィンドウの Y 座標
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, 272, 204)
@item = nil
@item_index = 0
refresh
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if @item != nil
number = $game_party.item_number(@item)
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 232, WLH, number, 2)
i = 0
self.contents.fill_rect(8, 32, 224, 1, Color.new(255,255,255,64))
self.contents.font.color = system_color
self.contents.font.size -= 4
self.contents.draw_text(12, 40, 224, WLH, "必要素材", 0)
# snf_statusfont(1)未知
for material in @item.need_materials
number = $game_party.item_number(material[0])
enabled = number >= material[1]
x = 12
y = 60 + WLH * i
draw_item_name(material[0], x, y, enabled)
self.contents.draw_text(x, y, 224, WLH, "#{number}/#{material[1]}", 2)
i += 1
end
y = 76 + WLH * i
self.contents.font.color = system_color
self.contents.font.size -= 4
self.contents.draw_text(12, y, 224, WLH, "作成回数", 0)
case @item
when RPG::Item
m = $game_system.maked_items[@item.id]
when RPG::Weapon
m = $game_system.maked_weapons[@item.id]
when RPG::Armor
m = $game_system.maked_armors[@item.id]
end
self.contents.font.color = normal_color
self.contents.draw_text(12, y, 224, WLH, m.to_s + "回", 2)
self.contents.font.size += 4
end
end
#--------------------------------------------------------------------------
# ● アイテムの設定
# item : 新しいアイテム
#--------------------------------------------------------------------------
def item=(item)
if @item != item
@item = item
refresh
end
end
end
module RPG
class BaseItem
def can_making?
result = true
for material in need_materials.compact
result = false unless $game_party.item_number(material[0]) >= material[1]
end
return result
end
def need_materials
return nil unless @note.include?("材料")
scand = @note.scan(/<材料:(\S+),(\S+),(\S+)>/)
mateiral_list = scand.flatten
#種別、ID、個数
result = []
for material_list in scand
case material_list[0].to_i
when 0
material = $data_items[material_list[1].to_i]
when 1
material = $data_weapons[material_list[1].to_i]
when 2
material = $data_armors[material_list[1].to_i]
end
case self
when RPG::Item
$game_system.maked_items[@id] = 0 if $game_system.maked_items[@id].nil?
m = $game_system.maked_items[@id]
when RPG::Weapon
$game_system.maked_weapons[@id] = 0 if $game_system.maked_weapons[@id].nil?
m = $game_system.maked_weapons[@id]
when RPG::Armor
$game_system.maked_armors[@id] = 0 if $game_system.maked_armors[@id].nil?
m = $game_system.maked_armors[@id]
end
volume = material_list[2].to_i + (m + 1) / 2
result.push([material, volume])
end
return result
end
end
end
class Game_System
attr_accessor:maked_items
attr_accessor:maked_weapons
attr_accessor:maked_armors
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias snf_initialize initialize
def initialize
snf_initialize
@maked_items = []
@maked_weapons = []
@maked_armors = []
end
end