赞 | 0 |
VIP | 0 |
好人卡 | 20 |
积分 | 17 |
经验 | 42858 |
最后登录 | 2024-9-22 |
在线时间 | 761 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 1696
- 在线时间
- 761 小时
- 注册时间
- 2013-9-23
- 帖子
- 211
|
- #==============================================================================
- # ■ 敌人AI强化
- #==============================================================================
- # 使敌人行动的目标具有优先级
- # ---------------------------------------------------------------------------
- # by Shad3Light 2014/03/20
- #==============================================================================
- # 写在敌人备注栏内的一些标记
- # <target [action_id] [shortcut]>
- # [action_id] :行动ID 这个ID是敌人行动栏内设置的行动的顺序 由上至下为1,2,3 …
- # [shortcut] :优先准则 决定优先对那种情况下的目标使用 种类如下
- # low_hp :HP最低
- # high_hp :HP最高
- # low_hp_rate :HP率最低
- # high_hp_rate :HP率最高
- # low_mp :MP最低
- # high_mp :MP最高
- # low_mp_rate :MP率最低
- # high_mp_rate :MP率最高
- # low_tp :TP最低
- # high_tp :TP最高
- # low_tp_rate :TP率最低
- # high_tp_rate :TP率最高
- # self
- # not_self
- # ---------------------------------------------------------------------------
- # 例子:
- # <target 1 high_hp>
- # 一般情况下第一个行动是"攻击" 目标是敌方HP最高者
- # <target 2 low_hp_rate>
- # 目标是HP比率最低者 如果第二个行动是治疗 那么将为HP残量最低的角色提供治疗
- # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- # 如果要使自己成为目标
- # <target eval [action_id]>
- # [eval]
- # </target eval>
- # 这里的 [eval] 是ruby的一个运算式,以返回-1, 0 或 1 。
- # [eval]里的a和b表示战斗者的序列
- #
- # 例如:让敌人优先攻击埃里克
- # <target eval 2>
- # if a.name == "埃里克"
- # -1
- # elsif b.name == "埃里克"
- # 1
- # else
- # a.hp <=> b.hp
- # end
- # </target eval>
- # ---------------------------------------------------------------------------
- # 注意:
- # VA自身的战斗方式是回合制,敌人的行动就和我方一样是在回合开始时指定好的。
- # 如果这个敌人的目标因为受到其他敌人的治疗而使得HP不再满足需要治疗的条件了,
- # 这个敌人也不会把目标更改为其他的敌人或是采取其他的行动。
- #==============================================================================
- if $imported && $imported[:SHD_TargetingManipulator]
- msgbox "Warning: Targeting Priority Manipulator script is imported twice."
- else
- $imported = {} if $imported.nil?
- $imported[:SHD_TargetingManipulator] = true
- #==============================================================================
- # 重写:DataManager
- # self.load_database
- # Game_Action
- # set_enemy_action
- # 新增:DataManager
- # self.load_notetags_adv_ai_target
- # RPG::Enemy
- # load_notetags_adv_ai_target
- # RPG::Enemy::Action
- # targeting_shortcut (attr_reader)
- # targeting_shortcut=
- # targeting_eval (attr_reader)
- # targeting_eval=
- # use_adv_targeting?
- # Game_Action
- # set_ai_target
- # set_ai_opponent_target
- # set_ai_friend_target
- # ai_sorting
- # ai_sorting_extension
- #==============================================================================
- module SHD
- module REGEXP
- ENEMY_TARG_EVAL = /<targ(?:et){,1}?[-_ ]?eval[: ]+(\d+)[ ]*>(.*?)<\/targ(:?et){,1}?[-_ ]?eval>/im
- ENEMY_TARG_SHORTCUT = /<targ(?:et){,1}?[: ]+(\d+)[, ]+(\w+)>/i
- end
- end
- #==============================================================================
- module DataManager
- class <<self
- alias :load_database_adv_ai_target :load_database
- end
- #------------------------------
- def self.load_database
- load_database_adv_ai_target
- load_notetags_adv_ai_target
- end
- #------------------------------
- def self.load_notetags_adv_ai_target
- $data_enemies.each do |o|
- next if o.nil?
- o.load_notetags_adv_ai_target
- end
- end
- end
- #==============================================================================
- # RPG::Enemy
- #==============================================================================
- class RPG::Enemy < RPG::BaseItem
- #------------------------------
- def load_notetags_adv_ai_target
- self.note.split(/[\r\n]+/).each { |line|
- if line =~ SHD::REGEXP::ENEMY_TARG_SHORTCUT
- action_id = $1.to_i - 1
- if @actions[action_id]
- @actions[action_id].targeting_shortcut = $2.downcase.to_sym
- end
- end
- }
- self.note.scan(SHD::REGEXP::ENEMY_TARG_EVAL).each { |match|
- action_id = match[0].to_i - 1
- if @actions[action_id]
- @actions[action_id].targeting_eval = match[1]
- end
- }
- end
- end
- #==============================================================================
- # RPG::Enemy::Action
- #==============================================================================
- class RPG::Enemy::Action
- attr_reader :targeting_shortcut
- attr_reader :targeting_eval
- #------------------------------
- def use_adv_targeting?
- @use_adv_targeting
- end
- #------------------------------
- def targeting_shortcut=(symbol)
- @targeting_shortcut = symbol
- @use_adv_targeting = true
- end
- #------------------------------
- def targeting_eval=(string)
- @targeting_shortcut = :eval
- @targeting_eval = string
- @use_adv_targeting = true
- end
- end
- #==============================================================================
- # Game_Action
- #==============================================================================
- class Game_Action
- alias :set_enemy_action_ai_prio :set_enemy_action
- def set_enemy_action(action)
- set_enemy_action_ai_prio(action)
- set_ai_target(action) if action
- end
- #------------------------------
- def set_ai_target(action)
- return unless action.use_adv_targeting?
- if item.for_opponent?
- set_ai_opponent_target(action)
- elsif item.for_friend?
- set_ai_friend_target(action)
- end
- end
- #------------------------------
- def set_ai_opponent_target(action)
- candidates = opponents_unit.alive_members
- candidates.sort! { |a, b| ai_sorting(a, b, action) }
- @target_index = candidates[0].index
- end
- #------------------------------
- def set_ai_friend_target(action)
- if item.for_dead_friend?
- candidates = friends_unit.dead_members
- else
- candidates = friends_unit.alive_members
- end
- candidates.sort! { |a, b| ai_sorting(a, b, action) }
- @target_index = candidates[0].index
- end
- #------------------------------
- def ai_sorting(a, b, action)
- case action.targeting_shortcut
- when :low_hp
- return a.hp <=> b.hp
- when :high_hp
- return b.hp <=> a.hp
- when :low_hp_rate
- return a.hp_rate <=> b.hp_rate
- when :high_hp_rate
- return b.hp_rate <=> a.hp_rate
- when :low_mp
- return a.mp <=> b.mp
- when :high_mp
- return b.mp <=> a.mp
- when :low_mp_rate
- return a.mp_rate <=> b.mp_rate
- when :high_mp_rate
- return b.mp_rate <=> a.mp_rate
- when :low_tp
- return a.tp <=> b.tp
- when :high_tp
- return b.tp <=> a.tp
- when :low_tp_rate
- return a.tp_rate <=> b.tp_rate
- when :high_tp_rate
- return b.tp_rate <=> a.tp_rate
- when :self
- return a == subject ? -1 : rand(2)
- when :not_self
- return a != subject ? rand(2) - 1 : 1
- when :eval
- return eval(action.targeting_eval)
- else
- return ai_sorting_extension(a, b, action)
- end
- end
- #------------------------------
- def ai_sorting_extension(a, b, action)
- return 0
- end
- end
- end
复制代码 原脚本不知道跑哪去了,以上是脑补+机翻+人工人话化...你懂的,一般机翻出来的东西都比较让人不知道说的是啥,
所以使用方法有啥不准确的地方,本渣灰常任性地概不负责,呵呵。 |
评分
-
查看全部评分
|