Project1
标题:
求1个装备鉴定的脚本
[打印本页]
作者:
kaspersky
时间:
2011-7-13 09:34
提示:
作者被禁止或删除 内容自动屏蔽
作者:
夜风袭
时间:
2011-7-13 09:36
http://rpg.blue/article-41127.html
module RPG
class Item
def name
return @name.split(/#/)[0]
end
def indentify
return @name.split(/#/)[1]
end
end
class Weapon
def name
return @name.split(/#/)[0]
end
def indentify
return @name.split(/#/)[1]
end
end
class Armor
def name
return @name.split(/#/)[0]
end
def indentify
return @name.split(/#/)[1]
end
end
end
module OPTION
CALL_WINDOW = Proc.new{$Scene.call_window }
end
class Game_System
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :item_indentify_table # 物品鉴定表
attr_accessor :weapon_indentify_table # 武器鉴定表
attr_accessor :armor_indentify_table # 防具鉴定表
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
alias ori_initialize initialize
def initialize
ori_initialize
@item_indentify_table = IT.new.set_item
@weapon_indentify_table = IT.new.set_weapon
@armor_indentify_table = IT.new.set_armor
end
end
#--------------------------------------------------------------------------
# ● 存储数据表的IT类
#--------------------------------------------------------------------------
class IT
def initialize
@items = $data_items
@weapons = $data_weapons
@armors = $data_armors
end
def set_item
hash = {}
for i in
[email protected]
hash[@items[i].name] = @items[i].indentify
end
return hash
end
def set_weapon
hash = {}
for i in
[email protected]
hash[@weapons[i].name] = @weapons[i].indentify
end
return hash
end
def set_armor
hash = {}
for i in
[email protected]
hash[@armors[i].name] = @armors[i].indentify
end
return hash
end
end
#==============================================================================
# ■ Window_Item
#------------------------------------------------------------------------------
# 物品画面、战斗画面、显示浏览物品的窗口。
#==============================================================================
class Window_Item < Window_Selectable
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
# 添加判断(物品)
indentify = $game_system.item_indentify_table[item.name]
when RPG::Weapon
number = $game_party.weapon_number(item.id)
# 添加判断(武器)
indentify = $game_system.weapon_indentify_table[item.name]
when RPG::Armor
# 添加判断(防具)
number = $game_party.armor_number(item.id)
indentify = $game_system.armor_indentify_table[item.name]
end
if item.is_a?(RPG::Item) and
$game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 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)
if indentify == "0"
self.contents.draw_text(x + 28, y, 212, 32,"未鉴定", 0)
else
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
end
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
end
#==============================================================================
# ■ Scene_Item
#------------------------------------------------------------------------------
# 处理物品画面的类。
#==============================================================================
class Scene_Item
#--------------------------------------------------------------------------
# ● 刷新画面 (目标窗口被激活的情况下)
#--------------------------------------------------------------------------
def update_target
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 由于物品用完而不能使用的场合
unless $game_party.item_can_use?(@item.id)
# 再次生成物品窗口的内容
@item_window.refresh
end
# 删除目标窗口
@item_window.active = true
@target_window.visible = false
@target_window.active = false
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 如果物品用完的情况下
if $game_party.item_number(@item.id) == 0
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
p $game_system.item_indentify_table[@item.name]
# 判断是否为未鉴定物品
if $game_system.item_indentify_table[@item.name] == "0"
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# --------------------
# 目标是全体的情况下
if @target_window.index == -1
# 对同伴全体应用物品使用效果
used = false
for i in $game_party.actors
used |= i.item_effect(@item)
end
end
# 目标是单体的情况下
if @target_window.index >= 0
# 对目标角色应用物品的使用效果
target = $game_party.actors[@target_window.index]
used = target.item_effect(@item)
end
# 使用物品的情况下
if used
# 演奏物品使用时的 SE
$game_system.se_play(@item.menu_se)
# 消耗品的情况下
if @item.consumable
# 使用的物品数减 1
$game_party.lose_item(@item.id, 1)
# 再描绘物品窗口的项目
@item_window.draw_item(@item_window.index)
end
# 再生成目标窗口的内容
@target_window.refresh
# 全灭的情况下
if $game_party.all_dead?
# 切换到游戏结束画面
$scene = Scene_Gameover.new
return
end
# 公共事件 ID 有效的情况下
if @item.common_event_id > 0
# 预约调用公共事件
$game_temp.common_event_id = @item.common_event_id
# 切换到地图画面
$scene = Scene_Map.new
return
end
end
# 无法使用物品的情况下
unless used
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
end
return
end
end
end
#==============================================================================
# ■ Window_EquipItem
#------------------------------------------------------------------------------
# 装备画面、显示浏览变更装备的候补物品的窗口。
#==============================================================================
class Window_EquipItem < Window_Selectable
#--------------------------------------------------------------------------
# ● 项目的描绘
# index : 项目符号
#--------------------------------------------------------------------------
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)
# 添加判断(武器)
indentify = $game_system.weapon_indentify_table[item.name]
when RPG::Armor
number = $game_party.armor_number(item.id)
# 添加判断(防具)
indentify = $game_system.armor_indentify_table[item.name]
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.font.color = normal_color
if indentify == "0"
self.contents.draw_text(x + 28, y, 212, 32,"未鉴定", 0)
else
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
end
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
end
#==============================================================================
# ■ Scene_Equip
#------------------------------------------------------------------------------
# 处理装备画面的类。
#==============================================================================
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)
case @item_window.item
when RPG::Weapon
# 添加判断(武器)
indentify = $game_system.weapon_indentify_table[@item_window.item.name]
when RPG::Armor
# 添加判断(防具)
indentify = $game_system.armor_indentify_table[@item_window.item.name]
end
if @item_window.item != nil
if indentify == "0"
return
end
end
# 演奏装备 SE
$game_system.se_play($data_system.equip_se)
# 获取物品窗口现在选择的装备数据
item = @item_window.item
# 变更装备
@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
class Game_Party
attr_reader :items
attr_reader :weapons
attr_reader :armors
end
class Window_Item_Indentify < Window_Selectable
def initialize
super(160,80,320,320)
self.contents = Bitmap.new(width - 32, height - 32)
@column_max = 1
@item_max = items[0].size + weapons[0].size + armors[0].size - 1
@data = []
refresh
self.index = 0
end
def items
hash = {}
item_names = []
item_ids = []
items = $game_party.items
items.each_key{|key|item_names.push($data_items[key].name)}
items.each_key{|key|item_ids.push(key)}
return [item_names,item_ids]
end
def weapons
hash = {}
weapon_names = []
weapon_ids = []
weapons = $game_party.weapons
weapons.each_key{|key|weapon_names.push($data_weapons[key].name)}
weapons.each_key{|key|weapon_ids.push(key)}
return [weapon_names,weapon_ids]
end
def armors
hash = {}
armor_names = []
armor_ids = []
armors = $game_party.armors
armors.each_key{|key|armor_names.push($data_armors[key].name)}
armors.each_key{|key|armor_ids.push(key)}
return [armor_names,armor_ids]
end
def all
all = []
items[1].each{|id| all.push($data_items[id])}
weapons[1].each{|id| all.push($data_weapons[id])}
armors[1].each{|id| all.push($data_armors[id])}
return all
end
def refresh
self.contents.clear
for i in 0...all.size
case all[i]
when RPG::Item
indentify = $game_system.item_indentify_table[all[i].name]
when RPG::Weapon
indentify = $game_system.weapon_indentify_table[all[i].name]
when RPG::Armor
indentify = $game_system.armor_indentify_table[all[i].name]
end
bitmap = RPG::Cache.icon(all[i].icon_name)
self.contents.blt(0,i*32,bitmap,Rect.new(0, 0, 24, 24))
if indentify == "0"
self.contents.draw_text(64,i*32,200,32,"未鉴定")
else
self.contents.draw_text(64,i*32,200,32,all[i].name)
end
end
end
end
class Scene_Indentify
def main
@spriteset = Spriteset_Map.new
@window = Window_Item_Indentify.new
@help_window = Window_Help.new
@help_window.active = false
@help_window.y = 0
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@window.dispose
@spriteset.dispose
end
def update
@help_window.update
if @window.active
window_update
end
if @help_window.active
help_window_update
end
end
def window_update
@window.update
if Input.trigger?(Input::C)
data = @window.all[@window.index]
case @window.all[@window.index]
when RPG::Item
indentify = $game_system.item_indentify_table[data.name]
if indentify == "0"
indentify = $game_system.item_indentify_table[data.name] = 1
@window.active = false
@help_window.active = true
@help_window.set_text("鉴定结果"+ data.name )
end
when RPG::Weapon
indentify = $game_system.weapon_indentify_table[data.name]
if indentify == "0"
indentify = $game_system.weapon_indentify_table[data.name] = 1
@window.active = false
@help_window.active = true
@help_window.set_text("鉴定结果"+ data.name )
end
when RPG::Armor
indentify = $game_system.armor_indentify_table[data.name]
if indentify == "0"
indentify = $game_system.armor_indentify_table[data.name] = 1
@window.active = false
@help_window.active = true
@help_window.set_text("鉴定结果"+ data.name )
end
end
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
end
end
def help_window_update
if Input.press?(Input::C)
$game_system.se_play($data_system.decision_se)
for i in 0..30
Graphics.update
end
$scene = Scene_Map.new
end
end
end
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1