目录
定制小程序开发费用让我们继续跟着Scene_Title定制小程序开发费用的脉络走下去。定制小程序开发费用本来这一节是要解析Game_Party,但由于Game_Party定制小程序开发费用类中又反复使用了一个定制小程序开发费用较为简单的类Game_Actors,Game_Actors定制小程序开发费用中又使用了Game_Actor……最后定义到了Game_BattleAction。查找RMXP脚本系统中最基础的类的感觉就像中不停地查找节点的子树。所以我们就先解析Game_BattleAction。
Scene_Title用到的类的集合,红色透明框内是我们这几节的内容
具体定义
Game_BattleAction类代码解析
- #==============================================================================
-
- # ■ Game_BattleAction
-
- #------------------------------------------------------------------------------
-
- # 处理行动 (战斗中的行动) 的类。这个类在 Game_Battler 类
-
- # 的内部使用。 #可以理解为这个类专门为Game_Battler设计
-
- #==============================================================================
-
- class Game_BattleAction #这个类的对象们是一个个行为
-
- #--------------------------------------------------------------------------
-
- # ● 定义实例变量
-
- #--------------------------------------------------------------------------
-
- attr_accessor :speed # 速度
-
- attr_accessor :kind # 种类 (基本 / 特技 / 物品) #此行为的种类
-
- attr_accessor :basic # 基本 (攻击 / 防御 / 逃跑) #此行为的类别
-
- attr_accessor :skill_id # 特技 ID #此行为使用的特技的ID
-
- attr_accessor :item_id # 物品 ID #此行为使用的物品的ID
-
- attr_accessor :target_index # 对像索引 #此行为指向的对象 也就是目标的索引光标
-
- attr_accessor :forcing # 强制标志
-
- #--------------------------------------------------------------------------
-
- # ● 初始化对像
-
- #--------------------------------------------------------------------------
-
- def initialize
-
- clear #Ruby中有个clear方法用于清空数组,但此类中指的是同名的类方法
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 清除
-
- #--------------------------------------------------------------------------
-
- def clear #说是清除,其实也就是恢复初始化 #当然,这个类的定义就注定了初始化的对象是无效的
-
- @speed = 0
-
- @kind = 0
-
- @basic = 3
-
- @skill_id = 0
-
- @item_id = 0
-
- @target_index = -1
-
- @forcing = false
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 有效判定
-
- #--------------------------------------------------------------------------
-
- def valid?
-
- return (not (@kind == 0 and @basic == 3)) #除了基本逃跑其他都有效,因为基本动作只有攻击和防御
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 己方单体使用判定
-
- #--------------------------------------------------------------------------
-
- def for_one_friend? #判断是否可以使用
-
- # 种类为特技、效果范围是我方单体 (包含 HP 0) 的情况
-
- if @kind == 1 and [3, 5].include?($data_skills[@skill_id].scope) #RPG::Skill.scope 表明技能的使用对象范围
-
- return true
-
- end
-
- # 种类为物品、效果范围是我方单体 (包含 HP 0) 的情况
-
- if @kind == 2 and [3, 5].include?($data_items[@item_id].scope)
-
- return true
-
- end
-
- return false #其他情况不可使用
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 己方单体用 (HP 0) 判定
-
- #--------------------------------------------------------------------------
-
- def for_one_friend_hp0? #同上
-
- # 种类为特技、效果范围是我方单体 (HP 0) 的情况
-
- if @kind == 1 and [5].include?($data_skills[@skill_id].scope)
-
- return true
-
- end
-
- # 种类为物品、效果范围是我方单体 (HP 0) 的情况
-
- if @kind == 2 and [5].include?($data_items[@item_id].scope)
-
- return true
-
- end
-
- return false
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 随机目标 (角色用)
-
- #--------------------------------------------------------------------------
-
- def decide_random_target_for_actor
-
- # 效果范围的分支
-
- if for_one_friend_hp0? #如果可以使用在hp0的己方角色身上
-
- battler = $game_party.random_target_actor_hp0 #你们还真是盘根错节...以下三个方法随机获得一个符合条件的对象
-
- elsif for_one_friend? #如果可以使用在己方角色身上
-
- battler = $game_party.random_target_actor
-
- else #其他情况
-
- battler = $game_troop.random_target_enemy
-
- end
-
- # 对像存在的话取得索引、
-
- # 对像不存在的场合下清除行动
-
- if battler != nil #如果返回的Game_Battler对象不为空
-
- @target_index = battler.index #此行动的光标指向它
-
- else
-
- clear #清除行动
-
- end
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 随机目标 (敌人用)
-
- #--------------------------------------------------------------------------
-
- def decide_random_target_for_enemy #同上
-
- # 效果范围的分支
-
- if for_one_friend_hp0?
-
- battler = $game_troop.random_target_enemy_hp0
-
- elsif for_one_friend?
-
- battler = $game_troop.random_target_enemy
-
- else
-
- battler = $game_party.random_target_actor
-
- end
-
- # 对像存在的话取得索引、
-
- # 对像不存在的场合下清除行动
-
- if battler != nil
-
- @target_index = battler.index
-
- else
-
- clear
-
- end
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 最后的目标 (角色用)
-
- #--------------------------------------------------------------------------
-
- def decide_last_target_for_actor #决定了光标之后,决定使用对象 #应该是玩家手动选择目标之后把值存在@target_index内,然后此方法取出battler
-
- # 效果范围是己方单体以及行动者以外的敌人
-
- if @target_index == -1 #当光标有意义时才继续
-
- battler = nil
-
- elsif for_one_friend? #如果这是对友军使用的行动
-
- battler = $game_party.actors[@target_index]
-
- else #对敌军时
-
- battler = $game_troop.enemies[@target_index]
-
- end
-
- # 对像不存在的场合下清除行动
-
- if battler == nil or not battler.exist? #如果index指向的battler为nil
-
- clear #清除此行动
-
- end
-
- end
-
- #--------------------------------------------------------------------------
-
- # ● 最后的目标 (敌人用)
-
- #--------------------------------------------------------------------------
-
- def decide_last_target_for_enemy #同上
-
- # 效果范围是己方单体以敌人以外的角色
-
- if @target_index == -1
-
- battler = nil
-
- elsif for_one_friend?
-
- battler = $game_troop.enemies[@target_index]
-
- else
-
- battler = $game_party.actors[@target_index]
-
- end
-
- # 对像不存在的场合下清除行动
-
- if battler == nil or not battler.exist?
-
- clear
-
- end
-
- end
-
- end
关于::Skill.scope的取值范围
效果范围(0:无,1:敌单体,2:敌全体,3:己方单体,4:己方全体,5:己方单体(HP 0),6:己方全体(HP 0),7:使用者)。
由此可得以下情况的效果范围取值:
-对敌方:[1,2]
-对己方:[3,5],没有6是因为6情况直接战斗失败。
关于本类的意义
作为供Game_Battler类内部使用的类,Game_BattleAction类的主要作用是记录战斗中的行动。RMXP(默认代码)制作出来的是回合制RPG,也就是各个角色轮流行动计算伤害的游戏,相比于ARPG,RMXP中没有关于碰撞的计算,但是对于行动的先后等有所要求。本类中虽然没有计算的部分,却展示了RMXP是如何存储战斗中所有角色的行为。