查看: 2024|回复: 2

[已经解决] RTAB魔法反射特效如何实现随机目标?

[复制链接]
梦石
0
星屑
50
在线时间
381 小时
注册时间
2012-8-13
回帖
103
发表于 2012-11-23 12:21:55 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 tyq4590 于 2012-11-24 23:19 编辑

脚本用的是RTAB自带的魔法反射脚本,代码如下(我稍微改了一下,把技能必须是魔法的判定取消了,这样只要是技能就可以反射):

[pre lang="ruby" line="1"]# ▼▲▼ XRXS27. 特殊効果 SuperEX「魔法反射」 ver.1.03 ▼▲▼
# by 桜雅 在土, clum-sea

#==============================================================================
# □ カスタマイズポイント
#==============================================================================
class Scene_Battle
  MAGIC_REFREX_STATE_NAME         = "反射"   # 「魔法反射」状态名
  MAGIC_REFREX_ANIMATION_ID       =  263          #  魔法反射的动画ID
  REFREX_PENETRATION_ELEMENT_NAME = "反射贯通"   # 「反射貫通」属性名
end

#=============================================================================
# ◇ 「魔法反射」ステート by 桜雅 在土
#=============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # ● スキルまたはアイテムの対象側バトラー設定
  #--------------------------------------------------------------------------
  alias xrxs_magic_refrex_set_target_battlers set_target_battlers
  def set_target_battlers(scope,battler)
    xrxs_magic_refrex_set_target_battlers(scope,battler)
    # スキル使用時
    if battler.current_action.kind == 1
      # 魔法である場合
        element_id = get_refrex_penetration_id
        # スキルに反射貫通が付加されているか。
        skill_state_penetration(@skill, element_id, battler)
        if battler.penetration != true
          # 検索
          for target in battler.target.dup
            # 魔法反射ステートにかかっているか?
            state_id = get_magical_refrex_id
            if state_id != nil and target.state?(state_id)
              # 反射---
              if rand(10) < 5
                target.refrexed = true
                battler.target.delete(target)
                unless battler.target.include?(battler)
                  battler.target.push(battler)
                end
              end
              # ---反射の設定完了
            end
          end
        end
    end
  end
  #--------------------------------------------------------------------------
  # ● スキルに反射貫通属性が付加されているか
  #--------------------------------------------------------------------------
  def skill_state_penetration(skill, element_id, user)
    if skill.element_set.include?(element_id)
      # 反射フラグリセット
      user.refrexed = false
      # 貫通フラグをセット
      user.penetration = true
    end
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新 (メインフェーズ ステップ 4 : 対象側アニメーション)
  #--------------------------------------------------------------------------
  alias xrxs_magic_refrex_update_phase4_step4 update_phase4_step4
  def update_phase4_step4(battler)
    # 対象側アニメーション
    xrxs_magic_refrex_update_phase4_step4(battler)
    # 魔法反射(貫通しない場合)
    for target in $game_party.actors + $game_troop.enemies - battler.target
      next if target.refrexed == nil or target.refrexed == false
    #  target.animation_id = MAGIC_REFREX_ANIMATION_ID
    #  target.animation_hit = (target.damage != "Miss")
      target.animation.push([MAGIC_REFREX_ANIMATION_ID,
                                          (target.damage[battler] != "Miss")])
      # 反射フラグリセット
      target.refrexed = false
    end
    for target in battler.target
      # 反射フラグリセット
      target.refrexed = false
    end
    # 貫通フラグリセット
    battler.penetration = false
  end
  #--------------------------------------------------------------------------
  # ○ 魔法反射ステートのID取得
  #--------------------------------------------------------------------------
  def get_magical_refrex_id
    if @xrxs27_magic_refrex_state_id == nil
      result = nil
      for i in 1 ... $data_states.size
        if $data_states.name[/\A#{MAGIC_REFREX_STATE_NAME}\Z/]
          result = $data_states.id
          break
        end
      end
      @xrxs27_magic_refrex_state_id = result
    end
    return @xrxs27_magic_refrex_state_id
  end
  #--------------------------------------------------------------------------
  # ○ 反射貫通属性のID取得
  #--------------------------------------------------------------------------
  def get_refrex_penetration_id
    if @xrxs27_refrex_penetration_element_id == nil
      result = nil
      for i in 1 ... $data_system.elements.size
        if $data_system.elements == REFREX_PENETRATION_ELEMENT_NAME
          result = i
          break
        end
      end
      @xrxs27_refrex_penetration_element_id = result
    end
    return @xrxs27_refrex_penetration_element_id
  end
end
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler
  attr_accessor :refrexed
  attr_accessor :penetration
end
[/pre]

这个脚本的功能是受到魔法攻击的时候将攻击对象改为攻击者自身(也就是被谁攻击就反射给谁)。但是我想修改一下,让反射的时候将攻击对象改为在敌方队伍里随机选择目标(也就是说如果敌方队伍里有A、B、C三个敌人,那么主角受到A攻击时可以把攻击对象转移到A、B、C中任意一人身上)。望高手指点!
梦石
0
星屑
249
在线时间
584 小时
注册时间
2012-9-7
回帖
592
发表于 2012-11-24 13:31:13 | 显示全部楼层
本帖最后由 wingzeroplus 于 2012-11-24 13:44 编辑
  1. #=============================================================================
  2. # ◇ 「魔法反射」ステート by 桜雅 在土
  3. #=============================================================================
  4. class Scene_Battle
  5.   #--------------------------------------------------------------------------
  6.   # ● スキルまたはアイテムの対象側バトラー設定
  7.   #--------------------------------------------------------------------------
  8.   alias xrxs_magic_refrex_set_target_battlers set_target_battlers
  9.   def set_target_battlers(scope,battler)
  10.     xrxs_magic_refrex_set_target_battlers(scope,battler)
  11.     # スキル使用時
  12.     if battler.current_action.kind == 1
  13.       # 魔法である場合
  14.       if skill_is_a_magic?(@skill)
  15.         element_id = get_refrex_penetration_id
  16.         # スキルに反射貫通が付加されているか。
  17.         skill_state_penetration(@skill, element_id, battler)
  18.         if battler.penetration != true
  19.           # 検索
  20.           for target in battler.target.dup
  21.             # 魔法反射ステートにかかっているか?
  22.             state_id = get_magical_refrex_id
  23.             if state_id != nil and target.state?(state_id)
  24.               # 反射---
  25.               target.refrexed = true
  26.               battler.target.delete(target)
  27. ################################
  28.              if battler.is_a?(Game_Enemy)
  29.                if @skill.scope==1
  30.                for enemy in $game_troop.enemies
  31.                  if enemy.exist?
  32.                   battler.target = [$game_troop.random_target_enemy]
  33.                  battler.target -=[battler] if battler.current_action.self_exclusion
  34.             battler.target = [battler.target[rand(battler.target.size)]]
  35.                 end
  36.                end
  37.                elsif @skill.scope==3 or @skill.scope==5
  38.                for actor in $game_party.actors
  39.                  if actor.exist?
  40.                    battler.target.push(actor)
  41.                    battler.target -=[battler] if battler.current_action.self_exclusion
  42.            battler.target = [battler.target[rand(battler.target.size)]]
  43.                 end
  44.                end
  45.                end
  46.              end
  47.             
  48.             if battler.is_a?(Game_Actor)
  49.               if @skill.scope==3 or @skill.scope==5
  50.                  for enemy in $game_troop.enemies
  51.                  if enemy.exist?
  52.                   battler.target = [$game_troop.random_target_enemy]
  53.                   battler.target -=[battler] if battler.current_action.self_exclusion
  54.         battler.target = [battler.target[rand(battler.target.size)]]
  55.                  end
  56.                 end
  57.               elsif @skill.scope==1
  58.                 for actor in $game_party.actors
  59.                  if actor.exist?
  60.                    battler.target.push(actor)
  61.                    battler.target -=[battler] if battler.current_action.self_exclusion
  62.            battler.target = [battler.target[rand(battler.target.size)]]
  63.                  end
  64.                 end
  65.               end
  66.             end
  67. #####################################           
  68.               # ---反射の設定完了
  69.             end
  70.           end
  71.         end
  72.       end
  73.     end
  74.   end
复制代码
把中间##那段替换相应的位置就可以
不过我把反射的定义改了,单体才能反射,全体魔法不能反射,下面是我自己改的定义
  def skill_is_a_magic?(skill)
    return false unless skill.is_a?(RPG::Skill)
   return (skill.atk_f ==0 and (skill.scope==1 or skill.scope==3 or skill.scope==5))  
end
end
LZ对何种技能才能反射的定义需要如何改的话,自己看着办吧,我只提供随机反射的效果

评分

参与人数 1梦石 +1 收起 理由
hcm + 1 认可答案

查看全部评分

FTM正式版已经发布,点击图片开启传送门
回复

使用道具 举报

梦石
0
星屑
50
在线时间
381 小时
注册时间
2012-8-13
回帖
103
 楼主| 发表于 2012-11-24 19:18:40 | 显示全部楼层
wingzeroplus 发表于 2012-11-24 17:31
把中间##那段替换相应的位置就可以
不过我把反射的定义改了,单体才能反射,全体魔法不能反射,下面是我自 ...

试了一下,是我要的效果。多谢啦!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部