#=begin
#==============================================================================
# ●CP制战斗
# 原作者:桜雅 在土, 和希 (XP版CP制),韩云溪(AT即时战斗)
# 修改:pigsss
# ■✖ !注意-------------------------
# ·敌人特殊能力【增加行动次数】不可用│
# ---------------------------------
#==============================================================================
class Game_BattlerBase
#
# 基本能力消耗的CP值
#
CP_COST_SKILL_ITEM_ACTION = 65535 # 技能 物品
CP_COST_BASIC_ATTACK = 32768 # 攻撃
CP_COST_BASIC_GUARD = 32768 # 防御
end
#==============================================================================
# □ CP_Thread
#==============================================================================
class CP_Thread
# 战斗速度
#
BATTLE_SPEED = 2.0
#
# 战斗开始的时候气槽百分比
#
START_CP_PERCENT = 0
#
# CP满时的音效
FULL_SE = "Audio/SE/system09"
#--------------------------------------------------------------------------
# ○ 变量公开
#--------------------------------------------------------------------------
attr_accessor :stop # CP加算ストップ
#----------------------------------------------------------------------------
# ○ 初始化
#----------------------------------------------------------------------------
def initialize
@battlers = []
@cancel = false
@stop = false
@agi_total = 0
# 配列 count_battlers を初期化
count_battlers = []
# エネミーを配列 count_battlers に追加
for enemy in $game_troop.members
count_battlers.push(enemy)
end
# アクターを配列 count_battlers に追加
for actor in $game_party.members
count_battlers.push(actor)
end
for battler in count_battlers
@agi_total += battler.agi
end
for battler in count_battlers
if @preemptive #-------先制攻击
if battler.is_a?(Game_Actor)
battler.cp = 65535
else
battler.cp = 0
end
elsif @surprise #-------被偷袭
if battler.is_a?(Game_Actor)
battler.cp = 0
else
battler.cp = 65535
end
else
battler.cp = [[65535 * START_CP_PERCENT * (rand(15) + 85) * 4 * battler.agi / @agi_total / 10000, 0].max, 65535].min
end
battler.turn_count = 0
end
end
#----------------------------------------------------------------------------
# ○ CP更新
#----------------------------------------------------------------------------
def update
# 停止刷新
return if @stop
#
for battler in $game_party.members + $game_troop.members
# 行動出来なければ無視
if battler.dead? == true
battler.cp = 0
next
end
battler.cp = [[battler.cp + BATTLE_SPEED * 2048 * battler.agi / @agi_total, 0].max, 65535].min
# CP满时
if battler.cp >= battler.max_cp
Audio.se_play(FULL_SE)
BattleManager.set_enable_go(battler)
battler.my_turn = true
BattleManager.input_start
break
end
unless BattleManager.cp_updating?
return
end
end
def update?
return !@stop
end
end
#----------------------------------------------------------------------------
# ○ CPカウントの開始
#----------------------------------------------------------------------------
def stop
@cancel = true
if @cp_thread != nil then
@cp_thread.join
@cp_thread = nil
end
end
end
#==============================================================================
# ■ Game_BattlerBase
#------------------------------------------------------------------------------
# 管理战斗者的类。主要含有能力值计算的方法。Game_Battler 类的父类。
#==============================================================================
class Game_BattlerBase
attr_reader :cp # CP
attr_accessor :turn_count
attr_accessor :my_turn
#------------------------------
alias old_initialize initialize
def initialize
old_initialize
@cp = 0
@turn_count = 0
@my_turn = false
end
#------------------------------
def inputable?
if @my_turn
return normal? && !auto_battle?# && @cp >= 65535
else
return false
end
end
#--------------------------------------------------------------------------
# ● 更改 CP
#--------------------------------------------------------------------------
def cp=(cp)
@cp = [[cp, max_cp].min, 0].max
end
#--------------------------------------------------------------------------
# ● 获取 CP 的最大值
#--------------------------------------------------------------------------
def max_cp
return 65535
end
#--------------------------------------------------------------------------
# ● 获取 CP 的比率
#--------------------------------------------------------------------------
def cp_rate
@cp.to_f / 65535
end
#--------------------------------------------------------------------------
# ● 扣除技能的使用消耗
#--------------------------------------------------------------------------
def pay_skill_cost(skill)
self.mp -= skill_mp_cost(skill)
self.tp -= skill_tp_cost(skill)
###########
case skill.id
when 1
@cp -= CP_COST_BASIC_ATTACK
when 2
@cp -= CP_COST_BASIC_GUARD
when 3...999 # 可自订不同消耗的技能
@cp -= CP_COST_SKILL_ITEM_ACTION
else
@cp = 0
end
###########
end
end
#--------------------------------------------------------
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# ● 消耗物品
#--------------------------------------------------------------------------
def consume_item(item)
$game_party.consume_item(item)
###########
case item.id
when 0...999 # 可自订不同消耗的物品
@cp -= CP_COST_SKILL_ITEM_ACTION
else
@cp = 0
end
###########
end
end
#-------------------------------------
class Game_Party < Game_Unit
def make_action(member)
unless member == nil
member.make_actions unless member.inputable?
end
end
end
#-------------------------------------
class Game_Troop < Game_Unit
def make_action(member)
member.make_actions unless member == nil
end
def increase_turn(enemy)
troop.pages.each {|page| @event_flags[page] = false if page.span == 1 }
enemy.turn_count += 1
aaa = []
for iii in $game_troop.members
aaa.push(iii.turn_count)
end
@turn_count = aaa.min
end
end
#-------------------------------------
module BattleManager
def self.battle_start
$game_system.battle_count += 1
$game_party.on_battle_start
$game_troop.on_battle_start
$game_troop.enemy_names.each do |name|
$game_message.add(sprintf(Vocab::Emerge, name))
end
if @preemptive
$game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
elsif @surprise
$game_message.add(sprintf(Vocab::Surprise, $game_party.name))
end
wait_for_message
end
def self.enable_go
@enable_go
end
def self.set_enable_go(b)
@enable_go = b
end
def self.enable_go_clear
@enable_go = nil
end
def self.max_agi
@max_agi
end
def self.cp_updation
@phase = :cp_update
end
def self.cp_updating?
@phase == :cp_update
end
#-------------------------------------------------------------------------
# ● 重定义:回合开始
#------------------------------------------------------------------------
def self.turn_start
@phase = :turn
clear_actor
make_action_orders
end
#-------------------------------------------------------------------------
# ● 重定义:行动顺序
#------------------------------------------------------------------------
def self.make_action_orders
@action_battlers = []
for b in $game_troop.members + $game_party.members
if b.my_turn
@action_battlers.push(b)
end
end
exclude_battler = []
for battler in @action_battlers
if battler.cp < 65535
exclude_battler.push(battler)
end
end
@action_battlers -= exclude_battler
end
end
#==============================================================================
# ■ Window_Base
#------------------------------------------------------------------------------
# 游戏中所有窗口的父类
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# ● 获取颜色
#--------------------------------------------------------------------------
def cp_gauge_color1; Color.new(255,255,255); end; # CP 值槽 1
def cp_gauge_color2; Color.new(62,240,240); end; # CP 值槽 2
#--------------------------------------------------------------------------
# ● 绘制值槽(长宽自由版)
# rate : 比率(1.0 为满值)
# color1 : 渐变色的左端
# color2 : 渐变色的右端
#--------------------------------------------------------------------------
def draw_gauge_free(x, y, width, rate, color1, color2, height)
#气槽蓄积速度
fill_w = (width * rate * 1.55).to_i
gauge_y = y + line_height - 8
contents.fill_rect(x, gauge_y, width+140, height, gauge_back_color)
contents.gradient_fill_rect(x, gauge_y, fill_w, height, color1, color2)
end
#--------------------------------------------------------------------------
# ● 绘制 CP
#--------------------------------------------------------------------------
def draw_actor_cp(actor, x, y, width = 0, height=0)
draw_gauge_free(x - 420, y + 25, width + 230, actor.cp_rate, cp_gauge_color1, cp_gauge_color2, height+20)
change_color(system_color)
end
end
####################################
class Window_CP < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(0, 0, window_width, window_height)
refresh
self.openness = 30
self.opacity = 180
self.contents_opacity = 180
end
#--------------------------------------------------------------------------
# ● 获取窗口的宽度
#--------------------------------------------------------------------------
def window_width
Graphics.width
end
#--------------------------------------------------------------------------
# ● 获取窗口的高度
#--------------------------------------------------------------------------
def window_height
fitting_height(visible_line_number)
end
#--------------------------------------------------------------------------
# ● 获取显示行数
#--------------------------------------------------------------------------
def visible_line_number
return 4
end
#--------------------------------------------------------------------------
# ● 获取项目数
#--------------------------------------------------------------------------
def item_max
$game_party.battle_members.size
end
#--------------------------------------------------------------------------
# ● 获取值槽区域的宽度
#--------------------------------------------------------------------------
def gauge_area_width
return 40
end
#--------------------------------------------------------------------------
# ● 获取值槽区域的矩形
#--------------------------------------------------------------------------
def gauge_area_rect(index)
rect = item_rect_for_text(index)
rect.x += rect.width - gauge_area_width
rect.width = gauge_area_width
rect
end
#~ #--------------------------------------------------------------------------
#~ # ● 绘制项目
#~ #--------------------------------------------------------------------------
#~ def draw_item(index)
#~ actor = $game_party.battle_members[index]
#~ rect = gauge_area_rect(index) ##
#~ draw_actor_cp(actor, rect.x - 165, rect.y - 10, 100, 16) ##
#~ draw_basic_area(basic_area_rect(index), actor)
#~ draw_gauge_area(gauge_area_rect(index), actor)
#~ end
#--------------------------------------------------------------------------
# ● 绘制项目
#--------------------------------------------------------------------------
def draw_cp(index)
actor = $game_party.battle_members[index]
rect = gauge_area_rect(index) ##
draw_actor_cp(actor, rect.x , rect.y - 10, 40, 16) ##
end
#--------------------------------------------------------------------------
# ● 绘制所有项目
#--------------------------------------------------------------------------
def draw_all_items_cp
item_max.times {|i| draw_cp(i) }
end
def refresh_cp
contents.clear
draw_all_items_cp
end
end
#---------------------------------------------------------------------------
class Scene_Battle
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_spriteset
create_all_windows
BattleManager.method_wait_for_message = method(:wait_for_message)
@cp_thread = CP_Thread.new
end
#--------------------------------------------------------------------------
# ● 开始后处理
#--------------------------------------------------------------------------
def post_start
super
battle_start
@cp_thread.stop = false #
end
#--------------------------------------------------------------------------
# ● 生成所有窗口
#--------------------------------------------------------------------------
alias o_create_all_windows create_all_windows
def create_all_windows
o_create_all_windows
create_CP_window
end
#--------------------------------------------------------------------------
# ● 生成状态窗口
#--------------------------------------------------------------------------
def create_CP_window
@cp_window = Window_CP.new
@cp_window.x = 0
@cp_window.y = 296
end
#-------------------------------------------------------------------------
# ● 当cp满时的操作
#------------------------------------------------------------------------
def on_cp_full
BattleManager.cp_updation
if BattleManager.enable_go.is_a?(Game_Actor) and
BattleManager.enable_go.inputable?
BattleManager.enable_go.on_turn_end
refresh_status
start_party_command_selection
@cp_window.close
else
if BattleManager.enable_go.is_a?(Game_Actor)
BattleManager.enable_go.on_turn_end
$game_party.make_action(BattleManager.enable_go)
turn_start
elsif BattleManager.enable_go.is_a?(Game_Enemy)
BattleManager.enable_go.on_turn_end
$game_troop.make_action(BattleManager.enable_go)
$game_troop.increase_turn(BattleManager.enable_go)
turn_start
end
end
BattleManager.enable_go_clear
end
#-------------------------------------------------------------------------
# ● 重定义:战斗开始
#------------------------------------------------------------------------
def battle_start
BattleManager.battle_start
process_event
unless scene_changing?
@status_window.unselect
@status_window.open
@cp_window.unselect
@cp_window.open
end
on_cp_full
end
#-------------------------------------------------------------------------
# ● cp刷新
#------------------------------------------------------------------------
def refresh_cp
if @cp_thread.update?
@cp_window.refresh_cp
end
end
#-------------------------------------------------------------------------
# ● 重定义:画面更新
#------------------------------------------------------------------------
def update
super
if BattleManager.cp_updating?
@cp_thread.update
#refresh_status
refresh_cp
on_cp_full
elsif BattleManager.in_turn?
process_event
on_cp_full
process_action
end
BattleManager.judge_win_loss
end
#--------------------------------------------------------------------------
# ● 处理战斗行动
#--------------------------------------------------------------------------
def process_action
@cp_thread.stop = true
return if scene_changing?
if !@subject || !@subject.current_action
@subject = BattleManager.next_subject
end
return turn_end unless @subject
if @subject.current_action
@subject.current_action.prepare
if @subject.current_action.valid?
@status_window.open
execute_action
end
@subject.remove_current_action
end
process_action_end unless @subject.current_action
end
#-------------------------------------------------------------------------
# ● 重定义:行动结束
#------------------------------------------------------------------------
def process_action_end
@subject.on_action_end
@subject.my_turn = false
refresh_status
@log_window.display_auto_affected_status(@subject)
@log_window.wait_and_clear
@log_window.display_current_state(@subject)
@log_window.wait_and_clear
BattleManager.judge_win_loss
@cp_thread.stop = false ###########
end
#--------------------------------------------------------------------------
# ● 回合开始
#--------------------------------------------------------------------------
def turn_start
@party_command_window.close
@actor_command_window.close
@cp_window.open #
@status_window.unselect
@subject = nil
BattleManager.turn_start
@log_window.wait
@log_window.clear
end
#-------------------------------------------------------------------------
# ● 重定义:回合结束
#------------------------------------------------------------------------
def turn_end
all_battle_members.each do |battler|
refresh_status
@log_window.display_auto_affected_status(battler)
@log_window.wait_and_clear
end
BattleManager.turn_end
process_event
on_cp_full
end
end