查看: 10026|回复: 0

[已经过期] YEP_BattleEngineCore的问题

[复制链接]
梦石
0
星屑
6963
在线时间
1557 小时
注册时间
2011-6-14
回帖
425
发表于 2016-4-22 13:31:40 | 显示全部楼层 |阅读模式

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

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

×
本来是连击多少次就显示多少次动画,使用YEP_BattleEngineCore后变成了连击N次只显示一次动画,求解 怎么改回去

  1. //=============================================================================
  2. // Yanfly Engine Plugins - Battle Engine Core
  3. // YEP_BattleEngineCore.js
  4. //=============================================================================

  5. var Imported = Imported || {};
  6. Imported.YEP_BattleEngineCore = true;

  7. var Yanfly = Yanfly || {};
  8. Yanfly.BEC = Yanfly.BEC || {};

  9. //=============================================================================
  10. /*:
  11. * @plugindesc v1.35 Have more control over the flow of the battle system
  12. * with this plugin and alter various aspects to your liking.
  13. * @author Yanfly Engine Plugins
  14. *
  15. * @param ---General---
  16. * @default
  17. *
  18. * @param Action Speed
  19. * @desc This is the formula used for an action's base speed.
  20. * Default: agi + Math.randomInt(Math.floor(5 + agi / 4))
  21. * @default agi
  22. *
  23. * @param Default System
  24. * @desc This is the default battle system your game uses.
  25. * Default: dtb
  26. * @default dtb
  27. *
  28. * @param ---Escape---
  29. * @default
  30. *
  31. * @param Escape Ratio
  32. * @desc This is the formula used to determine escape success.
  33. * Default: 0.5 * $gameParty.agility() / $gameTroop.agility()
  34. * @default 0.5 * $gameParty.agility() / $gameTroop.agility()
  35. *
  36. * @param Fail Escape Boost
  37. * @desc Each time the player fails escape, increase the success
  38. * rate by this much. Default: 0.1
  39. * @default 0.1
  40. *
  41. * @param ---Animation---
  42. * @default
  43. *
  44. * @param Animation Base Delay
  45. * @desc This sets the base delay in between animations.
  46. * Default: 8
  47. * @default 0
  48. *
  49. * @param Animation Next Delay
  50. * @desc This sets the sequential delay in between animations.
  51. * Default: 12
  52. * @default 0
  53. *
  54. * @param Certain Hit Animation
  55. * @desc Default animation to play for certain hit skills.
  56. * Use 0 if you wish for no animation.
  57. * @default 120
  58. *
  59. * @param Physical Animation
  60. * @desc Default animation to play for physical skills.
  61. * Use 0 if you wish for no animation.
  62. * @default 52
  63. *
  64. * @param Magical Animation
  65. * @desc Default animation to play for magical skills.
  66. * Use 0 if you wish for no animation.
  67. * @default 51
  68. *
  69. * @param Enemy Attack Animation
  70. * @desc This is the default attack animation played by enemies.
  71. * Default: 0
  72. * @default 39
  73. *
  74. * @param Reflect Animation
  75. * @desc The animation used when magic attacks are reflected.
  76. * @default 42
  77. *
  78. * @param Motion Waiting
  79. * @desc Play animations after performing an action or during?
  80. * During - false     After - true     Default: false
  81. * @default false
  82. *
  83. * @param ---Frontview---
  84. * @default
  85. *
  86. * @param Front Position X
  87. * @desc This formula determines the actor's home X position.
  88. * Default: 0
  89. * @default Graphics.boxWidth / 8 + Graphics.boxWidth / 4 * index
  90. *
  91. * @param Front Position Y
  92. * @desc This formula determines the actor's home Y position.
  93. * Default: 0
  94. * @default Graphics.boxHeight - 180
  95. *
  96. * @param Front Actor Sprite
  97. * @desc Show the actor battle sprite in frontview?
  98. * NO - false     YES - true     Default - false
  99. * @default false
  100. *
  101. * @param Front Sprite Priority
  102. * @desc Give actor sprites the priority of always being on top?
  103. * 0 - Normal   1 - Actors on Top   2 - Enemies on Top
  104. * @default 1
  105. *
  106. * @param ---Sideview---
  107. * @default
  108. *
  109. * @param Home Position X
  110. * @desc This formula determines the actor's home X position.
  111. * Default: 600 + index * 32
  112. * @default screenWidth - 16 - (maxSize + 2) * 32 + index * 32
  113. *
  114. * @param Home Position Y
  115. * @desc This formula determines the actor's home Y position.
  116. * Default: 280 + index * 48
  117. * @default screenHeight - statusHeight - maxSize * 48 + (index+1) * 48 - 32
  118. *
  119. * @param Side Sprite Priority
  120. * @desc Give actor sprites the priority of always being on top?
  121. * 0 - Normal   1 - Actors on Top   2 - Enemies on Top
  122. * @default 1
  123. *
  124. * @param ---Sprites---
  125. * @default
  126. *
  127. * @param Default X Anchor
  128. * @desc Default value used for your sprites's X Anchor.
  129. * Default: 0.5
  130. * @default 0.5
  131. *
  132. * @param Default Y Anchor
  133. * @desc Default value used for your sprites's Y Anchor.
  134. * Default: 1.0
  135. * @default 1.0
  136. *
  137. * @param Step Distance
  138. * @desc This is the distance a unit steps forward for actions.
  139. * Default: 48
  140. * @default 48
  141. *
  142. * @param Flinch Distance
  143. * @desc In sideview, when a unit takes damage or dodges, it will
  144. * flinch a certain distance in pixels.
  145. * @default 12
  146. *
  147. * @param Show Shadows
  148. * @desc Do you wish to have shadows appear under actors?
  149. * NO - false     YES - true
  150. * @default true
  151. *
  152. * @param ---Damage Popups---
  153. * @default
  154. *
  155. * @param Popup Duration
  156. * @desc Adjusts how many frames a popup will stay visible for.
  157. * Default: 90
  158. * @default 128
  159. *
  160. * @param Newest Popup Bottom
  161. * @desc Places the newest popup at the bottom of a group.
  162. * NO - false     YES - true
  163. * @default true
  164. *
  165. * @param Popup Overlap Rate
  166. * @desc When multiple damage popups appear, they cover each other.
  167. * Use this to change the buffer rate amount for each sprite.
  168. * @default 0.9
  169. *
  170. * @param Critical Popup
  171. * @desc Adjusts the popup's flashing color for critical hits.
  172. * Default: 255, 0, 0, 160
  173. * @default 255, 0, 0, 160
  174. *
  175. * @param Critical Duration
  176. * @desc How many frames the flashing will remain for a critical.
  177. * Default: 60
  178. * @default 60
  179. *
  180. * @param ---Tick-Settings---
  181. * @default
  182. *
  183. * @param Timed States
  184. * @desc If the battle system is Tick-based, use time instead of
  185. * turns for states? NO - false   YES - true
  186. * @default false
  187. *
  188. * @param Timed Buffs
  189. * @desc If the battle system is Tick-based, use time instead of
  190. * turns for buffs? NO - false   YES - true
  191. * @default false
  192. *
  193. * @param Turn Time
  194. * @desc How many ticks must past to equal 1 turn?
  195. * @default 100
  196. *
  197. * @param AI Self Turns
  198. * @desc Set AI to be based on their own individual turns?
  199. * NO - false     YES - true
  200. * @default true
  201. *
  202. * @param ---Window Settings---
  203. * @default
  204. *
  205. * @param Lower Windows
  206. * @desc Places the skill and item windows at the screen's bottom.
  207. * OFF - false     ON - true
  208. * @default true
  209. *
  210. * @param Window Rows
  211. * @desc For lower windows, how many rows of items do you wish for
  212. * the windows to display?
  213. * @default 4
  214. *
  215. * @param Command Window Rows
  216. * @desc Sets the number of rows for each command window to display.
  217. * Default: 4
  218. * @default 4
  219. *
  220. * @param Command Alignment
  221. * @desc Sets the text alignment for the Party/Actor Commands.
  222. * Default: left
  223. * @default center
  224. *
  225. * @param Start Actor Command
  226. * @desc Starts turn with the Actor Command Window instead of Party.
  227. * OFF - false     ON - true
  228. * @default true
  229. *
  230. * @param Current Max
  231. * @desc Display the entire current / max value of HP/MP?
  232. * NO - false     YES - true     Default: true
  233. * @default false
  234. *
  235. * @param ---Selection Help---
  236. * @default
  237. *
  238. * @param Mouse Over
  239. * @desc Allows you to mouse over the enemies to auto-select them.
  240. * OFF - false     ON - true
  241. * @default true
  242. *
  243. * @param Select Help Window
  244. * @desc When selecting actors and enemies, show the help window?
  245. * NO - false     YES - true
  246. * @default true
  247. *
  248. * @param User Help Text
  249. * @desc The singular form of 'User' used in a help window.
  250. * @default User
  251. *
  252. * @param Ally Help Text
  253. * @desc The singular form of 'Ally' used in a help window.
  254. * @default Ally
  255. *
  256. * @param Allies Help Text
  257. * @desc The plural form of 'Allies' used in a help window.
  258. * @default Allies
  259. *
  260. * @param Enemy Help Text
  261. * @desc The singular form of 'Enemy' used in a help window.
  262. * @default Enemy
  263. *
  264. * @param Enemies Help Text
  265. * @desc The plural form of 'Enemy' used in a help window.
  266. * @default Enemies
  267. *
  268. * @param All Help Text
  269. * @desc When selecting a entire group of targets.
  270. * %1 - Target Group (Allies or Enemies)
  271. * @default All %1
  272. *
  273. * @param Random Help Text
  274. * @desc When selecting a random selection of targets.
  275. * %1 - Target Group (Allies or Enemies)     %2 - Number
  276. * @default %2 Random %1
  277. *
  278. * @param ---Enemy Select---
  279. * @default
  280. *
  281. * @param Visual Enemy Select
  282. * @desc Replaces the enemy selection screen with a more visual one.
  283. * OFF - false     ON - true
  284. * @default true
  285. *
  286. * @param Show Enemy Name
  287. * @desc Show enemy names with Visual Enemy Select.
  288. * OFF - false     ON - true
  289. * @default true
  290. *
  291. * @param Show Select Box
  292. * @desc Show a selection box when selecting enemies.
  293. * OFF - false     ON - true
  294. * @default false
  295. *
  296. * @param Enemy Font Size
  297. * @desc Changes the font size used to display enemy names.
  298. * Default: 28
  299. * @default 20
  300. *
  301. * @param Enemy Auto Select
  302. * @desc Changes what enemy is automatically selected at first.
  303. * LEFT - 0     RIGHT - this.furthestRight()
  304. * @default this.furthestRight()
  305. *
  306. * @param ---Actor Select---
  307. * @default
  308. *
  309. * @param Visual Actor Select
  310. * @desc Allows you to click the actor on screen to select it.
  311. * OFF - false     ON - true
  312. * @default true
  313. *
  314. * @param ---Battle Log---
  315. * @default
  316. *
  317. * @param Show Emerge Text
  318. * @desc Shows the battle start text for enemies appearing.
  319. * OFF - false     ON - true
  320. * @default false
  321. *
  322. * @param Show Pre-Emptive Text
  323. * @desc Shows the text for getting a pre-emptive attack.
  324. * OFF - false     ON - true
  325. * @default true
  326. *
  327. * @param Show Surprise Text
  328. * @desc Shows the text for getting a surprise attack.
  329. * OFF - false     ON - true
  330. * @default true
  331. *
  332. * @param Optimize Speed
  333. * @desc Cuts log base line process to optimize the battle speed.
  334. * OFF - false     ON - true
  335. * @default true
  336. *
  337. * @param Show Action Text
  338. * @desc Displays full action text or a simplified version of it.
  339. * SIMPLE - false     FULL - true
  340. * @default false
  341. *
  342. * @param Show State Text
  343. * @desc Shows all text regarding states.
  344. * OFF - false     ON - true
  345. * @default false
  346. *
  347. * @param Show Buff Text
  348. * @desc Shows all text regarding buffs.
  349. * OFF - false     ON - true
  350. * @default false
  351. *
  352. * @param Show Counter Text
  353. * @desc Shows text regarding counter attacks.
  354. * OFF - false     ON - true
  355. * @default true
  356. *
  357. * @param Show Reflect Text
  358. * @desc Shows text regarding reflected spells.
  359. * OFF - false     ON - true
  360. * @default true
  361. *
  362. * @param Show Substitute Text
  363. * @desc Shows text regarding substituted damage.
  364. * OFF - false     ON - true
  365. * @default true
  366. *
  367. * @param Show Fail Text
  368. * @desc Shows text regarding failed attacks.
  369. * OFF - false     ON - true
  370. * @default false
  371. *
  372. * @param Show Critical Text
  373. * @desc Shows text regarding critical hits.
  374. * OFF - false     ON - true
  375. * @default false
  376. *
  377. * @param Show Miss Text
  378. * @desc Shows text regarding missed attacks.
  379. * OFF - false     ON - true
  380. * @default false
  381. *
  382. * @param Show Evasion Text
  383. * @desc Shows text regarding evaded attacks.
  384. * OFF - false     ON - true
  385. * @default false
  386. *
  387. * @param Show HP Text
  388. * @desc Shows text regarding HP damage or heals.
  389. * OFF - false     ON - true
  390. * @default false
  391. *
  392. * @param Show MP Text
  393. * @desc Shows text regarding MP damage or heals.
  394. * OFF - false     ON - true
  395. * @default false
  396. *
  397. * @param Show TP Text
  398. * @desc Shows text regarding TP damage or heals.
  399. * OFF - false     ON - true
  400. * @default false
  401. *
  402. * @help
  403. * ============================================================================
  404. * Introduction
  405. * ============================================================================
  406. *
  407. * This plugin alters the various aspects of the default battle system,
  408. * allowing it to be more streamlined like most modern RPG's and less clunky
  409. * like older RPG's. This ranges from choosing what text will appear in the
  410. * battle log window at the top and how it will be displayed.
  411. *
  412. * ============================================================================
  413. * Battle Messages
  414. * ============================================================================
  415. *
  416. * When changing "Terms" and the "Messages" that appear in battle, inserting
  417. * the following tag anywhere in the message will cause the message to center
  418. * itself in the battle log.
  419. *
  420. *   <CENTER>
  421. *   This tag must be all caps in order for the battle log window to recognize
  422. *   it as an instruction to center the displayed battle text message.
  423. *
  424. * There are a couple of notetags you can use to change the way certain skills
  425. * and items will show up incase you don't want a name like 'Harold's Attack'
  426. * to appear in the name.
  427. *
  428. * Skill and Item Notetags:
  429. *
  430. *   <Display Text: x>
  431. *   This will change the text displayed to x.
  432. *
  433. *   <Display Icon: x>
  434. *   This will change the icon displayed to x.
  435. *
  436. * ============================================================================
  437. * Battle Windows
  438. * ============================================================================
  439. *
  440. * There's various options to adjust the window settings found in the battle
  441. * system to make navigating the battle system more intuitive. Such options
  442. * include starting the turns with the Actor Command Window instead of the
  443. * Party Command Window (the Fight/Escape Window). The Party Command Window is
  444. * still accessible but only by pressing cancel on the first actor's window.
  445. *
  446. * ============================================================================
  447. * Battle Order
  448. * ============================================================================
  449. *
  450. * The battle turn order is also fixed, too. This way, any battlers that Have
  451. * their AGI value changed over the course of battle will reflect those changes
  452. * during the current turn rather than the following turn. The action speed
  453. * calculation can also be adjusted and finetuned to have the random factor of
  454. * its speed calculation formula removed, too, making AGI actually worthwhile
  455. * as a tactical parameter.
  456. *
  457. * Skill and Item Notetag:
  458. *   <speed: +x>
  459. *   <speed: -x>
  460. *   This lets you break past the editor's limit of -2000 and 2000 allowing you
  461. *   to set the speed of your actions with more control.
  462. *
  463. * ============================================================================
  464. * Multiple Hits
  465. * ============================================================================
  466. *
  467. * Multi-hit action will no longer end prematurely if the target dies midway
  468. * through the action. This is done through toggling immortal states. To make
  469. * use of feature, make sure your database has an Immortal State somewhere. If
  470. * you do not wish to use this feature, set the Parameter for Immortal State ID
  471. * to 0 instead.
  472. *
  473. * ============================================================================
  474. * Popup Revamp
  475. * ============================================================================
  476. *
  477. * Although the damage popups may still look the same as the default ones from
  478. * MV, the process in which they're created is now different to streamline the
  479. * damage popup process. Before, popups would only appear one a time with a
  480. * frame's different at minimum in order for them to show. Now, any actions
  481. * that occur at the same frame will now all show popups at the same frame,
  482. * making for smoother and less clunky damage popups.
  483. *
  484. * ============================================================================
  485. * Common Events
  486. * ============================================================================
  487. *
  488. * Common Events will now occur at the end of each action regardless of whether
  489. * or not the enemy party is still alive. With proper placing of the action
  490. * sequence tags, you can make the skill's common event occur in the middle of
  491. * an action, too. However, keep in mind if you force an action in the middle
  492. * of another action, the remainder of the former action's sequence list will
  493. * become null and void in favor of the new forced action.
  494. *
  495. * ============================================================================
  496. * Casting Animations
  497. * ============================================================================
  498. *
  499. * Casting Animations help provide visual hints for players either by letting
  500. * them know which battler is going to perform an action or what type of skill
  501. * that action will be. This plugin enables skills to have casting animations
  502. * that can be modified universally or customized for each individual skill.
  503. *
  504. * Skill Notetag:
  505. *   <Cast Animation: x>
  506. *   Sets the skill's cast animation to animation ID x. Setting x to zero will
  507. *   cause the skill to not have any animaton at all.
  508. *
  509. * ============================================================================
  510. * Changing Battle Systems
  511. * ============================================================================
  512. *
  513. * While the player is not in battle, you can change the battle system using a
  514. * Plugin Command. With only this plugin, there is only one battle system
  515. * included: the default battle system.
  516. *
  517. * Plugin Command:
  518. *   setBattleSys DTB      Sets battle system to Default Turn Battle.
  519. *
  520. * Other future plugins may include other battle systems that may utilize the
  521. * Battle Engine Core.
  522. *
  523. * ============================================================================
  524. * Sideview Actions
  525. * ============================================================================
  526. *
  527. * In RPG Maker MV's default battle system, both the sideview and the frontview
  528. * settings do not display counterattacks, reflected magic attacks, nor any
  529. * case of substituting for battle members. The Battle Engine Core provides
  530. * games that are using the sideview settings small amounts of animations to
  531. * relay information to the player in a more visual sense.
  532. *
  533. * Magic Reflection will also display a reflection animation to indicate the
  534. * battler has reflection properties. This animation can be changed in the
  535. * parameters, but certain actors, classes, enemies, weapons, armors, and
  536. * states can display a unique kind of animation for reflection if desired.
  537. *
  538. * Actor, Class, Enemy, Weapon, Armor, and State Notetag:
  539. *   <Reflect Animation ID: x>
  540. *   Changes the user's reflect animation to x. This will take priority in the
  541. *   following order: Actor, Class, Enemy, Weapon, Armor, State, Default.
  542. *
  543. * Sometimes, you don't want your enemies to be able to move. Or you don't want
  544. * certain actors to be able to move. They're just stationary for whatever
  545. * reason. To accomplish that, you can use this notetag to forbid the battler
  546. * from moving.
  547. *
  548. * Actor, Class, Enemy, Weapon, Armor, and State Notetag:
  549. *   <Sprite Cannot Move>
  550. *   Prevents the battler's sprite from moving. This will take priority in the
  551. *   following order: Actor, Class, Enemy, Weapon, Armor, and State. If an
  552. *   enemy is unable to move when it performs an action, it will flash white as
  553. *   if it normally does in front view.
  554. *
  555. * ============================================================================
  556. * Custom Sideview Battler Anchor
  557. * ============================================================================
  558. *
  559. * Sideview battlers are generally centered horizontally, and grounded at their
  560. * feet. However, not all sideview battler spritesheets work this way. In the
  561. * event you have a sideview battler that doesn't conform to those standards,
  562. * you can 'anchor' them a different way.
  563. *
  564. * Actor, Class, Weapon, Armor, State Notetags:
  565. *   <Anchor X: y.z>
  566. *   <Anchor Y: y.z>
  567. *   This sets the anchor location for the actor's sideview battler at y.z.
  568. *   By default, the X anchor is 0.5 while the Y anchor is 1.0. If you want
  569. *   the X anchor to be a bit more to the left, make it less than 0.5. Make it
  570. *   more than 0.5 to make the X anchor more towards the right. To raise the
  571. *   Y anchor, set the number value to less than 1.0. Keep adjusting until you
  572. *   find that perfect anchor setting.
  573. *
  574. * If an anchor has multiple traits that yield different anchors, it will be
  575. * used in a priority list akin to this order:
  576. *
  577. *   States
  578. *   Weapons
  579. *   Armors
  580. *   Class
  581. *   Actor
  582. *   Default
  583. *
  584. * The higher it is on the priority list, the higher its priority.
  585. *
  586. * ============================================================================
  587. * Enemy Attack Animation
  588. * ============================================================================
  589. *
  590. * To give your enemies unique attack animations, you can use this notetag:
  591. *
  592. * Enemy Notetag:
  593. *   <Attack Animation: x>
  594. *   Replace x with the ID of the battle animation you wish to set as the
  595. *   enemy's default attack animation.
  596. *
  597. * ============================================================================
  598. * Automatic State Removal Conditions
  599. * ============================================================================
  600. *
  601. * By default, RPG Maker MV's battle system has automatic state removal under
  602. * three different conditions: none, action end, turn end.
  603. *
  604. * None and Turn End are working as intended. However, Action End, however, had
  605. * the states removed at the start of the battler's action rather than the end.
  606. * This is changed and updated to occur only at the end of a battler's action.
  607. *
  608. * Two more automatic conditions are now added: Action Start and Turn Start.
  609. * These can be added and implemented using the following notetags:
  610. *
  611. * State Notetags:
  612. *   <Action Start: x>
  613. *   <Action Start: x to y>
  614. *   This will cause this state to update its turns remaining at the start of
  615. *   an action. x is the number of turns it will last. If you use x to y, upon
  616. *   applying the state, the state will be removed a random number of turns
  617. *   from x to y.
  618. *
  619. *   <Turn Start: x>
  620. *   <Turn Start: x to y>
  621. *   This will cause the state to update its turns remaining at the start of a
  622. *   battle turn. x is the number of turns it will last. If you use x to y,
  623. *   upon applying the state, the state will be removed a random number of
  624. *   turns from x to y.
  625. *
  626. * States with Action End have a unique trait to them where if the caster of
  627. * the state is the current active battler (subject) and if the state is then
  628. * applied on the user itself, they will gain a 'free turn'. The 'free turn' is
  629. * to mitigate the user from losing 1 duration of the turn since with an Action
  630. * End timing, they would lose the benefit of being under the state for that
  631. * turn's timing.
  632. *
  633. * ============================================================================
  634. * Action Sequences
  635. * ============================================================================
  636. *
  637. * The Yanfly Engine Plugins - Battle Engine Core includes the capability of
  638. * using custom action sequences. Action sequences are basic instructions for
  639. * the game to creating a customized skill both visually and mechanically.
  640. * The Battle Engine Core, however, will only include the most basic of action
  641. * sequences so the instructions on how to create a custom action sequence will
  642. * be included in the Help file on future extension plugins for this plugin.
  643. *
  644. * ============================================================================
  645. * Changelog
  646. * ============================================================================
  647. *
  648. * Verison 1.35:
  649. * - Scopes that target a dead ally will automatically target the first dead
  650. * ally now. Scopes that target all dead allies will lock onto the first dead
  651. * ally. This will hopefully provide less confusion amongst playing.
  652. *
  653. * Version 1.34a:
  654. * - Fixed a bug where 'NOT FOCUS' targets were not including dead members.
  655. * - Fixed a bug where using NOT FOCUS would cause dead targets to be visible.
  656. *
  657. * Version 1.33:
  658. * - Updated for RPG Maker MV version 1.1.0.
  659. *
  660. * Version 1.32d:
  661. * - Fixed a bug that caused a crash when an actor died.
  662. * - Added a motion engine to be used for future plugins.
  663. * - Preparation for a future plugin.
  664. * - <Anchor X: y.z> and <Anchor Y: y.z> notetags for actors are now extended
  665. * to actors, classes, weapons, armors, and states.
  666. * - Added <Display Text: x> and <Display Icon: x> notetags for skills and
  667. * items. These notetags will alter the display name shown and icon shown
  668. * respectively while performing a skill.
  669. * - Switched Magic Reflect checking order with Counterattack checking order.
  670. * This is to give priority to reflected actions over countered actions.
  671. *
  672. * Version 1.31b:
  673. * - States with Action End now have a unique trait to them where if the caster
  674. * of the state is the current active battler (subject) and if the state is
  675. * then applied on the user itself, they will gain a 'free turn'. The 'free
  676. * turn' is to mitigate the user from losing 1 duration of the turn since with
  677. * an Action End timing, they would lose the benefit of being under the state
  678. * for that turn's timing.
  679. * - Added failsafes for Free Turns in case other plugins have overwritten the
  680. * on battle start functions.
  681. * - Added a compatibility update to Animated SV Enemies for dead motion.
  682. *
  683. * Version 1.30:
  684. * - Optimization update.
  685. * - Fixed a bug that prevented added state effects be unable to apply if they
  686. * are an added Death state.
  687. * - Battlelog lines are now able to display text codes.
  688. *
  689. * Version 1.29:
  690. * - Fixed a bug with the 'else if' action sequences not working in the right
  691. * order of sequence conditions.
  692. *
  693. * Version 1.28d:
  694. * - Fixed a bug if instant casting a skill that would make an opponent battler
  695. * to force an action to end incorrectly. Thanks to DoubleX for the fix.
  696. * - Fixed a bug with mouse over not working properly.
  697. * - Fixed a bug regarding forced actions that will cause the battle to freeze
  698. * if the forced action causes the main active subject to leave the battle.
  699. * - Fixed a bug with timed states not updating their turns properly.
  700. * - Changed priority of IF action sequences to higher to no longer interfere
  701. * other action sequences.
  702. *
  703. * Version 1.27:
  704. * - Mechanic change. This will only affect those using turn-based state timing
  705. * mechanics. Turn End state updates are now shifted from Turn End to occur at
  706. * Regeneration timing to have a more synchronized aspect. The timings are very
  707. * close so there's next to no notice in difference. Buff turn updates are also
  708. * moved to the regeneration timing, too.
  709. *
  710. * Version 1.26:
  711. * - Added 'Mouse Over' parameter to Selection Help. This parameter enables
  712. * mouse users to simply hover over the enemy to select them rather than having
  713. * to click an enemy twice to select them.
  714. *
  715. * Version 1.25f:
  716. * - Added failsafes for Forced Action queues.
  717. * - Added 'Show Select Box' parameter when selecting enemies.
  718. * - Fixed a bug that caused End Turn events to not function properly.
  719. * - Battle animations, by default, are positioned relative to the base bitmap
  720. * for its target sprite. However, actor sprites do not have a base bitmap and
  721. * therefore, battle animations, regardless of position, will always target the
  722. * actor sprite's feet. This update now gives actor sprites a base bitmap.
  723. * - Readjusted sprite width and sprite height calculations.
  724. * - Added a failsafe for when no sideview actor graphics are used.
  725. *
  726. * Version 1.24:
  727. * - Implemented a Forced Action queue list. This means if a Forced Action
  728. * takes place in the middle of an action, the action will resume after the
  729. * forced action finishes rather than cancels it out like MV does.
  730. *
  731. * Version 1.23:
  732. * - Fixed a bug that didn't regenerate HP/MP/TP properly for tick-based.
  733. *
  734. * Version 1.22:
  735. * - Fixed a bug within MV that caused Forced Actions at Turn End to prompt and
  736. * trigger all turn-end related activities (such as regeneration and state turn
  737. * updating).
  738. * - Made a mechanic change so that Action Start and Action End state turns do
  739. * not update their turns through forced actions.
  740. *
  741. * Version 1.21:
  742. * - Fixed a bug where states Action End weren't going down properly with DTB.
  743. *
  744. * Version 1.20:
  745. * - Fixed a bug where revived actors using instant cast aren't properly set to
  746. * use actions immediately.
  747. *
  748. * Version 1.19:
  749. * - Added <Attack Animation: x> notetag for enemies.
  750. * - Added 'AI Self Turns' for Tick-Based Battles. Enemies can now have their
  751. * A.I. revolve around their own individual turns rather than the battle's.
  752. * - Mechanic change for states. Following suit with the change to Action End
  753. * removal, there are now two more conditions added: Action Start, Turn Start.
  754. * - Added <Action Start: x>, <Action Start: x to y>, <Turn Start: x>, and
  755. * <Turn Start: x to y> notetags for automatic state removal.
  756. *
  757. * Version 1.18:
  758. * - Fixed a bug with irregular targeting scopes.
  759. * - Fixed an MV-related bug with Recover All event not refreshing battlers.
  760. *
  761. * Version 1.17b:
  762. * - Fixed a bug with action end states to remove multiple at once.
  763. * - Fixed a visual error with flinching sprites.
  764. * - Added 'Current Max' parameter to change HP current/max display in battle.
  765. * - Mechanic change for states that update on Action End to end at the end of
  766. * a battler's turn instead of at the start.
  767. * - Began preparations for another battle system.
  768. *
  769. * Version 1.16:
  770. * - Fixed an issue with mirrored enemies having mirrored state icons.
  771. *
  772. * Version 1.15a:
  773. * - Fixed a bug revolving the status window not updating.
  774. * - Updated default home position formula to better fit other party sizes.
  775. * New Home Position X:
  776. *   screenWidth - 16 - (maxSize + 2) * 32 + index * 32
  777. * New Home Position Y:
  778. *   screenHeight - statusHeight - maxSize * 48 + (index+1) * 48 - 16
  779. *
  780. * Version 1.14:
  781. * - Fixed a bug with Forced Actions locking out the battle.
  782. * - New mechanic: For tick-based battle systems, states with action-end will
  783. * go down in turns based on how many actions took place for the actor instead.
  784. * Previously, they were indistinguishable from states with Turn End removal.
  785. * - New mechanic: Using Instant Skills/Items from YEP_InstantCast.js will also
  786. * cause states with action-end to go down in turns upon using actions.
  787. *
  788. * Version 1.13a:
  789. * - Fixed a bug that made battlebacks disappear.
  790. * - Reworked visual enemy selection.
  791. * - Victory phase doesn't immediately display level up changes in battle
  792. * status window.
  793. * - Fixed a bug with the visual enemy select showing dead enemy names.
  794. *
  795. * Version 1.12b:
  796. * - If the Battle HUD has been hidden for whatever reason during the victory
  797. * sequence, it will be returned.
  798. * - Added <speed: +x> and <speed: -x> notetags to break past editor limits.
  799. * - Added new conditions where the battle won't end until all action sequences
  800. * have been fulfilled.
  801. *
  802. * Version 1.11:
  803. * - Fixed a bug that didn't show HP/MP Regeneration.
  804. *
  805. * Version 1.10:
  806. * - Removed immortal state dependancy. Immortality is now its own setting.
  807. * - Added more abbreviated variables for action speed calculation.
  808. * - Fixed a bug where all-scope attacks would reveal Appear-Halfway enemies.
  809. * - Fixed a bug where the battle wouldn't end if the final enemy was killed
  810. * by state damage.
  811. *
  812. * Version 1.09:
  813. * - Fixed a undefined actor bug for refreshing the status window.
  814. * - Added 'Show Shadows' parameter to the plugin settings.
  815. * - Reworked the default action sequences so that forced actions do not appear
  816. * on top of each other and party-heal animations occur simultaneously.
  817. *
  818. * Version 1.08:
  819. * - Fixed a bug where battlers gaining HP/MP in the damage formula for
  820. * themselves wouldn't trigger popups.
  821. * - Fixed a bug where if the party failed to escape from battle, states that
  822. * would be removed by battle still get removed. *Fixed by Emjenoeg*
  823. * - Fixed a bug where instant death skills didn't work.
  824. * - Changed Sprite Priority settings to decide whether actors, enemies, or
  825. * neither would always be on top.
  826. *
  827. * Version 1.07:
  828. * - Optimized status window to refresh at a minimum.
  829. * - Set up frame work for future plugins:
  830. * - Added 'Escape Ratio' and 'Fail Escape Boost' to parameters to allow users
  831. * to set the escape ratio they want.
  832. * - Added 'Front Sprite Priority' and 'Side Sprite Priority' to parameters to
  833. * dictate if actor sprites are always on top.
  834. * - Added 'Tick-Settings' category for tick-based battle systems.
  835. *
  836. * Version 1.06:
  837. * - Fixed a bug that causes dead actors at the start of battle to not spawn.
  838. * - Fixed a bug where the help window on an empty slot would show the
  839. * previous skill's message.
  840. *
  841. * Version 1.05:
  842. * - Added new target typing: Character X, which allows you to select
  843. * specifically the actor with an actor ID of X if he/she/it is in the party.
  844. * - Fixed a bug that prevented Miss and Evade popups from showing.
  845. *
  846. * Version 1.04:
  847. * - Fixed a bug where popups didn't show under certain animation types.
  848. * - Fixed certain battler motions from not refreshing correctly.
  849. * - Actions with no scope will not trigger the confirmation selection window.
  850. *
  851. * Version 1.03:
  852. * - Added 'Wait for Effect' action sequence.
  853. * - Actions now wait for effects (such as collapsing) to be done before
  854. * continuing on with battle or to end battle.
  855. *
  856. * Version 1.02:
  857. * - Fixed a bug where the help window would retain descriptions on no skills.
  858. * - Synched up weapons with actor sprites so they would occur simultaneously.
  859. * - Fixed an issue where requesting certain motions from enemies that don't
  860. * exist would cause them to crash.
  861. *
  862. * Version 1.01:
  863. * - Skills and items that affect both HP and MP will now show popups for both.
  864. *
  865. * Version 1.00:
  866. * - Finished plugin!
  867. */
  868. //=============================================================================

  869. //=============================================================================
  870. // Parameter Variables
  871. //=============================================================================

  872. Yanfly.Parameters = PluginManager.parameters('YEP_BattleEngineCore');
  873. Yanfly.Param = Yanfly.Param || {};

  874. Yanfly.Param.BECSystem = String(Yanfly.Parameters['Default System']);
  875. Yanfly.Param.BECEscRatio = String(Yanfly.Parameters['Escape Ratio']);
  876. Yanfly.Param.BECEscFail = String(Yanfly.Parameters['Fail Escape Boost']);
  877. Yanfly.Param.CastCertHit = Number(Yanfly.Parameters['Certain Hit Animation']);
  878. Yanfly.Param.CastPhysical = Number(Yanfly.Parameters['Physical Animation']);
  879. Yanfly.Param.CastMagical = Number(Yanfly.Parameters['Magical Animation']);
  880. Yanfly.Param.EnemyAtkAni = Number(Yanfly.Parameters['Enemy Attack Animation']);
  881. Yanfly.Param.BECOptSpeed = String(Yanfly.Parameters['Optimize Speed']);
  882. Yanfly.Param.BECEmergeText = String(Yanfly.Parameters['Show Emerge Text']);
  883. Yanfly.Param.BECPreEmpText = String(Yanfly.Parameters['Show Pre-Emptive Text']);
  884. Yanfly.Param.BECSurpText = String(Yanfly.Parameters['Show Surprise Text']);
  885. Yanfly.Param.BECPopupOverlap = String(Yanfly.Parameters['Popup Overlap Rate']);
  886. Yanfly.Param.BECNewPopBottom = String(Yanfly.Parameters['Newest Popup Bottom']);
  887. Yanfly.Param.BECStartActCmd = String(Yanfly.Parameters['Start Actor Command']);
  888. Yanfly.Param.BECCurMax = eval(String(Yanfly.Parameters['Current Max']));
  889. Yanfly.Param.BECSelectHelp = String(Yanfly.Parameters['Select Help Window']);
  890. Yanfly.Param.BECHelpUserTx = String(Yanfly.Parameters['User Help Text']);
  891. Yanfly.Param.BECHelpAllyTx = String(Yanfly.Parameters['Ally Help Text']);
  892. Yanfly.Param.BECHelpAlliesTx = String(Yanfly.Parameters['Allies Help Text']);
  893. Yanfly.Param.BECHelpEnemyTx = String(Yanfly.Parameters['Enemy Help Text']);
  894. Yanfly.Param.BECHelpEnemiesTx = String(Yanfly.Parameters['Enemies Help Text']);
  895. Yanfly.Param.BECHelpAllTx = String(Yanfly.Parameters['All Help Text']);
  896. Yanfly.Param.BECHelpRandTx = String(Yanfly.Parameters['Random Help Text']);
  897. Yanfly.Param.BECFrontPosX = String(Yanfly.Parameters['Front Position X']);
  898. Yanfly.Param.BECFrontPosY = String(Yanfly.Parameters['Front Position Y']);
  899. Yanfly.Param.BECFrontSprite = String(Yanfly.Parameters['Front Actor Sprite']);
  900. Yanfly.Param.BECFrSpPrio = String(Yanfly.Parameters['Front Sprite Priority']);
  901. Yanfly.Param.BECHomePosX = String(Yanfly.Parameters['Home Position X']);
  902. Yanfly.Param.BECHomePosY = String(Yanfly.Parameters['Home Position Y']);
  903. Yanfly.Param.BECSideSpPrio = String(Yanfly.Parameters['Side Sprite Priority']);
  904. Yanfly.Param.BECAnchorX = Number(Yanfly.Parameters['Default X Anchor']);
  905. Yanfly.Param.BECAnchorY = Number(Yanfly.Parameters['Default Y Anchor']);
  906. Yanfly.Param.BECStepDist = Number(Yanfly.Parameters['Step Distance']);
  907. Yanfly.Param.BECFlinchDist = Number(Yanfly.Parameters['Flinch Distance']);
  908. Yanfly.Param.BECShowShadows = String(Yanfly.Parameters['Show Shadows']);
  909. Yanfly.Param.BECPopupDur = String(Yanfly.Parameters['Popup Duration']);
  910. Yanfly.Param.BECCritPopup = String(Yanfly.Parameters['Critical Popup']);
  911. Yanfly.Param.BECCritDur = String(Yanfly.Parameters['Critical Duration']);
  912. Yanfly.Param.BECActionSpeed = String(Yanfly.Parameters['Action Speed']);
  913. Yanfly.Param.BECReflectAni = Number(Yanfly.Parameters['Reflect Animation']);
  914. Yanfly.Param.BECMotionWait = String(Yanfly.Parameters['Motion Waiting']);
  915. Yanfly.Param.BECTimeStates = String(Yanfly.Parameters['Timed States']);
  916. Yanfly.Param.BECTimeBuffs = String(Yanfly.Parameters['Timed Buffs']);
  917. Yanfly.Param.BECTurnTime = Number(Yanfly.Parameters['Turn Time']);
  918. Yanfly.Param.BECAISelfTurn = eval(String(Yanfly.Parameters['AI Self Turns']));
  919. Yanfly.Param.BECLowerWindows = String(Yanfly.Parameters['Lower Windows']);
  920. Yanfly.Param.BECSelectMouseOver = eval(String(Yanfly.Parameters['Mouse Over']));
  921. Yanfly.Param.BECEnemySelect = String(Yanfly.Parameters['Visual Enemy Select']);
  922. Yanfly.Param.BECActorSelect = String(Yanfly.Parameters['Visual Actor Select']);
  923. Yanfly.Param.BECWindowRows = String(Yanfly.Parameters['Window Rows']);
  924. Yanfly.Param.BECEnemyFontSize = Number(Yanfly.Parameters['Enemy Font Size']);
  925. Yanfly.Param.BECShowEnemyName = String(Yanfly.Parameters['Show Enemy Name']);
  926. Yanfly.Param.BECShowSelectBox = String(Yanfly.Parameters['Show Select Box']);
  927. Yanfly.Param.BECEnemyAutoSel = String(Yanfly.Parameters['Enemy Auto Select']);
  928. Yanfly.Param.BECCommandAlign = String(Yanfly.Parameters['Command Alignment']);
  929. Yanfly.Param.BECCommandRows = String(Yanfly.Parameters['Command Window Rows']);
  930. Yanfly.Param.BECAniBaseDel = String(Yanfly.Parameters['Animation Base Delay']);
  931. Yanfly.Param.BECAniNextDel = String(Yanfly.Parameters['Animation Next Delay']);
  932. Yanfly.Param.BECFullActText = String(Yanfly.Parameters['Show Action Text']);
  933. Yanfly.Param.BECShowCntText = String(Yanfly.Parameters['Show Counter Text']);
  934. Yanfly.Param.BECShowRflText = String(Yanfly.Parameters['Show Reflect Text']);
  935. Yanfly.Param.BECShowSubText = String(Yanfly.Parameters['Show Substitute Text']);
  936. Yanfly.Param.BECShowFailText = String(Yanfly.Parameters['Show Fail Text']);
  937. Yanfly.Param.BECShowCritText = String(Yanfly.Parameters['Show Critical Text']);
  938. Yanfly.Param.BECShowMissText = String(Yanfly.Parameters['Show Miss Text']);
  939. Yanfly.Param.BECShowEvaText = String(Yanfly.Parameters['Show Evasion Text']);
  940. Yanfly.Param.BECShowHpText = String(Yanfly.Parameters['Show HP Text']);
  941. Yanfly.Param.BECShowMpText = String(Yanfly.Parameters['Show MP Text']);
  942. Yanfly.Param.BECShowTpText = String(Yanfly.Parameters['Show TP Text']);
  943. Yanfly.Param.BECShowStateText = String(Yanfly.Parameters['Show State Text']);
  944. Yanfly.Param.BECShowBuffText = String(Yanfly.Parameters['Show Buff Text']);

  945. //=============================================================================
  946. // DataManager
  947. //=============================================================================

  948. Yanfly.BEC.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  949. DataManager.isDatabaseLoaded = function() {
  950.   if (!Yanfly.BEC.DataManager_isDatabaseLoaded.call(this)) return false;
  951.   if (!Yanfly._loaded_YEP_BattleEngineCore) {
  952.     this.processMELODYNotetags($dataSkills);
  953.     this.processMELODYNotetags($dataItems);
  954.     this.processBECNotetags1($dataSkills);
  955.     this.processBECNotetags2($dataSkills);
  956.     this.processBECNotetags2($dataItems);
  957.     this.processBECNotetags3($dataEnemies);
  958.     this.processBECNotetags4($dataActors);
  959.     this.processBECNotetags4($dataClasses);
  960.     this.processBECNotetags4($dataWeapons);
  961.     this.processBECNotetags4($dataArmors);
  962.     this.processBECNotetags4($dataEnemies);
  963.     this.processBECNotetags4($dataStates);
  964.     this.processBECNotetags5($dataActors, true);
  965.     this.processBECNotetags5($dataClasses, false);
  966.     this.processBECNotetags5($dataWeapons, false);
  967.     this.processBECNotetags5($dataArmors, false);
  968.     this.processBECNotetags5($dataStates, false);
  969.     this.processBECNotetags6($dataStates);
  970.     Yanfly._loaded_YEP_BattleEngineCore = true;
  971.   }
  972.   return true;
  973. };

  974. DataManager.processMELODYNotetags = function(group) {
  975.   for (var n = 1; n < group.length; n++) {
  976.     var obj = group[n];
  977.     if (obj.actionsMade) continue;
  978.     obj.actionsMade = true;
  979.     var notedata = obj.note.split(/[\r\n]+/);

  980.     var actionType = 0;
  981.     this.setDefaultActions(obj);

  982.     for (var i = 0; i < notedata.length; i++) {
  983.       var line = notedata[i];
  984.       if (line.match(/<(?:SETUP ACTION|setup)>/i)) {
  985.         actionType = 1;
  986.         obj.setupActions = [];
  987.       } else if (line.match(/<\/(?:SETUP ACTION|setup)>/i)) {
  988.         var actionType = 0;
  989.       } else if (line.match(/<(?:WHOLE ACTION|whole)>/i)) {
  990.         actionType = 2;
  991.         obj.wholeActions = [];
  992.       } else if (line.match(/<\/(?:WHOLE ACTION|whole)>/i)) {
  993.         var actionType = 0;
  994.       } else if (line.match(/<(?:TARGET ACTION|target)>/i)) {
  995.         actionType = 3;
  996.         obj.targetActions = [];
  997.       } else if (line.match(/<\/(?:TARGET ACTION|target)>/i)) {
  998.         var actionType = 0;
  999.       } else if (line.match(/<(?:FOLLOW ACTION|follow)>/i)) {
  1000.         actionType = 4;
  1001.         obj.followActions = [];
  1002.       } else if (line.match(/<\/(?:FOLLOW ACTION|follow)>/i)) {
  1003.         var actionType = 0;
  1004.       } else if (line.match(/<(?:FINISH ACTION|finish)>/i)) {
  1005.         actionType = 5;
  1006.         obj.finishActions = [];
  1007.       } else if (line.match(/<\/(?:FINISH ACTION|finish)>/i)) {
  1008.         var actionType = 0;
  1009.       } else {
  1010.         this.convertSequenceLine(obj, line, actionType);
  1011.       }
  1012.     }
  1013.   }
  1014. };

  1015. Yanfly.BEC.DefaultActionSetup = [
  1016.     ['CLEAR BATTLE LOG'],
  1017.     ['DISPLAY ACTION'],
  1018.     ['IMMORTAL', ['TARGETS', 'TRUE']],
  1019.     ['PERFORM START'],
  1020.     ['WAIT FOR MOVEMENT'],
  1021.     ['CAST ANIMATION'],
  1022.     ['WAIT FOR ANIMATION']
  1023. ];
  1024. Yanfly.BEC.DefaultActionWhole = [
  1025.     ['PERFORM ACTION'],
  1026. ];
  1027. Yanfly.BEC.DefaultActionTarget = [
  1028.     ['PERFORM ACTION'],
  1029. ];
  1030. if (eval(Yanfly.Param.BECMotionWait)) {
  1031.   Yanfly.BEC.DefaultActionWhole.push(['MOTION WAIT', ['USER']]);
  1032.   Yanfly.BEC.DefaultActionTarget.push(['MOTION WAIT', ['USER']]);
  1033. } else {
  1034.   Yanfly.BEC.DefaultActionWhole.push(['WAIT', [10]]);
  1035.   Yanfly.BEC.DefaultActionTarget.push(['WAIT', [10]]);
  1036. };
  1037. Yanfly.BEC.DefaultActionWhole.push(['ACTION ANIMATION']);
  1038. Yanfly.BEC.DefaultActionWhole.push(['WAIT FOR ANIMATION']);
  1039. Yanfly.BEC.DefaultActionTarget.push(['ACTION ANIMATION']);
  1040. Yanfly.BEC.DefaultActionTarget.push(['WAIT FOR ANIMATION']);
  1041. Yanfly.BEC.DefaultActionFollow = [
  1042. ];
  1043. Yanfly.BEC.DefaultActionFinish = [
  1044.     ['IMMORTAL', ['TARGETS', 'FALSE']],
  1045.     ['WAIT FOR NEW LINE'],
  1046.     ['CLEAR BATTLE LOG'],
  1047.     ['PERFORM FINISH'],
  1048.     ['WAIT FOR MOVEMENT'],
  1049.     ['WAIT FOR EFFECT'],
  1050.     ['ACTION COMMON EVENT'],
  1051. ];
  1052. DataManager.setDefaultActions = function(obj) {
  1053.     obj.setupActions = Yanfly.BEC.DefaultActionSetup.slice();
  1054.     if (this.isWholeAction(obj)) {
  1055.       obj.wholeActions = Yanfly.BEC.DefaultActionWhole.slice();
  1056.       this.addActionEffects(obj, obj.wholeActions);
  1057.       obj.targetActions = [];
  1058.     } else {
  1059.       obj.wholeActions = [];
  1060.       obj.targetActions = Yanfly.BEC.DefaultActionTarget.slice();
  1061.       this.addActionEffects(obj, obj.targetActions);
  1062.     }
  1063.     obj.followActions = Yanfly.BEC.DefaultActionFollow.slice();
  1064.     obj.finishActions = Yanfly.BEC.DefaultActionFinish.slice();
  1065. };

  1066. DataManager.isWholeAction = function(obj) {
  1067.   if (obj.animationId > 0 && $dataAnimations[obj.animationId]) {
  1068.     var animation = $dataAnimations[obj.animationId];
  1069.     if (animation.position === 3) return true;
  1070.     if (animation.position !== 3 && [2, 8, 10].contains(obj.scope)) return true;
  1071.   }
  1072.   return false;
  1073. };

  1074. DataManager.addActionEffects = function(obj, array) {
  1075.     for (;;) {
  1076.       array[array.length] = ['ACTION EFFECT'];
  1077.       array[array.length] = ['DEATH BREAK'];
  1078.       obj.repeats -= 1;
  1079.       if (obj.repeats <= 0) break;
  1080.       array[array.length] = ['WAIT', [8]];
  1081.     }
  1082.     obj.repeats = 1;
  1083. };

  1084. Yanfly.BEC.SeqType6 =
  1085.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i;
  1086. Yanfly.BEC.SeqType5 =
  1087.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i;
  1088. Yanfly.BEC.SeqType4 =
  1089.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i;
  1090. Yanfly.BEC.SeqType3 =
  1091.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*)/i;
  1092. Yanfly.BEC.SeqType2 =
  1093.   /[ ]*(.*):[ ](.*),[ ](.*)/i;
  1094. Yanfly.BEC.SeqType1 =
  1095.   /[ ]*(.*):[ ](.*)/i;
  1096. Yanfly.BEC.SeqType0 =
  1097.   /[ ]*(.*)/i;
  1098. DataManager.convertSequenceLine = function(obj, line, actionType) {
  1099.   if (actionType <= 0 || actionType > 5) return;
  1100.   Yanfly.BEC.SeqType;
  1101.   var seqArgs;
  1102.   if (line.match(Yanfly.BEC.SeqType6)) {
  1103.     Yanfly.BEC.SeqType = RegExp.$1;
  1104.     seqArgs =
  1105.       [RegExp.$2, RegExp.$3, RegExp.$4, RegExp.$5, RegExp.$6, RegExp.$7];
  1106.   } else if (line.match(Yanfly.BEC.SeqType5)) {
  1107.     Yanfly.BEC.SeqType = RegExp.$1;
  1108.     seqArgs = [RegExp.$2, RegExp.$3, RegExp.$4, RegExp.$5, RegExp.$6];
  1109.   } else if (line.match(Yanfly.BEC.SeqType4)) {
  1110.     Yanfly.BEC.SeqType = RegExp.$1;
  1111.     seqArgs = [RegExp.$2, RegExp.$3, RegExp.$4, RegExp.$5];
  1112.   } else if (line.match(Yanfly.BEC.SeqType3)) {
  1113.     Yanfly.BEC.SeqType = RegExp.$1;
  1114.     seqArgs = [RegExp.$2, RegExp.$3, RegExp.$4];
  1115.   } else if (line.match(Yanfly.BEC.SeqType2)) {
  1116.     Yanfly.BEC.SeqType = RegExp.$1;
  1117.     seqArgs = [RegExp.$2, RegExp.$3];
  1118.   } else if (line.match(Yanfly.BEC.SeqType1)) {
  1119.     Yanfly.BEC.SeqType = RegExp.$1;
  1120.     seqArgs = [RegExp.$2];
  1121.   } else if (line.match(Yanfly.BEC.SeqType0)) {
  1122.     Yanfly.BEC.SeqType = RegExp.$1;
  1123.     seqArgs = [];
  1124.   } else {
  1125.     return;
  1126.   }
  1127.   var array = [Yanfly.BEC.SeqType, seqArgs];
  1128.   if (actionType === 1) obj.setupActions[obj.setupActions.length] = array;
  1129.   if (actionType === 2) obj.wholeActions[obj.wholeActions.length] = array;
  1130.   if (actionType === 3) obj.targetActions[obj.targetActions.length] = array;
  1131.   if (actionType === 4) obj.followActions[obj.followActions.length] = array;
  1132.   if (actionType === 5) obj.finishActions[obj.finishActions.length] = array;
  1133. };

  1134. DataManager.processBECNotetags1 = function(group) {
  1135.   var note1 = /<(?:CAST ANIMATION|cast ani):[ ](\d+)>/i;
  1136.   for (var n = 1; n < group.length; n++) {
  1137.     var obj = group[n];
  1138.     var notedata = obj.note.split(/[\r\n]+/);

  1139.     obj.castAnimation = 0;
  1140.     if (obj.hitType === 0) obj.castAnimation = Yanfly.Param.CastCertHit;
  1141.     if (obj.hitType === 1) obj.castAnimation = Yanfly.Param.CastPhysical;
  1142.     if (obj.hitType === 2) obj.castAnimation = Yanfly.Param.CastMagical;

  1143.     for (var i = 0; i < notedata.length; i++) {
  1144.       var line = notedata[i];
  1145.       if (line.match(note1)) {
  1146.         obj.castAnimation = parseInt(RegExp.$1);
  1147.       }
  1148.     }
  1149.   }
  1150. };

  1151. DataManager.processBECNotetags2 = function(group) {
  1152.   var note1 = /<(?:ACTION COPY):[ ](.*):[ ]*(\d+)>/i;
  1153.   var note2 = /<(?:SPEED):[ ]([\+\-]\d+)>/i;
  1154.   var note3 = /<(?:DISPLAY NAME|DISPLAY TEXT):[ ](.*)>/i;
  1155.   var note4 = /<(?:DISPLAY ICON):[ ](\d+)>/i;
  1156.   for (var n = 1; n < group.length; n++) {
  1157.     var obj = group[n];
  1158.     var notedata = obj.note.split(/[\r\n]+/);

  1159.     obj.battleDisplayText = obj.name;
  1160.     obj.battleDisplayIcon = obj.iconIndex;

  1161.     for (var i = 0; i < notedata.length; i++) {
  1162.       var line = notedata[i];
  1163.       if (line.match(note1)) {
  1164.         var text = String(RegExp.$1).toUpperCase();
  1165.         var target;
  1166.         if (['I', 'ITEM'].contains(text)) {
  1167.           target = $dataItems[parseInt(RegExp.$2)];
  1168.         } else if (['S', 'SKILL'].contains(text)) {
  1169.           target = $dataSkills[parseInt(RegExp.$2)];
  1170.         }
  1171.         if (target) {
  1172.           obj.setupActions = target.setupActions.slice();
  1173.           obj.wholeActions = target.wholeActions.slice();
  1174.           obj.targetActions = target.targetActions.slice();
  1175.           obj.followActions = target.followActions.slice();
  1176.           obj.finishActions = target.finishActions.slice();
  1177.         }
  1178.       } else if (line.match(note2)) {
  1179.         obj.speed = parseInt(RegExp.$1);
  1180.       } else if (line.match(note3)) {
  1181.         obj.battleDisplayText = String(RegExp.$1);
  1182.       } else if (line.match(note4)) {
  1183.         obj.battleDisplayIcon = parseInt(RegExp.$1);
  1184.       }
  1185.     }
  1186.   }
  1187. };

  1188. DataManager.processBECNotetags3 = function(group) {
  1189.   var note1 = /<(?:ATTACK ANIMATION|attack ani):[ ](\d+)>/i;
  1190.   for (var n = 1; n < group.length; n++) {
  1191.     var obj = group[n];
  1192.     var notedata = obj.note.split(/[\r\n]+/);

  1193.     obj.attackAnimationId = Yanfly.Param.EnemyAtkAni;

  1194.     for (var i = 0; i < notedata.length; i++) {
  1195.       var line = notedata[i];
  1196.       if (line.match(note1)) {
  1197.         obj.attackAnimationId = parseInt(RegExp.$1);
  1198.       }
  1199.     }
  1200.   }
  1201. };

  1202. DataManager.processBECNotetags4 = function(group) {
  1203.   var note1 = /<(?:REFLECT ANIMATION|reflect ani):[ ](\d+)>/i;
  1204.   for (var n = 1; n < group.length; n++) {
  1205.     var obj = group[n];
  1206.     var notedata = obj.note.split(/[\r\n]+/);

  1207.     obj.reflectAnimationId = 0;
  1208.     obj.spriteCannotMove = false;

  1209.     for (var i = 0; i < notedata.length; i++) {
  1210.       var line = notedata[i];
  1211.       if (line.match(note1)) {
  1212.         obj.reflectAnimationId = parseInt(RegExp.$1);
  1213.       } else if (line.match(/<(?:SPRITE CANNOT MOVE)>/i)) {
  1214.         obj.spriteCannotMove = true;
  1215.       }
  1216.     }
  1217.   }
  1218. };

  1219. DataManager.processBECNotetags5 = function(group, isActor) {
  1220.   for (var n = 1; n < group.length; n++) {
  1221.     var obj = group[n];
  1222.     var notedata = obj.note.split(/[\r\n]+/);

  1223.     if (isActor) {
  1224.       obj.anchorX = Yanfly.Param.BECAnchorX;
  1225.       obj.anchorY = Yanfly.Param.BECAnchorY;
  1226.     }

  1227.     for (var i = 0; i < notedata.length; i++) {
  1228.       var line = notedata[i];
  1229.       if (line.match(/<(?:ANCHOR X):[ ](\d+)[.](\d+)>/i)) {
  1230.         obj.anchorX = eval(String(RegExp.$1) + '.' + String(RegExp.$2));
  1231.       } else if (line.match(/<(?:ANCHOR Y):[ ](\d+)[.](\d+)>/i)) {
  1232.         obj.anchorY = eval(String(RegExp.$1) + '.' + String(RegExp.$2));
  1233.       }
  1234.     }
  1235.   }
  1236. };

  1237. DataManager.processBECNotetags6 = function(group) {
  1238.   var note1a = /<(?:ACTION START):[ ](\d+)>/i;
  1239.   var note1b = /<(?:ACTION START):[ ](\d+)[ ](?:THROUGH|to)[ ](\d+)>/i;
  1240.   var note2a = /<(?:TURN START):[ ](\d+)>/i;
  1241.   var note2b = /<(?:TURN START):[ ](\d+)[ ](?:THROUGH|to)[ ](\d+)>/i;
  1242.   for (var n = 1; n < group.length; n++) {
  1243.     var obj = group[n];
  1244.     var notedata = obj.note.split(/[\r\n]+/);

  1245.     for (var i = 0; i < notedata.length; i++) {
  1246.       var line = notedata[i];
  1247.       if (line.match(note1a)) {
  1248.         var turns = parseInt(RegExp.$1);
  1249.         obj.autoRemovalTiming = 3;
  1250.         obj.maxTurns = turns;
  1251.         obj.minTurns = turns;
  1252.       } else if (line.match(note1b)) {
  1253.         var turns1 = parseInt(RegExp.$1);
  1254.         var turns2 = parseInt(RegExp.$2);
  1255.         obj.autoRemovalTiming = 3;
  1256.         obj.maxTurns = turns1;
  1257.         obj.minTurns = turns2;
  1258.       } else if (line.match(note2a)) {
  1259.         var turns = parseInt(RegExp.$1);
  1260.         obj.autoRemovalTiming = 4;
  1261.         obj.maxTurns = turns;
  1262.         obj.minTurns = turns;
  1263.       } else if (line.match(note2b)) {
  1264.         var turns1 = parseInt(RegExp.$1);
  1265.         var turns2 = parseInt(RegExp.$2);
  1266.         obj.autoRemovalTiming = 4;
  1267.         obj.maxTurns = turns1;
  1268.         obj.minTurns = turns2;
  1269.       }
  1270.     }
  1271.   }
  1272. };

  1273. //=============================================================================
  1274. // TouchInput
  1275. //=============================================================================

  1276. Yanfly.BEC.TouchInput_onMouseMove = TouchInput._onMouseMove;
  1277. TouchInput._onMouseMove = function(event) {
  1278.     Yanfly.BEC.TouchInput_onMouseMove.call(this, event);
  1279.     this._mouseOverX = Graphics.pageToCanvasX(event.pageX);
  1280.     this._mouseOverY = Graphics.pageToCanvasY(event.pageY);
  1281. };

  1282. //=============================================================================
  1283. // BattleManager
  1284. //=============================================================================

  1285. Yanfly.BEC.BattleManager_initMembers = BattleManager.initMembers;
  1286. BattleManager.initMembers = function() {
  1287.     Yanfly.BEC.BattleManager_initMembers.call(this);
  1288.     this._forceSelection = false;
  1289.     this._allSelection = false;
  1290.     this._victoryPhase = false;
  1291.     this._forceActionQueue = [];
  1292. };

  1293. BattleManager.isBattleSystem = function(value) {
  1294.     return value.toLowerCase() === $gameSystem.getBattleSystem();
  1295. };

  1296. BattleManager.isDTB = function() {
  1297.     return this.isBattleSystem('dtb');
  1298. };

  1299. BattleManager.isTurnBased = function() {
  1300.     if (this.isDTB()) return true;
  1301.     return false;
  1302. };

  1303. BattleManager.isTickBased = function() {
  1304.     return !this.isTurnBased();
  1305. };

  1306. BattleManager.tickRate = function() {
  1307.     return 1;
  1308. };

  1309. BattleManager.forceSelection = function() {
  1310.     this._forceSelection = true;
  1311. };

  1312. BattleManager.isForceSelection = function() {
  1313.     return this._forceSelection;
  1314. };

  1315. BattleManager.resetSelection = function() {
  1316.     this._forceSelection = false;
  1317. };

  1318. BattleManager.startAllSelection = function() {
  1319.     this._allSelection = true;
  1320. };

  1321. BattleManager.isAllSelection = function() {
  1322.      return this._allSelection && BattleManager.isInputting();
  1323. };

  1324. BattleManager.stopAllSelection = function() {
  1325.     this._allSelection = false;
  1326. };

  1327. Yanfly.BEC.BattleManager_makeEscapeRatio = BattleManager.makeEscapeRatio;
  1328. BattleManager.makeEscapeRatio = function() {
  1329.     if (this.isDTB()) {
  1330.       this._escapeRatio = eval(Yanfly.Param.BECEscRatio);
  1331.       this._escapeFailBoost = eval(Yanfly.Param.BECEscFail);
  1332.     } else {
  1333.       this._escapeFailBoost = 0.1;
  1334.       Yanfly.BEC.BattleManager_makeEscapeRatio.call(this);
  1335.     }
  1336. };

  1337. BattleManager.timeBasedStates = function() {
  1338.     if (!$gameParty.inBattle()) return false;
  1339.     if (this.isTurnBased()) return false;
  1340.     if (this._timeBasedStates !== undefined) return this._timeBasedStates;
  1341.     this._timeBasedStates = eval(Yanfly.Param.BECTimeStates);
  1342.     return this._timeBasedStates;
  1343. };

  1344. BattleManager.timeBasedBuffs = function() {
  1345.     if (!$gameParty.inBattle()) return false;
  1346.     if (this.isTurnBased()) return false;
  1347.     if (this._timeBasedBuffs !== undefined) return this._timeBasedBuffs;
  1348.     this._timeBasedBuffs = eval(Yanfly.Param.BECTimeBuffs);
  1349.     return this._timeBasedBuffs;
  1350. };

  1351. BattleManager.displayStartMessages = function() {
  1352.     if (eval(Yanfly.Param.BECEmergeText)) {
  1353.       $gameTroop.enemyNames().forEach(function(name) {
  1354.           $gameMessage.add(TextManager.emerge.format(name));
  1355.       });
  1356.     }
  1357.     if (this._preemptive && eval(Yanfly.Param.BECPreEmpText)) {
  1358.         $gameMessage.add(TextManager.preemptive.format($gameParty.name()));
  1359.     } else if (this._surprise && eval(Yanfly.Param.BECSurpText)) {
  1360.         $gameMessage.add(TextManager.surprise.format($gameParty.name()));
  1361.     }
  1362. };

  1363. BattleManager.registerSprite = function(battler, sprite) {
  1364.   if (!this._registeredSprites) this._registeredSprites = {};
  1365.   if (battler.isActor()) var id = 100000 + battler.actorId();
  1366.   if (battler.isEnemy()) var id = 200000 + battler.index();
  1367.   this._registeredSprites[id] = sprite;
  1368. };

  1369. BattleManager.getSprite = function(battler) {
  1370.   if (!this._registeredSprites) this._registeredSprites = {};
  1371.   if (battler.isActor()) var id = 100000 + battler.actorId();
  1372.   if (battler.isEnemy()) var id = 200000 + battler.index();
  1373.   return this._registeredSprites[id];
  1374. };

  1375. BattleManager.setSpritePriority = function() {
  1376.     if ($gameSystem.isSideView()) {
  1377.       this._spritePriority = eval(Yanfly.Param.BECSideSpPrio);
  1378.     } else {
  1379.       this._spritePriority = eval(Yanfly.Param.BECFrontSprite);
  1380.     }
  1381.     if (this._spritePriority === false) this._spritePriority = 0;
  1382.     if (this._spritePriority === true) this._spritePriority = 1;
  1383. };

  1384. BattleManager.getSpritePriority = function() {
  1385.     if (!this._spritePriority) this.setSpritePriority();
  1386.     return this._spritePriority;
  1387. };

  1388. BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
  1389.     var lastActor = this.actor();
  1390.     this._actorIndex = newActorIndex;
  1391.     var newActor = this.actor();
  1392.     if (lastActor) {
  1393.         lastActor.setActionState(lastActorActionState);
  1394.         lastActor.spriteReturnHome();
  1395.     }
  1396.     if (newActor) {
  1397.         newActor.setActionState('inputting');
  1398.         newActor.spriteStepForward();
  1399.     }
  1400. };

  1401. BattleManager.createActions = function() {
  1402.     $gameParty.createActions();
  1403.     $gameTroop.createActions();
  1404. };

  1405. BattleManager.clearInputtingAction = function() {
  1406.     if (this.inputtingAction()) this.inputtingAction().clear();
  1407. };

  1408. Yanfly.BEC.BattleManager_checkBattleEnd = BattleManager.checkBattleEnd;
  1409. BattleManager.checkBattleEnd = function() {
  1410.     if (this._phase === 'actionList') return false;
  1411.     if (this._phase === 'actionTargetList') return false;
  1412.     if (this._phase === 'action') return false;
  1413.     if (this._phase === 'phaseChange') return false;
  1414.     if ($gameTroop.isEventRunning()) return false;
  1415.     return Yanfly.BEC.BattleManager_checkBattleEnd.call(this);
  1416. };

  1417. Yanfly.BEC.BattleManager_processTurn = BattleManager.processTurn;
  1418. BattleManager.processTurn = function() {
  1419.     this._processTurn = true;
  1420.     Yanfly.BEC.BattleManager_processTurn.call(this);
  1421.     this._processTurn = false;
  1422. };

  1423. Yanfly.BEC.BattleManager_processVictory = BattleManager.processVictory;
  1424. BattleManager.processVictory = function() {
  1425.     this._logWindow.clear();
  1426.     this._victoryPhase = true;
  1427.     if (this._windowLayer) this._windowLayer.x = 0;
  1428.     Yanfly.BEC.BattleManager_processVictory.call(this);
  1429. };

  1430. BattleManager.processEscape = function() {
  1431.     $gameParty.performEscape();
  1432.     SoundManager.playEscape();
  1433.     var success = this._preemptive ? true : (Math.random() < this._escapeRatio);
  1434.     if (success) {
  1435.         $gameParty.performEscapeSuccess();
  1436.         this.displayEscapeSuccessMessage();
  1437.         this._escaped = true;
  1438.         this.processAbort();
  1439.     } else {
  1440.         this.displayEscapeFailureMessage();
  1441.         this._escapeRatio += this._escapeFailBoost;
  1442.         $gameParty.clearActions();
  1443.         this.startTurn();
  1444.     }
  1445.     return success;
  1446. };

  1447. Yanfly.BEC.BattleManager_processAbort = BattleManager.processAbort;
  1448. BattleManager.processAbort = function() {
  1449.     $gameParty.removeBattleStates();
  1450.     Yanfly.BEC.BattleManager_processAbort.call(this);
  1451. };

  1452. BattleManager.startTurn = function() {
  1453.     this._enteredEndPhase = false;
  1454.     this._phase = 'turn';
  1455.     this.clearActor();
  1456.     $gameTroop.increaseTurn();
  1457.     $gameParty.onTurnStart();
  1458.     $gameTroop.onTurnStart();
  1459.     this._performedBattlers = [];
  1460.     this.makeActionOrders();
  1461.     $gameParty.requestMotionRefresh();
  1462.     this._logWindow.startTurn();
  1463.     this._subject = this.getNextSubject();
  1464. };

  1465. Yanfly.BEC.BattleManager_endTurn = BattleManager.endTurn;
  1466. BattleManager.endTurn = function() {
  1467.     if (this.isTurnBased() && this._spriteset.isPopupPlaying()) return;
  1468.     if (this.isTurnBased() && this._enteredEndPhase) {
  1469.       this._phase = 'turnEnd';
  1470.       this._preemptive = false;
  1471.       this._surprise = false;
  1472.       return;
  1473.     }
  1474.     this._enteredEndPhase = true;
  1475.     Yanfly.BEC.BattleManager_endTurn.call(this);
  1476. };

  1477. BattleManager.getNextSubject = function() {
  1478.     if ($gameTroop.turnCount() <= 0) return;
  1479.     this._performedBattlers = this._performedBattlers || [];
  1480.     this.makeActionOrders();
  1481.     for (;;) {
  1482.         var battlerArray = [];
  1483.         for (var i = 0; i < this._actionBattlers.length; ++i) {
  1484.           var obj = this._actionBattlers[i];
  1485.           if (!this._performedBattlers.contains(obj)) battlerArray.push(obj);
  1486.         }
  1487.         this._actionBattlers = battlerArray;
  1488.         var battler = this._actionBattlers.shift();
  1489.         if (!battler) return null;
  1490.         if (battler.isBattleMember() && battler.isAlive()) {
  1491.             this._performedBattlers.push(battler);
  1492.             return battler;
  1493.         }
  1494.     }
  1495. };

  1496. BattleManager.update = function() {
  1497.     if (!this.isBusy() && !this.updateEvent()) {
  1498.         switch (this._phase) {
  1499.         case 'start':
  1500.             this.startInput();
  1501.             break;
  1502.         case 'turn':
  1503.             this.updateTurn();
  1504.             break;
  1505.         case 'action':
  1506.             this.updateAction();
  1507.             break;
  1508.         case 'phaseChange':
  1509.             this.updatePhase();
  1510.             break;
  1511.         case 'actionList':
  1512.             this.updateActionList()
  1513.             break;
  1514.         case 'actionTargetList':
  1515.             this.updateActionTargetList()
  1516.             break;
  1517.         case 'turnEnd':
  1518.             this.updateTurnEnd();
  1519.             break;
  1520.         case 'battleEnd':
  1521.             this.updateBattleEnd();
  1522.             break;
  1523.         }
  1524.     }
  1525. };

  1526. BattleManager.updateEvent = function() {
  1527.     if (this._processingForcedAction) return false;
  1528.     switch (this._phase) {
  1529.     case 'start':
  1530.     case 'turn':
  1531.     case 'turnEnd':
  1532.     case 'actionList':
  1533.     case 'actionTargetList':
  1534.       if (this.isActionForced()) {
  1535.         this.processForcedAction();
  1536.         return true;
  1537.       } else {
  1538.         return this.updateEventMain();
  1539.       }
  1540.     }
  1541.     return this.checkAbort();
  1542. };

  1543. Yanfly.BEC.BattleManager_forceAction = BattleManager.forceAction;
  1544. BattleManager.forceAction = function(battler) {
  1545.     this.createForceActionFailSafes();
  1546.     this.savePreForceActionSettings();
  1547.     Yanfly.BEC.BattleManager_forceAction.call(this, battler);
  1548. };

  1549. BattleManager.createForceActionFailSafes = function() {
  1550.     this._actionList = this._actionList || [];
  1551.     this._targets = this._targets || [];
  1552.     this._allTargets = this._allTargets || [];
  1553.     this._individualTargets = this._individualTargets || [];
  1554.     this._phaseSteps = this._phaseSteps || [];
  1555.     this._conditionFlags = this._conditionFlags || [];
  1556.     this._trueFlags = this._trueFlags || [];
  1557. };

  1558. BattleManager.savePreForceActionSettings = function() {
  1559.     var settings = this.setPreForceActionSettings();
  1560.     this._forceActionQueue.push(settings);
  1561. };

  1562. BattleManager.setPreForceActionSettings = function() {
  1563.     return {
  1564.       subject: this._subject,
  1565.       action: JsonEx.makeDeepCopy(this._action),
  1566.       actionList: JsonEx.makeDeepCopy(this._actionList),
  1567.       targets: this._targets.slice(),
  1568.       allTargets: this._allTargets.slice(),
  1569.       indTargets: this._individualTargets.slice(),
  1570.       phaseSteps: JsonEx.makeDeepCopy(this._phaseSteps),
  1571.       returnPhase: this._returnPhase,
  1572.       phase: this._phase,
  1573.       conditionFlags: JsonEx.makeDeepCopy(this._conditionFlags),
  1574.       trueFlags: JsonEx.makeDeepCopy(this._trueFlags)
  1575.     }
  1576. };

  1577. BattleManager.loadPreForceActionSettings = function() {
  1578.     var settings = this._forceActionQueue[0];
  1579.     if (settings) {
  1580.       this._forceActionQueue.shift();
  1581.       this.resetPreForceActionSettings(settings);
  1582.       return this._subject && this._subject.isAppeared();
  1583.     } else {
  1584.       return false;
  1585.     }   
  1586. };

  1587. BattleManager.resetPreForceActionSettings = function(settings) {
  1588.     this._subject = settings['subject'];
  1589.     this._action = settings['action'];
  1590.     this._actionList = settings['actionList'];
  1591.     this._targets = settings['targets'];
  1592.     this._allTargets = settings['allTargets'];
  1593.     this._individualTargets = settings['indTargets'];
  1594.     this._phaseSteps = settings['phaseSteps'];
  1595.     this._returnPhase = settings['returnPhase'];
  1596.     this._conditionFlags = settings['conditionFlags'];
  1597.     this._trueFlags = settings['trueFlags'];
  1598.     this._phase = settings['phase'];   
  1599. };

  1600. Yanfly.BEC.BattleManager_processForcedAction =
  1601.     BattleManager.processForcedAction;
  1602. BattleManager.processForcedAction = function() {
  1603.     if (this._actionForcedBattler) {
  1604.       this._preForcePhase = this._phase;
  1605.       this._processingForcedAction = true;
  1606.     }
  1607.     Yanfly.BEC.BattleManager_processForcedAction.call(this);
  1608. };

  1609. BattleManager.setTargets = function(array) {
  1610.     this._targets = [];
  1611.     var max = array.length;
  1612.     for (var i = 0; i < max; ++i) {
  1613.       var target = array[i];
  1614.       if (target) this._targets.push(target);
  1615.     }
  1616. };

  1617. BattleManager.updateAction = function() {
  1618.     var target = this._targets.shift();
  1619.     if (target) {
  1620.         this.invokeAction(this._subject, target);
  1621.     } else {
  1622.         if (this._returnPhase === 'target') {
  1623.           this.setTargets([this._individualTargets[0]]);
  1624.           this._phase = 'actionTargetList';
  1625.         } else {
  1626.           this.setTargets(this._allTargets.slice());
  1627.           this._phase = 'actionList';
  1628.         }
  1629.     }
  1630. };

  1631. BattleManager.invokeAction = function(subject, target) {
  1632.   if (!eval(Yanfly.Param.BECOptSpeed))  this._logWindow.push('pushBaseLine');
  1633.   var normal = true;
  1634.   if (Math.random() < this._action.itemMrf(target)) {
  1635.     this.invokeMagicReflection(subject, target);
  1636.   } else if (Math.random() < this._action.itemCnt(target)) {
  1637.     this.invokeCounterAttack(subject, target);
  1638.   } else {
  1639.     this.invokeNormalAction(subject, target);
  1640.   }
  1641.   subject.setLastTarget(target);
  1642.   if (!eval(Yanfly.Param.BECOptSpeed)) this._logWindow.push('popBaseLine');
  1643. };

  1644. BattleManager.invokeCounterAttack = function(subject, target) {
  1645.     var action = new Game_Action(target);
  1646.     this._logWindow.displayCounter(target);
  1647.     action.setAttack();
  1648.     action.apply(subject);
  1649.     this._logWindow.displayActionResults(subject, subject);
  1650.     if (subject.isDead()) subject.performCollapse();
  1651. };

  1652. Yanfly.BEC.BattleManager_invokeMagicReflection =
  1653.     BattleManager.invokeMagicReflection;
  1654. BattleManager.invokeMagicReflection = function(subject, target) {
  1655.     Yanfly.BEC.BattleManager_invokeMagicReflection.call(this, subject, target);
  1656.     if (subject.isDead()) subject.performCollapse();
  1657. };

  1658. BattleManager.updatePhase = function() {
  1659.     var phase = this._phaseSteps.shift();
  1660.     if (phase) this.createPhaseChanges();
  1661.     switch (phase) {
  1662.     case 'setup':
  1663.       this.createSetupActions();
  1664.       break;
  1665.     case 'whole':
  1666.       this.createWholeActions();
  1667.       break;
  1668.     case 'target':
  1669.       this.createTargetActions();
  1670.       break;
  1671.     case 'follow':
  1672.       this.createFollowActions();
  1673.       break;
  1674.     case 'finish':
  1675.       this.createFinishActions();
  1676.       break;
  1677.     default:
  1678.       this.endAction();
  1679.       break;
  1680.     }
  1681. };

  1682. BattleManager.createPhaseChanges = function() {
  1683.     this._phase = 'actionList';
  1684.     this.setTargets(this._allTargets.slice());
  1685.     this._conditionFlags = [];
  1686.     this._trueFlags = [];
  1687. };

  1688. BattleManager.createSetupActions = function() {
  1689.     $gameTemp.clearActionSequenceSettings();
  1690.     this._returnPhase = 'setup';
  1691.     this._actionList = this._action.item().setupActions.slice();
  1692. };

  1693. BattleManager.createWholeActions = function() {
  1694.     this._returnPhase = 'whole';
  1695.     this._actionList = this._action.item().wholeActions.slice();
  1696. };

  1697. BattleManager.createTargetActions = function() {
  1698.     this._returnPhase = 'target';
  1699.     this._phase = 'actionTargetList';
  1700.     this.setTargets([this._individualTargets[0]]);
  1701.     this._actionList = this._action.item().targetActions.slice();
  1702. };

  1703. BattleManager.createFollowActions = function() {
  1704.     this._returnPhase = 'follow';
  1705.     this._actionList = this._action.item().followActions.slice();
  1706. };

  1707. BattleManager.createFinishActions = function() {
  1708.     this._returnPhase = 'finish';
  1709.     this._actionList = this._action.item().finishActions.slice();
  1710. };

  1711. Yanfly.BEC.BattleManager_endAction = BattleManager.endAction;
  1712. BattleManager.endAction = function() {
  1713.     if (this._processingForcedAction) {
  1714.       this._phase = this._preForcePhase;
  1715.     }
  1716.     this._processingForcedAction = false;
  1717.     if (this._subject) this._subject.onAllActionsEnd();
  1718.     if (this.loadPreForceActionSettings()) return;
  1719.     Yanfly.BEC.BattleManager_endAction.call(this);
  1720. };

  1721. BattleManager.updateActionList = function() {
  1722.     for (;;) {
  1723.       this._actSeq = this._actionList.shift();
  1724.       if (this._actSeq) {
  1725.         if (!this.actionConditionsMet(this._actSeq)) continue;
  1726.         var seqName = this._actSeq[0].toUpperCase();
  1727.         if (!this.processActionSequenceCheck(seqName, this._actSeq[1])) {
  1728.           break;
  1729.         }
  1730.       } else {
  1731.         this._phase = 'phaseChange';
  1732.         break;
  1733.       }
  1734.     }
  1735. };

  1736. BattleManager.updateActionTargetList = function() {
  1737.     for (;;) {
  1738.       this._actSeq = this._actionList.shift();
  1739.       if (this._actSeq) {
  1740.         if (!this.actionConditionsMet(this._actSeq)) continue;
  1741.         var seqName = this._actSeq[0].toUpperCase();
  1742.         if (!this.processActionSequenceCheck(seqName, this._actSeq[1])) {
  1743.           break;
  1744.         }
  1745.       } else if (this._individualTargets.length > 0) {
  1746.         this._individualTargets.shift();
  1747.         if (this._individualTargets.length > 0) {
  1748.           this.setTargets([this._individualTargets[0]]);
  1749.           this._actionList = this._action.item().targetActions.slice();
  1750.         } else {
  1751.           this._phase = 'phaseChange';
  1752.           break;
  1753.         }
  1754.       } else {
  1755.         this._phase = 'phaseChange';
  1756.         break;
  1757.       }
  1758.     }
  1759. };

  1760. BattleManager.updateActionTargetList = function() {
  1761.     for (;;) {
  1762.       this._actSeq = this._actionList.shift();
  1763.       if (this._actSeq) {
  1764.         if (!this.actionConditionsMet(this._actSeq)) continue;
  1765.         var seqName = this._actSeq[0].toUpperCase();
  1766.         if (!this.processActionSequenceCheck(seqName, this._actSeq[1])) {
  1767.           break;
  1768.         }
  1769.       } else if (this._individualTargets.length > 0) {
  1770.         this._individualTargets.shift();
  1771.         if (this._individualTargets.length > 0) {
  1772.           this.setTargets([this._individualTargets[0]]);
  1773.           this._actionList = this._action.item().targetActions.slice();
  1774.         } else {
  1775.           this._phase = 'phaseChange';
  1776.           break;
  1777.         }
  1778.       } else {
  1779.         this._phase = 'phaseChange';
  1780.         break;
  1781.       }
  1782.     }
  1783. };

  1784. BattleManager.startAction = function() {
  1785.     var subject = this._subject;
  1786.     var action = subject.currentAction();
  1787.     this._action = action;
  1788.     var targets = action.makeTargets();
  1789.     this.setTargets(targets);
  1790.     this._allTargets = targets.slice();
  1791.     this._individualTargets = targets.slice();
  1792.     this._phase = 'phaseChange';
  1793.     this._phaseSteps = ['setup', 'whole', 'target', 'follow', 'finish'];
  1794.     this._returnPhase = '';
  1795.     this._actionList = [];
  1796.     subject.useItem(this._action.item());
  1797.     this._action.applyGlobal();
  1798.     this._logWindow.startAction(this._subject, this._action, this._targets);
  1799. };

  1800. BattleManager.processActionSequenceCheck = function(actionName, actionArgs) {
  1801.     // IF condition
  1802.     if (actionName.match(/IF[ ](.*)/i)) {
  1803.       return this.actionIfConditions(actionName, actionArgs);
  1804.     }
  1805.     return this.processActionSequence(actionName, actionArgs)
  1806. };

  1807. BattleManager.processActionSequence = function(actionName, actionArgs) {
  1808.     // NO ACTION
  1809.     if (actionName === '') {
  1810.       return true;
  1811.     }
  1812.     // ACTION ANIMATION
  1813.     if (actionName === 'ACTION ANIMATION') {
  1814.       return this.actionActionAnimation(actionArgs);
  1815.     }
  1816.     // ACTION EFFECT
  1817.     if (actionName === 'ACTION COMMON EVENT') {
  1818.       return this.actionActionCommonEvent();
  1819.     }
  1820.     // ACTION EFFECT
  1821.     if (actionName === 'ACTION EFFECT') {
  1822.       return this.actionActionEffect(actionArgs);
  1823.     }
  1824.     // ANI WAIT: frames
  1825.     if (['ANI WAIT', 'ANIWAIT', 'ANIMATION WAIT'].contains(actionName)) {
  1826.       return this.actionAniWait(actionArgs[0]);
  1827.     }
  1828.     // CAST ANIMATION
  1829.     if (actionName === 'CAST ANIMATION') {
  1830.       return this.actionCastAnimation();
  1831.     }
  1832.     // CLEAR BATTLE LOG
  1833.     if (actionName === 'CLEAR BATTLE LOG') {
  1834.       return this.actionClearBattleLog();
  1835.     }
  1836.     // DEATH BREAK
  1837.     if (actionName === 'DEATH BREAK') {
  1838.       return this.actionDeathBreak();
  1839.     }
  1840.     // DISPLAY ACTION
  1841.     if (actionName === 'DISPLAY ACTION') {
  1842.       return this.actionDisplayAction();
  1843.     }
  1844.     // IMMORTAL: targets, true/false
  1845.     if (actionName === 'IMMORTAL') {
  1846.       return this.actionImmortal(actionArgs);
  1847.     }
  1848.     // MOTION WAIT
  1849.     if (actionName === 'MOTION WAIT') {
  1850.       return this.actionMotionWait(actionArgs);
  1851.     }
  1852.     // PERFORM ACTION
  1853.     if (actionName === 'PERFORM ACTION') {
  1854.       return this.actionPerformAction();
  1855.     }
  1856.     // PERFORM FINISH
  1857.     if (actionName === 'PERFORM FINISH') {
  1858.       return this.actionPerformFinish();
  1859.     }
  1860.     // PERFORM START
  1861.     if (actionName === 'PERFORM START') {
  1862.       return this.actionPerformStart();
  1863.     }
  1864.     // WAIT: frames
  1865.     if (actionName === 'WAIT') {
  1866.       return this.actionWait(actionArgs[0]);
  1867.     }
  1868.     // WAIT FOR ANIMATION
  1869.     if (actionName === 'WAIT FOR ANIMATION') {
  1870.       return this.actionWaitForAnimation();
  1871.     }
  1872.     // WAIT FOR EFFECT
  1873.     if (actionName === 'WAIT FOR EFFECT') {
  1874.       return this.actionWaitForEffect();
  1875.     }
  1876.     // WAIT FOR MOVEMENT
  1877.     if (actionName === 'WAIT FOR MOVEMENT') {
  1878.       return this.actionWaitForMovement();
  1879.     }
  1880.     // WAIT FOR NEW LINE
  1881.     if (actionName === 'WAIT FOR NEW LINE') {
  1882.       return this.actionWaitForNewLine();
  1883.     }
  1884.     // WAIT FOR POPUPS
  1885.     if (actionName === 'WAIT FOR POPUPS') {
  1886.       return this.actionWaitForPopups();
  1887.     }
  1888.     return false;
  1889. };

  1890. BattleManager.makeActionTargets = function(string) {
  1891.     var targets = []
  1892.     string = string.toUpperCase()
  1893.     if (['SUBJECT', 'USER'].contains(string)) {
  1894.       return [this._subject];
  1895.     }
  1896.     if (['TARGET', 'TARGETS'].contains(string)) {
  1897.       var group = this._targets;
  1898.       for (var i = 0; i < group.length; ++i) {
  1899.         var target = group[i];
  1900.         if (target) targets.push(target);
  1901.       }
  1902.       return targets;
  1903.     }
  1904.     if (['ACTORS', 'EXISTING ACTORS', 'ALIVE ACTORS'].contains(string)) {
  1905.       var group = $gameParty.aliveMembers();
  1906.       for (var i = 0; i < group.length; ++i) {
  1907.         var target = group[i];
  1908.         if (target) targets.push(target);
  1909.       }
  1910.       return targets;
  1911.     }
  1912.     if (['ACTORS ALL', 'ALL ACTORS', 'PARTY'].contains(string)) {
  1913.       var group = $gameParty.battleMembers();
  1914.       for (var i = 0; i < group.length; ++i) {
  1915.         var target = group[i];
  1916.         if (target) targets.push(target);
  1917.       }
  1918.       return targets;
  1919.     }
  1920.     if (['DEAD ACTORS', 'DEAD ACTOR'].contains(string)) {
  1921.       var group = $gameParty.deadMembers();
  1922.       for (var i = 0; i < group.length; ++i) {
  1923.         var target = group[i];
  1924.         if (target) targets.push(target);
  1925.       }
  1926.       return targets;
  1927.     }
  1928.     if (['ACTORS NOT USER', 'ACTORS NOT SUBJECT'].contains(string)) {
  1929.       var group = $gameParty.aliveMembers();
  1930.       for (var i = 0; i < group.length; ++i) {
  1931.         var target = group[i];
  1932.         if (target && target !== this._subject) targets.push(target);
  1933.       }
  1934.       return targets;
  1935.     }
  1936.     if (['ENEMIES', 'EXISTING ENEMIES', 'ALIVE ENEMIES', 'TROOP',
  1937.     'TROOPS'].contains(string)) {
  1938.       var group = $gameTroop.aliveMembers();
  1939.       for (var i = 0; i < group.length; ++i) {
  1940.         var target = group[i];
  1941.         if (target) targets.push(target);
  1942.       }
  1943.       return targets;
  1944.     }
  1945.     if (['ENEMIES ALL', 'ALL ENEMIES'].contains(string)) {
  1946.       var group = $gameTroop.members();
  1947.       for (var i = 0; i < group.length; ++i) {
  1948.         var target = group[i];
  1949.         if (target) targets.push(target);
  1950.       }
  1951.       return targets;
  1952.     }
  1953.     if (['DEAD ENEMIES', 'DEAD ENEMY'].contains(string)) {
  1954.       var group = $gameTroop.deadMembers();
  1955.       for (var i = 0; i < group.length; ++i) {
  1956.         var target = group[i];
  1957.         if (target) targets.push(target);
  1958.       }
  1959.       return targets;
  1960.     }
  1961.     if (['ENEMIES NOT USER', 'ENEMIES NOT SUBJECT', 'TROOP NOT USER',
  1962.     'TROOP NOT SUBJECT'].contains(string)) {
  1963.       var group = $gameTroop.aliveMembers();
  1964.       for (var i = 0; i < group.length; ++i) {
  1965.         var target = group[i];
  1966.         if (target && target !== this._subject) targets.push(target);
  1967.       }
  1968.       return targets;
  1969.     }
  1970.     if (string.match(/ACTOR[ ](\d+)/i)) {
  1971.       var target = $gameParty.battleMembers()[parseInt(RegExp.$1)];
  1972.       if (target) return [target];
  1973.     }
  1974.     if (string.match(/ENEMY[ ](\d+)/i)) {
  1975.       var target = $gameTroop.members()[parseInt(RegExp.$1)];
  1976.       if (target) return [target];
  1977.     }
  1978.     if (['FRIEND', 'FRIENDS', 'ALLIES'].contains(string)) {
  1979.       var group = this._action.friendsUnit().aliveMembers();
  1980.       for (var i = 0; i < group.length; ++i) {
  1981.         var target = group[i];
  1982.         if (target) targets.push(target);
  1983.       }
  1984.       return targets;
  1985.     }
  1986.     if (['ALL FRIENDS', 'ALL ALLIES'].contains(string)) {
  1987.       var group = this._action.friendsUnit().members();
  1988.       for (var i = 0; i < group.length; ++i) {
  1989.         var target = group[i];
  1990.         if (target) targets.push(target);
  1991.       }
  1992.       return targets;
  1993.     }
  1994.     if (['DEAD FRIEND', 'DEAD FRIENDS', 'DEAD ALLIES'].contains(string)) {
  1995.       var group = this._action.friendsUnit().deadMembers();
  1996.       for (var i = 0; i < group.length; ++i) {
  1997.         var target = group[i];
  1998.         if (target) targets.push(target);
  1999.       }
  2000.       return targets;
  2001.     }
  2002.     if (['OPPONENT', 'OPPONENTS', 'RIVALS', 'FOES'].contains(string)) {
  2003.       var group = this._action.opponentsUnit().aliveMembers();
  2004.       for (var i = 0; i < group.length; ++i) {
  2005.         var target = group[i];
  2006.         if (target) targets.push(target);
  2007.       }
  2008.       return targets;
  2009.     }
  2010.     if (['ALL OPPONENTS', 'ALL RIVALS', 'ALL FOES'].contains(string)) {
  2011.       var group = this._action.opponentsUnit().members();
  2012.       for (var i = 0; i < group.length; ++i) {
  2013.         var target = group[i];
  2014.         if (target) targets.push(target);
  2015.       }
  2016.       return targets;
  2017.     }
  2018.     if (['DEAD OPPONENT', 'DEAD OPPONENTS', 'DEAD RIVALS',
  2019.     'DEAD FOES'].contains(string)) {
  2020.       var group = this._action.opponentsUnit().deadMembers();
  2021.       for (var i = 0; i < group.length; ++i) {
  2022.         var target = group[i];
  2023.         if (target) targets.push(target);
  2024.       }
  2025.       return targets;
  2026.     }
  2027.     if (['FRIENDS NOT USER', 'ALLIES NOT USER'].contains(string)) {
  2028.       var group = this._action.friendsUnit().aliveMembers();
  2029.       for (var i = 0; i < group.length; ++i) {
  2030.         var target = group[i];
  2031.         if (target && target !== this._subject) targets.push(target);
  2032.       }
  2033.       return targets;
  2034.     }
  2035.     if (string.match(/(?:FRIEND|ALLY)[ ](\d+)/i)) {
  2036.       var target = this._action.friendsUnit().members()[parseInt(RegExp.$1)];
  2037.       if (target) return [target];
  2038.     }
  2039.     if (string.match(/(?:OPPONENT|FOE|RIVAL)[ ](\d+)/i)) {
  2040.       var target = this._action.opponentsUnit().members()[parseInt(RegExp.$1)]
  2041.       if (target) return [target];
  2042.     }
  2043.     if (['ALL ALIVE'].contains(string)) {
  2044.       var group = this._action.friendsUnit().aliveMembers();
  2045.       group = group.concat(this._action.opponentsUnit().aliveMembers());
  2046.       for (var i = 0; i < group.length; ++i) {
  2047.         var target = group[i];
  2048.         if (target) targets.push(target);
  2049.       }
  2050.       return targets;
  2051.     }
  2052.     if (['ALL MEMBERS'].contains(string)) {
  2053.       var group = this._action.friendsUnit().members();
  2054.       group = group.concat(this._action.opponentsUnit().members());
  2055.       for (var i = 0; i < group.length; ++i) {
  2056.         var target = group[i];
  2057.         if (target) targets.push(target);
  2058.       }
  2059.       return targets;
  2060.     }
  2061.     if (['ALL DEAD'].contains(string)) {
  2062.       var group = this._action.friendsUnit().deadMembers();
  2063.       group = group.concat(this._action.opponentsUnit().deadMembers());
  2064.       for (var i = 0; i < group.length; ++i) {
  2065.         var target = group[i];
  2066.         if (target) targets.push(target);
  2067.       }
  2068.       return targets;
  2069.     }
  2070.     if (['ALL NOT USER'].contains(string)) {
  2071.       var group = this._action.friendsUnit().aliveMembers();
  2072.       group = group.concat(this._action.opponentsUnit().aliveMembers());
  2073.       for (var i = 0; i < group.length; ++i) {
  2074.         var target = group[i];
  2075.         if (target && target !== this._subject) targets.push(target);
  2076.       }
  2077.       return targets;
  2078.     }
  2079.     if (['FOCUS', 'PARTICIPANTS'].contains(string)) {
  2080.       var group = this._targets;
  2081.       for (var i = 0; i < group.length; ++i) {
  2082.         var target = group[i];
  2083.         if (target) targets.push(target);
  2084.       }
  2085.       if (!targets.contains(this._subject)) targets.push(this._subject);
  2086.       return targets;
  2087.     }
  2088.     if (['NOT FOCUS', 'NONPARTICIPANTS'].contains(string)) {
  2089.       var group = this._action.friendsUnit().members();
  2090.       group = group.concat(this._action.opponentsUnit().members());
  2091.       for (var i = 0; i < group.length; ++i) {
  2092.         var target = group[i];
  2093.         if (target) {
  2094.           if (target === this._subject) continue;
  2095.           if (this._targets.contains(target)) continue;

  2096.           if (target.isDead()) {
  2097.                   if (Imported.YEP_X_AnimatedSVEnemies && target.isEnemy()) {
  2098.                           if (target.hasSVBattler() && !target.sideviewCollapse()) {
  2099.                                   // Ignore
  2100.                           } else {
  2101.                                   continue;
  2102.                           }
  2103.                   } else {
  2104.                           continue;
  2105.                   }
  2106.           }

  2107.           targets.push(target);
  2108.         }
  2109.       }
  2110.       return targets;
  2111.     }
  2112.     if (string.match(/(?:CHAR|CHARA|CHARACTER)[ ](\d+)/i)) {
  2113.       var actorId = parseInt(RegExp.$1);
  2114.       var actor = $gameActors.actor(actorId);
  2115.       if (actor && $gameParty.battleMembers().contains(actor)) {
  2116.         return [actor];
  2117.       }
  2118.     }
  2119.     if ('FIRST' === string.toUpperCase()) {
  2120.       return [this._targets[0]];
  2121.     }
  2122.     return targets;
  2123. };

  2124. BattleManager.actionConditionsMet = function(actSeq) {
  2125.     var ci = this._conditionFlags.length - 1;
  2126.     var actionName = actSeq[0];
  2127.     var actionArgs = actSeq[1];
  2128.     var subject = this._subject;
  2129.     var user = this._subject;
  2130.     var target = this._targets[0];
  2131.     var targets = this._targets;
  2132.     var action = this._action;
  2133.     var item = this._action.item();
  2134.     if (actionName.match(/ELSE[ ]IF[ ](.*)/i)) {
  2135.       if (this._conditionFlags.length <= 0) return false;
  2136.       if (this._conditionFlags[ci]) {
  2137.         this._conditionFlags[ci] = false;
  2138.         this._trueFlags[ci] = true;
  2139.       } else if (!this._conditionFlags[ci] && !this._trueFlags[ci]) {
  2140.         var text = String(RegExp.$1);
  2141.         this._conditionFlags[ci] = eval('(' + text + ')');
  2142.         this._trueFlags[ci] = eval('(' + text + ')');
  2143.       }
  2144.       return false;
  2145.     } else if (actionName.match(/ELSE[ ]*(.*)/i)) {
  2146.       if (this._conditionFlags.length <= 0) return false;
  2147.       if (this._conditionFlags[ci]) {
  2148.         this._conditionFlags[ci] = false;
  2149.         this._trueFlags[ci] = true;
  2150.       } else if (!this._conditionFlags[ci] && !this._trueFlags[ci]) {
  2151.         this._conditionFlags[ci] = true;
  2152.         this._trueFlags[ci] = true;
  2153.       }
  2154.       return false;
  2155.     } else if (actionName.toUpperCase() === 'END') {
  2156.       if (this._conditionFlags.length <= 0) return false;
  2157.       this._conditionFlags.pop();
  2158.       this._trueFlags.pop();
  2159.       return false;
  2160.     }
  2161.     if (this._conditionFlags.length > 0) return this._conditionFlags[ci];
  2162.     return true
  2163. };

  2164. BattleManager.actionActionAnimation = function(actionArgs) {
  2165.     if (actionArgs && actionArgs[0]) {
  2166.       var targets = this.makeActionTargets(actionArgs[0]);
  2167.     } else {
  2168.       var targets = this._targets;
  2169.     }
  2170.     var mirror = false;
  2171.     if (actionArgs && actionArgs[1]) {
  2172.       if (actionArgs[1].toUpperCase() === 'MIRROR') mirror = true;
  2173.     }
  2174.     var subject = this._subject;
  2175.     var group = targets.filter(Yanfly.Util.onlyUnique);
  2176.     var aniId = this._action.item().animationId;
  2177.     if (aniId < 0) {
  2178.       if (mirror) {
  2179.         this._logWindow.showActorAtkAniMirror(subject, group);
  2180.       } else {
  2181.         this._logWindow.showAttackAnimation(subject, group);
  2182.       }
  2183.     } else {
  2184.       this._logWindow.showNormalAnimation(group, aniId, mirror);
  2185.     }
  2186.     return true;
  2187. };

  2188. BattleManager.actionActionCommonEvent = function() {
  2189.     this._action.item().effects.forEach(function(effect) {
  2190.         if (effect.code === Game_Action.EFFECT_COMMON_EVENT) {
  2191.             $gameTemp.reserveCommonEvent(effect.dataId);
  2192.         }
  2193.     }, this);
  2194.     return false;
  2195. };

  2196. BattleManager.actionActionEffect = function(actionArgs) {
  2197.     if (actionArgs && actionArgs[0]) {
  2198.       var targets = this.makeActionTargets(actionArgs[0]);
  2199.     } else {
  2200.       var targets = this._targets;
  2201.     }
  2202.     targets.forEach(function(target) {
  2203.       if (target !== undefined) {
  2204.         var alreadyDead = target.isDead();
  2205.         this.invokeAction(this._subject, target);
  2206.         if (target.isDead() && !alreadyDead) {
  2207.             target.performCollapse();
  2208.         }
  2209.       }
  2210.     }, this);
  2211.     return true;
  2212. };

  2213. BattleManager.actionAniWait = function(frames) {
  2214.     frames *= Yanfly.Param.AnimationRate || 4;
  2215.     this._logWindow._waitCount = parseInt(frames);
  2216.     return false;
  2217. };

  2218. BattleManager.actionCastAnimation = function() {
  2219.   if (!$gameSystem.isSideView() && this._subject.isActor()) return true;
  2220.   if (!this._action.isAttack() && !this._action.isGuard() &&
  2221.   this._action.isSkill()) {
  2222.     if (this._action.item().castAnimation > 0) {
  2223.       var ani = $dataAnimations[this._action.item().castAnimation]
  2224.       this._logWindow.showAnimation(this._subject, [this._subject],
  2225.         this._action.item().castAnimation);
  2226.     }
  2227.   }
  2228.   return true;
  2229. };


  2230. BattleManager.actionClearBattleLog = function() {
  2231.     this._logWindow.clear();
  2232.     return false;
  2233. };

  2234. BattleManager.actionDeathBreak = function() {
  2235.     if (this._subject.isDead() || this._subject.hp <= 0) {
  2236.       this._targets = [];
  2237.       this._actionList = [];
  2238.       this._individualTargets = [];
  2239.       this._phase = 'phaseChange';
  2240.       return false;
  2241.     }
  2242.     return true;
  2243. };

  2244. BattleManager.actionDisplayAction = function() {
  2245.     this._logWindow.displayAction(this._subject, this._action.item());
  2246.     return false;
  2247. };

  2248. BattleManager.actionIfConditions = function(actionName, actionArgs) {
  2249.   var subject = this._subject;
  2250.   var user = this._subject;
  2251.   var target = this._targets[0];
  2252.   var targets = this._targets;
  2253.   var action = this._action;
  2254.   var item = this._action.item();
  2255.   var actionName = this._actSeq[0];
  2256.   if (actionName.match(/IF[ ](.*)/i)) {
  2257.     var text = String(RegExp.$1);
  2258.     this._conditionFlags.push(eval(text));
  2259.     this._trueFlags.push(false);
  2260.     var ci = this._conditionFlags.length;
  2261.   }
  2262.   return true;
  2263. };

  2264. BattleManager.actionImmortal = function(actionArgs) {
  2265.     var targets =
  2266.       this.makeActionTargets(actionArgs[0]).filter(Yanfly.Util.onlyUnique);
  2267.     var value = eval(String(actionArgs[1]).toLowerCase());
  2268.     targets.forEach(function (target) {
  2269.       if (value) {
  2270.         target.addImmortal();
  2271.       } else {
  2272.         var alreadyDead = target.isDead();
  2273.         target.removeImmortal();
  2274.       }
  2275.     }, this);
  2276.     return true;
  2277. };

  2278. BattleManager.actionMotionWait = function(actionArgs) {
  2279.     var targets = this.makeActionTargets(actionArgs[0]);
  2280.     if (targets[0].isActor() && targets[0].isSpriteVisible()) {
  2281.       this._logWindow._waitCount += 12;
  2282.       return false;
  2283.     }
  2284.     return true;
  2285. };

  2286. BattleManager.actionPerformAction = function() {
  2287.     this._logWindow.performAction(this._subject, this._action);
  2288.     if (this._subject.isActor() && this._subject.isSpriteVisible) {
  2289.       this._logWindow._waitCount += 20;
  2290.       return false;
  2291.     }
  2292.     return true;
  2293. };

  2294. BattleManager.actionPerformFinish = function() {
  2295.     this._logWindow.performActionEnd(this._subject);
  2296.     $gameParty.aliveMembers().forEach(function(member) {
  2297.       member.spriteReturnHome();
  2298.     });
  2299.     $gameTroop.aliveMembers().forEach(function(member) {
  2300.       member.spriteReturnHome();
  2301.     });
  2302.     return true;
  2303. };

  2304. BattleManager.actionPerformStart = function() {
  2305.     this._logWindow.performActionStart(this._subject, this._action);
  2306.     return true;
  2307. };

  2308. BattleManager.actionWait = function(frames) {
  2309.     this._logWindow._waitCount = parseInt(frames);
  2310.     return false;
  2311. };

  2312. BattleManager.actionWaitForAnimation = function() {
  2313.     this._logWindow.waitForAnimation();
  2314.     return false;
  2315. };

  2316. BattleManager.actionWaitForEffect = function() {
  2317.     this._logWindow.waitForEffect();
  2318.     return false;
  2319. };

  2320. BattleManager.actionWaitForMovement = function() {
  2321.     this._logWindow.waitForMovement();
  2322.     return false;
  2323. };

  2324. BattleManager.actionWaitForNewLine = function() {
  2325.     this._logWindow.waitForNewLine();
  2326.     return false;
  2327. };

  2328. BattleManager.actionWaitForPopups = function() {
  2329.     this._logWindow.waitForPopups();
  2330.     return false;
  2331. };

  2332. //=============================================================================
  2333. // Sprite_Battler
  2334. //=============================================================================

  2335. Yanfly.BEC.Sprite_Battler_initialize = Sprite_Battler.prototype.initialize;
  2336. Sprite_Battler.prototype.initialize = function(battler) {
  2337.     this.preSpriteInitialize(battler);
  2338.     Yanfly.BEC.Sprite_Battler_initialize.call(this, battler);
  2339. };

  2340. Sprite_Battler.prototype.preSpriteInitialize = function(battler) {
  2341. };

  2342. Yanfly.BEC.Sprite_Battler_update = Sprite_Battler.prototype.update;
  2343. Sprite_Battler.prototype.update = function() {
  2344.     Yanfly.BEC.Sprite_Battler_update.call(this);
  2345.     if (this._postSpriteInitialized) return;
  2346.     this.postSpriteInitialize();
  2347. };

  2348. Sprite_Battler.prototype.postSpriteInitialize = function() {
  2349.     this._postSpriteInitialized = true;
  2350. };

  2351. Yanfly.BEC.Sprite_Battler_initMembers = Sprite_Battler.prototype.initMembers;
  2352. Sprite_Battler.prototype.initMembers = function() {
  2353.     Yanfly.BEC.Sprite_Battler_initMembers.call(this);
  2354.     this.adjustAnchor();
  2355.     this.setZ();
  2356. };

  2357. Sprite_Battler.prototype.adjustAnchor = function() {
  2358.     this.anchor.x = 0.5;
  2359.     this.anchor.y = 1.0;
  2360. };

  2361. Sprite_Battler.prototype.setZ = function() {
  2362.     this.z = 1;
  2363. };

  2364. Sprite_Battler.prototype.setupDamagePopup = function() {
  2365.     if (this._battler.isDamagePopupRequested()) {
  2366.       if (this._battler.isSpriteVisible()) {
  2367.         var sprite = new Sprite_Damage();
  2368.         sprite.x = this.x + this.damageOffsetX();
  2369.         sprite.y = this.y + this.damageOffsetY();
  2370.         sprite.setup(this._battler);
  2371.         this.pushDamageSprite(sprite);
  2372.         BattleManager._spriteset.addChild(sprite);
  2373.         this._battler.clearResult();
  2374.       }
  2375.     } else {
  2376.       this._battler.clearDamagePopup();
  2377.     }
  2378. };

  2379. Sprite_Battler.prototype.pushDamageSprite = function(sprite) {
  2380.     var heightBuffer = eval(Yanfly.Param.BECPopupOverlap);
  2381.     if (eval(Yanfly.Param.BECNewPopBottom)) {
  2382.       this._damages.push(sprite);
  2383.       this._damages.forEach(function(spr) {
  2384.         for (var i = 0; i < spr.children.length; i++) {
  2385.           childSprite = spr.children[i];
  2386.           childSprite.anchor.y += heightBuffer;
  2387.         }
  2388.       }, this);
  2389.     } else {
  2390.       this._damages.push(sprite);
  2391.       heightBuffer *= this._damages.length
  2392.       for (var i = 0; i < sprite.children.length; i++) {
  2393.         childSprite = sprite.children[i];
  2394.         childSprite.anchor.y += heightBuffer;
  2395.       }
  2396.     }
  2397. };

  2398. Yanfly.BEC.Sprite_Battler_setBattler = Sprite_Battler.prototype.setBattler;
  2399. Sprite_Battler.prototype.setBattler = function(battler) {
  2400.     Yanfly.BEC.Sprite_Battler_setBattler.call(this, battler);
  2401.     if (battler) battler.setBattler(this);
  2402. };

  2403. Yanfly.BEC.Sprite_Battler_startMove = Sprite_Battler.prototype.startMove;
  2404. Sprite_Battler.prototype.startMove = function(x, y, duration) {
  2405.     if (this._battler && !this._battler.spriteCanMove()) return;
  2406.     Yanfly.BEC.Sprite_Battler_startMove.call(this, x, y, duration);
  2407. };

  2408. Sprite_Battler.prototype.stepForward = function() {
  2409.     this.startMove(Yanfly.Param.BECStepDist, 0, 12);
  2410. };

  2411. Sprite_Battler.prototype.stepBack = function() {
  2412.     this.startMove(0, 0, 12);
  2413. };

  2414. Sprite_Battler.prototype.stepFlinch = function() {
  2415.     var flinchX = this.x - this._homeX - Yanfly.Param.BECFlinchDist;
  2416.     var flinchY = this.y - this._homeY;
  2417.     this.startMove(flinchX, flinchY, 6);
  2418. };

  2419. Sprite_Battler.prototype.stepSubBack = function() {
  2420.     var backX = -1 * this.width / 2;
  2421.     this.startMove(backX, 0, 6);
  2422. };

  2423. Sprite_Battler.prototype.stepToSubstitute = function(focus) {
  2424.     var target = focus.battler();
  2425.     var targetX = (this.x - this._homeX) + (target._homeX - this._homeX);
  2426.     var targetY = (this.y - this._homeY) + (target._homeY - this._homeY);;
  2427.     if (focus.isActor()) targetX -= this._mainSprite.width / 2;
  2428.     if (focus.isEnemy()) targetX += this.width / 2;
  2429.     this.startMove(targetX, targetY, 1);
  2430. };

  2431. Sprite_Battler.prototype.startMotion = function(motionType) {
  2432. };

  2433. Sprite_Battler.prototype.forceMotion = function(motionType) {
  2434. };

  2435. Sprite_Battler.prototype.refreshMotion = function() {
  2436. };

  2437. Sprite_Battler.prototype.startActionMotion = function() {
  2438. };

  2439. Sprite_Battler.prototype.moveForward = function(distance, frames) {
  2440.     distance = parseInt(distance);
  2441.     frames = parseInt(frames);
  2442.     if (this._battler.isActor()) distance *= -1;
  2443.     var moveX = this.x - this._homeX + distance;
  2444.     var moveY = this.y - this._homeY;
  2445.     this.startMove(moveX, moveY, frames);
  2446. };

  2447. Sprite_Battler.prototype.moveToPoint = function(pointX, pointY, frames) {
  2448.     pointX = parseInt(pointX);
  2449.     pointY = parseInt(pointY);
  2450.     var targetX = pointX - this._homeX;
  2451.     var targetY = pointY - this._homeY;
  2452.     this.startMove(targetX, targetY, frames);
  2453. };

  2454. Sprite_Battler.prototype.setMirror = function(value) {
  2455.     if (this.scale.x > 0 && value) this.scale.x *= -1;
  2456.     if (this.scale.x < 0 && !value) this.scale.x *= -1;
  2457. };

  2458. Sprite_Battler.prototype.isPopupPlaying = function() {
  2459.     if (this._damages.length > 0) {
  2460.       for (var i = 0; i < this._damages.length; ++i) {
  2461.         return this._damages[i].isPlaying();
  2462.       }
  2463.     }
  2464.     return false;
  2465. };

  2466. //=============================================================================
  2467. // Sprite_Actor
  2468. //=============================================================================

  2469. Sprite_Actor.prototype.preSpriteInitialize = function(battler) {
  2470.     Sprite_Battler.prototype.preSpriteInitialize.call(this, battler);
  2471. };

  2472. Sprite_Actor.prototype.postSpriteInitialize = function() {
  2473.     Sprite_Battler.prototype.postSpriteInitialize.call(this);
  2474. };

  2475. Yanfly.BEC.Sprite_Actor_updateShadow = Sprite_Actor.prototype.updateShadow;
  2476. Sprite_Actor.prototype.updateShadow = function() {
  2477.     if (this._hideShadows === undefined) {
  2478.       this._hideShadows = eval(Yanfly.Param.BECShowShadows);
  2479.     }
  2480.     if (!this._hideShadows) return this._shadowSprite.visible = false;
  2481.     Yanfly.BEC.Sprite_Actor_updateShadow.call(this);
  2482. };

  2483. Sprite_Actor.prototype.setActorHome = function(index) {
  2484.     var screenWidth = Graphics.boxWidth;
  2485.     var screenHeight = Graphics.boxHeight;
  2486.     var maxSize = $gameParty.maxBattleMembers();
  2487.     var partySize = $gameParty.battleMembers().length;
  2488.     var statusHeight = eval(Yanfly.Param.BECCommandRows);
  2489.     statusHeight *= Window_Base.prototype.lineHeight.call(this);
  2490.     statusHeight += Window_Base.prototype.standardPadding.call(this) * 2;
  2491.     if ($gameSystem.isSideView()) {
  2492.       var homeX = eval(Yanfly.Param.BECHomePosX);
  2493.       var homeY = eval(Yanfly.Param.BECHomePosY);
  2494.     } else {
  2495.       var homeX = eval(Yanfly.Param.BECFrontPosX);
  2496.       var homeY = eval(Yanfly.Param.BECFrontPosY);
  2497.     }
  2498.     this._checkAliveStatus = false;
  2499.     if ($gameParty.battleMembers()[index]) {
  2500.       var actor = $gameParty.battleMembers()[index];
  2501.       if (actor.isAlive()) this._checkAliveStatus = true;
  2502.     }
  2503.     this.setHome(homeX, homeY);
  2504.     this.moveToStartPosition();
  2505. };

  2506. Sprite_Actor.prototype.moveToStartPosition = function() {
  2507.     if (BattleManager._bypassMoveToStartLocation) return;
  2508.     if ($gameSystem.isSideView() && this._checkAliveStatus) {
  2509.       this.startMove(300, 0, 0);
  2510.     }
  2511. };

  2512. Sprite_Actor.prototype.setupMotion = function() {
  2513. };

  2514. Sprite_Actor.prototype.forceMotion = function(motionType) {
  2515.     var newMotion = Sprite_Actor.MOTIONS[motionType];
  2516.     this._motion = newMotion;
  2517.     this._motionCount = 0;
  2518.     this._pattern = 0;
  2519. };

  2520. Sprite_Actor.prototype.updateTargetPosition = function() {
  2521. };

  2522. Sprite_Actor.prototype.updateMotion = function() {
  2523.     this.updateMotionCount();
  2524. };

  2525. Sprite_Actor.prototype.onMoveEnd = function() {
  2526.     Sprite_Battler.prototype.onMoveEnd.call(this);
  2527. };

  2528. Sprite_Actor.prototype.stepForward = function() {
  2529.     this.startMove(-Yanfly.Param.BECStepDist, 0, 12);
  2530. };

  2531. Sprite_Actor.prototype.stepFlinch = function() {
  2532.     var flinchX = this.x - this._homeX + Yanfly.Param.BECFlinchDist;
  2533.     var flinchY = this.y - this._homeY;
  2534.     this.startMove(flinchX, flinchY, 6);
  2535. };

  2536. Sprite_Actor.prototype.stepSubBack = function() {
  2537.     var backX = this._mainSprite.width / 2;
  2538.     this.startMove(backX, 0, 6);
  2539. };

  2540. Yanfly.BEC.Sprite_Actor_updateBitmap = Sprite_Actor.prototype.updateBitmap;
  2541. Sprite_Actor.prototype.updateBitmap = function() {
  2542.     var name = this._actor.battlerName();
  2543.     var needUpdate = false;
  2544.     if (this._battlerName !== name) needUpdate = true;
  2545.     Yanfly.BEC.Sprite_Actor_updateBitmap.call(this);
  2546.     if (needUpdate) this.adjustAnchor();
  2547. };

  2548. Sprite_Actor.prototype.adjustAnchor = function() {
  2549.     if (!this._mainSprite) return;
  2550.     this._mainSprite.anchor.x = this._actor.anchorX();
  2551.     this._mainSprite.anchor.y = this._actor.anchorY();
  2552. };

  2553. Yanfly.BEC.Sprite_Actor_updateFrame = Sprite_Actor.prototype.updateFrame;
  2554. Sprite_Actor.prototype.updateFrame = function() {
  2555.     Yanfly.BEC.Sprite_Actor_updateFrame.call(this);
  2556.     if (!this._mainSprite) return;
  2557.     if (!this._mainSprite.bitmap) return;
  2558.     if (this._mainSprite.bitmap.width > 0 && !this.bitmap) {
  2559.       var sw = this._mainSprite.bitmap.width / 9;
  2560.       var sh = this._mainSprite.bitmap.height / 6;
  2561.       this.bitmap = new Bitmap(sw, sh);
  2562.     }
  2563. };

  2564. Yanfly.BEC.Sprite_Actor_refreshMotion = Sprite_Actor.prototype.refreshMotion;
  2565. Sprite_Actor.prototype.refreshMotion = function() {
  2566.     var actor = this._actor;
  2567.     if (!actor) return;
  2568.     var motionGuard = Sprite_Actor.MOTIONS['guard'];
  2569.     if (this._motion === motionGuard && !BattleManager.isInputting()) return;
  2570.     var stateMotion = actor.stateMotionIndex();
  2571.     if (actor.isInputting() || actor.isActing()) {
  2572.       this.startMotion(actor.idleMotion());
  2573.     } else if (stateMotion === 3) {
  2574.       this.startMotion(actor.deadMotion());
  2575.     } else if (stateMotion === 2) {
  2576.       this.startMotion(actor.sleepMotion());
  2577.     } else if (actor.isChanting()) {
  2578.       this.startMotion(actor.chantMotion());
  2579.     } else if (actor.isGuard() || actor.isGuardWaiting()) {
  2580.       this.startMotion(actor.guardMotion());
  2581.     } else if (stateMotion === 1) {
  2582.       this.startMotion(actor.abnormalMotion());
  2583.     } else if (actor.isDying()) {
  2584.       this.startMotion(actor.dyingMotion());
  2585.     } else if (actor.isUndecided()) {
  2586.       this.startMotion(actor.idleMotion());
  2587.     } else {
  2588.       this.startMotion(actor.waitMotion());
  2589.     }
  2590. };

  2591. //=============================================================================
  2592. // Sprite_Enemy
  2593. //=============================================================================

  2594. Sprite_Enemy.prototype.preSpriteInitialize = function(battler) {
  2595.     Sprite_Battler.prototype.preSpriteInitialize.call(this, battler);
  2596.     this._visualSelect = eval(Yanfly.Param.BECEnemySelect);
  2597.     if (this._visualSelect) this.createVisualSelectWindow();
  2598. };

  2599. Yanfly.BEC.Sprite_Enemy_update = Sprite_Enemy.prototype.update;
  2600. Sprite_Enemy.prototype.update = function() {
  2601.     Yanfly.BEC.Sprite_Enemy_update.call(this);
  2602.     this.addVisualSelectWindow();
  2603. };

  2604. Sprite_Enemy.prototype.addVisualSelectWindow = function() {
  2605.     if (!this._visualSelect) return;
  2606.     if (this._addedVisualSelect) return;
  2607.     if (!SceneManager._scene) return;
  2608.     var scene = SceneManager._scene;
  2609.     if (!scene._windowLayer) return;
  2610.     this._addedVisualSelect = true;
  2611.     scene.addChild(this._visualSelectWindow);
  2612. };

  2613. Sprite_Enemy.prototype.createVisualSelectWindow = function() {
  2614.     this._visualSelectWindow = new Window_EnemyVisualSelect();
  2615. };

  2616. Yanfly.BEC.Sprite_Enemy_setBattler = Sprite_Enemy.prototype.setBattler;
  2617. Sprite_Enemy.prototype.setBattler = function(battler) {
  2618.     Yanfly.BEC.Sprite_Enemy_setBattler.call(this, battler);
  2619.     if (this._visualSelectWindow) this._visualSelectWindow.setBattler(battler);
  2620. };

  2621. //=============================================================================
  2622. // Sprite_Weapon
  2623. //=============================================================================

  2624. Yanfly.BEC.Sprite_Weapon_setup = Sprite_Weapon.prototype.setup;
  2625. Sprite_Weapon.prototype.setup = function(weaponImageId) {
  2626.     Yanfly.BEC.Sprite_Weapon_setup.call(this, weaponImageId);
  2627.     this._animationCount -= 1; // Synch with sprite
  2628. };

  2629. //=============================================================================
  2630. // Sprite_Damage
  2631. //=============================================================================

  2632. Yanfly.BEC.Sprite_Damage_initialize = Sprite_Damage.prototype.initialize;
  2633. Sprite_Damage.prototype.initialize = function() {
  2634.     Yanfly.BEC.Sprite_Damage_initialize.call(this);
  2635.     this._duration = eval(Yanfly.Param.BECPopupDur);
  2636. };

  2637. Sprite_Damage.prototype.setup = function(target) {
  2638.     var result = target.shiftDamagePopup();
  2639.     if (result.missed || result.evaded) {
  2640.       this.createMiss();
  2641.     } else if (result.hpAffected) {
  2642.       this.createDigits(0, result.hpDamage);
  2643.     } else if (target.isAlive() && result.mpDamage !== 0) {
  2644.       this.createDigits(2, result.mpDamage);
  2645.     }
  2646.     if (result.critical) {
  2647.       this.setupCriticalEffect();
  2648.     }
  2649. };

  2650. Sprite_Damage.prototype.setupCriticalEffect = function() {
  2651.     this._flashColor = eval('[' + Yanfly.Param.BECCritPopup + ']');
  2652.     this._flashDuration = eval(Yanfly.Param.BECCritDur);
  2653. };

  2654. //=============================================================================
  2655. // Sprite_StateIcon
  2656. //=============================================================================

  2657. Yanfly.BEC.Sprite_StateIcon_update = Sprite_StateIcon.prototype.update;
  2658. Sprite_StateIcon.prototype.update = function() {
  2659.     Yanfly.BEC.Sprite_StateIcon_update.call(this);
  2660.     this.updateMirror();
  2661. };

  2662. Sprite_StateIcon.prototype.updateMirror = function() {
  2663.     if (this.parent.scale.x < 0) this.scale.x = -1 * Math.abs(this.scale.x);
  2664.     if (this.parent.scale.x > 0) this.scale.x = Math.abs(this.scale.x);
  2665. };

  2666. //=============================================================================
  2667. // Sprite_StateOverlay
  2668. //=============================================================================

  2669. Yanfly.BEC.Sprite_StateOverlay_update = Sprite_StateOverlay.prototype.update;
  2670. Sprite_StateOverlay.prototype.update = function() {
  2671.     Yanfly.BEC.Sprite_StateOverlay_update.call(this);
  2672.     this.updateMirror();
  2673. };

  2674. Sprite_StateOverlay.prototype.updateMirror = function() {
  2675.     if (this.parent.scale.x < 0) this.scale.x = -1 * Math.abs(this.scale.x);
  2676.     if (this.parent.scale.x > 0) this.scale.x = Math.abs(this.scale.x);
  2677. };

  2678. //=============================================================================
  2679. // Spriteset_Battle
  2680. //=============================================================================

  2681. Spriteset_Battle.prototype.isBusy = function() {
  2682.     return false;
  2683. };

  2684. Yanfly.BEC.Spriteset_Battle_update = Spriteset_Battle.prototype.update;
  2685. Spriteset_Battle.prototype.update = function() {
  2686.     Yanfly.BEC.Spriteset_Battle_update.call(this);
  2687.     this.updateZCoordinates();
  2688. };

  2689. Spriteset_Battle.prototype.updateZCoordinates = function() {
  2690.     this._battleField.children.sort(this.battleFieldDepthCompare);
  2691. };

  2692. Spriteset_Battle.prototype.battleFieldDepthCompare = function(a, b) {
  2693.     if (a.tilePosition && !b.tilePosition) return -1;
  2694.     if (b.tilePosition && !a.tilePosition) return 1;
  2695.     var priority = BattleManager.getSpritePriority();
  2696.     if (a._battler && b._battler && priority !== 0) {
  2697.       if (priority === 1) {
  2698.         if (a._battler.isActor() && b._battler.isEnemy()) return 1;
  2699.         if (a._battler.isEnemy() && b._battler.isActor()) return -1;
  2700.       } else if (priority === 2) {
  2701.         if (a._battler.isActor() && b._battler.isEnemy()) return -1;
  2702.         if (a._battler.isEnemy() && b._battler.isActor()) return 1;
  2703.       }
  2704.     }
  2705.     if (a.z < b.z) return -1;
  2706.     if (a.z > b.z) return 1;
  2707.     if (a.y < b.y) return -1;
  2708.     if (a.y > b.y) return 1;
  2709.     return 0;
  2710. };

  2711. Spriteset_Battle.prototype.isPopupPlaying = function() {
  2712.     return this.battlerSprites().some(function(sprite) {
  2713.         return sprite.isPopupPlaying();
  2714.     });
  2715. };

  2716. //=============================================================================
  2717. // Game_Temp
  2718. //=============================================================================

  2719. Game_Temp.prototype.clearActionSequenceSettings = function() {
  2720. };

  2721. //=============================================================================
  2722. // Game_System
  2723. //=============================================================================

  2724. Yanfly.BEC.Game_System_initialize = Game_System.prototype.initialize;
  2725. Game_System.prototype.initialize = function() {
  2726.     Yanfly.BEC.Game_System_initialize.call(this);
  2727.     this.initBattleSystem();
  2728. };

  2729. Game_System.prototype.initBattleSystem = function() {
  2730.     this._battleSystem = Yanfly.Param.BECSystem.toLowerCase();
  2731. };

  2732. Game_System.prototype.getBattleSystem = function() {
  2733.     if (this._battleSystem === undefined) this.initBattleSystem();
  2734.     return this._battleSystem;
  2735. };

  2736. Game_System.prototype.setBattleSystem = function(type) {
  2737.     this._battleSystem = type.toLowerCase();
  2738. };

  2739. //=============================================================================
  2740. // Game_Interpreter
  2741. //=============================================================================

  2742. Yanfly.BEC.Game_Interpreter_pluginCommand =
  2743.     Game_Interpreter.prototype.pluginCommand;
  2744. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  2745.     Yanfly.BEC.Game_Interpreter_pluginCommand.call(this, command, args);
  2746.     if (command === 'setBattleSys' && !$gameParty.inBattle()) {
  2747.       this.setBattleSystem(args[0]);
  2748.     }
  2749. };

  2750. Game_Interpreter.prototype.setBattleSystem = function(value) {
  2751.     $gameSystem.setBattleSystem(value);
  2752. };

  2753. //=============================================================================
  2754. // Game_Action
  2755. //=============================================================================

  2756. Game_Action.prototype.speed = function() {
  2757.     var user = this.subject(); var a = user;
  2758.     var maxhp = user.mhp; var mhp = user.mhp; var hp = user.hp;
  2759.     var maxmp = user.mmp; var mmp = user.mmp; var mp = user.mp;
  2760.     var maxtp = user.maxTp(); var mtp = user.maxTp(); var tp = user.tp;
  2761.     var atk = user.atk; var def = user.def; var mat = user.mat;
  2762.     var int = user.mat; var mdf = user.mdf; var res = user.res;
  2763.     var agi = user.agi; var luk = user.luk;
  2764.     var speed = eval(Yanfly.Param.BECActionSpeed);
  2765.     if (this.item()) speed += this.item().speed;
  2766.     if (this.isAttack()) speed += this.subject().attackSpeed();
  2767.     return speed;
  2768. };

  2769. Yanfly.BEC.Game_Action_apply = Game_Action.prototype.apply;
  2770. Game_Action.prototype.apply = function(target) {
  2771.     target._result = null;
  2772.     target._result = new Game_ActionResult();
  2773.     this.subject()._result = null;
  2774.     this.subject()._result = new Game_ActionResult();
  2775.     Yanfly.BEC.Game_Action_apply.call(this, target);
  2776.     if ($gameParty.inBattle()) {
  2777.       target.startDamagePopup();
  2778.       target.performResultEffects();
  2779.       if (target !== this.subject()) this.subject().startDamagePopup();
  2780.     }
  2781. };

  2782. Game_Action.prototype.itemEffectAddAttackState = function(target, effect) {
  2783.     this.subject().attackStates().forEach(function(stateId) {
  2784.         var chance = effect.value1;
  2785.         chance *= target.stateRate(stateId);
  2786.         chance *= this.subject().attackStatesRate(stateId);
  2787.         chance *= this.lukEffectRate(target);
  2788.         if (Math.random() < chance) {
  2789.             if (stateId === target.deathStateId()) {
  2790.               if (target.isImmortal()) target.removeImmortal();
  2791.             }
  2792.             target.addState(stateId);
  2793.             this.makeSuccess(target);
  2794.         }
  2795.     }.bind(this), target);
  2796. };

  2797. Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
  2798.     var stateId = effect.dataId;
  2799.     var chance = effect.value1;
  2800.     if (!this.isCertainHit()) {
  2801.       chance *= target.stateRate(stateId);
  2802.       chance *= this.lukEffectRate(target);
  2803.     }
  2804.     if (Math.random() < chance) {
  2805.       if (stateId === target.deathStateId()) {
  2806.         if (target.isImmortal()) target.removeImmortal();
  2807.       }
  2808.       target.addState(stateId);
  2809.       this.makeSuccess(target);
  2810.     }
  2811. };

  2812. Yanfly.BEC.Game_Action_applyGlobal = Game_Action.prototype.applyGlobal;
  2813. Game_Action.prototype.applyGlobal = function() {
  2814.     if ($gameParty.inBattle()) return;
  2815.     Yanfly.BEC.Game_Action_applyGlobal.call(this);
  2816. };

  2817. Yanfly.BEC.Game_Action_needsSelection = Game_Action.prototype.needsSelection;
  2818. Game_Action.prototype.needsSelection = function() {
  2819.     if ($gameParty.inBattle() && this.item().scope === 0) return false;
  2820.     if ($gameParty.inBattle() && BattleManager.isForceSelection()) return true;
  2821.     return Yanfly.BEC.Game_Action_needsSelection.call(this);
  2822. };

  2823. //=============================================================================
  2824. // Game_BattlerBase
  2825. //=============================================================================

  2826. Yanfly.BEC.Game_BattlerBase_recoverAll = Game_BattlerBase.prototype.recoverAll;
  2827. Game_BattlerBase.prototype.recoverAll = function() {
  2828.     Yanfly.BEC.Game_BattlerBase_recoverAll.call(this);
  2829.     this.refresh();
  2830.     if ($gameParty.inBattle()) this.forceMotionRefresh();
  2831. };

  2832. Game_BattlerBase.prototype.requestStatusRefresh = function() {
  2833.     this._statusRefreshRequested = true;
  2834. };

  2835. Game_BattlerBase.prototype.isStatusRefreshRequested = function() {
  2836.     return this._statusRefreshRequested;
  2837. };

  2838. Game_BattlerBase.prototype.completetStatusRefreshRequest = function() {
  2839.     this._statusRefreshRequested = false;
  2840. };

  2841. Game_BattlerBase.prototype.updateStateTicks = function() {
  2842.     var needRefresh = false;
  2843.     for (var i = 0; i < this._states.length; ++i) {
  2844.       var stateId = this._states[i];
  2845.       var state = $dataStates[stateId];
  2846.       if (!state) continue;
  2847.       if (state.autoRemovalTiming !== 2) continue;
  2848.       if (!this._stateTurns[stateId]) continue;
  2849.       var value = BattleManager.tickRate() / Yanfly.Param.BECTurnTime;
  2850.       var shown1 = Math.ceil(this._stateTurns[stateId]);
  2851.       this._stateTurns[stateId] -= value;
  2852.       var shown2 = Math.ceil(this._stateTurns[stateId]);
  2853.       if (shown1 !== shown2) needRefresh = true;
  2854.       if (this._stateTurns[stateId] <= 0) this.removeState(stateId);
  2855.     }
  2856.     if (needRefresh) this.refresh();
  2857. };

  2858. Game_BattlerBase.prototype.isBypassUpdateTurns = function() {
  2859.     if ($gameTroop.isEventRunning()) return true;
  2860.     return false;
  2861. };

  2862. Game_BattlerBase.prototype.updateStateTurns = function() {
  2863.     this.updateStateTurnEnd();
  2864. };

  2865. Game_BattlerBase.prototype.updateStateTurnTiming = function(timing) {
  2866.     if (this.isBypassUpdateTurns()) return;
  2867.     var statesRemoved = [];
  2868.     this._freeStateTurn = this._freeStateTurn || [];
  2869.     for (var i = 0; i < this._states.length; ++i) {
  2870.       var stateId = this._states[i];
  2871.       var state = $dataStates[stateId];
  2872.       if (!state) continue;
  2873.       if (state.autoRemovalTiming !== timing) continue;
  2874.       if (!this._stateTurns[stateId]) continue;
  2875.       if (this._freeStateTurn.contains(stateId)) {
  2876.         var index = this._freeStateTurn.indexOf(stateId);
  2877.         this._freeStateTurn.splice(index, 1);
  2878.       } else {
  2879.         this._stateTurns[stateId] -= 1;
  2880.       }
  2881.       if (this._stateTurns[stateId] <= 0) statesRemoved.push(stateId);
  2882.     }
  2883.     for (var i = 0; i < statesRemoved.length; ++i) {
  2884.       var stateId = statesRemoved[i];
  2885.       this.removeState(stateId);
  2886.     }
  2887. };

  2888. Game_BattlerBase.prototype.updateStateActionStart = function() {
  2889.     this.updateStateTurnTiming(3);
  2890. };

  2891. Game_BattlerBase.prototype.updateStateActionEnd = function() {
  2892.     this.updateStateTurnTiming(1);
  2893. };

  2894. Game_BattlerBase.prototype.updateStateTurnStart = function() {
  2895.     this.updateStateTurnTiming(4);
  2896. };

  2897. Game_BattlerBase.prototype.updateStateTurnEnd = function() {
  2898.     this.updateStateTurnTiming(2);
  2899. };

  2900. Game_BattlerBase.prototype.updateBuffTicks = function() {
  2901.     var needRefresh = false;
  2902.     for (var i = 0; i < this._buffTurns.length; i++) {
  2903.       if (this._buffTurns[i] <= 0) continue;
  2904.       var value = BattleManager.tickRate() / Yanfly.Param.BECTurnTime;
  2905.       var shown1 = Math.ceil(this._buffTurns[i]);
  2906.       this._buffTurns[i] -= value;
  2907.       var shown2 = Math.ceil(this._buffTurns[i]);
  2908.       if (shown1 !== shown2) needRefresh = true;
  2909.       if (this._buffTurns[i] <= 0) this.removeBuff(i);
  2910.     }
  2911.     if (needRefresh) this.refresh();
  2912. };

  2913. Game_BattlerBase.prototype.timedTick = function() {
  2914.     return 1 * BattleManager.tickRate();
  2915. };

  2916. Yanfly.BEC.Game_BattlerBase_isStateResist =
  2917.     Game_BattlerBase.prototype.isStateResist;
  2918. Game_BattlerBase.prototype.isStateResist = function(stateId) {
  2919.     if (stateId === this.deathStateId() && this.isImmortal()) return true;
  2920.     return Yanfly.BEC.Game_BattlerBase_isStateResist.call(this, stateId);
  2921. };

  2922. Game_BattlerBase.prototype.isImmortal = function() {
  2923.     return this._immortalState;
  2924. };

  2925. Yanfly.BEC.Game_BattlerBase_paySkillCost =
  2926.     Game_BattlerBase.prototype.paySkillCost;
  2927. Game_BattlerBase.prototype.paySkillCost = function(skill) {
  2928.     this.requestStatusRefresh();
  2929.     Yanfly.BEC.Game_BattlerBase_paySkillCost.call(this, skill);
  2930. };

  2931. //=============================================================================
  2932. // Game_Battler
  2933. //=============================================================================

  2934. Yanfly.BEC.Game_Battler_useItem = Game_Battler.prototype.useItem;
  2935. Game_Battler.prototype.useItem = function(item) {
  2936.     Yanfly.BEC.Game_Battler_useItem.call(this, item);
  2937.     if (!$gameParty.inBattle()) return;
  2938.     this.increaseSelfTurnCount();
  2939.     this.updateStateActionStart();
  2940. };

  2941. Yanfly.BEC.Game_Battler_onBattleStart = Game_Battler.prototype.onBattleStart;
  2942. Game_Battler.prototype.onBattleStart = function() {
  2943.     Yanfly.BEC.Game_Battler_onBattleStart.call(this);
  2944.     this._freeStateTurn = [];
  2945.     this._immortalState = false;
  2946.     this._selfTurnCount = 0;
  2947. };

  2948. Yanfly.BEC.Game_Battler_onBattleEnd = Game_Battler.prototype.onBattleEnd;
  2949. Game_Battler.prototype.onBattleEnd = function() {
  2950.     Yanfly.BEC.Game_Battler_onBattleEnd.call(this);
  2951.     this._freeStateTurn = [];
  2952.     this._immortalState = false;
  2953. };

  2954. Yanfly.BEC.Game_Battler_isSelected = Game_Battler.prototype.isSelected;
  2955. Game_Battler.prototype.isSelected = function() {
  2956.     if ($gameParty.inBattle() && BattleManager.isAllSelection()) {
  2957.       if (!this.isAppeared()) return false;
  2958.       var action = BattleManager.inputtingAction();
  2959.       if (action && action.item()) {
  2960.         if (this.isDead() && this.isEnemy()) return false;
  2961.         if (this.isDead() && this.isActor()) return action.isForDeadFriend();
  2962.         if (action.isForFriend() && this.isActor()) return true;
  2963.         if (action.isForOpponent() && this.isEnemy()) return true;
  2964.       }
  2965.     }
  2966.     return Yanfly.BEC.Game_Battler_isSelected.call(this);
  2967. };

  2968. Yanfly.BEC.Game_Battler_regenerateAll = Game_Battler.prototype.regenerateAll;
  2969. Game_Battler.prototype.regenerateAll = function() {
  2970.     var lifeState = this.isAlive();
  2971.     Yanfly.BEC.Game_Battler_regenerateAll.call(this);
  2972.     if (!BattleManager.timeBasedStates()) this.updateStateTurns();
  2973.     if (!BattleManager.timeBasedBuffs()) {
  2974.       this.updateBuffTurns();
  2975.       this.removeBuffsAuto();
  2976.     }
  2977.     if (this.isDead() && lifeState === true) {
  2978.       this.performCollapse();
  2979.     }
  2980.     if ($gameParty.inBattle()) this.startDamagePopup();
  2981. };

  2982. Game_Battler.prototype.addImmortal = function() {
  2983.     this._immortalState = true;
  2984. };

  2985. Game_Battler.prototype.removeImmortal = function() {
  2986.     var alreadyDead = this.isDead();
  2987.     this._immortalState = false;
  2988.     this.refresh();
  2989.     if (this.isDead() && !alreadyDead) this.performCollapse();
  2990. };

  2991. Yanfly.BEC.Game_Battler_removeState = Game_Battler.prototype.removeState;
  2992. Game_Battler.prototype.removeState = function(stateId) {
  2993.     Yanfly.BEC.Game_Battler_removeState.call(this, stateId);
  2994. };

  2995. Game_Battler.prototype.clearDamagePopup = function() {
  2996.     this._damagePopup = [];
  2997. };

  2998. Game_Battler.prototype.isDamagePopupRequested = function() {
  2999.     if (!this._damagePopup) this.clearDamagePopup();
  3000.     return this._damagePopup.length > 0;
  3001. };

  3002. Game_Battler.prototype.startDamagePopup = function() {
  3003.     var result = this.result();
  3004.     if (result.missed || result.evaded) {
  3005.       var copyResult = JsonEx.makeDeepCopy(result);
  3006.       copyResult.hpAffected = false;
  3007.       copyResult.mpDamage = 0;
  3008.       this._damagePopup.push(copyResult);
  3009.     }
  3010.     if (result.hpAffected) {
  3011.       var copyResult = JsonEx.makeDeepCopy(result);
  3012.       copyResult.mpDamage = 0;
  3013.       this._damagePopup.push(copyResult);
  3014.     }
  3015.     if (result.mpDamage !== 0) {
  3016.       var copyResult = JsonEx.makeDeepCopy(result);
  3017.       copyResult.hpAffected = false;
  3018.       this._damagePopup.push(copyResult);
  3019.     }
  3020. };

  3021. Game_Battler.prototype.shiftDamagePopup = function() {
  3022.     if (!this._damagePopup) this.clearDamagePopup();
  3023.     return this._damagePopup.shift();
  3024. };

  3025. Yanfly.BEC.Game_Battler_performCollapse =
  3026.     Game_Battler.prototype.performCollapse;
  3027. Game_Battler.prototype.performCollapse = function() {
  3028.     Yanfly.BEC.Game_Battler_performCollapse.call(this);
  3029.     if ($gameParty.inBattle()) this.forceMotion(this.deadMotion());
  3030. };

  3031. Game_Battler.prototype.performResultEffects = function() {
  3032.     var result = this.result();
  3033.     if (result.missed && result.physical) this.performMiss();
  3034.     if (result.evaded) {
  3035.       if (result.physical) {
  3036.         this.performEvasion();
  3037.       } else {
  3038.         this.performMagicEvasion();
  3039.       }
  3040.     }
  3041.     if (result.hpAffected) {
  3042.       if (result.hpDamage > 0 && !result.drain) {
  3043.         this.performDamage();
  3044.       }
  3045.       if (result.hpDamage < 0) {
  3046.         this.performRecovery();
  3047.       }
  3048.     }
  3049.     if (this.isAlive() && result.mpDamage !== 0 && result.mpDamage < 0) {
  3050.       this.performRecovery();
  3051.     }
  3052.     if (this.isAlive() && result.tpDamage !== 0 && result.tpDamage < 0) {
  3053.       this.performRecovery();
  3054.     }
  3055. };

  3056. Yanfly.BEC.Game_Battler_performDamage =
  3057.   Game_Battler.prototype.performDamage;
  3058. Game_Battler.prototype.performDamage = function() {
  3059.     Yanfly.BEC.Game_Battler_performDamage.call(this);
  3060.     this.performFlinch();
  3061. };

  3062. Yanfly.BEC.Game_Battler_performMiss = Game_Battler.prototype.performMiss;
  3063. Game_Battler.prototype.performMiss = function() {
  3064.     Yanfly.BEC.Game_Battler_performMiss.call(this);
  3065.     this.performFlinch();
  3066. };

  3067. Yanfly.BEC.Game_Battler_performEvasion =
  3068.     Game_Battler.prototype.performEvasion;
  3069. Game_Battler.prototype.performEvasion = function() {
  3070.     Yanfly.BEC.Game_Battler_performEvasion.call(this);
  3071.     this.performFlinch();
  3072. };

  3073. Yanfly.BEC.Game_Battler_performMagicEvasion =
  3074.     Game_Battler.prototype.performMagicEvasion;
  3075. Game_Battler.prototype.performMagicEvasion = function() {
  3076.     Yanfly.BEC.Game_Battler_performMagicEvasion.call(this);
  3077.     this.performFlinch();
  3078. };

  3079. Game_Battler.prototype.performFlinch = function() {
  3080.     if (this._flinched || !$gameSystem.isSideView()) return;
  3081.     this._flinched = true;
  3082.     this.spriteStepFlinch();
  3083. };

  3084. Yanfly.BEC.Game_Battler_performReflection =
  3085.     Game_Battler.prototype.performReflection;
  3086. Game_Battler.prototype.performReflection = function() {
  3087.     Yanfly.BEC.Game_Battler_performReflection.call(this);
  3088.     if (!$gameSystem.isSideView() && this.isActor()) return;
  3089.     var animationId = this.reflectAnimationId();
  3090.     var mirror = this.isActor();
  3091.     this.startAnimation(animationId, mirror, 0);
  3092. };

  3093. Yanfly.BEC.Game_Battler_performSubstitute =
  3094.     Game_Battler.prototype.performSubstitute;
  3095. Game_Battler.prototype.performSubstitute = function(target) {
  3096.     Yanfly.BEC.Game_Battler_performSubstitute.call(this, target);
  3097.     if (!$gameSystem.isSideView()) return;
  3098.     this._flinched = true;
  3099.     if (BattleManager._action.isForAll()) {
  3100.       this.spriteStepForward();
  3101.       target.spriteStepSubBack();
  3102.     } else {
  3103.       this.spriteStepToSubstitute(target);
  3104.       target.spriteStepSubBack();
  3105.     }
  3106. };

  3107. Game_Battler.prototype.setBattler = function(sprite) {
  3108.     BattleManager.registerSprite(this, sprite);
  3109. };

  3110. Game_Battler.prototype.battler = function() {
  3111.     return BattleManager.getSprite(this);
  3112. };

  3113. Game_Battler.prototype.requestMotion = function(motionType) {
  3114.     this._motionType = motionType;
  3115.     if (this.battler()) {
  3116.       this.battler().startMotion(motionType);
  3117.     }
  3118. };

  3119. Game_Battler.prototype.forceMotion = function(motionType) {
  3120.     this._motionType = motionType;
  3121.     if (this.battler()) {
  3122.       this.battler().forceMotion(motionType);
  3123.     }
  3124. };

  3125. Game_Battler.prototype.startWeaponAnimation = function(weaponImageId) {
  3126.     this._weaponImageId = weaponImageId;
  3127.     if (this.battler()) {
  3128.       this.battler().setupWeaponAnimation();
  3129.     }
  3130. };

  3131. Game_Battler.prototype.performActionStart = function(action) {
  3132.     if (!action.isGuard()) {
  3133.         this.setActionState('acting');
  3134.         this.spriteStepForward();
  3135.     }
  3136. };

  3137. Yanfly.BEC.Game_Battler_performActionEnd =
  3138.     Game_Battler.prototype.performActionEnd;
  3139. Game_Battler.prototype.performActionEnd = function() {
  3140.     Yanfly.BEC.Game_Battler_performActionEnd.call(this);
  3141.     this.spriteReturnHome();
  3142. };

  3143. Game_Battler.prototype.spriteStepForward = function() {
  3144.     if ($gameSystem.isSideView() && this.battler()) {
  3145.       this.battler().stepForward();
  3146.     }
  3147. };

  3148. Game_Battler.prototype.spriteStepBack = function() {
  3149.     if ($gameSystem.isSideView() && this.battler()) {
  3150.       this.battler().stepBack();
  3151.     }
  3152. };

  3153. Game_Battler.prototype.spriteStepSubBack = function() {
  3154.     if ($gameSystem.isSideView() && this.battler()) {
  3155.       this.battler().stepSubBack();
  3156.     }
  3157. };

  3158. Game_Battler.prototype.spriteStepToSubstitute = function(target) {
  3159.     if ($gameSystem.isSideView() && this.battler()) {
  3160.       this.battler().stepToSubstitute(target);
  3161.     }
  3162. };

  3163. Game_Battler.prototype.spriteStepFlinch = function() {
  3164.     if ($gameSystem.isSideView() && this.battler()) {
  3165.       this.battler().stepFlinch();
  3166.     }
  3167. };

  3168. Game_Battler.prototype.spriteReturnHome = function() {
  3169.     if ($gameSystem.isSideView() && this.battler()) {
  3170.       this._flinched = false;
  3171.       this.spriteFaceForward();
  3172.       this.battler().stepBack();
  3173.       if (this.numActions() <= 0) {
  3174.         this.setActionState('undecided');
  3175.       }
  3176.       this.battler().refreshMotion();
  3177.     }
  3178. };

  3179. Game_Battler.prototype.reflectAnimationId = function() {
  3180.     for (var i = 0; i < this.states().length; ++i) {
  3181.       var state = this.states()[i];
  3182.       if (state.reflectAnimationId > 0) return state.reflectAnimationId;
  3183.     }
  3184.     return Yanfly.Param.BECReflectAni;
  3185. };

  3186. Game_Battler.prototype.spriteCanMove = function() {
  3187.     if (!$gameSystem.isSideView()) return false;
  3188.     for (var i = 0; i < this.states().length; ++i) {
  3189.       var state = this.states()[i];
  3190.       if (state.spriteCannotMove) return false;
  3191.     }
  3192.     return this.canMove();
  3193. };

  3194. Game_Battler.prototype.spritePosX = function() {
  3195.     if ($gameSystem.isSideView() && this.battler()) {
  3196.       return this.battler().x;
  3197.     } else if (this.battler()) {
  3198.       return this.battler().x;
  3199.     } else {
  3200.       return 0;
  3201.     }
  3202. };

  3203. Game_Battler.prototype.spritePosY = function() {
  3204.     if ($gameSystem.isSideView() && this.battler()) {
  3205.       return this.battler().y;
  3206.     } else if (this.battler()) {
  3207.       return this.battler().y;
  3208.     } else {
  3209.       return 0;
  3210.     }
  3211. };

  3212. Game_Battler.prototype.spriteWidth = function() {
  3213.     if ($gameSystem.isSideView() && this.battler() && this.battler().bitmap) {
  3214.       return this.battler().bitmap.width;
  3215.     } else if (this.battler()) {
  3216.       return this.battler().bitmap.width;
  3217.     } else {
  3218.       return 1;
  3219.     }
  3220. };

  3221. Game_Battler.prototype.spriteHeight = function() {
  3222.     if ($gameSystem.isSideView() && this.battler() && this.battler().bitmap) {
  3223.       return this.battler().bitmap.height;
  3224.     } else if (this.battler()) {
  3225.       return this.battler().bitmap.height;
  3226.     } else {
  3227.       return 1;
  3228.     }
  3229. };

  3230. Game_Battler.prototype.anchorX = function() {
  3231.     return Yanfly.Param.BECAnchorX;
  3232. };

  3233. Game_Battler.prototype.anchorY = function() {
  3234.     return Yanfly.Param.BECAnchorY;
  3235. };

  3236. Game_Battler.prototype.spriteHomeX = function() {
  3237.     if ($gameSystem.isSideView() && this.battler()) {
  3238.       return this.battler()._homeX;
  3239.     } else {
  3240.       return 0;
  3241.     }
  3242. };

  3243. Game_Battler.prototype.spriteHomeY = function() {
  3244.     if ($gameSystem.isSideView() && this.battler()) {
  3245.       return this.battler()._homeY;
  3246.     } else {
  3247.       return 0;
  3248.     }
  3249. };

  3250. Game_Battler.prototype.setMirror = function(value) {
  3251.     if ($gameSystem.isSideView() && this.battler() && this.spriteCanMove()) {
  3252.       this.battler().setMirror(value);
  3253.     }
  3254. };

  3255. Game_Battler.prototype.spriteFaceForward = function() {
  3256.     this.setMirror(false);
  3257. };

  3258. Game_Battler.prototype.spriteFaceBackward = function() {
  3259.     this.setMirror(true);
  3260. };

  3261. Game_Battler.prototype.spriteFacePoint = function(pointX, pointY) {
  3262.     if (this.spritePosX() > pointX) {
  3263.       this.spriteFaceBackward();
  3264.     } else {
  3265.       this.spriteFaceForward();
  3266.     }
  3267. };

  3268. Game_Battler.prototype.spriteFaceAwayPoint = function(pointX, pointY) {
  3269.     if (this.spritePosX() > pointX) {
  3270.       this.spriteFaceForward();
  3271.     } else {
  3272.       this.spriteFaceBackward();
  3273.     }
  3274. };

  3275. Game_Battler.prototype.spriteFaceTarget = function(target) {
  3276.     if (!target) return;
  3277.     var pointX = target.spritePosX();
  3278.     var pointY = target.spritePosY();
  3279.     this.spriteFacePoint(pointX, pointY);
  3280. };

  3281. Game_Battler.prototype.spriteFaceAwayTarget = function(target) {
  3282.     if (!target) return;
  3283.     var pointX = target.spritePosX();
  3284.     var pointY = target.spritePosY();
  3285.     this.spriteFaceAwayPoint(pointX, pointY);
  3286. };

  3287. Game_Battler.prototype.spriteFaceHome = function() {
  3288.     var pointX = this.spriteHomeX();
  3289.     var pointY = this.spriteHomeY();
  3290.     this.spriteFacePoint(pointX, pointY);
  3291. };

  3292. Game_Battler.prototype.spriteFaceAwayHome = function() {
  3293.     var pointX = target.spriteHomeX();
  3294.     var pointY = target.spriteHomeY();
  3295.     this.spriteFaceAwayPoint(pointX, pointY);
  3296. };

  3297. Game_Battler.prototype.attackMotion = function() {
  3298.     return 'thrust';
  3299. };

  3300. Game_Battler.prototype.performAttack = function() {
  3301. };

  3302. Game_Battler.prototype.forceMotionRefresh = function() {
  3303.     if (!$gameParty.inBattle()) return;
  3304.     if (this.battler()) this.battler().refreshMotion();
  3305. };

  3306. Game_Battler.prototype.requestMotionRefresh = function() {
  3307.     var deadMotion = this.deadMotion();
  3308.     if (this.isDead() && this._motionType !== deadMotion) {
  3309.       this.requestMotion(deadMotion);
  3310.     }
  3311.     if (this.isDead() && this._motionType === deadMotion) return;
  3312.     if (this._motionType === 'victory') return;
  3313.     if (this._motionType === 'escape' && !BattleManager.isInputting()) return;
  3314.     if (this._motionType === 'guard' && !BattleManager.isInputting()) return;
  3315.     this.clearMotion();
  3316.     if (this.battler() && BattleManager.isInputting()) {
  3317.       this.battler().refreshMotion();
  3318.     }
  3319. };

  3320. Game_Battler.prototype.onTurnStart = function() {
  3321.     this.updateStateTurnStart();
  3322. };

  3323. Game_Battler.prototype.onTurnEnd = function() {
  3324.     this.clearResult();
  3325.     if (BattleManager.isTurnBased()) {
  3326.       this.regenerateAll();
  3327.     } else if (BattleManager.isTickBased() && !BattleManager.isTurnEnd()) {
  3328.       this.regenerateAll();
  3329.     }
  3330.     this.removeStatesAuto(2);
  3331. };

  3332. Yanfly.BEC.Game_Battler_onAllActionsEnd =
  3333.     Game_Battler.prototype.onAllActionsEnd;
  3334. Game_Battler.prototype.onAllActionsEnd = function() {
  3335.     Yanfly.BEC.Game_Battler_onAllActionsEnd.call(this);
  3336.     if (!BattleManager._processTurn) this.updateStateActionEnd();
  3337. };

  3338. Game_Battler.prototype.updateTick = function() {
  3339.     if (BattleManager.timeBasedStates()) this.updateStateTicks();
  3340.     if (BattleManager.timeBasedBuffs()) this.updateBuffTicks();
  3341. };

  3342. Game_Battler.prototype.increaseSelfTurnCount = function() {
  3343.     if (this._selfTurnCount === undefined) this._selfTurnCount = 0;
  3344.     this._selfTurnCount += 1;
  3345. };

  3346. Game_Battler.prototype.turnCount = function() {
  3347.     if (BattleManager.isTurnBased()) return $gameTroop.turnCount();
  3348.     if (BattleManager.isTickBased() && Yanfly.Param.BECAISelfTurn) {
  3349.       return this._selfTurnCount;
  3350.     }
  3351.     return $gameTroop.turnCount();
  3352. };

  3353. Game_Battler.prototype.createActions = function() {
  3354.     if (this.currentAction()) return;
  3355.     this.makeActions();
  3356. };

  3357. Yanfly.BEC.Game_Battler_addState = Game_Battler.prototype.addState;
  3358. Game_Battler.prototype.addState = function(stateId) {
  3359.     Yanfly.BEC.Game_Battler_addState.call(this, stateId);
  3360.     if (this.canAddStateFreeTurn(stateId)) this.setStateFreeTurn(stateId);
  3361. };

  3362. Game_Battler.prototype.canAddStateFreeTurn = function(stateId) {
  3363.     if (!$gameParty.inBattle()) return false;
  3364.     if (!this.isStateAffected(stateId)) return false;
  3365.     if (BattleManager._subject !== this) return false;
  3366.     if ($dataStates[stateId].autoRemovalTiming !== 1) return false;
  3367.     return true;
  3368. };

  3369. Game_Battler.prototype.setStateFreeTurn = function(stateId) {
  3370.     this._freeStateTurn = this._freeStateTurn || [];
  3371.     this._freeStateTurn.push(stateId);
  3372. };

  3373. Game_Battler.prototype.idleMotion = function() {
  3374.     return 'walk';
  3375. };

  3376. Game_Battler.prototype.deadMotion = function() {
  3377.     return 'dead';
  3378. };

  3379. Game_Battler.prototype.sleepMotion = function() {
  3380.     return 'sleep';
  3381. };

  3382. Game_Battler.prototype.chantMotion = function() {
  3383.     return 'chant';
  3384. };

  3385. Game_Battler.prototype.guardMotion = function() {
  3386.     return 'guard';
  3387. };

  3388. Game_Battler.prototype.abnormalMotion = function() {
  3389.     return 'abnormal';
  3390. };

  3391. Game_Battler.prototype.dyingMotion = function() {
  3392.     return 'dying';
  3393. };

  3394. Game_Battler.prototype.waitMotion = function() {
  3395.     return 'wait';
  3396. };

  3397. //=============================================================================
  3398. // Game_Actor
  3399. //=============================================================================

  3400. Yanfly.BEC.Game_Actor_refresh = Game_Actor.prototype.refresh;
  3401. Game_Actor.prototype.refresh = function() {
  3402.     this._anchorX = undefined;
  3403.     this._anchorY = undefined;
  3404.     Yanfly.BEC.Game_Actor_refresh.call(this);
  3405.     if ($gameParty.inBattle()) this.requestStatusRefresh();
  3406. };

  3407. Game_Actor.prototype.isSpriteVisible = function() {
  3408.     if ($gameSystem.isSideView()) return true;
  3409.     return eval(Yanfly.Param.BECFrontSprite);
  3410. };

  3411. Game_Actor.prototype.reflectAnimationId = function() {
  3412.     if (this.actor().reflectAnimationId > 0) {
  3413.       return this.actor().reflectAnimationId;
  3414.     }
  3415.     if (this.currentClass().reflectAnimationId > 0) {
  3416.       return this.currentClass().reflectAnimationId;
  3417.     }
  3418.     for (var i = 0; i < this.equips().length; ++i) {
  3419.       var equip = this.equips()[i];
  3420.       if (equip && equip.reflectAnimationId > 0) {
  3421.         return equip.reflectAnimationId;
  3422.       }
  3423.     }
  3424.     return Game_Battler.prototype.reflectAnimationId.call(this);
  3425. };

  3426. Game_Actor.prototype.spriteCanMove = function() {
  3427.     if (this.actor().spriteCannotMove) return false;
  3428.     if (this.currentClass().spriteCannotMove) return false;
  3429.     for (var i = 0; i < this.equips().length; ++i) {
  3430.       var equip = this.equips()[i];
  3431.       if (equip && equip.spriteCannotMove) return false;
  3432.     }
  3433.     return Game_Battler.prototype.spriteCanMove.call(this);
  3434. };

  3435. Game_Actor.prototype.spriteWidth = function() {
  3436.     if ($gameSystem.isSideView() && this.battler()) {
  3437.       return this.battler()._mainSprite.width;
  3438.     } else {
  3439.       return 1;
  3440.     }
  3441. };

  3442. Game_Actor.prototype.spriteHeight = function() {
  3443.     if ($gameSystem.isSideView() && this.battler()) {
  3444.       return this.battler()._mainSprite.height;
  3445.     } else {
  3446.       return 1;
  3447.     }
  3448. };

  3449. Game_Actor.prototype.anchorX = function() {
  3450.     if (this._anchorX !== undefined) return this._anchorX;
  3451.     var length = this.states().length;
  3452.     for (var i = 0; i < length; ++i) {
  3453.       var obj = this.states()[i];
  3454.       if (obj && obj.anchorX !== undefined) {
  3455.         this._anchorX = obj.anchorX;
  3456.         return this._anchorX;
  3457.       }
  3458.     }
  3459.     length = this.equips().length;
  3460.     for (var i = 0; i < length; ++i) {
  3461.       var obj = this.equips()[i];
  3462.       if (obj && obj.anchorX !== undefined) {
  3463.         this._anchorX = obj.anchorX;
  3464.         return this._anchorX;
  3465.       }
  3466.     }
  3467.     if (this.currentClass().anchorX !== undefined) {
  3468.       this._anchorX = this.currentClass().anchorX;
  3469.       return this._anchorX;
  3470.     }
  3471.     this._anchorX = this.actor().anchorX;
  3472.     return this._anchorX;
  3473. };

  3474. Game_Actor.prototype.anchorY = function() {
  3475.     if (this._anchorY !== undefined) return this._anchorY;
  3476.     var length = this.states().length;
  3477.     for (var i = 0; i < length; ++i) {
  3478.       var obj = this.states()[i];
  3479.       if (obj && obj.anchorY !== undefined) {
  3480.         this._anchorY = obj.anchorY;
  3481.         return this._anchorY;
  3482.       }
  3483.     }
  3484.     length = this.equips().length;
  3485.     for (var i = 0; i < length; ++i) {
  3486.       var obj = this.equips()[i];
  3487.       if (obj && obj.anchorY !== undefined) {
  3488.         this._anchorY = obj.anchorY;
  3489.         return this._anchorY;
  3490.       }
  3491.     }
  3492.     if (this.currentClass().anchorY !== undefined) {
  3493.       this._anchorY = this.currentClass().anchorY;
  3494.       return this._anchorY;
  3495.     }
  3496.     this._anchorY = this.actor().anchorY;
  3497.     return this._anchorY;
  3498. };

  3499. Game_Actor.prototype.spriteFacePoint = function(pointX, pointY) {
  3500.     if (this.spritePosX() > pointX) {
  3501.       this.spriteFaceForward();
  3502.     } else {
  3503.       this.spriteFaceBackward();
  3504.     }
  3505. };

  3506. Game_Actor.prototype.spriteFaceAwayPoint = function(pointX, pointY) {
  3507.     if (this.spritePosX() > pointX) {
  3508.       this.spriteFaceBackward();
  3509.     } else {
  3510.       this.spriteFaceForward();
  3511.     }
  3512. };

  3513. Game_Actor.prototype.performAttack = function() {
  3514.     var weapons = this.weapons();
  3515.     var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
  3516.     var attackMotion = $dataSystem.attackMotions[wtypeId];
  3517.     if (attackMotion) {
  3518.       if (attackMotion.type === 0) {
  3519.         this.forceMotion('thrust');
  3520.       } else if (attackMotion.type === 1) {
  3521.         this.forceMotion('swing');
  3522.       } else if (attackMotion.type === 2) {
  3523.         this.forceMotion('missile');
  3524.       }
  3525.       this.startWeaponAnimation(attackMotion.weaponImageId);
  3526.     }
  3527. };

  3528. Game_Actor.prototype.attackMotion = function() {
  3529.     var weapons = this.weapons();
  3530.     var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
  3531.     var attackMotion = $dataSystem.attackMotions[wtypeId];
  3532.     if (attackMotion) {
  3533.       if (attackMotion.type === 0) {
  3534.         return 'thrust';
  3535.       } else if (attackMotion.type === 1) {
  3536.         return 'swing';
  3537.       } else if (attackMotion.type === 2) {
  3538.         return 'missile';
  3539.       }
  3540.     };
  3541.     return 'thrust';
  3542. };

  3543. Game_Actor.prototype.performEscapeSuccess = function() {
  3544.     if (this.battler()) {
  3545.       this.performEscape();
  3546.       this.battler().startMove(300, 0, 60);
  3547.     }
  3548. };

  3549. //=============================================================================
  3550. // Game_Enemy
  3551. //=============================================================================

  3552. Game_Enemy.prototype.performActionStart = function(action) {
  3553.     Game_Battler.prototype.performActionStart.call(this, action);
  3554.     if (!$gameSystem.isSideView() || !this.spriteCanMove()) {
  3555.       this.requestEffect('whiten');
  3556.     }
  3557. };

  3558. Yanfly.BEC.Game_Enemy_performDamage = Game_Enemy.prototype.performDamage;
  3559. Game_Enemy.prototype.performDamage = function() {
  3560.     if ($gameSystem.isSideView()) {
  3561.       Game_Battler.prototype.performDamage.call(this);
  3562.       SoundManager.playEnemyDamage();
  3563.     } else {
  3564.       Yanfly.BEC.Game_Enemy_performDamage.call(this);
  3565.     }
  3566. };

  3567. Game_Enemy.prototype.attackAnimationId = function() {
  3568.     return this.enemy().attackAnimationId;
  3569. };

  3570. Game_Enemy.prototype.reflectAnimationId = function() {
  3571.     if (this.enemy().reflectAnimationId > 0) {
  3572.       return this.enemy().reflectAnimationId;
  3573.     }
  3574.     return Game_Battler.prototype.reflectAnimationId.call(this);
  3575. };

  3576. Game_Enemy.prototype.spriteCanMove = function() {
  3577.     if (this.enemy().spriteCannotMove) return false;
  3578.     return Game_Battler.prototype.spriteCanMove.call(this);
  3579. };

  3580. Game_Enemy.prototype.meetsTurnCondition = function(param1, param2) {
  3581.     var n = this.turnCount();
  3582.     if (param2 === 0) {
  3583.         return n === param1;
  3584.     } else {
  3585.         return n > 0 && n >= param1 && n % param2 === param1 % param2;
  3586.     }
  3587. };

  3588. //=============================================================================
  3589. // Game_Unit
  3590. //=============================================================================

  3591. Game_Unit.prototype.createActions = function() {
  3592.     var max = this.members().length;
  3593.     for (var i = 0; i < max; ++i) {
  3594.       var member = this.members()[i];
  3595.       if (member) member.createActions();
  3596.     }
  3597. };

  3598. Game_Unit.prototype.requestMotionRefresh = function() {
  3599.     var max = this.members().length;
  3600.     for (var i = 0; i < max; ++i) {
  3601.       var member = this.members()[i];
  3602.       if (member) member.requestMotionRefresh();
  3603.     }
  3604. };

  3605. Game_Unit.prototype.onTurnStart = function() {
  3606.     var max = this.members().length;
  3607.     for (var i = 0; i < max; ++i) {
  3608.       var member = this.members()[i];
  3609.       if (member) member.onTurnStart();
  3610.     }
  3611. };

  3612. Game_Unit.prototype.updateTick = function() {
  3613.     var max = this.members().length;
  3614.     for (var i = 0; i < max; ++i) {
  3615.       var member = this.members()[i];
  3616.       if (member) member.updateTick();
  3617.     }
  3618. };

  3619. //=============================================================================
  3620. // Game_Party
  3621. //=============================================================================

  3622. Game_Party.prototype.performEscapeSuccess = function() {
  3623.     for (var i = 0; i < this.members().length; ++i) {
  3624.       var member = this.members()[i];
  3625.       if (member) member.performEscapeSuccess();
  3626.     }
  3627. };

  3628. //=============================================================================
  3629. // Scene_Battle
  3630. //=============================================================================

  3631. Yanfly.BEC.Scene_Battle_update = Scene_Battle.prototype.update;
  3632. Scene_Battle.prototype.update = function() {
  3633.     Yanfly.BEC.Scene_Battle_update.call(this);
  3634.     this.updateStatusWindowRequests();
  3635. };

  3636. Scene_Battle.prototype.updateStatusWindowRequests = function() {
  3637.     if (!this._statusWindow) return;
  3638.     if (this._statusWindow.isClosed()) return;
  3639.     this._statusWindow.updateStatusRequests();
  3640. };

  3641. Yanfly.BEC.Scene_Battle_createSkillWindow =
  3642.     Scene_Battle.prototype.createSkillWindow;
  3643. Scene_Battle.prototype.createSkillWindow = function() {
  3644.     Yanfly.BEC.Scene_Battle_createSkillWindow.call(this);
  3645.     if (eval(Yanfly.Param.BECLowerWindows)) {
  3646.       this.adjustLowerWindow(this._skillWindow);
  3647.     }
  3648. };

  3649. Yanfly.BEC.Scene_Battle_createItemWindow =
  3650.     Scene_Battle.prototype.createItemWindow;
  3651. Scene_Battle.prototype.createItemWindow = function() {
  3652.     Yanfly.BEC.Scene_Battle_createItemWindow.call(this);
  3653.     if (eval(Yanfly.Param.BECLowerWindows)) {
  3654.       this.adjustLowerWindow(this._itemWindow);
  3655.     }
  3656. };

  3657. Yanfly.BEC.Scene_Battle_createActorWindow =
  3658.     Scene_Battle.prototype.createActorWindow;
  3659. Scene_Battle.prototype.createActorWindow = function() {
  3660.     Yanfly.BEC.Scene_Battle_createActorWindow.call(this);
  3661.     this._actorWindow.x = Graphics.boxWidth - this._actorWindow.width;
  3662.     if (eval(Yanfly.Param.BECSelectHelp)) {
  3663.       this._actorWindow.setHelpWindow(this._helpWindow);
  3664.     }
  3665. };

  3666. Yanfly.BEC.Scene_Battle_createEnemyWindow =
  3667.     Scene_Battle.prototype.createEnemyWindow;
  3668. Scene_Battle.prototype.createEnemyWindow = function() {
  3669.     Yanfly.BEC.Scene_Battle_createEnemyWindow.call(this);
  3670.     if (eval(Yanfly.Param.BECSelectHelp)) {
  3671.       this._enemyWindow.setHelpWindow(this._helpWindow);
  3672.     }
  3673. };

  3674. Scene_Battle.prototype.adjustLowerWindow = function(win) {
  3675.     win.height = win.fittingHeight(eval(Yanfly.Param.BECWindowRows));
  3676.     win.y = Graphics.boxHeight - win.height;
  3677. };

  3678. Yanfly.BEC.Scene_Battle_startPartyCommandSelection =
  3679.     Scene_Battle.prototype.startPartyCommandSelection;
  3680. Scene_Battle.prototype.startPartyCommandSelection = function() {
  3681.     if (this.isStartActorCommand()) {
  3682.       this.selectNextCommand();
  3683.     } else {
  3684.       Yanfly.BEC.Scene_Battle_startPartyCommandSelection.call(this);
  3685.     }
  3686. };

  3687. Scene_Battle.prototype.isStartActorCommand = function() {
  3688.     if (this._isStartActorCommand === undefined) {
  3689.       this._isStartActorCommand = eval(Yanfly.Param.BECStartActCmd)
  3690.     }
  3691.     return this._isStartActorCommand;
  3692. };

  3693. Yanfly.BEC.Scene_Battle_selectPreviousCommand =
  3694.     Scene_Battle.prototype.selectPreviousCommand;
  3695. Scene_Battle.prototype.selectPreviousCommand = function() {
  3696.     if (this.isStartActorCommand()) {
  3697.       BattleManager.selectPreviousCommand();
  3698.       if (BattleManager.isInputting() && BattleManager.actor()) {
  3699.         this.startActorCommandSelection();
  3700.       } else {
  3701.         Yanfly.BEC.Scene_Battle_startPartyCommandSelection.call(this);
  3702.       }
  3703.     } else {
  3704.       Yanfly.BEC.Scene_Battle_selectPreviousCommand.call(this);
  3705.     }
  3706. };

  3707. Yanfly.BEC.Scene_Battle_selectNextCommand =
  3708.     Scene_Battle.prototype.selectNextCommand;
  3709. Scene_Battle.prototype.selectNextCommand = function() {
  3710.     Yanfly.BEC.Scene_Battle_selectNextCommand.call(this);
  3711.     this._helpWindow.clear();
  3712.     BattleManager.stopAllSelection();
  3713. };

  3714. Yanfly.BEC.Scene_Battle_commandSkill = Scene_Battle.prototype.commandSkill;
  3715. Scene_Battle.prototype.commandSkill = function() {
  3716.     this._helpWindow.clear();
  3717.     Yanfly.BEC.Scene_Battle_commandSkill.call(this);
  3718. };

  3719. Yanfly.BEC.Scene_Battle_commandItem = Scene_Battle.prototype.commandItem;
  3720. Scene_Battle.prototype.commandItem = function() {
  3721.     this._helpWindow.clear();
  3722.     Yanfly.BEC.Scene_Battle_commandItem.call(this);
  3723. };

  3724. Yanfly.BEC.Scene_Battle_startActorCommandSelection =
  3725.     Scene_Battle.prototype.startActorCommandSelection;
  3726. Scene_Battle.prototype.startActorCommandSelection = function() {
  3727.     BattleManager.createActions();
  3728.     Yanfly.BEC.Scene_Battle_startActorCommandSelection.call(this);
  3729.     this._statusWindow.refresh();
  3730. };

  3731. Yanfly.BEC.Scene_Battle_selectActorSelection =
  3732.     Scene_Battle.prototype.selectActorSelection;
  3733. Scene_Battle.prototype.selectActorSelection = function() {
  3734.     if (eval(Yanfly.Param.BECSelectHelp)) this._helpWindow.show();
  3735.     this._helpWindow.clear();
  3736.     Yanfly.BEC.Scene_Battle_selectActorSelection.call(this);
  3737.     this._actorWindow.autoSelect();
  3738. };

  3739. Yanfly.BEC.Scene_Battle_onActorCancel = Scene_Battle.prototype.onActorCancel;
  3740. Scene_Battle.prototype.onActorCancel = function() {
  3741.     if (eval(Yanfly.Param.BECSelectHelp)) this._helpWindow.hide();
  3742.     this._helpWindow.clear();
  3743.     Yanfly.BEC.Scene_Battle_onActorCancel.call(this);
  3744.     BattleManager.stopAllSelection();
  3745.     BattleManager.clearInputtingAction();
  3746. };

  3747. Yanfly.BEC.Scene_Battle_selectEnemySelection =
  3748.     Scene_Battle.prototype.selectEnemySelection;
  3749. Scene_Battle.prototype.selectEnemySelection = function() {
  3750.     if (eval(Yanfly.Param.BECSelectHelp)) this._helpWindow.show();
  3751.     this._helpWindow.clear();
  3752.     Yanfly.BEC.Scene_Battle_selectEnemySelection.call(this);
  3753.     this._enemyWindow.autoSelect();
  3754. };

  3755. Yanfly.BEC.Scene_Battle_onEnemyCancel = Scene_Battle.prototype.onEnemyCancel;
  3756. Scene_Battle.prototype.onEnemyCancel = function() {
  3757.     if (eval(Yanfly.Param.BECSelectHelp)) this._helpWindow.hide();
  3758.     this._helpWindow.clear();
  3759.     Yanfly.BEC.Scene_Battle_onEnemyCancel.call(this);
  3760.     BattleManager.stopAllSelection();
  3761.     BattleManager.clearInputtingAction();
  3762. };

  3763. Yanfly.BEC.Scene_Battle_onSelectAction = Scene_Battle.prototype.onSelectAction;
  3764. Scene_Battle.prototype.onSelectAction = function() {
  3765.     if (eval(Yanfly.Param.BECSelectHelp)) BattleManager.forceSelection();
  3766.     this._helpWindow.clear();
  3767.     Yanfly.BEC.Scene_Battle_onSelectAction.call(this);
  3768.     if (eval(Yanfly.Param.BECSelectHelp)) BattleManager.resetSelection();
  3769. };

  3770. Yanfly.BEC.Scene_Battle_onSkillOk =
  3771.     Scene_Battle.prototype.onSkillOk;
  3772. Scene_Battle.prototype.onSkillOk = function() {
  3773.     this._helpWindow.clear();
  3774.     Yanfly.BEC.Scene_Battle_onSkillOk.call(this);
  3775. };

  3776. Yanfly.BEC.Scene_Battle_onSkillCancel =
  3777.     Scene_Battle.prototype.onSkillCancel;
  3778. Scene_Battle.prototype.onSkillCancel = function() {
  3779.     this._helpWindow.clear();
  3780.     Yanfly.BEC.Scene_Battle_onSkillCancel.call(this);
  3781.     BattleManager.clearInputtingAction();
  3782. };

  3783. Yanfly.BEC.Scene_Battle_onItemOk =
  3784.     Scene_Battle.prototype.onItemOk;
  3785. Scene_Battle.prototype.onItemOk = function() {
  3786.     this._helpWindow.clear();
  3787.     Yanfly.BEC.Scene_Battle_onItemOk.call(this);
  3788. };

  3789. Yanfly.BEC.Scene_Battle_onItemCancel =
  3790.     Scene_Battle.prototype.onItemCancel;
  3791. Scene_Battle.prototype.onItemCancel = function() {
  3792.     this._helpWindow.clear();
  3793.     Yanfly.BEC.Scene_Battle_onItemCancel.call(this);
  3794.     BattleManager.clearInputtingAction();
  3795. };

  3796. //=============================================================================
  3797. // Window_Selectable
  3798. //=============================================================================

  3799. Yanfly.BEC.Window_Selectable_isCursorMovable =
  3800.     Window_Selectable.prototype.isCursorMovable;
  3801. Window_Selectable.prototype.isCursorMovable = function() {
  3802.     if (this._inputLock) return false;
  3803.     return Yanfly.BEC.Window_Selectable_isCursorMovable.call(this);
  3804. };

  3805. //=============================================================================
  3806. // Window_Help
  3807. //=============================================================================

  3808. Yanfly.BEC.Window_Help_clear = Window_Help.prototype.clear;
  3809. Window_Help.prototype.clear = function() {
  3810.     Yanfly.BEC.Window_Help_clear.call(this);
  3811.     this.contents.clear();
  3812. };

  3813. Window_Help.prototype.setBattler = function(battler) {
  3814.     this.contents.clear();
  3815.     this.clear();
  3816.     if (!$gameParty.inBattle()) return;
  3817.     if (!battler) return;
  3818.     var action = BattleManager.inputtingAction();
  3819.     if (this.specialSelectionText(action)) {
  3820.       this.drawSpecialSelectionText(action);
  3821.     } else {
  3822.       this.drawBattler(battler);
  3823.     }
  3824. };

  3825. Window_Help.prototype.specialSelectionText = function(action) {
  3826.     BattleManager.resetSelection();
  3827.     if (!action) return false;
  3828.     return !action.needsSelection();
  3829. };

  3830. Window_Help.prototype.drawBattler = function(battler) {
  3831.     var text = battler.name();
  3832.     var wx = 0;
  3833.     var wy = (this.contents.height - this.lineHeight()) / 2;
  3834.     this.drawText(text, wx, wy, this.contents.width, 'center');
  3835. };

  3836. Window_Help.prototype.drawSpecialSelectionText = function(action) {
  3837.     var wx = 0;
  3838.     var wy = (this.contents.height - this.lineHeight()) / 2;
  3839.     var text = '';
  3840.     if (action.isForUser()) {
  3841.       text = Yanfly.Param.BECHelpUserTx;
  3842.     } else if (action.isForRandom()) {
  3843.       BattleManager.startAllSelection();
  3844.       var fmt = Yanfly.Param.BECHelpRandTx;
  3845.       if (action.isForOpponent() && action.numTargets() !== 1) {
  3846.         var target = Yanfly.Param.BECHelpEnemiesTx;
  3847.       } else if (action.isForOpponent() && action.numTargets() === 1) {
  3848.         var target = Yanfly.Param.BECHelpEnemyTx;
  3849.       } else if (action.isForFriend() && action.numTargets() !== 1) {
  3850.         var target = Yanfly.Param.BECHelpAlliesTx;
  3851.       } else {
  3852.         var target = Yanfly.Param.BECHelpAllyTx;
  3853.       }
  3854.       text = fmt.format(target, Yanfly.Util.toGroup(action.numTargets()));
  3855.     } else if (action.isForAll()) {
  3856.       BattleManager.startAllSelection();
  3857.       var fmt = Yanfly.Param.BECHelpAllTx;
  3858.       if (action.isForOpponent()) {
  3859.         var target = Yanfly.Param.BECHelpEnemiesTx;
  3860.       } else {
  3861.         var target = Yanfly.Param.BECHelpAlliesTx;
  3862.       }
  3863.       text = fmt.format(target);
  3864.     }
  3865.     this.drawText(text, wx, wy, this.contents.width, 'center');
  3866. };

  3867. //=============================================================================
  3868. // Window_BattleActor
  3869. //=============================================================================

  3870. Window_BattleActor.prototype.autoSelect = function() {
  3871.     var action = BattleManager.inputtingAction();
  3872.     if (!action) return;
  3873.     this._inputLock = false;
  3874.     this._selectDead = false;
  3875.     if (action.isForUser()) {
  3876.       this.select(BattleManager.actor().index());
  3877.       this._inputLock = true;
  3878.     } else if (action.isForDeadFriend()) {
  3879.       this._selectDead = true;
  3880.       this.autoSelectFirstDeadActor();
  3881.       if (action.isForAll()) this._inputLock = true;
  3882.     }
  3883. };

  3884. Window_BattleActor.prototype.autoSelectFirstDeadActor = function() {
  3885.     var length = $gameParty.members().length;
  3886.     for (var i = 0; i < length; ++i) {
  3887.       var member = $gameParty.members()[i];
  3888.       if (member && member.isDead()) return this.select(i);
  3889.     }
  3890. };

  3891. Window_BattleActor.prototype.isOkEnabled = function() {
  3892.     if (this._selectDead) return this.actor().isDead();
  3893.     return Window_Selectable.prototype.isOkEnabled.call(this);
  3894. };

  3895. Window_BattleActor.prototype.updateHelp = function() {
  3896.     if (!this._helpWindow) return;
  3897.     this._helpWindow.setBattler(this.actor());
  3898. };

  3899. Yanfly.BEC.Window_BattleActor_processTouch =
  3900.     Window_BattleActor.prototype.processTouch;
  3901. Window_BattleActor.prototype.processTouch = function() {
  3902.     if (eval(Yanfly.Param.BECActorSelect) && this.isOpenAndActive()) {
  3903.       if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  3904.         if (this.getClickedActor() >= 0) {
  3905.           var index = this.getClickedActor();
  3906.           if (this.index() === index) {
  3907.             return this.processOk();
  3908.           } else {
  3909.             SoundManager.playCursor();
  3910.             return this.select(index);
  3911.           }
  3912.         }
  3913.       }
  3914.       if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  3915.         if (this.getClickedActor() >= 0) {
  3916.           var index = this.getClickedActor();
  3917.           if (this.index() !== index) {
  3918.             SoundManager.playCursor();
  3919.             return this.select(index);
  3920.           }
  3921.         }
  3922.       }
  3923.       if (Yanfly.Param.BECSelectMouseOver) {
  3924.         var index = this.getMouseOverActor();
  3925.         if (index >= 0 && this.index() !== index) {
  3926.           SoundManager.playCursor();
  3927.           return this.select(index);
  3928.         }
  3929.       }
  3930.     }
  3931.     Yanfly.BEC.Window_BattleActor_processTouch.call(this);
  3932. };

  3933. Window_BattleActor.prototype.getClickedActor = function() {
  3934.     for (var i = 0; i < $gameParty.battleMembers().length; ++i) {
  3935.       var actor = $gameParty.battleMembers().reverse()[i];
  3936.       if (!actor) continue;
  3937.       if (this.isClickedActor(actor)) {
  3938.         if (this._selectDead && !actor.isDead()) continue;
  3939.         if (this._inputLock && actor.index() !== this.index()) continue;
  3940.         return actor.index();
  3941.       }
  3942.     }
  3943.     return -1;
  3944. };

  3945. Window_BattleActor.prototype.isClickedActor = function(actor) {
  3946.     if (!actor) return false;
  3947.     if (!actor.isSpriteVisible()) return false;
  3948.     if (!actor.isAppeared()) return false;
  3949.     var x = TouchInput.x;
  3950.     var y = TouchInput.y;
  3951.     var rect = new Rectangle();
  3952.     rect.width = actor.spriteWidth();
  3953.     rect.height = actor.spriteHeight();
  3954.     rect.x = actor.spritePosX() - rect.width / 2;
  3955.     rect.y = actor.spritePosY() - rect.height;
  3956.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  3957.       y < rect.y + rect.height);
  3958. };

  3959. Window_BattleActor.prototype.getMouseOverActor = function() {
  3960.     for (var i = 0; i < $gameParty.battleMembers().length; ++i) {
  3961.       var actor = $gameParty.battleMembers().reverse()[i];
  3962.       if (!actor) continue;
  3963.       if (this.isMouseOverActor(actor)) {
  3964.         if (this._selectDead && !actor.isDead()) continue;
  3965.         if (this._inputLock && actor.index() !== this.index()) continue;
  3966.         return actor.index();
  3967.       }
  3968.     }
  3969.     return -1;
  3970. };

  3971. Window_BattleActor.prototype.isMouseOverActor = function(actor) {
  3972.     if (!actor) return false;
  3973.     if (!actor.isSpriteVisible()) return false;
  3974.     if (!actor.isAppeared()) return false;
  3975.     var x = TouchInput._mouseOverX;
  3976.     var y = TouchInput._mouseOverY;
  3977.     var rect = new Rectangle();
  3978.     rect.width = actor.spriteWidth();
  3979.     rect.height = actor.spriteHeight();
  3980.     rect.x = actor.spritePosX() - rect.width / 2;
  3981.     rect.y = actor.spritePosY() - rect.height;
  3982.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  3983.       y < rect.y + rect.height);
  3984. };

  3985. //=============================================================================
  3986. // Window_BattleEnemy
  3987. //=============================================================================

  3988. Yanfly.DisableWebGLMask = false;

  3989. Yanfly.BEC.Window_BattleEnemy_initialize =
  3990.     Window_BattleEnemy.prototype.initialize;
  3991. Window_BattleEnemy.prototype.initialize = function(x, y) {
  3992.     if (eval(Yanfly.Param.BECEnemySelect)) {
  3993.       x -= Graphics.boxWidth * 200;
  3994.       y -= Graphics.boxHeight * 200;
  3995.     };
  3996.     Yanfly.BEC.Window_BattleEnemy_initialize.call(this, x, y);
  3997. };

  3998. Yanfly.BEC.WindowLayer_webglMaskWindow =
  3999.     WindowLayer.prototype._webglMaskWindow;
  4000. WindowLayer.prototype._webglMaskWindow = function(renderSession, win) {
  4001.     if (win._ignoreMask) return;
  4002.     Yanfly.BEC.WindowLayer_webglMaskWindow.call(this, renderSession, win);
  4003. };

  4004. Yanfly.BEC.Window_BattleEnemy_maxCols =
  4005.     Window_BattleEnemy.prototype.maxCols;
  4006. Window_BattleEnemy.prototype.maxCols = function() {
  4007.     if (eval(Yanfly.Param.BECEnemySelect)) return this._enemies.length;
  4008.     return Yanfly.BEC.Window_BattleEnemy_maxCols.call(this);
  4009. };

  4010. Window_BattleEnemy.prototype.allowedTargets = function() {
  4011.     var targets = [];
  4012.     targets = targets.concat($gameTroop.aliveMembers());
  4013.     return targets;
  4014. };

  4015. Window_BattleEnemy.prototype.refresh = function() {
  4016.     this._enemies = this.allowedTargets();
  4017.     this.sortTargets();
  4018.     Window_Selectable.prototype.refresh.call(this);
  4019. };

  4020. Window_BattleEnemy.prototype.sortTargets = function() {
  4021.     this._enemies.sort(function(a, b) {
  4022.         if (a.spritePosX() == b.spritePosX()) {
  4023.           return a.spritePosY() - b.spritePosY();
  4024.         }
  4025.         return a.spritePosX() - b.spritePosX();
  4026.     });
  4027. };

  4028. Window_BattleEnemy.prototype.autoSelect = function() {
  4029.     var selectIndex = eval(Yanfly.Param.BECEnemyAutoSel);
  4030.     this.select(selectIndex);
  4031. };

  4032. Window_BattleEnemy.prototype.furthestRight = function() {
  4033.     return this.maxItems() - 1;
  4034. };

  4035. Window_BattleEnemy.prototype.updateHelp = function() {
  4036.     if (!this._helpWindow) return;
  4037.     this._helpWindow.setBattler(this.enemy());
  4038. };

  4039. Yanfly.BEC.Window_BattleEnemy_processTouch =
  4040.     Window_BattleEnemy.prototype.processTouch;
  4041. Window_BattleEnemy.prototype.processTouch = function() {
  4042.     if (eval(Yanfly.Param.BECEnemySelect) && this.isOpenAndActive()) {
  4043.       if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  4044.         if (this.getClickedEnemy() >= 0) {
  4045.           var index = this.getClickedEnemy();
  4046.           if (this.index() === index) {
  4047.             return this.processOk();
  4048.           } else {
  4049.             SoundManager.playCursor();
  4050.             return this.select(index);
  4051.           }
  4052.         }
  4053.       }
  4054.       if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  4055.         if (this.getClickedEnemy() >= 0) {
  4056.           var index = this.getClickedEnemy();
  4057.           if (this.index() !== index) {
  4058.             SoundManager.playCursor();
  4059.             return this.select(index);
  4060.           }
  4061.         }
  4062.       }
  4063.       if (Yanfly.Param.BECSelectMouseOver) {
  4064.         var index = this.getMouseOverEnemy();
  4065.         if (index >= 0 && this.index() !== index) {
  4066.           SoundManager.playCursor();
  4067.           return this.select(index);
  4068.         }
  4069.       }
  4070.     };
  4071.     Yanfly.BEC.Window_BattleEnemy_processTouch.call(this);
  4072. };

  4073. Window_BattleEnemy.prototype.getClickedEnemy = function() {
  4074.     for (var i = 0; i < this._enemies.length; ++i) {
  4075.       var enemy = this._enemies[i];
  4076.       if (!enemy) continue;
  4077.       if (this.isClickedEnemy(enemy)) {
  4078.         if (this._selectDead && !enemy.isDead()) continue;
  4079.         var index = this._enemies.indexOf(enemy)
  4080.         if (this._inputLock && index !== this.index()) continue;
  4081.         return index;
  4082.       }
  4083.     }
  4084.     return -1;
  4085. };

  4086. Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
  4087.     if (!enemy) return false;
  4088.     if (!enemy.isSpriteVisible()) return false;
  4089.     var x = TouchInput.x;
  4090.     var y = TouchInput.y;
  4091.     var rect = new Rectangle();
  4092.     rect.width = enemy.spriteWidth();
  4093.     rect.height = enemy.spriteHeight();
  4094.     rect.x = enemy.spritePosX() - rect.width / 2;
  4095.     rect.y = enemy.spritePosY() - rect.height;
  4096.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  4097.       y < rect.y + rect.height);
  4098. };

  4099. Window_BattleEnemy.prototype.getMouseOverEnemy = function() {
  4100.     for (var i = 0; i < this._enemies.length; ++i) {
  4101.       var enemy = this._enemies[i];
  4102.       if (!enemy) continue;
  4103.       if (this.isMouseOverEnemy(enemy)) {
  4104.         if (this._selectDead && !enemy.isDead()) continue;
  4105.         var index = this._enemies.indexOf(enemy)
  4106.         if (this._inputLock && index !== this.index()) continue;
  4107.         return index;
  4108.       }
  4109.     }
  4110.     return -1;
  4111. };

  4112. Window_BattleEnemy.prototype.isMouseOverEnemy = function(enemy) {
  4113.     if (!enemy) return false;
  4114.     if (!enemy.isSpriteVisible()) return false;
  4115.     var x = TouchInput._mouseOverX;
  4116.     var y = TouchInput._mouseOverY;
  4117.     var rect = new Rectangle();
  4118.     rect.width = enemy.spriteWidth();
  4119.     rect.height = enemy.spriteHeight();
  4120.     rect.x = enemy.spritePosX() - rect.width / 2;
  4121.     rect.y = enemy.spritePosY() - rect.height;
  4122.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  4123.       y < rect.y + rect.height);
  4124. };

  4125. //=============================================================================
  4126. // Window_EnemyVisualSelect
  4127. //=============================================================================

  4128. function Window_EnemyVisualSelect() {
  4129.     this.initialize.apply(this, arguments);
  4130. }

  4131. Window_EnemyVisualSelect.prototype = Object.create(Window_Base.prototype);
  4132. Window_EnemyVisualSelect.prototype.constructor = Window_EnemyVisualSelect;

  4133. Window_EnemyVisualSelect.prototype.initialize = function() {
  4134.     Window_Base.prototype.initialize.call(this, 0, 0, 1, 1);
  4135.     this._battler = null;
  4136.     this._battlerName = '';
  4137.     this._requestRefresh = false;
  4138.     this._showSelectCursor = eval(Yanfly.Param.BECShowSelectBox);
  4139.     this._showEnemyName = eval(Yanfly.Param.BECShowEnemyName);
  4140.     this.contentsOpacity = 0;
  4141.     this.opacity = 0;
  4142. };

  4143. Window_EnemyVisualSelect.prototype.setBattler = function(battler) {
  4144.     if (this._battler === battler) return;
  4145.     this._battler = battler;
  4146.     this._battlerName = battler.name();
  4147. };

  4148. Window_EnemyVisualSelect.prototype.update = function() {
  4149.     Window_Base.prototype.update.call(this);
  4150.     if (!this._battler) return;
  4151.     this.updateWindowAspects();
  4152. };

  4153. Window_EnemyVisualSelect.prototype.updateWindowAspects = function() {
  4154.     this.updateBattlerName();
  4155.     this.updateWindowSize();
  4156.     this.updateWindowPosition();
  4157.     this.updateOpacity();
  4158.     this.updateRefresh();
  4159.     this.updateCursor();
  4160. };

  4161. Window_EnemyVisualSelect.prototype.updateBattlerName = function() {
  4162.     if (this._battlerName !== this._battler.name())
  4163.     this._battlerName = this._battler.name();
  4164.     this._requestRefresh = true;
  4165. };

  4166. Window_EnemyVisualSelect.prototype.updateWindowSize = function() {
  4167.     var spriteWidth = this._battler.spriteWidth();
  4168.     this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
  4169.     var textWidth = this.textWidth(this._battler.name());
  4170.     textWidth += this.textPadding() * 2;
  4171.     var width = Math.max(spriteWidth, textWidth) + this.standardPadding() * 2;
  4172.     var height = this._battler.spriteHeight() + this.standardPadding() * 2;
  4173.     if (width === this.width && height === this.height) return;
  4174.     this.width = width;
  4175.     this.height = height;
  4176.     this.createContents();
  4177.     this._requestRefresh = true;
  4178.     this.makeWindowBoundaries();
  4179. };

  4180. Window_EnemyVisualSelect.prototype.makeWindowBoundaries = function() {
  4181.     if (!this._requestRefresh) return;
  4182.     this._minX = -1 * this.standardPadding();
  4183.     this._maxX = Graphics.boxWidth - this.width + this.standardPadding();
  4184.     this._minY = -1 * this.standardPadding();
  4185.     this._maxY = Graphics.boxHeight - this.height + this.standardPadding();
  4186.     this._maxY -= SceneManager._scene._statusWindow.height;
  4187. };

  4188. Window_EnemyVisualSelect.prototype.updateWindowPosition = function() {
  4189.     if (!this._battler) return;
  4190.     this.x = -1 * this.width / 2;
  4191.     this.y = -1 * this.height + this.standardPadding();
  4192.     this.x += this._battler.spritePosX();
  4193.     this.y += this._battler.spritePosY();
  4194.     this.x = this.x.clamp(this._minX, this._maxX);
  4195.     this.y = this.y.clamp(this._minY, this._maxY);
  4196. };

  4197. Window_EnemyVisualSelect.prototype.updateOpacity = function() {
  4198.     if (this.isShowWindow()) {
  4199.       this.contentsOpacity += 32;
  4200.     } else {
  4201.       this.contentsOpacity -= 32;
  4202.     }
  4203. };

  4204. Window_EnemyVisualSelect.prototype.isShowWindow = function() {
  4205.     var scene = SceneManager._scene;
  4206.     if (!scene._enemyWindow) return false;
  4207.     var enemyWindow = scene._enemyWindow;
  4208.     if (!enemyWindow.active) return false;
  4209.     if (!this._battler.isAppeared()) return false;
  4210.     if (this._battler.isDead()) {
  4211.       return enemyWindow._selectDead;
  4212.     }
  4213.     return enemyWindow._enemies.contains(this._battler);
  4214. };

  4215. Window_EnemyVisualSelect.prototype.updateCursor = function() {
  4216.     if (this.isShowCursor()) {
  4217.       var wy = this.contents.height - this.lineHeight();
  4218.       this.setCursorRect(0, wy, this.contents.width, this.lineHeight());
  4219.     } else {
  4220.       this.setCursorRect(0, 0, 0, 0);
  4221.     }
  4222. };

  4223. Window_EnemyVisualSelect.prototype.isShowCursor = function() {
  4224.     if (!this._showSelectCursor) return false;
  4225.     var scene = SceneManager._scene;
  4226.     if (!scene._enemyWindow) return false;
  4227.     var enemyWindow = scene._enemyWindow;
  4228.     if (!enemyWindow.active) return false;
  4229.     if (!this._battler.isAppeared()) return false;
  4230.     return this._battler.isSelected();
  4231. };

  4232. Window_EnemyVisualSelect.prototype.updateRefresh = function() {
  4233.     if (this._requestRefresh) this.refresh();
  4234. };

  4235. Window_EnemyVisualSelect.prototype.refresh = function() {
  4236.     this.contents.clear();
  4237.     if (!this._battler) return;
  4238.     if (!this._showEnemyName) return;
  4239.     if (this._battler.isHidden()) return;
  4240.     this._requestRefresh = false;
  4241.     this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
  4242.     var text = this._battler.name();
  4243.     var wy = this.contents.height - this.lineHeight();
  4244.     this.drawText(text, 0, wy, this.contents.width, 'center');
  4245. };

  4246. //=============================================================================
  4247. // Window_PartyCommand
  4248. //=============================================================================

  4249. Window_PartyCommand.prototype.itemTextAlign = function() {
  4250.     return Yanfly.Param.BECCommandAlign;
  4251. };

  4252. Window_PartyCommand.prototype.numVisibleRows = function() {
  4253.     return eval(Yanfly.Param.BECCommandRows);
  4254. };

  4255. //=============================================================================
  4256. // Window_ActorCommand
  4257. //=============================================================================

  4258. Window_ActorCommand.prototype.itemTextAlign = function() {
  4259.     return Yanfly.Param.BECCommandAlign;
  4260. };

  4261. Window_ActorCommand.prototype.numVisibleRows = function() {
  4262.     return eval(Yanfly.Param.BECCommandRows);
  4263. };

  4264. //=============================================================================
  4265. // Window_BattleStatus
  4266. //=============================================================================

  4267. Window_BattleStatus.prototype.numVisibleRows = function() {
  4268.     return eval(Yanfly.Param.BECCommandRows);
  4269. };

  4270. Window_BattleStatus.prototype.updateStatusRequests = function() {
  4271.     if (BattleManager._victoryPhase) return;
  4272.     for (var i = 0; i < $gameParty.battleMembers().length; ++i) {
  4273.       var actor = $gameParty.battleMembers()[i];
  4274.       if (!actor) continue;
  4275.       if (actor.isStatusRefreshRequested()) this.processStatusRefresh(i);
  4276.     }
  4277. };

  4278. Window_BattleStatus.prototype.processStatusRefresh = function(index) {
  4279.     var actor = $gameParty.battleMembers()[index];
  4280.     if (!actor) return;
  4281.     var rect = this.itemRect(index);
  4282.     this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
  4283.     this.drawItem(index);
  4284.     actor.completetStatusRefreshRequest();
  4285. };

  4286. if (!Yanfly.Param.BECCurMax) {

  4287. Window_BattleStatus.prototype.drawCurrentAndMax = function(current, max, x, y,
  4288.                                                    width, color1, color2) {
  4289.     var labelWidth = this.textWidth('HP');
  4290.     var valueWidth = this.textWidth(Yanfly.Util.toGroup(max));
  4291.     var slashWidth = this.textWidth('/');
  4292.     var x1 = x + width - valueWidth;
  4293.     this.changeTextColor(color1);
  4294.     this.drawText(Yanfly.Util.toGroup(current), x1, y, valueWidth, 'right');
  4295. };

  4296. }; // Yanfly.Param.BECCurMax

  4297. //=============================================================================
  4298. // Window_BattleLog
  4299. //=============================================================================

  4300. Yanfly.BEC.Window_BattleLog_isFastForward =
  4301.     Window_BattleLog.prototype.isFastForward;
  4302. Window_BattleLog.prototype.isFastForward = function() {
  4303.     if (eval(Yanfly.Param.BECOptSpeed)) return true;
  4304.     return Yanfly.BEC.Window_BattleLog_isFastForward.call(this);
  4305. };

  4306. Window_BattleLog.prototype.updateWaitCount = function() {
  4307.     if (this._waitCount > 0) {
  4308.         this._waitCount -= 1;
  4309.         if (this._waitCount < 0) {
  4310.             this._waitCount = 0;
  4311.         }
  4312.         return true;
  4313.     }
  4314.     return false;
  4315. };

  4316. Window_BattleLog.prototype.animationBaseDelay = function() {
  4317.     return eval(Yanfly.Param.BECAniBaseDel);
  4318. };

  4319. Window_BattleLog.prototype.animationNextDelay = function() {
  4320.     return eval(Yanfly.Param.BECAniNextDel);
  4321. };

  4322. Window_BattleLog.prototype.updateWaitMode = function() {
  4323.     var waiting = false;
  4324.     switch (this._waitMode) {
  4325.     case 'effect':
  4326.         waiting = this._spriteset.isEffecting();
  4327.         break;
  4328.     case 'movement':
  4329.         waiting = this._spriteset.isAnyoneMoving();
  4330.         break;
  4331.     case 'animation':
  4332.         waiting = this._spriteset.isAnimationPlaying();
  4333.         break;
  4334.     case 'popups':
  4335.         waiting = this._spriteset.isPopupPlaying();
  4336.         break;
  4337.     }
  4338.     if (!waiting) {
  4339.         this._waitMode = '';
  4340.     }
  4341.     return waiting;
  4342. };

  4343. Window_BattleLog.prototype.startAction = function(subject, action, targets) {
  4344. };

  4345. Window_BattleLog.prototype.endAction = function(subject) {
  4346. };

  4347. Window_BattleLog.prototype.waitForAnimation = function() {
  4348.     this.setWaitMode('animation');
  4349. };

  4350. Window_BattleLog.prototype.waitForEffect = function() {
  4351.     this.setWaitMode('effect');
  4352. };

  4353. Window_BattleLog.prototype.waitForPopups = function() {
  4354.     this.setWaitMode('popups');
  4355. };

  4356. Yanfly.BEC.Window_BattleLog_displayAction =
  4357.     Window_BattleLog.prototype.displayAction;
  4358. Window_BattleLog.prototype.displayAction = function(subject, item) {
  4359.     if (eval(Yanfly.Param.BECFullActText)) {
  4360.       Yanfly.BEC.Window_BattleLog_displayAction.call(this, subject, item);
  4361.     } else {
  4362.       this._actionIcon = this.displayIcon(item);
  4363.       var text = this.displayText(item);
  4364.       this.push('addText', '<SIMPLE>' + text);
  4365.       if (item.message2) {
  4366.         this.push('addText', '<CENTER>' + item.message2.format(text));
  4367.       }
  4368.     }
  4369. };

  4370. Window_BattleLog.prototype.displayIcon = function(item) {
  4371.     return item.battleDisplayIcon;
  4372. };

  4373. Window_BattleLog.prototype.displayText = function(item) {
  4374.     return item.battleDisplayText;
  4375. };

  4376. Yanfly.BEC.Window_BattleLog_displayActionResults =
  4377.     Window_BattleLog.prototype.displayActionResults;
  4378. Window_BattleLog.prototype.displayActionResults = function(subject, target) {
  4379.     if (eval(Yanfly.Param.BECOptSpeed)) {
  4380.       if (target.result().used) {
  4381.           this.displayCritical(target);
  4382.           this.displayDamage(target);
  4383.           this.displayAffectedStatus(target);
  4384.           this.displayFailure(target);
  4385.       }
  4386.     } else {
  4387.       Yanfly.BEC.Window_BattleLog_displayActionResults.call(this, subject,
  4388.           target);
  4389.     }
  4390.     if (target.isDead()) target.performCollapse();
  4391. };

  4392. Yanfly.BEC.Window_BattleLog_drawLineText =
  4393.     Window_BattleLog.prototype.drawLineText;
  4394. Window_BattleLog.prototype.drawLineText = function(index) {
  4395.     if (this._lines[index].match('<CENTER>')) {
  4396.       this.drawCenterLine(index);
  4397.     } else if (this._lines[index].match('<SIMPLE>')) {
  4398.       this.drawSimpleActionLine(index);
  4399.     } else {
  4400.       Yanfly.BEC.Window_BattleLog_drawLineText.call(this, index);
  4401.     }
  4402. };

  4403. Window_BattleLog.prototype.textWidthEx = function(text) {
  4404.     return this.drawTextEx(text, 0, this.contents.height);
  4405. };

  4406. Window_BattleLog.prototype.drawCenterLine = function(index) {
  4407.     var text = this._lines[index].replace('<CENTER>', '');
  4408.     var rect = this.itemRectForText(index);
  4409.     this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
  4410.     var tw = this.textWidthEx(text);
  4411.     var wx = rect.x + (rect.width - tw) / 2;
  4412.     this.drawTextEx(text, wx, rect.y);
  4413. };

  4414. Window_BattleLog.prototype.drawSimpleActionLine = function(index) {
  4415.     var text = this._lines[index].replace('<SIMPLE>', '');
  4416.     var rect = this.itemRectForText(index);
  4417.     this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
  4418.     if (this._actionIcon) {
  4419.       var tw = this.textWidth(text);
  4420.       var ix = (rect.width - tw) / 2 - 4;
  4421.       this.drawIcon(this._actionIcon, ix, rect.y + 2);
  4422.     }
  4423.     this.drawText(text, rect.x, rect.y, Graphics.boxWidth, 'center');
  4424. };

  4425. Window_BattleLog.prototype.displayCounter = function(target) {
  4426.     if (eval(Yanfly.Param.BECShowCntText)) {
  4427.       this.addText(TextManager.counterAttack.format(target.name()));
  4428.     }
  4429.     target.performCounter();
  4430.     this.showAttackAnimation(target, [BattleManager._subject]);
  4431.     this.waitForAnimation();
  4432. };

  4433. Window_BattleLog.prototype.displayReflection = function(target) {
  4434.     if (eval(Yanfly.Param.BECShowRflText)) {
  4435.       this.addText(TextManager.magicReflection.format(target.name()));
  4436.     }
  4437.     target.performReflection();
  4438.     var animationId = BattleManager._action.item().animationId;
  4439.     this.showNormalAnimation([BattleManager._subject], animationId);
  4440.     this.waitForAnimation();
  4441. };

  4442. Window_BattleLog.prototype.displaySubstitute = function(substitute, target) {
  4443.     if (eval(Yanfly.Param.BECShowSubText)) {
  4444.       var substName = substitute.name();
  4445.       this.addText(TextManager.substitute.format(substName, target.name()));
  4446.     }
  4447.     substitute.performSubstitute(target);
  4448. };

  4449. Yanfly.BEC.Window_BattleLog_displayFailure =
  4450.     Window_BattleLog.prototype.displayFailure;
  4451. Window_BattleLog.prototype.displayFailure = function(target) {
  4452.     if (!eval(Yanfly.Param.BECShowFailText)) return;
  4453.     Yanfly.BEC.Window_BattleLog_displayFailure.call(this, target);
  4454. };

  4455. Yanfly.BEC.Window_BattleLog_displayCritical =
  4456.     Window_BattleLog.prototype.displayCritical;
  4457. Window_BattleLog.prototype.displayCritical = function(target) {
  4458.     if (!eval(Yanfly.Param.BECShowCritText)) return;
  4459.     Yanfly.BEC.Window_BattleLog_displayCritical.call(this, target);
  4460. };

  4461. Yanfly.BEC.Window_BattleLog_displayMiss =
  4462.     Window_BattleLog.prototype.displayMiss;
  4463. Window_BattleLog.prototype.displayMiss = function(target) {
  4464.     if (!eval(Yanfly.Param.BECShowMissText)) return;
  4465.     Yanfly.BEC.Window_BattleLog_displayMiss.call(this, target);
  4466. };

  4467. Yanfly.BEC.Window_BattleLog_displayEvasion =
  4468.     Window_BattleLog.prototype.displayEvasion;
  4469. Window_BattleLog.prototype.displayEvasion = function(target) {
  4470.     if (!eval(Yanfly.Param.BECShowEvaText)) return;
  4471.     Yanfly.BEC.Window_BattleLog_displayEvasion.call(this, target);
  4472. };

  4473. Yanfly.BEC.Window_BattleLog_displayHpDamage =
  4474.     Window_BattleLog.prototype.displayHpDamage;
  4475. Window_BattleLog.prototype.displayHpDamage = function(target) {
  4476.     if (!eval(Yanfly.Param.BECShowHpText)) return;
  4477.     Yanfly.BEC.Window_BattleLog_displayHpDamage.call(this, target);
  4478. };

  4479. Yanfly.BEC.Window_BattleLog_displayMpDamage =
  4480.     Window_BattleLog.prototype.displayMpDamage;
  4481. Window_BattleLog.prototype.displayMpDamage = function(target) {
  4482.     if (!eval(Yanfly.Param.BECShowMpText)) return;
  4483.     Yanfly.BEC.Window_BattleLog_displayMpDamage.call(this, target);
  4484. };

  4485. Yanfly.BEC.Window_BattleLog_displayTpDamage =
  4486.     Window_BattleLog.prototype.displayTpDamage;
  4487. Window_BattleLog.prototype.displayTpDamage = function(target) {
  4488.     if (!eval(Yanfly.Param.BECShowTpText)) return;
  4489.     Yanfly.BEC.Window_BattleLog_displayTpDamage.call(this, target);
  4490. };

  4491. Yanfly.BEC.Window_BattleLog_displayCurrentState =
  4492.     Window_BattleLog.prototype.displayCurrentState;
  4493. Window_BattleLog.prototype.displayCurrentState = function(subject) {
  4494.     if (!eval(Yanfly.Param.BECShowStateText)) return;
  4495.     Yanfly.BEC.Window_BattleLog_displayCurrentState.call(this, subject);
  4496. };

  4497. Yanfly.BEC.Window_BattleLog_displayAddedStates =
  4498.     Window_BattleLog.prototype.displayAddedStates;
  4499. Window_BattleLog.prototype.displayAddedStates = function(target) {
  4500.     if (!eval(Yanfly.Param.BECShowStateText)) return;
  4501.     Yanfly.BEC.Window_BattleLog_displayAddedStates.call(this, target);
  4502. };

  4503. Yanfly.BEC.Window_BattleLog_displayRemovedStates =
  4504.     Window_BattleLog.prototype.displayRemovedStates;
  4505. Window_BattleLog.prototype.displayRemovedStates = function(target) {
  4506.     if (!eval(Yanfly.Param.BECShowStateText)) return;
  4507.     Yanfly.BEC.Window_BattleLog_displayRemovedStates.call(this, target);
  4508. };

  4509. Yanfly.BEC.Window_BattleLog_displayChangedBuffs =
  4510.     Window_BattleLog.prototype.displayChangedBuffs;
  4511. Window_BattleLog.prototype.displayChangedBuffs = function(target) {
  4512.     if (!eval(Yanfly.Param.BECShowBuffText)) return;
  4513.     Yanfly.BEC.Window_BattleLog_displayChangedBuffs.call(this, target);
  4514. };

  4515. Window_BattleLog.prototype.popupDamage = function(target) {
  4516. };

  4517. Yanfly.BEC.Window_BattleLog_showEnemyAttackAnimation =
  4518.     Window_BattleLog.prototype.showEnemyAttackAnimation;
  4519. Window_BattleLog.prototype.showEnemyAttackAnimation =
  4520. function(subject, targets) {
  4521.     if ($gameSystem.isSideView()) {
  4522.       this.showNormalAnimation(targets, subject.attackAnimationId(), false);
  4523.     } else {
  4524.       this.showNormalAnimation(targets, subject.attackAnimationId(), false);
  4525.       Yanfly.BEC.Window_BattleLog_showEnemyAttackAnimation.call(this, subject,
  4526.           targets);
  4527.     }
  4528. };

  4529. Window_BattleLog.prototype.showActorAtkAniMirror = function(subject, targets) {
  4530.     this.showNormalAnimation(targets, subject.attackAnimationId1(), true);
  4531.     this.showNormalAnimation(targets, subject.attackAnimationId2(), false);
  4532. };

  4533. //=============================================================================
  4534. // New Function
  4535. //=============================================================================

  4536. Yanfly.Util = Yanfly.Util || {};

  4537. if (!Yanfly.Util.toGroup) {
  4538.     Yanfly.Util.toGroup = function(inVal) {
  4539.         return inVal;
  4540.     }
  4541. };

  4542. Yanfly.Util.getRange = function(n, m) {
  4543.     var result = [];
  4544.     for (var i = n; i <= m; ++i) result.push(i);
  4545.     return result;
  4546. };

  4547. Yanfly.Util.onlyUnique = function(value, index, self) {
  4548.     return self.indexOf(value) === index;
  4549. };

  4550. //=============================================================================
  4551. // End of File
  4552. //=============================================================================
复制代码
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部