赞 | 3 |
VIP | 0 |
好人卡 | 2 |
积分 | 21 |
经验 | 39083 |
最后登录 | 2023-4-3 |
在线时间 | 950 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 2111
- 在线时间
- 950 小时
- 注册时间
- 2015-7-16
- 帖子
- 767
|
- #encoding:utf-8
- #==============================================================================
- # ■ Game_BattlerBase
- #------------------------------------------------------------------------------
- # 管理战斗者的类。主要含有能力值计算的方法。Game_Battler 类的父类。
- #==============================================================================
- class Game_BattlerBase
- #--------------------------------------------------------------------------
- # ● 常量(特性)
- #--------------------------------------------------------------------------
- FEATURE_ELEMENT_RATE = 11 # 属性抗性
- FEATURE_DEBUFF_RATE = 12 # 弱化抗性
- FEATURE_STATE_RATE = 13 # 状态抗性
- FEATURE_STATE_RESIST = 14 # 状态免疫
- FEATURE_PARAM = 21 # 普通能力
- FEATURE_XPARAM = 22 # 添加能力
- FEATURE_SPARAM = 23 # 特殊能力
- FEATURE_ATK_ELEMENT = 31 # 攻击附带属性
- FEATURE_ATK_STATE = 32 # 攻击附带状态
- FEATURE_ATK_SPEED = 33 # 修正攻击速度
- FEATURE_ATK_TIMES = 34 # 添加攻击次数
- FEATURE_STYPE_ADD = 41 # 添加技能类型
- FEATURE_STYPE_SEAL = 42 # 禁用技能类型
- FEATURE_SKILL_ADD = 43 # 添加技能
- FEATURE_SKILL_SEAL = 44 # 禁用技能
- FEATURE_EQUIP_WTYPE = 51 # 可装备武器类型
- FEATURE_EQUIP_ATYPE = 52 # 可装备护甲类型
- FEATURE_EQUIP_FIX = 53 # 固定装备
- FEATURE_EQUIP_SEAL = 54 # 禁用装备
- FEATURE_SLOT_TYPE = 55 # 装备风格
- FEATURE_ACTION_PLUS = 61 # 添加行动次数
- FEATURE_SPECIAL_FLAG = 62 # 特殊标志
- FEATURE_COLLAPSE_TYPE = 63 # 消失效果
- FEATURE_PARTY_ABILITY = 64 # 队伍能力
- #--------------------------------------------------------------------------
- # ● 常量(特殊标志)
- #--------------------------------------------------------------------------
- FLAG_ID_AUTO_BATTLE = 0 # 自动战斗
- FLAG_ID_GUARD = 1 # 擅长防御
- FLAG_ID_SUBSTITUTE = 2 # 保护弱者
- FLAG_ID_PRESERVE_TP = 3 # 特技专注
- #--------------------------------------------------------------------------
- # ● 常量(能力强化/弱化图标的起始编号)
- #--------------------------------------------------------------------------
- ICON_BUFF_START = 64 # 强化(16 个)
- ICON_DEBUFF_START = 80 # 弱化(16 个)
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :hp # HP
- attr_reader :mp # MP
- attr_reader :tp # TP
- #--------------------------------------------------------------------------
- # ● 各种能力值的简易访问方法
- #--------------------------------------------------------------------------
- def mhp; param(0); end # 最大HP Maximum Hit Point
- def mmp; param(1); end # 最大MP Maximum Magic Point
- def atk; param(2); end # 物理攻击 ATtacK power
- def def; param(3); end # 物理防御 DEFense power
- def mat; param(4); end # 魔法攻击 Magic ATtack power
- def mdf; param(5); end # 魔法防御 Magic DeFense power
- def agi; param(6); end # 敏 捷 值 AGIlity
- def luk; param(7); end # 幸 运 值 LUcK
- def hit; xparam(0); end # 成功几率 HIT rate
- def eva; xparam(1); end # 闪避几率 EVAsion rate
- def cri; xparam(2); end # 必杀几率 CRItical rate
- def cev; xparam(3); end # 闪避必杀几率 Critical EVasion rate
- def mev; xparam(4); end # 闪避魔法几率 Magic EVasion rate
- def mrf; xparam(5); end # 反射魔法几率 Magic ReFlection rate
- def cnt; xparam(6); end # 反击几率 CouNTer attack rate
- def hrg; xparam(7); end # HP再生速度 Hp ReGeneration rate
- def mrg; xparam(8); end # MP再生速度 Mp ReGeneration rate
- def trg; xparam(9); end # TP再生速度 Tp ReGeneration rate
- def tgr; sparam(0); end # 受到攻击的几率 TarGet Rate
- def grd; sparam(1); end # 防御效果比率 GuaRD effect rate
- def rec; sparam(2); end # 恢复效果比率 RECovery effect rate
- def pha; sparam(3); end # 药理知识 PHArmacology
- def mcr; sparam(4); end # MP消费率 Mp Cost Rate
- def tcr; sparam(5); end # TP消耗率 Tp Charge Rate
- def pdr; sparam(6); end # 物理伤害加成 Physical Damage Rate
- def mdr; sparam(7); end # 魔法伤害加成 Magical Damage Rate
- def fdr; sparam(8); end # 地形伤害加成 Floor Damage Rate
- def exr; sparam(9); end # 经验获得加成 EXperience Rate
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- def initialize
- @hp = @mp = @tp = 0
- @hidden = false
- clear_param_plus
- clear_states
- clear_buffs
- end
- #--------------------------------------------------------------------------
- # ● 清除能力的增加值
- #--------------------------------------------------------------------------
- def clear_param_plus
- @param_plus = [0] * 8
- end
- #--------------------------------------------------------------------------
- # ● 清除状态信息
- #--------------------------------------------------------------------------
- def clear_states
- @states = []
- @state_turns = {}
- @state_steps = {}
- end
- #--------------------------------------------------------------------------
- # ● 消除状态
- #--------------------------------------------------------------------------
- def erase_state(state_id)
- @states.delete(state_id)
- @state_turns.delete(state_id)
- @state_steps.delete(state_id)
- end
- #--------------------------------------------------------------------------
- # ● 清除能力强化信息
- #--------------------------------------------------------------------------
- def clear_buffs
- @buffs = Array.new(8) { 0 }
- @buff_turns = {}
- end
- #--------------------------------------------------------------------------
- # ● 检査是否含有某状态
- #--------------------------------------------------------------------------
- def state?(state_id)
- @states.include?(state_id)
- end
- #--------------------------------------------------------------------------
- # ● 检査是否含有无法战斗状态
- #--------------------------------------------------------------------------
- def death_state?
- state?(death_state_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取无法战斗的状态ID
- #--------------------------------------------------------------------------
- def death_state_id
- return 1
- end
- #--------------------------------------------------------------------------
- # ● 获取当前状态的实例数组
- #--------------------------------------------------------------------------
- def states
- @states.collect {|id| $data_states[id] }
- end
- #--------------------------------------------------------------------------
- # ● 获取当前状态的图标编号数组
- #--------------------------------------------------------------------------
- def state_icons
- icons = states.collect {|state| state.icon_index }
- icons.delete(0)
- icons
- end
- #--------------------------------------------------------------------------
- # ● 获取当前强化/弱化状态的图标编号数组
- #--------------------------------------------------------------------------
- def buff_icons
- icons = []
- @buffs.each_with_index {|lv, i| icons.push(buff_icon_index(lv, i)) }
- icons.delete(0)
- icons
- end
- #--------------------------------------------------------------------------
- # ● 获取强化/弱化状态的对应图标编号
- #--------------------------------------------------------------------------
- def buff_icon_index(buff_level, param_id)
- if buff_level > 0
- return ICON_BUFF_START + (buff_level - 1) * 8 + param_id
- elsif buff_level < 0
- return ICON_DEBUFF_START + (-buff_level - 1) * 8 + param_id
- else
- return 0
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取所有拥有特性的实例的数组
- #--------------------------------------------------------------------------
- def feature_objects
- states
- end
- #--------------------------------------------------------------------------
- # ● 获取所有特性实例的数组
- #--------------------------------------------------------------------------
- def all_features
- feature_objects.inject([]) {|r, obj| r + obj.features }
- end
- #--------------------------------------------------------------------------
- # ● 获取特性实例的数组(限定特性代码)
- #--------------------------------------------------------------------------
- def features(code)
- all_features.select {|ft| ft.code == code }
- end
- #--------------------------------------------------------------------------
- # ● 获取特性实例的数组(限定特性代码和数据ID)
- #--------------------------------------------------------------------------
- def features_with_id(code, id)
- all_features.select {|ft| ft.code == code && ft.data_id == id }
- end
- #--------------------------------------------------------------------------
- # ● 计算特性值的乘积
- #--------------------------------------------------------------------------
- def features_pi(code, id)
- features_with_id(code, id).inject(1.0) {|r, ft| r *= ft.value }
- end
- #--------------------------------------------------------------------------
- # ● 计算特性值的总和(指定数据ID)
- #--------------------------------------------------------------------------
- def features_sum(code, id)
- features_with_id(code, id).inject(0.0) {|r, ft| r += ft.value }
- end
- #--------------------------------------------------------------------------
- # ● 计算特性值的总和(不限定数据ID)
- #--------------------------------------------------------------------------
- def features_sum_all(code)
- features(code).inject(0.0) {|r, ft| r += ft.value }
- end
- #--------------------------------------------------------------------------
- # ● 特性的集合和计算
- #--------------------------------------------------------------------------
- def features_set(code)
- features(code).inject([]) {|r, ft| r |= [ft.data_id] }
- end
- #--------------------------------------------------------------------------
- # ● 获取普通能力的基础值
- #--------------------------------------------------------------------------
- def param_base(param_id)
- return 0
- end
- #--------------------------------------------------------------------------
- # ● 获取普通能力的附加值
- #--------------------------------------------------------------------------
- def param_plus(param_id)
- @param_plus[param_id]
- end
- #--------------------------------------------------------------------------
- # ● 获取普通能力的最小值
- #--------------------------------------------------------------------------
- def param_min(param_id)
- return 0 if param_id == 1 # MMP
- return 1
- end
- #--------------------------------------------------------------------------
- # ● 获取普通能力的最大值
- #--------------------------------------------------------------------------
- def param_max(param_id)
- return 999999 if param_id == 0 # MHP
- return 9999 if param_id == 1 # MMP
- return 999
- end
- #--------------------------------------------------------------------------
- # ● 获取普通能力的变化率
- #--------------------------------------------------------------------------
- def param_rate(param_id)
- features_pi(FEATURE_PARAM, param_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取普通能力的强化/弱化变化率
- #--------------------------------------------------------------------------
- def param_buff_rate(param_id)
- @buffs[param_id] * 0.25 + 1.0
- end
- #--------------------------------------------------------------------------
- # ● 获取普通能力
- #--------------------------------------------------------------------------
- def param(param_id)
- value = param_base(param_id) + param_plus(param_id)
- value *= param_rate(param_id) * param_buff_rate(param_id)
- [[value, param_max(param_id)].min, param_min(param_id)].max.to_i
- end
- #--------------------------------------------------------------------------
- # ● 获取添加能力
- #--------------------------------------------------------------------------
- def xparam(xparam_id)
- features_sum(FEATURE_XPARAM, xparam_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取特殊能力
- #--------------------------------------------------------------------------
- def sparam(sparam_id)
- features_pi(FEATURE_SPARAM, sparam_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取属性抗性
- #--------------------------------------------------------------------------
- def element_rate(element_id)
- features_pi(FEATURE_ELEMENT_RATE, element_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取弱化抗性
- #--------------------------------------------------------------------------
- def debuff_rate(param_id)
- features_pi(FEATURE_DEBUFF_RATE, param_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取状态抗性
- #--------------------------------------------------------------------------
- def state_rate(state_id)
- features_pi(FEATURE_STATE_RATE, state_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取免疫状态数组
- #--------------------------------------------------------------------------
- def state_resist_set
- features_set(FEATURE_STATE_RESIST)
- end
- #--------------------------------------------------------------------------
- # ● 判定状态是否免疫
- #--------------------------------------------------------------------------
- def state_resist?(state_id)
- state_resist_set.include?(state_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取攻击附加属性
- #--------------------------------------------------------------------------
- def atk_elements
- features_set(FEATURE_ATK_ELEMENT)
- end
- #--------------------------------------------------------------------------
- # ● 获取攻击附加状态
- #--------------------------------------------------------------------------
- def atk_states
- features_set(FEATURE_ATK_STATE)
- end
- #--------------------------------------------------------------------------
- # ● 获取攻击附加状态的发动几率
- #--------------------------------------------------------------------------
- def atk_states_rate(state_id)
- features_sum(FEATURE_ATK_STATE, state_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取修正攻击速度
- #--------------------------------------------------------------------------
- def atk_speed
- features_sum_all(FEATURE_ATK_SPEED)
- end
- #--------------------------------------------------------------------------
- # ● 获取添加攻击次数
- #--------------------------------------------------------------------------
- def atk_times_add
- [features_sum_all(FEATURE_ATK_TIMES), 0].max
- end
- #--------------------------------------------------------------------------
- # ● 获取添加技能类型
- #--------------------------------------------------------------------------
- def added_skill_types
- features_set(FEATURE_STYPE_ADD)
- end
- #--------------------------------------------------------------------------
- # ● 判定技能类型是否被禁用
- #--------------------------------------------------------------------------
- def skill_type_sealed?(stype_id)
- features_set(FEATURE_STYPE_SEAL).include?(stype_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取添加的技能
- #--------------------------------------------------------------------------
- def added_skills
- features_set(FEATURE_SKILL_ADD)
- end
- #--------------------------------------------------------------------------
- # ● 判定技能是否被禁用
- #--------------------------------------------------------------------------
- def skill_sealed?(skill_id)
- features_set(FEATURE_SKILL_SEAL).include?(skill_id)
- end
- #--------------------------------------------------------------------------
- # ● 判定武器是否可以装备
- #--------------------------------------------------------------------------
- def equip_wtype_ok?(wtype_id)
- features_set(FEATURE_EQUIP_WTYPE).include?(wtype_id)
- end
- #--------------------------------------------------------------------------
- # ● 判定护甲是否可以装备
- #--------------------------------------------------------------------------
- def equip_atype_ok?(atype_id)
- features_set(FEATURE_EQUIP_ATYPE).include?(atype_id)
- end
- #--------------------------------------------------------------------------
- # ● 判定是否固定武器
- #--------------------------------------------------------------------------
- def equip_type_fixed?(etype_id)
- features_set(FEATURE_EQUIP_FIX).include?(etype_id)
- end
- #--------------------------------------------------------------------------
- # ● 判定装备是否被禁用
- #--------------------------------------------------------------------------
- def equip_type_sealed?(etype_id)
- features_set(FEATURE_EQUIP_SEAL).include?(etype_id)
- end
- #--------------------------------------------------------------------------
- # ● 获取装备风格
- #--------------------------------------------------------------------------
- def slot_type
- features_set(FEATURE_SLOT_TYPE).max || 0
- end
- #--------------------------------------------------------------------------
- # ● 判定是否双持武器
- #--------------------------------------------------------------------------
- def dual_wield?
- slot_type == 1
- end
- #--------------------------------------------------------------------------
- # ● 获取添加行动次数几率的数组
- #--------------------------------------------------------------------------
- def action_plus_set
- features(FEATURE_ACTION_PLUS).collect {|ft| ft.value }
- end
- #--------------------------------------------------------------------------
- # ● 判定特殊标志
- #--------------------------------------------------------------------------
- def special_flag(flag_id)
- features(FEATURE_SPECIAL_FLAG).any? {|ft| ft.data_id == flag_id }
- end
- #--------------------------------------------------------------------------
- # ● 获取消失效果
- #--------------------------------------------------------------------------
- def collapse_type
- features_set(FEATURE_COLLAPSE_TYPE).max || 0
- end
- #--------------------------------------------------------------------------
- # ● 判定队伍能力
- #--------------------------------------------------------------------------
- def party_ability(ability_id)
- features(FEATURE_PARTY_ABILITY).any? {|ft| ft.data_id == ability_id }
- end
- #--------------------------------------------------------------------------
- # ● 判定是否自动战斗
- #--------------------------------------------------------------------------
- def auto_battle?
- special_flag(FLAG_ID_AUTO_BATTLE)
- end
- #--------------------------------------------------------------------------
- # ● 判定是否擅长防御
- #--------------------------------------------------------------------------
- def guard?
- special_flag(FLAG_ID_GUARD) && movable?
- end
- #--------------------------------------------------------------------------
- # ● 判定是否保护弱者
- #--------------------------------------------------------------------------
- def substitute?
- special_flag(FLAG_ID_SUBSTITUTE) && movable?
- end
- #--------------------------------------------------------------------------
- # ● 判定是否特技专注
- #--------------------------------------------------------------------------
- def preserve_tp?
- special_flag(FLAG_ID_PRESERVE_TP)
- end
- #--------------------------------------------------------------------------
- # ● 添加能力
- #--------------------------------------------------------------------------
- def add_param(param_id, value)
- @param_plus[param_id] += value
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 更改 HP
- #--------------------------------------------------------------------------
- def hp=(hp)
- @hp = hp
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 更改 MP
- #--------------------------------------------------------------------------
- def mp=(mp)
- @mp = mp
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 增减 HP (事件用)
- # value : 数值
- # enable_death : 是否允许致死
- #--------------------------------------------------------------------------
- def change_hp(value, enable_death)
- if !enable_death && @hp + value <= 0
- self.hp = 1
- else
- self.hp += value
- end
- end
- #--------------------------------------------------------------------------
- # ● 更改 TP
- #--------------------------------------------------------------------------
- def tp=(tp)
- @tp = [[tp, max_tp].min, 0].max
- end
- #--------------------------------------------------------------------------
- # ● 获取 TP 的最大值
- #--------------------------------------------------------------------------
- def max_tp
- return 100
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- state_resist_set.each {|state_id| erase_state(state_id) }
- @hp = [[@hp, mhp].min, 0].max
- @mp = [[@mp, mmp].min, 0].max
- @hp == 0 ? add_state(death_state_id) : remove_state(death_state_id)
- end
- #--------------------------------------------------------------------------
- # ● 完全恢复
- #--------------------------------------------------------------------------
- def recover_all
- clear_states
- @hp = mhp
- @mp = mmp
- end
- #--------------------------------------------------------------------------
- # ● 获取 HP 的比率
- #--------------------------------------------------------------------------
- def hp_rate
- @hp.to_f / mhp
- end
- #--------------------------------------------------------------------------
- # ● 获取 MP 的比率
- #--------------------------------------------------------------------------
- def mp_rate
- mmp > 0 ? @mp.to_f / mmp : 0
- end
- #--------------------------------------------------------------------------
- # ● 获取 TP 的比率
- #--------------------------------------------------------------------------
- def tp_rate
- @tp.to_f / 100
- end
- #--------------------------------------------------------------------------
- # ● 隐藏
- #--------------------------------------------------------------------------
- def hide
- @hidden = true
- end
- #--------------------------------------------------------------------------
- # ● 出现
- #--------------------------------------------------------------------------
- def appear
- @hidden = false
- end
- #--------------------------------------------------------------------------
- # ● 获取隐藏状态
- #--------------------------------------------------------------------------
- def hidden?
- @hidden
- end
- #--------------------------------------------------------------------------
- # ● 判定是否存在
- #--------------------------------------------------------------------------
- def exist?
- !hidden?
- end
- #--------------------------------------------------------------------------
- # ● 判定是否死亡
- #--------------------------------------------------------------------------
- def dead?
- exist? && death_state?
- end
- #--------------------------------------------------------------------------
- # ● 判定是否存活
- #--------------------------------------------------------------------------
- def alive?
- exist? && !death_state?
- end
- #--------------------------------------------------------------------------
- # ● 判定是否正常
- #--------------------------------------------------------------------------
- def normal?
- exist? && restriction == 0
- end
- #--------------------------------------------------------------------------
- # ● 判定是否可以输入指令
- #--------------------------------------------------------------------------
- def inputable?
- normal? && !auto_battle?
- end
- #--------------------------------------------------------------------------
- # ● 判定是否可以行动
- #--------------------------------------------------------------------------
- def movable?
- exist? && restriction < 4
- end
- #--------------------------------------------------------------------------
- # ● 判定是否处于混乱
- #--------------------------------------------------------------------------
- def confusion?
- exist? && restriction >= 1 && restriction <= 3
- end
- #--------------------------------------------------------------------------
- # ● 获取混乱等级
- #--------------------------------------------------------------------------
- def confusion_level
- confusion? ? restriction : 0
- end
- #--------------------------------------------------------------------------
- # ● 判定是否队友
- #--------------------------------------------------------------------------
- def actor?
- return false
- end
- #--------------------------------------------------------------------------
- # ● 判定是否敌人
- #--------------------------------------------------------------------------
- def enemy?
- return false
- end
- #--------------------------------------------------------------------------
- # ● 状态排序
- # 依照优先度排列数组 @states,高优先度显示的状态排在前面。
- #--------------------------------------------------------------------------
- def sort_states
- @states = @states.sort_by {|id| [-$data_states[id].priority, id] }
- end
- #--------------------------------------------------------------------------
- # ● 获取限制状态
- # 从当前附加的状态中获取限制最大的状态
- #--------------------------------------------------------------------------
- def restriction
- states.collect {|state| state.restriction }.push(0).max
- end
- #--------------------------------------------------------------------------
- # ● 获取最重要的状态信息
- #--------------------------------------------------------------------------
- def most_important_state_text
- states.each {|state| return state.message3 unless state.message3.empty? }
- return ""
- end
- #--------------------------------------------------------------------------
- # ● 判定是否装备着使用此技能所需要装备武器
- #--------------------------------------------------------------------------
- def skill_wtype_ok?(skill)
- return true
- end
- #--------------------------------------------------------------------------
- # ● 计算技能消费的 MP
- #--------------------------------------------------------------------------
- def skill_mp_cost(skill)
- (skill.mp_cost * mcr).to_i
- end
- #--------------------------------------------------------------------------
- # ● 计算技能消费的 TP
- #--------------------------------------------------------------------------
- def skill_tp_cost(skill)
- skill.tp_cost
- end
- #--------------------------------------------------------------------------
- # ● 判定是否足够扣除技能的使用消耗
- #--------------------------------------------------------------------------
- def skill_cost_payable?(skill)
- tp >= skill_tp_cost(skill) && mp >= skill_mp_cost(skill)
- end
- #--------------------------------------------------------------------------
- # ● 扣除技能的使用消耗
- #--------------------------------------------------------------------------
- def pay_skill_cost(skill)
- self.mp -= skill_mp_cost(skill)
- self.tp -= skill_tp_cost(skill)
- end
- #--------------------------------------------------------------------------
- # ● 检查是否可以使用技能/物品
- #--------------------------------------------------------------------------
- def occasion_ok?(item)
- $game_party.in_battle ? item.battle_ok? : item.menu_ok?
- end
- #--------------------------------------------------------------------------
- # ● 检查技能/物品的使用条件(共通)
- #--------------------------------------------------------------------------
- def usable_item_conditions_met?(item)
- movable? && occasion_ok?(item)
- end
- #--------------------------------------------------------------------------
- # ● 检查技能的使用条件
- #--------------------------------------------------------------------------
- def skill_conditions_met?(skill)
- usable_item_conditions_met?(skill) &&
- skill_wtype_ok?(skill) && skill_cost_payable?(skill) &&
- !skill_sealed?(skill.id) && !skill_type_sealed?(skill.stype_id)
- end
- #--------------------------------------------------------------------------
- # ● 检查物品的使用条件
- #--------------------------------------------------------------------------
- def item_conditions_met?(item)
- usable_item_conditions_met?(item) && $game_party.has_item?(item)
- end
- #--------------------------------------------------------------------------
- # ● 判定技能/使用物品是否可用
- #--------------------------------------------------------------------------
- def usable?(item)
- return skill_conditions_met?(item) if item.is_a?(RPG::Skill)
- return item_conditions_met?(item) if item.is_a?(RPG::Item)
- return false
- end
- #--------------------------------------------------------------------------
- # ● 判定物品是否可以装备
- #--------------------------------------------------------------------------
- def equippable?(item)
- return false unless item.is_a?(RPG::EquipItem)
- return false if equip_type_sealed?(item.etype_id)
- return equip_wtype_ok?(item.wtype_id) if item.is_a?(RPG::Weapon)
- return equip_atype_ok?(item.atype_id) if item.is_a?(RPG::Armor)
- return false
- end
- #--------------------------------------------------------------------------
- # ● 获取普通攻击的技能 ID
- #--------------------------------------------------------------------------
- def attack_skill_id
- return 1
- end
- #--------------------------------------------------------------------------
- # ● 获取防御的技能 ID
- #--------------------------------------------------------------------------
- def guard_skill_id
- return 2
- end
- #--------------------------------------------------------------------------
- # ● 判定是否能使用普通攻击
- #--------------------------------------------------------------------------
- def attack_usable?
- usable?($data_skills[attack_skill_id])
- end
- #--------------------------------------------------------------------------
- # ● 判定是否能进行防御
- #--------------------------------------------------------------------------
- def guard_usable?
- usable?($data_skills[guard_skill_id])
- end
- end
复制代码 以上為Game_BattlerBase,以下為Game_Battler- #encoding:utf-8
- #==============================================================================
- # ■ Game_Battler
- #------------------------------------------------------------------------------
- # 处理战斗者的类。Game_Actor 和 Game_Enemy 类的父类。
- #==============================================================================
- class Game_Battler < Game_BattlerBase
- #--------------------------------------------------------------------------
- # ● 常量(使用效果)
- #--------------------------------------------------------------------------
- EFFECT_RECOVER_HP = 11 # 恢复 HP
- EFFECT_RECOVER_MP = 12 # 恢复 MP
- EFFECT_GAIN_TP = 13 # 增加 TP
- EFFECT_ADD_STATE = 21 # 附加状态
- EFFECT_REMOVE_STATE = 22 # 解除状态
- EFFECT_ADD_BUFF = 31 # 强化能力
- EFFECT_ADD_DEBUFF = 32 # 弱化能力
- EFFECT_REMOVE_BUFF = 33 # 解除能力强化
- EFFECT_REMOVE_DEBUFF = 34 # 解除能力弱化
- EFFECT_SPECIAL = 41 # 特殊效果
- EFFECT_GROW = 42 # 能力提升
- EFFECT_LEARN_SKILL = 43 # 学会技能
- EFFECT_COMMON_EVENT = 44 # 公共事件
- #--------------------------------------------------------------------------
- # ● 常量(特殊效果)
- #--------------------------------------------------------------------------
- SPECIAL_EFFECT_ESCAPE = 0 # 撤退
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :battler_name # 战斗图像文件名
- attr_reader :battler_hue # 战斗图像色相
- attr_reader :action_times # 行动回数
- attr_reader :actions # 战斗行动(行动方)
- attr_reader :speed # 行动速度
- attr_reader :result # 行动结果(目标方)
- attr_accessor :last_target_index # 最后目标的索引
- attr_accessor :animation_id # 动画 ID
- attr_accessor :animation_mirror # 动画左右反转的标志
- attr_accessor :sprite_effect_type # 精灵的效果
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- def initialize
- @battler_name = ""
- @battler_hue = 0
- @actions = []
- @speed = 0
- @result = Game_ActionResult.new(self)
- @last_target_index = 0
- @guarding = false
- clear_sprite_effects
- super
- end
- #--------------------------------------------------------------------------
- # ● 清除精灵的效果
- #--------------------------------------------------------------------------
- def clear_sprite_effects
- @animation_id = 0
- @animation_mirror = false
- @sprite_effect_type = nil
- end
- #--------------------------------------------------------------------------
- # ● 清除战斗行动
- #--------------------------------------------------------------------------
- def clear_actions
- @actions.clear
- end
- #--------------------------------------------------------------------------
- # ● 清除状态信息
- #--------------------------------------------------------------------------
- def clear_states
- super
- @result.clear_status_effects
- end
- #--------------------------------------------------------------------------
- # ● 附加状态
- #--------------------------------------------------------------------------
- def add_state(state_id)
- if state_addable?(state_id)
- add_new_state(state_id) unless state?(state_id)
- reset_state_counts(state_id)
- @result.added_states.push(state_id).uniq!
- end
- end
- #--------------------------------------------------------------------------
- # ● 判定状态是否可以附加
- #--------------------------------------------------------------------------
- def state_addable?(state_id)
- alive? && $data_states[state_id] && !state_resist?(state_id) &&
- !state_removed?(state_id) && !state_restrict?(state_id)
- end
- #--------------------------------------------------------------------------
- # ● 判定状态是否已被解除
- #--------------------------------------------------------------------------
- def state_removed?(state_id)
- @result.removed_states.include?(state_id)
- end
- #--------------------------------------------------------------------------
- # ● 判定状态是否受到行动限制影响而无法附加
- #--------------------------------------------------------------------------
- def state_restrict?(state_id)
- $data_states[state_id].remove_by_restriction && restriction > 0
- end
- #--------------------------------------------------------------------------
- # ● 附加新的状态
- #--------------------------------------------------------------------------
- def add_new_state(state_id)
- die if state_id == death_state_id
- @states.push(state_id)
- on_restrict if restriction > 0
- sort_states
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 行动受到限制时的处理
- #--------------------------------------------------------------------------
- def on_restrict
- clear_actions
- states.each do |state|
- remove_state(state.id) if state.remove_by_restriction
- end
- end
- #--------------------------------------------------------------------------
- # ● 重置状态计数(回合数或步数)
- #--------------------------------------------------------------------------
- def reset_state_counts(state_id)
- state = $data_states[state_id]
- variance = 1 + [state.max_turns - state.min_turns, 0].max
- @state_turns[state_id] = state.min_turns + rand(variance)
- @state_steps[state_id] = state.steps_to_remove
- end
- #--------------------------------------------------------------------------
- # ● 解除状态
- #--------------------------------------------------------------------------
- def remove_state(state_id)
- if state?(state_id)
- revive if state_id == death_state_id
- erase_state(state_id)
- refresh
- @result.removed_states.push(state_id).uniq!
- end
- end
- #--------------------------------------------------------------------------
- # ● 死亡
- #--------------------------------------------------------------------------
- def die
- @hp = 0
- clear_states
- clear_buffs
- end
- #--------------------------------------------------------------------------
- # ● 复活
- #--------------------------------------------------------------------------
- def revive
- @hp = 1 if @hp == 0
- end
- #--------------------------------------------------------------------------
- # ● 撤退
- #--------------------------------------------------------------------------
- def escape
- hide if $game_party.in_battle
- clear_actions
- clear_states
- Sound.play_escape
- end
- #--------------------------------------------------------------------------
- # ● 强化能力
- #--------------------------------------------------------------------------
- def add_buff(param_id, turns)
- return unless alive?
- @buffs[param_id] += 1 unless buff_max?(param_id)
- erase_buff(param_id) if debuff?(param_id)
- overwrite_buff_turns(param_id, turns)
- @result.added_buffs.push(param_id).uniq!
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 弱化能力
- #--------------------------------------------------------------------------
- def add_debuff(param_id, turns)
- return unless alive?
- @buffs[param_id] -= 1 unless debuff_max?(param_id)
- erase_buff(param_id) if buff?(param_id)
- overwrite_buff_turns(param_id, turns)
- @result.added_debuffs.push(param_id).uniq!
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 解除能力强化/弱化状态
- #--------------------------------------------------------------------------
- def remove_buff(param_id)
- return unless alive?
- return if @buffs[param_id] == 0
- erase_buff(param_id)
- @buff_turns.delete(param_id)
- @result.removed_buffs.push(param_id).uniq!
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 消除能力强化/弱化
- #--------------------------------------------------------------------------
- def erase_buff(param_id)
- @buffs[param_id] = 0
- @buff_turns[param_id] = 0
- end
- #--------------------------------------------------------------------------
- # ● 判定能力强化状态
- #--------------------------------------------------------------------------
- def buff?(param_id)
- @buffs[param_id] > 0
- end
- #--------------------------------------------------------------------------
- # ● 判定能力弱化状态
- #--------------------------------------------------------------------------
- def debuff?(param_id)
- @buffs[param_id] < 0
- end
- #--------------------------------------------------------------------------
- # ● 判定能力强化是否为最大程度
- #--------------------------------------------------------------------------
- def buff_max?(param_id)
- @buffs[param_id] == 2
- end
- #--------------------------------------------------------------------------
- # ● 判定能力弱化是否为最大程度
- #--------------------------------------------------------------------------
- def debuff_max?(param_id)
- @buffs[param_id] == -2
- end
- #--------------------------------------------------------------------------
- # ● 重新设置能力强化/弱化的回合数
- # 如果新的回合数比较短,保持原值。
- #--------------------------------------------------------------------------
- def overwrite_buff_turns(param_id, turns)
- @buff_turns[param_id] = turns if @buff_turns[param_id].to_i < turns
- end
- #--------------------------------------------------------------------------
- # ● 更新状态的回总数数
- #--------------------------------------------------------------------------
- def update_state_turns
- states.each do |state|
- @state_turns[state.id] -= 1 if @state_turns[state.id] > 0
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新强化/弱化的回总数数
- #--------------------------------------------------------------------------
- def update_buff_turns
- @buff_turns.keys.each do |param_id|
- @buff_turns[param_id] -= 1 if @buff_turns[param_id] > 0
- end
- end
- #--------------------------------------------------------------------------
- # ● 解除战斗状态
- #--------------------------------------------------------------------------
- def remove_battle_states
- states.each do |state|
- remove_state(state.id) if state.remove_at_battle_end
- end
- end
- #--------------------------------------------------------------------------
- # ● 解除所有的强化/弱化状态
- #--------------------------------------------------------------------------
- def remove_all_buffs
- @buffs.size.times {|param_id| remove_buff(param_id) }
- end
- #--------------------------------------------------------------------------
- # ● 状态的自动解除
- # timing : 时机(1:行动结束 2:回合结束)
- #--------------------------------------------------------------------------
- def remove_states_auto(timing)
- states.each do |state|
- if @state_turns[state.id] == 0 && state.auto_removal_timing == timing
- remove_state(state.id)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 强化/弱化的自动解除
- #--------------------------------------------------------------------------
- def remove_buffs_auto
- @buffs.size.times do |param_id|
- next if @buffs[param_id] == 0 || @buff_turns[param_id] > 0
- remove_buff(param_id)
- end
- end
- #--------------------------------------------------------------------------
- # ● 受到伤害时解除状态
- #--------------------------------------------------------------------------
- def remove_states_by_damage
- states.each do |state|
- if state.remove_by_damage && rand(100) < state.chance_by_damage
- remove_state(state.id)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 决定行动回数
- #--------------------------------------------------------------------------
- def make_action_times
- action_plus_set.inject(1) {|r, p| rand < p ? r + 1 : r }
- end
- #--------------------------------------------------------------------------
- # ● 生成战斗行动
- #--------------------------------------------------------------------------
- def make_actions
- clear_actions
- return unless movable?
- @actions = Array.new(make_action_times) { Game_Action.new(self) }
- end
- #--------------------------------------------------------------------------
- # ● 决定行动速度
- #--------------------------------------------------------------------------
- def make_speed
- @speed = @actions.collect {|action| action.speed }.min || 0
- end
- #--------------------------------------------------------------------------
- # ● 获取当前战斗行动
- #--------------------------------------------------------------------------
- def current_action
- @actions[0]
- end
- #--------------------------------------------------------------------------
- # ● 移除当前战斗行动
- #--------------------------------------------------------------------------
- def remove_current_action
- @actions.shift
- end
- #--------------------------------------------------------------------------
- # ● 强制战斗行动
- #--------------------------------------------------------------------------
- def force_action(skill_id, target_index)
- clear_actions
- action = Game_Action.new(self, true)
- action.set_skill(skill_id)
- if target_index == -2
- action.target_index = last_target_index
- elsif target_index == -1
- action.decide_random_target
- else
- action.target_index = target_index
- end
- @actions.push(action)
- end
- #--------------------------------------------------------------------------
- # ● 计算伤害
- #--------------------------------------------------------------------------
- def make_damage_value(user, item)
- value = item.damage.eval(user, self, $game_variables)
- value *= item_element_rate(user, item)
- value *= pdr if item.physical?
- value *= mdr if item.magical?
- value *= rec if item.damage.recover?
- value = apply_critical(value) if @result.critical
- value = apply_variance(value, item.damage.variance)
- value = apply_guard(value)
- @result.make_damage(value.to_i, item)
- end
- #--------------------------------------------------------------------------
- # ● 获取技能/物品的属性修正值
- #--------------------------------------------------------------------------
- def item_element_rate(user, item)
- if item.damage.element_id < 0
- user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
- else
- element_rate(item.damage.element_id)
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取属性的最大修正值,返回所有属性中最有效的一个
- # elements : 属性 ID 数组
- #--------------------------------------------------------------------------
- def elements_max_rate(elements)
- elements.inject([0.0]) {|r, i| r.push(element_rate(i)) }.max
- end
- #--------------------------------------------------------------------------
- # ● 应用关键一击
- #--------------------------------------------------------------------------
- def apply_critical(damage)
- damage * 3
- end
- #--------------------------------------------------------------------------
- # ● 应用离散度
- #--------------------------------------------------------------------------
- def apply_variance(damage, variance)
- amp = [damage.abs * variance / 100, 0].max.to_i
- var = rand(amp + 1) + rand(amp + 1) - amp
- damage >= 0 ? damage + var : damage - var
- end
- #--------------------------------------------------------------------------
- # ● 应用防御修正
- #--------------------------------------------------------------------------
- def apply_guard(damage)
- damage / (damage > 0 && guard? ? 2 * grd : 1)
- end
- #--------------------------------------------------------------------------
- # ● 处理伤害
- # 调用前需要设置好
- # @result.hp_damage @result.mp_damage
- # @result.hp_drain @result.mp_drain
- #--------------------------------------------------------------------------
- def execute_damage(user)
- on_damage(@result.hp_damage) if @result.hp_damage > 0
- self.hp -= @result.hp_damage
- self.mp -= @result.mp_damage
- user.hp += @result.hp_drain
- user.mp += @result.mp_drain
- end
- #--------------------------------------------------------------------------
- # ● 技能/使用物品
- # 对使用目标使用完毕后,应用对于使用目标以外的效果。
- #--------------------------------------------------------------------------
- def use_item(item)
- pay_skill_cost(item) if item.is_a?(RPG::Skill)
- consume_item(item) if item.is_a?(RPG::Item)
- item.effects.each {|effect| item_global_effect_apply(effect) }
- end
- #--------------------------------------------------------------------------
- # ● 消耗物品
- #--------------------------------------------------------------------------
- def consume_item(item)
- $game_party.consume_item(item)
- end
- #--------------------------------------------------------------------------
- # ● 应用对于使用目标以外的效果
- #--------------------------------------------------------------------------
- def item_global_effect_apply(effect)
- if effect.code == EFFECT_COMMON_EVENT
- $game_temp.reserve_common_event(effect.data_id)
- end
- end
- #--------------------------------------------------------------------------
- # ● 技能/物品的应用测试
- # 如果使用目标的 HP 或者 MP 全满时,禁止使用恢复道具。
- #--------------------------------------------------------------------------
- def item_test(user, item)
- return false if item.for_dead_friend? != dead?
- return true if $game_party.in_battle
- return true if item.for_opponent?
- return true if item.damage.recover? && item.damage.to_hp? && hp < mhp
- return true if item.damage.recover? && item.damage.to_mp? && mp < mmp
- return true if item_has_any_valid_effects?(user, item)
- return false
- end
- #--------------------------------------------------------------------------
- # ● 判定技能/物品是否有效果
- #--------------------------------------------------------------------------
- def item_has_any_valid_effects?(user, item)
- item.effects.any? {|effect| item_effect_test(user, item, effect) }
- end
- #--------------------------------------------------------------------------
- # ● 计算技能/物品的反击几率
- #--------------------------------------------------------------------------
- def item_cnt(user, item)
- return 0 unless item.physical? # 攻击类型不是物理攻击
- return 0 unless opposite?(user) # 队友无法反击
- return cnt # 返回反击几率
- end
- #--------------------------------------------------------------------------
- # ● 计算技能/物品的反射几率
- #--------------------------------------------------------------------------
- def item_mrf(user, item)
- return mrf if item.magical? # 是魔法攻击则返回反射魔法几率
- return 0
- end
- #--------------------------------------------------------------------------
- # ● 计算技能/物品的成功几率
- #--------------------------------------------------------------------------
- def item_hit(user, item)
- rate = item.success_rate * 0.01 # 获取成功几率
- rate *= user.hit if item.physical? # 物理攻击:计算成功几率的乘积
- return rate # 返回计算后的成功几率
- end
- #--------------------------------------------------------------------------
- # ● 计算技能/物品的闪避几率
- #--------------------------------------------------------------------------
- def item_eva(user, item)
- return eva if item.physical? # 是物理攻击则返回闪避几率
- return mev if item.magical? # 是魔法攻击则返回闪避魔法几率
- return 0
- end
- #--------------------------------------------------------------------------
- # ● 计算技能/物品的必杀几率
- #--------------------------------------------------------------------------
- def item_cri(user, item)
- item.damage.critical ? user.cri * (1 - cev) : 0
- end
- #--------------------------------------------------------------------------
- # ● 应用普通攻击的效果
- #--------------------------------------------------------------------------
- def attack_apply(attacker)
- item_apply(attacker, $data_skills[attacker.attack_skill_id])
- end
- #--------------------------------------------------------------------------
- # ● 应用技能/物品的效果
- #--------------------------------------------------------------------------
- def item_apply(user, item)
- @result.clear
- @result.used = item_test(user, item)
- @result.missed = (@result.used && rand >= item_hit(user, item))
- @result.evaded = ([email protected] && rand < item_eva(user, item))
- if @result.hit?
- unless item.damage.none?
- @result.critical = (rand < item_cri(user, item))
- make_damage_value(user, item)
- execute_damage(user)
- end
- item.effects.each {|effect| item_effect_apply(user, item, effect) }
- item_user_effect(user, item)
- end
- end
- #--------------------------------------------------------------------------
- # ● 测试使用效果
- #--------------------------------------------------------------------------
- def item_effect_test(user, item, effect)
- case effect.code
- when EFFECT_RECOVER_HP
- hp < mhp || effect.value1 < 0 || effect.value2 < 0
- when EFFECT_RECOVER_MP
- mp < mmp || effect.value1 < 0 || effect.value2 < 0
- when EFFECT_ADD_STATE
- !state?(effect.data_id)
- when EFFECT_REMOVE_STATE
- state?(effect.data_id)
- when EFFECT_ADD_BUFF
- !buff_max?(effect.data_id)
- when EFFECT_ADD_DEBUFF
- !debuff_max?(effect.data_id)
- when EFFECT_REMOVE_BUFF
- buff?(effect.data_id)
- when EFFECT_REMOVE_DEBUFF
- debuff?(effect.data_id)
- when EFFECT_LEARN_SKILL
- actor? && !skills.include?($data_skills[effect.data_id])
- else
- true
- end
- end
- #--------------------------------------------------------------------------
- # ● 应用使用效果
- #--------------------------------------------------------------------------
- def item_effect_apply(user, item, effect)
- method_table = {
- EFFECT_RECOVER_HP => :item_effect_recover_hp,
- EFFECT_RECOVER_MP => :item_effect_recover_mp,
- EFFECT_GAIN_TP => :item_effect_gain_tp,
- EFFECT_ADD_STATE => :item_effect_add_state,
- EFFECT_REMOVE_STATE => :item_effect_remove_state,
- EFFECT_ADD_BUFF => :item_effect_add_buff,
- EFFECT_ADD_DEBUFF => :item_effect_add_debuff,
- EFFECT_REMOVE_BUFF => :item_effect_remove_buff,
- EFFECT_REMOVE_DEBUFF => :item_effect_remove_debuff,
- EFFECT_SPECIAL => :item_effect_special,
- EFFECT_GROW => :item_effect_grow,
- EFFECT_LEARN_SKILL => :item_effect_learn_skill,
- EFFECT_COMMON_EVENT => :item_effect_common_event,
- }
- method_name = method_table[effect.code]
- send(method_name, user, item, effect) if method_name
- end
- #--------------------------------------------------------------------------
- # ● 应用“恢复 HP”效果
- #--------------------------------------------------------------------------
- def item_effect_recover_hp(user, item, effect)
- value = (mhp * effect.value1 + effect.value2) * rec
- value *= user.pha if item.is_a?(RPG::Item)
- value = value.to_i
- @result.hp_damage -= value
- @result.success = true
- self.hp += value
- end
- #--------------------------------------------------------------------------
- # ● 应用“恢复 MP”效果
- #--------------------------------------------------------------------------
- def item_effect_recover_mp(user, item, effect)
- value = (mmp * effect.value1 + effect.value2) * rec
- value *= user.pha if item.is_a?(RPG::Item)
- value = value.to_i
- @result.mp_damage -= value
- @result.success = true if value != 0
- self.mp += value
- end
- #--------------------------------------------------------------------------
- # ● 应用“增加 TP”效果
- #--------------------------------------------------------------------------
- def item_effect_gain_tp(user, item, effect)
- value = effect.value1.to_i
- @result.tp_damage -= value
- @result.success = true if value != 0
- self.tp += value
- end
- #--------------------------------------------------------------------------
- # ● 应用“附加状态”效果
- #--------------------------------------------------------------------------
- def item_effect_add_state(user, item, effect)
- if effect.data_id == 0
- item_effect_add_state_attack(user, item, effect)
- else
- item_effect_add_state_normal(user, item, effect)
- end
- end
- #--------------------------------------------------------------------------
- # ● 应用“状态附加”效果:普通攻击
- #--------------------------------------------------------------------------
- def item_effect_add_state_attack(user, item, effect)
- user.atk_states.each do |state_id|
- chance = effect.value1
- chance *= state_rate(state_id)
- chance *= user.atk_states_rate(state_id)
- chance *= luk_effect_rate(user)
- if rand < chance
- add_state(state_id)
- @result.success = true
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 应用“状态附加”效果:普通
- #--------------------------------------------------------------------------
- def item_effect_add_state_normal(user, item, effect)
- chance = effect.value1
- chance *= state_rate(effect.data_id) if opposite?(user)
- chance *= luk_effect_rate(user) if opposite?(user)
- if rand < chance
- add_state(effect.data_id)
- @result.success = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 应用“状态解除”效果
- #--------------------------------------------------------------------------
- def item_effect_remove_state(user, item, effect)
- chance = effect.value1
- if rand < chance
- remove_state(effect.data_id)
- @result.success = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 应用“强化能力”效果
- #--------------------------------------------------------------------------
- def item_effect_add_buff(user, item, effect)
- add_buff(effect.data_id, effect.value1)
- @result.success = true
- end
- #--------------------------------------------------------------------------
- # ● 应用“弱化能力”效果
- #--------------------------------------------------------------------------
- def item_effect_add_debuff(user, item, effect)
- chance = debuff_rate(effect.data_id) * luk_effect_rate(user)
- if rand < chance
- add_debuff(effect.data_id, effect.value1)
- @result.success = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 应用“解除能力强化”效果
- #--------------------------------------------------------------------------
- def item_effect_remove_buff(user, item, effect)
- remove_buff(effect.data_id) if @buffs[effect.data_id] > 0
- @result.success = true
- end
- #--------------------------------------------------------------------------
- # ● 应用“解除能力弱化”效果
- #--------------------------------------------------------------------------
- def item_effect_remove_debuff(user, item, effect)
- remove_buff(effect.data_id) if @buffs[effect.data_id] < 0
- @result.success = true
- end
- #--------------------------------------------------------------------------
- # ● 应用“特殊效果”效果
- #--------------------------------------------------------------------------
- def item_effect_special(user, item, effect)
- case effect.data_id
- when SPECIAL_EFFECT_ESCAPE
- escape
- end
- @result.success = true
- end
- #--------------------------------------------------------------------------
- # ● 应用“能力提升”效果
- #--------------------------------------------------------------------------
- def item_effect_grow(user, item, effect)
- add_param(effect.data_id, effect.value1.to_i)
- @result.success = true
- end
- #--------------------------------------------------------------------------
- # ● 应用“学会技能”效果
- #--------------------------------------------------------------------------
- def item_effect_learn_skill(user, item, effect)
- learn_skill(effect.data_id) if actor?
- @result.success = true
- end
- #--------------------------------------------------------------------------
- # ● 应用“公共事件”效果
- #--------------------------------------------------------------------------
- def item_effect_common_event(user, item, effect)
- end
- #--------------------------------------------------------------------------
- # ● 对技能/物品使用者的效果
- #--------------------------------------------------------------------------
- def item_user_effect(user, item)
- user.tp += item.tp_gain * user.tcr
- end
- #--------------------------------------------------------------------------
- # ● 获取幸运影响程度
- #--------------------------------------------------------------------------
- def luk_effect_rate(user)
- [1.0 + (user.luk - luk) * 0.001, 0.0].max
- end
- #--------------------------------------------------------------------------
- # ● 判定是否敌对关系
- #--------------------------------------------------------------------------
- def opposite?(battler)
- actor? != battler.actor?
- end
- #--------------------------------------------------------------------------
- # ● 在地图上受到伤害时的效果
- #--------------------------------------------------------------------------
- def perform_map_damage_effect
- end
- #--------------------------------------------------------------------------
- # ● 初始化目标 TP
- #--------------------------------------------------------------------------
- def init_tp
- self.tp = rand * 25
- end
- #--------------------------------------------------------------------------
- # ● 清除 TP
- #--------------------------------------------------------------------------
- def clear_tp
- self.tp = 0
- end
- #--------------------------------------------------------------------------
- # ● 受到伤害时增加的 TP
- #--------------------------------------------------------------------------
- def charge_tp_by_damage(damage_rate)
- self.tp += 50 * damage_rate * tcr
- end
- #--------------------------------------------------------------------------
- # ● HP 自动恢复
- #--------------------------------------------------------------------------
- def regenerate_hp
- damage = -(mhp * hrg).to_i
- perform_map_damage_effect if $game_party.in_battle && damage > 0
- @result.hp_damage = [damage, max_slip_damage].min
- self.hp -= @result.hp_damage
- end
- #--------------------------------------------------------------------------
- # ● 获取连续伤害最大值
- #--------------------------------------------------------------------------
- def max_slip_damage
- $data_system.opt_slip_death ? hp : [hp - 1, 0].max
- end
- #--------------------------------------------------------------------------
- # ● MP 自动恢复
- #--------------------------------------------------------------------------
- def regenerate_mp
- @result.mp_damage = -(mmp * mrg).to_i
- self.mp -= @result.mp_damage
- end
- #--------------------------------------------------------------------------
- # ● TP 自动恢复
- #--------------------------------------------------------------------------
- def regenerate_tp
- self.tp += 100 * trg
- end
- #--------------------------------------------------------------------------
- # ● 全部自动恢复
- #--------------------------------------------------------------------------
- def regenerate_all
- if alive?
- regenerate_hp
- regenerate_mp
- regenerate_tp
- end
- end
- #--------------------------------------------------------------------------
- # ● 战斗开始处理
- #--------------------------------------------------------------------------
- def on_battle_start
- init_tp unless preserve_tp?
- end
- #--------------------------------------------------------------------------
- # ● 战斗行动结束时的处理
- #--------------------------------------------------------------------------
- def on_action_end
- @result.clear
- remove_states_auto(1)
- remove_buffs_auto
- end
- #--------------------------------------------------------------------------
- # ● 回合结束处理
- #--------------------------------------------------------------------------
- def on_turn_end
- @result.clear
- regenerate_all
- update_state_turns
- update_buff_turns
- remove_states_auto(2)
- end
- #--------------------------------------------------------------------------
- # ● 战斗结束处理
- #--------------------------------------------------------------------------
- def on_battle_end
- @result.clear
- remove_battle_states
- remove_all_buffs
- clear_actions
- clear_tp unless preserve_tp?
- appear
- end
- #--------------------------------------------------------------------------
- # ● 被伤害时的处理
- #--------------------------------------------------------------------------
- def on_damage(value)
- remove_states_by_damage
- charge_tp_by_damage(value.to_f / mhp)
- end
- end
复制代码 麻煩大家了>< |
|