Project1

标题: 游戏出错,是啥情况引起的 [打印本页]

作者: fjm    时间: 2023-10-5 16:42
标题: 游戏出错,是啥情况引起的
本帖最后由 fjm 于 2023-10-5 16:45 编辑

用了下面这个脚本后,有时候正常,有时候出现下面情况,是啥引起的

RUBY 代码复制
  1. #RTAB战斗系统 For RPG Maker VX Ace 编写者:SLICK
  2.  
  3. #encoding:utf-8
  4. #==============================================================================
  5. # ■ Scene_Battle
  6. #------------------------------------------------------------------------------
  7. #  战斗画面
  8. #==============================================================================
  9.  
  10. class Scene_Battle < Scene_Base
  11.   attr_accessor :cp_quota
  12.   attr_accessor :rtab_wait
  13.   attr_accessor :active_members
  14.   #--------------------------------------------------------------------------
  15.   # ● 开始处理
  16.   #--------------------------------------------------------------------------
  17.   def start
  18.     super
  19.     @cp_quota = 0
  20.     create_spriteset
  21.     create_all_windows
  22.     BattleManager.method_wait_for_message = method(:wait_for_message)
  23.   end
  24.   #--------------------------------------------------------------------------
  25.   # ● 战斗开始
  26.   #--------------------------------------------------------------------------
  27.   def battle_start
  28.     @rtab_wait = true
  29.     @active_members = []
  30.     BattleManager.battle_start
  31.     set_cp_quota
  32.     process_event
  33.     #start_party_command_selection
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   # ● 获取敌我双方人物的平均行动速度并决定CP槽的Quota值
  37.   #--------------------------------------------------------------------------
  38.   def set_cp_quota
  39.     sss = 0.0
  40.     for iii in $game_party.members
  41.       sss += iii.param(6)
  42.     end
  43.     sss /= $game_party.members.size
  44.     @cp_quota = sss * 200
  45.     @spriteset.cp_quota = @cp_quota
  46.     for iii in $game_party.members + $game_troop.members
  47.       iii.cp_quota = @cp_quota
  48.     end
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 进行下一个指令输入
  52.   #--------------------------------------------------------------------------
  53.   def next_command
  54.     if BattleManager.next_command
  55.       start_actor_command_selection
  56.     else
  57.       turn_start(@active_members)
  58.     end
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● 返回上一个指令输入
  62.   #--------------------------------------------------------------------------
  63.   def prior_command
  64.     if BattleManager.prior_command
  65.       start_actor_command_selection
  66.     else
  67.       start_party_command_selection
  68.     end
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ● 更新画面
  72.   #--------------------------------------------------------------------------
  73.   def update
  74.     super
  75.     if BattleManager.in_turn?
  76.       process_event
  77.       process_action
  78.     else
  79.       if @rtab_wait
  80.         for iii in $game_party.members + $game_troop.members
  81.           iii.in_turn = false
  82.           iii.rtab_cp += iii.param(6)
  83.           if iii.rtab_cp >= iii.cp_quota
  84.             @active_members.push(iii)
  85.             iii.in_turn = true
  86.           end
  87.         end
  88.         if @active_members.size > 0
  89.           @rtab_wait = false
  90.           start_party_command_selection
  91.         end
  92.       end
  93.     end
  94.     BattleManager.judge_win_loss
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # ● 回合开始
  98.   #--------------------------------------------------------------------------
  99.   def turn_start(members)
  100.     @party_command_window.close
  101.     @actor_command_window.close
  102.     @status_window.unselect
  103.     @subject = nil
  104.     BattleManager.turn_start(members)
  105.     @log_window.wait
  106.     @log_window.clear
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # ● 回合结束
  110.   #--------------------------------------------------------------------------
  111.   def turn_end
  112.     @active_members.each do |battler|
  113.       battler.on_turn_end
  114.       refresh_status
  115.       @log_window.display_auto_affected_status(battler)
  116.       @log_window.wait_and_clear
  117.     end
  118.     BattleManager.turn_end
  119.     process_event
  120.     @rtab_wait = true
  121.     @active_members = []
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # ● 处理战斗行动
  125.   #--------------------------------------------------------------------------
  126.   def process_action
  127.     return if scene_changing?
  128.     if !@subject || !@subject.current_action
  129.       @subject = BattleManager.next_subject
  130.     end
  131.     return turn_end unless @subject
  132.     if @subject.current_action
  133.       @subject.current_action.prepare
  134.       if @subject.current_action.valid?
  135.         @status_window.open
  136.         execute_action
  137.       end
  138.       @subject.remove_current_action
  139.     end
  140.     process_action_end unless @subject.current_action
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # ● 开始队伍指令的选择
  144.   #--------------------------------------------------------------------------
  145.   def start_party_command_selection
  146.     unless scene_changing?
  147.       refresh_status
  148.       @status_window.unselect
  149.       @status_window.open
  150.       if BattleManager.input_start
  151.         BattleManager.clear_actor
  152.         BattleManager.next_command
  153.         @status_window.select(BattleManager.actor.index)
  154.         @actor_command_window.setup(BattleManager.actor)
  155.       else
  156.         @party_command_window.deactivate
  157.         @actor_command_window.close
  158.         turn_start(@active_members)
  159.       end
  160.     end
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ● 生成角色指令窗口
  164.   #--------------------------------------------------------------------------
  165.   def create_actor_command_window
  166.     @actor_command_window = Window_ActorCommand.new
  167.     @actor_command_window.viewport = @info_viewport
  168.     @actor_command_window.set_handler(:attack, method(:command_attack))
  169.     @actor_command_window.set_handler(:skill,  method(:command_skill))
  170.     @actor_command_window.set_handler(:guard,  method(:command_guard))
  171.     @actor_command_window.set_handler(:item,   method(:command_item))
  172.     @actor_command_window.set_handler(:cancel, method(:prior_command))
  173.     @actor_command_window.set_handler(:escape, method(:command_escape))
  174.     @actor_command_window.x = Graphics.width
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 指令“撤退”
  178.   #--------------------------------------------------------------------------
  179.   def command_escape
  180.     unless BattleManager.process_escape
  181.       turn_start(@active_members)
  182.       for iii in @active_members
  183.         iii.rtab_cp = 0
  184.       end
  185.     end
  186.   end
  187. end
  188.  
  189. #encoding:utf-8
  190. #==============================================================================
  191. # ■ Window_ActorCommand
  192. #------------------------------------------------------------------------------
  193. #  战斗画面中,选择角色行动的窗口。
  194. #==============================================================================
  195.  
  196. class Window_ActorCommand < Window_Command
  197.   #--------------------------------------------------------------------------
  198.   # ● 生成指令列表
  199.   #--------------------------------------------------------------------------
  200.   def make_command_list
  201.     return unless @actor
  202.     add_attack_command
  203.     add_skill_commands
  204.     add_guard_command
  205.     add_item_command
  206.     add_escape_command
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # ● 添加撤退指令
  210.   #--------------------------------------------------------------------------
  211.   def add_escape_command
  212.     add_command(Vocab::escape, :escape, BattleManager.can_escape?)
  213.   end
  214. end
  215.  
  216. #encoding:utf-8
  217. #==============================================================================
  218. # ■ BattleManager
  219. #------------------------------------------------------------------------------
  220. #  战斗过程的管理器。
  221. #==============================================================================
  222.  
  223. module BattleManager
  224.   #--------------------------------------------------------------------------
  225.   # ● 战斗开始
  226.   #--------------------------------------------------------------------------
  227.   def self.battle_start
  228.     $game_system.battle_count += 1
  229.     $game_party.on_battle_start
  230.     $game_troop.on_battle_start
  231.     $game_troop.enemy_names.each do |name|
  232.       $game_message.add(sprintf(Vocab::Emerge, name))
  233.     end
  234.     if @preemptive
  235.       $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
  236.     elsif @surprise
  237.       $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
  238.     end
  239.     wait_for_message
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # ● 遇敌时的处理
  243.   #--------------------------------------------------------------------------
  244.   def self.on_encounter
  245.     @preemptive = false
  246.     @surprise = false
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # ● 回合开始
  250.   #--------------------------------------------------------------------------
  251.   def self.turn_start(members)
  252.     @phase = :turn
  253.     clear_actor
  254.     $game_troop.increase_turn(members)
  255.     make_action_orders(members)
  256.   end
  257.   #--------------------------------------------------------------------------
  258.   # ● 生成行动顺序
  259.   #--------------------------------------------------------------------------
  260.   def self.make_action_orders(members)
  261.     @action_battlers = []
  262.     for iii in $game_party.members
  263.       if members.include?(iii)
  264.         @action_battlers.push(iii) unless @surprise
  265.       end
  266.     end
  267.     for iii in $game_troop.members
  268.       if members.include?(iii)
  269.         @action_battlers.push(iii) unless @preemptive
  270.       end
  271.     end
  272.     @action_battlers.each {|battler| battler.make_speed }
  273.     @action_battlers.sort! {|a,b| b.speed - a.speed }
  274.   end
  275. end
  276.  
  277. #encoding:utf-8
  278. #==============================================================================
  279. # ■ Game_Battler
  280. #------------------------------------------------------------------------------
  281. #  处理战斗者的类。Game_Actor 和 Game_Enemy 类的父类。
  282. #==============================================================================
  283.  
  284. class Game_Battler < Game_BattlerBase
  285.   attr_accessor :turn_count
  286.   attr_accessor :rtab_cp
  287.   attr_accessor :cp_quota
  288.   attr_accessor :in_turn
  289.   #--------------------------------------------------------------------------
  290.   # ● 初始化对象
  291.   #--------------------------------------------------------------------------
  292.   alias neoinitialize initialize
  293.   def initialize
  294.     @turn_count = 0
  295.     @rtab_cp = 0
  296.     @cp_quota = 100
  297.     @in_turn = false
  298.     neoinitialize
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # ● 战斗开始处理
  302.   #--------------------------------------------------------------------------
  303.   def on_battle_start
  304.     @turn_count = 0
  305.     @rtab_cp = 0
  306.     @cp_quota = 100
  307.     @in_turn = false
  308.     init_tp unless preserve_tp?
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # ● 处理伤害
  312.   #    调用前需要设置好
  313.   #    @result.hp_damage   @result.mp_damage
  314.   #    @result.hp_drain    @result.mp_drain
  315.   #--------------------------------------------------------------------------
  316.   def execute_damage(user)
  317.     on_damage(@result.hp_damage) if @result.hp_damage > 0
  318.     self.hp -= @result.hp_damage
  319.     self.mp -= @result.mp_damage
  320.     user.hp += @result.hp_drain
  321.     user.mp += @result.mp_drain
  322.     # 受伤后计算CP退后量
  323.     cpback = @result.hp_damage + @result.mp_damage
  324.     cpback = (cpback < 0 ? 0 : cpback)
  325.     pent = 100.0 * cpback / self.mhp
  326.     cppentback = ((0.1 + pent / 10) * self.cp_quota / 100).to_i
  327.     @rtab_cp -= cppentback
  328.     @rtab_cp = (@rtab_cp < 0 ? 0 : @rtab_cp)
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   # ● 判定是否可以输入指令
  332.   #--------------------------------------------------------------------------
  333.   def inputable?
  334.     normal? && !auto_battle? && @in_turn
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # ● 回合结束处理
  338.   #--------------------------------------------------------------------------
  339.   def on_turn_end
  340.     @result.clear
  341.     regenerate_all
  342.     update_state_turns
  343.     update_buff_turns
  344.     remove_states_auto(2)
  345.     # 该角色的回合计数加1并清空CP
  346.     return unless SceneManager.scene_is?(Scene_Battle)
  347.     @turn_count += 1
  348.     @rtab_cp = 0
  349.   end
  350. end
  351.  
  352. #encoding:utf-8
  353. #==============================================================================
  354. # ■ Game_Troop
  355. #------------------------------------------------------------------------------
  356. #  管理敌群和战斗相关资料的类,也可执行如战斗事件管理之类的功能。
  357. #   本类的实例请参考 $game_troop 。
  358. #==============================================================================
  359.  
  360. class Game_Troop < Game_Unit
  361.   #--------------------------------------------------------------------------
  362.   # ● 增加回合
  363.   #--------------------------------------------------------------------------
  364.   def increase_turn(members)
  365.     troop.pages.each {|page| @event_flags[page] = false if page.span == 1 }
  366.     turnmax = []
  367.     for iii in members
  368.       turnmax.push(iii.turn_count)
  369.     end
  370.     @turn_count = turnmax.max
  371.   end
  372. end
  373.  
  374. #encoding:utf-8
  375. #==============================================================================
  376. # ■ Spriteset_Battle
  377. #------------------------------------------------------------------------------
  378. #  处理战斗画面的精灵的类。本类在 Scene_Battle 类的内部使用。
  379. #==============================================================================
  380.  
  381. class Spriteset_Battle
  382.   attr_accessor :icons
  383.   attr_accessor :cp_quota
  384.   #--------------------------------------------------------------------------
  385.   # ● 初始化对象
  386.   #--------------------------------------------------------------------------
  387.   def initialize
  388.     @cp_quota = 100
  389.     create_viewports
  390.     create_battleback1
  391.     create_battleback2
  392.     create_enemies
  393.     create_actors
  394.     create_pictures
  395.     create_timer
  396.     create_rtabcp_gauge
  397.     update
  398.   end
  399.   #--------------------------------------------------------------------------
  400.   # ● 生成战斗CP条
  401.   #--------------------------------------------------------------------------
  402.   def create_rtabcp_gauge
  403.     @cpgauge_back = Sprite.new(@viewport3)
  404.     @cpgauge_back.bitmap = Bitmap.new(400, 8)
  405.     @cpgauge_back.bitmap.gradient_fill_rect(0, 0, 400, 16, Color.new(0, 255, 0), Color.new(255, 0, 0))
  406.     @cpgauge_back.x = 16
  407.     @cpgauge_back.y = 16
  408.     # 为战斗中的各个角色生成其图标
  409.     @icons = {}
  410.     for iii in $game_party.members
  411.       @icons[iii] = Sprite.new(@viewport3)
  412.       @icons[iii].bitmap = Bitmap.new("Graphics/System/bicon1.png")
  413.       @icons[iii].ox = 12
  414.       @icons[iii].oy = 12
  415.       @icons[iii].x = 16
  416.       @icons[iii].y = 20
  417.     end
  418.     for iii in $game_troop.members
  419.       @icons[iii] = Sprite.new(@viewport3)
  420.       @icons[iii].bitmap = Bitmap.new("Graphics/System/bicon2.png")
  421.       @icons[iii].ox = 12
  422.       @icons[iii].oy = 12
  423.       @icons[iii].x = 16
  424.       @icons[iii].y = 20
  425.     end
  426.   end
  427.   #--------------------------------------------------------------------------
  428.   # ● 释放
  429.   #--------------------------------------------------------------------------
  430.   def dispose
  431.     dispose_battleback1
  432.     dispose_battleback2
  433.     dispose_enemies
  434.     dispose_actors
  435.     dispose_pictures
  436.     dispose_timer
  437.     dispose_viewports
  438.     dispose_rtabcp_gauge
  439.   end
  440.   #--------------------------------------------------------------------------
  441.   # ● 消灭战斗CP条
  442.   #--------------------------------------------------------------------------
  443.   def dispose_rtabcp_gauge
  444.     @cpgauge_back.bitmap.dispose
  445.     @cpgauge_back.dispose
  446.     for iii in $game_party.members
  447.       @icons[iii].bitmap.dispose
  448.       @icons[iii].dispose
  449.     end
  450.     for iii in $game_troop.members
  451.       @icons[iii].bitmap.dispose
  452.       @icons[iii].dispose
  453.     end
  454.   end
  455.   #--------------------------------------------------------------------------
  456.   # ● 更新画面
  457.   #--------------------------------------------------------------------------
  458.   def update
  459.     update_battleback1
  460.     update_battleback2
  461.     update_enemies
  462.     update_actors
  463.     update_cp
  464.     update_pictures
  465.     update_timer
  466.     update_viewports
  467.   end
  468.   #--------------------------------------------------------------------------
  469.   # ● 更新CP条
  470.   #--------------------------------------------------------------------------
  471.   def update_cp
  472.     for iii in $game_party.members + $game_troop.members
  473.       @icons[iii].x = 16 + 400 * iii.rtab_cp / @cp_quota
  474.       @icons[iii].visible = iii.alive?
  475.     end
  476.   end
  477. end





555555566666.png (41.29 KB, 下载次数: 25)

555555566666.png





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1