def main
end # line:99
def main
# 战斗之前
1.初始化(准备) 「战斗用数据」
2.生成各种窗口
3.生成活动块
4.执行过渡(窗口的切换)
# 战斗之中
5.战斗
6.更新
# 战斗之后
7.刷新地图
8.释放所有窗口
end # line:99
# 初始化战斗用的各种暂时数据
$game_temp.in_battle = true
$game_temp.battle_turn = 0
$game_temp.battle_event_flags.clear
$game_temp.battle_abort = false
$game_temp.battle_main_phase = false
$game_temp.battleback_name = $game_map.battleback_name
$game_temp.forcing_battler = nil
# 初始化战斗用事件解释器
$game_system.battle_interpreter.setup(nil, 0)
# 准备队伍
@troop_id = $game_temp.battle_troop_id
$game_troop.setup(@troop_id)
$game_temp.in_battle = true # 「角色处于战斗当中」标志 为 true
$game_temp.battle_turn = 0 # 建立「回合数」=0
$game_temp.battle_event_flags.clear # 清除所有战斗事件
$game_temp.battle_abort = false # 「战斗中断」标志 为 false
$game_temp.battle_main_phase = false # 「战斗状态」标志 为 false
$game_temp.battleback_name = $game_map.battleback_name # 读取「战斗背景」文件名
$game_temp.forcing_battler = nil # 清除「强制行动的战斗者」
# 初始化战斗用事件解释器
$game_system.battle_interpreter.setup(nil, 0)
# 准备队伍 <-(这里指的是「敌人队伍」)
@troop_id = $game_temp.battle_troop_id # 读取敌人队伍ID
$game_troop.setup(@troop_id) # 把敌人队伍Id 告诉 Game_Troop这个脚本,然后建
@troop_id = $game_temp.battle_troop_id # 读取敌人队伍ID
# 遇敌计数为 0 且、且遇敌列表不为空的情况下
if $game_player.encounter_count == 0 and $game_map.encounter_list != []
# 不是在事件执行中或者禁止遇敌中
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
# 确定队伍
n = rand($game_map.encounter_list.size)
troop_id = $game_map.encounter_list[n]
# 队伍有效的话
if $data_troops[troop_id] != nil
# 设置调用战斗标志
$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
# 生成角色命令窗口
s1 = $data_system.words.attack
s2 = $data_system.words.skill
s3 = $data_system.words.guard
s4 = $data_system.words.item
@actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
@actor_command_window.y = 160
@actor_command_window.back_opacity = 160
@actor_command_window.active = false
@actor_command_window.visible = false
# 生成其它窗口
@party_command_window = Window_PartyCommand.new
@help_window = Window_Help.new
@help_window.back_opacity = 160
@help_window.visible = false
@status_window = Window_BattleStatus.new
@message_window = Window_Message.new
@actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
s1 = $data_system.words.attack
s2 = $data_system.words.skill
s3 = $data_system.words.guard
s4 = $data_system.words.item
s1 = $data_system.words.attack # 系统当中的「攻击」描述文字
s2 = $data_system.words.skill # 系统当中的「技能」描述文字
s3 = $data_system.words.guard # 系统当中的「防御」描述文字
s4 = $data_system.words.item # 系统当中的「物品」描述文字
@actor_command_window.y = 160
@actor_command_window.back_opacity = 160
@actor_command_window.active = false
@actor_command_window.visible = false
@party_command_window = Window_PartyCommand.new
@help_window = Window_Help.new
@help_window.back_opacity = 160
@help_window.visible = false
@status_window = Window_BattleStatus.new
@message_window = Window_Message.new
@spriteset = Spriteset_Battle.new
# 初始化等待计数
@wait_count = 0
# 执行过渡
if $data_system.battle_transition == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$data_system.battle_transition)
end
# 开始自由战斗回合
start_phase1
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面切换的话就中断循环
if $scene != self
break
end
end
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面切换的话就中断循环
if $scene != self
break
end
# 刷新地图
$game_map.refresh
# 准备过渡
Graphics.freeze
# 释放窗口
@actor_command_window.dispose
@party_command_window.dispose
@help_window.dispose
@status_window.dispose
@message_window.dispose
if @skill_window != nil
@skill_window.dispose
end
if @item_window != nil
@item_window.dispose
end
if @result_window != nil
@result_window.dispose
end
# 释放活动块
@spriteset.dispose
# 标题画面切换中的情况
if $scene.is_a?(Scene_Title)
# 淡入淡出画面
Graphics.transition
Graphics.freeze
end
# 战斗测试或者游戏结束以外的画面切换中的情况
if $BTEST and not $scene.is_a?(Scene_Gameover)
$scene = nil
end
# 准备过渡
Graphics.freeze
if @skill_window != nil
@skill_window.dispose
end
if @item_window != nil
@item_window.dispose
end
if @result_window != nil
@result_window.dispose
end
@skill_window # 技能选择窗口
@item_window # 物品选择窗口
@result_window # 战斗结果窗口
# 标题画面切换中的情况
if $scene.is_a?(Scene_Title)
# 淡入淡出画面
Graphics.transition
Graphics.freeze
end
def update
end
def update
1.执行战斗事件
2.系统 (计时器)、刷新画面
3.刷新各窗口
4.「冻结」战斗画面
5.进行战斗
end
# 执行战斗事件中的情况下
if $game_system.battle_interpreter.running?
# 刷新解释器
$game_system.battle_interpreter.update
# 强制行动的战斗者不存在的情况下
if $game_temp.forcing_battler == nil
# 执行战斗事件结束的情况下
unless $game_system.battle_interpreter.running?
# 继续战斗的情况下、再执行战斗事件的设置
unless judge
setup_battle_event
end
end
# 如果不是结束战斗回合的情况下
if @phase != 5
# 刷新状态窗口
@status_window.refresh
end
end
end
# 执行战斗事件中的情况下
if $game_system.battle_interpreter.running?
def running?
return @list != nil
end
def judge
# 全灭判定是真、并且同伴人数为 0 的情况下
if $game_party.all_dead? or $game_party.actors.size == 0
# 允许失败的情况下
if $game_temp.battle_can_lose
# 还原为战斗开始前的 BGM
$game_system.bgm_play($game_temp.map_bgm)
# 战斗结束
battle_end(2)
# 返回 true
return true
end
# 设置游戏结束标志
$game_temp.gameover = true
# 返回 true
return true
end
# 如果存在任意 1 个敌人就返回 false
for enemy in $game_troop.enemies
if enemy.exist?
return false
end
end
# 开始结束战斗回合 (胜利)
start_phase5
# 返回 true
return true
end
# 全灭判定是真、并且同伴人数为 0 的情况下
if $game_party.all_dead? or $game_party.actors.size == 0
# 允许失败的情况下
if $game_temp.battle_can_lose
end
# 否则:
# 设置游戏结束标志
$game_temp.gameover = true
# 返回 true
return true
# 还原为战斗开始前的 BGM
$game_system.bgm_play($game_temp.map_bgm)
# 战斗结束,返回参数「2」
battle_end(2)
# 返回 true否则:
# 设置游戏结束标志
$game_temp.gameover = true
# 返回 true
return true
#--------------------------------------------------------------------------
# ● 战斗结束
# result : 结果 (0:胜利 1:失败 2:逃跑)
#--------------------------------------------------------------------------
def battle_end(result)
end
# 调用战斗返回调用
if $game_temp.battle_proc != nil
$game_temp.battle_proc.call(result)
$game_temp.battle_proc = nil
end
def setup_battle_event
# 正在执行战斗事件的情况下
if $game_system.battle_interpreter.running?
return
end
# 搜索全部页的战斗事件
for index in 0...$data_troops[@troop_id].pages.size
# 获取事件页
page = $data_troops[@troop_id].pages[index]
# 事件条件可以参考 c
c = page.condition
# 没有指定任何条件的情况下转到下一页
unless c.turn_valid or c.enemy_valid or
c.actor_valid or c.switch_valid
next
end
# 执行完毕的情况下转到下一页
if $game_temp.battle_event_flags[index]
next
end
# 确认回合条件
if c.turn_valid
n = $game_temp.battle_turn
a = c.turn_a
b = c.turn_b
if (b == 0 and n != a) or
(b > 0 and (n < 1 or n < a or n % b != a % b))
next
end
end
# 确认敌人条件
if c.enemy_valid
enemy = $game_troop.enemies[c.enemy_index]
if enemy == nil or enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp
next
end
end
# 确认角色条件
if c.actor_valid
actor = $game_actors[c.actor_id]
if actor == nil or actor.hp * 100.0 / actor.maxhp > c.actor_hp
next
end
end
# 确认开关条件
if c.switch_valid
if $game_switches[c.switch_id] == false
next
end
end
# 设置事件
$game_system.battle_interpreter.setup(page.list, 0)
# 本页的范围是 [战斗] 或 [回合] 的情况下
if page.span <= 1
# 设置执行结束标志
$game_temp.battle_event_flags[index] = true
end
return
end
end
# 执行战斗事件中的情况下
if $game_system.battle_interpreter.running?
# 执行战斗事件结束的情况下
unless $game_system.battle_interpreter.running?
$game_system.battle_interpreter.update
# 正在执行战斗事件的情况下
if $game_system.battle_interpreter.running?
return
end
# 搜索全部页的战斗事件
for index in 0...$data_troops[@troop_id].pages.size
# 获取事件页
page = $data_troops[@troop_id].pages[index]
# 事件条件可以参考 c
c = page.condition
# 系统 (计时器)、刷新画面
$game_system.update
$game_screen.update
# 计时器为 0 的情况下
if $game_system.timer_working and $game_system.timer == 0
# 中断战斗
$game_temp.battle_abort = true
end
$game_system.update # 更新定时器
$game_screen.update # 刷新画面
# 计时器为 0 的情况下
if $game_system.timer_working and $game_system.timer == 0
# 中断战斗
$game_temp.battle_abort = true
end
# 刷新窗口
@help_window.update # 刷新帮助窗口
@party_command_window.update # 刷新「战」或「逃」选择窗口
@actor_command_window.update # 刷新「行动命令窗口」
@status_window.update # 刷新「角色状态窗口」
@message_window.update # 刷新「信息窗口」
# 刷新活动块
@spriteset.update
# 处理过渡中的情况下
if $game_temp.transition_processing
# 清除处理过渡中标志
$game_temp.transition_processing = false
# 执行过渡
if $game_temp.transition_name == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$game_temp.transition_name)
end
end
# 显示信息窗口中的情况下
if $game_temp.message_window_showing
return
end
# 显示效果中的情况下
if @spriteset.effect?
return
end
# 游戏结束的情况下
if $game_temp.gameover
# 切换到游戏结束画面
$scene = Scene_Gameover.new
return
end
# 返回标题画面的情况下
if $game_temp.to_title
# 切换到标题画面
$scene = Scene_Title.new
return
end
# 中断战斗的情况下
if $game_temp.battle_abort
# 还原为战斗前的 BGM
$game_system.bgm_play($game_temp.map_bgm)
# 战斗结束
battle_end(1)
return
end
# 等待中的情况下
if @wait_count > 0
# 减少等待计数
@wait_count -= 1
return
end
# 强制行动的角色存在、
# 并且战斗事件正在执行的情况下
if $game_temp.forcing_battler == nil and
$game_system.battle_interpreter.running?
return
end
# 显示信息窗口中的情况下
if $game_temp.message_window_showing
return
end
# 显示效果中的情况下
if @spriteset.effect?
return
end
# 游戏结束的情况下
if $game_temp.gameover
# 切换到游戏结束画面
$scene = Scene_Gameover.new
return
end
# 返回标题画面的情况下
if $game_temp.to_title
# 切换到标题画面
$scene = Scene_Title.new
return
end
# 中断战斗的情况下
if $game_temp.battle_abort
# 还原为战斗前的 BGM
$game_system.bgm_play($game_temp.map_bgm)
# 战斗结束
battle_end(1)
return
end
# 等待中的情况下
if @wait_count > 0
# 减少等待计数
@wait_count -= 1
return
end
# 强制行动的角色存在、
# 并且战斗事件正在执行的情况下
if $game_temp.forcing_battler == nil and
$game_system.battle_interpreter.running?
return
end
# 回合分支
case @phase
when 1 # 自由战斗回合
update_phase1
when 2 # 同伴命令回合
update_phase2
when 3 # 角色命令回合
update_phase3
when 4 # 主回合
update_phase4
when 5 # 战斗结束回合
update_phase5
end
以下引用永远的卡卡布于2008-3-1 14:28:29的发言:
主站上某分析RTAB战斗系统的文章顺带分析过默认的系统
以下引用天圣的马甲于2008-3-2 12:13:48的发言:
好长……但是真的很强。呼叫斑竹过来鼓励并发布。-v-
以下引用Iselia雪于2008-3-2 12:20:17的发言:
默认战斗系统的精髓就是复杂的刷新判断
# 回合分支
case @phase
when 1 # 自由战斗回合
update_phase1
when 2 # 同伴命令回合
update_phase2
when 3 # 角色命令回合
update_phase3
when 4 # 主回合
update_phase4
when 5 # 战斗结束回合
update_phase5
end
# 回合分支
case @phase
when 1 # 自由战斗回合-(实际是「敌人出现」和「战斗事件设置」的回合)
update_phase1
when 2 # 同伴命令回合-(实际是「战」或「逃」的选择回合)
update_phase2
when 3 # 角色命令回合-(实际是选择「战斗行动」的回合)
update_phase3
when 4 # 主回合-(真正的战斗开始)
update_phase4
when 5 # 战斗结束回合-(结束战斗)
update_phase5
end
start_phase1(遇见敌人)
┃
┃ 更新_phase1
┆
┎┈ start_phase2(选择战斗或者逃跑)
┃ ┃ 更新 phase2
┃返 ┃ case 指令窗口光标位置
┃回 ┃ ┃┆ ┃
┃ ┃ ┃┃(战) ┃(逃)
┃战 ┃ ┆┃ ┆
┃或 ┃ start_phase3 update_phase2_escape
┃逃 ┃ (选择行动) (进行逃跑判断)
┃ ┃ ┃ ┃ ┃
┃选 ┃ 更新 phase3 ┃ ┃(成功) ┃(失败)
┃择 ┃ ┆ ┆ ┃
┃ ┃ phase3_next_actor 返回地图 ┃
┃ ┃ (下个角色) ┃
┃ ┃ ┃ ┃
┃ ┃ ┆ ┃
┃ ┗━━━┈ start_phase4(主战斗) ┈━━━━┛
┃ ┃
┃ phase4回合结束 ┃更新 phase4
┗━━━━━━━━━━━┫
┃if judge(判断为战斗结束) = true
┆
start_phase5(结束战斗)
┃
┃update_phase5
┆
返回地图
def update_phase4
case @phase4_step
when 1
update_phase4_step1
when 2
update_phase4_step2
when 3
update_phase4_step3
when 4
update_phase4_step4
when 5
update_phase4_step5
when 6
update_phase4_step6
end
end
def start_phase1
# 转移到回合 1
@phase = 1
# 清除全体同伴的行动
$game_party.clear_actions
# 设置战斗事件
setup_battle_event
end
$game_party.actors[0].add_state(1) # 角色1添加战斗不能的状态
$game_party.actors[1].add_state(1) if $game_party.actors[1] !=nil # 如果角色2存在就添加战斗不能的状态
def update_phase1
# 胜败判定
if judge
# 胜利或者失败的情况下 : 过程结束
return
end
# 开始同伴命令回合
start_phase2
end
# 开始同伴指令回合
start_phase2
def start_phase2
end
# 有效化同伴指令窗口
# 「战」或「逃」的选择活动 = true
@party_command_window.active = true
# 「战」或「逃」的选择可视 = true
@party_command_window.visible = true
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
# 开始同伴指令回合
start_phase2
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
# 清除主回合标志
$game_temp.battle_main_phase = false
$game_temp.battle_main_phase
# 不是主状态的时候稍稍降低点透明度
if $game_temp.battle_main_phase
self.opacity += 3 if self.opacity < 255
else
self.opacity -= 3 if self.opacity > 207
end
end
# 清除全体同伴的行动
$game_party.clear_actions
phase2到phase4的关系:
┏┄ phase2
┃ 逃(失败) 战
┃ ┃ ┃
┃ ┆ ┆
┗ pahse4 <= phase3
# 不能输入命令的情况下
unless $game_party.inputable?
# 开始主回合
start_phase4
end
# 设置角色为非选择状态
@actor_index = -1
@active_battler = nil
# 转移到回合 2
@phase = 2
def update_phase2
# 按下 C 键的情况下
if Input.trigger?(Input::C)
end
end
# 同伴指令窗口光标位置分支
case @party_command_window.index
when 0 # 战斗
when 1 # 逃跑
end
return
if a == 1
p "a"
elsif a == 2
p "b"
end
case a
when 1
p "a"
when 2
p "b"
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 开始角色的命令回合
start_phase3
# 不能逃跑的情况下
if $game_temp.battle_can_escape == false
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 逃走处理
update_phase2_escape
if $game_temp.battle_can_escape == false
return
end
return
def update_phase2_escape
# 逃跑成功判定
success = rand(100) < 50 * actors_agi / enemies_agi
# 成功逃跑的情况下
if success
else
end
end
if rand(100) < (50 * actors_agi / enemies_agi)
success = true
else
success = false
end
# 计算敌人速度的平均值
enemies_agi = 0
enemies_number = 0
for enemy in $game_troop.enemies
if enemy.exist?
enemies_agi += enemy.agi
enemies_number += 1
end
end
if enemies_number > 0
enemies_agi /= enemies_number
end
enemies_agi = 0 # 为enemies_agi 先赋值为 0
enemies_number = 0 # 为enemies_number 先赋值为 0
enemies_agi += enemy.agi
enemies_number += 1
for enemy in $game_troop.enemies
if enemy.exist?
enemies_agi += enemy.agi
enemies_number += 1
end
end
# 如果敌人数量大於0
if enemies_number > 0
# 「总agi数值」除以「敌人数目」
enemies_agi /= enemies_number
# 求得敌人单体的平均速度
end
success = rand(100) < 50 * actors_agi / enemies_agi
# 演奏逃跑 SE
$game_system.se_play($data_system.escape_se)
# 还原为战斗开始前的 BGM
$game_system.bgm_play($game_temp.map_bgm)
# 战斗结束
battle_end(1)
def battle_end(result)
end
def battle_end(result)
# 清除战斗中标志
$game_temp.in_battle = false
# 清除全体同伴的行动
$game_party.clear_actions
# 解除战斗用状态
for actor in $game_party.actors
actor.remove_states_battle
end
# 清除敌人
$game_troop.enemies.clear
# 如果调用战斗返回调用不为nil
if $game_temp.battle_proc != nil
# 告诉程序战斗的结果
$game_temp.battle_proc.call(result)
# 清空战斗返回调用
$game_temp.battle_proc = nil
end
# 返回到地图画面
$scene = Scene_Map.new
end
def remove_states_battle
for i in @states.clone
if $data_states.battle_only
remove_state(i)
end
end
end
$scene = Scene_Map.new
# 清除全体同伴的行动
$game_party.clear_actions
# 开始主回合
start_phase4
@help_window.set_text("逃走失败", 1)
@help_window.visible = true
@wait_count = 20
if @wait_count == 0
@help_window.visible = false
end
def start_phase3
# 转移到回合 3
@phase = 3
end
def update_phase3
# 开始主回合
start_phase4
end
def start_phase4
# 转移到回合 4
@phase = 4
end
def update_phase4
if judge # 如果不需要继续战斗
# 结束战斗
start_phase5
else # 如果需要继续战斗
# 返回「战」或「逃」的选择
start_phase2
end
end
def start_phase5
end
# 演奏战斗结束 ME
$game_system.me_play($game_system.battle_end_me)
# 还原为战斗开始前的 BGM
$game_system.bgm_play($game_temp.map_bgm)
# 生成战斗结果窗口
@result_window = Window_BattleResult.new(exp, gold, treasures)
# 设置等待计数
@phase5_wait_count = 100
# 取得战利品
get_trophies
def get_trophies
end
# 初始化 EXP、金钱、宝物
exp = 0
gold = 0
treasures = []
# 循环
for enemy in $game_troop.enemies
end
# 敌人不是隐藏状态的情况下
unless enemy.hidden
# 获得 EXP、增加金钱
exp += enemy.exp
gold += enemy.gold
# 出现宝物判定
if rand(100) < enemy.treasure_prob
end
if enemy.item_id > 0
treasures.push($data_items[enemy.item_id])
end
if enemy.weapon_id > 0
treasures.push($data_weapons[enemy.weapon_id])
end
if enemy.armor_id > 0
treasures.push($data_armors[enemy.armor_id])
end
# 限制宝物数为 6 个
treasures = treasures[0..5]
# 获得 EXP
for i in 0...$game_party.actors.size
actor = $game_party.actors
end
if actor.cant_get_exp? == false
last_level = actor.level
actor.exp += exp
end
if actor.level > last_level
# 显示升级的提示
@status_window.level_up(i)
end
# 获得金钱
$game_party.gain_gold(gold)
# 获得宝物
for item in treasures
case item
# 当宝物的父类是物品
when RPG::Item
# 调用获得物品的方法
$game_party.gain_item(item.id, 1)
# 当宝物的父类是武器
when RPG::Weapon
# 调用获得武器的方法
$game_party.gain_weapon(item.id, 1)
# 当宝物的父类是防具
when RPG::Armor
# 调用获得防具的方法
$game_party.gain_armor(item.id, 1)
end
end
# 等待计数大于 0 的情况下
if @phase5_wait_count > 0
# 减少等待计数
@phase5_wait_count -= 1
# 当等待计数为 0 的情况下
if @phase5_wait_count == 0
# 显示结果窗口
@result_window.visible = true
# 清除主回合标志
$game_temp.battle_main_phase = false
# 刷新状态窗口
@status_window.refresh
end
# 结束方法
return
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 战斗结束
battle_end(0)
end
def start_phase3
# 转移到回合 3
@phase = 3
# 设置觉得为非选择状态
@actor_index = -1
@active_battler = nil
# 输入下一个角色的命令
phase3_next_actor
end
@actor_index = -1
@active_battler = nil
def phase3_prior_actor
end
# 循环
begin
end until @active_battler.inputable?
def inputable?
return (not @hidden and restriction <= 1)
end
# 角色的明灭效果 OFF
if @active_battler != nil
@active_battler.blink = false
end
# 最后的角色的情况
if @actor_index == $game_party.actors.size-1
# 开始主回合
start_phase4
return
end
# 推进角色索引
@actor_index += 1
@active_battler = $game_party.actors[@actor_index]
@active_battler.blink = true
# 明灭
if @battler.blink
blink_on
else
blink_off
end
# 设置角色的命令窗口
phase3_setup_command_window
def phase3_setup_command_window
end
# 同伴指令窗口无效化
@party_command_window.active = false
@party_command_window.visible = false
# 角色指令窗口无效化
@actor_command_window.active = true
@actor_command_window.visible = true
# 设置角色指令窗口的位置
@actor_command_window.x = @actor_index * 160
# 设置索引为 0
@actor_command_window.index = 0
def update_phase3
end
if a == true
p "true"
end
if a
p "true"
end
def update_phase3
# 如果敌人箭头光标(Sprite-活动块)存在
if @enemy_arrow != nil
# 更新选择敌人箭头光标
update_phase3_enemy_select
# 如果角色箭头光标(Sprite-活动块)存在
elsif @actor_arrow != nil
# 更新选择角色箭头光标
update_phase3_actor_select
# 如果特技窗口(窗口)存在
elsif @skill_window != nil
# 更新特技选择窗口
update_phase3_skill_select
# 如果物品窗口(窗口)存在
elsif @item_window != nil
# 更新物品选择窗口
update_phase3_item_select
# 如果角色指令窗口(窗口)活动
elsif @actor_command_window.active
# 更新角色指令窗口
update_phase3_basic_command
end
end
def update_phase3_basic_command
# 按下 B 键的情况下
if Input.trigger?(Input::B)
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
end
end
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 转向前一个角色的指令输入
phase3_prior_actor
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 角色指令窗口光标位置分歧
case @actor_command_window.index
when 0 # 攻击
when 1 # 特技
when 2 # 防御
when 3 # 物品
end
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
@active_battler.current_action.kind
# 行动种类分支
case @active_battler.current_action.kind
when 0 # 基本
make_basic_action_result
when 1 # 特技
make_skill_action_result
when 2 # 物品
make_item_action_result
end
@active_battler.current_action.kind
# 攻击的情况下
if @active_battler.current_action.basic == 0
# 设置攻击动画 ID
@animation1_id = @active_battler.animation1_id
@animation2_id = @active_battler.animation2_id
return
end
# 防御的情况下
if @active_battler.current_action.basic == 1
# 帮助窗口显示"防御"
@help_window.set_text($data_system.words.guard, 1)
return
end
# 逃跑的情况下
if @active_battler.is_a?(Game_Enemy) and
@active_battler.current_action.basic == 2
# 帮助窗口显示"逃跑"
@help_window.set_text("逃跑", 1)
# 逃跑
@active_battler.escape
return
end
# 什么也不做的情况下
if @active_battler.current_action.basic == 3
# 清除强制行动对像的战斗者
$game_temp.forcing_battler = nil
# 移至步骤 1
@phase4_step = 1
return
end
end
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 1
@active_battler.current_action.kind = 1
@active_battler.current_action.kind = 2
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 角色指令窗口光标位置分歧
case @actor_command_window.index
when 0 # 攻击
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
start_enemy_select # 开始选择敌人
when 1 # 特技
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
start_skill_select # 开始选择特技
when 2 # 防御
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
phase3_next_actor# 直接此角色的结束选择窗口,进入下个角色的选择窗口
when 3 # 物品
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
start_item_select # 开始选择物品
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
#---------------------------------------------------
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
#---------------------------------------------------
# 角色指令窗口光标位置分歧
case @actor_command_window.index
when 0 # 攻击
start_enemy_select # 开始选择敌人
when 1 # 特技
start_skill_select # 开始选择特技
when 2 # 防御
phase3_next_actor# 直接此角色的结束选择窗口,进入下个角色的选择窗口
when 3 # 物品
start_item_select # 开始选择物品
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
#---------------------------------------------------
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
#---------------------------------------------------
# 角色指令窗口光标位置分歧
case @actor_command_window.index
when 0 # 攻击
#--------------------------------------------
# 设置行动
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
#--------------------------------------------
start_enemy_select # 开始选择敌人
when 1 # 特技
#--------------------------------------------
# 设置行动
@active_battler.current_action.kind = 1
#--------------------------------------------
start_skill_select # 开始选择特技
when 2 # 防御
#--------------------------------------------
# 设置行动
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 1
#--------------------------------------------
phase3_next_actor# 直接此角色的结束选择窗口,进入下个角色的选择窗口
when 3 # 物品
#--------------------------------------------
# 设置行动
@active_battler.current_action.kind = 2
#--------------------------------------------
start_item_select # 开始选择物品
end
具体来说,整个phase3 的 update过程可以用下图表示
上一位角色的选择窗口
┃按下B键
指令窗口
┃按下C键
┏━━━━━┳━━┻━━┳━━━━━┓
┃(攻击) ┃(技能) ┃(防御) ┃(物品)
┃ ┗━━━━━━━━━┓
┃ 选择招数 选择物品 ┃
┃ ┃
┃ ┃ ┃ ┃
┃ ┗━━┳━━━━━┳━━┛ ┃
┃ ┃
┗━━━━━ 选择敌人 / 选择队友(or自己) ┃
┃
┗━━┳━━┛ ┃
┃
下个角色的选择窗口 ━┛
#--------------------------------------------------------------------------
# ● 开始选择特技
#--------------------------------------------------------------------------
def start_skill_select
# 临时生成特技窗口
@skill_window = Window_Skill.new(@active_battler)
# 生成关联帮助窗口-(描述技能)
@skill_window.help_window = @help_window
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
end
#--------------------------------------------------------------------------
# ● 刷新画面 (角色命令回合 : 选择特技)
#--------------------------------------------------------------------------
def update_phase3_skill_select
# 设置特技窗口为可视状态
@skill_window.visible = true
# 刷新特技窗口
@skill_window.update
# 按下 B 键的情况下(取消)
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 结束特技选择
end_skill_select
return
end
# 按下 C 键的情况下(确认)
if Input.trigger?(Input::C)
# 获取特技选择窗口现在选择的特技的数据
@skill = @skill_window.skill
# 如果无法使用-(技能不存在 或者 技能不能使用)
if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 如果可以使用:
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置角色将要使用的技能
@active_battler.current_action.skill_id = @skill.id
# 设置特技窗口为不可见状态
@skill_window.visible = false
# 效果范围是敌单体的情况下
if @skill.scope == 1
# 开始选择敌人
start_enemy_select
# 如果效果范围是我方单体 或者 我方单体(hp 0)
elsif @skill.scope == 3 or @skill.scope == 5
# 开始选择角色
start_actor_select
# 此外:(全体、自身、己方全体、己方全体(hp 0))
else
# 选择特技结束
end_skill_select
# 转到下一位角色的指令输入
phase3_next_actor
end
return
end
end
@active_battler.current_action.skill_id = @skill.id
#--------------------------------------------------------------------------
# ● 选择特技结束
#--------------------------------------------------------------------------
def end_skill_select
# 释放特技窗口
@skill_window.dispose
# nil化
@skill_window = nil
# 隐藏帮助窗口
@help_window.visible = false
# 有效化角色指令窗口
@actor_command_window.active = true
@actor_command_window.visible = true
end
#--------------------------------------------------------------------------
# ● 开始选择敌人
#--------------------------------------------------------------------------
def start_enemy_select
# 生成敌人箭头
@enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1)
# 关联帮助窗口
@enemy_arrow.help_window = @help_window
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
end
#--------------------------------------------------------------------------
# ● 刷新画面画面 (角色命令回合 : 选择敌人)
#--------------------------------------------------------------------------
def update_phase3_enemy_select
# 刷新敌人箭头
@enemy_arrow.update
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 选择敌人结束
end_enemy_select
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置目标(单体) - 根据选择指示箭头的位置确定
@active_battler.current_action.target_index = @enemy_arrow.index
# 选择敌人结束
end_enemy_select
# 显示特技窗口中的情况下
if @skill_window != nil
# 结束特技选择
end_skill_select
end
# 显示物品窗口的情况下
if @item_window != nil
# 结束物品选择
end_item_select
end
# 转到下一位角色的指令输入
phase3_next_actor
end
end
# 显示特技窗口中的情况下
if @skill_window != nil
# 结束特技选择
end_skill_select
end
# 显示物品窗口的情况下
if @item_window != nil
# 结束物品选择
end_item_select
end
#--------------------------------------------------------------------------
# 设置目标(单体) - 根据选择指示箭头的位置确定
@active_battler.current_action.target_index = @enemy_arrow.index
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# ● 结束选择敌人
#--------------------------------------------------------------------------
def end_enemy_select
# 释放敌人箭头
@enemy_arrow.dispose
@enemy_arrow = nil
# 指令为 [战斗] 的情况下
if @actor_command_window.index == 0
# 有效化角色指令窗口
@actor_command_window.active = true
@actor_command_window.visible = true
# 隐藏帮助窗口
@help_window.visible = false
end
end
# 转到下一位角色的指令输入
phase3_next_actor
#--------------------------------------------------------------------------
# ● 转到输入下一个角色的命令
#--------------------------------------------------------------------------
def phase3_next_actor
end
def phase3_next_actor
#-------------------------------------------------------
# 循环
begin
# 如果角色是在无法接受指令的状态就再试
end until @active_battler.inputable?
#-------------------------------------------------------
end
def phase3_next_actor
# 循环
begin
#-------------------------------------------------------
# 角色的明灭效果 OFF
if @active_battler != nil
@active_battler.blink = false
end
#-------------------------------------------------------
# 如果角色是在无法接受指令的状态就再试
end until @active_battler.inputable?
end
def phase3_next_actor
# 循环
begin
# 角色的明灭效果 OFF
if @active_battler != nil
@active_battler.blink = false
end
#-------------------------------------------------------
# 最后的角色的情况
if @actor_index == $game_party.actors.size-1
# 开始主回合
start_phase4
return
end
#-------------------------------------------------------
# 如果角色是在无法接受指令的状态就再试
end until @active_battler.inputable?
end
def phase3_next_actor
# 循环
begin
# 角色的明灭效果 OFF
if @active_battler != nil
@active_battler.blink = false
end
# 最后的角色的情况
if @actor_index == $game_party.actors.size-1
# 开始主回合
start_phase4
return
end
#-------------------------------------------------------
# 推进角色索引
@actor_index += 1
@active_battler = $game_party.actors[@actor_index]
@active_battler.blink = true
#-------------------------------------------------------
# 如果角色是在无法接受指令的状态就再试
end until @active_battler.inputable?
end
def phase3_next_actor
# 循环
begin
# 角色的明灭效果 OFF
if @active_battler != nil
@active_battler.blink = false
end
# 最后的角色的情况
if @actor_index == $game_party.actors.size-1
# 开始主回合
start_phase4
return
end
# 推进角色索引
@actor_index += 1
@active_battler = $game_party.actors[@actor_index]
@active_battler.blink = true
# 如果角色是在无法接受指令的状态就再试
end until @active_battler.inputable?
#-------------------------------------------------------
# 设置角色的命令窗口
phase3_setup_command_window
#-------------------------------------------------------
end
以下引用精灵使者于2008-3-4 13:49:26的发言:
很多东西的语法都很明了。
.index类初始化都是-1,我方逃跑的时候占用了整个回合数(这很明显)。另外,为-1的话就不会显示光标(这个方法在选择类很常用)
其实小数点这个使用很广泛,一个是调用函数,带回返回值。
一个是调用某个类里面的某个变量。
执行.new其实就是
执行这个Scene类的installize函数。
如果有main函数的话,执行main函数在这里定义:
在main函数里面有一句
while $scene != nil
$scene.main
end
就是执行的他。
据说,如果临时生成窗口或者销毁窗口的话,会引起系统不稳定(我的游戏里就碰到了)
以下引用禾西于2008-3-4 14:17:50的发言:
很不幸地告訴妳,這個我也有遇到過了……Orz
[本贴由作者于 2008-3-4 14:19:04 最后编辑]
上一位角色的选择窗口
┃按下B键
指令窗口
┃按下C键
┏━━━━━┳━━┻━━┳━━━━━┓
┃(攻击) ┃(技能) ┃(防御) ┃(物品)
┃ ┗━━━━━━━━━┓
┃ 选择招数 选择物品 ┃
┃ ┃
┃ ┃ ┃ ┃
┃ ┗━━┳━━━━━┳━━┛ ┃
┃ ┃
┗━━━━━ 选择敌人 / 选择队友(or自己) ┃
┃
┗━━┳━━┛ ┃
┃
下个角色的选择窗口 ━┛
def start_phase4
end
# 转移到回合 4
@phase = 4
# 回合数计数
$game_temp.battle_turn += 1
# 搜索全页的战斗事件
for index in 0...$data_troops[@troop_id].pages.size
# 获取事件页
page = $data_troops[@troop_id].pages[index]
# 本页的范围是 [回合] 的情况下
if page.span == 1
# 设置已经执行标志
$game_temp.battle_event_flags[index] = false
end
end
# 设置角色为非选择状态
@actor_index = -1
@active_battler = nil
# 有效化同伴指令窗口
@party_command_window.active = false
@party_command_window.visible = false
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
# 设置主回合标志
$game_temp.battle_main_phase = true
在Sprite_Battler
line:67
[quote]
# 不是主状态的时候稍稍降低点透明度
if $game_temp.battle_main_phase
self.opacity += 3 if self.opacity < 255
else
self.opacity -= 3 if self.opacity > 207
end
end
# 生成敌人行动
for enemy in $game_troop.enemies
enemy.make_action
end
enemy.make_action
Game_Enemy
line:251
[quote]
def make_action
end
# 清除当前行动
self.current_action.clear
# 无法行动的情况
unless self.movable?
# 过程结束
return
end
# 抽取现在有效的行动
available_actions = []
rating_max = 0
for action in self.actions
n = $game_temp.battle_turn
a = action.condition_turn_a
b = action.condition_turn_b
if (b == 0 and n != a) or
(b > 0 and (n < 1 or n < a or n % b != a % b))
next
end
1/4 = 0.25
12/5 = 2.5
1%4 = 1
12%5 = 2
# 确认 HP 条件
if self.hp * 100.0 / self.maxhp > action.condition_hp
next
end
# 确认等级条件
if $game_party.max_level < action.condition_level
next
end
# 确认开关条件
switch_id = action.condition_switch_id
if switch_id > 0 and $game_switches[switch_id] == false
next
end
# 符合条件 : 添加本行动
available_actions.push(action)
if action.rating > rating_max
rating_max = action.rating
end
ratings_total = 0
for action in available_actions
if action.rating > rating_max - 3
ratings_total += action.rating - (rating_max - 3)
end
# 概率合计不为 0 的情况下
if ratings_total > 0
# 根据概率合计生成允许差额
value = rand(ratings_total)
# 取得可用行为的数据
for action in available_actions
# 如果可用行为的概率比(最高概率-3)大
if action.rating > rating_max - 3
# 如果允许差额 比 「可用行为的概率」与「最高概率-3」之间的差额小
if value < action.rating - (rating_max - 3)
# 自动设置行为 - 如同角色一样
self.current_action.kind = action.kind
self.current_action.basic = action.basic
self.current_action.skill_id = action.skill_id
# 随机目标(敌人用)- 参考:Game_BattleAction - line:95
self.current_action.decide_random_target_for_enemy
return
else
# 否则,再缩小允许差额
value -= action.rating - (rating_max - 3)
end
end
end
end
# 生成行动顺序
make_action_orders
#--------------------------------------------------------------------------
# ● 生成行动循序
#--------------------------------------------------------------------------
def make_action_orders
# 初始化序列 @action_battlers
@action_battlers = []
# 添加敌人到 @action_battlers 序列
for enemy in $game_troop.enemies
@action_battlers.push(enemy)
end
# 添加角色到 @action_battlers 序列
for actor in $game_party.actors
@action_battlers.push(actor)
end
# 确定全体的行动速度
for battler in @action_battlers
battler.make_action_speed
# 参考:Game_Battler 1 line:262
[quote]
#--------------------------------------------------------------------------
# ● 确定动作速度
#--------------------------------------------------------------------------
def make_action_speed
@current_action.speed = agi + rand(10 + agi / 4)
end
@action_battlers.sort! {|a,b|
b.current_action.speed - a.current_action.speed }
sort! {|a, b| ... }
对数组内容进行排序。若带块调用时,将把 2 个参数传给块,然后使用块的计算结果进行比较。若没有块时,使用 <=> 运算符进行比较。sort! 的对数组单元的排序过程具有破环性。
sort 将生成一个经过排序的新数组并返回它,sort! 通常会返回 self。
# 移动到步骤 1
@phase4_step = 1
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |