查看: 974|回复: 0

角色生命护盾

[复制链接]

闇吼者の災悪眷族

梦石
0
星屑
1366
在线时间
2881 小时
注册时间
2014-7-29
回帖
6408
发表于 2015-2-19 13:35:19 | 显示全部楼层 |阅读模式

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

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

×
这个脚本用于给默认脚本基础上的敌我增加一个“生命护盾”,用于吸收来自“Item”造成的体力伤害。
在VA中Item指代物品和技能,所以是抵消物品和技能造成的体力伤害。

每个角色受到的伤害如果大于现有护盾,溢出的部分会打在体力上。

[pre lang="ruby"]#==============================================================================
# +++ 角色生命护盾 +++
#==============================================================================
# 作者 By 三途亚梦
#  -- 本脚本来自 https://rpg.blue 使用或转载请保留以上信息。
#==============================================================================
# 本脚本的作用是给玩家人物、敌人添加一个新的能力值“生命护盾”,
# 生命护盾会吸收该角色受到的来自技能造成的体力伤害。
#==============================================================================
#
# ★再次强调,生命护盾仅仅吸收来自“技能”造成的体力伤害!
#
# ★人物的生命护盾是amuhsp,
# 可以通过$game_actors[1].amuhsp之类的方式在事件中改变它的数值。
#
# ★HspClear = true 时,人物的生命护盾将在战斗结束时清零。
# 如果不想清零请将 true改为false
#
# ★HspNoAddition = true 时,
# 生命护盾的恢复将不享受恢复效果、物理及魔法伤害比率的加成,
# 但是会对 make_damage_value 的方法做出改变,会降低本脚本的兼容性。
#
# 设定部分所有文字信息的描述方法修改时请保留“”引号。
#
# ★将技能设置成体力值恢复,并在技能备注栏备注“[护盾恢复]”,
# 那么这个技能将变成增加目标角色的生命护盾值
# ★备注的时候不需要写入“”引号
#
# 角色的生命护盾没有上限,下限为0
#
# 如果需要设置一个技能为角色体力值的10%,又不想令护盾无限的加下去
# 技能公式请参照这个写法:
# b.hp * 0.1 - b.amuhsp
#
#==============================================================================
# ★ 设定部分 ★
#==============================================================================
module Amu
  module Hsp
   
  HspClear = true  #是否在战斗结束时清除掉玩家剩余的生命护盾
  
  HspNoAddition = false #是否采用本脚本的计算伤害的方法
   
  HspName = "生命护盾"  #生命护盾的名字
  
  HspABonus = "%s的%s剩余%s点!"  #玩家人物的生命护盾损伤后显示剩余值的文字
  
  HspEBonus = "%s的%s还剩%s点!"  #敌人的生命护盾损伤后显示剩余值的文字
  
  HspADamage = "%s的%s受到%s点伤害!"  #玩家人物的生命护盾受到伤害的文字
  
  HspEDamage = "%s的%s受到%s点伤害!"  #敌人的生命护盾受到伤害的文字
  
  HspARecovery  = "%s获得了一个%s点的%s保护!" #玩家的生命护盾得到提高的文字

  HspERecovery  = "%s接受了一个%s点的%s保护!" #敌人的生命护盾得到提高的文字

  HspADestory  = "%s的%s受到%s点伤害而遭到击破!" #玩家的生命护盾被击破时的文字
  
  HspEDestroy  = "%s的%s受到%s点伤害而被击破了!" #敌人的生命护盾被击破时的文字
  
  def self.play_actor_amuhspdamage  # 玩家的生命护盾受到伤害的音效
    Audio.se_play("Audio/SE/sword1.ogg", 100, 50)
  end
  
  def self.play_enemy_amuhspdamage   # 敌人的生命护盾受到伤害的音效
    Audio.se_play("Audio/SE/sword1.ogg", 100, 50)
  end
  
  def self.play_amuhsp_destory   # 生命护盾被击破时的音效
    Audio.se_play("Audio/SE/Crash.ogg", 60, 90)
  end
  
  end
end
#==============================================================================
# ■ Game_ActionResult
#------------------------------------------------------------------------------
#  战斗行动结果的管理类。本类在 Game_Battler 类的内部使用。
#==============================================================================
class Game_ActionResult
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_accessor :amuhsp_damage                # 生命护盾 伤害
  #--------------------------------------------------------------------------
  # ● 清除伤害值`
  #--------------------------------------------------------------------------
  alias amu_20141125_clear_damage_values clear_damage_values
  def clear_damage_values
    amu_20141125_clear_damage_values
    @amuhsp_damage = 0
  end
  #--------------------------------------------------------------------------
  # ● 生成伤害
  #--------------------------------------------------------------------------
  alias amu_20141125_make_damage make_damage
  def make_damage(value, item)
    amu_20141125_make_damage(value, item)
    @amuhsp_damage = value if item.damage.to_hp? && @battler.amuhsp > 0 && value > 0
    @amuhsp_damage = value if item.damage.to_hp? && item.damage.recover? && item.note.include?("[护盾恢复]")
  end
  #--------------------------------------------------------------------------
  # ● 获取具有生命护盾时 HP 伤害的文字
  #--------------------------------------------------------------------------
  def hp_damage_text
    if @hp_drain > 0
      fmt = @battler.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
      sprintf(fmt, @battler.name, Vocab::hp, @hp_drain)
    elsif @hp_damage > 0
      fmt = @battler.actor? ? Vocab::ActorDamage : Vocab::EnemyDamage
      sprintf(fmt, @battler.name, @hp_damage)
    elsif @hp_damage < 0
      fmt = @battler.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
      sprintf(fmt, @battler.name, Vocab::hp, -hp_damage)
    elsif @hp_damage = 0 && @battler.amuhsp > 0
      fmt = @battler.actor? ? Amu::Hsp::HspABonus : Amu::Hsp::HspEBonus
      sprintf(fmt, @battler.name, Amu::Hsp::HspName, @battler.amuhsp)
    else
      fmt = @battler.actor? ? Vocab::ActorNoDamage : Vocab::EnemyNoDamage
      sprintf(fmt, @battler.name)
    end
  end
  #--------------------------------------------------------------------------
  # ● 获取 生命护盾 伤害的文字
  #--------------------------------------------------------------------------
  def amuhsp_damage_text
    if @amuhsp_damage > 0 && @battler.amuhsp > 0
      fmt = @battler.actor? ? Amu::Hsp::HspADamage : Amu::Hsp::HspEDamage
      sprintf(fmt, @battler.name, Amu::Hsp::HspName, @amuhsp_damage)
    elsif @amuhsp_damage > 0 && @battler.amuhsp == 0
      fmt = @battler.actor? ? Amu::Hsp::HspADestory : Amu::Hsp::HspEDestroy
      sprintf(fmt, @battler.name, Amu::Hsp::HspName, @amuhsp_damage)
    elsif @amuhsp_damage < 0
      fmt = @battler.actor? ? Amu::Hsp::HspARecovery : Amu::Hsp::HspERecovery
      sprintf(fmt, @battler.name, -@amuhsp_damage, Amu::Hsp::HspName)
    else
      ""
    end
  end
end
#==============================================================================
# ■ Game_BattlerBase
#------------------------------------------------------------------------------
#  管理战斗者的类。主要含有能力值计算的方法。Game_Battler 类的父类。
#==============================================================================
class Game_BattlerBase
  attr_reader   :amuhsp                       # 生命护盾
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  alias amu_20141125_initialize initialize
  def initialize
    amu_20141125_initialize
    @amuhsp = 0
  end
  #--------------------------------------------------------------------------
  # ● 更改 HSP
  #--------------------------------------------------------------------------
  def amuhsp=(amuhsp)
    @amuhsp = amuhsp
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  alias amu_20141125_refresh refresh
  def refresh
    amu_20141125_refresh
    @amuhsp = [@amuhsp, 0].max
  end
end
#==============================================================================
# ■ Game_Battler
#------------------------------------------------------------------------------
#  处理战斗者的类。Game_Actor 和 Game_Enemy 类的父类。
#==============================================================================
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● 计算伤害
  #--------------------------------------------------------------------------
  alias amu_20141125_make_damage_value make_damage_value
  def make_damage_value(user, item)
    if Amu::Hsp::HspNoAddition
      value = item.damage.eval(user, self, $game_variables)
      value *= item_element_rate(user, item)
      value *= pdr if item.physical? && !make_amuhsp?(item)
      value *= mdr if item.magical? && !make_amuhsp?(item)
      value *= rec if item.damage.recover? && !make_amuhsp?(item)
      value = apply_critical(value) if @result.critical
      value = apply_variance(value, item.damage.variance)
      value = apply_guard(value)
      if make_amuhsp?(item)
        def actor_amuhsp?
          return true
        end
      end
      @result.make_damage(value.to_i, item)
    end
    else
      amu_20141125_make_damage_value(user, item)
      if make_amuhsp?(item)
        def actor_amuhsp?
          return true
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 处理伤害
  #    调用前需要设置好
  #    @result.hp_damage   @result.mp_damage
  #    @result.hp_drain    @result.mp_drain
  #--------------------------------------------------------------------------
  def execute_damage(user)
    on_damage(@result.hp_damage) if @result.hp_damage > 0
    if self.amuhsp > 0 && @result.hp_damage > 0
      eamuhsp = self.amuhsp
      self.amuhsp -= @result.hp_damage
      self.amuhsp <= 0 ? @result.hp_damage -= eamuhsp : @result.hp_damage = 0
    end
    if actor_amuhsp?
      self.amuhsp -= @result.hp_damage
      @result.hp_damage = 0
      def actor_amuhsp?
        return false
      end
    else
      self.hp -= @result.hp_damage
    end
    self.mp -= @result.mp_damage
    user.hp += @result.hp_drain
    user.mp += @result.mp_drain
  end
  #--------------------------------------------------------------------------
  # ● 判断技能是否用来增加生命护盾
  #--------------------------------------------------------------------------
  def make_amuhsp?(item)
    return false unless item.is_a?(RPG::Skill)
    return item.note.include?("[护盾恢复]")
  end
  def actor_amuhsp?
    return false
  end
  #--------------------------------------------------------------------------
  # ● 清除 生命护盾
  #--------------------------------------------------------------------------
  def clear_amuhsp
    self.amuhsp = 0
  end
  #--------------------------------------------------------------------------
  # ● 战斗结束处理
  #--------------------------------------------------------------------------
  alias amu_20141125_on_battle_end on_battle_end
  def on_battle_end
    amu_20141125_on_battle_end
    clear_amuhsp if Amu::Hsp::HspClear == true
  end
end

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ● 设置具有生命护盾时玩家被击的效果
  #--------------------------------------------------------------------------
  def perform_hspdamage_effect
    $game_troop.screen.start_shake(5, 5, 10)
    @sprite_effect_type = :blink
    Amu::Hsp.play_actor_amuhspdamage
  end
end

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # ● 设置具有生命护盾时敌人被击的效果
  #--------------------------------------------------------------------------
  def perform_hspdamage_effect
    $game_troop.screen.start_shake(5, 5, 10)
    @sprite_effect_type = :blink
    Amu::Hsp.play_enemy_amuhspdamage
  end
end

class Window_BattleLog < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 显示伤害
  #--------------------------------------------------------------------------
  def display_damage(target, item)
    if target.result.missed
      display_miss(target, item)
    elsif target.result.evaded
      display_evasion(target, item)
    else
      display_amuhsp_damage(target, item)
      display_hp_damage(target, item)
      display_mp_damage(target, item)
      display_tp_damage(target, item)
    end
  end
  #--------------------------------------------------------------------------
  # ● 显示 生命护盾 伤害
  #--------------------------------------------------------------------------
  def display_amuhsp_damage(target, item)
    return if target.dead? || target.result.amuhsp_damage == 0
    if target.result.amuhsp_damage > 0 && target.amuhsp > 0 && target.result.hp_drain == 0
      target.perform_hspdamage_effect
    end
    Amu::Hsp.play_amuhsp_destory if target.result.amuhsp_damage > 0 && target.amuhsp == 0
    Sound.play_recovery if target.result.amuhsp_damage < 0
    add_text(target.result.amuhsp_damage_text)
    wait
  end
end[/pre]

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

在本发帖返回顶部