敌人显血
# @taroxd metadata 1.0
# @id enemy_hp
# @display 敌人显血
# @require taroxd_core
# @require roll_gauge
# @help 
#    如不想显示,可在敌人处备注 <hide hp>
#    可在敌人处备注 <hp width w>、<hp height h>、<hp dxy dx dy> 调整血槽。
#    其中 w 表示宽度、h 表示高度,dx、dy 表示坐标的偏移。

Taroxd::EnemyHP = true

class RPG::Enemy < RPG::BaseItem

  note_any :hp_dxy, [0, 0], /\s+(-?\d+)\s+(-?\d+)/, '[$1.to_i, $2.to_i]'
  note_i :hp_width, 80
  note_i :hp_height, 6
  note_bool :hide_hp?

  # 初始化并获取战斗图的尺寸
  def init_width_height
    bitmap = Bitmap.new("Graphics/Battlers/#{@battler_name}")
    @width = bitmap.width
    @height = bitmap.height
    bitmap.dispose
  end

  def width
    return @width if @width
    init_width_height
    @width
  end

  def height
    return @height if @height
    init_width_height
    @height
  end
end

class Sprite_EnemyHP < Sprite

  include Taroxd::RollGauge
  include Taroxd::DisposeBitmap

  HP_COLOR1 = Color.new(223, 127, 63)
  HP_COLOR2 = Color.new(239, 191, 63)
  BACK_COLOR = Color.new(31, 31, 63)

  def initialize(viewport, enemy)
    @enemy = enemy
    super(viewport)
    data = enemy.enemy
    @width = data.hp_width
    @height = data.hp_height
    self.bitmap = Bitmap.new(@width, @height)
    dx, dy = enemy.enemy.hp_dxy
    self.ox = @width / 2
    self.oy = @height
    self.x = enemy.screen_x + dx
    self.y = enemy.screen_y + dy
    self.z = enemy.screen_z + 10
    refresh
  end

  def make_gauge_transitions
    Transition.new(gauge_roll_times) do
      @enemy.hp.fdiv(@enemy.mhp)
    end
  end

  def update_gauge_transitions
    gauge_transitions.update
  end

  def refresh
    bitmap.clear
    rate = gauge_transitions.value
    return if rate.zero?
    fill_w = (bitmap.width * rate).to_i
    bitmap.fill_rect(fill_w, 0, @width - fill_w, @height, BACK_COLOR)
    bitmap.gradient_fill_rect(0, 0, fill_w, @height, HP_COLOR1, HP_COLOR2)
  end
end

class Spriteset_Battle

  # 导入精灵组
  def_after :create_enemies do
    @enemy_hp_sprites = $game_troop.members.map { |enemy|
      Sprite_EnemyHP.new(@viewport1, enemy) unless enemy.enemy.hide_hp?
    }.compact
  end

  def_after(:update_enemies)  { @enemy_hp_sprites.each(&:update)  }
  def_after(:dispose_enemies) { @enemy_hp_sprites.each(&:dispose) }
end
属性修正的扩展
# @taroxd metadata 1.0
# @display 属性修正的扩展
# @require taroxd_core
# @id element_effect
# @help 
#             表示该角色/该职业/习得技能后/装上装备后/该敌人/获得状态后,
#             战斗者使用第 id 号属性的技能时,效果乘以 rate

Taroxd::ElementEffect = true

class RPG::BaseItem
  # 属性效果构成的 hash,属性ID => 效果
  def element_effect
    @element_effect ||= @note.scan(/<ELEMENT\s+(\d+)\s+(\d+(?:\.\d+)?)>/i)
      .each_with_object(Hash.new(1.0)) { |(id, rate), hash|
        hash[id.to_i] *= rate.to_f }
  end
end

class Game_Battler < Game_BattlerBase
  def element_effect
    note_objects.each_with_object(Hash.new(1.0)) do |e, h|
      h.merge!(e.element_effect) { |_, r1, r2| r1 * r2 }
    end
  end

  calc_new_rate = lambda do |old, user, item|
    if item.damage.element_id < 0
      user.atk_elements.pi(old) { |id| user.element_effect[id] }
    else
      old * user.element_effect[item.damage.element_id]
    end
  end
  def_with :item_element_rate, calc_new_rate
end
按比例吸血
# @taroxd metadata 1.0
# @id drain
# @display 按比例吸血
# @require taroxd_core
#   在可以设置“特性”的地方备注 <drain r>。
#   其中 r 为吸血的比例。

Taroxd::Drain = true

RPG::BaseItem.note_f :drain

Game_Battler.send :def_after, :execute_damage do |user|
  if @result.hp_damage > 0
    user.hp += (@result.hp_damage * user.feature_objects.sum(&:drain)).to_i
  end
end