Project1

标题: cp战斗脚本错误 [打印本页]

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

作者: 哇哈哈哇哈哈    时间: 2014-6-29 08:01
试试放在Sideview下边(如果有这个脚本),实在不行就把这个脚本放在最下边(Main类之前)




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