Project1

标题: 事件脚本快捷方式 [打印本页]

作者: taroxd    时间: 2014-7-5 13:12
标题: 事件脚本快捷方式
本帖最后由 taroxd 于 2014-12-29 12:46 编辑

与 “事件转译器” 可能会有冲突,故停止维护


  1. #----------------------------------------------------------------------------
  2. # ● require Taroxd基础设置
  3. #----------------------------------------------------------------------------

  4. module Taroxd::Eval
  5.   #--------------------------------------------------------------------------
  6.   # ● 脚本中的简称列表
  7.   #--------------------------------------------------------------------------
  8.   SCRIPT_ABBR_LIST = {
  9.     'V' => '$game_variables',
  10.     'S' => '$game_switches',
  11.     'N' => '$game_actors',
  12.     'A' => '$game_actors',
  13.     'P' => '$game_party',
  14.     'G' => '$game_party.gold',
  15.     'E' => '$game_troop'
  16.   }
  17.   #--------------------------------------------------------------------------
  18.   # ● 处理脚本用的正则表达式
  19.   #--------------------------------------------------------------------------
  20.   words = SCRIPT_ABBR_LIST.keys.join('|')
  21.   SCRIPT_ABBR_RE = /(?<!::|['"\\\.])\b(?:#{words})\b(?! *[(@$\w'"])/
  22.   #--------------------------------------------------------------------------
  23.   module_function
  24.   #--------------------------------------------------------------------------
  25.   # ● 对脚本的处理
  26.   #--------------------------------------------------------------------------
  27.   def process_script(script)
  28.     script.gsub(SCRIPT_ABBR_RE, SCRIPT_ABBR_LIST)
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # ● 执行脚本
  32.   #--------------------------------------------------------------------------
  33.   def eval(script, *args)
  34.     v = $game_variables
  35.     s = $game_switches
  36.     n = $game_actors
  37.     a = $game_actors
  38.     p = $game_party
  39.     g = $game_party.gold
  40.     e = $game_troop
  41.     script = process_script(script)
  42.     if args.empty?
  43.       instance_eval(script, __FILE__, __LINE__)
  44.     else
  45.       Kernel.eval(script, *args)
  46.     end
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # ● 混入模块
  50.   #--------------------------------------------------------------------------
  51.   Game_Character.send   :include, self
  52.   Game_Interpreter.send :include, self
  53. end
  54.   
  55. class RPG::UsableItem::Damage
  56.   #--------------------------------------------------------------------------
  57.   # ● 根据参数执行计算公式
  58.   #--------------------------------------------------------------------------
  59.   def eval(a, b, v)
  60.     value = Taroxd::Eval.eval(@formula, b.formula_binding(a, b, v))
  61.     value > 0 ? value * sign : 0
  62.   end
  63. end

  64. class Game_BattlerBase
  65.   #--------------------------------------------------------------------------
  66.   # ● 执行计算公式的环境
  67.   #--------------------------------------------------------------------------
  68.   def formula_binding(a, b, v)
  69.     s = $game_switches
  70.     n = $game_actors
  71.     p = $game_party
  72.     g = $game_party.gold
  73.     e = $game_troop
  74.     binding
  75.   end
  76. end

  77. class Window_Base < Window
  78.   #--------------------------------------------------------------------------
  79.   # ● 对 #{} 的处理
  80.   #--------------------------------------------------------------------------
  81.   process_expression = Proc.new do |old|
  82.     old.gsub(/\e?#(?<brace>\{([^{}]|\g<brace>)*\})/) do |code|
  83.       next code if code.slice!(0) == "\e"
  84.       Taroxd::Eval.eval code[1..-2]
  85.     end
  86.   end
  87.   def_with :convert_escape_characters, process_expression
  88. end
复制代码





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1