赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 2945 |
最后登录 | 2012-12-14 |
在线时间 | 29 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 29 小时
- 注册时间
- 2008-5-23
- 帖子
- 14
|
呵呵,刚做完这个脚本.
思路不是最好,如果你能想出更好思路.就更好啦~你看对你有没有帮助?脚本如下:
#==============================================================================
# ■ 物品互换商店
#------------------------------------------------------------------------------
#
# 本脚本也带有普通商店的一部分。
#
# 当物品互换商店开关关闭时,在商店只能正常交易(- -#)
# 当物品互换商店开关开启时,在商店里才可以物品互换
#
# 比如:自身物品的价格与商店摆放的物品价格一致(默认等于)可以进行互换
# 自身物品的其他属性与商店摆放的物品其他属性一致时可以进行互换等等。。
#
# 脚本都有注释总之基本思路时这样了,有兴趣的话自己可以改成思路更加好的。
#
# By 水果℃篮子
#
# 物品互换商店开启开关
$calathus = 1
# 可以本脚本搜索 (- -#) 自定义添加或者修改其他符合物品互换的条件。
#
#==============================================================================
#==============================================================================
# ■ Window_Gold_e
#------------------------------------------------------------------------------
# 显示互换物品所值金钱的窗口。
#==============================================================================
class Window_Gold < Window_Base
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
cx = contents.text_size($data_system.words.gold).width
self.contents.font.color = normal_color
# 手动刷新
if $game_switches[$calathus] == true
if Input.trigger?(Input::DOWN) or Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT) or Input.trigger?(Input::UP) or Input.trigger?(Input::C)
self.contents.draw_text(4, 0, 120-cx-2, 32, $e_item.price.to_s, 2)
elsif Input.trigger?(Input::B)
self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
else
self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
end
else
self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
end
self.contents.font.color = system_color
self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
end
end
#==============================================================================
# ■ Window_ShopCommand
#------------------------------------------------------------------------------
# 商店画面、选择要做的事的窗口
#==============================================================================
class Window_ShopCommand < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 64, 480, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 3
@column_max = 3
# 物品互换商店开启时
if $game_switches[$calathus] == true
@commands = ["查看", "互换", "取消"]
else
@commands = ["买", "卖", "取消"]
end
refresh
self.index = 0
end
end
#==============================================================================
# ■ Window_ShopBuy
#------------------------------------------------------------------------------
# 商店画面、浏览显示可以购买的商品的窗口。
#==============================================================================
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
# 获取物品所持数
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
# 处在物品互换中
if $e_s == true
# 商店物品价格与要互换的物品的价格 相同时
if item.price == $e_item.price
self.contents.font.color = normal_color
## 商店物品名称与要互换的物品的名称(- -#) 相同时
#elsif item.name == $e_item.name
else
self.contents.font.color = disabled_color
end
else
if item.price <= $game_party.gold and number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 88, 32, item.price.to_s, 2)
end
end
#==============================================================================
# ■ Window_ShopNumber
#------------------------------------------------------------------------------
# 商店画面、输入买卖数量的窗口。
#==============================================================================
class Window_ShopNumber < Window_Base
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_item_name(@item, 4, 96)
self.contents.font.color = normal_color
self.contents.draw_text(272, 96, 32, 32, "×")
self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2)
self.cursor_rect.set(304, 96, 32, 32)
# 物品互换商店开启时
unless $game_switches[$calathus] == true
# 描绘合计价格和货币单位
domination = $data_system.words.gold
cx = contents.text_size(domination).width
total_price = @price * @number
self.contents.font.color = normal_color
self.contents.draw_text(4, 160, 328-cx-2, 32, total_price.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
end
end
end
#==============================================================================
# ■ Scene_Shop
#------------------------------------------------------------------------------
# 处理商店以及物品商店画面的类。
#==============================================================================
class Scene_Shop
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
# 生成帮助窗口
@help_window = Window_Help.new
# 生成指令窗口
@command_window = Window_ShopCommand.new
# 生成金钱窗口
@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 64
# 生成时间窗口
@dummy_window = Window_Base.new(0, 128, 640, 352)
# 生成购买窗口
@buy_window = Window_ShopBuy.new($game_temp.shop_goods)
@buy_window.active = false
@buy_window.visible = false
@buy_window.help_window = @help_window
# 生成卖出窗口
@sell_window = Window_ShopSell.new
@sell_window.active = false
@sell_window.visible = false
@sell_window.help_window = @help_window
# 生成数量输入窗口
@number_window = Window_ShopNumber.new
@number_window.active = false
@number_window.visible = false
# 生成状态窗口
@status_window = Window_ShopStatus.new
@status_window.visible = false
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面切换的话就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
# 释放窗口
@help_window.dispose
@command_window.dispose
@gold_window.dispose
@dummy_window.dispose
@buy_window.dispose
@sell_window.dispose
@number_window.dispose
@status_window.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新窗口
@help_window.update
@command_window.update
@gold_window.update
@dummy_window.update
@buy_window.update
@sell_window.update
@number_window.update
@status_window.update
# 指令窗口激活的情况下: 调用 update_command
if @command_window.active
update_command
return
end
# 购买窗口激活的情况下: 调用 update_buy
if @buy_window.active
if $game_switches[$calathus] == true
update_buy_e
else
update_buy
end
return
end
# 卖出窗口激活的情况下: 调用 update_sell
if @sell_window.active
if $game_switches[$calathus] == true
update_sell_e
else
update_sell
end
return
end
# 个数输入窗口激活的情况下: 调用 update_number
if @number_window.active
if $game_switches[$calathus] == true
update_number_e
else
update_number
end
return
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 (指令窗口激活的情况下)
#--------------------------------------------------------------------------
def update_command
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 切换到地图画面
$scene = Scene_Map.new
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 命令窗口光标位置分支
case @command_window.index
when 0 # 购买
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 窗口状态转向购买模式
@command_window.active = false
@dummy_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@buy_window.refresh
@status_window.visible = true
when 1 # 卖出
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 窗口状态转向卖出模式
@command_window.active = false
@dummy_window.visible = false
@sell_window.active = true
@sell_window.visible = true
@sell_window.refresh
# 获取物品
@item = @sell_window.item
# 互换窗口中的所选物品
$e_item = @item
# 刷新金钱窗口
@gold_window.refresh
when 2 # 取消
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 切换到地图画面
$scene = Scene_Map.new
end
return
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 (购买窗口激活的情况下)
#--------------------------------------------------------------------------
def update_buy
# 设置状态窗口的物品
@status_window.item = @buy_window.item
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 窗口状态转向初期模式
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
# 删除帮助文本
@help_window.set_text("")
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 获取物品
@item = @buy_window.item
# CE锲肺扌У那榭鱿隆⒒蛘呒鄹裨谒?纸鹨陨系那榭鱿?
if @item == nil or @item.price > $game_party.gold
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 获取物品所持数
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
# 如果已经拥有了 99 个情况下
if number == 99
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 计算可以最多购买的数量
max = @item.price == 0 ? 99 : $game_party.gold / @item.price
max = [max, 99 - number].min
# 窗口状态转向数值输入模式
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@item, max, @item.price)
@number_window.active = true
@number_window.visible = true
end
end
#--------------------------------------------------------------------------
# ● 画面更新 (卖出窗口激活的情况下)
#--------------------------------------------------------------------------
def update_sell
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 窗口状态转向初期模式
@command_window.active = true
@dummy_window.visible = true
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
# 删除帮助文本
@help_window.set_text("")
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 获取物品
@item = @sell_window.item
# 设置状态窗口的物品
@status_window.item = @item
# 物品无效的情况下、或者价格为 0 (不能卖出) 的情况下
if @item == nil or @item.price == 0
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 获取物品的所持数
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
# 最大卖出个数 = 物品的所持数
max = number
# 窗口状态转向个数输入模式
@sell_window.active = false
@sell_window.visible = false
@number_window.set(@item, max, @item.price / 2)
@number_window.active = true
@number_window.visible = true
@status_window.visible = true
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 (个数输入窗口激活的情况下)
#--------------------------------------------------------------------------
def update_number
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 设置个数输入窗口为不活动·非可视状态
@number_window.active = false
@number_window.visible = false
# 命令窗口光标位置分支
case @command_window.index
when 0 # 购买
# 窗口状态转向购买模式
@buy_window.active = true
@buy_window.visible = true
when 1 # 卖出
# 窗口状态转向卖出模式
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 演奏商店 SE
$game_system.se_play($data_system.shop_se)
# 设置个数输入窗口为不活动·非可视状态
@number_window.active = false
@number_window.visible = false
# 命令窗口光标位置分支
case @command_window.index
when 0 # 购买
# 购买处理
$game_party.lose_gold(@number_window.number * @item.price)
case @item
when RPG::Item
$game_party.gain_item(@item.id, @number_window.number)
when RPG::Weapon
$game_party.gain_weapon(@item.id, @number_window.number)
when RPG::Armor
$game_party.gain_armor(@item.id, @number_window.number)
end
# 刷新各窗口
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
# 窗口状态转向购买模式
@buy_window.active = true
@buy_window.visible = true
when 1 # 卖出
# 卖出处理
$game_party.gain_gold(@number_window.number * (@item.price / 2))
case @item
when RPG::Item
$game_party.lose_item(@item.id, @number_window.number)
when RPG::Weapon
$game_party.lose_weapon(@item.id, @number_window.number)
when RPG::Armor
$game_party.lose_armor(@item.id, @number_window.number)
end
# 刷新各窗口
@gold_window.refresh
@sell_window.refresh
@status_window.refresh
# 窗口状态转向卖出模式
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 (查看窗口激活的情况下)
#--------------------------------------------------------------------------
def update_buy_e
# 设置状态窗口的物品
@status_window.item = @buy_window.item
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 命令窗口光标位置分支
case @command_window.index
when 0 # 查看
# 窗口状态转向查看模式
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
@command_window.active = true
@dummy_window.visible = true
when 1 # 互换
# 窗口状态转向初期模式
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
@sell_window.active = true
@sell_window.visible = true
@sell_window.refresh
end
# 删除帮助文本
@help_window.set_text("")
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 获取物品
@item = @buy_window.item
# 互换开始
if $e_s == true
# 无物品 双方价格不同 的情况下
if @item == nil or @item.price != $e_item.price
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
p "呵呵~物品价格不同"
return
## 无物品 双方名称不同(- -#) 的情况下
#elsif @item == nil or @item.name != $e_item.name
# # 演奏冻结 SE
# $game_system.se_play($data_system.buzzer_se)
# p "呵呵~物品名称不同"
# return
end
case @item
when RPG::Item
$game_party.gain_item(@item.id, $e_number)
# 互换处理的物品类型(0:道具 1:武器 2:防具)
case $e_t
when 0
$game_party.lose_item($e_id, $e_number)
when 1
$game_party.lose_weapon($e_id, $e_number)
when 2
$game_party.lose_armor($e_id, $e_number)
end
when RPG::Weapon
$game_party.gain_weapon(@item.id, $e_number)
# 互换处理的物品类型(0:道具 1:武器 2:防具)
case $e_t
when 0
$game_party.lose_item($e_id, $e_number)
when 1
$game_party.lose_weapon($e_id, $e_number)
when 2
$game_party.lose_armor($e_id, $e_number)
end
when RPG::Armor
$game_party.gain_armor(@item.id, $e_number)
# 互换处理的物品类型(0:道具 1:武器 2:防具)
case $e_t
when 0
$game_party.lose_item($e_id, $e_number)
when 1
$game_party.lose_weapon($e_id, $e_number)
when 2
$game_party.lose_armor($e_id, $e_number)
end
end
# 演奏商店 SE
$game_system.se_play($data_system.shop_se)
# 窗口状态转向数值输入模式
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@sell_window.active = true
@sell_window.visible = true
$e_s = false
@sell_window.refresh
# 刷新金钱窗口
@gold_window.refresh
else
## 演奏确定 SE
#$game_system.se_play($data_system.decision_se)
## 窗口状态转向数值输入模式
#@buy_window.active = false
#@buy_window.visible = false
#@buy_window.refresh
#@status_window.visible = false
#@sell_window.active = true
#@sell_window.visible = true
#@sell_window.refresh
p "有兴趣的可以自己扩展内容"
end
end
end
#--------------------------------------------------------------------------
# ● 画面更新 (互换窗口激活的情况下)
#--------------------------------------------------------------------------
def update_sell_e
# 获取物品
@item = @sell_window.item
# 互换窗口中的所选物品
$e_item = @item
# 按下 下/左/右/上/C 键的情况下
if Input.trigger?(Input::DOWN) or Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT) or Input.trigger?(Input::UP) or Input.trigger?(Input::C)
# 刷新金钱窗口
@gold_window.refresh
end
# 按下 B 键的情况下
if Input.trigger?(Input::B)
@gold_window.refresh
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 窗口状态转向初期模式
@command_window.active = true
@dummy_window.visible = true
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
# 删除帮助文本
@help_window.set_text("")
# 关闭互换
$e_s = false
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 获取物品
@item = @sell_window.item
# 设置状态窗口的物品
@status_window.item = @item
# 物品无效的情况下、或者价格为 0 (不能互换) 的情况下
if @item == nil or @item.price == 0
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 获取物品的所持数
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
# 最大互换个数 = 物品的所持数
max = number
# 窗口状态转向个数输入模式
@sell_window.active = false
@sell_window.visible = false
@number_window.set(@item, max, @item.price / 2)
@number_window.active = true
@number_window.visible = true
@status_window.visible = true
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 (物品互换时,个数输入窗口激活的情况下)
#--------------------------------------------------------------------------
def update_number_e
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 设置个数输入窗口为不活动·非可视状态
@number_window.active = false
@number_window.visible = false
# 命令窗口光标位置分支
case @command_window.index
when 0 # 查看
# 窗口状态转向查看模式
@buy_window.active = true
@buy_window.visible = true
when 1 # 互换
# 窗口状态转向互换模式
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
@sell_window.refresh
end
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
## 演奏商店 SE
#$game_system.se_play($data_system.shop_se)
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置个数输入窗口为不活动·非可视状态
@number_window.active = false
@number_window.visible = false
# 命令窗口光标位置分支
case @command_window.index
when 0 # 查看
# 查看处理
#$game_party.lose_gold(@number_window.number * @item.price)
case @item
when RPG::Item
#$game_party.gain_item(@item.id, @number_window.number)
when RPG::Weapon
#$game_party.gain_weapon(@item.id, @number_window.number)
when RPG::Armor
#$game_party.gain_armor(@item.id, @number_window.number)
end
# 刷新各窗口
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
# 窗口状态转向查看模式
@buy_window.active = true
@buy_window.visible = true
when 1 # 互换
# 卖出处理
$game_party.gain_gold(@number_window.number * (@item.price / 2))
case @item
when RPG::Item
# 互换处理的物品ID
$e_id = @item.id
# 互换处理的物品数量
$e_number = @number_window.number
# 互换处理的物品类型(0:道具 1:武器 2:防具)
$e_t = 0
# 互换处理开始
$e_s = true
when RPG::Weapon
#$game_party.lose_weapon(@item.id, @number_window.number)
# 互换处理的物品ID
$e_id = @item.id
# 互换处理的物品数量
$e_number = @number_window.number
# 互换处理的物品类型(0:道具 1:武器 2:防具)
$e_t = 1
# 互换处理开始
$e_s = true
#p $e_id
#p $e_number
when RPG::Armor
#$game_party.lose_armor(@item.id, @number_window.number)
# 互换处理的物品ID
$e_id = @item.id
# 互换处理的物品数量
$e_number = @number_window.number
# 互换处理的物品类型(0:道具 1:武器 2:防具)
$e_t = 2
# 互换处理开始
$e_s = true
end
# 窗口状态转向互换模式
#@sell_window.active = true
#@sell_window.visible = true
#@status_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@buy_window.refresh
# 刷新各窗口
@gold_window.refresh
#@sell_window.refresh
@status_window.refresh
end
return
end
end
end
#################
系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~ |
|