Project1

标题: 技能只消耗一半CP值,如何实现? [打印本页]

作者: JasperCrazy    时间: 2019-2-10 14:53
标题: 技能只消耗一半CP值,如何实现?
使用的是图书馆里这个:https://rpg.blue/thread-237131-1-1.html

想实现 “防御”只消耗一半CP值便可再次行动 这类效果。
顺便问一下能否实现 打退敌人的CP条,延迟其行动 的效果。

脚本如下:
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(battler)
  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 = ((5 + 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(skill)
  340.     @result.clear
  341.     regenerate_all
  342.     update_state_turns
  343.     update_buff_turns
  344.     remove_states_auto(2)
  345.     # 该角色的回合计数加1并清空CP
  346.     @turn_count += 1
  347.      case skill.id
  348.     when 80
  349.       @rtab_cp = 0.7
  350.     else
  351.     @rtab_cp = 0.2
  352.     end
  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.   # ● 生成战斗CP条
  405.   #--------------------------------------------------------------------------
  406.   def create_rtabcp_gauge
  407.     @cpgauge_back = Sprite.new(@viewport3)
  408.     @cpgauge_back.bitmap = Bitmap.new(400, 8)
  409.     @cpgauge_back.bitmap.gradient_fill_rect(0, 0, 400, 16, Color.new(0, 255, 0), Color.new(255, 0, 0))
  410.     @cpgauge_back.x = 16
  411.     @cpgauge_back.y = 16
  412.     # 为战斗中的各个角色生成其图标
  413.     @icons = {}
  414.     for iii in $game_party.members
  415.       @icons[iii] = Sprite.new(@viewport3)
  416.       @icons[iii].bitmap = Bitmap.new("Graphics/System/bicon1.png")
  417.       @icons[iii].ox = 12
  418.       @icons[iii].oy = 12
  419.       @icons[iii].x = 16
  420.       @icons[iii].y = 20
  421.     end
  422.     for iii in $game_troop.members
  423.       @icons[iii] = Sprite.new(@viewport3)
  424.       @icons[iii].bitmap = Bitmap.new("Graphics/System/bicon2.png")
  425.       @icons[iii].ox = 12
  426.       @icons[iii].oy = 12
  427.       @icons[iii].x = 16
  428.       @icons[iii].y = 20
  429.     end
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # ● 释放
  433.   #--------------------------------------------------------------------------
  434.   def dispose
  435.     dispose_battleback1
  436.     dispose_battleback2
  437.     dispose_enemies
  438.     dispose_actors
  439.     dispose_pictures
  440.     dispose_timer
  441.     dispose_viewports
  442.     dispose_rtabcp_gauge
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # ● 消灭战斗CP条
  446.   #--------------------------------------------------------------------------
  447.   def dispose_rtabcp_gauge
  448.     @cpgauge_back.bitmap.dispose
  449.     @cpgauge_back.dispose
  450.     for iii in $game_party.members
  451.       @icons[iii].bitmap.dispose
  452.       @icons[iii].dispose
  453.     end
  454.     for iii in $game_troop.members
  455.       @icons[iii].bitmap.dispose
  456.       @icons[iii].dispose
  457.     end
  458.   end
  459.   #--------------------------------------------------------------------------
  460.   # ● 更新画面
  461.   #--------------------------------------------------------------------------
  462.   def update
  463.     update_battleback1
  464.     update_battleback2
  465.     update_enemies
  466.     update_actors
  467.     update_cp
  468.     update_pictures
  469.     update_timer
  470.     update_viewports
  471.   end
  472.   #--------------------------------------------------------------------------
  473.   # ● 更新CP条
  474.   #--------------------------------------------------------------------------
  475.   def update_cp
  476.     for iii in $game_party.members + $game_troop.members
  477.       @icons[iii].x = 16 + 400 * iii.rtab_cp / @cp_quota
  478.       @icons[iii].visible = iii.alive?
  479.     end
  480.   end
  481. end

作者: JasperCrazy    时间: 2019-2-11 09:11
关于如何打退敌人的CP条,作为脚本盲想了个很野的办法:
开关[击退CP]关闭时,关闭脚本自带的造成伤害击退CP效果;
开关[击退CP]开启时,启用效果;
然后特定技能释放前后公共事件开关开关……
感觉局限性很大,希望各位大佬指正。
作者: asdasd1dsadsa    时间: 2019-2-17 04:52
减少CP时间的话,改两句就行了。
首先是加一个initial_cp变量进去,改动的地方自己找。
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ Game_Battler
  4. #------------------------------------------------------------------------------
  5. #  处理战斗者的类。Game_Actor 和 Game_Enemy 类的父类。
  6. #==============================================================================

  7. class Game_Battler < Game_BattlerBase
  8.   attr_accessor :turn_count
  9.   attr_accessor :rtab_cp
  10.   attr_accessor :initial_cp
  11.   attr_accessor :cp_quota
  12.   attr_accessor :in_turn
  13.   #--------------------------------------------------------------------------
  14.   # ● 初始化对象
  15.   #--------------------------------------------------------------------------
  16.   alias neoinitialize initialize
  17.   def initialize
  18.     @turn_count = 0
  19.     @rtab_cp = 0
  20.     @initial_cp = 0
  21.     @cp_quota = 100
  22.     @in_turn = false
  23.     neoinitialize
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 回合结束处理
  27.   #--------------------------------------------------------------------------
  28.   def on_turn_end
  29.     @result.clear
  30.     regenerate_all
  31.     update_state_turns
  32.     update_buff_turns
  33.     remove_states_auto(2)
  34.     # 该角色的回合计数加1并清空CP
  35.     @turn_count += 1
  36.     @rtab_cp = @cp_quota * @initial_cp / 100
  37.     @initial_cp = 0
  38.   end
  39. end
复制代码

然后从技能的备注栏读取CP恢复的百分比。
  1. class RPG::Skill
  2.   def skill_cp_supply
  3.     /<CP_SUPPLY\s*(\d+)>/ =~ note ? $1.to_i : 0
  4.   end
  5. end
复制代码

在pay_skill_cost环节更改initila_cp
  1. class Game_Actor
  2.   alias neo_pay_skill_cost pay_skill_cost
  3.   def pay_skill_cost(skill)
  4.     neo_pay_skill_cost(skill)
  5.     @initial_cp += skill.skill_cp_supply
  6.   end
  7. end
复制代码

作者: asdasd1dsadsa    时间: 2019-2-17 04:54
JasperCrazy 发表于 2019-2-11 09:11
关于如何打退敌人的CP条,作为脚本盲想了个很野的办法:
开关[击退CP]关闭时,关闭脚本自带的造成伤害击退C ...

至于打退CP条,不太清楚你想实现的是什么。开关的话,在他的那段代码那儿加个条件判断呗。
作者: asdasd1dsadsa    时间: 2019-2-17 04:56
改QUOTA也行,视觉效果好些,有种越来越快的感觉。




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