Project1

标题: 敌人行动条件修改 [打印本页]

作者: soulsaga    时间: 2018-12-23 15:50
标题: 敌人行动条件修改
本帖最后由 soulsaga 于 2018-12-23 23:08 编辑

RUBY 代码复制
  1. STATEIF = [1,2,3]#判断的状态ID
  2.  
  3. class Game_Enemy < Game_Battler
  4. #--------------------------------------------------------------------------
  5. # ● 生成行动
  6. #--------------------------------------------------------------------------
  7. def make_action
  8. # 清除当前行动
  9. self.current_action.clear
  10. # 无法行动的情况
  11. unless self.movable?
  12. # 过程结束
  13. return
  14. end
  15. # 抽取现在有效的行动
  16. available_actions = []
  17. rating_max = 0
  18. for action in self.actions
  19. # 确认回合条件
  20. n = $game_temp.battle_turn
  21. a = action.condition_turn_a
  22. b = action.condition_turn_b
  23. if (b == 0 and n != a) or
  24. (b > 0 and (n < 1 or n < a or n % b != a % b))
  25. next
  26. end
  27. # 确认 HP 条件
  28. if self.hp * 100.0 / self.maxhp > action.condition_hp
  29. next
  30. end
  31. # 确认等级条件
  32. if $game_party.max_level < action.condition_level
  33. next
  34. end
  35. # 确认开关条件
  36. switch_id = action.condition_switch_id
  37. if switch_id > 0 and $game_switches[switch_id] == false
  38. next
  39. end
  40. # 确认状态条件BY:灯笼菜刀王修改
  41. next if $game_switches[switch_id] and (STATEIF & self.states).empty?
  42. # 符合条件 : 添加本行动
  43. available_actions.push(action)
  44. if action.rating > rating_max
  45. rating_max = action.rating
  46. end
  47. end
  48. # 最大概率值作为 3 合计计算(0 除外)
  49. ratings_total = 0
  50. for action in available_actions
  51. if action.rating > rating_max - 3
  52. ratings_total += action.rating - (rating_max - 3)
  53. end
  54. end
  55. # 概率合计不为 0 的情况下
  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. end


用法:敌人行动条件随便打勾一个开关,当敌人拥有1或2或3号状态时才许可使用该技能 1,2,3,可以自行修改
作者: RyanBern    时间: 2018-12-23 22:56
能否加上一些转载的来源呢?




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