Project1
标题: 如何在CP战斗脚本里添加一个新的类Game_Pet ? [打印本页]
作者: 幻耶 时间: 2011-8-26 12:51
标题: 如何在CP战斗脚本里添加一个新的类Game_Pet ?
柳柳的宠物脚本就是那个是把宠物装备在角色身上的,可能由于把宠物定义为一个新的类Game_Pet,所以与CP战斗冲突,宠物装备后在战斗中没有任何反应,我想应该要在CP制御脚本中相应地添加关于宠物的类,请教具体应该怎么写?
宠物脚本- class Game_BattleAction
- #--------------------------------------------------------------------------
- # ● 随机目标 (敌人用)
- #--------------------------------------------------------------------------
- def decide_random_target_for_pet
- # 效果范围的分支
- if for_one_friend_hp0?
- battler = $game_party.random_target_actor_hp0
- elsif for_one_friend?
- battler = $game_party.random_target_actor
- else
- battler = $game_troop.random_target_enemy
- end
- # 对像存在的话取得索引、
- # 对像不存在的场合下清除行动
- if battler != nil
- @target_index = battler.index
- else
- clear
- end
- end
- end
- #==============================================================================
- # ■ Game_Actor
- #------------------------------------------------------------------------------
- # 处理角色的类。本类在 Game_Actors 类 ($game_actors)
- # 的内部使用、Game_Party 类请参考 ($game_party) 。
- #==============================================================================
- class Game_Actor < Game_Battler
- attr_accessor :pet_id # 宠物的敌人ID号
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # actor_id : 角色 ID
- #--------------------------------------------------------------------------
- def initialize(actor_id)
- super()
- #########################################################################
- @pet_id = 0
- #########################################################################
- setup(actor_id)
- end
- end
- #==============================================================================
- # ■ Game_Pet
- #------------------------------------------------------------------------------
- # 处理宠物的类,专用。
- #==============================================================================
- class Game_Pet < Game_Battler
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # troop_id : 循环 ID
- # member_index : 循环成员的索引
- #--------------------------------------------------------------------------
- def initialize(enemy_id)
- super()
- @enemy_id = enemy_id
- enemy = $data_enemies[@enemy_id]
- @battler_name = enemy.battler_name
- @battler_hue = enemy.battler_hue
- @hp = maxhp
- @sp = maxsp
- end
- #--------------------------------------------------------------------------
- # ● 获取敌人 ID
- #--------------------------------------------------------------------------
- def id
- return @enemy_id
- end
- #--------------------------------------------------------------------------
- # ● 获取索引
- #--------------------------------------------------------------------------
- def index
- return @member_index
- end
- #--------------------------------------------------------------------------
- # ● 获取名称
- #--------------------------------------------------------------------------
- def name
- return $data_enemies[@enemy_id].name
- end
- #--------------------------------------------------------------------------
- # ● 获取基本 MaxHP
- #--------------------------------------------------------------------------
- def base_maxhp
- return $data_enemies[@enemy_id].maxhp
- end
- #--------------------------------------------------------------------------
- # ● 获取基本 MaxSP
- #--------------------------------------------------------------------------
- def base_maxsp
- return $data_enemies[@enemy_id].maxsp
- end
- #--------------------------------------------------------------------------
- # ● 获取基本力量
- #--------------------------------------------------------------------------
- def base_str
- return $data_enemies[@enemy_id].str
- end
- #--------------------------------------------------------------------------
- # ● 获取基本灵巧
- #--------------------------------------------------------------------------
- def base_dex
- return $data_enemies[@enemy_id].dex
- end
- #--------------------------------------------------------------------------
- # ● 获取基本速度
- #--------------------------------------------------------------------------
- def base_agi
- return $data_enemies[@enemy_id].agi
- end
- #--------------------------------------------------------------------------
- # ● 获取基本魔力
- #--------------------------------------------------------------------------
- def base_int
- return $data_enemies[@enemy_id].int
- end
- #--------------------------------------------------------------------------
- # ● 获取基本攻击力
- #--------------------------------------------------------------------------
- def base_atk
- return $data_enemies[@enemy_id].atk
- end
- #--------------------------------------------------------------------------
- # ● 获取基本物理防御
- #--------------------------------------------------------------------------
- def base_pdef
- return $data_enemies[@enemy_id].pdef
- end
- #--------------------------------------------------------------------------
- # ● 获取基本魔法防御
- #--------------------------------------------------------------------------
- def base_mdef
- return $data_enemies[@enemy_id].mdef
- end
- #--------------------------------------------------------------------------
- # ● 获取基本回避修正
- #--------------------------------------------------------------------------
- def base_eva
- return $data_enemies[@enemy_id].eva
- end
- #--------------------------------------------------------------------------
- # ● 普通攻击 获取攻击方动画 ID
- #--------------------------------------------------------------------------
- def animation1_id
- return $data_enemies[@enemy_id].animation1_id
- end
- #--------------------------------------------------------------------------
- # ● 普通攻击 获取对像方动画 ID
- #--------------------------------------------------------------------------
- def animation2_id
- return $data_enemies[@enemy_id].animation2_id
- end
- #--------------------------------------------------------------------------
- # ● 获取属性修正值
- # element_id : 属性 ID
- #--------------------------------------------------------------------------
- def element_rate(element_id)
- # 获取对应属性有效度的数值
- table = [0,200,150,100,50,0,-100]
- result = table[$data_enemies[@enemy_id].element_ranks[element_id]]
- # 状态能防御本属性的情况下效果减半
- for i in @states
- if $data_states[i].guard_element_set.include?(element_id)
- result /= 2
- end
- end
- # 过程结束
- return result
- end
- #--------------------------------------------------------------------------
- # ● 获取属性有效度
- #--------------------------------------------------------------------------
- def state_ranks
- return $data_enemies[@enemy_id].state_ranks
- end
- #--------------------------------------------------------------------------
- # ● 属性防御判定
- # state_id : 状态 ID
- #--------------------------------------------------------------------------
- def state_guard?(state_id)
- return false
- end
- #--------------------------------------------------------------------------
- # ● 获取普通攻击属性
- #--------------------------------------------------------------------------
- def element_set
- return []
- end
- #--------------------------------------------------------------------------
- # ● 获取普通攻击的状态变化 (+)
- #--------------------------------------------------------------------------
- def plus_state_set
- return []
- end
- #--------------------------------------------------------------------------
- # ● 获取普通攻击的状态变化 (-)
- #--------------------------------------------------------------------------
- def minus_state_set
- return []
- end
- #--------------------------------------------------------------------------
- # ● 获取行动
- #--------------------------------------------------------------------------
- def actions
- return $data_enemies[@enemy_id].actions
- end
- #--------------------------------------------------------------------------
- # ● 获取 EXP
- #--------------------------------------------------------------------------
- def exp
- return $data_enemies[@enemy_id].exp
- end
- #--------------------------------------------------------------------------
- # ● 获取金钱
- #--------------------------------------------------------------------------
- def gold
- return $data_enemies[@enemy_id].gold
- end
- #--------------------------------------------------------------------------
- # ● 获取物品 ID
- #--------------------------------------------------------------------------
- def item_id
- return $data_enemies[@enemy_id].item_id
- end
- #--------------------------------------------------------------------------
- # ● 获取武器 ID
- #--------------------------------------------------------------------------
- def weapon_id
- return $data_enemies[@enemy_id].weapon_id
- end
- #--------------------------------------------------------------------------
- # ● 获取放具 ID
- #--------------------------------------------------------------------------
- def armor_id
- return $data_enemies[@enemy_id].armor_id
- end
- #--------------------------------------------------------------------------
- # ● 获取宝物出现率
- #--------------------------------------------------------------------------
- def treasure_prob
- return $data_enemies[@enemy_id].treasure_prob
- end
- #--------------------------------------------------------------------------
- # ● 逃跑
- #--------------------------------------------------------------------------
- def escape
- # 设置击中标志
- @hidden = true
- # 清除当前行动
- self.current_action.clear
- end
- #--------------------------------------------------------------------------
- # ● 变身
- # enemy_id : 变身为的敌人 ID
- #--------------------------------------------------------------------------
- def transform(enemy_id)
- # 更改敌人 ID
- @enemy_id = enemy_id
- # 更改战斗图形
- @battler_name = $data_enemies[@enemy_id].battler_name
- @battler_hue = $data_enemies[@enemy_id].battler_hue
- # 在生成行动
- make_action
- 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
- # 符合条件 : 添加本行动
- 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_pet
- return
- else
- value -= action.rating - (rating_max - 3)
- end
- end
- end
- end
- end
- end
- #==============================================================================
- # ■ Sprite_Pet
- #——————————————————————————————————————
- # 全新定义
- #==============================================================================
- class Sprite_Pet < RPG::Sprite
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :battler # 战斗者
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # viewport : 显示端口;battler : 战斗者 (Game_Battler)
- #--------------------------------------------------------------------------
- def initialize(viewport, father_id = 0)
- super(viewport)
- @father_id = father_id
- if $game_party.actors[father_id] != nil
- if $game_party.actors[father_id].pet_id != 0
- @battler = Game_Pet.new($game_party.actors[father_id].pet_id)
- else
- @battler = nil
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- if self.bitmap != nil
- self.bitmap.dispose
- end
- super
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- super
- # 战斗者为 nil 的情况下
- if @battler == nil
- self.bitmap = nil
- loop_animation(nil)
- return
- end
- if self.battler != nil
- self.bitmap = RPG::Cache.battler(@battler.battler_name, @battler.battler_hue)
- if @battler.animation_id != 0
- animation = $data_animations[@battler.animation_id]
- animation(animation, @battler.animation_hit)
- @battler.animation_id = 0
- end
- if $game_party.actors[@father_id].pet_id == 0
- self.battler = nil
- collapse
- end
- end
- # 设置活动块的坐标
- self.x = @father_id * 160 + 85
- self.y = 400
- self.z = 5
- self.zoom_x = 0.6
- self.zoom_y = 0.6
- end
- end
- #==============================================================================
- # ■ Spriteset_Battle
- #------------------------------------------------------------------------------
- # 处理战斗画面的活动块的类。本类在 Scene_Battle 类
- # 的内部使用。
- #==============================================================================
- class Spriteset_Battle
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :viewport1 # 敌人方的显示端口
- attr_reader :viewport2 # 角色方的显示端口
- #--------------------------------------------------------------------------
- # ● 初始化变量
- #--------------------------------------------------------------------------
- def initialize
- # 生成显示端口
- @viewport1 = Viewport.new(0, 0, 640, 320)
- @viewport2 = Viewport.new(0, 0, 640, 480)
- @viewport3 = Viewport.new(0, 0, 640, 480)
- @viewport4 = Viewport.new(0, 0, 640, 480)
- @viewport2.z = 101
- @viewport3.z = 200
- @viewport4.z = 5000
- # 生成战斗背景活动块
- @battleback_sprite = Sprite.new(@viewport1)
- # 生成敌人活动块
- @enemy_sprites = []
- for enemy in $game_troop.enemies.reverse
- @enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))
- end
- # 生成自己人活动块
- @actor_sprites = []
- @actor_sprites.push(Sprite_Battler.new(@viewport2))
- @actor_sprites.push(Sprite_Battler.new(@viewport2))
- @actor_sprites.push(Sprite_Battler.new(@viewport2))
- @actor_sprites.push(Sprite_Battler.new(@viewport2))
- ###########################################################################
- $pet_sprites = []
- $pet_sprites.push(Sprite_Pet.new(@viewport2,0))
- $pet_sprites.push(Sprite_Pet.new(@viewport2,1))
- $pet_sprites.push(Sprite_Pet.new(@viewport2,2))
- $pet_sprites.push(Sprite_Pet.new(@viewport2,3))
- ###########################################################################
- # 生成天候
- @weather = RPG::Weather.new(@viewport1)
- # 生成图片活动块
- @picture_sprites = []
- for i in 51..100
- @picture_sprites.push(Sprite_Picture.new(@viewport3,
- $game_screen.pictures[i]))
- end
- # 生成计时器块
- @timer_sprite = Sprite_Timer.new
- # 刷新画面
- update
- end
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- # 如果战斗背景位图存在的情况下就释放
- if @battleback_sprite.bitmap != nil
- @battleback_sprite.bitmap.dispose
- end
- # 释放战斗背景活动块
- @battleback_sprite.dispose
- # 释放敌人活动块、角色活动块
- ###########################################################################
- for sprite in @enemy_sprites + @actor_sprites + $pet_sprites
- sprite.dispose
- end
- ###########################################################################
- # 释放天候
- @weather.dispose
- # 释放图片活动块
- for sprite in @picture_sprites
- sprite.dispose
- end
- # 释放计时器活动块
- @timer_sprite.dispose
- # 释放显示端口
- @viewport1.dispose
- @viewport2.dispose
- @viewport3.dispose
- @viewport4.dispose
- end
- #--------------------------------------------------------------------------
- # ● 显示效果中判定
- #--------------------------------------------------------------------------
- def effect?
- # 如果是在显示效果中的话就返回 true
- for sprite in @enemy_sprites + @actor_sprites
- return true if sprite.effect?
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- # 刷新角色的活动块 (对应角色的替换)
- @actor_sprites[0].battler = $game_party.actors[0]
- @actor_sprites[1].battler = $game_party.actors[1]
- @actor_sprites[2].battler = $game_party.actors[2]
- @actor_sprites[3].battler = $game_party.actors[3]
- # 战斗背景的文件名与现在情况有差异的情况下
- if @battleback_name != $game_temp.battleback_name
- @battleback_name = $game_temp.battleback_name
- if @battleback_sprite.bitmap != nil
- @battleback_sprite.bitmap.dispose
- end
- @battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name)
- @battleback_sprite.src_rect.set(0, 0, 640, 320)
- end
- # 刷新战斗者的活动块
- ###########################################################################
- for sprite in @enemy_sprites + @actor_sprites + $pet_sprites
- sprite.update
- end
- ###########################################################################
- # 刷新天气图形
- @weather.type = $game_screen.weather_type
- @weather.max = $game_screen.weather_max
- @weather.update
- # 刷新图片活动块
- for sprite in @picture_sprites
- sprite.update
- end
- # 刷新计时器活动块
- @timer_sprite.update
- # 设置画面的色调与震动位置
- @viewport1.tone = $game_screen.tone
- @viewport1.ox = $game_screen.shake
- # 设置画面的闪烁色
- @viewport4.color = $game_screen.flash_color
- # 刷新显示端口
- @viewport1.update
- @viewport2.update
- @viewport4.update
- end
- end
- #==============================================================================
- # ■ Window_Base
- #------------------------------------------------------------------------------
- # 游戏中全部窗口的超级类。
- #==============================================================================
- class Window_Base < Window
- #############################################################################
- def draw_actor_pet(actor, x, y)#——绘制宠物图形
- if actor.pet_id != 0
- bitmap = RPG::Cache.battler($data_enemies[actor.pet_id].battler_name, $data_enemies[actor.pet_id].battler_hue)
- cw = bitmap.width
- ch = bitmap.height
- src_rect = Rect.new(0, 0, cw, ch)
- self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
- end
- end
- #############################################################################
- end
-
- #==============================================================================
- # ■ Window_Status
- #------------------------------------------------------------------------------
- # 显示状态画面、完全规格的状态窗口。
- #==============================================================================
- class Window_Status < Window_Base
- alias carol3_refresh refresh
- def refresh
- carol3_refresh
- draw_actor_pet(@actor, 40, 250)
- end
- end
-
-
- class Scene_Battle
- #--------------------------------------------------------------------------
- # ● 主处理
- #--------------------------------------------------------------------------
- def main
- # 初始化战斗用的各种暂时数据
- $game_temp.in_battle = true
- $game_temp.battle_turn = 0
- $game_temp.battle_event_flags.clear
- $game_temp.battle_abort = false
- $game_temp.battle_main_phase = false
- $game_temp.battleback_name = $game_map.battleback_name
- $game_temp.forcing_battler = nil
- # 初始化战斗用事件解释器
- $game_system.battle_interpreter.setup(nil, 0)
- # 准备队伍
- @troop_id = $game_temp.battle_troop_id
- $game_troop.setup(@troop_id)
- # 生成角色命令窗口
- s1 = $data_system.words.attack
- s2 = $data_system.words.skill
- s3 = $data_system.words.guard
- s4 = $data_system.words.item
- @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
- @actor_command_window.y = 160
- @actor_command_window.back_opacity = 160
- @actor_command_window.active = false
- @actor_command_window.visible = false
- # 生成其它窗口
- @party_command_window = Window_PartyCommand.new
- @help_window = Window_Help.new
- @help_window.back_opacity = 160
- @help_window.visible = false
- @status_window = Window_BattleStatus.new
- @message_window = Window_Message.new
- # 生成活动块
- @spriteset = Spriteset_Battle.new
- ############################################################################
- @pet_actor = []
- for i in 0..3
- if $pet_sprites[i].battler != nil
- @pet_actor.push($pet_sprites[i].battler)
- end
- end
- ############################################################################
- # 初始化等待计数
- @wait_count = 0
- # 执行过渡
- if $data_system.battle_transition == ""
- Graphics.transition(20)
- else
- Graphics.transition(40, "Graphics/Transitions/" +
- $data_system.battle_transition)
- end
- # 开始自由战斗回合
- start_phase1
- # 主循环
- loop do
- # 刷新游戏画面
- Graphics.update
- # 刷新输入信息
- Input.update
- # 刷新画面
- update
- # 如果画面切换的话就中断循环
- if $scene != self
- break
- end
- end
- # 刷新地图
- $game_map.refresh
- # 准备过渡
- Graphics.freeze
- # 释放窗口
- @actor_command_window.dispose
- @party_command_window.dispose
- @help_window.dispose
- @status_window.dispose
- @message_window.dispose
- if @skill_window != nil
- @skill_window.dispose
- end
- if @item_window != nil
- @item_window.dispose
- end
- if @result_window != nil
- @result_window.dispose
- end
- # 释放活动块
- @spriteset.dispose
- # 标题画面切换中的情况
- if $scene.is_a?(Scene_Title)
- # 淡入淡出画面
- Graphics.transition
- Graphics.freeze
- end
- # 战斗测试或者游戏结束以外的画面切换中的情况
- if $BTEST and not $scene.is_a?(Scene_Gameover)
- $scene = nil
- end
- end
- def start_phase4
- # 转移到回合 4
- @phase = 4
- # 回合数计数
- $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
- # 设置角色为非选择状态
- @actor_index = -1
- @active_battler = nil
- # 无效化同伴指令窗口
- @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
- # 生成敌人行动
- for enemy in $game_troop.enemies
- enemy.make_action
- end
- ############################################################################
- for enemy in @pet_actor
- enemy.make_action
- enemy.current_action.decide_random_target_for_pet
- end
- ############################################################################
- # 生成行动顺序
- make_action_orders
- # 移动到步骤 1
- @phase4_step = 1
- end
-
- #--------------------------------------------------------------------------
- # ● 生成行动循序
- #--------------------------------------------------------------------------
- def make_action_orders
- # 初始化序列 @action_battlers
- @action_battlers = []
- # 添加敌人到 @action_battlers 序列
- for enemy in $game_troop.enemies
- @action_battlers.push(enemy)
- end
- ############################################################################
- for enemy in @pet_actor
- @action_battlers.push(enemy)
- end
- ############################################################################
- # 添加角色到 @action_battlers 序列
- for actor in $game_party.actors
- @action_battlers.push(actor)
- end
- # 确定全体的行动速度
- for battler in @action_battlers
- battler.make_action_speed
- end
- # 按照行动速度从大到小排列
- @action_battlers.sort! {|a,b|
- b.current_action.speed - a.current_action.speed }
- end
-
- #--------------------------------------------------------------------------
- # ● 刷新画面 (主回合步骤 1 : 准备行动)
- #--------------------------------------------------------------------------
- def update_phase4_step1
- # 隐藏帮助窗口
- @help_window.visible = false
- # 判定胜败
- if judge
- # 胜利或者失败的情况下 : 过程结束
- return
- end
- # 强制行动的战斗者不存在的情况下
- if $game_temp.forcing_battler == nil
- # 设置战斗事件
- setup_battle_event
- # 执行战斗事件中的情况下
- if $game_system.battle_interpreter.running?
- return
- end
- 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.size == 0
- # 开始同伴命令回合
- start_phase2
- return
- end
- # 初始化动画 ID 和公共事件 ID
- @animation1_id = 0
- @animation2_id = 0
- @common_event_id = 0
- # 未行动的战斗者移动到序列的头部
- @active_battler = @action_battlers.shift
- ###########################################################################
- if @active_battler.is_a?(Game_Pet)
- # 移至步骤 2
- @phase4_step = 2
- else
- # 如果已经在战斗之外的情况下
- if @active_battler.index == nil
- return
- 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
- ###########################################################################
- end
-
-
-
- #--------------------------------------------------------------------------
- # ● 生成基本行动结果
- #--------------------------------------------------------------------------
- def make_basic_action_result
- # 攻击的情况下
- if @active_battler.current_action.basic == 0
- # 设置攻击 ID
- @animation1_id = @active_battler.animation1_id
- @animation2_id = @active_battler.animation2_id
- # 行动方的战斗者是敌人的情况下
- if @active_battler.is_a?(Game_Actor) or @active_battler.is_a?(Game_Pet)
- if @active_battler.restriction == 3
- target = $game_party.random_target_actor
- elsif @active_battler.restriction == 2
- target = $game_troop.random_target_enemy
- else
- index = @active_battler.current_action.target_index
- target = $game_troop.smooth_target_enemy(index)
- end
- else
- if @active_battler.restriction == 3
- $game_variables[2]+=1
- target = $game_troop.random_target_enemy
- elsif @active_battler.restriction == 2
- target = $game_party.random_target_actor
- else
- index = @active_battler.current_action.target_index
- target = $game_party.smooth_target_actor(index)
- end
- end
- # 设置对像方的战斗者序列
- @target_battlers = [target]
- # 应用通常攻击效果
- for target in @target_battlers
- target.attack_effect(@active_battler)
- end
- return
- end
- # 防御的情况下
- if @active_battler.current_action.basic == 1
- # 帮助窗口显示"防御"
- @help_window.set_text($data_system.words.guard, 1)
- return
- end
- # 逃跑的情况下
- if @active_battler.is_a?(Game_Enemy) and
- @active_battler.current_action.basic == 2
- # 帮助窗口显示"逃跑"
- @help_window.set_text("逃跑", 1)
- # 逃跑
- @active_battler.escape
- return
- end
- # 什么也不做的情况下
- if @active_battler.current_action.basic == 3
- # 清除强制行动对像的战斗者
- $game_temp.forcing_battler = nil
- # 移至步骤 1
- @phase4_step = 1
- return
- end
- end
-
-
- #--------------------------------------------------------------------------
- # ● 设置物品或特技对像方的战斗者
- # scope : 特技或者是物品的范围
- #--------------------------------------------------------------------------
- def set_target_battlers(scope)
- # 行动方的战斗者是敌人的情况下
- if @active_battler.is_a?(Game_Enemy)
- # 效果范围分支
- case scope
- when 1 # 敌单体
- index = @active_battler.current_action.target_index
- @target_battlers.push($game_party.smooth_target_actor(index))
- when 2 # 敌全体
- for actor in $game_party.actors
- if actor.exist?
- @target_battlers.push(actor)
- end
- end
- when 3 # 我方单体
- index = @active_battler.current_action.target_index
- @target_battlers.push($game_troop.smooth_target_enemy(index))
- when 4 # 我方全体
- for enemy in $game_troop.enemies
- if enemy.exist?
- @target_battlers.push(enemy)
- end
- end
- when 5 # 我方单体 (HP 0)
- index = @active_battler.current_action.target_index
- enemy = $game_troop.enemies[index]
- if enemy != nil and enemy.hp0?
- @target_battlers.push(enemy)
- end
- when 6 # 我方全体 (HP 0)
- for enemy in $game_troop.enemies
- if enemy != nil and enemy.hp0?
- @target_battlers.push(enemy)
- end
- end
- when 7 # 使用者
- @target_battlers.push(@active_battler)
- end
- end
- # 行动方的战斗者是角色的情况下
- if @active_battler.is_a?(Game_Actor) or @active_battler.is_a?(Game_Pet)
- # 效果范围分支
- case scope
- when 1 # 敌单体
- index = @active_battler.current_action.target_index
- @target_battlers.push($game_troop.smooth_target_enemy(index))
- when 2 # 敌全体
- for enemy in $game_troop.enemies
- if enemy.exist?
- @target_battlers.push(enemy)
- end
- end
- when 3 # 我方单体
- index = @active_battler.current_action.target_index
- @target_battlers.push($game_party.smooth_target_actor(index))
- when 4 # 我方全体
- for actor in $game_party.actors
- if actor.exist?
- @target_battlers.push(actor)
- end
- end
- when 5 # 我方单体 (HP 0)
- index = @active_battler.current_action.target_index
- actor = $game_party.actors[index]
- if actor != nil and actor.hp0?
- @target_battlers.push(actor)
- end
- when 6 # 我方全体 (HP 0)
- for actor in $game_party.actors
- if actor != nil and actor.hp0?
- @target_battlers.push(actor)
- end
- end
- when 7 # 使用者
- @target_battlers.push(@active_battler)
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- class Sprite_Battler < RPG::Sprite
- def update
- super
- # 战斗者为 nil 的情况下
- if @battler == nil
- self.bitmap = nil
- loop_animation(nil)
- return
- end
- # 文件名和色相与当前情况有差异的情况下
- if @battler.battler_name != @battler_name or
- @battler.battler_hue != @battler_hue
- # 获取、设置位图
- @battler_name = @battler.battler_name
- @battler_hue = @battler.battler_hue
- self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
- @width = bitmap.width
- @height = bitmap.height
- self.ox = @width / 2
- self.oy = @height
- # 如果是战斗不能或者是隐藏状态就把透明度设置成 0
- if @battler.dead? or @battler.hidden
- self.opacity = 0
- end
- end
- # 动画 ID 与当前的情况有差异的情况下
- if @battler.damage == nil and
- @battler.state_animation_id != @state_animation_id
- @state_animation_id = @battler.state_animation_id
- loop_animation($data_animations[@state_animation_id])
- end
- # 应该被显示的角色的情况下
- if @battler.is_a?(Game_Actor) and @battler_visible
- # 不是主状态的时候稍稍降低点透明度
- if $game_temp.battle_main_phase
- self.opacity += 3 if self.opacity < 255
- else
- self.opacity -= 3 if self.opacity > 207
- end
- end
- # 明灭
- if @battler.blink
- blink_on
- else
- blink_off
- end
- # 不可见的情况下
- unless @battler_visible
- # 出现
- if not @battler.hidden and not @battler.dead? and
- (@battler.damage == nil or @battler.damage_pop)
- appear
- @battler_visible = true
- end
- end
- # 可见的情况下
- if @battler_visible
- # 逃跑
- if @battler.hidden
- $game_system.se_play($data_system.escape_se)
- escape
- @battler_visible = false
- end
- # 白色闪烁
- if @battler.white_flash
- whiten
- @battler.white_flash = false
- end
- # 动画
- if @battler.animation_id != 0
- animation = $data_animations[@battler.animation_id]
- animation(animation, @battler.animation_hit)
- @battler.animation_id = 0
- end
- # 伤害
- if @battler.damage_pop
- damage(@battler.damage, @battler.critical)
- @battler.damage = nil
- @battler.critical = false
- @battler.damage_pop = false
- end
- # korapusu
- if @battler.damage == nil and @battler.dead?
- if @battler.is_a?(Game_Enemy)
- $game_system.se_play($data_system.enemy_collapse_se)
- else
- @battler.pet_id = 0
- $game_system.se_play($data_system.actor_collapse_se)
- end
- collapse
- @battler_visible = false
- end
- end
- # 设置活动块的坐标
- self.x = @battler.screen_x
- self.y = @battler.screen_y
- self.z = @battler.screen_z
- end
- end
复制代码 CP制御脚本- module XRXS65
- #
- # 「バトルスピード」(数値が高いほど早い)
- #
- SPEED = 4.0
- #
- # 戦闘開始時 CP。 固定値と占有率
- #
- CP_PRESET_FIXNUM = 0
- CP_PRESET_RATIO = 2.0
- #
- # ターンコントローラ (nil : カウント/ターンを有効。
- # 数値 : そのインデックスをもつエネミーが支配)
- #
- TC = 0
- #
- # カウント/ターン (TCが有効な場合は無視)
- #
- CPT = 40
- #
- # CP スキン
- #
- SKIN = "123" # スキンファイル名(Graphics/Windowskinsフォルダ)
- LINE_HEIGHT = 6 # スキンの"一行"の縦幅[単位:ピクセル]
- #
- # 表示位置セッティング
- #
- X_OFFSET = 144 # 横位置
- Y_OFFSET = 464 # 縦位置
- ALIGN = 1 #「位置揃え」(CPメーターの位置。0:左寄せ 1:中央 2:右寄せ)
- MAX = 4 # 確保するサイズ[単位:~人分]
- #
- # アクターコマンドがポップしたときの効果音
- #
- COMMAND_UP_SE = "Audio/SE/046-Book01.ogg"
- end
- #==============================================================================
- # --- CP メーターの描画情報の取得 --- (Game_Battlerにインクルードされます)
- #==============================================================================
- module XRXS_CP
- #--------------------------------------------------------------------------
- # ○ スキンライン (スキンの何行目を使うか)
- #--------------------------------------------------------------------------
- def cp_linetype
- # CP フルの場合はスキンの 2 行目を使う
- return 2 if self.cp_full?
- # 通常はスキンの 1 行目を使う
- return 1
- end
- #--------------------------------------------------------------------------
- # ○ メーター量[単位:%]
- #--------------------------------------------------------------------------
- def cp_lineamount
- # 戦闘不能の場合は 0 %として表示させる
- return 0 if self.dead?
- # CP値を%値に変換して返却する
- return 100 * self.cp / self.max_cp
- end
- end
- #
- # カスタマイズポイントここまで。
- #------------------------------------------------------------------------------
- #==============================================================================
- # --- XRXS. CP機構 ---
- #==============================================================================
- module XRXS_CP_SYSTEM
- #----------------------------------------------------------------------------
- # ○ 合計 AGI の取得
- #----------------------------------------------------------------------------
- def self.total_agi
- total = 0
- for battler in $game_party.actors + $game_troop.enemies
- total += battler.agi
- end
- return total
- end
- end
- #==============================================================================
- # --- バトラーにCP機能を追加 モジュール ---
- #==============================================================================
- module XRXS_CP
- #--------------------------------------------------------------------------
- # ○ 最大 CP の取得
- #--------------------------------------------------------------------------
- def max_cp
- return 65535
- end
- #--------------------------------------------------------------------------
- # ○ CP の取得と設定
- #--------------------------------------------------------------------------
- def cp
- return @cp == nil ? @cp = 0 : @cp
- end
- def cp=(n)
- @cp = [[n.to_i, 0].max, self.max_cp].min
- end
- #--------------------------------------------------------------------------
- # ○ CP 初期設定
- #--------------------------------------------------------------------------
- def cp_preset
- percent = self.max_cp * XRXS65::CP_PRESET_RATIO * (rand(16) + 16) * self.agi / XRXS_CP_SYSTEM.total_agi / 24
- self.cp = XRXS65::CP_PRESET_FIXNUM + percent
- end
- #--------------------------------------------------------------------------
- # ○ CP カウントアップ
- #--------------------------------------------------------------------------
- def cp_update
- self.cp += XRXS65::SPEED * 4096 * self.agi / XRXS_CP_SYSTEM.total_agi
- end
- #--------------------------------------------------------------------------
- # ○ CP 満タン?
- #--------------------------------------------------------------------------
- def cp_full?
- return @cp == self.max_cp
- end
- end
- class Game_Battler
- include XRXS_CP
- end
- #==============================================================================
- # --- ガード機能 ---
- #==============================================================================
- class Game_Battler
- #--------------------------------------------------------------------------
- # ○ ガードフラグ
- #--------------------------------------------------------------------------
- def guarding=(n)
- @guarding = n
- end
- #--------------------------------------------------------------------------
- # ● 防御中判定 [再定義]
- #--------------------------------------------------------------------------
- def guarding?
- return @guarding
- end
- end
- #==============================================================================
- # --- アクター「コマンド入力可能判定」:CPがないとコマンドしない ---
- #==============================================================================
- module XRXS_CP_INPUTABLE
- def inputable?
- return (self.cp_full? and super)
- end
- end
- class Game_Actor < Game_Battler
- include XRXS_CP_INPUTABLE
- end
- #==============================================================================
- # --- エネミー「行動可能判定」:CPがないとコマンドしない ---
- #==============================================================================
- module XRXS_CP_MOVABLE
- def movable?
- return (self.cp_full? and super)
- end
- end
- class Game_Enemy < Game_Battler
- include XRXS_CP_MOVABLE
- end
- class Game_Pet < Game_Battler # XXOO
- include XRXS_CP_MOVABLE
- end
- #==============================================================================
- # --- 戦闘時 CPカウント ---
- #==============================================================================
- module XRXS_CP_Battle
- #--------------------------------------------------------------------------
- # ○ パーティ全員の CP を初期設定
- #--------------------------------------------------------------------------
- def cp_preset_party
- for actor in $game_party.actors
- actor.cp_preset
- end
- end
-
- #--------------------------------------------------------------------------
- # ○ トループ全員の CP を初期設定
- #--------------------------------------------------------------------------
- def cp_preset_troop
- for enemy in $game_troop.enemies
- enemy.cp_preset
- end
- end
-
- def cp_preset_troop
- for enemy in $game_troop.enemies
- enemy.cp_preset
- end
- end
-
- #--------------------------------------------------------------------------
- # ○ バトラー全員の CP をカウントアップ
- #--------------------------------------------------------------------------
- def cp_update
- for battler in $game_party.actors + $game_troop.enemies
- battler.cp_update
- end
- end
- end
- class Scene_Battle
- include XRXS_CP_Battle
- end
- #==============================================================================
- # ■ Scene_Battle
- #==============================================================================
- class Scene_Battle
- #--------------------------------------------------------------------------
- # ● メイン処理
- #--------------------------------------------------------------------------
- alias xrxs65_main main
- def main
- # エクストラスプライトの初期化
- @extra_sprites = [] if @extra_sprites == nil
- # CP の初期化
- cp_preset_party
- # CP メーターの作成
- @cp_meters = CP_Meters.new
- # CP メーターをエクストラスプライトへ登録
- @extra_sprites.push(@cp_meters)
- # 呼び戻す
- xrxs65_main
- # メーターの解放
- @cp_meters.dispose
- end
- #--------------------------------------------------------------------------
- # ● プレバトルフェーズ開始
- #--------------------------------------------------------------------------
- alias xrxs65_start_phase1 start_phase1
- def start_phase1
- # 呼び戻す
- xrxs65_start_phase1
- # CP の初期化
- cp_preset_troop
- # CP メーターの更新
- @cp_meters.refresh
- # インデックスを計算
- @cp_escape_actor_command_index = @actor_command_window.height/32 - 1
- # アクターコマンドウィンドウに追加
- # @actor_command_window.add_command("逃げる") # XXOO
- if !$game_temp.battle_can_escape
- @actor_command_window.disable_item(@cp_escape_actor_command_index)
- end
- end
- #--------------------------------------------------------------------------
- # ● パーティコマンドフェーズ開始
- #--------------------------------------------------------------------------
- alias xrxs65_start_phase2 start_phase2
- def start_phase2
- # 呼び戻す
- xrxs65_start_phase2
- # パーティコマンドウィンドウを無効化
- @party_command_window.active = false
- @party_command_window.visible = false
- # 強制的にフェイズ 2 を保持
- @phase = 2
- # ただし、既に行動可能者が存在する場合は 3 へ
- start_phase3 if anybody_movable?
- end
- #--------------------------------------------------------------------------
- # ○ CP制での ターンのカウント
- #--------------------------------------------------------------------------
- def cp_turn_count
- $game_temp.battle_turn += 1
- # バトルイベントの全ページを検索
- for index in 0...$data_troops[@troop_id].pages.size
- # このページのスパンが [ターン] の場合
- if $data_troops[@troop_id].pages[index].span == 1
- # 実行済みフラグをクリア
- $game_temp.battle_event_flags[index] = false
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● フレーム更新 (パーティコマンドフェーズ)
- #--------------------------------------------------------------------------
- alias xrxs65_update_phase2 update_phase2
- def update_phase2
- # パーティコマンドウィンドウのインデックスを無効化
- @party_command_window.index = -1
- # 呼び戻す
- xrxs65_update_phase2
- # 例外補正
- @turn_count_time = 1 if @turn_count_time == nil
- # ターンのカウント
- if @turn_count_time > 0
- @turn_count_time -= 1
- if @turn_count_time == 0
- cp_turn_count
- @turn_count_time = XRXS65::CPT if XRXS65::TC == nil
- end
- end
- # CP のフレーム更新
- cp_update
- @cp_meters.refresh
- # フル CP のバトラーが存在する場合、ターン開始
- start_phase3 if anybody_movable?
- end
- #--------------------------------------------------------------------------
- # ○ フル CP バトラーが存在するか?
- #--------------------------------------------------------------------------
- def anybody_movable?
- for battler in $game_party.actors + $game_troop.enemies
- return true if battler.cp_full?
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● アクターコマンドウィンドウのセットアップ
- #--------------------------------------------------------------------------
- alias xrxs65_phase3_setup_command_window phase3_setup_command_window
- def phase3_setup_command_window
- # 効果音の再生
- Audio.se_play(XRXS65::COMMAND_UP_SE) rescue nil
- # 呼び戻す
- xrxs65_phase3_setup_command_window
- end
- #--------------------------------------------------------------------------
- # ● フレーム更新 (アクターコマンドフェーズ : 基本コマンド)
- #--------------------------------------------------------------------------
- alias xrxs_bsp1_update_phase3_basic_command update_phase3_basic_command
- def update_phase3_basic_command
- # C ボタンが押された場合
- if Input.trigger?(Input::C)
- # アクターコマンドウィンドウのカーソル位置で分岐
- case @actor_command_window.index
- when @cp_escape_actor_command_index # 逃げる
- if $game_temp.battle_can_escape
- # 決定 SE を演奏
- $game_system.se_play($data_system.decision_se)
- # アクションを設定
- @active_battler.current_action.kind = 0
- @active_battler.current_action.basic = 4
- # 次のアクターのコマンド入力へ
- phase3_next_actor
- else
- # ブザー SE を演奏
- $game_system.se_play($data_system.buzzer_se)
- end
- return
- end
- end
- # 呼び戻す
- xrxs_bsp1_update_phase3_basic_command
- end
- #--------------------------------------------------------------------------
- # ● メインフェーズ開始
- #--------------------------------------------------------------------------
- alias xrxs65_start_phase4 start_phase4
- def start_phase4
- # ターン数を引くことによって擬似的にカウントに変化を起こさせない
- $game_temp.battle_turn -= 1
- # フラグを退避
- save_flags = $game_temp.battle_event_flags.dup
- # 呼び戻す
- xrxs65_start_phase4
- # フラグを復旧
- $game_temp.battle_event_flags = save_flags
- end
- #--------------------------------------------------------------------------
- # ● 行動順序作成
- #--------------------------------------------------------------------------
- alias xrxs65_make_action_orders make_action_orders
- def make_action_orders
- # 呼び戻す
- xrxs65_make_action_orders
- # CPが不足している場合は @action_battlers から除外する
- for battler in @action_battlers.dup
- @action_battlers.delete(battler) unless battler.cp_full?
- end
- end
- #--------------------------------------------------------------------------
- # ● フレーム更新 (メインフェーズ ステップ 2 : アクション開始)
- #--------------------------------------------------------------------------
- alias xrxs65_update_phase4_step2 update_phase4_step2
- def update_phase4_step2
- # ガードの解除
- @active_battler.guarding = false
- # CPの消費
- @active_battler.cp = 0
- # CP メーターの更新
- @cp_meters.refresh
- # 呼び戻す
- xrxs65_update_phase4_step2
- # 例外補正
- return if @active_battler == nil
- # ターンコントローラ
- if @active_battler.is_a?(Game_Enemy) and @active_battler.index == XRXS65::TC
- cp_turn_count
- end
- end
- #--------------------------------------------------------------------------
- # ● 基本アクション 結果作成
- #--------------------------------------------------------------------------
- alias xrxs65_make_basic_action_result make_basic_action_result
- def make_basic_action_result
- # 呼び戻す
- xrxs65_make_basic_action_result
- # 防御の場合
- if @active_battler.current_action.basic == 1
- @active_battler.guarding = true
- return
- end
- # パーティの逃亡の場合
- if @active_battler.current_action.basic == 4
- # 逃走可能ではない場合
- if $game_temp.battle_can_escape == false
- # ブザー SE を演奏
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # パーティ全員の CP をクリア
- for actor in $game_party.actors
- actor.cp = 0
- end
- # CP メーターの更新
- @cp_meters.refresh
- # 逃走処理
- update_phase2_escape
- return
- end
- end
- #--------------------------------------------------------------------------
- # ● フレーム更新 (メインフェーズ ステップ 5 : ダメージ表示)
- #--------------------------------------------------------------------------
- alias xrxs65_update_phase4_step5 update_phase4_step5
- def update_phase4_step5
- # 呼び戻す
- xrxs65_update_phase4_step5
- # CP メーターの更新
- @cp_meters.refresh
- end
- end
- #==============================================================================
- # --- CP メーターをまとめて管理するクラス、表示関係はすべてココ ---
- #==============================================================================
- class CP_Meters
- #--------------------------------------------------------------------------
- # ○ オブジェクト初期化
- #--------------------------------------------------------------------------
- def initialize
- # メーター群の生成
- @meters = []
- for i in 0...$game_party.actors.size
- make_meter(i)
- end
- refresh
- end
- #--------------------------------------------------------------------------
- # ○ リフレッシュ
- #--------------------------------------------------------------------------
- def refresh
- # 戦闘メンバー数の変更を判別
- for i in @meters.size...$game_party.actors.size
- make_meter(i)
- end
- for i in [email protected]
- @meters[i].dispose
- @meters[i] = nil
- end
- @meters.compact!
- # 表示更新
- for i in 0...$game_party.actors.size
- actor = $game_party.actors[i]
- @meters[i].line = actor.cp_linetype
- @meters[i].amount = actor.cp_lineamount
- end
- end
- #--------------------------------------------------------------------------
- # ○ メーターひとつの生成
- #--------------------------------------------------------------------------
- def make_meter(i)
- # スキンの取得
- skin = RPG::Cache.windowskin(XRXS65::SKIN)
- #
- space = 640 / XRXS65::MAX
- case XRXS65::ALIGN
- when 0
- actor_x = i * space + 2
- when 1
- actor_x = (space * ((XRXS65::MAX - $game_party.actors.size)/2.0 + i)).floor
- when 2
- actor_x = (i + XRXS65::MAX - $game_party.actors.size) * space + 2
- end
- meter = MeterSprite.new(skin, XRXS65::LINE_HEIGHT)
- meter.x = actor_x + XRXS65::X_OFFSET - skin.width
- meter.y = XRXS65::Y_OFFSET
- @meters[i] = meter
- end
- #--------------------------------------------------------------------------
- # ○ 可視状態
- #--------------------------------------------------------------------------
- def visible=(b)
- @meters.each{|sprite| sprite.visible = b }
- end
- #--------------------------------------------------------------------------
- # ○ 解放
- #--------------------------------------------------------------------------
- def dispose
- @meters.each{|sprite| sprite.dispose }
- end
- end
- #==============================================================================
- # --- XRXS. レクタンギュラーメーター表示・極 ---
- #==============================================================================
- class MeterSprite < Sprite
- #--------------------------------------------------------------------------
- # ○ オブジェクト初期化
- #--------------------------------------------------------------------------
- def initialize(skin, line_height)
- @skin = skin
- @width = @skin.width
- @height = line_height
- @line = 1
- @amount = 0
- @base_sprite = Sprite.new
- @base_sprite.bitmap = @skin
- @base_sprite.src_rect.set(0, 0, @width, @height)
- @base_sprite.z = 601
- super()
- self.z = @base_sprite.z + 1
- self.bitmap = @skin
- self.line = 1
- end
- #--------------------------------------------------------------------------
- # ○ 値の設定
- #--------------------------------------------------------------------------
- def line=(n)
- @line = n
- refresh
- end
- def amount=(n)
- @amount = n
- refresh
- end
- def refresh
- self.src_rect.set(0, @line * @height, @width * @amount / 100, @height)
- end
- #--------------------------------------------------------------------------
- # ○ 座標の設定
- #--------------------------------------------------------------------------
- def x=(n)
- super
- @base_sprite.x = n
- end
- def y=(n)
- super
- @base_sprite.y = n
- end
- #--------------------------------------------------------------------------
- # ○ 解放
- #--------------------------------------------------------------------------
- def dispose
- @base_sprite.dispose
- super
- end
- end
复制代码