@encounter_count是Game_Player类定义的变量,用途是记录遇敌步数
默认脚本75~80行定义了
[pre lang="ruby"] #--------------------------------------------------------------------------
# * Get Encounter Count
#--------------------------------------------------------------------------
def encounter_count
return @encounter_count
end[/pre]
也就是可以通过$game_player.encounter_count来访问这个数值。
默认脚本81~90行定义了@encounter_count的赋值方法
[pre lang="ruby"] #--------------------------------------------------------------------------
# * Make Encounter Count
#--------------------------------------------------------------------------
def make_encounter_count
# Image of two dice rolling
if $game_map.map_id != 0
n = $game_map.encounter_step
@encounter_count = rand(n) + rand(n) + 1
end
end[/pre]
也就是@encounter_count = @encounter_count = rand(n) + rand(n) + 1 哪怕不算rand随机数,只看 + 1 就可知这个数值绝对不可能在“初始化时赋值为0”
默认脚本update方法定义了@encounter_count的改变。265行左右
也就是每次玩家移动步数减去1,直到减少到0遇敌战斗
[pre lang="ruby"] # If not moving
unless moving?
# If player was moving last time
if last_moving
# Event determinant is via touch of same position event
result = check_event_trigger_here([1,2])
# If event which started does not exist
if result == false
# Disregard if debug mode is ON and ctrl key was pressed
unless $DEBUG and Input.press?(Input::CTRL)
# Encounter countdown
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end[/pre]
Scene_Map update方法定义了遇敌
[pre lang="ruby"]# If encounter list isn't empty, and encounter count is 0
if $game_player.encounter_count == 0 and $game_map.encounter_list != []
# If event is running or encounter is not forbidden
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
# Confirm troop
n = rand($game_map.encounter_list.size)
troop_id = $game_map.encounter_list[n]
# If troop is valid
if $data_troops[troop_id] != nil
# Set battle calling flag
$game_temp.battle_calling = true
$game_temp.battle_troop_id = troop_id
$game_temp.battle_can_escape = true
$game_temp.battle_can_lose = false
$game_temp.battle_proc = nil
end
end
end[/pre]
也就是当这个数值为0,并且设置了敌群,那么就随机一个敌群战斗。