地图显血
# @taroxd metadata 1.0
# @id map_hp
# @display 地图显血
# @require taroxd_core
# @require roll_gauge
# @help 在地图上显示一个简易的血条。
class Sprite_MapHP < Sprite

  Taroxd::MapHP = self

  include Taroxd::DisposeBitmap
  include Taroxd::RollGauge

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

  # 大小
  WIDTH = 124
  HEIGHT = 100

  def initialize(_)
    super
    self.z = 170
    self.bitmap = Bitmap.new(WIDTH, HEIGHT)
    roll_all_gauge
  end

  def roll_all_gauge
    bitmap.clear
    $game_party.each_with_index do |actor, i|
      rate = gauge_transitions[actor][:hp].value.fdiv(actor.mhp)
      fill_w = (width * rate).to_i
      gauge_y = i * 16 + 12
      bitmap.fill_rect(fill_w, gauge_y, WIDTH - fill_w, 6, BACK_COLOR)
      bitmap.gradient_fill_rect(0, gauge_y, fill_w, 6, HP_COLOR1, HP_COLOR2)
    end
  end
end

Spriteset_Map.use_sprite(Sprite_MapHP) { @viewport2 }
迭代所有事件指令
# @taroxd metadata 1.0
# @id load_and_save_event_command
# @display 迭代所有事件指令
# @help 迭代整个游戏的每个事件指令,并保存所做的修改。
module Taroxd
  module LoadAndSaveEventCommand

    module_function

    # 迭代所有地图事件的事件指令
    def of_map(&block)
      return to_enum(__method__) unless block
      load_data('Data/MapInfos.rvdata2').each_key do |map_id|
        load_and_save(sprintf('Data/Map%03d.rvdata2', map_id)) do |map|
          map.events.each_value do |event|
            event.pages.flat_map(&:list).each(&block)
          end
        end
      end
    end

    # 迭代所有公共事件的事件指令
    def of_common_event(&block)
      return to_enum(__method__) unless block
      load_and_save('Data/CommonEvents.rvdata2') do |events|
        events.each { |event| event.list.each(&block) if event }
      end
    end

    # 迭代所有敌群事件的事件指令
    def of_troop(&block)
      return to_enum(__method__) unless block
      load_and_save('Data/Troops.rvdata2') do |troops|
        troops.each do |troop|
          troop.pages.flat_map(&:list).each(&block) if troop
        end
      end
    end

    # 迭代上述所有事件指令
    def all(&block)
      return to_enum(__method__) unless block
      of_map(&block)
      of_common_event(&block)
      of_troop(&block)
    end

    # 读取文件,执行 block 并保存到原来的文件
    def load_and_save(filename, &block)
      save_data(load_data(filename).tap(&block), filename)
    end
  end
end
持有物品时习得技能
# @taroxd metadata 1.0
# @id learn_skill_by_item
# @display 持有物品时习得技能
# @require taroxd_core
# @help 在角色处备注 <learn x by y>,表示当持有道具 y 时习得技能 x
Taroxd::LearnSkillByItem = /<learn\s*(\d+)\s*by\s*(\d+)>/i

class RPG::Actor < RPG::BaseItem

  # 由 [技能id, 物品] 构成的数组
  def learn_skill_by_item
    @learn_skill_by_item ||=
    @note.scan(Taroxd::LearnSkillByItem).map do |(x, y)|
      [x.to_i, $data_items[y.to_i]]
    end
  end
end

class Game_Actor < Game_Battler

  def_with :added_skills do |old|
    actor.learn_skill_by_item.each do |(skill_id, item)|
      old.push(skill_id) if $game_party.has_item?(item)
    end
    old
  end
end