66RPG
本站首页
制作教程
文章作品
制作素材
原创游戏区
周边下载
本站论坛
 ※ 站内搜索
栏 目:
方 式:
关键词:
  
 ※ 教程分类
 RMXP 图文教学
 初级教学
 中级教学
 高级教学
 个人创意与研究
 RMXP 录像教学
 新人入门录像
 零散录像教学
 商业素材使用录像 ★
 周边教学
 美工 与 音乐
 RMXP 脚本发布
 游戏系统修改
 地图效果类
 战斗系统相关
 全新系统类
 API与高难度类
 RMVX 制作教学
 RMVX 初级教学
 RMVX 中级教程
 RMVX 高级教程
 RMVX 综合制作展
 ※ 无图目录 (按点击量横排序)


-- 66RPG全内容文字目录 --


 ※ 近期特色教学
战斗中机率反击 ( 66RPG, RPG MAKER XP教程 )
 本站首页→制作教程→RMVX 初级教学

战斗中机率反击


教学摘要:
  环境设定:
① 受到普通攻击以及带有"反击"属性的特技攻击,才能发生反击
② 默认发动反击的机率为50%,可自定义
③ 防御可提高30%反击机率
④ 武器或特技即使带"双重打击"属性,也只反击一次
⑤ 异常状态(行动受限等)和死亡时,不能反击
⑥ 开启"是否每回合只反击一次开关"后,可设定无限反击的角色\敌人(仿英雄无敌)

使用说明:
① 复制脚本,插入到Main之前
② 系统设定中,增加名为"反击"的属性,所有允许反击的特技均钩选此属性
③ 脚本第19行设定发动反击的机率, 第21行设定"是否每回合只反击一次"
④ 无限反击的角色或敌人: [数据库-角色\敌人-名称]后加上,1表示该角色\敌人
可以无限反击型("是否每回合只反击一次开关"开启时有效)

教程作者:沉影不器
首发网址:点此进入本教学的原始帖
适宜用户:战斗加强
技术通用度:★★★★
技术应用复杂度:40 (满分150分)
学习的理解难度:60 (满分150分)

 作者的话:

战斗中机率反击 by 沉影不器

 教学正文:

#==============================================================================
# 战斗中机率反击 by 沉影不器
#------------------------------------------------------------------------------
# 环境设定:
#   ① 受到普通攻击以及带有"反击"属性的特技攻击,才能发生反击
#   ② 默认发动反击的机率为50%,可自定义
#   ③ 防御可提高30%反击机率
#   ④ 武器或特技即使带"双重打击"属性,也只反击一次
#   ⑤ 异常状态(行动受限等)和死亡时,不能反击
#   ⑥ 开启"是否每回合只反击一次开关"后,可设定无限反击的角色\敌人(仿英雄无敌)
#------------------------------------------------------------------------------
# 使用说明:
#   ① 复制脚本,插入到Main之前
#   ② 系统设定中,增加名为"反击"的属性,所有允许反击的特技均钩选此属性
#   ③ 脚本第19行设定发动反击的机率, 第21行设定"是否每回合只反击一次"
#   ④ 无限反击的角色或敌人: [数据库-角色\敌人-名称]后加上,1表示该角色\敌人
#      可以无限反击型("是否每回合只反击一次开关"开启时有效)
#==============================================================================
# ■ Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
  #-------------------------------------------------------------------------
  # ○ 参数设定
  #-------------------------------------------------------------------------
  # 发动反击的机率
    PROBA = 50
  # 是否每回合只反击一次
    CA_ONCE = true
  #--------------------------------------------------------------------------
  # ● 执行战斗行动: 攻击
  #--------------------------------------------------------------------------
  def execute_action_attack
    text = sprintf(Vocab::DoAttack, @active_battler.name)
    @message_window.add_instant_text(text)
    targets = @active_battler.action.make_targets
    display_attack_animation(targets)
    wait(20)
    # 二次攻击标志位
    @attacked = false
    for target in targets
      target.attack_effect(@active_battler)
      display_action_effects(target)
      # 已被打死时 异常状态时 跳过反击
      next if target.dead? or !target.movable?
      # 是否无限反击
      (target.counterattack ? target.counterattack = false : next) if CA_ONCE
      # 对无限反击者,还原标志位
      target.counterattack = true if target.ca_forever == 1
      # 判断二次攻击
      if target.dual_attack and !@attacked
        @attacked = true
        next
      end
      proba = PROBA
      # 防御时增加反击机率
      proba += 30 if target.guarding?
      # 计算机率
      next if rand(100) > proba
      @active_battler.attack_effect(target)
      Sound.play_evasion
      # 生成战斗信息
      text = sprintf(Vocab::Counterattack, @active_battler.name, target.name)
      @message_window.add_instant_text(text)
      display_attack_animation([@active_battler])
      wait(20)
      display_action_effects(@active_battler)
    end
  end
  #--------------------------------------------------------------------------
  # ● 执行战斗行动 : 特技
  #--------------------------------------------------------------------------
  def execute_action_skill
    skill = @active_battler.action.skill
    text = @active_battler.name + skill.message1
    @message_window.add_instant_text(text)
    unless skill.message2.empty?
      wait(10)
      @message_window.add_instant_text(skill.message2)
    end
    targets = @active_battler.action.make_targets
    display_animation(targets, skill.animation_id)
    @active_battler.mp -= @active_battler.calc_mp_cost(skill)
    $game_temp.common_event_id = skill.common_event_id
    # 二次攻击标志位
    @attacked = false
    for target in targets
      target.skill_effect(@active_battler, skill)
      display_action_effects(target, skill)
      # 已被打死时 异常状态时 跳过反击
      next if target.dead? or !target.movable?
      # 是否无限反击
      (target.counterattack ? target.counterattack = false : next) if CA_ONCE
      # 对无限反击者,还原标志位
      target.counterattack = true if target.ca_forever == 1
      # 判断二次攻击
      if skill.dual? and !@attacked
        @attacked = true
        next
      end
      # 判断"反击"属性
      p skill.element_set,ca_element_id
      next unless skill.element_set.include?(ca_element_id)
      proba = PROBA
      # 防御时增加反击机率
      proba += 30 if target.guarding?
      # 计算机率
      next if rand(100) > proba
      @active_battler.attack_effect(target)
      Sound.play_evasion
      text = sprintf(Vocab::Counterattack, @active_battler.name, target.name)
      @message_window.add_instant_text(text)
      display_attack_animation([@active_battler])
      wait(20)
      display_action_effects(@active_battler)
    end
  end
  #--------------------------------------------------------------------------
  # ● 回合结束
  #--------------------------------------------------------------------------
  def turn_end
    $game_troop.turn_ending = true
    $game_party.slip_damage_effect
    $game_troop.slip_damage_effect
    $game_party.do_auto_recovery
    $game_troop.preemptive = false
    $game_troop.surprise = false
    process_battle_event
    $game_troop.turn_ending = false
    start_party_command_selection
    # 还原反击标志位
    for i in $game_party.members + $game_troop.members
      i.counterattack = true
    end
  end
  #--------------------------------------------------------------------------
  # ○ 取得反击属性 ID
  #--------------------------------------------------------------------------
  def ca_element_id
    ca_element_id = 0
    for i in 0...$data_system.elements.size
      if $data_system.elements[i] =~ /反击/
        ca_element_id = i
        break
      end
    end
    return ca_element_id
  end
end
#==============================================================================
# ■ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :ca_forever               # 反击标志位
  #--------------------------------------------------------------------------
  # ● 设置
  #     actor_id : 角色 ID
  #--------------------------------------------------------------------------
  alias old_setup setup
  def setup(actor_id)
    old_setup(actor_id)
    @ca_forever = actor.ca_forever
  end
end
#==============================================================================
# ■ Game_Enemy
#------------------------------------------------------------------------------
#  处理敌人的类。本类在 Game_Troop 类 ($game_troop) 的
# 内部使用。
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :ca_forever               # 反击标志位
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  def initialize(index, enemy_id)
    super()
    @index = index
    @enemy_id = enemy_id
    enemy = $data_enemies[@enemy_id]
    @original_name = enemy.name
    @letter = ''
    @plural = false
    @screen_x = 0
    @screen_y = 0
    @battler_name = enemy.battler_name
    @battler_hue = enemy.battler_hue
    @hp = maxhp
    @mp = maxmp
    @ca_forever = enemy.ca_forever
  end
end
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_accessor :counterattack            # 反击标志位
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #--------------------------------------------------------------------------
  alias ini initialize
  def initialize
    # 允许反击
    @counterattack = true
    ini
  end
end
#==============================================================================
# ■ Vocab
#==============================================================================
module Vocab
  # 反击
  Counterattack          = "%s遭到%s反击!"
end
#==============================================================================
# ■ RPG
#==============================================================================
module RPG
  #============================================================================
  # ■ Actor
  #============================================================================
  class Actor
    #-------------------------------------------------------------------------
    # ● 定义实例变量
    #-------------------------------------------------------------------------
    attr_reader :ca_forever     # 无限反击标志
    #-------------------------------------------------------------------------
    # ● 名称函数化
    #-------------------------------------------------------------------------
    def name
      name = @name.split(/,/)[0]
      return name != nil ? name : ''
    end
    #-------------------------------------------------------------------------
    # ● 无限反击
    #-------------------------------------------------------------------------
    def ca_forever
      ca_forever = @name.split(/,/)[1]
      return ca_forever != nil ? ca_forever.to_i : 0
    end
  end
  #============================================================================
  # ■ Enemy
  #============================================================================
  class Enemy
    #-------------------------------------------------------------------------
    # ● 定义实例变量
    #-------------------------------------------------------------------------
    attr_reader :ca_forever     # 无限反击标志
    #-------------------------------------------------------------------------
    # ● 名称函数化
    #-------------------------------------------------------------------------
    def name
      name = @name.split(/,/)[0]
      return name != nil ? name : ''
    end
    #-------------------------------------------------------------------------
    # ● 无限反击
    #-------------------------------------------------------------------------
    def ca_forever
      ca_forever = @name.split(/,/)[1]
      return ca_forever != nil ? ca_forever.to_i : 0
    end
  end
end

 教学相关RGSS类/函数:

class Scene_Battle < Scene_Base


关键字:RMVX 战斗 特技 反击 效果

发布日期:2008-8-7 18:21:42 点击量:1


 上一篇:新套装系统
 下一篇:没有下一条记录
关于我们
支援本站
友情连接
站点目录
站内搜索



WWW.66RPG.COM,2005-2013 ^o^

备案序号:京ICP备05035415号



 
Web www.66rpg.com bbs.66rpg.com