- #============================================================================== 
- # ** 事件触发范围脚本 
- #------------------------------------------------------------------------------ 
- # 该脚本可以给事件定义一个可调整的触发范围,如果玩家进入该范围, 
- # 则打开该事件的独立开关D。 
- # 
- # 使用方法: 
- # 在事件页的注释栏中输入: 
- # <rpgm_trigger_range: range> 
- # 其中 range 为触发范围,可以为任意正整数,代表以该事件为中心的正方形边长。 
- # 如果不输入该注释,则默认触发范围为0(仅事件本格)。 
-   
- # 
- # By ChatGPT/润色 Smallgeeser 
- #============================================================================== 
-   
- class Game_Event < Game_Character 
-   #-------------------------------------------------------------------------- 
-   # ● 定义常量 
-   #-------------------------------------------------------------------------- 
-   TRIGGER_RANGE_REGEX = /<rpgm_trigger_range:\s*(\d+)\s*>/i 
-   #-------------------------------------------------------------------------- 
-   # ● 初始化对象 
-   #-------------------------------------------------------------------------- 
-   alias rpgm_trigger_range_initialize initialize 
-   def initialize(map_id, event) 
-     rpgm_trigger_range_initialize(map_id, event) 
-     @trigger_range = 0 # 默认触发范围为0 
-     set_trigger_range_from_comment # 从事件页注释中获取触发范围 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 获取触发范围 
-   #-------------------------------------------------------------------------- 
-   def trigger_range 
-     return @trigger_range 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 更新事件 
-   #-------------------------------------------------------------------------- 
-   alias rpgm_trigger_range_update update 
-   def update 
-     rpgm_trigger_range_update 
-     if @trigger_range >= 1 # 只有触发范围大于等于1的事件才需要检测玩家位置 
-       check_player_position # 检测玩家位置是否在触发范围内 
-     else 
-     end 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 检测玩家位置是否在触发范围内 
-   #-------------------------------------------------------------------------- 
- #-------------------------------------------------------------------------- 
-   def check_player_position 
-     sx = [self.x - @trigger_range, 0].max 
-     sy = [self.y - @trigger_range, 0].max 
-     ex = [self.x + @trigger_range, $game_map.width - 1].min 
-     ey = [self.y + @trigger_range, $game_map.height - 1].min 
-     for x in sx..ex 
-       for y in sy..ey 
-         if $game_player.pos?(x, y) 
-           $game_self_switches[[@map_id, @id, "D"]] = true # 玩家位置在触发范围内,打开独立开关D 
-           return 
-         end 
-       end 
-     end 
-     $game_self_switches[[@map_id, @id, "D"]] = false # 玩家位置离开触发范围,关闭独立开关D 
-   end 
- #-------------------------------------------------------------------------- 
-   #-------------------------------------------------------------------------- 
-   # ● 从注释中设置触发范围 
-   #-------------------------------------------------------------------------- 
- def set_trigger_range_from_comment 
-   if @list != nil && @list[0] != nil # 如果 @list 不为空且第一个命令不为空 
-     if @list[0].code == 108 || @list[0].code == 408 # 只检测第一个注释 
-       comment = @list[0].parameters[0] 
-       match = TRIGGER_RANGE_REGEX.match(comment) 
-       if match != nil 
-         @trigger_range = match[1].to_i 
-       end 
-     end 
-   end 
- end 
- end