查看: 1895|回复: 4

[已经过期] 请人帮我整理一下脚本

[复制链接]
梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

发表于 2014-10-12 21:46:21 | 显示全部楼层 |阅读模式

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

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

×
之前发贴,得到@Thylakoid 的帮助获得了2号人物自动的脚本。
可是放进去使用后发现战斗的时候2号人物经常连续多次进行动作。
我发现那是和我的CP脚本冲突了。
希望有人能帮我把脚本整合一下。
http://pan.baidu.com/s/1jGBUA5C

故九江太守

梦石
0
星屑
314
在线时间
2158 小时
注册时间
2012-12-5
回帖
4323
发表于 2014-10-13 12:58:30 | 显示全部楼层
什么叫2号人物自动的脚本
回复

使用道具 举报

梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

 楼主| 发表于 2014-10-13 13:20:12 | 显示全部楼层
你最珍贵 发表于 2014-10-13 12:58
什么叫2号人物自动的脚本

就是主角是自己选择攻击防御技能。其他角色自动选择攻击防御技能进行自动战斗。上面有工程,运行一下就能明白。

点评

我运行了没有自动啊……  发表于 2014-10-13 14:09
回复

使用道具 举报

梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

 楼主| 发表于 2014-10-13 20:26:47 | 显示全部楼层
你最珍贵 发表于 2014-10-13 12:58
什么叫2号人物自动的脚本

不是全自动。主角不自动,其他人自动
回复

使用道具 举报

梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

 楼主| 发表于 2014-10-13 23:11:52 | 显示全部楼层
使用的CP脚本

[pre lang="ruby" line="1"]#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================


# ————————————————————————————————————

# ▼▲▼ XRXS_BP 1. CP制導入 ver..23 ▼▲▼
# by 桜雅 在土, 和希

#==============================================================================
# □ カスタマイズポイント
#==============================================================================
module XRXS_BP1
#
# 对齐方式。0:左 1:中央 2:右
#
ALIGN = 0
#
# 人数
#
MAX = 4
end
class Scene_Battle_CP
#
# 战斗速度
#
BATTLE_SPEED = 2.0
#
# 战斗开始的时候气槽百分比
#
START_CP_PERCENT = 100
end

class Scene_Battle

# 效果音效,可以自己添加
DATA_SYSTEM_COMMAND_UP_SE = ""

# 各项数值功能消耗的CP值
CP_COST_BASIC_ACTIONS = 0 # 基础共同
CP_COST_SKILL_ACTION = 65535 # 技能
CP_COST_ITEM_ACTION = 65535 # 物品
CP_COST_BASIC_ATTACK = 65535 # 攻撃
CP_COST_BASIC_GUARD = 32768 # 防御
CP_COST_BASIC_NOTHING = 65535 # 不做任何事情
CP_COST_BASIC_ESCAPE = 65535 # 逃跑
end

#==============================================================================
# --- XRXS.コマンドウィンドウ?コマンド追加機構 ---
#------------------------------------------------------------------------------
# Window_Commandクラスに add_command メソッドを追加します。
#==============================================================================
module XRXS_Window_Command_Add_Command
#--------------------------------------------------------------------------
# ○ コマンドを追加
#--------------------------------------------------------------------------
def add_command(command)
# 初期化されていない場合、無効化判別用の配列 @disabled の初期化
#
if @disabled == nil
@disabled = []
end
if @commands.size != @disabled.size
for i in 0...@commands.size
@disabled = false
end
end
#
# 追加
#
@commands.push(command)
@disabled.push(false)
@item_max = @commands.size
self.y -= 32
self.height += 32
self.contents.dispose
self.contents = nil
self.contents = Bitmap.new(self.width - 32, @item_max * 32)
refresh
for i in 0...@commands.size
if @disabled
disable_item(i)
end
end
end
#--------------------------------------------------------------------------
# ○ 項目の無効化
# index : 項目番号
#--------------------------------------------------------------------------
def disable_item(index)
if @disabled == nil
@disabled = []
end
@disabled[index] = true
draw_item(index, disabled_color)
end
end
class Window_Command < Window_Selectable
#--------------------------------------------------------------------------
# ○ インクルード
#--------------------------------------------------------------------------
include XRXS_Window_Command_Add_Command
#--------------------------------------------------------------------------
# ● 項目の無効化
# index : 項目番号
#--------------------------------------------------------------------------
def disable_item(index)
super
end
end
#==============================================================================
# □ Scene_Battle_CP
#==============================================================================
class Scene_Battle_CP
#--------------------------------------------------------------------------
# ○ 公開インスタンス変数
#--------------------------------------------------------------------------
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.enemies
count_battlers.push(enemy)
end
# アクターを配列 count_battlers に追加
for actor in $game_party.actors
count_battlers.push(actor)
end
for battler in count_battlers
@agi_total += battler.agi
end
for battler in count_battlers
battler.cp = [[65535 * START_CP_PERCENT * (rand(15) + 85) * 4 * battler.agi / @agi_total / 10000, 0].max, 65535].min
end
end
#----------------------------------------------------------------------------
# ○ CPカウントアップ
#----------------------------------------------------------------------------
def update
# ストップされているならリターン
return if @stop
#
for battler in $game_party.actors + $game_troop.enemies
# 行動出来なければ無視
if battler.dead? == true
battler.cp = 0
next
end
battler.cp = [[battler.cp + BATTLE_SPEED * 4096 * battler.agi / @agi_total, 0].max, 65535].min
end
end
#----------------------------------------------------------------------------
# ○ CPカウントの開始
#----------------------------------------------------------------------------
def stop
@cancel = true
if @cp_thread != nil then
@cp_thread.join
@cp_thread = nil
end
end
end

#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler
attr_accessor :now_guarding # 現在防御中フラグ
attr_accessor :cp # 現在CP
attr_accessor :slip_state_update_ban # スリップ?ステート自動処理の禁止
#--------------------------------------------------------------------------
# ○ CP の変更
#--------------------------------------------------------------------------
def cp=(p)
@cp = [[p, 0].max, 65535].min
end
#--------------------------------------------------------------------------
# ● 防御中判定 [ 再定義 ]
#--------------------------------------------------------------------------
def guarding?
return @now_guarding
end
#--------------------------------------------------------------------------
# ● コマンド入力可能判定
#--------------------------------------------------------------------------
alias xrxs_bp1_inputable? inputable?
def inputable?
bool = xrxs_bp1_inputable?
return (bool and (@cp >= 65535))
end
#--------------------------------------------------------------------------
# ● ステート [スリップダメージ] 判定
#--------------------------------------------------------------------------
alias xrxs_bp1_slip_damage? slip_damage?
def slip_damage?
return false if @slip_state_update_ban
return xrxs_bp1_slip_damage?
end
#--------------------------------------------------------------------------
# ● ステート自然解除 (ターンごとに呼び出し)
#--------------------------------------------------------------------------
alias xrxs_bp1_remove_states_auto remove_states_auto
def remove_states_auto
return if @slip_state_update_ban
xrxs_bp1_remove_states_auto
end
end
#==============================================================================
# ■ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# ● セットアップ
#--------------------------------------------------------------------------
alias xrxs_bp1_setup setup
def setup(actor_id)
xrxs_bp1_setup(actor_id)
@cp = 0
@now_guarding = false
@slip_state_update_ban = false
end
end
#==============================================================================
# ■ Game_Enemy
#==============================================================================
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias xrxs_bp1_initialize initialize
def initialize(troop_id, member_index)
xrxs_bp1_initialize(troop_id, member_index)
@cp = 0
@now_guarding = false
@slip_state_update_ban = false
end
end
#==============================================================================
# ■ Window_BattleStatus
#==============================================================================
class Window_BattleStatus < Window_Base
#--------------------------------------------------------------------------
# ○ 公開インスタンス変数
#--------------------------------------------------------------------------
attr_accessor :update_cp_only # CPメーターのみの更新
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias xrxs_bp1_initialize initialize
def initialize
@update_cp_only = false
xrxs_bp1_initialize
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
alias xrxs_bp1_refresh refresh
def refresh
unless @update_cp_only
xrxs_bp1_refresh
end
refresh_cp
end
#--------------------------------------------------------------------------
# ○ リフレッシュ(CPのみ)
#--------------------------------------------------------------------------
def refresh_cp
for i in 0...$game_party.actors.size
actor = $game_party.actors
width = [self.width*3/4 / XRXS_BP1::MAX, 80].max
space = self.width / XRXS_BP1::MAX
case XRXS_BP1::ALIGN
when 0
actor_x = i * space + 4
when 1
actor_x = (space * ((XRXS_BP1::MAX - $game_party.actors.size)/2.0 + i)).floor
when 2
actor_x = (i + XRXS_BP1::MAX - $game_party.actors.size) * space + 4
end
actor_x += self.x
draw_actor_cp_meter(actor, actor_x, 96, width, 0)
end
end
#--------------------------------------------------------------------------
# ○ CPメーター の描画
#--------------------------------------------------------------------------
def draw_actor_cp_meter(actor, x, y, width = 156, type = 0)
self.contents.font.color = system_color
self.contents.fill_rect(x-1, y+27, width+2,6, Color.new(0, 0, 0, 255))
if actor.cp == nil
actor.cp = 0
end
w = width * [actor.cp,65535].min / 65535
self.contents.fill_rect(x, y+28, w,1, Color.new(255, 255, 128, 255))
self.contents.fill_rect(x, y+29, w,1, Color.new(255, 255, 0, 255))
self.contents.fill_rect(x, y+30, w,1, Color.new(192, 192, 0, 255))
self.contents.fill_rect(x, y+31, w,1, Color.new(128, 128, 0, 255))
end
end
#==============================================================================
# ■ Scene_Battle
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias xrxs_bp1_update update
def update
xrxs_bp1_update
# CP更新
@cp_thread.update
end
#--------------------------------------------------------------------------
# ● バトル終了
# result : 結果 (0:勝利 1:敗北 2:逃走)
#--------------------------------------------------------------------------
alias xrxs_bp1_battle_end battle_end
def battle_end(result)
# CPカウントを停止する
@cp_thread.stop
# 呼び戻す
xrxs_bp1_battle_end(result)
end
#--------------------------------------------------------------------------
# ● プレバトルフェーズ開始
#--------------------------------------------------------------------------
alias xrxs_bp1_start_phase1 start_phase1
def start_phase1
@agi_total = 0
# CP加算を開始する
@cp_thread = Scene_Battle_CP.new
# インデックスを計算
@cp_escape_actor_command_index = @actor_command_window.height/32 - 1
# アクターコマンドウィンドウに追加
@actor_command_window.add_command("逃     跑")
if !$game_temp.battle_can_escape
@actor_command_window.disable_item(@cp_escape_actor_command_index)
end
# 呼び戻す
xrxs_bp1_start_phase1
end
#--------------------------------------------------------------------------
# ● パーティコマンドフェーズ開始
#--------------------------------------------------------------------------
alias xrxs_bp1_start_phase2 start_phase2
def start_phase2
xrxs_bp1_start_phase2
@party_command_window.active = false
@party_command_window.visible = false
# CP加算を再開する
@cp_thread.stop = false
# 次へ
start_phase3
end
#--------------------------------------------------------------------------
# ● アクターコマンドウィンドウのセットアップ
#--------------------------------------------------------------------------
alias xrxs_bp1_phase3_setup_command_window phase3_setup_command_window
def phase3_setup_command_window
# CPスレッドを一時停止する
@cp_thread.stop = true
# ウィンドウのCP更新
@status_window.refresh_cp
# @active_battlerの防御を解除
@active_battler.now_guarding = false
# 効果音の再生
Audio.se_play(DATA_SYSTEM_COMMAND_UP_SE) if DATA_SYSTEM_COMMAND_UP_SE != ""
# 呼び戻す
xrxs_bp1_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 xrxs_bp1_start_phase4 start_phase4
def start_phase4
# 呼び戻す
xrxs_bp1_start_phase4
# CPスレッドを一時停止する
unless @action_battlers.empty?
@cp_thread.stop = true
end
end
#--------------------------------------------------------------------------
# ● 行動順序作成
#--------------------------------------------------------------------------
alias xrxs_bp1_make_action_orders make_action_orders
def make_action_orders
xrxs_bp1_make_action_orders
# 全員のCPを確認
exclude_battler = []
for battler in @action_battlers
# CPが不足している場合は @action_battlers から除外する
if battler.cp < 65535
exclude_battler.push(battler)
end
end
@action_battlers -= exclude_battler
end
#--------------------------------------------------------------------------
# ● フレーム更新 (メインフェーズ ステップ 1 : アクション準備)
#--------------------------------------------------------------------------
alias xrxs_bp1_update_phase4_step1 update_phase4_step1
def update_phase4_step1
# 初期化
@phase4_act_continuation = 0
# 勝敗判定
if judge
@cp_thread.stop
# 勝利または敗北の場合 : メソッド終了
return
end
# 未行動バトラー配列の先頭から取得
@active_battler = @action_battlers[0]
# ステータス更新をCPだけに限定。
@status_window.update_cp_only = true
# ステート更新を禁止。
@active_battler.slip_state_update_ban = true if @active_battler != nil
# 戻す
xrxs_bp1_update_phase4_step1
# @status_windowがリフレッシュされなかった場合は手動でリフレッシュ(CPのみ)
if @phase4_step != 2
# リフレッシュ
@status_window.refresh
# 軽量化:たったコレだけΣ(?w?
Graphics.frame_reset
end
# 禁止を解除
@status_window.update_cp_only = false
@active_battler.slip_state_update_ban = false if @active_battler != nil
end
#--------------------------------------------------------------------------
# ● フレーム更新 (メインフェーズ ステップ 2 : アクション開始)
#--------------------------------------------------------------------------
alias xrxs_bp1_update_phase4_step2 update_phase4_step2
def update_phase4_step2
# 強制アクションでなければ
unless @active_battler.current_action.forcing
# 制約が [敵を通常攻撃する] か [味方を通常攻撃する] の場合
if @active_battler.restriction == 2 or @active_battler.restriction == 3
# アクションに攻撃を設定
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
end
# 制約が [行動できない] の場合
if @active_battler.restriction == 4
# アクション強制対象のバトラーをクリア
$game_temp.forcing_battler = nil
if @phase4_act_continuation == 0 and @active_battler.cp >= 65535
# ステート自然解除
@active_battler.remove_states_auto
# CP消費
@active_battler.cp -= 65535
# ステータスウィンドウをリフレッシュ
@status_window.refresh
end
# ステップ 1 に移行
@phase4_step = 1
return
end
end
# アクションの種別で分岐
case @active_battler.current_action.kind
when 0
# 攻撃?防御?逃げる?何もしない時の共通消費CP
@active_battler.cp -= CP_COST_BASIC_ACTIONS if @phase4_act_continuation == 0
when 1
# スキル使用時の消費CP
@active_battler.cp -= CP_COST_SKILL_ACTION if @phase4_act_continuation == 0
when 2
# アイテム使用時の消費CP
@active_battler.cp -= CP_COST_ITEM_ACTION if @phase4_act_continuation == 0
end
# ステート自然解除
@active_battler.remove_states_auto
# 呼び戻す
xrxs_bp1_update_phase4_step2
end
#--------------------------------------------------------------------------
# ● 基本アクション 結果作成
#--------------------------------------------------------------------------
alias xrxs_bp1_make_basic_action_result make_basic_action_result
def make_basic_action_result
# 攻撃の場合
if @active_battler.current_action.basic == 0 and @phase4_act_continuation == 0
@active_battler.cp -= CP_COST_BASIC_ATTACK # 攻撃時のCP消費
end
# 防御の場合
if @active_battler.current_action.basic == 1 and @phase4_act_continuation == 0
@active_battler.cp -= CP_COST_BASIC_GUARD # 防御時のCP消費
# @active_battlerの防御をON
@active_battler.now_guarding = true
end
# 敵の逃げるの場合
if @active_battler.is_a?(Game_Enemy) and
@active_battler.current_action.basic == 2 and @phase4_act_continuation == 0
@active_battler.cp -= CP_COST_BASIC_ESCAPE # 逃走時のCP消費
end
# 何もしないの場合
if @active_battler.current_action.basic == 3 and @phase4_act_continuation == 0
@active_battler.cp -= CP_COST_BASIC_NOTHING # 何もしない時のCP消費
end
# 逃げるの場合
if @active_battler.current_action.basic == 4 and @phase4_act_continuation == 0
@active_battler.cp -= CP_COST_BASIC_ESCAPE # 逃走時のCP消費
# 逃走可能ではない場合
if $game_temp.battle_can_escape == false
# ブザー SE を演奏
$game_system.se_play($data_system.buzzer_se)
return
end
# 逃走処理
update_phase2_escape
return
end
# 呼び戻す
xrxs_bp1_make_basic_action_result
end
#--------------------------------------------------------------------------
# ● フレーム更新 (メインフェーズ ステップ 6 : リフレッシュ)
#--------------------------------------------------------------------------
alias xrxs_bp1_update_phase4_step6 update_phase4_step6
def update_phase4_step6
# スリップダメージ
if @active_battler.hp > 0 and @active_battler.slip_damage?
@active_battler.slip_damage_effect
@active_battler.damage_pop = true
# ステータスウィンドウをリフレッシュ
@status_window.refresh
end
# 呼び戻す
xrxs_bp1_update_phase4_step6
end
end


#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
[/pre]



使用的除主角外的人物自动脚本
[pre lang="ruby" line="1"]#==============================================================================
# ★【  自动战斗  】★
#==============================================================================
#  by -> 芯☆淡如水
#==============================================================================
# ● 使用方法:复制该脚本,插入到 main 前。
#==============================================================================
# ● 说明:
#         自动战斗,顾名思义,就是角色选择“自动战斗”后,无需玩家给角色下达
#      指令,角色仍可自己行动。
#        
#         该自动战斗有 2 个模式:普通自动战斗 和 AI自动战斗。2 种模式的切换
#       使用下面设置项的开关。
#
#         角色在 普通自动战斗 时,只是普通攻击敌人。选择的敌人目标偏向血较少
#      者。
#
#         角色在 AI自动战斗 时,判断角色行动类型的流程为:复活同伴 --》 恢复
#      同伴(HP和SP)--》攻击。
#         如果队伍中有同伴死亡,有很大几率复活同伴(具体多大几率就不透露),
#      死亡的同伴个数越多,几率越大。复活同伴的前提条件是有复活类药品或特技。
#         跳过复活同伴是恢复同伴,恢复同伴的几率以整体的剩余HP/SP的百分比来
#      算,百分比越小,几率越高。单体恢复同伴HP/SP的恢复对象,偏向HP/SP较少
#      者。恢复同伴的前提条件是有恢复类药品或特技。
#         最后是攻击,攻击判断之前有一定的几率对同伴使用 增益特技。攻击分为
#      普通攻击和使用特技,几率以角色的不同而不同,如果是战士类型的角色,普通
#      攻击的几率高于使用特技的几率;法师类型的角色则相反。使用特技时有一定的
#      几率使用不良状态特技。所有使用特技都是以角色已习得的特技为基础。普通攻
#      击和使用单体攻击特技的对象目标,也是偏向血较少者。
#
#
#   ■ 恢复:     自动战斗者在恢复同伴时,首先确定恢复对象,根据对象需要恢复的
#               HP/SP 的多少,来确定使用的物品或特技。需要恢复的对象越多,使用
#               “己方全体”的物品或特技的几率越大,单个的恢复对象是不会使用
#               “己方全体”的物品或特技。
#              
#                比如确定了某个恢复对象,该对象需要回复 HP 100 ,所能使用的物品
#               或特技有 3 种:回复 HP 60 ;回复 HP 110 ;回复 HP 220 。那么自动
#               战斗者会选择 “回复 HP 110” 的这个物品或特技来恢复该对象。
#
#
#   ■ 特技攻击:  如果自动战斗者能够使用“敌全体”特技,并且敌人的数量是 2 个
#               或以上时,自动战斗者有几率使用“敌全体”特技,敌人数量越多,几
#               率越大。
#
#                  如果是单个攻击对象,首先确定对象,根据该对象剩余的 HP 来选择
#               特技。在这之前会先判断普通攻击能否打倒该对象,如果能打倒该对象,
#               就使用普通攻击,而不使用特技了。
#
#               比如:例1:攻击对象剩余HP:160 ,自动战斗者可使用的特技有:对该
#                          对象伤害 HP 180 和 伤害 HP 260 两个特技,但自动战斗者
#                          对该对象的普通攻击伤害为:HP 200 ,那么自动战斗者会
#                          选择普通攻击而不使用特技。
#
#                     例2:攻击对象剩余HP:2000 ,自动战斗者可使用的特技有:对该
#                          对象伤害 HP 200 ; 伤害 HP 600 ;伤害 HP 1000 三种,
#                          那么自动战斗者会选择 伤害 HP 1000 的这个特技来攻击该
#                          对象。
#==============================================================================
# ● 设置:
#------------------------------------------------------------------------------
# 打开或关闭 自动战斗功能 的开关 ID。
#AUTO_SWEITCHE = 1
#------------------------------------------------------------------------------
# 是否 AI自动战斗 的开关 ID。该开关打开为 AI自动;关闭为 普通自动。
#AI_AUTO_SWEITCHE = 2
#------------------------------------------------------------------------------
# 角色自动战斗时,自动提示的等待时间(帧)。
#WAIT_TIME = 50
#------------------------------------------------------------------------------
# 增益状态 特技 ID 。
UP_PLUS_SKILLS = [53, 54]
#------------------------------------------------------------------------------
# 不良状态 特技 ID 。
DOWN_PLUS_SKILLS = [41, 46]
#=============================================================================
##############################################################################
#=============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  attr_accessor :auto_battle
  attr_accessor :auto_battle_targets
  #--------------------------------------------------------------------------
  alias add_setup_xdrs setup
  def setup(actor_id)
    @auto_battle = false
    @auto_battle_targets = []
    add_setup_xdrs(actor_id)
  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
    #s5 = "自动"
    s6 = "逃跑"
    #if $game_switches[AUTO_SWEITCHE]
      #@actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
      #@actor_command_window.y = 96
    #else  
      @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, s6])
      @actor_command_window.y = 128
    #end
    @actor_command_window.back_opacity = 160
    @actor_command_window.active = false
    @actor_command_window.visible = false
   
    # 生成其它窗口
    #
    #@auto_top = Window_Base.new(0, 256, 160, 64)
    #@auto_top.contents = Bitmap.new(@auto_top.width - 32, @auto_top.height - 32)
    #@auto_top.contents.draw_text(0, 0, 138, 32,"确定键:取消自动")
    #@auto_top.back_opacity = 160
    #@auto_top.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
    # 初始化等待计数
    @wait_count = 0
    #@auto_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
    # 释放窗口
    #@auto_top.dispose
    @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_phase2
    # 转移到回合 2
    @phase = 2
    # 设置角色为非选择状态
    @actor_index = -1
    @active_battler = nil
    unless $game_party.inputable?
      # 开始主回合
      start_phase4
      return
    end
    start_phase3
  end
  #--------------------------------------------------------------------------
  def phase3_prior_actor
    # 循环
    begin
      # 角色的明灭效果 OFF
      if @active_battler != nil
        @active_battler.blink = false
      end
      # 最初的角色的情况下
      if @actor_index == 0
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 返回角色索引
      @actor_index -= 1
      @active_battler = $game_party.actors[@actor_index]
      @active_battler.blink = true
    # 如果角色是在无法接受指令的状态就再试
    end until @active_battler.inputable?
    # 设置角色的命令窗口
    phase3_setup_command_window
  end
#--------------------------------------------------------------------------
  def update_phase3_basic_command
#=================================================   
    if @actor_index == 0 #当前行动者是主角
#=================================================
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 转向前一个角色的指令输入
      phase3_prior_actor
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 角色指令窗口光标位置分之
      case @actor_command_window.index
      when 0  # 攻击
        # 演奏确定 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  # 防御
        # 演奏确定 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
     # when 4  # 自动
     #   if $game_switches[AUTO_SWEITCHE]
     #     # 演奏确定 SE
     #     $game_system.se_play($data_system.decision_se)
     #     @actor_command_window.active = false
     #     @actor_command_window.visible = false
     #     @active_battler.auto_battle = true
     #     phase3_next_actor
     #   else
     #      # 演奏确定 SE
     #     $game_system.se_play($data_system.decision_se)
          # 逃走处理
     #     update_phase2_escape
     #   end        
      when 4  # 逃跑
        # 不能逃跑的情况下
        if $game_temp.battle_can_escape == false
          # 演奏冻结 SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 逃走处理
        update_phase2_escape
      end
      return
    end
  else  # 当前行动者是队友
    @actor_command_window.active = false
    @actor_command_window.visible = false
    @active_battler.auto_battle = true
    phase3_next_actor
    return
    end
  end
  #--------------------------------------------------------------------------
  #alias add_phase3_setup_command_window_xdrs phase3_setup_command_window
  #def phase3_setup_command_window
  #  if @active_battler.auto_battle
  #    @auto_wait_count = WAIT_TIME  
  #    @auto_top.visible = true
  #    @auto_top.x = @actor_index * 160
  #   return
  #  end
  #  add_phase3_setup_command_window_xdrs
  #end
  #--------------------------------------------------------------------------
  #alias add_update_phase3_xdrs update_phase3
  #def update_phase3
  #  if @auto_wait_count > 0
  #    update_wait_at
  #    return
  #  end
  #  add_update_phase3_xdrs
  #end
  #--------------------------------------------------------------------------
  #def update_wait_at
  #  @auto_wait_count -= 1
  #  if @auto_wait_count == 0
  #    $game_system.se_play($data_system.decision_se)
  #    @auto_top.visible = false
  #    phase3_next_actor
  #    return
  #  end
  #  if Input.trigger?(Input::B)
  #    $game_system.se_play($data_system.cancel_se)
  #    @auto_wait_count = 0
  #    phase3_prior_actor
  #    return
  #  end
  #  if Input.trigger?(Input::C)
  #    $game_system.se_play($data_system.decision_se)
  #    @auto_wait_count = 0
  #    @active_battler.auto_battle = false
  #    @auto_top.visible = false
  #    @actor_index -= 1
  #    phase3_next_actor
  #  end
  #end
  #--------------------------------------------------------------------------
  def update_phase4_step2
    # 如果不是强制行动
    unless @active_battler.current_action.forcing
      # 限制为 [敌人为普通攻击] 或 [我方为普通攻击] 的情况下
      if @active_battler.restriction == 2 or @active_battler.restriction == 3
        # 设置行动为攻击
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 0
      end
      # 限制为 [不能行动] 的情况下
      if @active_battler.restriction == 4
        # 清除行动强制对像的战斗者
        $game_temp.forcing_battler = nil
        # 移至步骤 1
        @phase4_step = 1
        return
      end
    end
    # 清除对像战斗者
    @target_battlers = []
    if @active_battler.is_a?(Game_Actor)
      if @active_battler.auto_battle and not @active_battler.dead?
        set_auto_battle
        case @active_battler.current_action.kind
        when 0  
          make_basic_auto
        when 1  
          make_skill_auto
        when 2  
          make_item_auto
        end
        if @phase4_step == 2
          @phase4_step = 3
        end
        return
      end
    end
    # 行动种类分支
    case @active_battler.current_action.kind
    when 0  # 基本
      make_basic_action_result
    when 1  # 特技
      make_skill_action_result
    when 2  # 物品
      make_item_action_result
    end
    # 移至步骤 3
    if @phase4_step == 2
      @phase4_step = 3
    end
  end
  #--------------------------------------------------------------------------
  def make_basic_auto
    case @active_battler.current_action.basic
    when 0
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      if @active_battler.restriction == 3
        target = $game_party.random_target_actor
        @active_battler.auto_battle_targets = []
        @active_battler.auto_battle_targets.push(target)
      elsif @active_battler.restriction == 2
        target = $game_troop.random_target_enemy
        @active_battler.auto_battle_targets = []
        @active_battler.auto_battle_targets.push(target)
      end
      @target_battlers = @active_battler.auto_battle_targets
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    when 1
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
  end
  #--------------------------------------------------------------------------
  def make_skill_auto
    @skill = $data_skills[@active_battler.current_action.skill_id]
    unless @active_battler.current_action.forcing
      unless @active_battler.skill_can_use?(@skill.id)
        $game_temp.forcing_battler = nil
        @phase4_step = 1
        return
      end
    end
    @active_battler.sp -= @skill.sp_cost
    @status_window.refresh
    @help_window.set_text(@skill.name, 1)
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    @common_event_id = @skill.common_event_id
    @target_battlers = @active_battler.auto_battle_targets
    for target in @target_battlers
      target.skill_effect(@active_battler, @skill)
    end
  end
  #--------------------------------------------------------------------------
  def make_item_auto
    @item = $data_items[@active_battler.current_action.item_id]
    unless $game_party.item_can_use?(@item.id)
      @phase4_step = 1
      return
    end
    if @item.consumable
      $game_party.lose_item(@item.id, 1)
    end
    @help_window.set_text(@item.name, 1)
    @animation1_id = @item.animation1_id
    @animation2_id = @item.animation2_id
    @common_event_id = @item.common_event_id
    @target_battlers = @active_battler.auto_battle_targets
    for target in @target_battlers
      target.item_effect(@item)
    end
  end
  #--------------------------------------------------------------------------
  alias add_update_phase4_step6_xdrs update_phase4_step6
  def update_phase4_step6
    @active_battler.auto_battle_targets = [] if @active_battler.is_a?(Game_Actor)
    add_update_phase4_step6_xdrs
  end
  #==============================================================================
  #==============================================================================
  def set_auto_battle
    #if $game_switches[AI_AUTO_SWEITCHE]
      ai_auto_battle
    #else
      #base_atk
    #end
  end
  #----------------------------------------------------------------------------
  def ai_auto_battle
    set_probability
    if rand (100) < @f_probability
      f_actor
      return
    end
    judge_r_actor
  end
  #----------------------------------------------------------------------------
  def set_probability
    @f_probability = 0
    h = mh = s = ms = 0.0
    if dead_actors != []
      @f_probability = 70
      @f_probability += (dead_actors.size - 1) * 20
    end
    for actor in all_actors
      h += actor.hp
      mh += actor.maxhp
      s += actor.sp
      ms += actor.maxsp
    end
    @rh_probability = 100 - (h / mh * 100).ceil
    @rh_probability += pressing_actor_hp.size * 30
    @rs_probability = 100 - (s / ms * 100).ceil
    @rs_probability += pressing_actor_sp.size * 30
  end
  #----------------------------------------------------------------------------
  def f_actor
    @f_skills = @f_items = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and [5, 6].include?(skill.scope)
        @f_skills.push(skill)
      end
    end
    for id in 1...$data_items.size
      item = $data_items[id]
      if $game_party.item_number(id) > 0 and [5, 6].include?(item.scope)
        @f_items.push(item)
      end
    end
    if @f_skills != [] or @f_items != []
      if rand (2) == 0
        if @f_skills != []
          f_actor_skill
          return
        end
        f_actor_item
        return
      else
        if @f_items != []
          f_actor_item
          return
        end
        f_actor_skill
        return
      end
    end
    judge_r_actor
  end
  #----------------------------------------------------------------------------
  def f_actor_skill
    @active_battler.current_action.kind = 1
    skill = @f_skills[rand (@f_skills.size)]
    @active_battler.current_action.skill_id = skill.id
    set_autobattler_targets
  end
  #----------------------------------------------------------------------------
  def f_actor_item
    @active_battler.current_action.kind = 2
    item = @f_items[rand (@f_items.size)]
    @active_battler.current_action.item_id = item.id
    set_autobattler_targets
  end
  #----------------------------------------------------------------------------
  def judge_r_actor
    if @rh_probability >= 30 and rand (120) < @rh_probability
      r_actor_hp
      return
    end
    if @rs_probability >= 50 and rand (150) < @rs_probability
      r_actor_sp
      return
    end
    judge_battle
  end
  #----------------------------------------------------------------------------
  def r_actor_hp
    if recover_hp_items != [] or recover_hp_skills != []   
      if rand (2) == 0
        if recover_hp_items != []
          r_hp_item
          return
        end
        r_hp_skill
        return
      else
        if recover_hp_skills != []
          r_hp_skill
          return
        end
        r_hp_item
        return
      end
    end
    if @rs_probability >= 50 and rand (150) < @rs_probability
      r_actor_sp
      return
    end
    judge_battle
  end
  #----------------------------------------------------------------------------
  def r_actor_sp
    if recover_sp_items != []   
      r_sp_item
      return
    end
    judge_battle
  end
  #----------------------------------------------------------------------------
  def r_hp_item
    @active_battler.current_action.kind = 2
    date = []
    items = []
    for actor in all_actors
      if actor.hp * 100 < actor.maxhp * 90
        date.push(actor)
      end
    end
    for item in recover_hp_items
      items.push(item) if item.scope == 4
    end
    if ! items.empty? and date.size >= 2
      n = 10
      n += (date.size - 1) * 20
      if rand (100) < n
        item = items[rand (items.size)]
        @active_battler.current_action.item_id = item.id
        @active_battler.auto_battle_targets = all_actors
        return
      end
    end
    now_items = recover_hp_items - items
    if now_items.empty?
      judge_battle
      return
    end
    @active_battler.auto_battle_targets.push(targets_actor_hp)
    target = @active_battler.auto_battle_targets[0]
    set_use_item(now_items, target, 0)
  end
  #----------------------------------------------------------------------------
  def r_sp_item
    @active_battler.current_action.kind = 2
    date = []
    items = []
    for actor in all_actors
      if actor.sp * 100 < actor.maxsp * 60
        date.push(actor)
      end
    end
    for item in recover_sp_items
      items.push(item) if item.scope == 4
    end
    if ! items.empty? and date.size >= 2
      n = 10
      n += (date.size - 1) * 20
      if rand (100) < n
        item = items[rand (items.size)]
        @active_battler.current_action.item_id = item.id
        @active_battler.auto_battle_targets = all_actors
        return
      end
    end
    now_items = recover_sp_items - items
    if now_items.empty?
      judge_battle
      return
    end
    @active_battler.auto_battle_targets.push(targets_actor_sp)
    target = @active_battler.auto_battle_targets[0]
    set_use_item(now_items, target, 1)
  end
  #----------------------------------------------------------------------------
  def r_hp_skill
    date = []
    skills = []
    for actor in all_actors
      if actor.hp * 100 < actor.maxhp * 90
        date.push(actor)
      end
    end
    for skill in recover_hp_skills
      skills.push(skill) if skill.scope == 4
    end
    if ! skills.empty? and date.size >= 2
      n = 20
      n += (date.size - 1) * 20
      if rand (100) < n
        @active_battler.current_action.kind = 1
        skill = skills[rand(skills.size)]
        @active_battler.current_action.skill_id = skill.id
        @active_battler.auto_battle_targets = all_actors
        return
      end
    end
    now_skills = recover_hp_skills - skills
    if now_skills.empty?
      judge_battle
      return
    end
    @active_battler.current_action.kind = 1
    @active_battler.auto_battle_targets.push(targets_actor_hp)
    target = @active_battler.auto_battle_targets[0]
    set_use_skill(now_skills, target)
  end
  #---------------------------------------------------------------------------
  def judge_battle
    if up_plus_skills != []
      if rand (100) < 20
        use_up_skill
        return
      end
    end
    battle
  end
  #---------------------------------------------------------------------------
  def battle
    n = 100 - @active_battler.hp * 100 / @active_battler.maxhp
    if n > 80
      if rand (150) < n
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 1
        return
      end
    end
    if @active_battler.int > @active_battler.str
      n = 80
    elsif @active_battler.int == @active_battler.str
      n = 60
    else
      n = 40
    end
    if rand (100) < n
      use_skill
    else
      base_atk
    end
  end
  #---------------------------------------------------------------------------
  def use_skill
    if down_plus_skills != []
      if rand (100) < 20
        use_down_skill
        return
      end
    end
    if att_skills != []
      use_att_skill
      return
    end
    base_atk
  end
  #---------------------------------------------------------------------------
  def use_up_skill
    @active_battler.current_action.kind = 1
    skill = up_plus_skills[rand (up_plus_skills.size)]
    @active_battler.current_action.skill_id = skill.id
    set_autobattler_targets
  end
  #--------------------------------------------------------------------------
  def use_down_skill
    @active_battler.current_action.kind = 1
    skill = down_plus_skills[rand (down_plus_skills.size)]
    @active_battler.current_action.skill_id = skill.id
    set_autobattler_targets
  end
  #--------------------------------------------------------------------------
  def use_att_skill
    @active_battler.current_action.kind = 1
    date = []
    for skill in att_skills
      date.push(skill) if skill.scope == 2
    end
    if all_enemys.size >= 2
      n = 10
      n += (all_enemys.size - 1) * 10
      n = [n, 80].min
      if rand (100) < n and ! date.empty?
        skill = date[rand (date.size)]
        @active_battler.current_action.skill_id = skill.id
        @active_battler.auto_battle_targets = all_enemys
        return
      end
    end
    now_skills = att_skills - date
    if now_skills.empty?
      base_atk
      return
    end
    @active_battler.auto_battle_targets.push(targets_enemy_hp)
    target = @active_battler.auto_battle_targets[0]
    if use_base_atk?(target)
      base_atk
      return
    end
    set_use_skill(now_skills, target)
  end
  #----------------------------------------------------------------------------
  def base_atk
    @active_battler.current_action.kind = 0
    @active_battler.current_action.basic = 0
    if @active_battler.auto_battle_targets.empty?
      @active_battler.auto_battle_targets.push(targets_enemy_hp)
    end
  end
  ############################################################################
  #----------------------------------------------------------------------------
  def rand_actors
    date = []
    while date.size != $game_party.actors.size
      actor = $game_party.actors[rand ($game_party.actors.size)]
      date.push(actor) if not date.include?(actor)
    end
    return date
  end
  #----------------------------------------------------------------------------
  def dead_actors
    date = []
    for actor in rand_actors
      date.push(actor) if actor.dead?
    end
    return date
  end
  #----------------------------------------------------------------------------
  def all_actors
    date = []
    for actor in rand_actors
      date.push(actor) if actor.exist?
    end
    return date
  end
  #----------------------------------------------------------------------------
  def targets_actor_hp
    if pressing_actor_hp != []      
      target = pressing_actor_hp[rand (pressing_actor_hp.size)]
      return target
    end
    date = []
    for actor in all_actors
      if actor.hp * 100 < actor.maxhp * 90
        date.push(actor)
      end
    end
    target = nil
    if date != []
      for actor in date
        hn = 100 - actor.hp * 100 / actor.maxhp
        if rand (100) < hn
          target = actor
          break
        end
      end
      target = date[rand (date.size)] if target == nil
    end
    target = all_actors[rand (all_actors.size)] if target == nil
    return target
  end
  #----------------------------------------------------------------------------
  def targets_actor_sp
    if pressing_actor_sp != []      
      target = pressing_actor_sp[rand (pressing_actor_sp.size)]
      return target
    end
    date = []
    for actor in all_actors
      if actor.sp * 100 < actor.maxsp * 80
        date.push(actor)
      end
    end
    target = nil
    if date != []
      for actor in date
        sn = 100 - actor.sp * 100 / actor.maxsp
        if rand (100) < sn
          target = actor
          break
        end
      end
      target = date[rand (date.size)] if target == nil
    end
    target = all_actors[rand (all_actors.size)] if target == nil
    return target
  end
  #----------------------------------------------------------------------------
  def pressing_actor_hp
    date = []
    for actor in all_actors
      if actor.hp * 100 <= actor.maxhp * 30
        date.push(actor)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def pressing_actor_sp
    date = []
    for actor in all_actors
      if actor.sp * 100 <= actor.maxsp * 10
        date.push(actor)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def recover_hp_items
    date = []
    for i in 1...$data_items.size
      item = $data_items
      if $game_party.item_number(i) > 0 and [0, 1].include?(item.occasion)
        if not [5, 6].include?(item.scope)
          date.push(item) if item.recover_hp_rate > 0 or item.recover_hp > 0
        end
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def recover_sp_items
    date = []
    for i in 1...$data_items.size
      item = $data_items
      if $game_party.item_number(i) > 0 and [0, 1].include?(item.occasion)
        date.push(item) if item.recover_sp_rate > 0 or item.recover_sp > 0
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def all_enemys
    date = []
    for enemy in $game_troop.enemies
      date.push(enemy) if enemy.exist?
    end
    return date
  end
  #----------------------------------------------------------------------------
  def targets_enemy_hp
    date = []
    for enemy in all_enemys
      if enemy.hp < enemy.maxhp
        date.push(enemy)
      end
    end
    target = nil
    if date != []
      for enemy in date
        hn = 100 - enemy.hp * 100 / enemy.maxhp
        if rand (100) < hn
          target = enemy
          break
        end
      end
    end
    target = all_enemys[rand (all_enemys.size)] if target == nil
    return target
  end
  #----------------------------------------------------------------------------
  def recover_hp_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and skill.power < 0
        date.push(skill)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def att_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and skill.power > 0
        date.push(skill)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def up_plus_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and UP_PLUS_SKILLS.include?(id)
        date.push(skill)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def down_plus_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and DOWN_PLUS_SKILLS.include?(id)
        date.push(skill)
      end
    end
    return date
  end
  #---------------------------------------------------------------------------
  def set_use_item(items, target, toyp)
    @item = nil
    case toyp
    when 0
      date = []
      for item in items
        recover = item.recover_hp + item.recover_hp_rate * target.maxhp
        n = (recover - (target.maxhp - target.hp)).abs
        date.push(n)
      end
      date.sort!
      for item in items
        recover = item.recover_hp + item.recover_hp_rate * target.maxhp
        n = (recover - (target.maxhp - target.hp)).abs
        if n == date[0]
          @item = item
          break
        end
      end
    when 1
      date = []
      for item in items
        recover = item.recover_sp + item.recover_sp_rate * target.maxsp
        n = (recover - (target.maxsp - target.sp)).abs
        date.push(n)
      end
      date.sort!
      for item in items
        recover = item.recover_sp + item.recover_sp_rate * target.maxsp
        n = (recover - (target.maxsp - target.sp)).abs
        if n == date[0]
          @item = item
          break
        end
      end
    end
    @item = items[rand(items.size)] if @item == nil
    @active_battler.current_action.item_id = @item.id
  end
  #---------------------------------------------------------------------------
  def set_use_skill(skills, target)
    r_skills = []
    a_skills = []
    skill = nil
    for i in skills
      damage = count_skill_damage(i, target)
      if damage < 0
        n = (target.maxhp - target.hp + damage).abs
        r_skills.push(n)
      else
        n = (target.hp - damage).abs
        a_skills.push(n)
      end
    end
    r_skills.sort!
    a_skills.sort!
    for i in skills
      damage = count_skill_damage(i, target)
      if damage < 0
        n = (target.maxhp - target.hp + damage).abs
        skill = i if n == r_skills[0]
      else
        n = (target.hp - damage).abs
        skill = i if n == a_skills[0]
      end
    end
    skill = skills[rand (skills.sizs)] if skill == nil
    @active_battler.current_action.skill_id = skill.id
  end
  #----------------------------------------------------------------------------
  def count_skill_damage(skill, target)
    power = skill.power + @active_battler.atk * skill.atk_f / 100
    if power > 0
      power -= target.pdef * skill.pdef_f / 200
      power -= target.mdef * skill.mdef_f / 200
      power = [power, 0].max
    end
    rate = 20
    rate += (target.str * skill.str_f / 100)
    rate += (target.dex * skill.dex_f / 100)
    rate += (target.agi * skill.agi_f / 100)
    rate += (target.int * skill.int_f / 100)
    damage = power * rate / 20
    if skill.element_set == []
      rn = 100
    else
      rn = -100
      for i in skill.element_set
        rn = [rn, target.element_rate(i)].max
      end
    end
    damage = damage * rn / 100
    return damage
  end
  #----------------------------------------------------------------------------
  def use_base_atk?(target)
    atk = [@active_battler.atk - target.pdef / 2, 0].max
    damage = atk * (20 + @active_battler.str) / 20
    if @active_battler.element_set == []
      rn = 100
    else
      rn = -100
      for i in skill.element_set
        rn = [rn, target.element_rate(i)].max
      end
    end
    damage = damage * rn / 100
    n = target.hp - damage
    return true if n <= 0
    return false
  end
  #--------------------------------------------------------------------------
  def set_autobattler_targets
    case @active_battler.current_action.kind
    when 0
      @active_battler.auto_battle_targets.push(targets_enemy_hp)
    when 1
      skill = $data_skills[@active_battler.current_action.skill_id]
      if [5, 6].include?(skill.scope) and dead_actors != []
        if skill.scope == 5
          target = dead_actors[rand (dead_actors.size)]
          @active_battler.auto_battle_targets.push(target)
        else
          @active_battler.auto_battle_targets = dead_actors
        end
        return
      end
      if UP_PLUS_SKILLS.include?(skill.id)
        if skill.scope == 3
          target = all_actors[rand (all_actors.size)]
          @active_battler.auto_battle_targets.push(target)
        elsif skill.scope == 4
          @active_battler.auto_battle_targets = all_actors
        elsif skill.scope == 7
          @active_battler.auto_battle_targets.push(@active_battler)
        end
        return
      end
      if DOWN_PLUS_SKILLS.include?(skill.id)
        if skill.scope == 1
          target = all_enemys[rand (all_enemys.size)]
          @active_battler.auto_battle_targets.push(target)
        elsif skill.scope == 2
          @active_battler.auto_battle_targets = all_enemys
        end
        return
      end
      if skill.power > 0
        if skill.scope == 1
          @active_battler.auto_battle_targets.push(targets_enemy_hp)
        elsif skill.scope == 2
          @active_battler.auto_battle_targets = all_enemys
        end
      elsif skill.power < 0
        if skill.scope == 3
          @active_battler.auto_battle_targets.push(targets_actor_hp)
        elsif skill.scope == 4
          @active_battler.auto_battle_targets = all_actors
        end
      end
    when 2
      item = $data_items[@active_battler.current_action.item_id]
      case item.scope
      when 1
        @active_battler.auto_battle_targets.push(targets_enemy_hp)
      when 2
        @active_battler.auto_battle_targets = all_enemys
      when 3
        if (item.recover_sp_rate > 0 or item.recover_sp > 0) and
          (item.recover_hp_rate > 0 or item.recover_hp > 0)
          if rand (100) < 50
            @active_battler.auto_battle_targets.push(targets_actor_sp)
          else
            @active_battler.auto_battle_targets.push(targets_actor_hp)
          end
          return
        end
        if item.recover_hp_rate > 0 or item.recover_hp > 0
          @active_battler.auto_battle_targets.push(targets_actor_hp)
          return
        end
        if item.recover_sp_rate > 0 or item.recover_sp > 0
          @active_battler.auto_battle_targets.push(targets_actor_sp)
          return
        end
      when 4
        @active_battler.auto_battle_targets = all_actors
      when 5
        target = dead_actors[rand (dead_actors.size)]
        @active_battler.auto_battle_targets.push(target)
      when 6
        @active_battler.auto_battle_targets = dead_actors
      when 7
        @active_battler.auto_battle_targets.push(@active_battler)
      end
    end
  end
end
#==============================================================================
###############################################################################
#==============================================================================[/pre]
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部