设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1613|回复: 4
打印 上一主题 下一主题

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

[复制链接]

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

跳转到指定楼层
1
发表于 2014-10-12 21:46:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

Lv2.观梦者

故九江太守

梦石
0
星屑
559
在线时间
2160 小时
注册时间
2012-12-5
帖子
4463
2
发表于 2014-10-13 12:58:30 | 只看该作者
什么叫2号人物自动的脚本
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

3
 楼主| 发表于 2014-10-13 13:20:12 | 只看该作者
你最珍贵 发表于 2014-10-13 12:58
什么叫2号人物自动的脚本

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

点评

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

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

4
 楼主| 发表于 2014-10-13 20:26:47 | 只看该作者
你最珍贵 发表于 2014-10-13 12:58
什么叫2号人物自动的脚本

不是全自动。主角不自动,其他人自动
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

5
 楼主| 发表于 2014-10-13 23:11:52 | 只看该作者
使用的CP脚本

RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================
  4.  
  5.  
  6. # ————————————————————————————————————
  7.  
  8. # ▼▲▼ XRXS_BP 1. CP制導入 ver..23 ▼▲▼
  9. # by 桜雅 在土, 和希
  10.  
  11. #==============================================================================
  12. # □ カスタマイズポイント
  13. #==============================================================================
  14. module XRXS_BP1
  15. #
  16. # 对齐方式。0:左 1:中央 2:右
  17. #
  18. ALIGN = 0
  19. #
  20. # 人数
  21. #
  22. MAX = 4
  23. end
  24. class Scene_Battle_CP
  25. #
  26. # 战斗速度
  27. #
  28. BATTLE_SPEED = 2.0
  29. #
  30. # 战斗开始的时候气槽百分比
  31. #
  32. START_CP_PERCENT = 100
  33. end
  34.  
  35. class Scene_Battle
  36.  
  37. # 效果音效,可以自己添加
  38. DATA_SYSTEM_COMMAND_UP_SE = ""
  39.  
  40. # 各项数值功能消耗的CP值
  41. CP_COST_BASIC_ACTIONS = 0 # 基础共同
  42. CP_COST_SKILL_ACTION = 65535 # 技能
  43. CP_COST_ITEM_ACTION = 65535 # 物品
  44. CP_COST_BASIC_ATTACK = 65535 # 攻撃
  45. CP_COST_BASIC_GUARD = 32768 # 防御
  46. CP_COST_BASIC_NOTHING = 65535 # 不做任何事情
  47. CP_COST_BASIC_ESCAPE = 65535 # 逃跑
  48. end
  49.  
  50. #==============================================================================
  51. # --- XRXS.コマンドウィンドウ?コマンド追加機構 ---
  52. #------------------------------------------------------------------------------
  53. # Window_Commandクラスに add_command メソッドを追加します。
  54. #==============================================================================
  55. module XRXS_Window_Command_Add_Command
  56. #--------------------------------------------------------------------------
  57. # ○ コマンドを追加
  58. #--------------------------------------------------------------------------
  59. def add_command(command)
  60. # 初期化されていない場合、無効化判別用の配列 [url=home.php?mod=space&uid=249395]@disabled[/url] の初期化
  61. #
  62. if @disabled == nil
  63. @disabled = []
  64. end
  65. if @commands.size != @disabled.size
  66. for i in [email]0...@commands.size[/email]
  67. @disabled[i] = false
  68. end
  69. end
  70. #
  71. # 追加
  72. #
  73. @commands.push(command)
  74. @disabled.push(false)
  75. @item_max = @commands.size
  76. self.y -= 32
  77. self.height += 32
  78. self.contents.dispose
  79. self.contents = nil
  80. self.contents = Bitmap.new(self.width - 32, @item_max * 32)
  81. refresh
  82. for i in [email]0...@commands.size[/email]
  83. if @disabled[i]
  84. disable_item(i)
  85. end
  86. end
  87. end
  88. #--------------------------------------------------------------------------
  89. # ○ 項目の無効化
  90. # index : 項目番号
  91. #--------------------------------------------------------------------------
  92. def disable_item(index)
  93. if @disabled == nil
  94. @disabled = []
  95. end
  96. @disabled[index] = true
  97. draw_item(index, disabled_color)
  98. end
  99. end
  100. class Window_Command < Window_Selectable
  101. #--------------------------------------------------------------------------
  102. # ○ インクルード
  103. #--------------------------------------------------------------------------
  104. include XRXS_Window_Command_Add_Command
  105. #--------------------------------------------------------------------------
  106. # ● 項目の無効化
  107. # index : 項目番号
  108. #--------------------------------------------------------------------------
  109. def disable_item(index)
  110. super
  111. end
  112. end
  113. #==============================================================================
  114. # □ Scene_Battle_CP
  115. #==============================================================================
  116. class Scene_Battle_CP
  117. #--------------------------------------------------------------------------
  118. # ○ 公開インスタンス変数
  119. #--------------------------------------------------------------------------
  120. attr_accessor :stop # CP加算ストップ
  121. #----------------------------------------------------------------------------
  122. # ○ オブジェクトの初期化
  123. #----------------------------------------------------------------------------
  124. def initialize
  125. @battlers = []
  126. [url=home.php?mod=space&uid=9053]@cancel[/url] = false
  127. [url=home.php?mod=space&uid=76426]@stop[/url] = false
  128. @agi_total = 0
  129. # 配列 count_battlers を初期化
  130. count_battlers = []
  131. # エネミーを配列 count_battlers に追加
  132. for enemy in $game_troop.enemies
  133. count_battlers.push(enemy)
  134. end
  135. # アクターを配列 count_battlers に追加
  136. for actor in $game_party.actors
  137. count_battlers.push(actor)
  138. end
  139. for battler in count_battlers
  140. @agi_total += battler.agi
  141. end
  142. for battler in count_battlers
  143. battler.cp = [[65535 * START_CP_PERCENT * (rand(15) + 85) * 4 * battler.agi / @agi_total / 10000, 0].max, 65535].min
  144. end
  145. end
  146. #----------------------------------------------------------------------------
  147. # ○ CPカウントアップ
  148. #----------------------------------------------------------------------------
  149. def update
  150. # ストップされているならリターン
  151. return if @stop
  152. #
  153. for battler in $game_party.actors + $game_troop.enemies
  154. # 行動出来なければ無視
  155. if battler.dead? == true
  156. battler.cp = 0
  157. next
  158. end
  159. battler.cp = [[battler.cp + BATTLE_SPEED * 4096 * battler.agi / @agi_total, 0].max, 65535].min
  160. end
  161. end
  162. #----------------------------------------------------------------------------
  163. # ○ CPカウントの開始
  164. #----------------------------------------------------------------------------
  165. def stop
  166. @cancel = true
  167. if @cp_thread != nil then
  168. @cp_thread.join
  169. @cp_thread = nil
  170. end
  171. end
  172. end
  173.  
  174. #==============================================================================
  175. # ■ Game_Battler
  176. #==============================================================================
  177. class Game_Battler
  178. attr_accessor :now_guarding # 現在防御中フラグ
  179. attr_accessor :cp # 現在CP
  180. attr_accessor :slip_state_update_ban # スリップ?ステート自動処理の禁止
  181. #--------------------------------------------------------------------------
  182. # ○ CP の変更
  183. #--------------------------------------------------------------------------
  184. def cp=(p)
  185. @cp = [[p, 0].max, 65535].min
  186. end
  187. #--------------------------------------------------------------------------
  188. # ● 防御中判定 [ 再定義 ]
  189. #--------------------------------------------------------------------------
  190. def guarding?
  191. return @now_guarding
  192. end
  193. #--------------------------------------------------------------------------
  194. # ● コマンド入力可能判定
  195. #--------------------------------------------------------------------------
  196. alias xrxs_bp1_inputable? inputable?
  197. def inputable?
  198. bool = xrxs_bp1_inputable?
  199. return (bool and (@cp >= 65535))
  200. end
  201. #--------------------------------------------------------------------------
  202. # ● ステート [スリップダメージ] 判定
  203. #--------------------------------------------------------------------------
  204. alias xrxs_bp1_slip_damage? slip_damage?
  205. def slip_damage?
  206. return false if @slip_state_update_ban
  207. return xrxs_bp1_slip_damage?
  208. end
  209. #--------------------------------------------------------------------------
  210. # ● ステート自然解除 (ターンごとに呼び出し)
  211. #--------------------------------------------------------------------------
  212. alias xrxs_bp1_remove_states_auto remove_states_auto
  213. def remove_states_auto
  214. return if @slip_state_update_ban
  215. xrxs_bp1_remove_states_auto
  216. end
  217. end
  218. #==============================================================================
  219. # ■ Game_Actor
  220. #==============================================================================
  221. class Game_Actor < Game_Battler
  222. #--------------------------------------------------------------------------
  223. # ● セットアップ
  224. #--------------------------------------------------------------------------
  225. alias xrxs_bp1_setup setup
  226. def setup(actor_id)
  227. xrxs_bp1_setup(actor_id)
  228. @cp = 0
  229. @now_guarding = false
  230. @slip_state_update_ban = false
  231. end
  232. end
  233. #==============================================================================
  234. # ■ Game_Enemy
  235. #==============================================================================
  236. class Game_Enemy < Game_Battler
  237. #--------------------------------------------------------------------------
  238. # ● オブジェクト初期化
  239. #--------------------------------------------------------------------------
  240. alias xrxs_bp1_initialize initialize
  241. def initialize(troop_id, member_index)
  242. xrxs_bp1_initialize(troop_id, member_index)
  243. @cp = 0
  244. @now_guarding = false
  245. @slip_state_update_ban = false
  246. end
  247. end
  248. #==============================================================================
  249. # ■ Window_BattleStatus
  250. #==============================================================================
  251. class Window_BattleStatus < Window_Base
  252. #--------------------------------------------------------------------------
  253. # ○ 公開インスタンス変数
  254. #--------------------------------------------------------------------------
  255. attr_accessor :update_cp_only # CPメーターのみの更新
  256. #--------------------------------------------------------------------------
  257. # ● オブジェクト初期化
  258. #--------------------------------------------------------------------------
  259. alias xrxs_bp1_initialize initialize
  260. def initialize
  261. @update_cp_only = false
  262. xrxs_bp1_initialize
  263. end
  264. #--------------------------------------------------------------------------
  265. # ● リフレッシュ
  266. #--------------------------------------------------------------------------
  267. alias xrxs_bp1_refresh refresh
  268. def refresh
  269. unless @update_cp_only
  270. xrxs_bp1_refresh
  271. end
  272. refresh_cp
  273. end
  274. #--------------------------------------------------------------------------
  275. # ○ リフレッシュ(CPのみ)
  276. #--------------------------------------------------------------------------
  277. def refresh_cp
  278. for i in 0...$game_party.actors.size
  279. actor = $game_party.actors[i]
  280. width = [self.width*3/4 / XRXS_BP1::MAX, 80].max
  281. space = self.width / XRXS_BP1::MAX
  282. case XRXS_BP1::ALIGN
  283. when 0
  284. actor_x = i * space + 4
  285. when 1
  286. actor_x = (space * ((XRXS_BP1::MAX - $game_party.actors.size)/2.0 + i)).floor
  287. when 2
  288. actor_x = (i + XRXS_BP1::MAX - $game_party.actors.size) * space + 4
  289. end
  290. actor_x += self.x
  291. draw_actor_cp_meter(actor, actor_x, 96, width, 0)
  292. end
  293. end
  294. #--------------------------------------------------------------------------
  295. # ○ CPメーター の描画
  296. #--------------------------------------------------------------------------
  297. def draw_actor_cp_meter(actor, x, y, width = 156, type = 0)
  298. self.contents.font.color = system_color
  299. self.contents.fill_rect(x-1, y+27, width+2,6, Color.new(0, 0, 0, 255))
  300. if actor.cp == nil
  301. actor.cp = 0
  302. end
  303. w = width * [actor.cp,65535].min / 65535
  304. self.contents.fill_rect(x, y+28, w,1, Color.new(255, 255, 128, 255))
  305. self.contents.fill_rect(x, y+29, w,1, Color.new(255, 255, 0, 255))
  306. self.contents.fill_rect(x, y+30, w,1, Color.new(192, 192, 0, 255))
  307. self.contents.fill_rect(x, y+31, w,1, Color.new(128, 128, 0, 255))
  308. end
  309. end
  310. #==============================================================================
  311. # ■ Scene_Battle
  312. #==============================================================================
  313. class Scene_Battle
  314. #--------------------------------------------------------------------------
  315. # ● フレーム更新
  316. #--------------------------------------------------------------------------
  317. alias xrxs_bp1_update update
  318. def update
  319. xrxs_bp1_update
  320. # CP更新
  321. @cp_thread.update
  322. end
  323. #--------------------------------------------------------------------------
  324. # ● バトル終了
  325. # result : 結果 (0:勝利 1:敗北 2:逃走)
  326. #--------------------------------------------------------------------------
  327. alias xrxs_bp1_battle_end battle_end
  328. def battle_end(result)
  329. # CPカウントを停止する
  330. @cp_thread.stop
  331. # 呼び戻す
  332. xrxs_bp1_battle_end(result)
  333. end
  334. #--------------------------------------------------------------------------
  335. # ● プレバトルフェーズ開始
  336. #--------------------------------------------------------------------------
  337. alias xrxs_bp1_start_phase1 start_phase1
  338. def start_phase1
  339. @agi_total = 0
  340. # CP加算を開始する
  341. @cp_thread = Scene_Battle_CP.new
  342. # インデックスを計算
  343. @cp_escape_actor_command_index = @actor_command_window.height/32 - 1
  344. # アクターコマンドウィンドウに追加
  345. @actor_command_window.add_command("逃     跑")
  346. if !$game_temp.battle_can_escape
  347. @actor_command_window.disable_item(@cp_escape_actor_command_index)
  348. end
  349. # 呼び戻す
  350. xrxs_bp1_start_phase1
  351. end
  352. #--------------------------------------------------------------------------
  353. # ● パーティコマンドフェーズ開始
  354. #--------------------------------------------------------------------------
  355. alias xrxs_bp1_start_phase2 start_phase2
  356. def start_phase2
  357. xrxs_bp1_start_phase2
  358. @party_command_window.active = false
  359. @party_command_window.visible = false
  360. # CP加算を再開する
  361. @cp_thread.stop = false
  362. # 次へ
  363. start_phase3
  364. end
  365. #--------------------------------------------------------------------------
  366. # ● アクターコマンドウィンドウのセットアップ
  367. #--------------------------------------------------------------------------
  368. alias xrxs_bp1_phase3_setup_command_window phase3_setup_command_window
  369. def phase3_setup_command_window
  370. # CPスレッドを一時停止する
  371. @cp_thread.stop = true
  372. # ウィンドウのCP更新
  373. @status_window.refresh_cp
  374. # @active_battlerの防御を解除
  375. @active_battler.now_guarding = false
  376. # 効果音の再生
  377. Audio.se_play(DATA_SYSTEM_COMMAND_UP_SE) if DATA_SYSTEM_COMMAND_UP_SE != ""
  378. # 呼び戻す
  379. xrxs_bp1_phase3_setup_command_window
  380. end
  381. #--------------------------------------------------------------------------
  382. # ● フレーム更新 (アクターコマンドフェーズ : 基本コマンド)
  383. #--------------------------------------------------------------------------
  384. alias xrxs_bsp1_update_phase3_basic_command update_phase3_basic_command
  385. def update_phase3_basic_command
  386. # C ボタンが押された場合
  387. if Input.trigger?(Input::C)
  388. # アクターコマンドウィンドウのカーソル位置で分岐
  389. case @actor_command_window.index
  390. when @cp_escape_actor_command_index # 逃げる
  391. if $game_temp.battle_can_escape
  392. # 決定 SE を演奏
  393. $game_system.se_play($data_system.decision_se)
  394. # アクションを設定
  395. @active_battler.current_action.kind = 0
  396. @active_battler.current_action.basic = 4
  397. # 次のアクターのコマンド入力へ
  398. phase3_next_actor
  399. else
  400. # ブザー SE を演奏
  401. $game_system.se_play($data_system.buzzer_se)
  402. end
  403. return
  404. end
  405. end
  406. xrxs_bsp1_update_phase3_basic_command
  407. end
  408. #--------------------------------------------------------------------------
  409. # ● メインフェーズ開始
  410. #--------------------------------------------------------------------------
  411. alias xrxs_bp1_start_phase4 start_phase4
  412. def start_phase4
  413. # 呼び戻す
  414. xrxs_bp1_start_phase4
  415. # CPスレッドを一時停止する
  416. unless @action_battlers.empty?
  417. @cp_thread.stop = true
  418. end
  419. end
  420. #--------------------------------------------------------------------------
  421. # ● 行動順序作成
  422. #--------------------------------------------------------------------------
  423. alias xrxs_bp1_make_action_orders make_action_orders
  424. def make_action_orders
  425. xrxs_bp1_make_action_orders
  426. # 全員のCPを確認
  427. exclude_battler = []
  428. for battler in @action_battlers
  429. # CPが不足している場合は @action_battlers から除外する
  430. if battler.cp < 65535
  431. exclude_battler.push(battler)
  432. end
  433. end
  434. @action_battlers -= exclude_battler
  435. end
  436. #--------------------------------------------------------------------------
  437. # ● フレーム更新 (メインフェーズ ステップ 1 : アクション準備)
  438. #--------------------------------------------------------------------------
  439. alias xrxs_bp1_update_phase4_step1 update_phase4_step1
  440. def update_phase4_step1
  441. # 初期化
  442. @phase4_act_continuation = 0
  443. # 勝敗判定
  444. if judge
  445. @cp_thread.stop
  446. # 勝利または敗北の場合 : メソッド終了
  447. return
  448. end
  449. # 未行動バトラー配列の先頭から取得
  450. @active_battler = @action_battlers[0]
  451. # ステータス更新をCPだけに限定。
  452. @status_window.update_cp_only = true
  453. # ステート更新を禁止。
  454. @active_battler.slip_state_update_ban = true if @active_battler != nil
  455. # 戻す
  456. xrxs_bp1_update_phase4_step1
  457. # @status_windowがリフレッシュされなかった場合は手動でリフレッシュ(CPのみ)
  458. if @phase4_step != 2
  459. # リフレッシュ
  460. @status_window.refresh
  461. # 軽量化:たったコレだけΣ(?w?
  462. Graphics.frame_reset
  463. end
  464. # 禁止を解除
  465. @status_window.update_cp_only = false
  466. @active_battler.slip_state_update_ban = false if @active_battler != nil
  467. end
  468. #--------------------------------------------------------------------------
  469. # ● フレーム更新 (メインフェーズ ステップ 2 : アクション開始)
  470. #--------------------------------------------------------------------------
  471. alias xrxs_bp1_update_phase4_step2 update_phase4_step2
  472. def update_phase4_step2
  473. # 強制アクションでなければ
  474. unless @active_battler.current_action.forcing
  475. # 制約が [敵を通常攻撃する] か [味方を通常攻撃する] の場合
  476. if @active_battler.restriction == 2 or @active_battler.restriction == 3
  477. # アクションに攻撃を設定
  478. @active_battler.current_action.kind = 0
  479. @active_battler.current_action.basic = 0
  480. end
  481. # 制約が [行動できない] の場合
  482. if @active_battler.restriction == 4
  483. # アクション強制対象のバトラーをクリア
  484. $game_temp.forcing_battler = nil
  485. if @phase4_act_continuation == 0 and @active_battler.cp >= 65535
  486. # ステート自然解除
  487. @active_battler.remove_states_auto
  488. # CP消費
  489. @active_battler.cp -= 65535
  490. # ステータスウィンドウをリフレッシュ
  491. @status_window.refresh
  492. end
  493. # ステップ 1 に移行
  494. @phase4_step = 1
  495. return
  496. end
  497. end
  498. # アクションの種別で分岐
  499. case @active_battler.current_action.kind
  500. when 0
  501. # 攻撃?防御?逃げる?何もしない時の共通消費CP
  502. @active_battler.cp -= CP_COST_BASIC_ACTIONS if @phase4_act_continuation == 0
  503. when 1
  504. # スキル使用時の消費CP
  505. @active_battler.cp -= CP_COST_SKILL_ACTION if @phase4_act_continuation == 0
  506. when 2
  507. # アイテム使用時の消費CP
  508. @active_battler.cp -= CP_COST_ITEM_ACTION if @phase4_act_continuation == 0
  509. end
  510. # ステート自然解除
  511. @active_battler.remove_states_auto
  512. # 呼び戻す
  513. xrxs_bp1_update_phase4_step2
  514. end
  515. #--------------------------------------------------------------------------
  516. # ● 基本アクション 結果作成
  517. #--------------------------------------------------------------------------
  518. alias xrxs_bp1_make_basic_action_result make_basic_action_result
  519. def make_basic_action_result
  520. # 攻撃の場合
  521. if @active_battler.current_action.basic == 0 and @phase4_act_continuation == 0
  522. @active_battler.cp -= CP_COST_BASIC_ATTACK # 攻撃時のCP消費
  523. end
  524. # 防御の場合
  525. if @active_battler.current_action.basic == 1 and @phase4_act_continuation == 0
  526. @active_battler.cp -= CP_COST_BASIC_GUARD # 防御時のCP消費
  527. # @active_battlerの防御をON
  528. @active_battler.now_guarding = true
  529. end
  530. # 敵の逃げるの場合
  531. if @active_battler.is_a?(Game_Enemy) and
  532. @active_battler.current_action.basic == 2 and @phase4_act_continuation == 0
  533. @active_battler.cp -= CP_COST_BASIC_ESCAPE # 逃走時のCP消費
  534. end
  535. # 何もしないの場合
  536. if @active_battler.current_action.basic == 3 and @phase4_act_continuation == 0
  537. @active_battler.cp -= CP_COST_BASIC_NOTHING # 何もしない時のCP消費
  538. end
  539. # 逃げるの場合
  540. if @active_battler.current_action.basic == 4 and @phase4_act_continuation == 0
  541. @active_battler.cp -= CP_COST_BASIC_ESCAPE # 逃走時のCP消費
  542. # 逃走可能ではない場合
  543. if $game_temp.battle_can_escape == false
  544. # ブザー SE を演奏
  545. $game_system.se_play($data_system.buzzer_se)
  546. return
  547. end
  548. # 逃走処理
  549. update_phase2_escape
  550. return
  551. end
  552. # 呼び戻す
  553. xrxs_bp1_make_basic_action_result
  554. end
  555. #--------------------------------------------------------------------------
  556. # ● フレーム更新 (メインフェーズ ステップ 6 : リフレッシュ)
  557. #--------------------------------------------------------------------------
  558. alias xrxs_bp1_update_phase4_step6 update_phase4_step6
  559. def update_phase4_step6
  560. # スリップダメージ
  561. if @active_battler.hp > 0 and @active_battler.slip_damage?
  562. @active_battler.slip_damage_effect
  563. @active_battler.damage_pop = true
  564. # ステータスウィンドウをリフレッシュ
  565. @status_window.refresh
  566. end
  567. # 呼び戻す
  568. xrxs_bp1_update_phase4_step6
  569. end
  570. end
  571.  
  572.  
  573. #==============================================================================
  574. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  575. #==============================================================================




使用的除主角外的人物自动脚本
RUBY 代码复制
  1. #==============================================================================
  2. # ★【  自动战斗  】★
  3. #==============================================================================
  4. #  by -> 芯☆淡如水
  5. #==============================================================================
  6. # ● 使用方法:复制该脚本,插入到 main 前。
  7. #==============================================================================
  8. # ● 说明:
  9. #         自动战斗,顾名思义,就是角色选择“自动战斗”后,无需玩家给角色下达
  10. #      指令,角色仍可自己行动。
  11. #        
  12. #         该自动战斗有 2 个模式:普通自动战斗 和 AI自动战斗。2 种模式的切换
  13. #       使用下面设置项的开关。
  14. #
  15. #         角色在 普通自动战斗 时,只是普通攻击敌人。选择的敌人目标偏向血较少
  16. #      者。
  17. #
  18. #         角色在 AI自动战斗 时,判断角色行动类型的流程为:复活同伴 --》 恢复
  19. #      同伴(HP和SP)--》攻击。
  20. #         如果队伍中有同伴死亡,有很大几率复活同伴(具体多大几率就不透露),
  21. #      死亡的同伴个数越多,几率越大。复活同伴的前提条件是有复活类药品或特技。
  22. #         跳过复活同伴是恢复同伴,恢复同伴的几率以整体的剩余HP/SP的百分比来
  23. #      算,百分比越小,几率越高。单体恢复同伴HP/SP的恢复对象,偏向HP/SP较少
  24. #      者。恢复同伴的前提条件是有恢复类药品或特技。
  25. #         最后是攻击,攻击判断之前有一定的几率对同伴使用 增益特技。攻击分为
  26. #      普通攻击和使用特技,几率以角色的不同而不同,如果是战士类型的角色,普通
  27. #      攻击的几率高于使用特技的几率;法师类型的角色则相反。使用特技时有一定的
  28. #      几率使用不良状态特技。所有使用特技都是以角色已习得的特技为基础。普通攻
  29. #      击和使用单体攻击特技的对象目标,也是偏向血较少者。
  30. #
  31. #
  32. #   ■ 恢复:     自动战斗者在恢复同伴时,首先确定恢复对象,根据对象需要恢复的
  33. #               HP/SP 的多少,来确定使用的物品或特技。需要恢复的对象越多,使用
  34. #               “己方全体”的物品或特技的几率越大,单个的恢复对象是不会使用
  35. #               “己方全体”的物品或特技。
  36. #              
  37. #                比如确定了某个恢复对象,该对象需要回复 HP 100 ,所能使用的物品
  38. #               或特技有 3 种:回复 HP 60 ;回复 HP 110 ;回复 HP 220 。那么自动
  39. #               战斗者会选择 “回复 HP 110” 的这个物品或特技来恢复该对象。
  40. #
  41. #
  42. #   ■ 特技攻击:  如果自动战斗者能够使用“敌全体”特技,并且敌人的数量是 2 个
  43. #               或以上时,自动战斗者有几率使用“敌全体”特技,敌人数量越多,几
  44. #               率越大。
  45. #
  46. #                  如果是单个攻击对象,首先确定对象,根据该对象剩余的 HP 来选择
  47. #               特技。在这之前会先判断普通攻击能否打倒该对象,如果能打倒该对象,
  48. #               就使用普通攻击,而不使用特技了。
  49. #
  50. #               比如:例1:攻击对象剩余HP:160 ,自动战斗者可使用的特技有:对该
  51. #                          对象伤害 HP 180 和 伤害 HP 260 两个特技,但自动战斗者
  52. #                          对该对象的普通攻击伤害为:HP 200 ,那么自动战斗者会
  53. #                          选择普通攻击而不使用特技。
  54. #
  55. #                     例2:攻击对象剩余HP:2000 ,自动战斗者可使用的特技有:对该
  56. #                          对象伤害 HP 200 ; 伤害 HP 600 ;伤害 HP 1000 三种,
  57. #                          那么自动战斗者会选择 伤害 HP 1000 的这个特技来攻击该
  58. #                          对象。
  59. #==============================================================================
  60. # ● 设置:
  61. #------------------------------------------------------------------------------
  62. # 打开或关闭 自动战斗功能 的开关 ID。
  63. #AUTO_SWEITCHE = 1
  64. #------------------------------------------------------------------------------
  65. # 是否 AI自动战斗 的开关 ID。该开关打开为 AI自动;关闭为 普通自动。
  66. #AI_AUTO_SWEITCHE = 2
  67. #------------------------------------------------------------------------------
  68. # 角色自动战斗时,自动提示的等待时间(帧)。
  69. #WAIT_TIME = 50
  70. #------------------------------------------------------------------------------
  71. # 增益状态 特技 ID 。
  72. UP_PLUS_SKILLS = [53, 54]
  73. #------------------------------------------------------------------------------
  74. # 不良状态 特技 ID 。
  75. DOWN_PLUS_SKILLS = [41, 46]
  76. #=============================================================================
  77. ##############################################################################
  78. #=============================================================================
  79. class Game_Actor < Game_Battler
  80.   #--------------------------------------------------------------------------
  81.   attr_accessor :auto_battle
  82.   attr_accessor :auto_battle_targets
  83.   #--------------------------------------------------------------------------
  84.   alias add_setup_xdrs setup
  85.   def setup(actor_id)
  86.     @auto_battle = false
  87.     @auto_battle_targets = []
  88.     add_setup_xdrs(actor_id)
  89.   end
  90. end
  91. #==============================================================================
  92. class Scene_Battle
  93.   #--------------------------------------------------------------------------
  94.   def main
  95.     # 初始化战斗用的各种暂时数据
  96.     $game_temp.in_battle = true
  97.     $game_temp.battle_turn = 0
  98.     $game_temp.battle_event_flags.clear
  99.     $game_temp.battle_abort = false
  100.     $game_temp.battle_main_phase = false
  101.     $game_temp.battleback_name = $game_map.battleback_name
  102.     $game_temp.forcing_battler = nil
  103.     # 初始化战斗用事件解释器
  104.     $game_system.battle_interpreter.setup(nil, 0)
  105.     # 准备队伍
  106.     @troop_id = $game_temp.battle_troop_id
  107.     $game_troop.setup(@troop_id)
  108.     # 生成角色命令窗口
  109.     s1 = $data_system.words.attack
  110.     s2 = $data_system.words.skill
  111.     s3 = $data_system.words.guard
  112.     s4 = $data_system.words.item
  113.     #s5 = "自动"
  114.     s6 = "逃跑"
  115.     #if $game_switches[AUTO_SWEITCHE]
  116.       #@actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
  117.       #@actor_command_window.y = 96
  118.     #else  
  119.       @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, s6])
  120.       @actor_command_window.y = 128
  121.     #end
  122.     @actor_command_window.back_opacity = 160
  123.     @actor_command_window.active = false
  124.     @actor_command_window.visible = false
  125.  
  126.     # 生成其它窗口
  127.     #
  128.     #@auto_top = Window_Base.new(0, 256, 160, 64)
  129.     #@auto_top.contents = Bitmap.new(@auto_top.width - 32, @auto_top.height - 32)
  130.     #@auto_top.contents.draw_text(0, 0, 138, 32,"确定键:取消自动")
  131.     #@auto_top.back_opacity = 160
  132.     #@auto_top.visible = false
  133.     #
  134.     @party_command_window = Window_PartyCommand.new
  135.     @help_window = Window_Help.new
  136.     @help_window.back_opacity = 160
  137.     @help_window.visible = false
  138.     @status_window = Window_BattleStatus.new
  139.     @message_window = Window_Message.new
  140.     # 生成活动块
  141.     @spriteset = Spriteset_Battle.new
  142.     # 初始化等待计数
  143.     @wait_count = 0
  144.     #@auto_wait_count = 0
  145.     # 执行过渡
  146.     if $data_system.battle_transition == ""
  147.       Graphics.transition(20)
  148.     else
  149.       Graphics.transition(40, "Graphics/Transitions/" +
  150.         $data_system.battle_transition)
  151.     end
  152.     # 开始自由战斗回合
  153.     start_phase1
  154.     # 主循环
  155.     loop do
  156.       # 刷新游戏画面
  157.       Graphics.update
  158.       # 刷新输入信息
  159.       Input.update
  160.       # 刷新画面
  161.       update
  162.       # 如果画面切换的话就中断循环
  163.       if $scene != self
  164.         break
  165.       end
  166.     end
  167.     # 刷新地图
  168.     $game_map.refresh
  169.     # 准备过渡
  170.     Graphics.freeze
  171.     # 释放窗口
  172.     #@auto_top.dispose
  173.     @actor_command_window.dispose
  174.     @party_command_window.dispose
  175.     @help_window.dispose
  176.     @status_window.dispose
  177.     @message_window.dispose
  178.     if @skill_window != nil
  179.       @skill_window.dispose
  180.     end
  181.     if @item_window != nil
  182.       @item_window.dispose
  183.     end
  184.     if @result_window != nil
  185.       @result_window.dispose
  186.     end
  187.     # 释放活动块
  188.     @spriteset.dispose
  189.     # 标题画面切换中的情况
  190.     if $scene.is_a?(Scene_Title)
  191.       # 淡入淡出画面
  192.       Graphics.transition
  193.       Graphics.freeze
  194.     end
  195.     # 战斗测试或者游戏结束以外的画面切换中的情况
  196.     if $BTEST and not $scene.is_a?(Scene_Gameover)
  197.       $scene = nil
  198.     end
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   def start_phase2
  202.     # 转移到回合 2
  203.     @phase = 2
  204.     # 设置角色为非选择状态
  205.     @actor_index = -1
  206.     @active_battler = nil
  207.     unless $game_party.inputable?
  208.       # 开始主回合
  209.       start_phase4
  210.       return
  211.     end
  212.     start_phase3
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   def phase3_prior_actor
  216.     # 循环
  217.     begin
  218.       # 角色的明灭效果 OFF
  219.       if @active_battler != nil
  220.         @active_battler.blink = false
  221.       end
  222.       # 最初的角色的情况下
  223.       if @actor_index == 0
  224.         $game_system.se_play($data_system.buzzer_se)
  225.         return
  226.       end
  227.       # 返回角色索引
  228.       @actor_index -= 1
  229.       @active_battler = $game_party.actors[@actor_index]
  230.       @active_battler.blink = true
  231.     # 如果角色是在无法接受指令的状态就再试
  232.     end until @active_battler.inputable?
  233.     # 设置角色的命令窗口
  234.     phase3_setup_command_window
  235.   end
  236. #--------------------------------------------------------------------------
  237.   def update_phase3_basic_command
  238. #=================================================   
  239.     if @actor_index == 0 #当前行动者是主角
  240. #=================================================
  241.     # 按下 B 键的情况下
  242.     if Input.trigger?(Input::B)
  243.       # 演奏取消 SE
  244.       $game_system.se_play($data_system.cancel_se)
  245.       # 转向前一个角色的指令输入
  246.       phase3_prior_actor
  247.       return
  248.     end
  249.     # 按下 C 键的情况下
  250.     if Input.trigger?(Input::C)
  251.       # 角色指令窗口光标位置分之
  252.       case @actor_command_window.index
  253.       when 0  # 攻击
  254.         # 演奏确定 SE
  255.         $game_system.se_play($data_system.decision_se)
  256.         # 设置行动
  257.         @active_battler.current_action.kind = 0
  258.         @active_battler.current_action.basic = 0
  259.         # 开始选择敌人
  260.         start_enemy_select
  261.       when 1  # 特技
  262.         # 演奏确定 SE
  263.         $game_system.se_play($data_system.decision_se)
  264.         # 设置行动
  265.         @active_battler.current_action.kind = 1
  266.         # 开始选择特技
  267.         start_skill_select
  268.       when 2  # 防御
  269.         # 演奏确定 SE
  270.         $game_system.se_play($data_system.decision_se)
  271.         # 设置行动
  272.         @active_battler.current_action.kind = 0
  273.         @active_battler.current_action.basic = 1
  274.         # 转向下一位角色的指令输入
  275.         phase3_next_actor
  276.       when 3  # 物品
  277.         # 演奏确定 SE
  278.         $game_system.se_play($data_system.decision_se)
  279.         # 设置行动
  280.         @active_battler.current_action.kind = 2
  281.         # 开始选择物品
  282.         start_item_select
  283.      # when 4  # 自动
  284.      #   if $game_switches[AUTO_SWEITCHE]
  285.      #     # 演奏确定 SE
  286.      #     $game_system.se_play($data_system.decision_se)
  287.      #     @actor_command_window.active = false
  288.      #     @actor_command_window.visible = false
  289.      #     @active_battler.auto_battle = true
  290.      #     phase3_next_actor
  291.      #   else
  292.      #      # 演奏确定 SE
  293.      #     $game_system.se_play($data_system.decision_se)
  294.           # 逃走处理
  295.      #     update_phase2_escape
  296.      #   end        
  297.       when 4  # 逃跑
  298.         # 不能逃跑的情况下
  299.         if $game_temp.battle_can_escape == false
  300.           # 演奏冻结 SE
  301.           $game_system.se_play($data_system.buzzer_se)
  302.           return
  303.         end
  304.         # 演奏确定 SE
  305.         $game_system.se_play($data_system.decision_se)
  306.         # 逃走处理
  307.         update_phase2_escape
  308.       end
  309.       return
  310.     end
  311.   else  # 当前行动者是队友
  312.     @actor_command_window.active = false
  313.     @actor_command_window.visible = false
  314.     @active_battler.auto_battle = true
  315.     phase3_next_actor
  316.     return
  317.     end
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   #alias add_phase3_setup_command_window_xdrs phase3_setup_command_window
  321.   #def phase3_setup_command_window
  322.   #  if @active_battler.auto_battle
  323.   #    @auto_wait_count = WAIT_TIME  
  324.   #    @auto_top.visible = true
  325.   #    @auto_top.x = @actor_index * 160
  326.   #   return
  327.   #  end
  328.   #  add_phase3_setup_command_window_xdrs
  329.   #end
  330.   #--------------------------------------------------------------------------
  331.   #alias add_update_phase3_xdrs update_phase3
  332.   #def update_phase3
  333.   #  if @auto_wait_count > 0
  334.   #    update_wait_at
  335.   #    return
  336.   #  end
  337.   #  add_update_phase3_xdrs
  338.   #end
  339.   #--------------------------------------------------------------------------
  340.   #def update_wait_at
  341.   #  @auto_wait_count -= 1
  342.   #  if @auto_wait_count == 0
  343.   #    $game_system.se_play($data_system.decision_se)
  344.   #    @auto_top.visible = false
  345.   #    phase3_next_actor
  346.   #    return
  347.   #  end
  348.   #  if Input.trigger?(Input::B)
  349.   #    $game_system.se_play($data_system.cancel_se)
  350.   #    @auto_wait_count = 0
  351.   #    phase3_prior_actor
  352.   #    return
  353.   #  end
  354.   #  if Input.trigger?(Input::C)
  355.   #    $game_system.se_play($data_system.decision_se)
  356.   #    @auto_wait_count = 0
  357.   #    @active_battler.auto_battle = false
  358.   #    @auto_top.visible = false
  359.   #    @actor_index -= 1
  360.   #    phase3_next_actor
  361.   #  end
  362.   #end
  363.   #--------------------------------------------------------------------------
  364.   def update_phase4_step2
  365.     # 如果不是强制行动
  366.     unless @active_battler.current_action.forcing
  367.       # 限制为 [敌人为普通攻击] 或 [我方为普通攻击] 的情况下
  368.       if @active_battler.restriction == 2 or @active_battler.restriction == 3
  369.         # 设置行动为攻击
  370.         @active_battler.current_action.kind = 0
  371.         @active_battler.current_action.basic = 0
  372.       end
  373.       # 限制为 [不能行动] 的情况下
  374.       if @active_battler.restriction == 4
  375.         # 清除行动强制对像的战斗者
  376.         $game_temp.forcing_battler = nil
  377.         # 移至步骤 1
  378.         @phase4_step = 1
  379.         return
  380.       end
  381.     end
  382.     # 清除对像战斗者
  383.     @target_battlers = []
  384.     if @active_battler.is_a?(Game_Actor)
  385.       if @active_battler.auto_battle and not @active_battler.dead?
  386.         set_auto_battle
  387.         case @active_battler.current_action.kind
  388.         when 0  
  389.           make_basic_auto
  390.         when 1  
  391.           make_skill_auto
  392.         when 2  
  393.           make_item_auto
  394.         end
  395.         if @phase4_step == 2
  396.           @phase4_step = 3
  397.         end
  398.         return
  399.       end
  400.     end
  401.     # 行动种类分支
  402.     case @active_battler.current_action.kind
  403.     when 0  # 基本
  404.       make_basic_action_result
  405.     when 1  # 特技
  406.       make_skill_action_result
  407.     when 2  # 物品
  408.       make_item_action_result
  409.     end
  410.     # 移至步骤 3
  411.     if @phase4_step == 2
  412.       @phase4_step = 3
  413.     end
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   def make_basic_auto
  417.     case @active_battler.current_action.basic
  418.     when 0
  419.       @animation1_id = @active_battler.animation1_id
  420.       @animation2_id = @active_battler.animation2_id
  421.       if @active_battler.restriction == 3
  422.         target = $game_party.random_target_actor
  423.         @active_battler.auto_battle_targets = []
  424.         @active_battler.auto_battle_targets.push(target)
  425.       elsif @active_battler.restriction == 2
  426.         target = $game_troop.random_target_enemy
  427.         @active_battler.auto_battle_targets = []
  428.         @active_battler.auto_battle_targets.push(target)
  429.       end
  430.       @target_battlers = @active_battler.auto_battle_targets
  431.       for target in @target_battlers
  432.         target.attack_effect(@active_battler)
  433.       end
  434.       return
  435.     when 1
  436.       @help_window.set_text($data_system.words.guard, 1)
  437.       return
  438.     end
  439.   end
  440.   #--------------------------------------------------------------------------
  441.   def make_skill_auto
  442.     @skill = $data_skills[@active_battler.current_action.skill_id]
  443.     unless @active_battler.current_action.forcing
  444.       unless @active_battler.skill_can_use?(@skill.id)
  445.         $game_temp.forcing_battler = nil
  446.         @phase4_step = 1
  447.         return
  448.       end
  449.     end
  450.     @active_battler.sp -= @skill.sp_cost
  451.     @status_window.refresh
  452.     @help_window.set_text(@skill.name, 1)
  453.     @animation1_id = @skill.animation1_id
  454.     @animation2_id = @skill.animation2_id
  455.     @common_event_id = @skill.common_event_id
  456.     @target_battlers = @active_battler.auto_battle_targets
  457.     for target in @target_battlers
  458.       target.skill_effect(@active_battler, @skill)
  459.     end
  460.   end
  461.   #--------------------------------------------------------------------------
  462.   def make_item_auto
  463.     @item = $data_items[@active_battler.current_action.item_id]
  464.     unless $game_party.item_can_use?(@item.id)
  465.       @phase4_step = 1
  466.       return
  467.     end
  468.     if @item.consumable
  469.       $game_party.lose_item(@item.id, 1)
  470.     end
  471.     @help_window.set_text(@item.name, 1)
  472.     @animation1_id = @item.animation1_id
  473.     @animation2_id = @item.animation2_id
  474.     @common_event_id = @item.common_event_id
  475.     @target_battlers = @active_battler.auto_battle_targets
  476.     for target in @target_battlers
  477.       target.item_effect(@item)
  478.     end
  479.   end
  480.   #--------------------------------------------------------------------------
  481.   alias add_update_phase4_step6_xdrs update_phase4_step6
  482.   def update_phase4_step6
  483.     @active_battler.auto_battle_targets = [] if @active_battler.is_a?(Game_Actor)
  484.     add_update_phase4_step6_xdrs
  485.   end
  486.   #==============================================================================
  487.   #==============================================================================
  488.   def set_auto_battle
  489.     #if $game_switches[AI_AUTO_SWEITCHE]
  490.       ai_auto_battle
  491.     #else
  492.       #base_atk
  493.     #end
  494.   end
  495.   #----------------------------------------------------------------------------
  496.   def ai_auto_battle
  497.     set_probability
  498.     if rand (100) < @f_probability
  499.       f_actor
  500.       return
  501.     end
  502.     judge_r_actor
  503.   end
  504.   #----------------------------------------------------------------------------
  505.   def set_probability
  506.     @f_probability = 0
  507.     h = mh = s = ms = 0.0
  508.     if dead_actors != []
  509.       @f_probability = 70
  510.       @f_probability += (dead_actors.size - 1) * 20
  511.     end
  512.     for actor in all_actors
  513.       h += actor.hp
  514.       mh += actor.maxhp
  515.       s += actor.sp
  516.       ms += actor.maxsp
  517.     end
  518.     @rh_probability = 100 - (h / mh * 100).ceil
  519.     @rh_probability += pressing_actor_hp.size * 30
  520.     @rs_probability = 100 - (s / ms * 100).ceil
  521.     @rs_probability += pressing_actor_sp.size * 30
  522.   end
  523.   #----------------------------------------------------------------------------
  524.   def f_actor
  525.     @f_skills = @f_items = []
  526.     for id in @active_battler.skills
  527.       skill = $data_skills[id]
  528.       if @active_battler.skill_can_use?(id) and [5, 6].include?(skill.scope)
  529.         @f_skills.push(skill)
  530.       end
  531.     end
  532.     for id in 1...$data_items.size
  533.       item = $data_items[id]
  534.       if $game_party.item_number(id) > 0 and [5, 6].include?(item.scope)
  535.         @f_items.push(item)
  536.       end
  537.     end
  538.     if @f_skills != [] or @f_items != []
  539.       if rand (2) == 0
  540.         if @f_skills != []
  541.           f_actor_skill
  542.           return
  543.         end
  544.         f_actor_item
  545.         return
  546.       else
  547.         if @f_items != []
  548.           f_actor_item
  549.           return
  550.         end
  551.         f_actor_skill
  552.         return
  553.       end
  554.     end
  555.     judge_r_actor
  556.   end
  557.   #----------------------------------------------------------------------------
  558.   def f_actor_skill
  559.     @active_battler.current_action.kind = 1
  560.     skill = @f_skills[rand (@f_skills.size)]
  561.     @active_battler.current_action.skill_id = skill.id
  562.     set_autobattler_targets
  563.   end
  564.   #----------------------------------------------------------------------------
  565.   def f_actor_item
  566.     @active_battler.current_action.kind = 2
  567.     item = @f_items[rand (@f_items.size)]
  568.     @active_battler.current_action.item_id = item.id
  569.     set_autobattler_targets
  570.   end
  571.   #----------------------------------------------------------------------------
  572.   def judge_r_actor
  573.     if @rh_probability >= 30 and rand (120) < @rh_probability
  574.       r_actor_hp
  575.       return
  576.     end
  577.     if @rs_probability >= 50 and rand (150) < @rs_probability
  578.       r_actor_sp
  579.       return
  580.     end
  581.     judge_battle
  582.   end
  583.   #----------------------------------------------------------------------------
  584.   def r_actor_hp
  585.     if recover_hp_items != [] or recover_hp_skills != []   
  586.       if rand (2) == 0
  587.         if recover_hp_items != []
  588.           r_hp_item
  589.           return
  590.         end
  591.         r_hp_skill
  592.         return
  593.       else
  594.         if recover_hp_skills != []
  595.           r_hp_skill
  596.           return
  597.         end
  598.         r_hp_item
  599.         return
  600.       end
  601.     end
  602.     if @rs_probability >= 50 and rand (150) < @rs_probability
  603.       r_actor_sp
  604.       return
  605.     end
  606.     judge_battle
  607.   end
  608.   #----------------------------------------------------------------------------
  609.   def r_actor_sp
  610.     if recover_sp_items != []   
  611.       r_sp_item
  612.       return
  613.     end
  614.     judge_battle
  615.   end
  616.   #----------------------------------------------------------------------------
  617.   def r_hp_item
  618.     @active_battler.current_action.kind = 2
  619.     date = []
  620.     items = []
  621.     for actor in all_actors
  622.       if actor.hp * 100 < actor.maxhp * 90
  623.         date.push(actor)
  624.       end
  625.     end
  626.     for item in recover_hp_items
  627.       items.push(item) if item.scope == 4
  628.     end
  629.     if ! items.empty? and date.size >= 2
  630.       n = 10
  631.       n += (date.size - 1) * 20
  632.       if rand (100) < n
  633.         item = items[rand (items.size)]
  634.         @active_battler.current_action.item_id = item.id
  635.         @active_battler.auto_battle_targets = all_actors
  636.         return
  637.       end
  638.     end
  639.     now_items = recover_hp_items - items
  640.     if now_items.empty?
  641.       judge_battle
  642.       return
  643.     end
  644.     @active_battler.auto_battle_targets.push(targets_actor_hp)
  645.     target = @active_battler.auto_battle_targets[0]
  646.     set_use_item(now_items, target, 0)
  647.   end
  648.   #----------------------------------------------------------------------------
  649.   def r_sp_item
  650.     @active_battler.current_action.kind = 2
  651.     date = []
  652.     items = []
  653.     for actor in all_actors
  654.       if actor.sp * 100 < actor.maxsp * 60
  655.         date.push(actor)
  656.       end
  657.     end
  658.     for item in recover_sp_items
  659.       items.push(item) if item.scope == 4
  660.     end
  661.     if ! items.empty? and date.size >= 2
  662.       n = 10
  663.       n += (date.size - 1) * 20
  664.       if rand (100) < n
  665.         item = items[rand (items.size)]
  666.         @active_battler.current_action.item_id = item.id
  667.         @active_battler.auto_battle_targets = all_actors
  668.         return
  669.       end
  670.     end
  671.     now_items = recover_sp_items - items
  672.     if now_items.empty?
  673.       judge_battle
  674.       return
  675.     end
  676.     @active_battler.auto_battle_targets.push(targets_actor_sp)
  677.     target = @active_battler.auto_battle_targets[0]
  678.     set_use_item(now_items, target, 1)
  679.   end
  680.   #----------------------------------------------------------------------------
  681.   def r_hp_skill
  682.     date = []
  683.     skills = []
  684.     for actor in all_actors
  685.       if actor.hp * 100 < actor.maxhp * 90
  686.         date.push(actor)
  687.       end
  688.     end
  689.     for skill in recover_hp_skills
  690.       skills.push(skill) if skill.scope == 4
  691.     end
  692.     if ! skills.empty? and date.size >= 2
  693.       n = 20
  694.       n += (date.size - 1) * 20
  695.       if rand (100) < n
  696.         @active_battler.current_action.kind = 1
  697.         skill = skills[rand(skills.size)]
  698.         @active_battler.current_action.skill_id = skill.id
  699.         @active_battler.auto_battle_targets = all_actors
  700.         return
  701.       end
  702.     end
  703.     now_skills = recover_hp_skills - skills
  704.     if now_skills.empty?
  705.       judge_battle
  706.       return
  707.     end
  708.     @active_battler.current_action.kind = 1
  709.     @active_battler.auto_battle_targets.push(targets_actor_hp)
  710.     target = @active_battler.auto_battle_targets[0]
  711.     set_use_skill(now_skills, target)
  712.   end
  713.   #---------------------------------------------------------------------------
  714.   def judge_battle
  715.     if up_plus_skills != []
  716.       if rand (100) < 20
  717.         use_up_skill
  718.         return
  719.       end
  720.     end
  721.     battle
  722.   end
  723.   #---------------------------------------------------------------------------
  724.   def battle
  725.     n = 100 - @active_battler.hp * 100 / @active_battler.maxhp
  726.     if n > 80
  727.       if rand (150) < n
  728.         @active_battler.current_action.kind = 0
  729.         @active_battler.current_action.basic = 1
  730.         return
  731.       end
  732.     end
  733.     if @active_battler.int > @active_battler.str
  734.       n = 80
  735.     elsif @active_battler.int == @active_battler.str
  736.       n = 60
  737.     else
  738.       n = 40
  739.     end
  740.     if rand (100) < n
  741.       use_skill
  742.     else
  743.       base_atk
  744.     end
  745.   end
  746.   #---------------------------------------------------------------------------
  747.   def use_skill
  748.     if down_plus_skills != []
  749.       if rand (100) < 20
  750.         use_down_skill
  751.         return
  752.       end
  753.     end
  754.     if att_skills != []
  755.       use_att_skill
  756.       return
  757.     end
  758.     base_atk
  759.   end
  760.   #---------------------------------------------------------------------------
  761.   def use_up_skill
  762.     @active_battler.current_action.kind = 1
  763.     skill = up_plus_skills[rand (up_plus_skills.size)]
  764.     @active_battler.current_action.skill_id = skill.id
  765.     set_autobattler_targets
  766.   end
  767.   #--------------------------------------------------------------------------
  768.   def use_down_skill
  769.     @active_battler.current_action.kind = 1
  770.     skill = down_plus_skills[rand (down_plus_skills.size)]
  771.     @active_battler.current_action.skill_id = skill.id
  772.     set_autobattler_targets
  773.   end
  774.   #--------------------------------------------------------------------------
  775.   def use_att_skill
  776.     @active_battler.current_action.kind = 1
  777.     date = []
  778.     for skill in att_skills
  779.       date.push(skill) if skill.scope == 2
  780.     end
  781.     if all_enemys.size >= 2
  782.       n = 10
  783.       n += (all_enemys.size - 1) * 10
  784.       n = [n, 80].min
  785.       if rand (100) < n and ! date.empty?
  786.         skill = date[rand (date.size)]
  787.         @active_battler.current_action.skill_id = skill.id
  788.         @active_battler.auto_battle_targets = all_enemys
  789.         return
  790.       end
  791.     end
  792.     now_skills = att_skills - date
  793.     if now_skills.empty?
  794.       base_atk
  795.       return
  796.     end
  797.     @active_battler.auto_battle_targets.push(targets_enemy_hp)
  798.     target = @active_battler.auto_battle_targets[0]
  799.     if use_base_atk?(target)
  800.       base_atk
  801.       return
  802.     end
  803.     set_use_skill(now_skills, target)
  804.   end
  805.   #----------------------------------------------------------------------------
  806.   def base_atk
  807.     @active_battler.current_action.kind = 0
  808.     @active_battler.current_action.basic = 0
  809.     if @active_battler.auto_battle_targets.empty?
  810.       @active_battler.auto_battle_targets.push(targets_enemy_hp)
  811.     end
  812.   end
  813.   ############################################################################
  814.   #----------------------------------------------------------------------------
  815.   def rand_actors
  816.     date = []
  817.     while date.size != $game_party.actors.size
  818.       actor = $game_party.actors[rand ($game_party.actors.size)]
  819.       date.push(actor) if not date.include?(actor)
  820.     end
  821.     return date
  822.   end
  823.   #----------------------------------------------------------------------------
  824.   def dead_actors
  825.     date = []
  826.     for actor in rand_actors
  827.       date.push(actor) if actor.dead?
  828.     end
  829.     return date
  830.   end
  831.   #----------------------------------------------------------------------------
  832.   def all_actors
  833.     date = []
  834.     for actor in rand_actors
  835.       date.push(actor) if actor.exist?
  836.     end
  837.     return date
  838.   end
  839.   #----------------------------------------------------------------------------
  840.   def targets_actor_hp
  841.     if pressing_actor_hp != []      
  842.       target = pressing_actor_hp[rand (pressing_actor_hp.size)]
  843.       return target
  844.     end
  845.     date = []
  846.     for actor in all_actors
  847.       if actor.hp * 100 < actor.maxhp * 90
  848.         date.push(actor)
  849.       end
  850.     end
  851.     target = nil
  852.     if date != []
  853.       for actor in date
  854.         hn = 100 - actor.hp * 100 / actor.maxhp
  855.         if rand (100) < hn
  856.           target = actor
  857.           break
  858.         end
  859.       end
  860.       target = date[rand (date.size)] if target == nil
  861.     end
  862.     target = all_actors[rand (all_actors.size)] if target == nil
  863.     return target
  864.   end
  865.   #----------------------------------------------------------------------------
  866.   def targets_actor_sp
  867.     if pressing_actor_sp != []      
  868.       target = pressing_actor_sp[rand (pressing_actor_sp.size)]
  869.       return target
  870.     end
  871.     date = []
  872.     for actor in all_actors
  873.       if actor.sp * 100 < actor.maxsp * 80
  874.         date.push(actor)
  875.       end
  876.     end
  877.     target = nil
  878.     if date != []
  879.       for actor in date
  880.         sn = 100 - actor.sp * 100 / actor.maxsp
  881.         if rand (100) < sn
  882.           target = actor
  883.           break
  884.         end
  885.       end
  886.       target = date[rand (date.size)] if target == nil
  887.     end
  888.     target = all_actors[rand (all_actors.size)] if target == nil
  889.     return target
  890.   end
  891.   #----------------------------------------------------------------------------
  892.   def pressing_actor_hp
  893.     date = []
  894.     for actor in all_actors
  895.       if actor.hp * 100 <= actor.maxhp * 30
  896.         date.push(actor)
  897.       end
  898.     end
  899.     return date
  900.   end
  901.   #----------------------------------------------------------------------------
  902.   def pressing_actor_sp
  903.     date = []
  904.     for actor in all_actors
  905.       if actor.sp * 100 <= actor.maxsp * 10
  906.         date.push(actor)
  907.       end
  908.     end
  909.     return date
  910.   end
  911.   #----------------------------------------------------------------------------
  912.   def recover_hp_items
  913.     date = []
  914.     for i in 1...$data_items.size
  915.       item = $data_items[i]
  916.       if $game_party.item_number(i) > 0 and [0, 1].include?(item.occasion)
  917.         if not [5, 6].include?(item.scope)
  918.           date.push(item) if item.recover_hp_rate > 0 or item.recover_hp > 0
  919.         end
  920.       end
  921.     end
  922.     return date
  923.   end
  924.   #----------------------------------------------------------------------------
  925.   def recover_sp_items
  926.     date = []
  927.     for i in 1...$data_items.size
  928.       item = $data_items[i]
  929.       if $game_party.item_number(i) > 0 and [0, 1].include?(item.occasion)
  930.         date.push(item) if item.recover_sp_rate > 0 or item.recover_sp > 0
  931.       end
  932.     end
  933.     return date
  934.   end
  935.   #----------------------------------------------------------------------------
  936.   def all_enemys
  937.     date = []
  938.     for enemy in $game_troop.enemies
  939.       date.push(enemy) if enemy.exist?
  940.     end
  941.     return date
  942.   end
  943.   #----------------------------------------------------------------------------
  944.   def targets_enemy_hp
  945.     date = []
  946.     for enemy in all_enemys
  947.       if enemy.hp < enemy.maxhp
  948.         date.push(enemy)
  949.       end
  950.     end
  951.     target = nil
  952.     if date != []
  953.       for enemy in date
  954.         hn = 100 - enemy.hp * 100 / enemy.maxhp
  955.         if rand (100) < hn
  956.           target = enemy
  957.           break
  958.         end
  959.       end
  960.     end
  961.     target = all_enemys[rand (all_enemys.size)] if target == nil
  962.     return target
  963.   end
  964.   #----------------------------------------------------------------------------
  965.   def recover_hp_skills
  966.     date = []
  967.     for id in @active_battler.skills
  968.       skill = $data_skills[id]
  969.       if @active_battler.skill_can_use?(id) and skill.power < 0
  970.         date.push(skill)
  971.       end
  972.     end
  973.     return date
  974.   end
  975.   #----------------------------------------------------------------------------
  976.   def att_skills
  977.     date = []
  978.     for id in @active_battler.skills
  979.       skill = $data_skills[id]
  980.       if @active_battler.skill_can_use?(id) and skill.power > 0
  981.         date.push(skill)
  982.       end
  983.     end
  984.     return date
  985.   end
  986.   #----------------------------------------------------------------------------
  987.   def up_plus_skills
  988.     date = []
  989.     for id in @active_battler.skills
  990.       skill = $data_skills[id]
  991.       if @active_battler.skill_can_use?(id) and UP_PLUS_SKILLS.include?(id)
  992.         date.push(skill)
  993.       end
  994.     end
  995.     return date
  996.   end
  997.   #----------------------------------------------------------------------------
  998.   def down_plus_skills
  999.     date = []
  1000.     for id in @active_battler.skills
  1001.       skill = $data_skills[id]
  1002.       if @active_battler.skill_can_use?(id) and DOWN_PLUS_SKILLS.include?(id)
  1003.         date.push(skill)
  1004.       end
  1005.     end
  1006.     return date
  1007.   end
  1008.   #---------------------------------------------------------------------------
  1009.   def set_use_item(items, target, toyp)
  1010.     @item = nil
  1011.     case toyp
  1012.     when 0
  1013.       date = []
  1014.       for item in items
  1015.         recover = item.recover_hp + item.recover_hp_rate * target.maxhp
  1016.         n = (recover - (target.maxhp - target.hp)).abs
  1017.         date.push(n)
  1018.       end
  1019.       date.sort!
  1020.       for item in items
  1021.         recover = item.recover_hp + item.recover_hp_rate * target.maxhp
  1022.         n = (recover - (target.maxhp - target.hp)).abs
  1023.         if n == date[0]
  1024.           @item = item
  1025.           break
  1026.         end
  1027.       end
  1028.     when 1
  1029.       date = []
  1030.       for item in items
  1031.         recover = item.recover_sp + item.recover_sp_rate * target.maxsp
  1032.         n = (recover - (target.maxsp - target.sp)).abs
  1033.         date.push(n)
  1034.       end
  1035.       date.sort!
  1036.       for item in items
  1037.         recover = item.recover_sp + item.recover_sp_rate * target.maxsp
  1038.         n = (recover - (target.maxsp - target.sp)).abs
  1039.         if n == date[0]
  1040.           @item = item
  1041.           break
  1042.         end
  1043.       end
  1044.     end
  1045.     @item = items[rand(items.size)] if @item == nil
  1046.     @active_battler.current_action.item_id = @item.id
  1047.   end
  1048.   #---------------------------------------------------------------------------
  1049.   def set_use_skill(skills, target)
  1050.     r_skills = []
  1051.     a_skills = []
  1052.     skill = nil
  1053.     for i in skills
  1054.       damage = count_skill_damage(i, target)
  1055.       if damage < 0
  1056.         n = (target.maxhp - target.hp + damage).abs
  1057.         r_skills.push(n)
  1058.       else
  1059.         n = (target.hp - damage).abs
  1060.         a_skills.push(n)
  1061.       end
  1062.     end
  1063.     r_skills.sort!
  1064.     a_skills.sort!
  1065.     for i in skills
  1066.       damage = count_skill_damage(i, target)
  1067.       if damage < 0
  1068.         n = (target.maxhp - target.hp + damage).abs
  1069.         skill = i if n == r_skills[0]
  1070.       else
  1071.         n = (target.hp - damage).abs
  1072.         skill = i if n == a_skills[0]
  1073.       end
  1074.     end
  1075.     skill = skills[rand (skills.sizs)] if skill == nil
  1076.     @active_battler.current_action.skill_id = skill.id
  1077.   end
  1078.   #----------------------------------------------------------------------------
  1079.   def count_skill_damage(skill, target)
  1080.     power = skill.power + @active_battler.atk * skill.atk_f / 100
  1081.     if power > 0
  1082.       power -= target.pdef * skill.pdef_f / 200
  1083.       power -= target.mdef * skill.mdef_f / 200
  1084.       power = [power, 0].max
  1085.     end
  1086.     rate = 20
  1087.     rate += (target.str * skill.str_f / 100)
  1088.     rate += (target.dex * skill.dex_f / 100)
  1089.     rate += (target.agi * skill.agi_f / 100)
  1090.     rate += (target.int * skill.int_f / 100)
  1091.     damage = power * rate / 20
  1092.     if skill.element_set == []
  1093.       rn = 100
  1094.     else
  1095.       rn = -100
  1096.       for i in skill.element_set
  1097.         rn = [rn, target.element_rate(i)].max
  1098.       end
  1099.     end
  1100.     damage = damage * rn / 100
  1101.     return damage
  1102.   end
  1103.   #----------------------------------------------------------------------------
  1104.   def use_base_atk?(target)
  1105.     atk = [@active_battler.atk - target.pdef / 2, 0].max
  1106.     damage = atk * (20 + @active_battler.str) / 20
  1107.     if @active_battler.element_set == []
  1108.       rn = 100
  1109.     else
  1110.       rn = -100
  1111.       for i in skill.element_set
  1112.         rn = [rn, target.element_rate(i)].max
  1113.       end
  1114.     end
  1115.     damage = damage * rn / 100
  1116.     n = target.hp - damage
  1117.     return true if n <= 0
  1118.     return false
  1119.   end
  1120.   #--------------------------------------------------------------------------
  1121.   def set_autobattler_targets
  1122.     case @active_battler.current_action.kind
  1123.     when 0
  1124.       @active_battler.auto_battle_targets.push(targets_enemy_hp)
  1125.     when 1
  1126.       skill = $data_skills[@active_battler.current_action.skill_id]
  1127.       if [5, 6].include?(skill.scope) and dead_actors != []
  1128.         if skill.scope == 5
  1129.           target = dead_actors[rand (dead_actors.size)]
  1130.           @active_battler.auto_battle_targets.push(target)
  1131.         else
  1132.           @active_battler.auto_battle_targets = dead_actors
  1133.         end
  1134.         return
  1135.       end
  1136.       if UP_PLUS_SKILLS.include?(skill.id)
  1137.         if skill.scope == 3
  1138.           target = all_actors[rand (all_actors.size)]
  1139.           @active_battler.auto_battle_targets.push(target)
  1140.         elsif skill.scope == 4
  1141.           @active_battler.auto_battle_targets = all_actors
  1142.         elsif skill.scope == 7
  1143.           @active_battler.auto_battle_targets.push(@active_battler)
  1144.         end
  1145.         return
  1146.       end
  1147.       if DOWN_PLUS_SKILLS.include?(skill.id)
  1148.         if skill.scope == 1
  1149.           target = all_enemys[rand (all_enemys.size)]
  1150.           @active_battler.auto_battle_targets.push(target)
  1151.         elsif skill.scope == 2
  1152.           @active_battler.auto_battle_targets = all_enemys
  1153.         end
  1154.         return
  1155.       end
  1156.       if skill.power > 0
  1157.         if skill.scope == 1
  1158.           @active_battler.auto_battle_targets.push(targets_enemy_hp)
  1159.         elsif skill.scope == 2
  1160.           @active_battler.auto_battle_targets = all_enemys
  1161.         end
  1162.       elsif skill.power < 0
  1163.         if skill.scope == 3
  1164.           @active_battler.auto_battle_targets.push(targets_actor_hp)
  1165.         elsif skill.scope == 4
  1166.           @active_battler.auto_battle_targets = all_actors
  1167.         end
  1168.       end
  1169.     when 2
  1170.       item = $data_items[@active_battler.current_action.item_id]
  1171.       case item.scope
  1172.       when 1
  1173.         @active_battler.auto_battle_targets.push(targets_enemy_hp)
  1174.       when 2
  1175.         @active_battler.auto_battle_targets = all_enemys
  1176.       when 3
  1177.         if (item.recover_sp_rate > 0 or item.recover_sp > 0) and
  1178.           (item.recover_hp_rate > 0 or item.recover_hp > 0)
  1179.           if rand (100) < 50
  1180.             @active_battler.auto_battle_targets.push(targets_actor_sp)
  1181.           else
  1182.             @active_battler.auto_battle_targets.push(targets_actor_hp)
  1183.           end
  1184.           return
  1185.         end
  1186.         if item.recover_hp_rate > 0 or item.recover_hp > 0
  1187.           @active_battler.auto_battle_targets.push(targets_actor_hp)
  1188.           return
  1189.         end
  1190.         if item.recover_sp_rate > 0 or item.recover_sp > 0
  1191.           @active_battler.auto_battle_targets.push(targets_actor_sp)
  1192.           return
  1193.         end
  1194.       when 4
  1195.         @active_battler.auto_battle_targets = all_actors
  1196.       when 5
  1197.         target = dead_actors[rand (dead_actors.size)]
  1198.         @active_battler.auto_battle_targets.push(target)
  1199.       when 6
  1200.         @active_battler.auto_battle_targets = dead_actors
  1201.       when 7
  1202.         @active_battler.auto_battle_targets.push(@active_battler)
  1203.       end
  1204.     end
  1205.   end
  1206. end
  1207. #==============================================================================
  1208. ###############################################################################
  1209. #==============================================================================
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-22 23:18

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表