module RPG
class Weapon
Regex_Lvl_Need = /%lvl\[(\d+)\]/
unless method_defined? :rb_description_20150202
alias rb_description_20150202 description
def description
return rb_description_20150202.gsub(Regex_Lvl_Need, "")
end
end
def level_need
Regex_Lvl_Need =~ @description
return $1.to_i
end
end
class Armor
Regex_Lvl_Need = /%lvl\[(\d+)\]/
unless method_defined? :rb_description_20150202
alias rb_description_20150202 description
def description
return rb_description_20150202.gsub(Regex_Lvl_Need, "")
end
end
def level_need
Regex_Lvl_Need =~ @description
return $1.to_i
end
end
end
class Game_Actor < Game_Battler
def can_equip?(equipment)
return true if equipment.nil?
return self.level >= equipment.level_need
end
end
class Window_EquipItem < Window_Selectable
def draw_item(index)
item = @data[index]
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
case item
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
bitmap = RPG::Cache.icon(item.icon_name)
opacity = @actor.can_equip?(item) ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.font.color = @actor.can_equip?(item) ? normal_color : disabled_color
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
def update_help
text = @actor.can_equip?(self.item) ? "" : sprintf("(角色需要达到LV%d)", self.item.level_need)
@help_window.set_text(self.item == nil ? "" : self.item.description + text)
end
end
class Scene_Equip
def update_item
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 激活右侧窗口
@right_window.active = true
@item_window.active = false
@item_window.index = -1
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 获取物品窗口现在选择的装备数据
item = @item_window.item
unless @actor.can_equip?(item)
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏装备 SE
$game_system.se_play($data_system.equip_se)
# 变更装备
@actor.equip(@right_window.index, item == nil ? 0 : item.id)
# 激活右侧窗口
@right_window.active = true
@item_window.active = false
@item_window.index = -1
# 再生成右侧窗口、物品窗口的内容
@right_window.refresh
@item_window.refresh
return
end
end
end