- 注册时间
- 2008-3-9
- 最后登录
- 2008-3-17
③业余
- 积分
- 200
|
嗯,实现北欧女神2的CP制,米有地图效果,在默认战斗中实现的。
真的很垃圾ORZ……表Pia偶哦~~ #=====================================================================
# 仿北欧女神2 CP制战斗 By Iselia雪
# 战斗一开始根据敌我速度敏捷比例设定初始CP值,
# 我方的每一种行动都有它所对应的CP消耗,当CP值不足以完成行动时该行动不能被执行。
# 战斗中在选择行动时摁下B键进入敌人行动模式,该模式下CP会慢慢回复,
# 而敌人会以一般CP制的方式行动(算法照抄RTAB,加入了敌方速度的计算)。
# 在被敌人攻时,CP会有一定的回复,回复量在下面设定。
# 敌人行动模式下摁C键进入我方行动设定,设定完成的行动会立刻被执行。
# 设定我方行动时用左右键选择行动的角色。
# 特技和物品的名称需要做以下调整 :
# 名称@CP消耗 这个格式,没有设定CP消耗默认值5,
# 近似于无限使用。
# 其他数值设定在下面进行,平衡度还是比较容易调的口牙。
#=====================================================================
$基本CP = 20 #战斗一开始我方CP的基础值。
$CP恢复速度 = 4 #数值越大敌人行动模式下CP回复越慢。
$敌人行动速度 = 12 #敌人的行动速度,数值越小越快
$物理攻击CP消耗 = 15 #物理攻击消耗的CP值
$防御CP消耗 = 10 #防御消耗的CP值
$被攻CP回复 = 5 #被敌人攻击时CP的回复量,设为0就是不回复。
$回合进行速度 = 5 #战斗回合增加的速度,数值越大越慢(倍数增长慎用ORZ)- -
$逃跑CP消耗 = 30 #逃跑消耗的CP
$CP名 = "小攻点数" #CP的名称,懒人模式用- -
$懒人模式 = true #自动显示物品和特技消耗的CP。
#=====================================================================
#修改CP的显示改这个部分,小雪不负责讲解|||||
class CP < RPG::Sprite
attr_accessor :cp
def initialize(val = 0)
super()
self.bitmap = Bitmap.new(30,240)
self.bitmap.fill_rect(10,0,10,200,Color.new(0,0,0,255))
self.bitmap.font.size = 16
self.x = 20
self.y = 70
self.z = 100
self.visible = true
self.opacity = 255
@cp = val
@ori = val
refresh
end
def update
super
refresh if @cp != @ori
end
def refresh
self.bitmap.clear
self.bitmap.fill_rect(10,0,10,200,Color.new(0,0,0,255))
h = ((@cp / 100.to_f) * 200).round
y = 200 - h
src_rect = Rect.new(10,y,10,h)
self.bitmap.fill_rect(src_rect,Color.new(255,200,0,255))
self.bitmap.font.color = Color.new(0,0,0,255)
self.bitmap.draw_text(1,200,30,32,@cp.to_s,1)
self.bitmap.draw_text(-1,200,30,32,@cp.to_s,1)
self.bitmap.draw_text(0,201,30,32,@cp.to_s,1)
self.bitmap.draw_text(0,199,30,32,@cp.to_s,1)
self.bitmap.font.color = Color.new(255,255,255,255)
self.bitmap.draw_text(0,200,30,32,@cp.to_s,1)
@ori = @cp
end
end
#=========================================================================
module RPG
class Item
def cp_cost
return @description.split(/@/)[1] == nil ? 5 : @description.split(/@/)[1].to_i
end
def description
return @description.split(/@/)[0] + ($懒人模式 == true ? "消耗#{$CP名}#{cp_cost}。" : "")
end
end
end
module RPG
class Skill
def cp_cost
return @description.split(/@/)[1] == nil ? 5 : @description.split(/@/)[1].to_i
end
def description
return @description.split(/@/)[0] + ($懒人模式 == true ? "消耗#{$CP名}#{cp_cost}。" : "")
end
end
end
class Game_Enemy
attr_accessor :at
alias lovelyiselia :initialize
def initialize(troop_id, member_index)
lovelyiselia(troop_id, member_index)
@at = 0
end
def make_action
# 清除当前行动
self.current_action.clear
# 无法行动的情况
unless self.movable?
# 过程结束
return
end
# 抽取现在有效的行动
available_actions = []
rating_max = 0
for action in self.actions
# 确认回合条件
n = $game_temp.battle_turn
a = action.condition_turn_a
b = action.condition_turn_b
if (b == 0 and n != a) or
(b > 0 and (n < 1 or n < a or n % b != a % b))
next
end
# 确认 HP 条件
if self.hp * 100.0 / self.maxhp > action.condition_hp
next
end
# 确认等级条件
if $game_party.max_level < action.condition_level
next
end
# 确认开关条件
switch_id = action.condition_switch_id
if switch_id > 0 and $game_switches[switch_id] == false
next
end
#============================================小雪
#确认SP条件
if self.sp < $data_skills[action.skill_id].sp_cost
next
end
#============================================小雪
# 符合条件 : 添加本行动
available_actions.push(action)
if action.rating > rating_max
rating_max = action.rating
end
end
# 最大概率值作为 3 合计计算(0 除外)
ratings_total = 0
for action in available_actions
if action.rating > rating_max - 3
ratings_total += action.rating - (rating_max - 3)
end
end
# 概率合计不为 0 的情况下
if ratings_total > 0
# 生成随机数
value = rand(ratings_total)
# 设置对应生成随机数的当前行动
for action in available_actions
if action.rating > rating_max - 3
if value < action.rating - (rating_max - 3)
self.current_action.kind = action.kind
self.current_action.basic = action.basic
self.current_action.skill_id = action.skill_id
self.current_action.decide_random_target_for_enemy
return
else
value -= action.rating - (rating_max - 3)
end
end
end
end
end
end
class Game_Party
alias item_can_use_vp? :item_can_use?
def item_can_use?(item_id)
return false if $scene.is_a?(Scene_Battle) && $data_items[item_id].cp_cost > $scene.cp
item_can_use_vp?(item_id)
end
end
class Game_Battler
alias skill_can_use_vp? :skill_can_use?
def skill_can_use?(skill_id)
return false if $scene.is_a?(Scene_Battle) && self.is_a?(Game_Actor) && $data_skills[skill_id].cp_cost > $scene.cp
skill_can_use_vp?(skill_id)
end
end
class Scene_Battle
attr_accessor :cp
def fullat_se
Audio.se_play("Audio/SE/033-switch02", 80, 100)
end
alias main_vp :main
def main
@cp_re = 0
@troop_id = $game_temp.battle_troop_id
$game_troop.setup(@troop_id)
s = 0
w = 0
($game_troop.enemies).each {|v| s += v.agi}
s /= $game_troop.enemies.size
($game_party.actors).each {|v| w += v.agi}
w /= $game_party.actors.size
@cpadd = ((w/s.to_f - 1)* 10).round
@cp = [[@cpadd + $基本CP,0].max,100].min
@cp_meter = CP.new(@cp)
@lovelyiselia = false
#敌人速度照抄RTAB算法50%- -bbb
($game_troop.enemies).each {|v| v.at = 0}
@max = 0
($game_troop.enemies+$game_party.actors).each {|v| @max += v.agi}
@max *= $敌人行动速度
@max / ($game_troop.enemies.size + $game_party.actors.size)
@turn = 0
@turn_cut = 0
($game_troop.enemies+$game_party.actors).each {|v| @turn += v.agi}
@turn / ($game_troop.enemies.size + $game_party.actors.size)
@en = false
main_vp
@cp_meter.dispose
end
def turn_action
@turn_cut += @turn
if @turn_cut >= (@max * $回合进行速度)
@turn_cut = 0
$game_temp.battle_turn += 1
for index in 0...$data_troops[@troop_id].pages.size
# 获取事件页
page = $data_troops[@troop_id].pages[index]
# 本页的范围是 [回合] 的情况下
if page.span == 1
# 设置已经执行标志
$game_temp.battle_event_flags[index] = false
end
end
# 强制行动的战斗者不存在的情况下
if $game_temp.forcing_battler == nil
# 设置战斗事件
setup_battle_event
# 执行战斗事件中的情况下
if $game_system.battle_interpreter.running?
return
end
end
end
end
def enemy_action
for v in $game_troop.enemies
if v.exist?
v.at += v.agi
if v.at >= @max
$game_temp.battle_turn = 1 if $game_temp.battle_turn == 0
v.at = 0
v.make_action
@active_battler = v
@action_battlers = Array(@active_battler)
return if @active_battler.current_action.kind == 0 and @active_battler.current_action.basic == 3
start_phase4
return
end
end
end
end
def update_lovelyiselia
turn_action
enemy_action
#敌人行动处理
@cp_re += 1
if @cp_re % ([[$CP恢复速度,2].max,20].min) == 0
@cp = [@cp += 1,100].min
fullat_se if @cp == 100 && @cp_meter.cp != 100
@cp_meter.cp = @cp
@cp_re = 0
end
@cp_meter.update
if Input.trigger?(Input::B) && $game_party.inputable?
@party_command_window.refresh
$game_system.se_play($data_system.cancel_se)
@lovelyiselia = false
start_phase2
end
if Input.trigger?(Input::C) && $game_party.inputable?
$game_system.se_play($data_system.decision_se)
@actor_command_window.active = true
@actor_command_window.visible = true
@lovelyiselia = false
@en = true
start_phase3
return
end
end
end
class Window_PartyCommand < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 160
@commands = ["战斗", "逃跑"]
@item_max = 2
@column_max = 2
draw_item(0, normal_color)
#====================================小雪
draw_item(1, ($game_temp.battle_can_escape && $scene.cp >= $逃跑CP消耗)? normal_color : disabled_color)
#====================================小雪
self.active = false
self.visible = false
self.index = 0
#====================================小雪
def refresh
self.contents.clear
draw_item(0, normal_color)
#====================================小雪
draw_item(1, ($game_temp.battle_can_escape && $scene.cp >= $逃跑CP消耗)? normal_color : disabled_color)
#====================================小雪
end
end
end
class Scene_Battle
def clear_action
($game_party.actors+$game_troop.enemies).each do |v|
v.current_action.clear
end
@action_battlers.clear
end
def update_phase2
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 同伴指令窗口光标位置分支
case @party_command_window.index
when 0 # 战斗
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 开始角色的命令回合
start_phase3
when 1 # 逃跑
# 不能逃跑的情况下
#========================================小雪
if $game_temp.battle_can_escape == false or $逃跑CP消耗 > @cp
#========================================小雪
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
@cp -= $逃跑CP消耗
@cp_meter.cp = @cp
@cp_meter.update
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 逃走处理
update_phase2_escape
end
return
end
end
def update_phase2_escape
# 计算敌人速度的平均值
enemies_agi = 0
enemies_number = 0
for enemy in $game_troop.enemies
if enemy.exist?
enemies_agi += enemy.agi
enemies_number += 1
end
end
if enemies_number > 0
enemies_agi /= enemies_number
end
# 计算角色速度的平均值
actors_agi = 0
actors_number = 0
for actor in $game_party.actors
if actor.exist?
actors_agi += actor.agi
actors_number += 1
end
end
if actors_number > 0
actors_agi /= actors_number
end
# 逃跑成功判定
success = rand(100) < 50 * actors_agi / enemies_agi
# 成功逃跑的情况下
if success
# 演奏逃跑 SE
$game_system.se_play($data_system.escape_se)
# 还原为战斗开始前的 BGM
$game_system.bgm_play($game_temp.map_bgm)
# 战斗结束
battle_end(1)
# 逃跑失败的情况下
else
#================================小雪
@party_command_window.refresh
#================================小雪
# 清除全体同伴的行动
$game_party.clear_actions
# 开始主回合
#================================小雪
#start_phase2
#================================小雪
end
end
def start_phase3
# 转移到回合 3
@phase = 3
# 设置角色为非选择状态
#=================================小雪
@actor_index == -1 ? @actor_index = -1 : @actor_index -= 1
#=================================小雪
@active_battler = nil
# 输入下一个角色的命令
phase3_next_actor
end
alias update_phase3_vp :update_phase3
def update_phase3
#========================小雪
if @lovelyiselia == true
update_lovelyiselia
end
update_phase3_vp
#========================小雪
end
def phase3_next_actor
#===============================小雪
return if judge
return if @lovelyiselia == true
if @active_battler != nil && @active_battler.inputable?
($game_party.actors+$game_troop.enemies).each do |v|
if v != @active_battler
v.current_action.kind = 0
v.current_action.basic = 3
end
@action_battlers = Array(@active_battler)
# 有效化同伴指令窗口
@party_command_window.active = false
@party_command_window.visible = false
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
start_phase4
return
end
end
@actor_command_window.refresh
if @cp < $物理攻击CP消耗
@actor_command_window.disable_item(0)
end
if @cp < $防御CP消耗
@actor_command_window.disable_item(2)
end
#===============================小雪
# 循环
begin
# 角色的明灭效果 OFF
if @active_battler != nil
@active_battler.blink = false
end
# 推进角色索引
@actor_index += 1
#============================小雪
@actor_index %= $game_party.actors.size
($game_party.actors+$game_troop.enemies).each{|v|v.blink = false}
#============================小雪
@active_battler = $game_party.actors[@actor_index]
@active_battler.blink = true
# 如果角色是在无法接受指令的状态就再试
end until @active_battler.inputable?
# 设置角色的命令窗口
#============================小雪
phase3_setup_command_window if @lovelyiselia == false
#============================小雪
end
def update_phase3_basic_command
#=====================================小雪
#向前
if Input.trigger?(Input: EFT) && @lovelyiselia == false
@active_battler = nil
phase3_prior_actor
end
#向后
if Input.trigger?(Input::RIGHT) && @lovelyiselia == false
@active_battler = nil
phase3_next_actor
end
#进入敌人行动
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
($game_party.actors+$game_troop.enemies).each{|v|v.blink = false}
@actor_command_window.active = false
@actor_command_window.visible = false
@lovelyiselia = true
end
#=====================================小雪
# 按下 C 键的情况下
if Input.trigger?(Input::C) && @en == true
@en = false
return
end
if Input.trigger?(Input::C) && @lovelyiselia == false && @en == false
# 角色指令窗口光标位置分之
case @actor_command_window.index
when 0 # 攻击
#=========================小雪
if @cp < $物理攻击CP消耗
$game_system.se_play($data_system.buzzer_se)
return
end
#=========================小雪
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置行动
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
# 开始选择敌人
start_enemy_select
when 1 # 特技
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置行动
@active_battler.current_action.kind = 1
# 开始选择特技
start_skill_select
when 2 # 防御
#=========================小雪
if @cp < $防御CP消耗
$game_system.se_play($data_system.buzzer_se)
return
end
#=========================小雪
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置行动
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 1
# 转向下一位角色的指令输入
phase3_next_actor
when 3 # 物品
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置行动
@active_battler.current_action.kind = 2
# 开始选择物品
start_item_select
end
return
end
end
#--------------------------------------------------------------------------
# ● 转向前一个角色的命令输入
#--------------------------------------------------------------------------
def phase3_prior_actor
# 循环
begin
# 角色的明灭效果 OFF
if @active_battler != nil
@active_battler.blink = false
end
# 返回角色索引
@actor_index -= 1
#=======================小雪
@actor_index %= $game_party.actors.size
($game_party.actors+$game_troop.enemies).each{|v|v.blink = false}
@actor_command_window.refresh
if @cp < $物理攻击CP消耗
@actor_command_window.disable_item(0)
end
if @cp < $防御CP消耗
@actor_command_window.disable_item(2)
end
#=======================小雪
@active_battler = $game_party.actors[@actor_index]
@active_battler.blink = true
# 如果角色是在无法接受指令的状态就再试
end until @active_battler.inputable?
# 设置角色的命令窗口
phase3_setup_command_window
end
#--------------------------------------------------------------------------
# ● 开始主回合
#--------------------------------------------------------------------------
def start_phase4
#===============================小雪
unless $game_party.inputable?
@lovelyiselia = true
start_phase3
end
#===============================小雪
#清除闪烁
($game_party.actors+$game_troop.enemies).each{|v|v.blink = false}
# 转移到回合 4
@phase = 4
# 有效化同伴指令窗口
@party_command_window.active = false
@party_command_window.visible = false
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
# 设置主回合标志
$game_temp.battle_main_phase = true
# 移动到步骤 1
@phase4_step = 1
end
alias update_phase4_step5_vp :update_phase4_step5
def update_phase4_step5
@damage_size = 0
@target_battlers.each {|v| @damage_size += 1 if ![0,"Miss",nil].include?(v.damage)}
update_phase4_step5_vp
end
alias update_phase4_step6_vp :update_phase4_step6
def update_phase4_step6
#===================小雪
if @active_battler != nil && @active_battler.is_a?(Game_Actor)
case @active_battler.current_action.kind
when 0
@cp -= $物理攻击CP消耗 if @active_battler.current_action.basic == 0
@cp -= $防御CP消耗 if @active_battler.current_action.basic == 1
when 1
@cp -= $data_skills[@active_battler.current_action.skill_id].cp_cost
when 2
@cp -= $data_items[@active_battler.current_action.item_id].cp_cost
end
@cp = [@cp,0].max
@cp_meter.cp = @cp
@cp_meter.update
end
if @active_battler.is_a?(Game_Enemy) and not ((@active_battler.current_action.kind == 1 && $data_skills[@active_battler.current_action.skill_id].scope > 2))
@cp = [[@cp + $被攻CP回复 * @damage_size,0].max,100].min
@cp_meter.cp = @cp
@cp_meter.update
end
clear_action
#===================小雪
update_phase4_step6_vp
start_phase3
end
#--------------------------------------------------------------------------
# ● 刷新画面 (主回合步骤 1 : 准备行动)
#--------------------------------------------------------------------------
def update_phase4_step1
# 隐藏帮助窗口
@help_window.visible = false
# 判定胜败
if judge
# 胜利或者失败的情况下 : 过程结束
return
end
#============================小雪
# if @action_battlers == nil
#@action_battlers = []
# return
# end
#============================小雪
# 强制行动的战斗者存在的情况下
if $game_temp.forcing_battler != nil
# 在头部添加后移动
@action_battlers.delete($game_temp.forcing_battler)
@action_battlers.unshift($game_temp.forcing_battler)
end
# 未行动的战斗者不存在的情况下 (全员已经行动)
if @action_battlers == nil
# 开始同伴命令回合
start_phase3
return
end
# 初始化动画 ID 和公共事件 ID
@animation1_id = 0
@animation2_id = 0
@common_event_id = 0
# 未行动的战斗者移动到序列的头部
#@active_battler = @action_battlers.shift
# 如果已经在战斗之外的情况下
if @active_battler != nil and @active_battler.index == nil
return
end
#=============================小雪
if @active_battler.current_action.kind == 0 and @active_battler.current_action.basic == 3
start_phase3
end
#=============================小雪
# 连续伤害
if @active_battler.hp > 0 and @active_battler.slip_damage?
@active_battler.slip_damage_effect
@active_battler.damage_pop = true
end
# 自然解除状态
@active_battler.remove_states_auto
# 刷新状态窗口
@status_window.refresh
# 移至步骤 2
@phase4_step = 2
end
#===================================================
#除BUG
#===================================================
def make_skill_action_result
# 获取特技
@skill = $data_skills[@active_battler.current_action.skill_id]
# 如果不是强制行动
unless @active_battler.current_action.forcing
# 因为 SP 耗尽而无法使用的情况下
unless @active_battler.skill_can_use?(@skill.id)
# 清除强制行动对像的战斗者
$game_temp.forcing_battler = nil
# 移至步骤 1
#======================================小雪
@active_battler.current_action.clear
start_phase3
#======================================小雪
#@phase4_step = 1
return
end
end
# 消耗 SP
@active_battler.sp -= @skill.sp_cost
# 刷新状态窗口
@status_window.refresh
# 在帮助窗口显示特技名
@help_window.set_text(@skill.name, 1)
# 设置动画 ID
@animation1_id = @skill.animation1_id
@animation2_id = @skill.animation2_id
# 设置公共事件 ID
@common_event_id = @skill.common_event_id
# 设置对像侧战斗者
set_target_battlers(@skill.scope)
# 应用特技效果
for target in @target_battlers
target.skill_effect(@active_battler, @skill)
end
end
def make_item_action_result
# 获取物品
@item = $data_items[@active_battler.current_action.item_id]
# 因为物品耗尽而无法使用的情况下
unless $game_party.item_can_use?(@item.id)
# 移至步骤 1
#@phase4_step = 1
#==================================================小雪
@active_battler.current_action.clear
start_phase3
#==================================================小雪
return
end
# 消耗品的情况下
if @item.consumable
# 使用的物品减 1
$game_party.lose_item(@item.id, 1)
end
# 在帮助窗口显示物品名
@help_window.set_text(@item.name, 1)
# 设置动画 ID
@animation1_id = @item.animation1_id
@animation2_id = @item.animation2_id
# 设置公共事件 ID
@common_event_id = @item.common_event_id
# 确定对像
index = @active_battler.current_action.target_index
target = $game_party.smooth_target_actor(index)
# 设置对像侧战斗者
set_target_battlers(@item.scope)
# 应用物品效果
for target in @target_battlers
target.item_effect(@item)
end
end
#====================================================
#除BUG
#====================================================
end |
|