查看: 1227|回复: 1

[已经过期] atb腳本的問題

[复制链接]
梦石
0
星屑
50
在线时间
292 小时
注册时间
2009-10-30
回帖
18
发表于 2013-11-25 12:06:03 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 graygod 于 2013-11-25 12:44 编辑

在atb腳本裡有一段   

#------------------------------------------------------------------
  #●新方法: advance_turn  回合計算
  #--------------------------------------------------------------------------
  def self.advance_turn
    return if CBS::TURN_LENGTH == 0  
    @turn_counter += 1
    if @turn_counter == 60 * CBS::TURN_LENGTH
      $game_troop.increase_turn
      SceneManager.scene.turn_end
      @turn_counter = 0
    end
  end
end
  #--------------------------------------------------------------------------
其中 CBS::TURN_LENGTH 是計算用的秒數  我設定為1


所以這段程式是說  @turn_counter 計算到60 時 如果與  60 * CBS::TURN_LENGTH相等
則 增加1回合

問題是  我將@turn_counte 用p 印出來   測試  
每三四 次 測試  @turn_counte 竟然會 跳出78 79 的數字出來

而沒而執行     if @turn_counter == 60 * CBS::TURN_LENGTH  後面的  程式
我剛剛在把  60 * CBS::TURN_LENGTH  用p 列出來  固定都是 60 沒錯
這中間  到底發生什麼事 !!!?

另外  我懷疑是反擊 產生的錯誤  
但   @turn_counter += 1 後  一定會執行     if @turn_counter == 60 * CBS::TURN_LENGTH
不是 嗎   怎會出現  61 62 這種值出來  




自己解決了   原本的腳本就有bug
YanFly 在寫atb 時有二個 計算回合的方式  一個是秒數  一個是行動數
結果二個方法  都有 @turn_counter += 1   這句  
如果 在@turn_counter 為59時 剛好有行動  就會出現這問題  ....


完整腳本


=
  1. begin
  2. YanFly Compatible Customisable ATB/Stamina Based Battle System Script
  3. by Fomar0153
  4. Version 1.2
  5. ----------------------
  6. Notes
  7. ----------------------
  8. Requires Yanfly Engine Ace - Ace Battle Engine
  9. Customises the battle system to be similar to
  10. ATB or Stamina based battle systems.
  11. ----------------------
  12. Instructions
  13. ----------------------
  14. Edit variables in CBS to suit your needs.
  15. The guard status should be set to 2~2 turns.
  16. ----------------------
  17. Change Log
  18. ----------------------
  19. 1.0 -> 1.1 Added CTB related options
  20.            Added the ability to pass a turn
  21.            Added options for turn functionality to be based on time
  22.            or number of actions
  23.            Added the ability to change the bar colours based on states
  24. 1.1 -> 1.2 Fixed a bug when escaping using CTB mode
  25. ----------------------
  26. Known bugs
  27. ----------------------
  28. None
  29. =end

  30. $imported = {} if $imported.nil?
  31. $imported["Fomar0153-CBS"] = true

  32. module CBS

  33.   MAX_STAMINA = 400 #行動值的分母
  34.   RESET_STAMINA = true
  35.   
  36.   # If ATB is set to false then the bars won't appear and
  37.   # the pauses where the bars would be filling up are removed
  38.   # effectively turning this into a CTB system
  39.   ATB = true
  40.   SAMINA_GAUGE_NAME = "ATB"
  41.   ENABLE_PASSING = true
  42.   PASSING_COST = 200

  43.   #回合長度
  44.   # If TURN_LENGTH is set to 0 then a turn length will be
  45.   # decided on number of actions
  46.   # TURN_LENGTH is number of seconds per turn
  47.   TURN_LENGTH = 1
  48.   
  49.   ESCAPE_COST = 500
  50.   # If reset stamina is set to true then all characters
  51.   # will start with a random amount of stamina capped at
  52.   # the percentage you set.
  53.   # If reset stamina is set to false then this just
  54.   # affects enemies.
  55.   STAMINA_START_PERCENT = 20

  56.   # Default skill cost
  57.   # If you want to customise skill costs do it like this
  58.   # SKILL_COST[skill_id] = cost
  59.   SKILL_COST = []
  60.   SKILL_COST[0] = 1000
  61.   # Attack
  62.   SKILL_COST[1] = 1000
  63.   # Guard
  64.   SKILL_COST[2] = 500
  65.   ITEM_COST = 1000

  66.   # 增益設定 設為 true 則公式只看agi決定 參考stamina_mult方法
  67.   STATES_HANDLE_AGI = false
  68.   # In the following section mult means the amount you multiply stamina gains by
  69.   # if STATES_HANDLE_AGI is set to true then it is only used to determine bar color
  70.   # with debuffs taking precedence over buffs
  71.   STAMINA_STATES = []
  72.   # Default colour
  73.   STAMINA_STATES[0] = [1,31,32]
  74.   # in the form
  75.   # STAMINA_STATES[STATE_ID] = [MULT,FILL_COLOUR,EMPTY_COLOR]
  76.   # e.g. 快速  #狀態78 則二倍快 ,進度為第4色, 空的為32色
  77.   STAMINA_STATES[78] = [2,4,32]
  78.   # e.g. 停止  
  79.   STAMINA_STATES[79] = [0,8,32]
  80.   # e.g. 慢速    #狀態80 慢一半 ,進度為第8色, 空的為32色
  81.   STAMINA_STATES[80] = [0.5,8,32]

  82.   #--------------------------------------------------------------------------
  83.   # ●新方法: 行動力增加公式  
  84.   #--------------------------------------------------------------------------
  85.   def self.stamina_gain(battler)
  86.     return ((2 + [0, battler.agi / 10].max) * self.stamina_mult(battler)).to_i
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   #●新方法: 行動力增加倍率公式
  90.   #--------------------------------------------------------------------------
  91.   def self.stamina_mult(battler)
  92.     return 1 if STATES_HANDLE_AGI
  93.     mult = STAMINA_STATES[0][0]
  94.     for state in battler.states
  95.       unless STAMINA_STATES[state.id].nil?
  96.         mult *= STAMINA_STATES[state.id][0]
  97.       end
  98.     end
  99.     return mult
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   #●新方法:  行動力增加顏色
  103.   #--------------------------------------------------------------------------
  104.   def self.stamina_colors(battler)
  105.     colors = STAMINA_STATES[0]
  106.     for state in battler.states
  107.       unless STAMINA_STATES[state.id].nil?
  108.         if STAMINA_STATES[state.id][0] < colors[0] or colors[0] == 1
  109.           colors = STAMINA_STATES[state.id]
  110.         end
  111.       end
  112.     end
  113.     return colors
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   #●新方法: 行動力初始值
  117.   #--------------------------------------------------------------------------
  118.   def self.stamina_start(battler)
  119.     battler.stamina = rand(MAX_STAMINA * STAMINA_START_PERCENT / 100)
  120.   end
  121. end

  122. class Game_BattlerBase
  123.   #--------------------------------------------------------------------------
  124.   # ● New attr_accessor
  125.   #--------------------------------------------------------------------------
  126.   attr_accessor :stamina
  127.   #--------------------------------------------------------------------------
  128.   # ● Aliases initialize
  129.   #--------------------------------------------------------------------------
  130.   alias yf_fomar_cbs_initialize initialize
  131.   def initialize
  132.     yf_fomar_cbs_initialize
  133.     @stamina = 0
  134.   end
  135.   #--------------------------------------------------------------------------
  136.   # ● 新方法 獲得行動值比例
  137.   #--------------------------------------------------------------------------
  138.   def stamina_rate
  139.     @stamina.to_f / CBS::MAX_STAMINA
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   #●新方法: stamina_rate
  143.   #--------------------------------------------------------------------------
  144.   def stamina_gain
  145.     return if not movable?
  146.     @stamina = [CBS::MAX_STAMINA, @stamina + CBS.stamina_gain(self)].min
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   #●新方法: stamina_color
  150.   #--------------------------------------------------------------------------
  151.   def stamina_color
  152.     for state in @states
  153.       unless CBS::STAMINA_STATES[state].nil?
  154.         return STAMINA_STATES[state]
  155.       end
  156.     end
  157.     return STAMINA_STATES[0]
  158.   end
  159. end

  160. class Scene_Battle < Scene_Base
  161.   #--------------------------------------------------------------------------
  162.   # ● Rewrote update
  163.   #--------------------------------------------------------------------------
  164.   def update
  165.     super
  166.     if (CBS::ENABLE_PASSING and @actor_command_window.active) and Input.press?(:A)
  167.       command_pass
  168.     end
  169.     if BattleManager.in_turn? and !inputting?
  170.       while @subject.nil? and !CBS::ATB
  171.         process_stamina
  172.       end
  173.       if CBS::ATB
  174.         process_stamina
  175.       end
  176.       process_event
  177.       process_action
  178.     end
  179.     BattleManager.judge_win_loss
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ● Rewrote Method update_info_viewport
  183.   #--------------------------------------------------------------------------
  184.   def update_info_viewport
  185.     move_info_viewport(0)   if @party_command_window.active
  186.     move_info_viewport(128) if @actor_command_window.active
  187.     move_info_viewport(64)  if BattleManager.in_turn? and !inputting?
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   #●新方法: inputting?
  191.   #--------------------------------------------------------------------------
  192.   def inputting?
  193.     return @actor_command_window.active || @skill_window.active ||
  194.       @item_window.active || @actor_window.active || @enemy_window.active
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   #●新方法: process_stamina  
  198.   #--------------------------------------------------------------------------
  199.   def process_stamina
  200.     @actor_command_window.close   #命令視窗關閉
  201.     return if @subject
  202.     BattleManager.advance_turn   #回合計算
  203.     all_battle_members.each do |battler|
  204.       battler.stamina_gain         #所有人行動值增加
  205.     end
  206.     @status_window.refresh_stamina  #更行狀態視窗之行動值
  207.     if @status_window.close?
  208.       @status_window.open
  209.      end
  210.     if BattleManager.escaping?
  211.       $game_party.battle_members.each do |battler|
  212.         if battler.stamina < CBS::MAX_STAMINA   #行動力沒滿
  213.           $game_troop.members.each do |enemy|
  214.             if enemy.stamina == CBS::MAX_STAMINA #如果敵人行動力值滿
  215.               enemy.make_actions
  216.               @subject = enemy
  217.             end
  218.           end
  219.           return
  220.         end
  221.       end
  222.       unless BattleManager.process_escape
  223.         $game_party.battle_members.each do |actor|
  224.           actor.stamina -= CBS::ESCAPE_COST
  225.         end
  226.         BattleManager.set_escaping(false) unless CBS::ATB
  227.       end
  228.     end
  229.     all_battle_members.each do |battler|
  230.       if battler.stamina == CBS::MAX_STAMINA  #如果戰鬥者行動力值滿
  231.         battler.make_actions
  232.         @subject = battler
  233.         if @subject.inputable? and battler.is_a?(Game_Actor)
  234.           @actor_command_window.setup(@subject)
  235.           @status_window.index = @subject.index
  236.           BattleManager.set_actor(battler)
  237.         end
  238.         return
  239.       end
  240.     end
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # ● Rewrote start_party_command_selection Yanfly version
  244.   #--------------------------------------------------------------------------
  245.   def start_party_command_selection
  246.     unless scene_changing?
  247.       refresh_status
  248.       @status_window.unselect
  249.       @status_window.open
  250.       if BattleManager.input_start
  251.         @actor_command_window.close
  252.         @party_command_window.setup
  253.       else
  254.         @party_command_window.deactivate
  255.         turn_start
  256.       end
  257.     end
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # ● Rewrote start_actor_command_selection
  261.   #--------------------------------------------------------------------------
  262.   def start_actor_command_selection
  263.     @party_command_window.close
  264.     BattleManager.set_escaping(false)
  265.     turn_start
  266.   end
  267.   #--------------------------------------------------------------------------
  268.   # ● Rewrote prior_command Yanfly version
  269.   #--------------------------------------------------------------------------
  270.   def prior_command
  271.     redraw_current_status
  272.     start_party_command_selection
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # ● Rewrote process_action
  276.   #--------------------------------------------------------------------------
  277.   def process_action
  278.     return if scene_changing?
  279.     if !@subject || !@subject.current_action
  280.       @subject = BattleManager.next_subject
  281.     end
  282.     if Input.trigger?(:B) and (@subject == nil)
  283.       start_party_command_selection
  284.     end
  285.     return unless @subject
  286.     if @subject.current_action
  287.       @subject.current_action.prepare
  288.       if @subject.current_action.valid?
  289.         @status_window.open
  290.         execute_action
  291.       end
  292.       @subject.remove_current_action
  293.       refresh_status
  294.       @log_window.display_auto_affected_status(@subject)
  295.       @log_window.wait_and_clear
  296.     end
  297.     process_action_end unless @subject.current_action
  298.   end
  299.   #--------------------------------------------------------------------------
  300.   # ● Aliases 使用道具或技能
  301.   #--------------------------------------------------------------------------
  302.   alias cbs_use_item use_item
  303.   def use_item
  304.     cbs_use_item
  305.     @subject.stamina_loss
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # ● Rewrote turn_end
  309.   #--------------------------------------------------------------------------
  310.   def turn_end
  311.     p "atb回合結束"
  312.     all_battle_members.each do |battler|
  313.       battler.on_turn_end
  314.       refresh_status
  315.       @log_window.display_auto_affected_status(battler)
  316.       @log_window.wait_and_clear
  317.     end
  318.     #BattleManager.turn_end
  319.     #process_event
  320.     #start_party_command_selection
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # ● Rewrote command_fight
  324.   #--------------------------------------------------------------------------
  325.   def command_fight
  326.     BattleManager.next_command
  327.     start_actor_command_selection
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # ● Rewrote command_escape
  331.   #--------------------------------------------------------------------------
  332.   def command_escape
  333.     @party_command_window.close
  334.     BattleManager.set_escaping(true)
  335.     turn_start
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   #●新方法: command_pass
  339.   #--------------------------------------------------------------------------
  340.   def command_pass
  341.     BattleManager.actor.stamina -= CBS::PASSING_COST
  342.     BattleManager.clear_actor
  343.     @subject = nil
  344.     turn_start
  345.     @actor_command_window.active = false
  346.     @actor_command_window.close
  347.   end
  348.   #--------------------------------------------------------------------------
  349.   # ● Destroyed next_command
  350.   #--------------------------------------------------------------------------
  351.   def next_command
  352.     @status_window.show
  353.     @actor_command_window.show
  354.     @status_aid_window.hide
  355.   end
  356. end




  357. module BattleManager
  358.   #--------------------------------------------------------------------------
  359.   # ● Rewrote setup
  360.   #--------------------------------------------------------------------------
  361.   def self.setup(troop_id, can_escape = true, can_lose = false)
  362.     init_members
  363.     $game_troop.setup(troop_id)
  364.     @can_escape = can_escape
  365.     @can_lose = can_lose
  366.     make_escape_ratio
  367.     @escaping = false
  368.     @turn_counter = 0
  369.     @actions_per_turn = $game_party.members.size + $game_troop.members.size
  370.     ($game_party.members + $game_troop.members).each do |battler|
  371.       if battler.is_a?(Game_Enemy) or CBS::RESET_STAMINA
  372.         CBS.stamina_start(battler)
  373.       end
  374.     end
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   #●新方法: set_escaping
  378.   #--------------------------------------------------------------------------
  379.   def self.set_escaping(escaping)
  380.     @escaping = escaping
  381.   end
  382.   #--------------------------------------------------------------------------
  383.   #●新方法: escaping?
  384.   #--------------------------------------------------------------------------
  385.   def self.escaping?
  386.     return @escaping
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # ● Rewrote turn_start Yanfly version
  390.   #--------------------------------------------------------------------------
  391.   def self.turn_start
  392.     @phase = :turn
  393.     clear_actor
  394.     $game_troop.increase_turn if $game_troop.turn_count == 0
  395.     @performed_battlers = []
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   #●新方法: set_actor
  399.   #--------------------------------------------------------------------------
  400.   def self.set_actor(actor)
  401.     @actor_index = actor.index
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # ● New Increase action counter
  405.   #--------------------------------------------------------------------------
  406.   def self.add_action
  407.     return if @actions_per_turn.nil?
  408.     @turn_counter += 1
  409.     if @turn_counter == @actions_per_turn and CBS::TURN_LENGTH == 0 #@actions_per_turn為戰鬥成員總數
  410.       $game_troop.increase_turn
  411.       SceneManager.scene.turn_end
  412.       @turn_counter = 0
  413.     end
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   #●新方法: advance_turn  回合計算
  417.   #--------------------------------------------------------------------------
  418.   def self.advance_turn
  419.     return if CBS::TURN_LENGTH == 0  
  420.     p "@turn_counter"
  421.     p @turn_counter
  422.     @turn_counter += 1
  423.     if @turn_counter == 60 * CBS::TURN_LENGTH
  424.       $game_troop.increase_turn
  425.       SceneManager.scene.turn_end
  426.       @turn_counter = 0
  427.     end
  428.   end
  429. end

  430. class Game_Battler < Game_BattlerBase
  431.   #--------------------------------------------------------------------------
  432.   # ● Rewrote on_turn_end
  433.   #--------------------------------------------------------------------------
  434.   def on_turn_end
  435.     @result.clear
  436.     regenerate_all
  437.     update_state_turns
  438.     update_buff_turns
  439.     remove_states_auto(2)
  440.   end
  441.   #--------------------------------------------------------------------------
  442.   #●新方法: 角色行動結束
  443.   #--------------------------------------------------------------------------
  444.   def stamina_loss
  445.     if self.actor?
  446.       @stamina -= input.stamina_cost
  447.     else
  448.       @stamina -= @actions[0].stamina_cost if @actions[0]  
  449.     end
  450.     BattleManager.add_action
  451.   end
  452. end

  453. class Game_Actor < Game_Battler
  454.   #--------------------------------------------------------------------------
  455.   # ● Rewrote input
  456.   #--------------------------------------------------------------------------
  457.   def input
  458.     if @actions[@action_input_index] == nil
  459.       @actions[@action_input_index] = Game_Action.new(self)
  460.     end
  461.     return @actions[@action_input_index]
  462.   end
  463. end

  464. class Game_Action
  465.   #--------------------------------------------------------------------------
  466.   #●新方法: stamina_cost
  467.   #--------------------------------------------------------------------------
  468.   def stamina_cost
  469.     if @item.is_skill?
  470.       return CBS::SKILL_COST[item.id] if CBS::SKILL_COST[item.id]
  471.       return CBS::SKILL_COST[0]
  472.     end
  473.     return CBS::ITEM_COST if @item.is_item?
  474.     return CBS::MAX_STAMINA
  475.   end
  476. end

  477. class Window_BattleStatus < Window_Selectable
  478.   #--------------------------------------------------------------------------
  479.   # Aliases method: draw_item yanfly version
  480.   #--------------------------------------------------------------------------
  481.   alias prefomar_draw_item draw_item
  482.   def draw_item(index)
  483.     unless CBS::ATB
  484.       prefomar_draw_item(index)
  485.       return
  486.     end
  487.     return if index.nil?
  488.     clear_item(index)
  489.     actor =  $game_party.battle_members[index]#battle_members[index]
  490.     rect = item_rect(index)
  491.     return if actor.nil?
  492.     draw_actor_face(actor, rect.x+2, rect.y+2, actor.alive?)
  493.     draw_actor_name(actor, rect.x, rect.y, rect.width-8)
  494.     draw_actor_action(actor, rect.x, rect.y)
  495.     draw_actor_icons(actor, rect.x, line_height*1, rect.width)
  496.     gx = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
  497.     contents.font.size = YEA::BATTLE::BATTLESTATUS_TEXT_FONT_SIZE
  498.     draw_actor_hp(actor, rect.x+2, line_height*2, rect.width-4)
  499.     if draw_tp?(actor) && draw_mp?(actor)
  500.       dw = rect.width/2-2
  501.       dw += 1 if $imported["YEA-CoreEngine"] && YEA::CORE::GAUGE_OUTLINE
  502.       draw_actor_tp(actor, rect.x+2, line_height*2+gx, dw)
  503.       dw = rect.width - rect.width/2 - 2
  504.       draw_actor_mp(actor, rect.x+rect.width/2, line_height*2+gx, dw)
  505.     elsif draw_tp?(actor) && !draw_mp?(actor)
  506.       draw_actor_tp(actor, rect.x+2, line_height*2+gx, rect.width-4)
  507.     else
  508.       draw_actor_mp(actor, rect.x+2, line_height*2+gx, rect.width-4)
  509.     end
  510.     draw_actor_stamina(actor, rect.x+2, line_height*3, rect.width-4)
  511.   end
  512.   #--------------------------------------------------------------------------
  513.   # overwrite method: draw_item yanfly version
  514.   #--------------------------------------------------------------------------
  515.   def draw_item_stamina(index)
  516.     return if index.nil?
  517.     actor = $game_party.battle_members[index]#battle_members[index]
  518.     rect = item_rect(index)
  519.     return if actor.nil?
  520.     gx = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
  521.     contents.font.size = YEA::BATTLE::BATTLESTATUS_TEXT_FONT_SIZE
  522.     draw_actor_stamina(actor, rect.x+2, line_height*3, rect.width-4)
  523.   end
  524.   #--------------------------------------------------------------------------
  525.   #新方法: refresh_stamina
  526.   #--------------------------------------------------------------------------
  527.   def refresh_stamina
  528.     return unless CBS::ATB
  529.     item_max.times {|i| draw_item_stamina(i) }
  530.   end
  531.   #--------------------------------------------------------------------------
  532.   #新方法: 描繪行動值
  533.   #--------------------------------------------------------------------------
  534.   def draw_actor_stamina(actor, dx, dy, width = 124)
  535.    draw_gauge(dx, dy, width, actor.stamina_rate, text_color(CBS.stamina_colors(actor)[2]),text_color(CBS.stamina_colors(actor)[1]))
  536.     change_color(system_color)
  537.     cy = (Font.default_size - contents.font.size) / 2 + 1
  538.     draw_text(dx+2, dy+cy, 30, line_height, CBS::SAMINA_GAUGE_NAME)
  539.   end
  540. end
复制代码

簡報1.jpg
梦石
0
星屑
55
在线时间
416 小时
注册时间
2012-11-30
回帖
146
发表于 2013-11-25 12:16:34 | 显示全部楼层
加脚本框呀!!!!

<object width="630" height="500" align="middle" id="reader" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-44455354000
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部