Project1

标题: CP战斗的问题 [打印本页]

作者: wuwei0923    时间: 2013-10-5 16:34
标题: CP战斗的问题
本帖最后由 76213585 于 2013-10-5 10:27 编辑

CP战斗时在敌我任意一名角色被状态杀死的时候会卡死。
由于改了原脚本所以不敢确定是否是兼容问题还是其他问题。
RUBY 代码复制
  1. module CP
  2. #
  3. # 基本能力消耗的CP值
  4. #
  5. CP_COST_SKILL_ITEM_ACTION = 65535 # 技能 物品
  6. CP_COST_BASIC_ATTACK = 65535 # 攻撃
  7. CP_COST_BASIC_GUARD = 32768 # 防御
  8. CP_COST_BASIC_ESCAPE = 65535 #逃跑
  9. end
  10. #==============================================================================
  11. # □ CP_Thread
  12. #==============================================================================
  13. class CP_Thread
  14.  
  15. # 战斗速度
  16. #
  17. BATTLE_SPEED = 1.0
  18. #
  19. # 战斗开始的时候气槽百分比
  20. #
  21. START_CP_PERCENT = 10
  22. #
  23. # CP满时的音效
  24. #
  25. FULL_SE = "Audio/SE/open1"
  26. #--------------------------------------------------------------------------
  27. # ○ 变量公开
  28. #--------------------------------------------------------------------------
  29. attr_accessor :stop # CP加算ストップ
  30. #----------------------------------------------------------------------------
  31. # ○ 初始化
  32. #----------------------------------------------------------------------------
  33. def initialize
  34. @battlers = []
  35. [url=home.php?mod=space&uid=9053]@cancel[/url] = false
  36. [url=home.php?mod=space&uid=76426]@stop[/url] = false
  37. @agi_total = 0
  38. # 配列 count_battlers を初期化
  39. count_battlers = []
  40. # エネミーを配列 count_battlers に追加
  41. for enemy in $game_troop.members
  42. count_battlers.push(enemy)
  43. end
  44. # アクターを配列 count_battlers に追加
  45. for actor in $game_party.battle_members
  46. count_battlers.push(actor)
  47. end
  48. for battler in count_battlers
  49. @agi_total += battler.agi
  50. end
  51.  
  52. for battler in count_battlers
  53.     battler.cp = [[65535 * START_CP_PERCENT * (rand(15) + 85) * 4 * battler.agi / @agi_total / 10000, 0].max, 65535].min
  54.     battler.turn_count = 0
  55. end
  56. end
  57. #----------------------------------------------------------------------------
  58. # ○ CP更新
  59. #----------------------------------------------------------------------------
  60. def update
  61. # 停止刷新
  62. return if @stop
  63. #
  64. for battler in $game_party.battle_members + $game_troop.members
  65. # 行動出来なければ無視
  66. if battler.dead? || battler.hidden?
  67. battler.cp = 0
  68. next
  69. end
  70.  
  71.  
  72. battler.cp = [[battler.cp + BATTLE_SPEED * 2048 * battler.agi / @agi_total, 0].max, 65535].min
  73.  
  74. # CP满时
  75.  
  76.     if battler.cp >= battler.max_cp
  77.         Audio.se_play(FULL_SE)
  78.         BattleManager.set_enable_go(battler)
  79.         battler.my_turn = true
  80.         BattleManager.input_start
  81.         break
  82.       end
  83.     unless BattleManager.cp_updating?
  84.       return
  85.     end
  86.  
  87. end
  88.  
  89. def update?
  90.   return !@stop
  91. end
  92. end
  93.  
  94. #----------------------------------------------------------------------------
  95. # ○ CPカウントの開始
  96. #----------------------------------------------------------------------------
  97. def stop
  98. [url=home.php?mod=space&uid=9053]@cancel[/url] = true
  99. if @cp_thread != nil then
  100. @cp_thread.join
  101. @cp_thread = nil
  102. end
  103. end
  104. end
  105. #==============================================================================
  106. # ■ Game_BattlerBase
  107. #------------------------------------------------------------------------------
  108. #  管理战斗者的类。主要含有能力值计算的方法。Game_Battler 类的父类。
  109. #==============================================================================
  110. class Game_BattlerBase
  111.   attr_reader   :cp                       # CP
  112.   attr_accessor :turn_count
  113.   attr_accessor :my_turn
  114.   include CP
  115.   #------------------------------
  116.   alias old_initialize initialize
  117.   def initialize
  118.     old_initialize
  119.     @cp = 0
  120.     @turn_count = 0
  121.     @my_turn = false
  122.   end
  123.   #------------------------------
  124.   def inputable?
  125.     if @my_turn
  126.       return normal? && !auto_battle?# && @cp >= 65535
  127.     else
  128.       return false
  129.     end
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● 更改 CP
  133.   #--------------------------------------------------------------------------
  134.   def cp=(cp)
  135.     @cp = [[cp, max_cp].min, 0].max
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # ● 获取 CP 的最大值
  139.   #--------------------------------------------------------------------------
  140.   def max_cp
  141.     return 65535
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # ● 获取 CP 的比率
  145.   #--------------------------------------------------------------------------
  146.   def cp_rate
  147.     @cp.to_f / 65535
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ● 扣除技能的使用消耗
  151.   #--------------------------------------------------------------------------
  152.   alias :old_pay_skill_cost :pay_skill_cost
  153.   def pay_skill_cost(skill)
  154.     old_pay_skill_cost(skill)
  155.     ###########
  156.     case skill.id
  157.     when 1
  158.      @cp -= CP_COST_BASIC_ATTACK
  159.     when 2
  160.      @cp -= CP_COST_BASIC_GUARD
  161.     when 3...999 # 可自订不同消耗的技能
  162.      @cp -= CP_COST_SKILL_ITEM_ACTION
  163.     else
  164.      @cp = 0
  165.     end
  166.     ###########
  167.   end
  168. end
  169. #--------------------------------------------------------
  170. class Game_Battler < Game_BattlerBase
  171.   include CP
  172.   #--------------------------------------------------------------------------
  173.   # ● 消耗物品
  174.   #--------------------------------------------------------------------------
  175.   alias :old_consume_item :consume_item
  176.   def consume_item(item)
  177.     old_consume_item(item)
  178.     ###########
  179.     case item.id
  180.     when 0...999 # 可自订不同消耗的物品
  181.      @cp -= CP_COST_SKILL_ITEM_ACTION
  182.     else
  183.      @cp = 0
  184.     end
  185.     ###########
  186.   end
  187. end
  188. #-------------------------------------
  189. class Game_Party < Game_Unit
  190.   def make_action(member)
  191.     unless member == nil
  192.       member.make_actions unless member.inputable?
  193.     end
  194.   end
  195. end
  196. #-------------------------------------
  197. class Game_Troop < Game_Unit
  198.   def make_action(member)
  199.     member.make_actions unless member == nil
  200.   end
  201.  
  202.   def increase_turn(enemy)
  203.     troop.pages.each {|page| @event_flags[page] = false if page.span == 1 }
  204.     enemy.turn_count += 1
  205.     aaa = []
  206.     for iii in $game_troop.members
  207.       aaa.push(iii.turn_count)
  208.     end
  209.     @turn_count = aaa.max
  210.   end
  211. end
  212. #-------------------------------------
  213. module BattleManager
  214.   def self.battle_start
  215.     $game_system.battle_count += 1
  216.     $game_party.on_battle_start
  217.     $game_troop.on_battle_start
  218.     $game_troop.enemy_names.each do |name|
  219.       $game_message.add(sprintf(Vocab::Emerge, name))
  220.     end
  221.  
  222.     if @preemptive
  223.       $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
  224.       for b in $game_troop.members
  225.         if !b.hidden?
  226.           b.cp = 0
  227.         end
  228.       end
  229.       for b in $game_party.battle_members
  230.         if !b.hidden?
  231.           b.cp = b.max_cp
  232.         end
  233.       end
  234.     elsif @surprise
  235.       $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
  236.       for b in $game_troop.members
  237.         if !b.hidden?
  238.           b.cp = b.max_cp
  239.         end
  240.       end
  241.       for b in $game_party.battle_members
  242.         if !b.hidden?
  243.           b.cp = 0
  244.         end
  245.       end
  246.     end
  247.     wait_for_message
  248.   end
  249.  
  250.   def self.enable_go
  251.     @enable_go
  252.   end
  253.  
  254.   def self.set_enable_go(b)
  255.     @enable_go = b
  256.   end
  257.  
  258.   def self.enable_go_clear
  259.     @enable_go = nil
  260.   end
  261.  
  262.   def self.max_agi
  263.     @max_agi
  264.   end
  265.  
  266.   def self.cp_updation
  267.     @phase = :cp_update
  268.   end
  269.  
  270.   def self.cp_updating?
  271.     @phase == :cp_update
  272.   end
  273.   #--------------------------------------------------------------------------
  274.   # ● 重定义:开始输入指令
  275.   #--------------------------------------------------------------------------
  276.   def self.input_start
  277.     if @phase != :input
  278.       @phase = :input
  279.       $game_party.make_actions
  280.       $game_troop.make_actions
  281.       clear_actor
  282.     end
  283.     return $game_party.inputable?
  284.   end
  285.   #-------------------------------------------------------------------------
  286.   # ● 重定义:回合开始
  287.   #------------------------------------------------------------------------
  288.   def self.turn_start
  289.     @phase = :turn
  290.     clear_actor
  291.     make_action_orders
  292.   end
  293.   #-------------------------------------------------------------------------
  294.   # ● 重定义:行动顺序
  295.   #------------------------------------------------------------------------
  296.   def self.make_action_orders
  297.     @action_battlers = []
  298.     for b in $game_troop.members + $game_party.battle_members
  299.       if b.my_turn
  300.         @action_battlers.push(b)
  301.       end
  302.     end
  303.     exclude_battler = []
  304.     for battler in @action_battlers
  305.      if battler.cp < 65535
  306.        exclude_battler.push(battler)
  307.      end
  308.     end
  309.     @action_battlers -= exclude_battler
  310.   end
  311. end
  312. #==============================================================================
  313. # ■ Window_Base
  314. #------------------------------------------------------------------------------
  315. #  游戏中所有窗口的父类
  316. #==============================================================================
  317.  
  318. class Window_Base < Window
  319.   #--------------------------------------------------------------------------
  320.   # ● 获取颜色
  321.   #--------------------------------------------------------------------------
  322.   def cp_gauge_color1;   Color.new(200,200,120); end;    # CP 值槽 1
  323.   def cp_gauge_color2;   Color.new(100,100,70);  end;    # CP 值槽 2
  324.   #--------------------------------------------------------------------------
  325.   # ● 绘制值槽(长宽自由版)
  326.   #     rate   : 比率(1.0 为满值)
  327.   #     color1 : 渐变色的左端
  328.   #     color2 : 渐变色的右端
  329.   #--------------------------------------------------------------------------
  330.   def draw_gauge_free(x, y, width, rate, color1, color2, height)
  331.     fill_w = (width * rate).to_i
  332.     gauge_y = y + line_height - 8
  333.     contents.fill_rect(x, gauge_y, width, height, gauge_back_color)
  334.     contents.gradient_fill_rect(x, gauge_y, fill_w, height, color1, color2)
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # ● 绘制 CP
  338.   #--------------------------------------------------------------------------
  339.   def draw_actor_cp(actor, x, y, width = 124, height)
  340.     draw_gauge_free(x, y, width, actor.cp_rate, cp_gauge_color1, cp_gauge_color2, height)
  341.     change_color(system_color)
  342.   end
  343. end
  344. ####################################
  345.  
  346. class Window_CP < Window_Selectable
  347.   #--------------------------------------------------------------------------
  348.   # ● 初始化对象
  349.   #--------------------------------------------------------------------------
  350.   def initialize
  351.     super(0, 0, window_width, window_height)
  352.     refresh
  353.     self.openness = 0
  354.     self.opacity = 200
  355.     self.contents_opacity = 200
  356.   end
  357.  
  358.  
  359.   #--------------------------------------------------------------------------
  360.   # ● 获取窗口的宽度
  361.   #--------------------------------------------------------------------------
  362.   def window_width
  363.     64
  364.   end
  365.   #--------------------------------------------------------------------------
  366.   # ● 获取窗口的高度
  367.   #--------------------------------------------------------------------------
  368.   def window_height
  369.     fitting_height(visible_line_number)
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # ● 获取显示行数
  373.   #--------------------------------------------------------------------------
  374.   def visible_line_number
  375.     return 4
  376.   end
  377.   #--------------------------------------------------------------------------
  378.   # ● 获取项目数
  379.   #--------------------------------------------------------------------------
  380.   def item_max
  381.     $game_party.battle_members.size
  382.   end
  383.  
  384.   #--------------------------------------------------------------------------
  385.   # ● 获取值槽区域的宽度
  386.   #--------------------------------------------------------------------------
  387.   def gauge_area_width
  388.     return 40
  389.   end
  390.   #--------------------------------------------------------------------------
  391.   # ● 获取值槽区域的矩形
  392.   #--------------------------------------------------------------------------
  393.   def gauge_area_rect(index)
  394.     rect = item_rect_for_text(index)
  395.     rect.x += rect.width - gauge_area_width
  396.     rect.width = gauge_area_width
  397.     rect
  398.   end
  399. #~   #--------------------------------------------------------------------------
  400. #~   # ● 绘制项目
  401. #~   #--------------------------------------------------------------------------
  402. #~   def draw_item(index)
  403. #~     actor = $game_party.battle_members[index]
  404. #~     rect = gauge_area_rect(index) ##
  405. #~     draw_actor_cp(actor, rect.x - 165, rect.y - 10, 100, 16) ##
  406. #~     draw_basic_area(basic_area_rect(index), actor)
  407. #~     draw_gauge_area(gauge_area_rect(index), actor)
  408. #~   end
  409.   #--------------------------------------------------------------------------
  410.   # ● 绘制项目
  411.   #--------------------------------------------------------------------------
  412.   def draw_cp(index)
  413.     actor = $game_party.battle_members[index]
  414.     rect = gauge_area_rect(index) ##
  415.     draw_actor_cp(actor, rect.x , rect.y - 10, 40, 16) ##
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # ● 绘制所有项目
  419.   #--------------------------------------------------------------------------
  420.   def draw_all_items_cp
  421.     item_max.times {|i| draw_cp(i) }
  422.   end
  423.  
  424.   def refresh_cp
  425.     contents.clear
  426.     draw_all_items_cp
  427.   end
  428.  
  429. end
  430. #---------------------------------------------------------------------------
  431.  
  432. class Scene_Battle
  433.   #--------------------------------------------------------------------------
  434.   # ● 重定义:开始处理
  435.   #--------------------------------------------------------------------------
  436.   def start
  437.     super
  438.     create_spriteset
  439.     create_all_windows
  440.     BattleManager.method_wait_for_message = method(:wait_for_message)
  441.     @cp_thread = CP_Thread.new
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # ● 重定义:开始后处理
  445.   #--------------------------------------------------------------------------
  446.   def post_start
  447.     super
  448.     battle_start
  449.     @cp_thread.stop = false #
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # ● 生成所有窗口
  453.   #--------------------------------------------------------------------------
  454.   alias :o_create_all_windows :create_all_windows
  455.   def create_all_windows
  456.     o_create_all_windows
  457.     create_CP_window
  458.     create_name_window
  459.   end
  460.   #--------------------------------------------------------------------------
  461.   # ● 生成名字窗口
  462.   #--------------------------------------------------------------------------
  463.   def create_name_window
  464.     @name_window = Window_Name.new
  465.     @name_window.y = 250 + Graphics.height - 416
  466.   end
  467.   #--------------------------------------------------------------------------
  468.   # ● 生成状态窗口
  469.   #--------------------------------------------------------------------------
  470.   def create_CP_window
  471.     @cp_window = Window_CP.new
  472.     @cp_window.x = 0
  473.     @cp_window.y = Graphics.height - 120
  474.   end
  475.   #--------------------------------------------------------------------------
  476.   # ● 重定义:开始角色指令的选择
  477.   #--------------------------------------------------------------------------
  478.   def start_actor_command_selection
  479.     @status_window.select(BattleManager.actor.index)
  480.     @party_command_window.close
  481.     @actor_command_window.setup(BattleManager.actor)
  482.     @name_window.setup(BattleManager.actor)
  483.     @name_window.open
  484.   end
  485.  
  486.   #-------------------------------------------------------------------------
  487.   # ● 当cp满时的操作
  488.   #------------------------------------------------------------------------
  489.   def on_cp_full
  490.     BattleManager.cp_updation
  491.     if BattleManager.enable_go.is_a?(Game_Actor) and
  492.       BattleManager.enable_go.inputable?
  493.       BattleManager.enable_go.on_turn_end
  494.       refresh_status
  495.       start_party_command_selection
  496.       @cp_window.close
  497.     else
  498.       if BattleManager.enable_go.is_a?(Game_Actor)
  499.         BattleManager.enable_go.on_turn_end
  500.         $game_party.make_action(BattleManager.enable_go)
  501.         turn_start
  502.       elsif BattleManager.enable_go.is_a?(Game_Enemy)
  503.         BattleManager.enable_go.on_turn_end
  504.         $game_troop.make_action(BattleManager.enable_go)
  505.         $game_troop.increase_turn(BattleManager.enable_go)
  506.         turn_start
  507.       end
  508.     end
  509.     BattleManager.enable_go_clear
  510.   end
  511.   #-------------------------------------------------------------------------
  512.   # ● 重定义:战斗开始
  513.   #------------------------------------------------------------------------
  514.   def battle_start
  515.     BattleManager.battle_start
  516.     process_event
  517.     unless scene_changing?
  518.       @status_window.unselect
  519.       @status_window.open
  520.       @cp_window.unselect
  521.       @cp_window.open
  522.     end
  523.     on_cp_full
  524.   end
  525.   #-------------------------------------------------------------------------
  526.   # ● cp刷新
  527.   #------------------------------------------------------------------------
  528.   def refresh_cp
  529.     if @cp_thread.update?
  530.       @cp_window.refresh_cp
  531.     end
  532.   end
  533.   #--------------------------------------------------------------------------
  534.   # ● 指令“撤退”
  535.   #--------------------------------------------------------------------------
  536.   def command_escape
  537.     turn_start unless BattleManager.process_escape
  538.     for a in $game_party.battle_members
  539.       a.cp -= CP::CP_COST_BASIC_ESCAPE
  540.     end
  541.   end
  542.   #-------------------------------------------------------------------------
  543.   # ● 重定义:画面更新
  544.   #------------------------------------------------------------------------
  545.   def update
  546.     super
  547.     if BattleManager.cp_updating?
  548.       @cp_thread.update
  549.       #refresh_status
  550.       refresh_cp
  551.       on_cp_full
  552.     elsif BattleManager.in_turn?
  553.       process_event
  554.       on_cp_full
  555.       process_action
  556.     end
  557.  
  558.     BattleManager.judge_win_loss
  559.  
  560.   end
  561.   #--------------------------------------------------------------------------
  562.   # ● 重定义:处理战斗行动
  563.   #--------------------------------------------------------------------------
  564.   def process_action
  565.     @cp_thread.stop = true
  566.     return if scene_changing?
  567.     if !@subject || !@subject.current_action
  568.       @subject = BattleManager.next_subject
  569.     end
  570.     return turn_end unless @subject
  571.     if @subject.current_action
  572.       @subject.current_action.prepare
  573.       if @subject.current_action.valid?
  574.         @status_window.open
  575.         execute_action
  576.       end
  577.       @subject.remove_current_action
  578.     end
  579.     process_action_end unless @subject.current_action
  580.   end
  581.   #-------------------------------------------------------------------------
  582.   # ● 重定义:行动结束
  583.   #------------------------------------------------------------------------
  584.   def process_action_end
  585.     @subject.on_action_end
  586.     @subject.my_turn = false
  587.     if @subject.cp >= 65535
  588.       @subject.cp = 0
  589.     end
  590.     refresh_status
  591.     @log_window.display_auto_affected_status(@subject)
  592.     @log_window.wait_and_clear
  593.     @log_window.display_current_state(@subject)
  594.     @log_window.wait_and_clear
  595.     BattleManager.judge_win_loss
  596.     @subject =  nil
  597.     @cp_thread.stop = false ###########
  598.   end
  599.   #--------------------------------------------------------------------------
  600.   # ● 重定义:回合开始
  601.   #--------------------------------------------------------------------------
  602.   def turn_start
  603.     @party_command_window.close
  604.     @actor_command_window.close
  605.     @name_window.close
  606.     @cp_window.open #
  607.     @status_window.unselect
  608.     BattleManager.turn_start
  609.     @log_window.wait
  610.     @log_window.clear
  611.   end
  612.   #-------------------------------------------------------------------------
  613.   # ● 重定义:回合结束
  614.   #------------------------------------------------------------------------
  615.    def turn_end
  616.      all_battle_members.each do |battler|
  617.        refresh_status
  618.        @log_window.display_auto_affected_status(battler)
  619.        @log_window.wait_and_clear
  620.      end
  621.      BattleManager.turn_end
  622.      process_event
  623.      on_cp_full
  624.    end
  625. end
  626. class Window_Name < Window_Base
  627.   #--------------------------------------------------------------------------
  628.   # ● 初始化对象
  629.   #--------------------------------------------------------------------------
  630.   def initialize
  631.     super(Graphics.width - 128, 0, window_width, fitting_height(1))
  632.     self.openness = 0
  633.     [url=home.php?mod=space&uid=95897]@actor[/url] = nil
  634.   end
  635.   #--------------------------------------------------------------------------
  636.   # ● 获取窗口的宽度
  637.   #--------------------------------------------------------------------------
  638.   def window_width
  639.     return 128
  640.   end
  641.   #--------------------------------------------------------------------------
  642.   # ● 刷新
  643.   #--------------------------------------------------------------------------
  644.   def refresh
  645.     contents.clear
  646.     draw_actor_name(@actor, 0 , 0, 100)
  647.   end
  648.   #--------------------------------------------------------------------------
  649.   # ●
  650.   #--------------------------------------------------------------------------
  651.   def setup(actor)
  652.     [url=home.php?mod=space&uid=95897]@actor[/url] = actor
  653.   end
  654.   #--------------------------------------------------------------------------
  655.   # ● 打开窗口
  656.   #--------------------------------------------------------------------------
  657.   def open
  658.     refresh
  659.     super
  660.   end
  661. end

请大神看一下是否更改后,此脚本的问题……  
作者: wuwei0923    时间: 2013-10-5 17:21
没人吗……




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