Project1
标题: 请问:@encounter_count的值为什么是0? [打印本页]
作者: kvkv97 时间: 2022-8-30 20:32
标题: 请问:@encounter_count的值为什么是0?
主角移动中,在类Scene_Map中 P $game_player.encounter_count的值和在Game_Player类中P @encounter_count = rand(n) + rand(n) + 1的值,后者的值永远不等于0,为什么$game_player.encounter_count的值可以等于0?
作者: 939034448 时间: 2022-8-31 16:30
本帖最后由 939034448 于 2022-8-31 16:31 编辑
$game_player的encounter_count有被减少的地方,调用@encounter_count = rand(n) + rand(n) + 1这段的方法好像是每次进入地图的时候被调用一次,所以并不是永远不等于0的
作者: kvkv97 时间: 2022-8-31 17:44
有高手指点一下在下的疑惑吗?
作者: 我为鱼肉 时间: 2022-8-31 22:43
本帖最后由 我为鱼肉 于 2022-9-1 22:02 编辑
@encounter_count是Game_Player类定义的变量,用途是记录遇敌步数
默认脚本75~80行定义了
#--------------------------------------------------------------------------
# * Get Encounter Count
#--------------------------------------------------------------------------
def encounter_count
return @encounter_count
end
#--------------------------------------------------------------------------
# * Get Encounter Count
#--------------------------------------------------------------------------
def encounter_count
return @encounter_count
end
也就是可以通过$game_player.encounter_count来访问这个数值。
默认脚本81~90行定义了@encounter_count的赋值方法
#--------------------------------------------------------------------------
# * 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
#--------------------------------------------------------------------------
# * 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
也就是@encounter_count = @encounter_count = rand(n) + rand(n) + 1 哪怕不算rand随机数,只看 + 1 就可知这个数值绝对不可能在“初始化时赋值为0”
默认脚本update方法定义了@encounter_count的改变。265行左右
也就是每次玩家移动步数减去1,直到减少到0遇敌战斗
# 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
# 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
Scene_Map update方法定义了遇敌
# 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
# 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
也就是当这个数值为0,并且设置了敌群,那么就随机一个敌群战斗。
另外,每次地图改变,进入战斗都会重新刷新步数
视频教程那么多,建议好好看看视频教学。很快就学会这些简单的了
不明白你想问什么
@encounter_count = rand(n) + rand(n) + 1
生成遇敌计数,n是地图遇敌步数,默认是30,所以这个值肯定不可能是0
角色每次移动这个值减少,直到等于0遇敌战斗(如果设置了敌队)
$game_player.encounter_count和你说的@encounter_count是一回事。
它是0就战斗,凭什么不让人家等于0。。
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |