Project1

标题: 请教设置当敌人有第15号状态时50%几率发动第8号技能的方法 [打印本页]

作者: taeckle    时间: 2022-3-1 10:19
标题: 请教设置当敌人有第15号状态时50%几率发动第8号技能的方法
本帖最后由 taeckle 于 2022-3-3 06:40 编辑

数据里没有根据敌人自身状态设置行为的选项,

所以我想自己做个根据敌人自身状态设置发动某个技能,比如我想让1到40号敌人在有第15号状态的情况下50%几率发动第8号技能

还请大家指点一二,多谢了!

敌人行为设置_数据库.png (42.25 KB, 下载次数: 5)

敌人行为设置_数据库.png

作者: 灯笼菜刀王    时间: 2022-3-1 10:50
本帖最后由 灯笼菜刀王 于 2022-3-1 11:11 编辑

首先, 把猫大的这个脚本塞进去 https://rpg.blue/thread-488418-1-1.html

然后, 把这个脚本塞到main前
  1. def emy_use?
  2.   return false if !$game_temp.in_battle
  3.   return false if (a = $scene.instance_variable_get(:@active_battler)).nil?
  4.   return false if !a.is_a?(Game_Enemy)
  5.   return false if !(1..40).include?(a.id)
  6.   return false if !a.stete?(2)
  7.   return false if rand(100) < 50
  8.   return true
  9. end
  10. class Scene_Battle
  11.   alias oxox_update_phase4_step1 update_phase4_step1
  12.   def update_phase4_step1
  13.     oxox_update_phase4_step1
  14.     @active_battler.make_action if @active_battler.is_a?(Game_Enemy)
  15.   end
  16. end
复制代码


然后找个开关 把名字改成  =emy_use?

然后, 把你要释放的技能, 出现条件里调用这个开关, 搞定收工
作者: taeckle    时间: 2022-3-3 06:52
本帖最后由 taeckle 于 2022-3-3 11:08 编辑
灯笼菜刀王 发表于 2022-3-1 10:50
首先, 把猫大的这个脚本塞进去 https://rpg.blue/thread-488418-1-1.html

然后, 把这个脚本塞到main前


大神我自己用了一个比较笨的方法也能达到相同的目的,还请大神过目:
在默认脚本中找到Game_Enemy类下的def make_action, 然后用下面的代码替换掉整个默认def make_action:

  1.   def make_action
  2.     # 清除当前行动
  3.     self.current_action.clear
  4.     # 无法行动的情况
  5.     unless self.movable?
  6.       # 过程结束
  7.       return
  8.     end
  9.     # 抽取现在有效的行动
  10.     available_actions = []
  11.     rating_max = 0
  12.     for action in self.actions
  13.       # 确认回合条件
  14.       n = $game_temp.battle_turn
  15.       a = action.condition_turn_a
  16.       b = action.condition_turn_b
  17.       if (b == 0 and n != a) or
  18.          (b > 0 and (n < 1 or n < a or n % b != a % b))
  19.         next
  20.       end
  21.       # 确认 HP 条件
  22.       if self.hp * 100.0 / self.maxhp > action.condition_hp
  23.         next
  24.       end
  25.       # 确认等级条件
  26.       if $game_party.max_level < action.condition_level
  27.         next
  28.       end
  29.       # 确认开关条件
  30.       switch_id = action.condition_switch_id
  31.       if switch_id > 0 and $game_switches[switch_id] == false
  32.         next
  33.       end
  34.       # 符合条件 : 添加本行动
  35.       available_actions.push(action)
  36.       if action.rating > rating_max
  37.         rating_max = action.rating
  38.       end
  39.     end
  40.     # 最大概率值作为 3 合计计算(0 除外)
  41.     ratings_total = 0
  42.     for action in available_actions
  43.       if action.rating > rating_max - 3
  44.         ratings_total += action.rating - (rating_max - 3)
  45.       end
  46.     end
  47.     #下面是我自己做的改动
  48.     if (1..40).to_a.include?(self.id)  #第1至40号敌人
  49.      if rand(100)<50 && self.state?(15) #有15号状态且50%时
  50.           self.current_action.kind = 1
  51.           self.current_action.basic = 0
  52.           self.current_action.skill_id = 8
  53.           self.current_action.decide_random_target_for_enemy
  54.           return
  55.      else
  56.       if ratings_total > 0
  57.       # 生成随机数
  58.       value = rand(ratings_total)
  59.       # 设置对应生成随机数的当前行动
  60.        for action in available_actions
  61.         if action.rating > rating_max - 3
  62.           if value < action.rating - (rating_max - 3)
  63.            self.current_action.kind = action.kind
  64.            self.current_action.basic = action.basic
  65.            self.current_action.skill_id = action.skill_id
  66.            self.current_action.decide_random_target_for_enemy
  67.            return
  68.           else
  69.            value -= action.rating - (rating_max - 3)
  70.           end
  71.         end
  72.        end
  73.       end         
  74.      end  
  75.     else
  76.      if ratings_total > 0
  77.       # 生成随机数
  78.       value = rand(ratings_total)
  79.       # 设置对应生成随机数的当前行动
  80.       for action in available_actions
  81.         if action.rating > rating_max - 3
  82.           if value < action.rating - (rating_max - 3)
  83.            self.current_action.kind = action.kind
  84.            self.current_action.basic = action.basic
  85.            self.current_action.skill_id = action.skill_id
  86.            self.current_action.decide_random_target_for_enemy
  87.            return
  88.           else
  89.            value -= action.rating - (rating_max - 3)
  90.           end
  91.         end
  92.       end
  93.      end
  94.     end      
  95.   end
复制代码






欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1