#RTAB战斗系统 For RPG Maker VX Ace 编写者:SLICK #encoding:utf-8 #============================================================================== # ■ Scene_Battle #------------------------------------------------------------------------------ # 战斗画面 #============================================================================== class Scene_Battle < Scene_Base attr_accessor :cp_quota attr_accessor :rtab_wait attr_accessor :active_members #-------------------------------------------------------------------------- # ● 开始处理 #-------------------------------------------------------------------------- def start super @cp_quota = 0 create_spriteset create_all_windows BattleManager.method_wait_for_message = method(:wait_for_message) end #-------------------------------------------------------------------------- # ● 战斗开始 #-------------------------------------------------------------------------- def battle_start @rtab_wait = true @active_members = [] BattleManager.battle_start set_cp_quota process_event #start_party_command_selection end #-------------------------------------------------------------------------- # ● 获取敌我双方人物的平均行动速度并决定CP槽的Quota值 #-------------------------------------------------------------------------- def set_cp_quota sss = 0.0 for iii in $game_party.members sss += iii.param(6) end sss /= $game_party.members.size @cp_quota = sss * 200 @spriteset.cp_quota = @cp_quota for iii in $game_party.members + $game_troop.members iii.cp_quota = @cp_quota end end #-------------------------------------------------------------------------- # ● 进行下一个指令输入 #-------------------------------------------------------------------------- def next_command if BattleManager.next_command start_actor_command_selection else turn_start(@active_members) end end #-------------------------------------------------------------------------- # ● 返回上一个指令输入 #-------------------------------------------------------------------------- def prior_command if BattleManager.prior_command start_actor_command_selection else start_party_command_selection end end #-------------------------------------------------------------------------- # ● 更新画面 #-------------------------------------------------------------------------- def update super if BattleManager.in_turn? process_event process_action else if @rtab_wait for iii in $game_party.members + $game_troop.members iii.in_turn = false iii.rtab_cp += iii.param(6) if iii.rtab_cp >= iii.cp_quota @active_members.push(iii) iii.in_turn = true end end if @active_members.size > 0 @rtab_wait = false start_party_command_selection end end end BattleManager.judge_win_loss end #-------------------------------------------------------------------------- # ● 回合开始 #-------------------------------------------------------------------------- def turn_start(members) @party_command_window.close @actor_command_window.close @status_window.unselect @subject = nil BattleManager.turn_start(members) @log_window.wait @log_window.clear end #-------------------------------------------------------------------------- # ● 回合结束 #-------------------------------------------------------------------------- def turn_end @active_members.each do |battler| battler.on_turn_end refresh_status @log_window.display_auto_affected_status(battler) @log_window.wait_and_clear end BattleManager.turn_end process_event @rtab_wait = true @active_members = [] end #-------------------------------------------------------------------------- # ● 处理战斗行动 #-------------------------------------------------------------------------- def process_action return if scene_changing? if !@subject || !@subject.current_action @subject = BattleManager.next_subject end return turn_end unless @subject if @subject.current_action @subject.current_action.prepare if @subject.current_action.valid? @status_window.open execute_action end @subject.remove_current_action end process_action_end unless @subject.current_action end #-------------------------------------------------------------------------- # ● 开始队伍指令的选择 #-------------------------------------------------------------------------- def start_party_command_selection unless scene_changing? refresh_status @status_window.unselect @status_window.open if BattleManager.input_start BattleManager.clear_actor BattleManager.next_command @status_window.select(BattleManager.actor.index) @actor_command_window.setup(BattleManager.actor) else @party_command_window.deactivate @actor_command_window.close turn_start(@active_members) end end end #-------------------------------------------------------------------------- # ● 生成角色指令窗口 #-------------------------------------------------------------------------- def create_actor_command_window @actor_command_window = Window_ActorCommand.new @actor_command_window.viewport = @info_viewport @actor_command_window.set_handler(:attack, method(:command_attack)) @actor_command_window.set_handler(:skill, method(:command_skill)) @actor_command_window.set_handler(:guard, method(:command_guard)) @actor_command_window.set_handler(:item, method(:command_item)) @actor_command_window.set_handler(:cancel, method(:prior_command)) @actor_command_window.set_handler(:escape, method(:command_escape)) @actor_command_window.x = Graphics.width end #-------------------------------------------------------------------------- # ● 指令“撤退” #-------------------------------------------------------------------------- def command_escape unless BattleManager.process_escape turn_start(@active_members) for iii in @active_members iii.rtab_cp = 0 end end end end #encoding:utf-8 #============================================================================== # ■ Window_ActorCommand #------------------------------------------------------------------------------ # 战斗画面中,选择角色行动的窗口。 #============================================================================== class Window_ActorCommand < Window_Command #-------------------------------------------------------------------------- # ● 生成指令列表 #-------------------------------------------------------------------------- def make_command_list return unless @actor add_attack_command add_skill_commands add_guard_command add_item_command add_escape_command end #-------------------------------------------------------------------------- # ● 添加撤退指令 #-------------------------------------------------------------------------- def add_escape_command add_command(Vocab::escape, :escape, BattleManager.can_escape?) end end #encoding:utf-8 #============================================================================== # ■ BattleManager #------------------------------------------------------------------------------ # 战斗过程的管理器。 #============================================================================== module BattleManager #-------------------------------------------------------------------------- # ● 战斗开始 #-------------------------------------------------------------------------- def self.battle_start $game_system.battle_count += 1 $game_party.on_battle_start $game_troop.on_battle_start $game_troop.enemy_names.each do |name| $game_message.add(sprintf(Vocab::Emerge, name)) end if @preemptive $game_message.add(sprintf(Vocab::Preemptive, $game_party.name)) elsif @surprise $game_message.add(sprintf(Vocab::Surprise, $game_party.name)) end wait_for_message end #-------------------------------------------------------------------------- # ● 遇敌时的处理 #-------------------------------------------------------------------------- def self.on_encounter @preemptive = false @surprise = false end #-------------------------------------------------------------------------- # ● 回合开始 #-------------------------------------------------------------------------- def self.turn_start(members) @phase = :turn clear_actor $game_troop.increase_turn(members) make_action_orders(members) end #-------------------------------------------------------------------------- # ● 生成行动顺序 #-------------------------------------------------------------------------- def self.make_action_orders(members) @action_battlers = [] for iii in $game_party.members if members.include?(iii) @action_battlers.push(iii) unless @surprise end end for iii in $game_troop.members if members.include?(iii) @action_battlers.push(iii) unless @preemptive end end @action_battlers.each {|battler| battler.make_speed } @action_battlers.sort! {|a,b| b.speed - a.speed } end end #encoding:utf-8 #============================================================================== # ■ Game_Battler #------------------------------------------------------------------------------ # 处理战斗者的类。Game_Actor 和 Game_Enemy 类的父类。 #============================================================================== class Game_Battler < Game_BattlerBase attr_accessor :turn_count attr_accessor :rtab_cp attr_accessor :cp_quota attr_accessor :in_turn #-------------------------------------------------------------------------- # ● 初始化对象 #-------------------------------------------------------------------------- alias neoinitialize initialize def initialize @turn_count = 0 @rtab_cp = 0 @cp_quota = 100 @in_turn = false neoinitialize end #-------------------------------------------------------------------------- # ● 战斗开始处理 #-------------------------------------------------------------------------- def on_battle_start @turn_count = 0 @rtab_cp = 0 @cp_quota = 100 @in_turn = false init_tp unless preserve_tp? end #-------------------------------------------------------------------------- # ● 处理伤害 # 调用前需要设置好 # @result.hp_damage @result.mp_damage # @result.hp_drain @result.mp_drain #-------------------------------------------------------------------------- def execute_damage(user) on_damage(@result.hp_damage) if @result.hp_damage > 0 self.hp -= @result.hp_damage self.mp -= @result.mp_damage user.hp += @result.hp_drain user.mp += @result.mp_drain # 受伤后计算CP退后量 cpback = @result.hp_damage + @result.mp_damage cpback = (cpback < 0 ? 0 : cpback) pent = 100.0 * cpback / self.mhp cppentback = ((0.1 + pent / 10) * self.cp_quota / 100).to_i @rtab_cp -= cppentback @rtab_cp = (@rtab_cp < 0 ? 0 : @rtab_cp) end #-------------------------------------------------------------------------- # ● 判定是否可以输入指令 #-------------------------------------------------------------------------- def inputable? normal? && !auto_battle? && @in_turn end #-------------------------------------------------------------------------- # ● 回合结束处理 #-------------------------------------------------------------------------- def on_turn_end @result.clear regenerate_all update_state_turns update_buff_turns remove_states_auto(2) # 该角色的回合计数加1并清空CP return unless SceneManager.scene_is?(Scene_Battle) @turn_count += 1 @rtab_cp = 0 end end #encoding:utf-8 #============================================================================== # ■ Game_Troop #------------------------------------------------------------------------------ # 管理敌群和战斗相关资料的类,也可执行如战斗事件管理之类的功能。 # 本类的实例请参考 $game_troop 。 #============================================================================== class Game_Troop < Game_Unit #-------------------------------------------------------------------------- # ● 增加回合 #-------------------------------------------------------------------------- def increase_turn(members) troop.pages.each {|page| @event_flags[page] = false if page.span == 1 } turnmax = [] for iii in members turnmax.push(iii.turn_count) end @turn_count = turnmax.max end end #encoding:utf-8 #============================================================================== # ■ Spriteset_Battle #------------------------------------------------------------------------------ # 处理战斗画面的精灵的类。本类在 Scene_Battle 类的内部使用。 #============================================================================== class Spriteset_Battle attr_accessor :icons attr_accessor :cp_quota #-------------------------------------------------------------------------- # ● 初始化对象 #-------------------------------------------------------------------------- def initialize @cp_quota = 100 create_viewports create_battleback1 create_battleback2 create_enemies create_actors create_pictures create_timer create_rtabcp_gauge update end #-------------------------------------------------------------------------- # ● 生成战斗CP条 #-------------------------------------------------------------------------- def create_rtabcp_gauge @cpgauge_back = Sprite.new(@viewport3) @cpgauge_back.bitmap = Bitmap.new(400, 8) @cpgauge_back.bitmap.gradient_fill_rect(0, 0, 400, 16, Color.new(0, 255, 0), Color.new(255, 0, 0)) @cpgauge_back.x = 16 @cpgauge_back.y = 16 # 为战斗中的各个角色生成其图标 @icons = {} for iii in $game_party.members @icons[iii] = Sprite.new(@viewport3) @icons[iii].bitmap = Bitmap.new("Graphics/System/bicon1.png") @icons[iii].ox = 12 @icons[iii].oy = 12 @icons[iii].x = 16 @icons[iii].y = 20 end for iii in $game_troop.members @icons[iii] = Sprite.new(@viewport3) @icons[iii].bitmap = Bitmap.new("Graphics/System/bicon2.png") @icons[iii].ox = 12 @icons[iii].oy = 12 @icons[iii].x = 16 @icons[iii].y = 20 end end #-------------------------------------------------------------------------- # ● 释放 #-------------------------------------------------------------------------- def dispose dispose_battleback1 dispose_battleback2 dispose_enemies dispose_actors dispose_pictures dispose_timer dispose_viewports dispose_rtabcp_gauge end #-------------------------------------------------------------------------- # ● 消灭战斗CP条 #-------------------------------------------------------------------------- def dispose_rtabcp_gauge @cpgauge_back.bitmap.dispose @cpgauge_back.dispose for iii in $game_party.members @icons[iii].bitmap.dispose @icons[iii].dispose end for iii in $game_troop.members @icons[iii].bitmap.dispose @icons[iii].dispose end end #-------------------------------------------------------------------------- # ● 更新画面 #-------------------------------------------------------------------------- def update update_battleback1 update_battleback2 update_enemies update_actors update_cp update_pictures update_timer update_viewports end #-------------------------------------------------------------------------- # ● 更新CP条 #-------------------------------------------------------------------------- def update_cp for iii in $game_party.members + $game_troop.members @icons[iii].x = 16 + 400 * iii.rtab_cp / @cp_quota @icons[iii].visible = iii.alive? end end end
555555566666.png (41.29 KB, 下载次数: 25)
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |