#==============================================================================
# ■ 背包系统 —— by 水镜风生
#------------------------------------------------------------------------------
LOSE_ITEM_SE_NAME = "Evasion" # 丢弃物品时播放的SE
LOW_SPEED = 1 # 背包塞满时的移动速度
USUAL_SPEED = 4 # 平时的移动速度
WARING_STRING = "背包里东西太多了!" # 超重时的提示
IM = 41 # IM号系统变量决定物品种类的最大值
#==============================================================================
# ■ Scene_Item
#------------------------------------------------------------------------------
# 处理物品画面的类。
#==============================================================================
class Scene_Item < Scene_Base
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_menu_background
@viewport = Viewport.new(0, 0, 544, 416)
@help_window = Window_Help.new
@help_window.viewport = @viewport
@item_window = Window_Item.new(0, 67, 544, 280)
@item_window.viewport = @viewport
@item_window.help_window = @help_window
@item_window.active = false
@target_window = Window_MenuStatus.new(0, 0)
@max_window = Window_Item_Max.new
@max_window.viewport = @viewport
@number_window = Window_LoseNumber.new(142, 156)
@number_window.viewport = @viewport
@command_window = Window_Command.new(145, [" 使用"," 丢弃"], 1, 2)
@command_window.x = 200
@command_window.y = 160
hide_command_window
hide_number_window
hide_target_window
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
alias terminate2 terminate
def terminate
terminate2
@max_window.dispose
@command_window.dispose
@number_window.dispose
end
#--------------------------------------------------------------------------
# ● 回到原画面
#--------------------------------------------------------------------------
def return_scene
$scene = Scene_Menu.new(0)
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
@help_window.update
@item_window.update
@target_window.update
@max_window.update
@command_window.update
@number_window.update
if @item_window.active
update_item_selection
elsif @target_window.active
update_target_selection
elsif @command_window.active
update_command_selection
elsif @number_window.active
update_number_selection
end
end
#--------------------------------------------------------------------------
# ● 更新物品选择
#--------------------------------------------------------------------------
def update_item_selection
if Input.trigger?(Input::B)
if $game_party.items.size <= $game_variables[IM]# 如果物品种类没超过限制
$game_player.change_move_speed(USUAL_SPEED)
end
Sound.play_cancel
return_scene
elsif Input.trigger?(Input::C)
@item = @item_window.item
if @item != nil
$game_party.last_item_id = @item.id
Sound.play_decision
if $game_party.item_can_use?(@item) # 物品是否可用
@command_window.draw_item(0,true)
else @command_window.draw_item(0,false) # 不可用的话【使用】选项颜色无效
end
if @item.price == 0 # 物品价格是否为0
@command_window.draw_item(1,false) # 是的话【丢弃】选项无效
else
@command_window.draw_item(1,true)
end
show_command_window
else
Sound.play_buzzer
end
end
end
#--------------------------------------------------------------------------
# ● 更新目标选择
#--------------------------------------------------------------------------
def update_target_selection
if Input.trigger?(Input::B)
Sound.play_cancel
if $game_party.item_number(@item) == 0 # 判断物品是否耗尽
@item_window.refresh # 刷新窗口内容
@max_window.refresh # 刷新物品种类窗口
end
hide_target_window
elsif Input.trigger?(Input::C)
if not $game_party.item_can_use?(@item)
Sound.play_buzzer
else
determine_target
end
end
end
#--------------------------------------------------------------------------
# ★ 更新指令选择
#--------------------------------------------------------------------------
def update_command_selection
if Input.trigger?(Input::B)
Sound.play_cancel
hide_command_window
elsif Input.trigger?(Input::C)
if @command_window.index == 0
if $game_party.item_can_use?(@item)
Sound.play_decision
@command_window.active = false
@command_window.visible =false
determine_item
else
Sound.play_buzzer
end
elsif @item == nil or @item.price == 0
Sound.play_buzzer
else
Sound.play_decision
@command_window.active = false
@command_window.visible =false
max = $game_party.item_number(@item)
@number_window.set(@item, max)
show_number_window
end
end
end
#--------------------------------------------------------------------------
# ★ 更新数量输入
#--------------------------------------------------------------------------
def update_number_selection
if Input.trigger?(Input::B)
Sound.play_cancel
hide_number_window
elsif Input.trigger?(Input::C)
Audio.se_play("Audio/SE/#{LOSE_ITEM_SE_NAME}", 80, 100)
$game_party.lose_item(@item, @number_window.number)
@item_window.refresh
@max_window.refresh
hide_number_window
end
end
#--------------------------------------------------------------------------
# ★ 显示指令选择窗口
#--------------------------------------------------------------------------
def show_command_window
@command_window.index = 0
@item_window.active = false
@command_window.visible = true
@command_window.active = true
end
#--------------------------------------------------------------------------
# ★ 显示数量窗口
#--------------------------------------------------------------------------
def show_number_window
@command_window.active = false
@number_window.visible = true
@number_window.active = true
end
#--------------------------------------------------------------------------
# ★ 隐藏指令选择窗口
#--------------------------------------------------------------------------
def hide_command_window
@item_window.active = true
@command_window.visible = false
@command_window.active = false
@viewport.rect.set(0, 0, 544, 416)
@viewport.ox = 0
end
#--------------------------------------------------------------------------
# ★ 隐藏数量窗口
#--------------------------------------------------------------------------
def hide_number_window
@item_window.active = true
@number_window.visible = false
@number_window.active = false
@viewport.rect.set(0, 0, 544, 416)
@viewport.ox = 0
end
end
#==============================================================================
# ■ Window_lost_item
#------------------------------------------------------------------------------
# 显示物品丢弃数量的窗口,仿 Window_ShopNumber。
#==============================================================================
class Window_LoseNumber < Window_Base
#--------------------------------------------------------------------------
# ★ 初始化对像
# x : 窗口 X 座标
# y : 窗口 Y 座标
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, 260, 104)
@item = nil
[url=home.php?mod=space&uid=25307]@Max[/url] = 1
[url=home.php?mod=space&uid=27178]@Number[/url] = 1
end
#--------------------------------------------------------------------------
# ★ 设置物品、最大数量
#--------------------------------------------------------------------------
def set(item, max)
@item = item
[url=home.php?mod=space&uid=25307]@Max[/url] = max
[url=home.php?mod=space&uid=27178]@Number[/url] = 1
refresh
end
#--------------------------------------------------------------------------
# ★ 设置数量输入
#--------------------------------------------------------------------------
def number
return @number
end
#--------------------------------------------------------------------------
# ★ 刷新
#--------------------------------------------------------------------------
def refresh
y = 24
self.contents.clear
draw_item_name(@item, 0, y)
self.contents.font.color = normal_color
self.contents.draw_text(164, y, 20, WLH, "×")
self.contents.draw_text(190, y, 20, WLH, @number, 2)
self.cursor_rect.set(186, y, 28, WLH)
end
#--------------------------------------------------------------------------
# ★ 更新画面
#--------------------------------------------------------------------------
def update
super
if self.active
last_number = @number
if Input.repeat?(Input::RIGHT) and @number < @max
@number += 1
end
if Input.repeat?(Input::LEFT) and @number > 1
@number -= 1
end
if Input.repeat?(Input::UP) and @number < @max
@number = [@number + 10, @max].min
end
if Input.repeat?(Input::DOWN) and @number > 1
@number = [@number - 10, 1].max
end
if @number != last_number
Sound.play_cursor
refresh
end
end
end
end
#==============================================================================
# ■ Window_Item_Max
#-----------------------------------------------------------------------------
# 显示背包容量和当前物品数的窗口
#============================================================================
class Window_Item_Max < Window_Base
#--------------------------------------------------------------------------
# ★ 初始化对像
#--------------------------------------------------------------------------
def initialize
super(290, 360, 254, 56)
refresh
end
#--------------------------------------------------------------------------
# ★ 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_icon(144, 0, 0)
self.contents.draw_text(36, 0, 100, 24, "背包容量:")
item = $game_party.items
string = item.size.to_s
self.contents.font.color = knockout_color if item.size > $game_variables[IM]
self.contents.draw_text(135, 0, 30, 24, string, 2)
self.contents.font.color = normal_color
string = "/ " + $game_variables[IM].to_s
self.contents.draw_text(173, 0, 100, 24, string )
end
end
#==============================================================================
# ■ Window_Waring
#-----------------------------------------------------------------------------
# 显示超重警告的窗口
#============================================================================
class Window_Waring < Window_Base
def initialize
width = WARING_STRING.size * 8
super(544 - width, 416 - 56, width, 56)
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(0, -4, width - 32, 32, WARING_STRING)
end
end
#==============================================================================
# Game_Player 添加更改移动速度的方法
#============================================================================
class Game_Player
def change_move_speed(n)
@move_speed = n
end
end
#==============================================================================
# Scene_Map 添加在地图上显示警告窗口的处理
#============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
alias start2 start
def start
start2
@waring_window = Window_Waring.new
@waring_window.visible = false
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
alias terminate2 terminate
def terminate
@waring_window.dispose
terminate2
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias update2 update
def update
update2
update_over_item
end
#--------------------------------------------------------------------------
# ● 更新物品超限判定
#--------------------------------------------------------------------------
def update_over_item
if $game_party.items.size > $game_variables[IM]
@waring_window.visible = true
$game_player.change_move_speed(LOW_SPEED)
else
@waring_window.visible = false
end
end
end