视野限制
# @taroxd metadata 1.0
# @id sight
# @display 视野限制
# @require taroxd_core
# @require bitmap_ext
# @help 
#  使用方法:在地图上备注 <sight x>,则该地图限制视野。x 为无补正时的可见半径
#  在角色、职业、装备、状态上备注 <sight x>,则可以设置角色周围 x 的视野补正
#  在事件名称上备注 <sight x> 则可以在事件周围设置 x 的视野补正
#
#  可以设置 $game_map.sight 属性来调整视野范围。
#  该值默认为地图上备注的数字或 nil(无备注,不限制视野)

module Taroxd::Sight
  DARKNESS = 32    # 视野限制时可见区域的暗度。

  # 阴影的位图。纯白色,越靠近中间透明度越大。
  def self.shadow
    return @shadow if @shadow && !@shadow.disposed?
    @shadow = Bitmap.new(128, 128)
    @shadow.fill_rect(@shadow.rect, Color.new(255, 255, 255, 0))
    @shadow.width.times do |x|
      @shadow.height.times do |y|
        bright = 4096 - (x - 64)**2 - (y - 64)**2
        next if bright <= 0
        @shadow.set_pixel(x, y, Color.new(255, 255, 255, bright / DARKNESS))
      end
    end
    @shadow
  end
end

RPG::Map.note_i :sight, nil
RPG::BaseItem.note_i :sight
RPG::Event.note_i :sight

class Game_Map
  attr_accessor :sight
  def_after(:setup) { |_| @sight = @map.sight }
end

class Game_Actor < Game_Battler
  def sight
    note_objects.sum(&:sight)
  end
end

class Game_CharacterBase
  def sight
    0
  end
end

class Game_Event < Game_Character
  def sight
    @event.sight
  end
end

class Game_Player < Game_Character
  def sight
    return 0 unless $game_map.sight
    $game_party.sum($game_map.sight, &:sight)
  end
end

class Sprite_SightShadow < Sprite_Base

  # sprites: Sprite_Character 实例的数组
  def initialize(viewport, sprites)
    super(viewport)
    @sprites = sprites
    self.z = 160
    self.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  end

  def dispose
    bitmap.dispose
    super
  end

  def update
    self.visible = $game_map.sight
    refresh if visible
  end

  private

  def refresh
    bitmap.fill_rect(bitmap.rect, Color.new(255, 255, 255, 0))
    @sprites.each { |s| draw_shadow(s) }
    bitmap.xor!(0xFFFFFFFF)
  end

  def draw_shadow(sprite)
    r = sprite.character.sight
    x = sprite.x - sprite.ox + sprite.width / 2 - r
    y = sprite.y - sprite.oy + sprite.height / 2 - r
    bitmap.stretch_blt(Rect.new(x, y, r * 2, r * 2), shadow, shadow.rect)
  end

  def shadow
    Taroxd::Sight.shadow
  end
end

class Spriteset_Map

  def create_sight_shadow
    sprites = @character_sprites.select { |s| s.character.sight > 0 }
    @sight_shadow = Sprite_SightShadow.new(@viewport2, sprites)
  end

  def dispose_sight_shadow
    @sight_shadow.dispose
  end

  def update_sight_shadow
    @sight_shadow.update
  end

  def refresh_sight_shadow
    dispose_sight_shadow
    create_sight_shadow
  end

  %w(create dispose update refresh).each do |prefix|
    def_after :"#{prefix}_characters", :"#{prefix}_sight_shadow"
  end
end
显示地图通行度
# @taroxd metadata 1.0
# @id show_passage
# @display 显示地图通行度
# @require taroxd_core
# @require rgss_bugfix
# @help 游戏测试中按下F6即可启用,再按一次关闭
class Taroxd::PlanePassage < Plane

  ENABLE = $TEST                       # 是否启用功能
  KEY = :F6                            # 控制显示通行度的按键
  VISIBLE = false                      # 起始时是否可见
  OPACITY = 150                        # 不透明度
  NG = Color.new(255, 0, 0, OPACITY)   # 不可通行的颜色
  OK = Color.new(0, 0, 255, OPACITY)   # 可以通行的颜色
  NG_WIDTH = 4                         # 不可通行方向显示的宽度

  include Taroxd::DisposeBitmap
  include Taroxd::BugFix::PlaneVisible

  def initialize(_)
    super
    self.visible = VISIBLE
    self.z = 200
    refresh
    update
  end

  def update
    self.visible ^= true if Input.trigger?(KEY)
    self.ox = $game_map.display_x * 32
    self.oy = $game_map.display_y * 32
  end

  def refresh
    bitmap.dispose if bitmap
    self.bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
    $game_map.width.times do |x|
      $game_map.height.times do |y|
        draw_point(x, y)
      end
    end
  end

  # 绘制地图上的点 (x, y)
  def draw_point(x, y)
    ng_dirs = [2, 4, 6, 8].reject { |d| $game_map.passable?(x, y, d) }
    if ng_dirs.size == 4
      bitmap.fill_rect(x * 32, y * 32, 32, 32, NG)
      return
    end
    bitmap.fill_rect(x * 32, y * 32, 32, 32, OK)
    ng_dirs.each do |d|
      dx = d == 6 ? 32 - NG_WIDTH : 0
      dy = d == 2 ? 32 - NG_WIDTH : 0
      if d == 2 || d == 8
        width  = 32
        height = NG_WIDTH
      else
        width  = NG_WIDTH
        height = 32
      end
      bitmap.fill_rect(x * 32 + dx, y * 32 + dy, width, height, NG)
    end
  end
end

class Spriteset_Map
  def_before :create_parallax do
    @passage_plane = Taroxd::PlanePassage.new(@viewport3)
  end
  def_before(:update_parallax)    { @passage_plane.update  }
  def_before(:refresh_characters) { @passage_plane.refresh }
  def_before(:dispose_parallax)   { @passage_plane.dispose }
end if Taroxd::PlanePassage::ENABLE
Shift 功能反转
# @taroxd metadata 1.0
# @id shift_reverse
# @require taroxd_core
# @display Shift 功能反转
module Taroxd
  ShiftReverse = true
end

class Game_Player < Game_Character

  def dash?
    !@move_route_forcing && !$game_map.disable_dash? &&
      !vehicle && !Input.press?(:A)
  end

end