Project1

标题: 一个关于老版CP的问题= = [打印本页]

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

求大神指点迷津!!!另外,我在拿这个包的时候,里面有一部分出问题的似乎就已经被封印了= =
作者: zshuser    时间: 2014-1-29 15:27
呜呜……难道没有大神可以解决的么……话说给一个别的CP也好啊= =




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