Project1

标题: rmxp嘲讽技能问题 [打印本页]

作者: lijin123    时间: 2024-9-14 16:35
标题: rmxp嘲讽技能问题
最近想在一款游戏里增加一个嘲讽类的技能,就是使用完以后怪我强制攻击使用者,但好像没办法用公共事件实现,必须用脚本,有没有大佬能提供一个,万分感谢
作者: 契约师Vi    时间: 2024-9-17 18:05
https://www.bilibili.com/video/B ... _history.page.click
rpgmaker的嘲讽技能怎么用开关和变量来做
作者: 无忧谷主幻    时间: 2024-10-3 04:24
RUBY 代码复制
  1. #===============================================================================
  2. =begin
  3. 嘲讽技能
  4.  
  5. 2023/1/13
  6. By : 真·可乐
  7. 修正了嘲讽状态下,战斗中强制行动无效的问题
  8.  
  9. 2018/7/20
  10. By : Zen Cola
  11. 个人lofter :[url]http://zencola.lofter.com/[/url]
  12. =end
  13. #===============================================================================
  14.  
  15.  
  16.  
  17.  
  18. module Taunt
  19. TAUNTSTATE = 51 #嘲讽状态对应的ID
  20.  
  21.  
  22.  
  23.   #判断是否有人嘲讽了的方法
  24.   def is_someone_taunt?
  25.  
  26.     $game_party.actors.each do |target|
  27.          if target.states.include?(TAUNTSTATE)
  28.           return true
  29.            break
  30.          end
  31.        end
  32.        return false
  33.      end
  34.  
  35.   #判断谁嘲讽了的方法
  36.   def who_taunt
  37.     taunt = Array.new
  38.      $game_party.actors.each do |target|
  39.          if target.states.include?(TAUNTSTATE)
  40.           next if target.hp0? #死掉就不算了
  41.            taunt.push(target)
  42.          end
  43.        end
  44.        return taunt
  45.     end
  46.  
  47.   end
  48.  
  49.  
  50. class Scene_Battle
  51.   include Taunt
  52. alias update_phase4_step2_zen_cola201884 update_phase4_step2
  53. def update_phase4_step2
  54.    #让敌人在进行目标选择前再进行一次行动准备
  55.     # Make enemy action
  56.     for enemy in $game_troop.enemies
  57.        if enemy.is_a?(Game_Enemy)
  58.          next if enemy.current_action.forcing  #2023113 ZK修正了这里
  59.          enemy.make_action
  60.        end
  61.     end
  62.    update_phase4_step2_zen_cola201884
  63. end
  64.  
  65.  
  66.   alias set_target_battlers_zen_cola201884 set_target_battlers
  67.   def set_target_battlers(scope)
  68.     set_target_battlers_zen_cola201884(scope)
  69.      return if !@active_battler.is_a?(Game_Enemy)
  70.     #有人嘲讽,此时的技能目标选择
  71.     # If battler performing action is enemy
  72.     if is_someone_taunt?
  73.       @target_battlers.clear
  74.  
  75.       case scope
  76.       when 1  # single enemy
  77.  
  78.         #@target_battlers.push($game_party.smooth_target_actor(index))
  79.         tat = who_taunt
  80.         @target_battlers.push(tat[rand(tat.size)])
  81.       when 2  # all enemies
  82.         for actor in $game_party.actors
  83.           if actor.exist?
  84.             @target_battlers.push(actor)
  85.           end
  86.         end
  87.  
  88.       end
  89.     end
  90. end
  91.  
  92. alias make_basic_action_result_zen_cola2018720 make_basic_action_result
  93.   def make_basic_action_result
  94.     if is_someone_taunt? and @active_battler.is_a?(Game_Enemy)
  95.       if @active_battler.current_action.basic == 0
  96.       # Set anaimation ID
  97.       @animation1_id = @active_battler.animation1_id
  98.       @animation2_id = @active_battler.animation2_id
  99.       # If action battler is enemy
  100.       if @active_battler.is_a?(Game_Enemy)
  101.  
  102.         if @active_battler.restriction == 3
  103.           target = $game_troop.random_target_enemy
  104.  
  105.         elsif @active_battler.restriction == 2
  106.           target = $game_party.random_target_actor
  107.  
  108.         else
  109.  
  110.          wt = who_taunt
  111.         target = wt[rand(wt.size)]
  112.  
  113.         end
  114.       end
  115.  
  116.       # Set array of targeted battlers
  117.       @target_battlers = [target]
  118.       # Apply normal attack results
  119.       for target in @target_battlers
  120.  
  121.         target.attack_effect(@active_battler)
  122.       end
  123.       return
  124.  
  125.     end
  126.  
  127.   end
  128.   make_basic_action_result_zen_cola2018720
  129. end
  130. end
  131.  
  132.  
  133. class Game_Enemy
  134.    include Taunt
  135.    alias make_action_zen_cola2018720 make_action
  136.    def make_action
  137.    if is_someone_taunt?
  138.      make_action_someone_taunt
  139.      return
  140.    end
  141.    make_action_zen_cola2018720
  142.    end
  143.  
  144. #有人嘲讽的情况下选择技能      
  145. def make_action_someone_taunt
  146.       # Clear current action
  147.     self.current_action.clear
  148.     # If unable to move
  149.     unless self.movable?
  150.       # End Method
  151.       return
  152.     end
  153.     # Extract current effective actions
  154.     available_actions = []
  155.     rating_max = 0
  156.     for action in self.actions
  157.       #跳过防御逃跑和什么都不干
  158.       next if action.kind == 0 and action.basic >= 1 and action.basic <= 3
  159.       #跳过无威力和威力为负的技能
  160.       next if action.kind == 1 and verifyskill(action.skill_id)
  161.       # Confirm turn conditions
  162.       n = $game_temp.battle_turn
  163.       a = action.condition_turn_a
  164.       b = action.condition_turn_b
  165.       if (b == 0 and n != a) or
  166.          (b > 0 and (n < 1 or n < a or n % b != a % b))
  167.         next
  168.       end
  169.       # Confirm HP conditions
  170.       if self.hp * 100.0 / self.maxhp > action.condition_hp
  171.         next
  172.       end
  173.       # Confirm level conditions
  174.       if $game_party.max_level < action.condition_level
  175.         next
  176.       end
  177.       # Confirm switch conditions
  178.       switch_id = action.condition_switch_id
  179.       if switch_id > 0 and $game_switches[switch_id] == false
  180.         next
  181.       end
  182.       # Add this action to applicable conditions
  183.       available_actions.push(action)
  184.       if action.rating > rating_max
  185.         rating_max = action.rating
  186.       end
  187.     end
  188.     # Calculate total with max rating value at 3 (exclude 0 or less)
  189.     ratings_total = 0
  190.     for action in available_actions
  191.       if action.rating > rating_max - 3
  192.         ratings_total += action.rating - (rating_max - 3)
  193.       end
  194.     end
  195.     # If ratings total isn't 0
  196.     if ratings_total > 0
  197.       # Create random numbers
  198.       value = rand(ratings_total)
  199.       # Set things that correspond to created random numbers as current action
  200.       for action in available_actions
  201.         if action.rating > rating_max - 3
  202.           if value < action.rating - (rating_max - 3)
  203.             self.current_action.kind = action.kind
  204.             self.current_action.basic = action.basic
  205.             self.current_action.skill_id = action.skill_id
  206.             self.current_action.decide_random_target_for_enemy
  207.             return
  208.           else
  209.             value -= action.rating - (rating_max - 3)
  210.           end
  211.         end
  212.       end
  213.     end
  214.   end
  215.  
  216.  
  217.  
  218.     #判断技能的威力
  219.     def verifyskill(id)
  220.     return true if $data_skills[id].power <= 0
  221.   end
  222.  
  223. end





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