sacred-ritual-academy/Scripts/_.10.rb
2025-03-18 19:45:34 -05:00

145 lines
6 KiB
Ruby
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#==============================================================================
# ■ RGSS3 見張りイベント補助 by オシブ
#------------------------------------------------------------------------------
# 使い方イベントスクリプトにfind_player?(main_range, sub_range)と入力します。
# main_range、sub_range は見張りの視界の範囲です。整数を入れてください。
# 見張りがプレイヤーを見つけるとtrueを返します。
# 遮蔽物としたいものには、地形タグに0以外を設定してください。
# 遮蔽物にしたいイベントの名前に特定ワードを入れると判定します。
# また、イベントはプライオリティが「通常キャラ同じ」でないと判定しません。
# 一応seach_playerもイベントスクリプトに入力すると動きます。
# その場合はseach_player(イベントID, main_range, sub_range)を入れてください。
#==============================================================================
module OXIB
#遮蔽物とするイベントにつける名前の言葉
WORD = "ゲート"
end
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ● 障害物のイベントあるかどうか判定
#--------------------------------------------------------------------------
def search_events(x, y)
result = false
return result if events_xy(x, y).empty?
for event in events.values
next if event.x != x
next if event.y != y
next unless event.normal_priority?
result = true if event.name.include?(OXIB::WORD)
end
return result
end
#--------------------------------------------------------------------------
# ● 遮蔽物はあるかどうか判定
#--------------------------------------------------------------------------
def search_shields(x ,y)
return true if terrain_tag(x, y) != 0
return true if search_events(x, y)
return false
end
#--------------------------------------------------------------------------
# ● X軸周辺で遮蔽物があるかどうか判定
#--------------------------------------------------------------------------
def x_search_shields(x ,y)
return false unless search_shields(x ,y)
return true if terrain_tag(x + 1, y) != 0
return true if terrain_tag(x - 1, y) != 0
return true if search_events(x + 1, y)
return true if search_events(x - 1, y)
return false
end
#--------------------------------------------------------------------------
# ● Y軸周辺で遮蔽物があるかどうか判定
#--------------------------------------------------------------------------
def y_search_shields(x ,y)
return false unless search_shields(x ,y)
return true if terrain_tag(x , y + 1) != 0
return true if terrain_tag(x, y - 1) != 0
return true if search_events(x ,y + 1)
return true if search_events(x ,y - 1)
return false
end
end
#==============================================================================
# ■ Game_Interpreter
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# ● プレイヤーが視界に入っているかの判定
#--------------------------------------------------------------------------
def search_player(event, main_range, sub_range = main_range)
event = get_character(event) if event.is_a?(Fixnum)
case event.direction
when 2, 8
x_range = sub_range
y_range = main_range
when 4, 6
x_range = main_range
y_range = sub_range
end
x = event.x
y = event.y
res = false #未発見
for ix in x - x_range..x + x_range
for iy in y - y_range..y + y_range
next if ix < 0 || iy < 0 #マップ外は飛ばす
case event.direction
when 2; next if iy < y + 1 #下を向いている
when 4; next if ix > x - 1 #左を向いている
when 6; next if ix < x + 1 #右を向いている
when 8; next if iy > y - 1 #上を向いている
end
res = true if $game_player.pos?(ix, iy) #発見
break if res #発見したら処理を中断
end
break if res #発見したら処理を中断
end
return res
end
#--------------------------------------------------------------------------
# ● 遮蔽物がイベントとプレイヤーの間にあるかの判定
#--------------------------------------------------------------------------
def find_player?(main_range, sub_range = main_range)
player = $game_player
event = get_character(0)
#視界範囲内にプレイヤーがいない場合は処理を中断
return false unless search_player(event, main_range, sub_range)
min_x = [player.x, event.x].min
max_x = [player.x, event.x].max
min_y = [player.y, event.y].min
max_y = [player.y, event.y].max
flag = true #発見した状態からスタート
case event.direction
when 2, 8 #下か上を向いている
for iy in min_y..max_y
flag = false if $game_map.search_shields(player.x, iy)
if flag == true
for ix in min_x + 1..max_x - 1
flag = false if $game_map.y_search_shields(ix, iy)
end
end
end
return flag #結果を返す
when 4, 6 #左か右を向いている
for ix in min_x..max_x
flag = false if $game_map.search_shields(ix, player.y)
if flag == true
for iy in min_y + 1..max_y - 1
flag = false if $game_map.x_search_shields(ix ,iy)
end
end
end
return flag #結果を返す
end
p "find_player?: error"
return true
end
end