#==============================================================================
# 装备耐久度 by 沉影不器
# protosssonny修改版
#------------------------------------------------------------------------------
# ① 自定义各个装备耐久度上限
# ② 允许显示"无法破坏"的装备,允许忽略耐久度的装备(如:戒指等装饰类)
# ③ 物理攻击消耗武器耐久度,被打消耗防具耐久度
# 攻击越高,对方防具减耐久度的机率越大,防御越高,对方武器减耐久度的机率越大
# ④ 装备耐久度降为 0 时装备即损坏,该装备能力消失,提供修复耐久度的功能
# ⑤ 修复装备时耐久度上限也会下降,提供同时修复耐久度和上限的功能
# ⑥ 装备卖出价格随耐久度打折
#==============================================================================
module Game_Equip
## 耐久度上限(指所有装备耐久度上限不可超过的值)
MaxDur = 999
# 忽略耐久度的防具类型(0:盾 1:头盔 2:衣服 3:装饰 4:武器)
# 非忽略耐久度 且未定义耐久度,则被认为"无法破坏"
NoDur = [3]
# 降低耐久度的基本机率最小值和最大值(大于0小于1)
Dur_BaseDec = [0.25, 0.75]
# 修复装备时耐久度上限减少量
MaxDur_Dec = 1
# 装备耐久度剩余多少比值(0到1)时提示
Show_If_Lower = 0.5
# 损坏时装备显示颜色
BrokenColor = Color.new(255,0,0)
# 耐久度占总价格比值(0到1)
Dur_Price = 0.7
end
module RPG
class BaseItem
#------------------------------------------------------------------------
# 是否被破坏
#------------------------------------------------------------------------
def broken?
return false
end
end
end
module RPG
class Weapon < BaseItem
include Game_Equip
#------------------------------------------------------------------------
# 附加属性
#------------------------------------------------------------------------
attr_accessor :base_id
attr_reader :maxdur
attr_reader :dur
attr_reader :indesctructible
#------------------------------------------------------------------------
# 是否无耐久度
#------------------------------------------------------------------------
def nodur
return NoDur.include? 4
end
#------------------------------------------------------------------------
# 是否被破坏
#------------------------------------------------------------------------
def broken?
return false if dur.nil?
return true if dur.zero?
end
#------------------------------------------------------------------------
# 是否需修复
#------------------------------------------------------------------------
def need_repair?(hyper)
return false if dur.nil?
return false if hyper.nil?
max = hyper ? read_note('耐久度').to_i : maxdur
return true if max > dur
return false
end
#------------------------------------------------------------------------
# 耐久度初始化
#------------------------------------------------------------------------
def inidur
d = read_note('耐久度').to_i
if d.zero?
@indesctructible = true
else
@indesctructible = false
@maxdur = @dur = [d, MaxDur].min
end
end
#------------------------------------------------------------------------
# 耐久度损耗
#------------------------------------------------------------------------
def decdur(n = 1)
return if @dur.nil?
n = [n, maxdur].min
@dur -= n unless nodur or indesctructible or dur < n
@dur -= 1
end
#------------------------------------------------------------------------
# 耐久度修复
#------------------------------------------------------------------------
def repair
return false if dur.nil?
if dur < maxdur and maxdur > 0
@maxdur -= MaxDur_Dec if @maxdur - @dur > MaxDur_Dec
@dur = @maxdur
return true
else
return false
end
end
#------------------------------------------------------------------------
# 耐久度全修复
#------------------------------------------------------------------------
def hyper_repair
return false if dur.nil?
max = read_note('耐久度').to_i
if dur < max and max > 0
@dur = @maxdur = max
return true
else
return false
end
end
#------------------------------------------------------------------------
# 攻击力
#------------------------------------------------------------------------
def atk
return [url=home.php?mod=space&uid=101599]@atk[/url] if dur.nil?
return dur > 0 ? [url=home.php?mod=space&uid=101599]@atk[/url] : 0
end
#------------------------------------------------------------------------
# 防御力
#------------------------------------------------------------------------
def def
return @def if dur.nil?
return dur > 0 ? @def : 0
end
#------------------------------------------------------------------------
# 魔力
#------------------------------------------------------------------------
def spi
return [url=home.php?mod=space&uid=87501]@SPI[/url] if dur.nil?
return dur > 0 ? [url=home.php?mod=space&uid=87501]@SPI[/url] : 0
end
#------------------------------------------------------------------------
# 敏捷
#------------------------------------------------------------------------
def agi
return [url=home.php?mod=space&uid=6136]@agi[/url] if dur.nil?
return dur > 0 ? [url=home.php?mod=space&uid=6136]@agi[/url] : 0
end
end
end
module RPG
class Armor < BaseItem
include Game_Equip
#------------------------------------------------------------------------
# 附加属性
#------------------------------------------------------------------------
attr_accessor :base_id
attr_reader :maxdur
attr_reader :dur
attr_reader :indesctructible
#------------------------------------------------------------------------
# 是否无耐久度
#------------------------------------------------------------------------
def nodur
return NoDur.include? kind
end
#------------------------------------------------------------------------
# 是否被破坏
#------------------------------------------------------------------------
def broken?
return false if dur.nil?
return true if dur.zero?
end
#------------------------------------------------------------------------
# 是否需修复
#------------------------------------------------------------------------
def need_repair?(hyper)
return false if dur.nil?
return false if hyper.nil?
max = hyper ? read_note('耐久度').to_i : maxdur
return true if max > dur
return false
end
#------------------------------------------------------------------------
# 耐久度初始化
#------------------------------------------------------------------------
def inidur
d = read_note('耐久度').to_i
if d.zero?
@indesctructible = true
else
@indesctructible = false
@maxdur = @dur = [d, MaxDur].min
end
end
#------------------------------------------------------------------------
# 耐久度损耗
#------------------------------------------------------------------------
def decdur(n = 1)
return if @dur.nil?
n = [n, maxdur].min
n = 0 if PA::USE_DUR == false #不使用耐久度时,耐久度不减少
@dur -= n unless nodur or indesctructible or dur < n
end
#------------------------------------------------------------------------
# 耐久度修复
#------------------------------------------------------------------------
def repair
return false if dur.nil?
if dur < maxdur and maxdur > 0
@maxdur -= MaxDur_Dec if @maxdur - @dur > MaxDur_Dec
@dur = @maxdur
return true
else
return false
end
end
#------------------------------------------------------------------------
# 耐久度全修复
#------------------------------------------------------------------------
def hyper_repair
return false if dur.nil?
max = read_note('耐久度').to_i
if dur < max and max > 0
@dur = @maxdur = max
return true
else
return false
end
end
#------------------------------------------------------------------------
# 攻击力
#------------------------------------------------------------------------
def atk
return [url=home.php?mod=space&uid=101599]@atk[/url] if dur.nil?
return dur > 0 ? @atk : 0
end
#------------------------------------------------------------------------
# 防御力
#------------------------------------------------------------------------
def def
return @def if dur.nil?
return dur > 0 ? @def : 0
end
#------------------------------------------------------------------------
# 魔力
#------------------------------------------------------------------------
def spi
return [url=home.php?mod=space&uid=87501]@SPI[/url] if dur.nil?
return dur > 0 ? @spi : 0
end
#------------------------------------------------------------------------
# 敏捷
#------------------------------------------------------------------------
def agi
return [url=home.php?mod=space&uid=6136]@agi[/url] if dur.nil?
return dur > 0 ? @agi : 0
end
#------------------------------------------------------------------------
# 闪避率
#------------------------------------------------------------------------
def eva
return [url=home.php?mod=space&uid=284635]@eva[/url] if dur.nil?
return dur > 0 ? [url=home.php?mod=space&uid=284635]@eva[/url] : 0
end
end
end
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# ● 判断是否防御
#--------------------------------------------------------------------------
def guarding?
return @action.guard?
end
#--------------------------------------------------------------------------
# ● 反映伤害
# user : 特技以及物品的使用者
# 调用前先设置 @hp_damage、@mp_damage、@absorbed。
#--------------------------------------------------------------------------
def execute_damage(user)
if @hp_damage > 0 # 伤害为正数
remove_states_shock # 受到攻击解除的状态
end
self.hp -= @hp_damage
self.mp -= @mp_damage
if @absorbed # 吸收的情况
user.hp += @hp_damage
user.mp += @mp_damage
end
end
#--------------------------------------------------------------------------
# ● 应用普通攻击效果
# attacker : 攻击者
#--------------------------------------------------------------------------
def attack_effect(attacker)
clear_action_results
unless attack_effective?(attacker)
@skipped = true
return
end
if rand(100) >= calc_hit(attacker) # 判断命中
@missed = true
return
end
if rand(100) < calc_eva(attacker) # 判断回避
@evaded = true
return
end
make_attack_damage_value(attacker) # 计算伤害
execute_damage(attacker) # 反映伤害
if @hp_damage == 0 # 判断物理攻击无效
return
end
## 处理耐久度
set_dur(attacker, self)
apply_state_changes(attacker) # 状态变化
end
#--------------------------------------------------------------------------
# ● 应用特技效果
# user : 特技使用者
# skill : 特技
#--------------------------------------------------------------------------
def skill_effect(user, skill)
clear_action_results
unless skill_effective?(user, skill)
@skipped = true
return
end
if rand(100) >= calc_hit(user, skill) # 判断命中
@missed = true
return
end
if rand(100) < calc_eva(user, skill) # 判断回避
@evaded = true
return
end
make_obj_damage_value(user, skill) # 计算伤害
make_obj_absorb_effect(user, skill) # 计算吸收效果
execute_damage(user) # 反映伤害
if skill.physical_attack and @hp_damage == 0 # 判断物理攻击无效
return
end
## 处理耐久度
set_dur(user, self, skill)
apply_state_changes(skill) # 状态变化
end
#--------------------------------------------------------------------------
# ● 应用物品效果
# user : 物品使用者
# item : 物品
#--------------------------------------------------------------------------
def item_effect(user, item)
clear_action_results
unless item_effective?(user, item)
@skipped = true
return
end
if rand(100) >= calc_hit(user, item) # 判断命中
@missed = true
return
end
if rand(100) < calc_eva(user, item) # 判断回避
@evaded = true
return
end
hp_recovery = calc_hp_recovery(user, item) # 计算 HP 回复量
mp_recovery = calc_mp_recovery(user, item) # 计算 MP 回复量
make_obj_damage_value(user, item) # 计算伤害
@hp_damage -= hp_recovery # 减去 HP 回复量
@mp_damage -= mp_recovery # 减去 MP 回复量
make_obj_absorb_effect(user, item) # 计算吸收效果
execute_damage(user) # 反映伤害
item_growth_effect(user, item) # 应用成长效果
if item.physical_attack and @hp_damage == 0 # 判断物理攻击无效
return
end
## 处理耐久度
set_dur(user, self, item)
apply_state_changes(item) # 状态变化
end
#--------------------------------------------------------------------------
# ● 处理耐久度
#--------------------------------------------------------------------------
def set_dur(attacker, defender, obj = nil)
## 补血时返回
return if @hp_damage < 0
atk_f = obj.nil? ? 1.0 : obj.atk_f / 100.0
w = defender.def / 999.0 * atk_f
a = attacker.atk / 999.0 * atk_f
w = [[w, Game_Equip::Dur_BaseDec[0]].max, Game_Equip::Dur_BaseDec[1]].min
a = [[a, Game_Equip::Dur_BaseDec[0]].max, Game_Equip::Dur_BaseDec[1]].min
if attacker.actor? and 0.8 > rand
weapons = attacker.weapons.compact
return if weapons.empty?
weapons[rand weapons.size].decdur
end
if defender.actor? and 0.8 > rand
armors = defender.armors.compact
return if armors.empty?
armors[rand armors.size].decdur
end
end
end
#==============================================================================
# ■ Window_ScrRepair
#==============================================================================
class Window_ScrRepair < Window_Item
#--------------------------------------------------------------------------
# ● 初始化对象
# x : 窗口的 X 坐标
# y : 窗口的 Y 坐标
# width : 窗口的宽
# height : 窗口的高
#--------------------------------------------------------------------------
def initialize(x, y, width, height, hyper_repair)
super(x, y, width, height)
@column_max = 1
self.index = 0
@hyper_repair = hyper_repair
refresh
end
#--------------------------------------------------------------------------
# ● 列表中包含的物品
# item : 物品
#--------------------------------------------------------------------------
def include?(item)
return true if item == nil
return false if item.is_a? RPG::Armor and item.base_id == PA::CRYSTAL
return true if item.is_a? RPG::Weapon and item.need_repair?(@hyper_repair)
return true if item.is_a? RPG::Armor and item.need_repair?(@hyper_repair)
return false
end
#--------------------------------------------------------------------------
# ● 是否可以使用物品
# item : 物品
#--------------------------------------------------------------------------
def enable?(item)
return true
end
end
#==============================================================================
# ■ Window_DestRepair #equip add clear items
#==============================================================================
class Window_DestRepair < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :equips
#--------------------------------------------------------------------------
# ● 初始化对象
# x : 窗口的 X 坐标
# y : 窗口的 Y 坐标
# width : 窗口的宽
# height : 窗口的高
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super(x, y, width, height)
clear
end
#--------------------------------------------------------------------------
# ● 添加物品
#--------------------------------------------------------------------------
def add(item)
return if item.nil?
$game_party.lose_item(item, 1)
@equips << item
[url=home.php?mod=space&uid=370741]@Index[/url] += 1
draw_item(item)
end
#--------------------------------------------------------------------------
# ● 清除物品
#--------------------------------------------------------------------------
def clear
@equips = []
[url=home.php?mod=space&uid=370741]@Index[/url] = 0
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(0,0,self.contents.width-16,WLH,"请放入需修复的装备:")
end
#--------------------------------------------------------------------------
# ● 归还物品
#--------------------------------------------------------------------------
def revert
$game_party.gain_item(@equip, 1)
@equips.each{|i| $game_party.gain_item(i, 1)}
clear
end
#--------------------------------------------------------------------------
# ● 描绘项目
#--------------------------------------------------------------------------
def draw_item(item)
rect = Rect.new(4,WLH*@index,self.contents.width-8, WLH)
if item != nil
draw_item_name(item, rect.x, rect.y)
self.contents.draw_text(rect, sprintf(":%2d", 1), 2)
end
end
#--------------------------------------------------------------------------
# ● 更新帮助文本
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(item == nil ? "" : item.description)
end
end
#==============================================================================
# ■ Scene_Repair
#==============================================================================
class Scene_Repair < Scene_Base
include Game_Equip
#--------------------------------------------------------------------------
# ● 初始化对象
# menu_index : 指令光标初期位置
#--------------------------------------------------------------------------
def initialize(hyper_repair = false)
@hyper_repair = hyper_repair
end
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_menu_background
create_command_window
@name_window = Window_Base.new(0,0,128,56)
if @hyper_repair == true
@name_window.contents.draw_text(4,0,544,24,"特殊修理",0)
else
@name_window.contents.draw_text(4,0,544,24,"普通修理",0)
end
@help_window = Window_Process_Help.new
@help_window.contents.draw_text(0,0,352,24,"请选择需要修复的装备,按W确定。", 0)
@help_window.visible = true
@scrhelp_window = Window_Help.new
@gold_window = Window_Gold.new(384, 0)
@gold_need_window = Window_Gold_Need.new
@gold_need_window.set_text(0)
@scr_window = Window_ScrRepair.new(0,112,272,304,@hyper_repair)
@scr_window.active = true
@scr_window.help_window = @scrhelp_window
@dest_window = Window_DestRepair.new(272,112,272,304-56)
@result_window = Window_Base.new(80,56,384,80)
@result_window.active = false
@result_window.visible = false
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
dispose_command_window
@name_window.dispose
@gold_need_window.dispose
@help_window.dispose
@scrhelp_window.dispose
@gold_window.dispose
@scr_window.dispose
@dest_window.dispose
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
if @command_window.active
@scr_window.contents_opacity = 128
@command_window.contents_opacity = 255
update_command_selection
elsif @scr_window.active
@scr_window.contents_opacity = 255
@command_window.contents_opacity = 128
update_item_selection
elsif @result_window.active
update_result_window
end
@command_window.update
@gold_window.update
@scr_window.update
@dest_window.update
@help_window.update
@scrhelp_window.update
end
#--------------------------------------------------------------------------
# ● 生成指令窗口
#--------------------------------------------------------------------------
def create_command_window
s1 = "修理"
s2 = "退出"
@command_window = Window_Command.new(256, [s1, s2], 4, 0, 8)
@command_window.x = 128
@command_window.active = false
@command_window.contents_opacity = 128
end
#--------------------------------------------------------------------------
# ● 释放指令窗口
#--------------------------------------------------------------------------
def dispose_command_window
@command_window.dispose
end
#--------------------------------------------------------------------------
# ● 是否满足修复装备条件?
#--------------------------------------------------------------------------
def repairable?(equips)
return false if equips.empty?
price = 0
equips.each{|e| price += e.price*Game_Equip::Dur_Price*e.dur/e.maxdur}
return false if $game_party.gold < evaluate_price
## 扣钱
$game_party.lose_gold(evaluate_price)
## 修复
equips.each{|e| @hyper_repair ? e.hyper_repair : e.repair}
return true
end
#--------------------------------------------------------------------------
# ● 显示结果(包括处理金钱物品)
#--------------------------------------------------------------------------
def show_result
@result_window.active = true
@result_window.visible = true
if @dest_window.equips.empty?
@result_window.contents.clear
@result_window.contents.draw_text(0,0,352,24,"请放入装备!", 1)
return
end
if repairable?(@dest_window.equips)
@result_window.contents.clear
@result_window.contents.draw_text(0,0,352,24,"指定装备已被修复!", 1)
@dest_window.revert
Sound.play_shop
@gold_window.refresh
@gold_need_window.set_text(0)
else
@result_window.contents.clear
@result_window.contents.draw_text(0,0,352,24,"金钱不足,无法修复!", 1)
@dest_window.revert
Sound.play_actor_collapse
@gold_window.refresh
@gold_need_window.set_text(0)
end
end
#--------------------------------------------------------------------------
# ● 更新帮助文本
#--------------------------------------------------------------------------
def update_help(text)
@help_window.set_text2(text)
end
#--------------------------------------------------------------------------
# ● 更新指令窗口
#--------------------------------------------------------------------------
def update_command_selection
case @command_window.index
when 0
update_help("确定键开始修复装备")
when 1
update_help("退出修复界面")
end
if Input.trigger?(Input::B)
## 重来
Sound.play_cancel
@scr_window.active = true
@command_window.active = false
elsif Input.trigger?(Input::C)
case @command_window.index
when 0 # 修复
Sound.play_decision
@command_window.active = false
@scr_window.active = false
######### 显示修复结果,归还物品
show_result
when 1 # 退出
Sound.play_decision
@dest_window.revert
$scene = Scene_Map.new
end
end
end
#--------------------------------------------------------------------------
# ● 更新选择物品
#--------------------------------------------------------------------------
def update_item_selection
if Input.trigger?(Input::R)
Sound.play_decision
@command_window.active = true
@scr_window.active = false
return
end
if Input.trigger?(Input::B) or Input.trigger?(Input::L)
Sound.play_cancel
if @dest_window.equips == []
@dest_window.revert
$scene = Scene_Map.new
return
end
@dest_window.revert
@scr_window.refresh
@scr_window.active = true
@help_window.contents.clear
@help_window.contents.draw_text(0,0,352,24,"请选择需要修复的装备,按W确定。", 0)
end
if Input.trigger?(Input::C)
@item = @scr_window.item
number = $game_party.item_number(@item)
if @item == nil or number == 0
Sound.play_buzzer
else
Sound.play_shop
@dest_window.add(@scr_window.item)
@scr_window.refresh
@gold_need_window.set_text(evaluate_price)
end
end
end
#--------------------------------------------------------------------------
# ● 修理估价
#--------------------------------------------------------------------------
def evaluate_price
price = 0
@dest_window.equips.each{|e| price += e.price*Game_Equip::Dur_Price*e.dur/e.maxdur }
price = price.round
return (@hyper_repair == true ? (5 * price) : (1 * price))
end
#--------------------------------------------------------------------------
# ● 更新结果窗体
#--------------------------------------------------------------------------
def update_result_window
if Input.trigger?(Input::B) or Input.trigger?(Input::C)
Sound.play_decision
@scr_window.refresh
@scr_window.active = true
@result_window.active = false
@result_window.visible = false
end
end
end