赞 | 9 |
VIP | 0 |
好人卡 | 11 |
积分 | 29 |
经验 | 29235 |
最后登录 | 2023-12-28 |
在线时间 | 713 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 2920
- 在线时间
- 713 小时
- 注册时间
- 2010-7-25
- 帖子
- 813
|
- #==============================================================================
- # ■ Game_Map
- #------------------------------------------------------------------------------
- # 管理地图的类。拥有卷动地图以及判断通行度的功能。
- # 本类的实例请参考 $game_map 。
- #==============================================================================
- =begin
- 由於直接重定義 check_passage
- 如果其他腳本有定義可能會發生衝突
- =end
- class Game_Map
- #--------------------------------------------------------------------------
- # ● セットアップ
- #--------------------------------------------------------------------------
- alias :d8_bridgepass_ori_setup :setup unless defined? d8_bridgepass_ori_setup
- def setup(map_id)
- d8_bridgepass_ori_setup(map_id)
- fix_a3_roof_passage
- end
- #--------------------------------------------------------------------------
- # ● 修正房屋屋頂部分通行判定
- #--------------------------------------------------------------------------
- def fix_a3_roof_passage
- for i in (48..55).to_a + (64..71).to_a
- id_base = 2048 + i * 48
- for t in 0..15
- id = id_base + t
- pass_flag = 0b0000
- pass_flag |= 0x02 if [1, 3, 5, 7, 9, 11, 13, 15].include?(t)
- pass_flag |= 0x04 if [4, 5, 6, 7, 12, 13, 14, 15].include?(t)
- pass_flag |= 0x08 if [2, 3, 6, 7, 10, 11, 14, 15].include?(t)
- flag = tileset.flags[id]
- flag = (flag >> 4 << 4) | pass_flag
- tileset.flags[id] = flag
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 通行检查
- # bit : 判断通行禁止与否的字节(请参照二进制运算)
- #--------------------------------------------------------------------------
- def check_passage(x, y, bit)
- # 非飛行船 => 前方有橋 => 方向不同則提高前方優先級+可通行
- if bit != 0x800
- case bit
- when 0x01 # 2 D
- if $game_player.pos?(x, y) && check_upper_bridge(x, y + 1, bit)
- set_bridge(x, y + 1, 0x10)
- return true
- elsif check_front_bridge(x, y, bit) && check_roof(tile_id(x, y + 1, 0)) && !check_roof(tile_id(x, y, 0))
- return false
- elsif check_front_bridge(x, y, bit) && check_front_bridge(x, y + 1, bit) && check_upper_bridge(x + 1, y, bit)
- return false
- elsif check_upper_bridge(x, y, 0x08)
- return true if $game_player.pos?(x, y + 1)
- end
- when 0x02 # 4 L
- if $game_player.pos?(x, y) && check_upper_bridge(x - 1, y, bit)
- set_bridge(x - 1, y, 0x10)
- return true
- elsif check_front_bridge(x, y, bit) && check_roof(tile_id(x - 1, y, 0)) && !check_roof(tile_id(x, y, 0))
- return false
- elsif check_front_bridge(x, y, bit) && check_front_bridge(x - 1, y, bit) && check_upper_bridge(x, y - 1, bit)
- return false
- elsif check_upper_bridge(x, y, 0x04)
- return true if $game_player.pos?(x - 1, y)
- end
- when 0x04 # 6 R
- if $game_player.pos?(x, y) && check_upper_bridge(x + 1, y, bit)
- set_bridge(x + 1, y, 0x10)
- return true
- elsif check_front_bridge(x, y, bit) && check_roof(tile_id(x + 1, y, 0)) && !check_roof(tile_id(x, y, 0))
- return false
- elsif check_front_bridge(x, y, bit) && check_front_bridge(x + 1, y, bit) && check_upper_bridge(x, y + 1, bit)
- return false
- elsif check_upper_bridge(x, y, 0x02)
- return true if $game_player.pos?(x + 1, y)
- end
- when 0x08 # 8 U
- if $game_player.pos?(x, y) && check_upper_bridge(x, y - 1, bit)
- set_bridge(x, y - 1, 0x10)
- return true
- elsif check_front_bridge(x, y, bit) && check_roof(tile_id(x, y - 1, 0)) && !check_roof(tile_id(x, y, 0))
- return false
- elsif check_front_bridge(x, y, bit) && check_front_bridge(x, y - 1, bit) && check_upper_bridge(x - 1, y, bit)
- return false
- elsif check_upper_bridge(x, y, 0x01)
- return true if $game_player.pos?(x, y - 1)
- end
- when 0x200, 0x400 # Ship
- end
- end
- # 方向判別狀態
- if bit <= 0xf
- # 在屋頂邊緣 & 自身不在橋上 => 是否有橋
- if check_roof(tile_id(x, y, 0)) && !check_front_bridge(x, y, bit)
- case bit
- when 0x01 # 2 D
- set_bridge(x, y + 1, 0) if $game_player.pos?(x, y) && check_front_bridge(x, y + 1, bit)
- when 0x02 # 4 L
- set_bridge(x - 1, y, 0) if $game_player.pos?(x, y) && check_front_bridge(x - 1, y, bit)
- return true if check_bridge_passage(x - 1, y, bit)
- when 0x04 # 6 R
- set_bridge(x + 1, y, 0) if $game_player.pos?(x, y) && check_front_bridge(x + 1, y, bit)
- return true if check_bridge_passage(x + 1, y, bit)
- when 0x08 # 8 U
- set_bridge(x, y - 1, 0) if $game_player.pos?(x, y) && check_front_bridge(x, y - 1, bit)
- return true if check_bridge_passage(x, y - 1, bit)
- end
- # 在橋可通行方向上 => 前方是否有屋頂
- elsif check_bridge_passage(x, y, bit)
- case bit
- when 0x01 # 2 D
- return true if check_roof(tile_id(x, y + 1, 0)) && check_roof_edge(tile_id(x, y + 1, 0))
- when 0x02 # 4 L
- return true if check_roof(tile_id(x - 1, y, 0)) && check_roof_edge(tile_id(x - 1, y, 0))
- when 0x04 # 6 R
- return true if check_roof(tile_id(x + 1, y, 0)) && check_roof_edge(tile_id(x + 1, y, 0))
- end
- end
- end
- # 原始判定
- all_tiles(x, y).each do |tile_id|
- flag = tileset.flags[tile_id]
- next if flag & 0x10 != 0 # [☆] : 不影响通行
- return true if flag & bit == 0 # [○] : 可以通行
- return false if flag & bit == bit # [×] : 不能通行
- end
- return false # 不能通行
- end
- #--------------------------------------------------------------------------
- # ● 屋頂?
- #--------------------------------------------------------------------------
- def check_roof(tile_id)
- return false if tile_id < 2048
- case (tile_id - 2048) / 48
- when 48..55, 64..71 # A3 House Roof #1, #2
- return true
- when 80..87, 96..103, 112..119 # A4 House Roof #1, #2
- return true
- else
- return false
- end
- end
- #--------------------------------------------------------------------------
- # ● 屋頂邊緣?
- #--------------------------------------------------------------------------
- def check_roof_edge(tile_id)
- return false if tile_id < 2048
- case (tile_id - 2048) / 48
- when 48..55, 64..71 # A3 House Roof #1, #2
- return (tile_id - 2048) % 48 != 0
- when 80..87, 96..103, 112..119 # A4 House Roof #1, #2
- return ![1, 34, 36, 38, 40, 46].include?((tile_id - 2048) % 48)
- else
- return false
- end
- end
- #--------------------------------------------------------------------------
- # ● 確認是否為上方橋面(通行方向相反之橋面)
- #--------------------------------------------------------------------------
- def check_upper_bridge(x, y, bit)
- all_tiles(x, y).each do |tile_id|
- flag = tileset.flags[tile_id]
- next if flag & 0x10 != 0
- bridge = check_bridge(tile_id)
- next unless bridge
- if flag & 0x0800 == 0x00
- tileset.flags[tile_id] = flag | 0x0800
- end
- return true if (bit == 0x01 || bit == 0x08) && bridge == 1
- return true if (bit == 0x02 || bit == 0x04) && bridge == 2
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 確認使是否為調過優先顯示之前方橋面
- #--------------------------------------------------------------------------
- def check_front_bridge(x, y, bit)
- all_tiles(x, y).each do |tile_id|
- flag = tileset.flags[tile_id]
- next if flag & 0x10 == 0
- bridge = check_bridge(tile_id)
- next unless bridge
- return true if (bit == 0x01 || bit == 0x08) && bridge == 2
- return true if (bit == 0x02 || bit == 0x04) && bridge == 1
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 確認前方是否為可通行方向之橋面
- #--------------------------------------------------------------------------
- def check_bridge_passage(x, y, bit)
- all_tiles(x, y).each do |tile_id|
- flag = tileset.flags[tile_id]
- next if flag & 0x10 != 0
- bridge = check_bridge(tile_id)
- next unless bridge
- if flag & 0x0800 == 0x00
- tileset.flags[tile_id] = flag | 0x0800
- end
- return true if (bit == 0x01 || bit == 0x08) && bridge == 2
- return true if (bit == 0x02 || bit == 0x04) && bridge == 1
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 橋面?
- #--------------------------------------------------------------------------
- def check_bridge(tile_id)
- # 痾... 橋面判定... 目前就先以只能直線通行且非梯子為判定吧XD
- return false if tile_id > 2048
- flag = tileset.flags[tile_id]
- return false if flag & 0x20 == 0x20
- return 1 if flag & 0x09 == 0x09 && flag & 0x06 == 0x00
- return 2 if flag & 0x09 == 0x00 && flag & 0x06 == 0x06
- return false
- end
- #--------------------------------------------------------------------------
- # ● 設定橋面顯示優先度
- #--------------------------------------------------------------------------
- def set_bridge(x, y, bit)
- all_tiles(x, y).each do |tile_id|
- flag = tileset.flags[tile_id]
- next unless check_bridge(tile_id)
- pass = flag & 0x0f
- flag = (flag >> 5 << 5) | bit | pass
- tileset.flags[tile_id] = flag
- end
- end
- end
复制代码 这个? |
|