导出脚本
# @taroxd metadata 1.0
# @display 导出脚本
# @id export_scripts
# @require metadata
module Taroxd
  module ExportScripts
    Success = Class.new(StandardError)
    PATH = 'rgss3'
    EXT = '.rb'
    
    def self.call
      if File.directory?(PATH)
        Dir.glob("#{PATH}/*#{EXT}", &File.method(:delete))
      else
        Dir.mkdir(PATH)
      end

      $RGSS_SCRIPTS.each do |(_, tag, _, contents)|
        next unless contents.force_encoding('utf-8')[/\S/]
        metadata = Taroxd::Metadata.read(contents)
        next unless metadata
        filename = metadata[:id]
        if filename
          File.open("#{PATH}/#{filename}#{EXT}", 'wb', encoding: 'utf-8') do |f|
            f.write contents.delete("\r")
          end
        end
      end
      # raise in order to navigate to this page
      raise Success, 'Scripts are exported successfully.' 
    end

    call if $TEST && !$BTEST
  end
end
自定义经验公式
# @taroxd metadata 1.0
# @display 自定义经验公式
# @id exp_formula
# @help 
#    <exp>
#      升级到等级 lv 所需要的总经验值公式
#    </exp>
#    可以使用的参数:
#      lv:    等级
#      basis:基础值
#      extra:修正值
#      acc_a:增加度 a
#      acc_b:增加度 b
#
#    例(默认公式):
#    <exp>
#      basis*((lv-1)**(0.9+acc_a/250))*
#      lv*(lv+1)/(6+lv**2/50/acc_b)+
#      (lv-1)*extra
#    </exp>
#
#    注意事项:
#      如果需要使用转职功能,则 lv 为 1 时的经验值请不要大于 0 !

module Taroxd
  EXPFormula = /<exp>\s*(.+)\s*<\/exp>/mi
end

class RPG::Class < RPG::BaseItem

  include Math

  original_formula = instance_method(:exp_for_level)
  define_method :exp_for_level do |level|
    @exp_formula ||= if @note =~ Taroxd::EXPFormula
      basis, extra, acc_a, acc_b = @exp_params.map(&:to_f)
      eval("->lv{lv=lv.to_f;(#{$1}).round}")
    else
      original_formula.bind(self)
    end
    @exp_formula.call(level)
  end
end
事件转译器嵌入
# @taroxd metadata 1.0
# @display 事件转译器嵌入
# @require event_transcompiler
# @id event_transcompiler_integration
class Taroxd::EventTranscompiler

  # 是否需要与旧存档兼容。不是新工程的话填 true。
  SAVEDATA_COMPATIBLE = false

  # 读档时是否重新执行事件。(暂不支持从中断处开始。因此建议不要在事件执行时存档)
  # true 表示读档时从头开始执行事件,false 表示读档时丢弃执行中的事件。
  # 该选项仅当 SAVEDATA_COMPATIBLE 为 false 时有效。
  RUN_ON_LOAD = false

  # 调试模式,开启时会将转译的脚本输出到控制台
  DEBUG = false

  @cache = {}

  class << self
    attr_reader :cache
  end
end

class Game_Interpreter

  EventTranscompiler = Taroxd::EventTranscompiler

  def run
    wait_for_message
    instance_eval(&compile_code)
    Fiber.yield
    @fiber = nil
  end

  unless EventTranscompiler::SAVEDATA_COMPATIBLE

    def marshal_dump
      [@map_id, @event_id, @list]
    end

    def marshal_load(obj)
      @map_id, @event_id, @list = obj
      create_fiber if EventTranscompiler::RUN_ON_LOAD
    end
  end # unless EventTranscompiler::SAVEDATA_COMPATIBLE

  private

  def rb_code
    EventTranscompiler.transcompile(@list, @map_id, @event_id)
  end

  def transcompiler_binding
    binding
  end

  def transcompiler_cache_key
    "#{@map_id}-#{@event_id}-#{@list.__id__}"
  end

  if $TEST && EventTranscompiler::DEBUG

    def compile_code
      proc = EventTranscompiler.cache[transcompiler_cache_key]
      return proc if proc
      code = rb_code
      puts code
      EventTranscompiler.cache[transcompiler_cache_key] =
        eval(code, transcompiler_binding)
    rescue StandardError, SyntaxError => e
      p e
      puts e.backtrace
      rgss_stop
    end

  else

    def compile_code
      EventTranscompiler.cache[transcompiler_cache_key] ||=
        eval(rb_code, transcompiler_binding)
    end

  end # if $TEST && EventTranscompiler::DEBUG
end

# 切换地图时,清除事件页转译代码的缓存

class Game_Map

  alias_method :setup_without_transcompiler, :setup

  def setup(map_id)
    setup_without_transcompiler(map_id)
    Taroxd::EventTranscompiler.cache.clear
  end
end