Advertisement
Guest User

Untitled

a guest
Dec 17th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 229.36 KB | None | 0 0
  1. /*
  2. #=============================================================================
  3. # Lecode's Tactical Battle System
  4. # LeTBS.js
  5. # By Lecode
  6. # Version 0.6
  7. #-----------------------------------------------------------------------------
  8. # TERMS OF USE
  9. #-----------------------------------------------------------------------------
  10. # This plugin and all its add-ons made by Lecode is under the MIT License.
  11. # (http://choosealicense.com/licenses/mit/)
  12. # In addition, you should keep this header.
  13. #-----------------------------------------------------------------------------
  14. # Version History
  15. #-----------------------------------------------------------------------------
  16. # - 0.0 : Beta started.
  17. # - 0.1 : Battles start and end correctly.
  18. # Troop events are correctly triggered in battle. (mostly)
  19. # Added an end window which appears when pressing ESC on the command window.
  20. # That window allows you to escape and change options.
  21. # Added the tags and parameters for one time move only and one time offense only.
  22. # Fixed some errors in the demo.
  23. # - 0.2 : The Item command is functional.
  24. # Added custom move scopes and options.
  25. # Downgraded the turn order visual for now to fix some bugs.
  26. # Added a new option for turn order: "fair repartition".
  27. # Status window is updated when a target is selected.
  28. # There's now a help window. Status window is shifted if needed.
  29. # - 0.3 : The mouse is supported.
  30. # Prototype of the projectiles system.
  31. # Prototype of the AI.
  32. # Fixed a bug and improved the Turn Order Visual Version A.
  33. # 85% of the tile effects and marks system.
  34. # Fixed a bug with the line of sight.
  35. # - 0.4 : Now there is ony one unique tag.
  36. # Support custom sprites. (Yay !)
  37. # AI improved.
  38. # Added AI patterns. They can be used in AI commands.
  39. # Now each entity has his own sequence system. This allows simultaneous sequences.
  40. # Added some sequence commands.
  41. # Now a sequence is played for the following events:
  42. # battle start, turn start, victory, death, damaged, healed, buffed, weakened.
  43. # - 0.5 : Projectile system completed
  44. # Tile, Mark & Aura effects completed
  45. # Fixed and added some sequence commands
  46. # Fixed some bugs
  47. # Created DamagePopupEX
  48. # - 0.6 : Added these sequence commands: call_for_every_cell, call_for_every_entity
  49. # Added these sequence commands: save_cells, save_entities
  50. # Support directional scope
  51. # Fixed a bug where custom scopes ignore line of sight
  52. #=============================================================================
  53. */
  54. var Imported = Imported || {};
  55. Imported["LeTBS"] = true;
  56.  
  57. var Lecode = Lecode || {};
  58. Lecode.S_TBS = {};
  59. /*:
  60. * @plugindesc A tactical battle system with awesome features
  61. * @author Lecode
  62. * @version 0.5
  63. *
  64. * @param Ally Color Cell
  65. * @desc Color of actor cells.
  66. * @default #0FC50B
  67. *
  68. * @param Enemy Color Cell
  69. * @desc Color of enemy cells.
  70. * @default #C50B1B
  71. *
  72. * @param Cell Opacity Color
  73. * @desc Opacity of the placement cells.
  74. * @default 175
  75. *
  76. * @param Placed Animation
  77. * @desc Animation ID when a battler is placed.
  78. * @default 124
  79. *
  80. * @param -- Misc --
  81. * @desc ...
  82. * @default
  83. *
  84. * @param Exploration Input
  85. * @desc Input to trigger exploration.
  86. * @default shift
  87. *
  88. * @param Opacity Input
  89. * @desc Input to change windows' opacity.
  90. * @default control
  91. *
  92. * @param Min Input Opacity
  93. * @desc Minimum opacity of windows.
  94. * @default 0
  95. *
  96. * @param Opacity Steps
  97. * @desc Value of opacity to reduce when inputed.
  98. * @default 10
  99. *
  100. * @param Battle Start Sprite Delay
  101. * @desc Duration of the battle start sprite.
  102. * @default 50
  103. *
  104. * @param Turn Order Fair Repartition ?
  105. * @desc Allow a fair repartition of the turn order ?
  106. * @default true
  107. *
  108. * @param Destination Duration
  109. * @desc Duration of the destination sprite (when a cell is selected).
  110. * @default 60
  111. *
  112. * @param -- Scopes --
  113. * @desc ...
  114. * @default
  115. *
  116. * @param Scope Cell Width
  117. * @desc Width of cells.
  118. * @default 46
  119. *
  120. * @param Scope Cell Height
  121. * @desc Height of cells.
  122. * @default 46
  123. *
  124. * @param Obstacle Region Id
  125. * @desc Region ID for obstacles.
  126. * @default 250
  127. *
  128. * @param -- Move Action --
  129. * @desc ...
  130. * @default
  131. *
  132. * @param Default Move Scope
  133. * @desc Default move scope data.
  134. * @default circle(_mp_)
  135. *
  136. * @param Default Move Points
  137. * @desc Default amount of move points.
  138. * @default 3
  139. *
  140. * @param Move Scope Color
  141. * @desc Color of the move scope.
  142. * @default #0A5C85
  143. *
  144. * @param Move Scope Opacity
  145. * @desc Opacity of the move scope.
  146. * @default 175
  147. *
  148. * @param Invalid Move Scope Opacity
  149. * @desc Opacity of the move scope when cells are invalid.
  150. * @default 60
  151. *
  152. * @param Selected Move Scope Opacity
  153. * @desc Opacity of the move scope when cells are selected.
  154. * @default 255
  155. *
  156. * @param Enable Directional Facing
  157. * @desc Battlers will be allowed to change their direction.
  158. * @default true
  159. *
  160. * @param -- Attack Action --
  161. * @desc ...
  162. * @default
  163. *
  164. * @param Default Attack Animation
  165. * @desc Default attack animation.
  166. * @default 1
  167. *
  168. * @param Default Attack Sequence
  169. * @desc Default attack sequence.
  170. * @default atk
  171. *
  172. * @param Default Attack Scope
  173. * @desc Default attack scope data.
  174. * @default circle(1)
  175. *
  176. * @param Default Attack Ao E
  177. * @desc Default attack aoe data.
  178. * @default circle(0)
  179. *
  180. * @param Attack Scope Color
  181. * @desc Color of the attack scope.
  182. * @default #DF3A01
  183. *
  184. * @param Attack Scope Opacity
  185. * @desc Opacity of the attack scope.
  186. * @default 175
  187. *
  188. * @param Invalid Attack Scope Opacity
  189. * @desc Opacity of the attack scope when cells are invalid.
  190. * @default 60
  191. *
  192. * @param Selected Attack Scope Opacity
  193. * @desc Opacity of the attack scope when cells are selected.
  194. * @default 255
  195. *
  196. * @param -- Skill Action --
  197. * @desc ...
  198. * @default
  199. *
  200. * @param Default Skill Sequence
  201. * @desc Default skill sequence.
  202. * @default skill
  203. *
  204. * @param Default Skill Scope
  205. * @desc Default skill scope data.
  206. * @default circle(3)
  207. *
  208. * @param Default Skill Ao E
  209. * @desc Default skill aoe data.
  210. * @default circle(0)
  211. *
  212. * @param Skill Scope Color
  213. * @desc Color of the skill scope.
  214. * @default #DF3A01
  215. *
  216. * @param Skill Scope Opacity
  217. * @desc Opacity of the skill scope.
  218. * @default 175
  219. *
  220. * @param Invalid Skill Scope Opacity
  221. * @desc Opacity of the skill scope when cells are invalid.
  222. * @default 60
  223. *
  224. * @param Selected Skill Scope Opacity
  225. * @desc Opacity of the skill scope when cells are selected.
  226. * @default 255
  227. *
  228. * @param -- Item Action --
  229. * @desc ...
  230. * @default
  231. *
  232. * @param Default Item Sequence
  233. * @desc Default item sequence.
  234. * @default item
  235. *
  236. * @param Default Item Scope
  237. * @desc Default item scope data.
  238. * @default circle(3)
  239. *
  240. * @param Default Item Ao E
  241. * @desc Default item aoe data.
  242. * @default circle(0)
  243. *
  244. * @param Item Scope Color
  245. * @desc Color of the item scope.
  246. * @default #DF01D7
  247. *
  248. * @param Item Scope Opacity
  249. * @desc Opacity of the item scope.
  250. * @default 175
  251. *
  252. * @param Invalid Item Scope Opacity
  253. * @desc Opacity of the item scope when cells are invalid.
  254. * @default 60
  255. *
  256. * @param Selected Item Scope Opacity
  257. * @desc Opacity of the item scope when cells are selected.
  258. * @default 255
  259. *
  260. * @param -- Directional Damage --
  261. * @desc ...
  262. * @default
  263. *
  264. * @param Back Directional Damage Effects
  265. * @desc Damage % when a battler is hit on the back.
  266. * @default 15
  267. *
  268. * @param Side Directional Damage Effects
  269. * @desc Damage % when a battler is hit on the sides.
  270. * @default 0
  271. *
  272. * @param Face Directional Damage Effects
  273. * @desc Damage % when a battler is hit on the face.
  274. * @default -10
  275. *
  276. * @param -- Collision Damage --
  277. * @desc ...
  278. * @default
  279. *
  280. * @param Default Collision Formula
  281. * @desc Formula to evaluate collision damage.
  282. * @default b.mhp * 0.05 * (distance-covered)
  283. *
  284. * @param Collission Damage Chain Rate
  285. * @desc Collision damage chain rate.
  286. * @default 0.3
  287. *
  288. * @param -- Motions --
  289. * @desc ...
  290. * @default
  291. *
  292. * @param Battlers Move Speed
  293. * @desc Default move speed.
  294. * @default 4
  295. *
  296. * @param Battlers Frame Delay
  297. * @desc Default delay value between sprites frames.
  298. * @default 10
  299. *
  300. * @param -- AI --
  301. * @desc ...
  302. * @default
  303. *
  304. * @param Default Ai Pattern
  305. * @desc Default AI pattern.
  306. * @default melee_fighter
  307. *
  308. * @param Ai Wait Time
  309. * @desc AI wait time.
  310. * @default 5
  311. *
  312. * @param -- Actions Restrictions --
  313. * @desc ...
  314. * @default
  315. *
  316. * @param One Time Move
  317. * @desc Enable the one time move feature. (See doc)
  318. * @default false
  319. *
  320. * @param One Time Offense
  321. * @desc Enable the one time offense feature. (See doc)
  322. * @default true
  323. *
  324. * @param Auto Pass
  325. * @desc Enable the auto pass feature. (See doc)
  326. * @default true
  327. *
  328. * @param -- Battle End --
  329. * @desc ...
  330. * @default
  331. *
  332. * @param Escape Sound
  333. * @desc Sound when the party try to escape.
  334. * @default Buzzer2
  335. *
  336. * @param End Of Battle Wait
  337. * @desc Wait amount before the end of the battle.
  338. * @default 60
  339. *
  340. * @param Collapse Animation
  341. * @desc Default collapse animation.
  342. * @default 136
  343. *
  344. * @help
  345. * See the documentation
  346. */
  347. //#=============================================================================
  348.  
  349.  
  350. /*-------------------------------------------------------------------------
  351. * Get Parameters
  352. -------------------------------------------------------------------------*/
  353. var parameters = PluginManager.parameters('LeTBS');
  354.  
  355. Lecode.S_TBS.allyColorCell = String(parameters["Ally Color Cell"] || "#0FC50B"); // (): Color of actor cells.
  356. Lecode.S_TBS.enemyColorCell = String(parameters["Enemy Color Cell"] || "#C50B1B"); // (): Color of enemy cells.
  357. Lecode.S_TBS.placementCellOpacity = Number(parameters["Cell Opacity Color"] || 175); // (Cell Opacity Color): Opacity of the placement cells.
  358. Lecode.S_TBS.placedBattlerAnim = Number(parameters["Placed Animation"] || 124); // (Placed Animation): Animation ID when a battler is placed.
  359. // Divider: -- Misc --
  360. Lecode.S_TBS.explorationInput = String(parameters["Exploration Input"] || "shift"); // (): Input to trigger exploration.
  361. Lecode.S_TBS.opacityInput = String(parameters["Opacity Input"] || "control"); // (): Input to change windows' opacity.
  362. Lecode.S_TBS.minInputOpacity = Number(parameters["Min Input Opacity"] || 0); // (): Minimum opacity of windows.
  363. Lecode.S_TBS.inputOpacityDecreaseSteps = Number(parameters["Opacity Steps"] || 10); // (Opacity Steps): Value of opacity to reduce when inputed.
  364. Lecode.S_TBS.battleStartSpriteDelay = Number(parameters["Battle Start Sprite Delay"] || 50); // (): Duration of the battle start sprite.
  365. Lecode.S_TBS.turnOrderFairRepartition = String(parameters["Turn Order Fair Repartition ?"] || 'true') === 'true'; // (Turn Order Fair Repartition ?): Allow a fair repartition of the turn order ?
  366. Lecode.S_TBS.destinationDuration = Number(parameters["Destination Duration"] || 60); // (): Duration of the destination sprite (when a cell is selected).
  367. // Divider: -- Scopes --
  368. Lecode.S_TBS.scopeCellWidth = Number(parameters["Scope Cell Width"] || 46); // (): Width of cells.
  369. Lecode.S_TBS.scopeCellHeight = Number(parameters["Scope Cell Height"] || 46); // (): Height of cells.
  370. Lecode.S_TBS.obstacleRegionId = Number(parameters["Obstacle Region Id"] || 250); // (): Region ID for obstacles.
  371. // Divider: -- Move Action --
  372. Lecode.S_TBS.defaultMoveScope = String(parameters["Default Move Scope"] || "circle(_mp_)"); // (): Default move scope data.
  373. Lecode.S_TBS.defaultMovePoints = Number(parameters["Default Move Points"] || 3); // (): Default amount of move points.
  374. Lecode.S_TBS.moveColorCell = String(parameters["Move Scope Color"] || "#0A5C85"); // (Move Scope Color): Color of the move scope.
  375. Lecode.S_TBS.moveCellOpacity = Number(parameters["Move Scope Opacity"] || 175); // (Move Scope Opacity): Opacity of the move scope.
  376. Lecode.S_TBS.moveInvalidCellOpacity = Number(parameters["Invalid Move Scope Opacity"] || 60); // (Invalid Move Scope Opacity): Opacity of the move scope when cells are invalid.
  377. Lecode.S_TBS.moveSelectedCellOpacity = Number(parameters["Selected Move Scope Opacity"] || 255); // (Selected Move Scope Opacity): Opacity of the move scope when cells are selected.
  378. Lecode.S_TBS.enableDirectionalFacing = String(parameters["Enable Directional Facing"] || 'true') === 'true'; // (): Battlers will be allowed to change their direction.
  379. // Divider: -- Attack Action --
  380. Lecode.S_TBS.defaultAttackAnimation = Number(parameters["Default Attack Animation"] || 1); // (): Default attack animation.
  381. Lecode.S_TBS.defaultAttackSequence = String(parameters["Default Attack Sequence"] || "atk"); // (): Default attack sequence.
  382. Lecode.S_TBS.defaultAttackScope = String(parameters["Default Attack Scope"] || "circle(1)"); // (): Default attack scope data.
  383. Lecode.S_TBS.defaultAttackAoE = String(parameters["Default Attack Ao E"] || "circle(0)"); // (): Default attack aoe data.
  384. Lecode.S_TBS.attackColorCell = String(parameters["Attack Scope Color"] || "#DF3A01"); // (Attack Scope Color): Color of the attack scope.
  385. Lecode.S_TBS.attackCellOpacity = Number(parameters["Attack Scope Opacity"] || 175); // (Attack Scope Opacity): Opacity of the attack scope.
  386. Lecode.S_TBS.attackInvalidCellOpacity = Number(parameters["Invalid Attack Scope Opacity"] || 60); // (Invalid Attack Scope Opacity): Opacity of the attack scope when cells are invalid.
  387. Lecode.S_TBS.attackSelectedCellOpacity = Number(parameters["Selected Attack Scope Opacity"] || 255); // (Selected Attack Scope Opacity): Opacity of the attack scope when cells are selected.
  388. // Divider: -- Skill Action --
  389. Lecode.S_TBS.defaultSkillSequence = String(parameters["Default Skill Sequence"] || "skill"); // (): Default skill sequence.
  390. Lecode.S_TBS.defaultSkillScope = String(parameters["Default Skill Scope"] || "circle(3)"); // (): Default skill scope data.
  391. Lecode.S_TBS.defaultSkillAoE = String(parameters["Default Skill Ao E"] || "circle(0)"); // (): Default skill aoe data.
  392. Lecode.S_TBS.skillColorCell = String(parameters["Skill Scope Color"] || "#DF3A01"); // (Skill Scope Color): Color of the skill scope.
  393. Lecode.S_TBS.skillCellOpacity = Number(parameters["Skill Scope Opacity"] || 175); // (Skill Scope Opacity): Opacity of the skill scope.
  394. Lecode.S_TBS.skillInvalidCellOpacity = Number(parameters["Invalid Skill Scope Opacity"] || 60); // (Invalid Skill Scope Opacity): Opacity of the skill scope when cells are invalid.
  395. Lecode.S_TBS.skillSelectedCellOpacity = Number(parameters["Selected Skill Scope Opacity"] || 255); // (Selected Skill Scope Opacity): Opacity of the skill scope when cells are selected.
  396. // Divider: -- Item Action --
  397. Lecode.S_TBS.defaultItemSequence = String(parameters["Default Item Sequence"] || "item"); // (): Default item sequence.
  398. Lecode.S_TBS.defaultItemScope = String(parameters["Default Item Scope"] || "circle(3)"); // (): Default item scope data.
  399. Lecode.S_TBS.defaultItemAoE = String(parameters["Default Item Ao E"] || "circle(0)"); // (): Default item aoe data.
  400. Lecode.S_TBS.ItemColorCell = String(parameters["Item Scope Color"] || "#DF01D7"); // (Item Scope Color): Color of the item scope.
  401. Lecode.S_TBS.ItemCellOpacity = Number(parameters["Item Scope Opacity"] || 175); // (Item Scope Opacity): Opacity of the item scope.
  402. Lecode.S_TBS.ItemInvalidCellOpacity = Number(parameters["Invalid Item Scope Opacity"] || 60); // (Invalid Item Scope Opacity): Opacity of the item scope when cells are invalid.
  403. Lecode.S_TBS.ItemSelectedCellOpacity = Number(parameters["Selected Item Scope Opacity"] || 255); // (Selected Item Scope Opacity): Opacity of the item scope when cells are selected.
  404. // Divider: -- Directional Damage --
  405. Lecode.S_TBS.backDirectionalDamageEffects = Number(parameters["Back Directional Damage Effects"] || 15); // (): Damage % when a battler is hit on the back.
  406. Lecode.S_TBS.sideDirectionalDamageEffects = Number(parameters["Side Directional Damage Effects"] || 0); // (): Damage % when a battler is hit on the sides.
  407. Lecode.S_TBS.faceDirectionalDamageEffects = Number(parameters["Face Directional Damage Effects"] || -10); // (): Damage % when a battler is hit on the face.
  408. // Divider: -- Collision Damage --
  409. Lecode.S_TBS.defaultCollisionFormula = String(parameters["Default Collision Formula"] || "b.mhp * 0.05 * (distance-covered)"); // (): Formula to evaluate collision damage.
  410. Lecode.S_TBS.collissionDamageChainRate = Number(parameters["Collission Damage Chain Rate"] || 0.3); // (): Collision damage chain rate.
  411. // Divider: -- Motions --
  412. Lecode.S_TBS.battlersMoveSpeed = Number(parameters["Battlers Move Speed"] || 4); // (): Default move speed.
  413. Lecode.S_TBS.battlersFrameDelay = Number(parameters["Battlers Frame Delay"] || 10); // (): Default delay value between sprites frames.
  414. // Divider: -- AI --
  415. Lecode.S_TBS.defaultAiPattern = String(parameters["Default Ai Pattern"] || "melee_fighter"); // (): Default AI pattern.
  416. Lecode.S_TBS.aiWaitTime = Number(parameters["Ai Wait Time"] || 5); // (): AI wait time.
  417. // Divider: -- Actions Restrictions --
  418. Lecode.S_TBS.oneTimeMove = String(parameters["One Time Move"] || 'false') === 'true'; // (): Enable the one time move feature. (See doc)
  419. Lecode.S_TBS.oneTimeOffense = String(parameters["One Time Offense"] || 'true') === 'true'; // (): Enable the one time offense feature. (See doc)
  420. Lecode.S_TBS.autoPass = String(parameters["Auto Pass"] || 'true') === 'true'; // (): Enable the auto pass feature. (See doc)
  421. // Divider: -- Battle End --
  422. Lecode.S_TBS.escapeSound = String(parameters["Escape Sound"] || "Buzzer2"); // (): Sound when the party try to escape.
  423. Lecode.S_TBS.endOfBattleWait = Number(parameters["End Of Battle Wait"] || 60); // (): Wait amount before the end of the battle.
  424. Lecode.S_TBS.collapseAnimation = Number(parameters["Collapse Animation"] || 136); // (): Default collapse animation.
  425.  
  426.  
  427. Lecode.S_TBS.drawLimits = false;
  428.  
  429. /*-------------------------------------------------------------------------
  430. * Spriteset_BattleTBS
  431. -------------------------------------------------------------------------*/
  432. function Spriteset_BattleTBS() {
  433. this.initialize.apply(this, arguments);
  434. }
  435.  
  436. Spriteset_BattleTBS.prototype = Object.create(Spriteset_Map.prototype);
  437. Spriteset_BattleTBS.prototype.constructor = Spriteset_BattleTBS;
  438.  
  439. Spriteset_BattleTBS.prototype.initialize = function () {
  440. Spriteset_Map.prototype.initialize.call(this);
  441. this.createBattleLayers();
  442. };
  443.  
  444. Spriteset_BattleTBS.prototype.createCharacters = function () {
  445. this._characterSprites = [];
  446. $gameMap.events().forEach(function (event) {
  447. if (event.event().note.match(/tbs_event/i))
  448. this._characterSprites.push(new Sprite_Character(event));
  449. }, this);
  450.  
  451. for (var i = 0; i < this._characterSprites.length; i++) {
  452. this._tilemap.addChild(this._characterSprites[i]);
  453. }
  454. };
  455.  
  456. Spriteset_BattleTBS.prototype.createBattleLayers = function () {
  457. //-Ground entities
  458. this._groundEntitiesLayer = new Sprite();
  459. this._groundEntitiesLayer.z = 0;
  460. this._tilemap.addChild(this._groundEntitiesLayer);
  461. //-Scopes
  462. this._scopesLayer = new TBSScopeLayer();
  463. this._scopesLayer.z = 2;
  464. this._tilemap.addChild(this._scopesLayer);
  465. this._scopesLayer.createSelectionLayer();
  466. //-Ground
  467. this._groundLayer = new Sprite();
  468. this._groundLayer.z = 2;
  469. this._tilemap.addChild(this._groundLayer);
  470. //-Battlers
  471. this._battlersLayer = new Sprite();
  472. this._battlersLayer.z = 2;
  473. this._tilemap.addChild(this._battlersLayer);
  474. //-Animations
  475. this._animationsLayer = new TBSMapAnimation();
  476. this._animationsLayer.z = 4;
  477. this._tilemap.addChild(this._animationsLayer);
  478. //-Movable Infos
  479. this._movableInfoLayer = new Sprite();
  480. this._movableInfoLayer.z = 6;
  481. this._tilemap.addChild(this._movableInfoLayer);
  482. //-Fixed Infos
  483. this._fixedInfoLayer = new Sprite();
  484. this._fixedInfoLayer.z = 6;
  485. this._tilemap.addChild(this._fixedInfoLayer);
  486. //-Debug
  487. var bitmap = new Bitmap(Graphics.width, Graphics.height);
  488. this._debugLayer = new Sprite(bitmap);
  489. this._debugLayer.z = 7;
  490. this._tilemap.addChild(this._debugLayer);
  491. };
  492.  
  493.  
  494. /*-------------------------------------------------------------------------
  495. * TBSScopeLayer
  496. -------------------------------------------------------------------------*/
  497. function TBSScopeLayer() {
  498. this.initialize.apply(this, arguments);
  499. }
  500. TBSScopeLayer.prototype = Object.create(Sprite.prototype);
  501. TBSScopeLayer.prototype.constructor = TBSScopeLayer;
  502.  
  503. TBSScopeLayer.prototype.initialize = function () {
  504. var w = $gameMap.width() * $gameMap.tileWidth();
  505. var h = $gameMap.height() * $gameMap.tileHeight();
  506. var bitmap = new Bitmap(w, h);
  507. Sprite.prototype.initialize.call(this, bitmap);
  508. this._selectionLayer = null;
  509. };
  510.  
  511. TBSScopeLayer.prototype.createSelectionLayer = function () {
  512. this._selectionLayer = new TBSScopeLayer();
  513. this._selectionLayer.z = 2;
  514. this.parent.addChild(this._selectionLayer);
  515. };
  516.  
  517. TBSScopeLayer.prototype.update = function () {
  518. Sprite.prototype.update.call(this);
  519. if (this._selectionLayer) {
  520. this._selectionLayer.x = this.x;
  521. this._selectionLayer.y = this.y;
  522. }
  523. };
  524.  
  525. TBSScopeLayer.prototype.clear = function () {
  526. this.bitmap.clear();
  527. };
  528.  
  529. TBSScopeLayer.prototype.clearSelection = function () {
  530. this._selectionLayer.clear();
  531. };
  532.  
  533. TBSScopeLayer.prototype.drawCell = function (x, y, opacity, color) {
  534. var w = Lecode.S_TBS.scopeCellWidth;
  535. var h = Lecode.S_TBS.scopeCellHeight;
  536. var sx = $gameMap.tileWidth() - w;
  537. var sy = $gameMap.tileHeight() - h;
  538. w -= sx;
  539. h -= sy;
  540. sx += x * $gameMap.tileWidth();
  541. sy += y * $gameMap.tileHeight();
  542. this.bitmap.paintOpacity = opacity;
  543. this.bitmap.fillRect(sx, sy, w, h, color);
  544. };
  545.  
  546. TBSScopeLayer.prototype.drawSelectionCell = function (x, y, opacity, color) {
  547. this._selectionLayer.drawCell(x, y, opacity, color);
  548. };
  549.  
  550.  
  551. /*-------------------------------------------------------------------------
  552. * TBSMapAnimation
  553. -------------------------------------------------------------------------*/
  554. function TBSMapAnimation() {
  555. this.initialize.apply(this, arguments);
  556. }
  557.  
  558. TBSMapAnimation.prototype = Object.create(Sprite_Base.prototype);
  559. TBSMapAnimation.prototype.constructor = TBSMapAnimation;
  560.  
  561. TBSMapAnimation.prototype.initialize = function (battler) {
  562. Sprite_Base.prototype.initialize.call(this);
  563. this._cell = null;
  564. this._target = null;
  565. };
  566.  
  567. TBSMapAnimation.prototype.update = function () {
  568. Sprite_Base.prototype.update.call(this);
  569. };
  570.  
  571. TBSMapAnimation.prototype.newAnimation = function (id, mirror, delay, cell, target) {
  572. this._cell = cell;
  573. this._target = target;
  574. this.startAnimation($dataAnimations[id], mirror, delay);
  575. };
  576.  
  577. TBSMapAnimation.prototype.startAnimation = function (animation, mirror, delay) {
  578. var sprite = new Sprite_TBSAnimation();
  579. sprite.setup(this._target || this._effectTarget, animation, mirror, delay, this._cell);
  580. this.addChild(sprite);
  581. this._animationSprites.push(sprite);
  582. };
  583.  
  584.  
  585. /*-------------------------------------------------------------------------
  586. * Sprite_TBSAnimation
  587. -------------------------------------------------------------------------*/
  588. function Sprite_TBSAnimation() {
  589. this.initialize.apply(this, arguments);
  590. }
  591.  
  592. Sprite_TBSAnimation.prototype = Object.create(Sprite_Animation.prototype);
  593. Sprite_TBSAnimation.prototype.constructor = Sprite_TBSAnimation;
  594.  
  595. Sprite_TBSAnimation.prototype.initialize = function (battler) {
  596. Sprite_Animation.prototype.initialize.call(this);
  597. this._cell = null;
  598. };
  599.  
  600. Sprite_TBSAnimation.prototype.update = function () {
  601. Sprite_Animation.prototype.update.call(this);
  602. };
  603.  
  604. Sprite_TBSAnimation.prototype.setup = function (target, animation, mirror, delay, cell) {
  605. this._cell = cell;
  606. this._target = target;
  607. this._animation = animation;
  608. this._mirror = mirror;
  609. this._delay = delay;
  610. if (this._animation) {
  611. this.remove();
  612. this.setupRate();
  613. this.setupDuration();
  614. this.loadBitmaps();
  615. this.createSprites();
  616. }
  617. };
  618.  
  619. Sprite_TBSAnimation.prototype.updatePosition = function () {
  620. if (this._animation.position === 3) {
  621. this.x = this.parent.width / 2;
  622. this.y = this.parent.height / 2;
  623. } else {
  624. var w = $gameMap.tileWidth();
  625. var h = $gameMap.tileHeight();
  626. this.x = this._cell.x * $gameMap.tileWidth() + w / 2;
  627. this.y = this._cell.y * $gameMap.tileHeight() + h / 2;
  628. if (this._animation.position === 2)
  629. this.y += h / 2;
  630. else if (this._animation.position === 0)
  631. this.y -= h / 2;
  632.  
  633. }
  634. };
  635.  
  636.  
  637. /*-------------------------------------------------------------------------
  638. * Scene_Battle
  639. -------------------------------------------------------------------------*/
  640. Lecode.S_TBS.oldSB_create = Scene_Battle.prototype.create;
  641. Scene_Battle.prototype.create = function () {
  642. if (Lecode.S_TBS.commandOn) {
  643. Scene_Base.prototype.create.call(this);
  644. this.createDisplayObjects();
  645. } else {
  646. Lecode.S_TBS.oldSB_create.call(this);
  647. }
  648. };
  649.  
  650. Lecode.S_TBS.oldSB_createDisplayObjects = Scene_Battle.prototype.createDisplayObjects;
  651. Scene_Battle.prototype.createDisplayObjects = function () {
  652. if (Lecode.S_TBS.commandOn) {
  653. this.createSpriteset();
  654. this.createWindowLayer();
  655. this.createAllWindows();
  656. } else {
  657. Lecode.S_TBS.oldSB_createDisplayObjects.call(this);
  658. }
  659. };
  660.  
  661. Lecode.S_TBS.oldSB_start = Scene_Battle.prototype.start;
  662. Scene_Battle.prototype.start = function () {
  663. if (Lecode.S_TBS.commandOn) {
  664. Scene_Base.prototype.start.call(this);
  665. this.startFadeIn(this.fadeSpeed(), false);
  666.  
  667. BattleManager.playBattleBgm();
  668. BattleManagerTBS._spriteset = this._spriteset;
  669. InputHandlerTBS.setup();
  670.  
  671. InputHandlerTBS.addWindowBlockingTouch(this._windowConfirm);
  672. InputHandlerTBS.addWindowBlockingTouch(this._windowCommand);
  673. InputHandlerTBS.addWindowBlockingTouch(this._windowSkill);
  674. InputHandlerTBS.addWindowBlockingTouch(this._windowItem);
  675. InputHandlerTBS.addWindowBlockingTouch(this._windowStatus);
  676. InputHandlerTBS.addWindowBlockingTouch(this._helpWindow);
  677.  
  678. BattleManagerTBS.startBattle();
  679. } else {
  680. Lecode.S_TBS.oldSB_start.call(this);
  681. }
  682. };
  683.  
  684. Lecode.S_TBS.oldSB_update = Scene_Battle.prototype.update;
  685. Scene_Battle.prototype.update = function () {
  686. if (Lecode.S_TBS.commandOn) {
  687. $gameMap.update();
  688. $gameTimer.update(true);
  689. $gameScreen.update();
  690. InputHandlerTBS.update();
  691. BattleManagerTBS.update();
  692. Scene_Base.prototype.update.call(this);
  693. } else {
  694. Lecode.S_TBS.oldSB_update.call(this);
  695. }
  696. };
  697.  
  698. Lecode.S_TBS.oldSB_createSpriteset = Scene_Battle.prototype.createSpriteset;
  699. Scene_Battle.prototype.createSpriteset = function () {
  700. if (Lecode.S_TBS.commandOn) {
  701. this._spriteset = new Spriteset_BattleTBS();
  702. this.addChild(this._spriteset);
  703. } else {
  704. Lecode.S_TBS.oldSB_createSpriteset.call(this);
  705. }
  706. };
  707.  
  708. Lecode.S_TBS.oldSB_createAllWindows = Scene_Battle.prototype.createAllWindows;
  709. Scene_Battle.prototype.createAllWindows = function () {
  710. if (Lecode.S_TBS.commandOn) {
  711. //this.createLogWindow();
  712. this.createPlacementWindow();
  713. this.createConfirmationWindow();
  714. this.createStatusWindow();
  715. this.createCommandWindow();
  716. this.createHelpWindow();
  717. this.createSkillWindow();
  718. this.createItemWindow();
  719. this.createEndCommandWindow();
  720. this.createMessageWindow();
  721. } else {
  722. Lecode.S_TBS.oldSB_createAllWindows.call(this);
  723. }
  724. };
  725.  
  726. Scene_Battle.prototype.createPlacementWindow = function () {
  727. this._windowPlacement = new Window_TBSPlacementInfo();
  728. this._windowPlacement.hide();
  729. this._windowPlacement.deactivate();
  730. this.addWindow(this._windowPlacement);
  731. };
  732.  
  733. Scene_Battle.prototype.createConfirmationWindow = function () {
  734. this._windowConfirm = new Window_TBSConfirm();
  735. this._windowConfirm.setHandler('ok', this.onConfirmationOK.bind(this));
  736. this._windowConfirm.setHandler('cancel', this.onConfirmationCancel.bind(this));
  737. this._windowConfirm.hide();
  738. this._windowConfirm.deactivate();
  739. this.addWindow(this._windowConfirm);
  740. };
  741.  
  742. Lecode.S_TBS.oldSB_createStatusWindow = Scene_Battle.prototype.createStatusWindow;
  743. Scene_Battle.prototype.createStatusWindow = function () {
  744. if (Lecode.S_TBS.commandOn) {
  745. this._windowStatus = new Window_TBSStatus();
  746. this._windowStatus.hide();
  747. this.addWindow(this._windowStatus);
  748. } else {
  749. Lecode.S_TBS.oldSB_createStatusWindow.call(this);
  750. }
  751. };
  752.  
  753. Lecode.S_TBS.oldSB_createCommandWindow = Scene_Battle.prototype.createCommandWindow;
  754. Scene_Battle.prototype.createCommandWindow = function () {
  755. if (Lecode.S_TBS.commandOn) {
  756. this._windowCommand = new Window_TBSCommand();
  757. this._windowCommand.setHandler('move', this.onCommandInput.bind(this, "move"));
  758. this._windowCommand.setHandler('attack', this.onCommandInput.bind(this, "attack"));
  759. this._windowCommand.setHandler('skill', this.onCommandInput.bind(this, "skill"));
  760. this._windowCommand.setHandler('item', this.onCommandInput.bind(this, "item"));
  761. this._windowCommand.setHandler('pass', this.onCommandInput.bind(this, "pass"));
  762. this._windowCommand.setHandler('cancel', this.onCommandInput.bind(this, "cancel"));
  763. this._windowCommand.hide();
  764. this._windowCommand.deactivate();
  765. this.addWindow(this._windowCommand);
  766. } else {
  767. Lecode.S_TBS.oldSB_createCommandWindow.call(this);
  768. }
  769. };
  770.  
  771. Lecode.S_TBS.oldSB_createSkillWindow = Scene_Battle.prototype.createSkillWindow;
  772. Scene_Battle.prototype.createSkillWindow = function () {
  773. if (Lecode.S_TBS.commandOn) {
  774. this._windowSkill = new Window_TBSSkillList();
  775. this._windowSkill.setHandler('ok', this.onSkillInput.bind(this, "ok"));
  776. this._windowSkill.setHandler('cancel', this.onSkillInput.bind(this, "cancel"));
  777. this._windowSkill._helpWindow = this._helpWindow;
  778. this._windowSkill.hide();
  779. this._windowSkill.deactivate();
  780. this.addWindow(this._windowSkill);
  781. } else {
  782. Lecode.S_TBS.oldSB_createSkillWindow.call(this);
  783. }
  784. };
  785.  
  786. Lecode.S_TBS.oldSB_createItemWindow = Scene_Battle.prototype.createItemWindow;
  787. Scene_Battle.prototype.createItemWindow = function () {
  788. if (Lecode.S_TBS.commandOn) {
  789. this._windowItem = new Window_TBSItemList();
  790. this._windowItem.setHandler('ok', this.onItemInput.bind(this, "ok"));
  791. this._windowItem.setHandler('cancel', this.onItemInput.bind(this, "cancel"));
  792. this._windowItem._helpWindow = this._helpWindow;
  793. this._windowItem.hide();
  794. this._windowItem.deactivate();
  795. this.addWindow(this._windowItem);
  796. } else {
  797. Lecode.S_TBS.oldSB_createItemWindow.call(this);
  798. }
  799. };
  800.  
  801. Scene_Battle.prototype.createEndCommandWindow = function () {
  802. this._windowEndCommand = new Window_TBSEndCommand();
  803. this._windowEndCommand.setHandler('options', this.onEndCommandInput.bind(this, "options"));
  804. this._windowEndCommand.setHandler('escape', this.onEndCommandInput.bind(this, "escape"));
  805. this._windowEndCommand.setHandler('cancel', this.onEndCommandInput.bind(this, "cancel"));
  806. this._windowEndCommand.hide();
  807. this._windowEndCommand.deactivate();
  808. this.addWindow(this._windowEndCommand);
  809. };
  810.  
  811. Scene_Battle.prototype.showPlacementWindow = function (cell, battler) {
  812. this.placeWindowOverCell(this._windowPlacement, cell);
  813. this._windowPlacement.show();
  814. this._windowPlacement.open();
  815. this._windowPlacement._battler = battler;
  816. this._windowPlacement.refresh();
  817. };
  818.  
  819. Scene_Battle.prototype.showStatusWindow = function (battler) {
  820. //if (battler === this._windowStatus._battler) return;
  821. var window = this._windowStatus;
  822. this._windowStatus._battler = battler;
  823. this._windowStatus.show();
  824. this._windowStatus.open();
  825. this._windowStatus.refresh();
  826. };
  827.  
  828. Scene_Battle.prototype.showCommandWindow = function () {
  829. var entity = BattleManagerTBS.activeEntity();
  830. var cell = entity.getCell();
  831. var battler = BattleManagerTBS.activeBattler();
  832. this.placeWindowOverCell(this._windowCommand, cell);
  833. this._windowCommand.setup(battler, entity);
  834. };
  835.  
  836. Scene_Battle.prototype.showSkillWindow = function () {
  837. var entity = BattleManagerTBS.activeEntity();
  838. var cell = entity.getCell();
  839. var battler = BattleManagerTBS.activeBattler();
  840. this.placeWindowOverCell(this._windowSkill, cell);
  841. this._windowSkill.setActor(battler);
  842. this._windowSkill.show();
  843. this._windowSkill.open();
  844. this._windowSkill.refresh();
  845. this._windowSkill.activate();
  846. this.showHelpWindow();
  847. };
  848.  
  849. Scene_Battle.prototype.showItemWindow = function () {
  850. var entity = BattleManagerTBS.activeEntity();
  851. var cell = entity.getCell();
  852. var battler = BattleManagerTBS.activeBattler();
  853. this.placeWindowOverCell(this._windowItem, cell);
  854. this._windowItem.show();
  855. this._windowItem.open();
  856. this._windowItem.refresh();
  857. this._windowItem.activate();
  858. this.showHelpWindow();
  859. };
  860.  
  861. Scene_Battle.prototype.showHelpWindow = function () {
  862. var status = this._windowStatus;
  863. var help = this._helpWindow;
  864. help.x = 0;
  865. help.y = Graphics.height - help.height;
  866. while ((status.y + status.height) > help.y)
  867. status.y--;
  868. status.y++;
  869. help.visible = true;
  870. };
  871.  
  872. Scene_Battle.prototype.showEndCommandWindow = function () {
  873. this._windowEndCommand.show();
  874. this._windowEndCommand.open();
  875. this._windowEndCommand.activate();
  876. };
  877.  
  878. Scene_Battle.prototype.placeWindowOverCell = function (window, cell) {
  879. var x = $gameMap.adjustX(cell.x) * $gameMap.tileWidth();
  880. var y = $gameMap.adjustY(cell.y) * $gameMap.tileHeight();
  881. var w = window.width;
  882. var h = window.height;
  883.  
  884. x += $gameMap.tileWidth() / 2 - w / 2;
  885. while (x < 0) x++;
  886. while ((x + w) > Graphics.width) x--;
  887.  
  888. if (y <= h)
  889. y += $gameMap.tileHeight() / 2 + 10;
  890. else
  891. y -= h - 10;
  892.  
  893. window.move(x, y, w, h);
  894. window._leU_float = true;
  895. window._leU_floatData.ini_pos = [x, y];
  896. };
  897.  
  898. Scene_Battle.prototype.hidePlacementWindow = function (cell, battler) {
  899. this._windowPlacement.close();
  900. };
  901.  
  902. Scene_Battle.prototype.hideHelpWindow = function () {
  903. var status = this._windowStatus;
  904. var help = this._helpWindow;
  905. if ((status.y + status.height) == (help.y + 1))
  906. status.y += help.height;
  907. help.y += help.height;
  908. help.visible = false;
  909. };
  910.  
  911. Scene_Battle.prototype.showConfirmationWindow = function () {
  912. this._windowConfirm.show();
  913. this._windowConfirm.open();
  914. this._windowConfirm.activate();
  915. };
  916.  
  917. Scene_Battle.prototype.hideConfirmationWindow = function () {
  918. this._windowConfirm.close();
  919. this._windowConfirm.deactivate();
  920. };
  921.  
  922. Scene_Battle.prototype.onConfirmationOK = function () {
  923. if (this._windowConfirm.openness == 255);
  924. BattleManagerTBS.onConfirmationWindowOK();
  925. };
  926.  
  927. Scene_Battle.prototype.onConfirmationCancel = function () {
  928. if (this._windowConfirm.openness == 255);
  929. BattleManagerTBS.onConfirmationWindowCancel();
  930. };
  931.  
  932. Scene_Battle.prototype.onCommandInput = function (command) {
  933. this._windowCommand.close();
  934. this._windowCommand.deactivate();
  935. BattleManagerTBS.onCommandInput(command);
  936. };
  937.  
  938. Scene_Battle.prototype.onSkillInput = function (command) {
  939. this._windowSkill.close();
  940. this._windowSkill.deactivate();
  941. this.hideHelpWindow();
  942. BattleManagerTBS.onSkillInput(command);
  943. };
  944.  
  945. Scene_Battle.prototype.onItemInput = function (command) {
  946. this._windowItem.close();
  947. this._windowItem.deactivate();
  948. this.hideHelpWindow();
  949. BattleManagerTBS.onItemInput(command);
  950. };
  951.  
  952. Scene_Battle.prototype.onEndCommandInput = function (command) {
  953. this._windowEndCommand.close();
  954. this._windowEndCommand.deactivate();
  955. BattleManagerTBS.onEndCommandInput(command);
  956. };
  957.  
  958. Scene_Battle.prototype.getWindowsWChangeableOpa = function () {
  959. return [this._windowConfirm, this._windowPlacement, this._windowCommand, this._windowStatus,
  960. this._windowSkill, this._helpWindow
  961. ];
  962. };
  963.  
  964. Scene_Battle.prototype.stop = function () {
  965. Scene_Base.prototype.stop.call(this);
  966. if (this.needsSlowFadeOut()) {
  967. this.startFadeOut(this.slowFadeSpeed(), false);
  968. } else {
  969. this.startFadeOut(this.fadeSpeed(), false);
  970. }
  971. if (Lecode.S_TBS.commandOn) {
  972. this.getWindowsWChangeableOpa().forEach(function (window) {
  973. window.close();
  974. }.bind(this));
  975. } else {
  976. this._statusWindow.close();
  977. this._partyCommandWindow.close();
  978. this._actorCommandWindow.close();
  979. }
  980. };
  981.  
  982.  
  983. /*-------------------------------------------------------------------------
  984. * InputHandlerTBS
  985. -------------------------------------------------------------------------*/
  986. function InputHandlerTBS() {
  987. throw new Error('This is a static class');
  988. }
  989.  
  990. InputHandlerTBS.setup = function () {
  991. this._active = true;
  992. this._lastSelectedCell = null;
  993. this._windowsBlocking = [];
  994. };
  995.  
  996. InputHandlerTBS.isActive = function () {
  997. return this._active;
  998. };
  999.  
  1000. InputHandlerTBS.lastSelectedCell = function () {
  1001. return this._lastSelectedCell;
  1002. };
  1003.  
  1004. InputHandlerTBS.setActive = function (active) {
  1005. this._active = active;
  1006. };
  1007.  
  1008. InputHandlerTBS.addWindowBlockingTouch = function (window) {
  1009. this._windowsBlocking.push(window);
  1010. };
  1011.  
  1012. InputHandlerTBS.setOnTouchCallback = function (callback) {
  1013. this._onTouchCallback = callback;
  1014. };
  1015.  
  1016. InputHandlerTBS.setOnTouchCancelCallback = function (callback) {
  1017. this._onTouchCancelCallback = callback;
  1018. };
  1019.  
  1020. InputHandlerTBS.setOnUpCallback = function (callback) {
  1021. this._onUpCallback = callback;
  1022. };
  1023.  
  1024. InputHandlerTBS.setOnRightCallback = function (callback) {
  1025. this._onRightCallback = callback;
  1026. };
  1027.  
  1028. InputHandlerTBS.setOnDownCallback = function (callback) {
  1029. this._onDownCallback = callback;
  1030. };
  1031.  
  1032. InputHandlerTBS.setOnLeftCallback = function (callback) {
  1033. this._onLeftCallback = callback;
  1034. };
  1035.  
  1036. InputHandlerTBS.setOnOkCallback = function (callback) {
  1037. this._onOkCallback = callback;
  1038. };
  1039.  
  1040. InputHandlerTBS.setOnCancelCallback = function (callback) {
  1041. this._onCancelCallback = callback;
  1042. };
  1043.  
  1044. InputHandlerTBS.update = function () {
  1045. if (!this.isActive()) return;
  1046. if (BattleManagerTBS.isWaiting()) return;
  1047.  
  1048. if (Input.isPressed(Lecode.S_TBS.explorationInput) && !BattleManagerTBS.isExploring()) {
  1049. BattleManagerTBS.startMapExploration();
  1050. return;
  1051. }
  1052. if (!Input.isPressed(Lecode.S_TBS.explorationInput) && BattleManagerTBS.isExploring()) {
  1053. BattleManagerTBS.endMapExploration();
  1054. return;
  1055. }
  1056. if (BattleManagerTBS.isExploring()) {
  1057. this.updateExplorationInput();
  1058. return;
  1059. }
  1060.  
  1061. if (Input.isPressed(Lecode.S_TBS.opacityInput))
  1062. BattleManagerTBS.setInputOpacity();
  1063. else
  1064. BattleManagerTBS._opacityInputed = false;
  1065.  
  1066. if (TouchInput.isTriggered()) {
  1067. if (!this.isTouchBlocked()) {
  1068. var cell = this.touchSelectedCell();
  1069. this.processCallback("Touch", cell);
  1070. this._lastSelectedCell = cell;
  1071. var x = $gameMap.canvasToMapX(TouchInput.x);
  1072. var y = $gameMap.canvasToMapY(TouchInput.y);
  1073. $gameTemp.setDestination(x, y);
  1074. BattleManagerTBS.resetDestinationCount();
  1075. }
  1076. return;
  1077. }
  1078.  
  1079. if (TouchInput.isCancelled()) {
  1080. this.processCallback("TouchCancel");
  1081. return;
  1082. }
  1083.  
  1084. if (Input.isTriggered("right"))
  1085. this.processCallback("Right");
  1086. if (Input.isTriggered("down"))
  1087. this.processCallback("Down");
  1088. if (Input.isTriggered("left"))
  1089. this.processCallback("Left");
  1090. if (Input.isTriggered("up"))
  1091. this.processCallback("Up");
  1092. if (Input.isTriggered("ok"))
  1093. this.processCallback("Ok");
  1094. if (Input.isTriggered("cancel"))
  1095. this.processCallback("Cancel");
  1096. };
  1097.  
  1098. InputHandlerTBS.processCallback = function (key, arg) {
  1099. var func = eval("this._on" + key + "Callback");
  1100. if (func)
  1101. func(arg);
  1102. };
  1103.  
  1104. InputHandlerTBS.updateExplorationInput = function () {
  1105. if (Input.isPressed("right"))
  1106. BattleManagerTBS.scrollRight(1);
  1107. if (Input.isPressed("down"))
  1108. BattleManagerTBS.scrollDown(1);
  1109. if (Input.isPressed("up"))
  1110. BattleManagerTBS.scrollUp(1);
  1111. if (Input.isPressed("left"))
  1112. BattleManagerTBS.scrollLeft(1);
  1113. };
  1114.  
  1115. InputHandlerTBS.touchSelectedCell = function () {
  1116. var w = $gameMap.tileWidth();
  1117. var h = $gameMap.tileHeight();
  1118. var x = TouchInput.x;
  1119. var y = TouchInput.y;
  1120. var cells = BattleManagerTBS._groundCells;
  1121. for (var i = 0; i < cells.length; i++) {
  1122. var cell = cells[i];
  1123. if (x >= cell.x * w && x <= (cell.x * w + w)) {
  1124. if (y >= cell.y * h && y <= (cell.y * h + h))
  1125. return cell;
  1126. }
  1127. }
  1128. return null;
  1129. };
  1130.  
  1131. InputHandlerTBS.isTouchBlocked = function () {
  1132. var x = TouchInput.x;
  1133. var y = TouchInput.y;
  1134. for (var i = 0; i < this._windowsBlocking.length; i++) {
  1135. var w = this._windowsBlocking[i];
  1136. if (!w.visible || w.opacity === 0 || w.openness === 0) continue;
  1137. if (x >= w.x && x <= (w.x + w.width)) {
  1138. if (y >= w.y && y <= (w.y + w.height))
  1139. return true;
  1140. }
  1141. }
  1142. return false;
  1143. };
  1144.  
  1145.  
  1146. /*-------------------------------------------------------------------------
  1147. * BattleManager
  1148. -------------------------------------------------------------------------*/
  1149. Lecode.S_TBS.oldBM_setup = BattleManager.setup;
  1150. BattleManager.setup = function (troopId, canEscape, canLose) {
  1151. Lecode.S_TBS.oldBM_setup.call(this, troopId, canEscape, canLose);
  1152. BattleManagerTBS.setup();
  1153. };
  1154.  
  1155. Lecode.S_TBS.oldBM_isTurnEnd = BattleManager.isTurnEnd;
  1156. BattleManager.isTurnEnd = function () {
  1157. return Lecode.S_TBS.oldBM_isTurnEnd.call(this) || BattleManagerTBS._subPhase == "turn_end";
  1158. };
  1159.  
  1160. Lecode.S_TBS.oldBM_canEscape = BattleManager.canEscape;
  1161. BattleManager.canEscape = function () {
  1162. var entity = BattleManagerTBS.activeEntity();
  1163. if (entity) {
  1164. var bool = entity._movePerformed || entity._actionPerformed;
  1165. return Lecode.S_TBS.oldBM_canEscape.call(this) && !bool;
  1166. } else {
  1167. return Lecode.S_TBS.oldBM_canEscape.call(this);
  1168. }
  1169. };
  1170.  
  1171.  
  1172. /*-------------------------------------------------------------------------
  1173. * BattleManagerTBS
  1174. -------------------------------------------------------------------------*/
  1175. function BattleManagerTBS() {
  1176. throw new Error('This is a static class');
  1177. }
  1178.  
  1179. BattleManagerTBS.setup = function () {
  1180. this.initMembers();
  1181. };
  1182.  
  1183. BattleManagerTBS.initMembers = function () {
  1184. this._phase = "init";
  1185. this._subPhase = "";
  1186. this._startCells = [];
  1187. this._groundCells = [];
  1188. this._cursor = null;
  1189. this._activeCell = null;
  1190. this._spriteset = null;
  1191. this._battlerEntities = [];
  1192. this._explorationIniCell = null;
  1193. this._exploring = false;
  1194. this._inputOpacity = 0;
  1195. this._opacityInputed = false;
  1196. this._waitTime = 0;
  1197. this._turnOrder = [];
  1198. this._activeIndex = 0;
  1199. this._activeAction = null;
  1200. this._dummyChara = new Game_Character();
  1201. this._moveScope = null;
  1202. this._movePath = null;
  1203. this._actionScope = null;
  1204. this._destinationCount = 0;
  1205. };
  1206.  
  1207. BattleManagerTBS.cursor = function () {
  1208. return this._cursor;
  1209. };
  1210.  
  1211. BattleManagerTBS.allEntities = function () {
  1212. return this._battlerEntities;
  1213. };
  1214.  
  1215. BattleManagerTBS.dummyCharacter = function () {
  1216. return this._dummyChara;
  1217. };
  1218.  
  1219. BattleManagerTBS.moveScope = function () {
  1220. return this._moveScope;
  1221. };
  1222.  
  1223. BattleManagerTBS.movePath = function () {
  1224. return this._movePath;
  1225. };
  1226.  
  1227. BattleManagerTBS.actionScope = function () {
  1228. return this._actionScope;
  1229. };
  1230.  
  1231. BattleManagerTBS.lastSelectedCell = function () {
  1232. return this._lastSelectedCell;
  1233. };
  1234.  
  1235. BattleManagerTBS.isExploring = function () {
  1236. return this._exploring;
  1237. };
  1238.  
  1239. BattleManagerTBS.activeAction = function () {
  1240. return this._activeAction;
  1241. };
  1242.  
  1243. BattleManagerTBS.getLayer = function (id) {
  1244. var layer = eval("this._spriteset._" + id + "Layer");
  1245. return layer;
  1246. };
  1247.  
  1248. BattleManagerTBS.wait = function (time) {
  1249. this._waitTime += time;
  1250. };
  1251.  
  1252. BattleManagerTBS.isWaiting = function () {
  1253. return this._waitTime > 0;
  1254. };
  1255.  
  1256. BattleManagerTBS.startBattle = function () {
  1257. this.prepare();
  1258. this.processPlacementPhase();
  1259. };
  1260.  
  1261. BattleManagerTBS.prepare = function () {
  1262. this.createStartCells();
  1263. this.createGroundCells();
  1264. this.createTBSObjects();
  1265. };
  1266.  
  1267. BattleManagerTBS.createTBSObjects = function () {
  1268. this.createDirectionSelector();
  1269. this.createCursor();
  1270. this.createBattleStartSprite();
  1271. this.createTurnOrderVisual();
  1272. this.createProjectilesManager();
  1273. this.createAiManager();
  1274. this._easystar = new EasyStar.js();
  1275. };
  1276.  
  1277. BattleManagerTBS.createDirectionSelector = function () {
  1278. var layer = this.getLayer("movableInfo");
  1279. this._directionSelector = new TBSDirectionSelector(layer);
  1280. };
  1281.  
  1282. BattleManagerTBS.createCursor = function () {
  1283. var bitmap = ImageManager.loadLeTBS("MapCursor");
  1284. this._cursor = new SpriteCursorTBS(bitmap);
  1285. this.getLayer("ground").addChild(this.cursor());
  1286. };
  1287.  
  1288. BattleManagerTBS.createBattleStartSprite = function () {
  1289. var bitmap = ImageManager.loadLeTBS("Battle_Start");
  1290. this._startSprite = new Sprite(bitmap);
  1291. this._startSprite.visible = false;
  1292. this.getLayer("fixedInfo").addChild(this._startSprite);
  1293. };
  1294.  
  1295. BattleManagerTBS.createProjectilesManager = function () {
  1296. var layer = this.getLayer("animations");
  1297. this._projectilesManager = new TBSProjectilesManager(layer);
  1298. };
  1299.  
  1300. BattleManagerTBS.createAiManager = function () {
  1301. this._aiManager = new TBSAiManager();
  1302. };
  1303. BattleManagerTBS.createTurnOrderVisual = function () {
  1304. var layer = this.getLayer("fixedInfo");
  1305. this._turnOrderVisual = new TBSTurnOrderVisual(layer);
  1306. };
  1307.  
  1308. BattleManagerTBS.createStartCells = function () {
  1309. this.getLayer("scopes").clear();
  1310. this._startCells = [];
  1311. $gameMap.events().forEach(function (eventObj) {
  1312. var x = eventObj.event().x;
  1313. var y = eventObj.event().y;
  1314. var name = eventObj.event().name;
  1315. var cell = new TBSCell(x, y);
  1316. cell._event = eventObj.event();
  1317. if (name == "ally" || name == "enemy")
  1318. this.createPlacementCell(name, x, y, cell);
  1319. this._startCells.push(cell);
  1320. }.bind(this));
  1321. };
  1322.  
  1323. BattleManagerTBS.createGroundCells = function () {
  1324. this._groundCells = [];
  1325. for (var i = 0; i < $gameMap.width(); i++) {
  1326. for (var j = 0; j < $gameMap.height(); j++) {
  1327. var cell = new TBSCell(i, j);
  1328. cell._regionId = $gameMap.regionId(i, j);
  1329. this._groundCells.push(cell);
  1330. }
  1331. }
  1332. };
  1333.  
  1334. BattleManagerTBS.update = function () {
  1335. this.waitForMessages();
  1336. this.updateWait();
  1337. this.updateWindowsInputOpacity();
  1338. this.updateTBSObjects();
  1339. this.updatePhase();
  1340. this.updateBattlers();
  1341. this.updateDestination();
  1342. };
  1343.  
  1344. BattleManagerTBS.updateDestination = function () {
  1345. this._destinationCount++;
  1346. if (this._destinationCount >= Lecode.S_TBS.destinationDuration) {
  1347. this._destinationCount = 0;
  1348. $gameTemp.clearDestination();
  1349. }
  1350. };
  1351.  
  1352. BattleManagerTBS.resetDestinationCount = function () {
  1353. this._destinationCount = 0;
  1354. };
  1355.  
  1356. BattleManagerTBS.waitForMessages = function () {
  1357. if ($gameMessage.isBusy()) {
  1358. this.wait(1);
  1359. var window = LeUtilities.getScene()._windowCommand;
  1360. if (window.active) {
  1361. //window.close();
  1362. window.deactivate();
  1363. this._windowToResume = window;
  1364. }
  1365. } else {
  1366. if (this._windowToResume) {
  1367. this._windowToResume.open();
  1368. this._windowToResume.activate();
  1369. this._windowToResume = null;
  1370. }
  1371. }
  1372. };
  1373.  
  1374. BattleManagerTBS.updateWait = function () {
  1375. if (this.isWaiting())
  1376. this._waitTime--;
  1377. };
  1378.  
  1379. BattleManagerTBS.updateWindowsInputOpacity = function () {
  1380. if (this._inputOpacity === 0)
  1381. return;
  1382.  
  1383. var windows = LeUtilities.getScene().getWindowsWChangeableOpa();
  1384. windows.forEach(function (window) {
  1385. window.opacity = 255 - this._inputOpacity;
  1386. window.backOpacity = 255 - this._inputOpacity;
  1387. window.contentsOpacity = 255 - this._inputOpacity;
  1388. }.bind(this));
  1389.  
  1390. if (!this._opacityInputed) {
  1391. var steps = Lecode.S_TBS.inputOpacityDecreaseSteps;
  1392. var max = 255 - Lecode.S_TBS.minInputOpacity;
  1393. this._inputOpacity -= steps;
  1394. this._inputOpacity = this._inputOpacity.clamp(0, max);
  1395. }
  1396. };
  1397.  
  1398. BattleManagerTBS.updateTBSObjects = function () {
  1399. this.updateCursor();
  1400. this._turnOrderVisual.update();
  1401. this._projectilesManager.update();
  1402. };
  1403.  
  1404. BattleManagerTBS.updateCursor = function () {
  1405. if (!this._activeCell || !this.cursor()) return;
  1406. var x = this._activeCell.x;
  1407. var y = this._activeCell.y;
  1408. this.cursor().cellX = x;
  1409. this.cursor().cellY = y;
  1410. x *= $gameMap.tileWidth();
  1411. y *= $gameMap.tileHeight();
  1412. this.cursor().x = x;
  1413. this.cursor().y = y;
  1414. this.cursor().update();
  1415. };
  1416.  
  1417. BattleManagerTBS.startMapExploration = function () {
  1418. this._exploring = true;
  1419. this._explorationIniCell = this._activeCell;
  1420. };
  1421.  
  1422. BattleManagerTBS.endMapExploration = function () {
  1423. this._exploring = false;
  1424. this.centerCell(this._explorationIniCell);
  1425. };
  1426.  
  1427. BattleManagerTBS.setInputOpacity = function () {
  1428. this._opacityInputed = true;
  1429. var steps = Lecode.S_TBS.inputOpacityDecreaseSteps;
  1430. var max = 255 - Lecode.S_TBS.minInputOpacity;
  1431. this._inputOpacity += steps;
  1432. this._inputOpacity = this._inputOpacity.clamp(0, max);
  1433. };
  1434.  
  1435. BattleManagerTBS.updatePhase = function () {
  1436. if ($gameMessage.isBusy()) return;
  1437. switch (this._phase) {
  1438. case "placement":
  1439. this.updatePlacementPhase();
  1440. break;
  1441. case "battle_beginning":
  1442. this.updateBeginningPhase();
  1443. break;
  1444. case "battle_processing":
  1445. this.updateBattleProcessing();
  1446. break;
  1447. case "battle_stopping":
  1448. this.updateBattleStopping();
  1449. break;
  1450. case "battle_end":
  1451. this.updateBattleEnd();
  1452. break;
  1453. }
  1454. };
  1455.  
  1456. BattleManagerTBS.updateBattlers = function () {
  1457. this.allEntities().forEach(function (entity) {
  1458. entity.update();
  1459. }.bind(this));
  1460. };
  1461.  
  1462. BattleManagerTBS.createPlacementCell = function (type, x, y, cell) {
  1463. var opacity = Lecode.S_TBS.placementCellOpacity;
  1464. var color = (type == "ally") ? Lecode.S_TBS.allyColorCell : Lecode.S_TBS.enemyColorCell;
  1465. this.getLayer("scopes").drawCell(x, y, opacity, color);
  1466. cell._type = type;
  1467. };
  1468.  
  1469. BattleManagerTBS.drawTileLimits = function (cell, x, y) {
  1470. if (!Lecode.S_TBS.drawLimits) return false;
  1471. var lines = 0;
  1472. if ($gameMap.isPassable(x, y, 2)) { //-Down
  1473. cell._bitmap.fillRect(0, 0, $gameMap.tileWidth(), 1, "#FFFFFF");
  1474. lines++;
  1475. }
  1476. if ($gameMap.isPassable(x, y, 4)) { //-Left
  1477. cell._bitmap.fillRect($gameMap.tileWidth() - 1, 0, 1, $gameMap.tileHeight(), "#FFFFFF");
  1478. lines++;
  1479. }
  1480. if ($gameMap.isPassable(x, y, 6)) { //-Right
  1481. cell._bitmap.fillRect(0, 0, 1, $gameMap.tileHeight(), "#FFFFFF");
  1482. lines++;
  1483. }
  1484. if ($gameMap.isPassable(x, y, 8)) { //-Up
  1485. cell._bitmap.fillRect(0, $gameMap.tileHeight() - 1, $gameMap.tileWidth(), 1, "#FFFFFF");
  1486. lines++;
  1487. }
  1488. return lines;
  1489. };
  1490.  
  1491. BattleManagerTBS.processPlacementPhase = function () {
  1492. this._phase = "placement";
  1493. this._subPhase = "";
  1494. this._placeAllies = [];
  1495. this._placeEnemies = [];
  1496. $gameParty.battleMembers().forEach(function (mem) {
  1497. this._placeAllies.push(mem);
  1498. }.bind(this));
  1499. $gameTroop.members().forEach(function (mem) {
  1500. this._placeEnemies.push(mem);
  1501. }.bind(this));
  1502. this.processEnemyPlacement();
  1503.  
  1504. InputHandlerTBS.setOnTouchCallback(this.placementPhaseOnTouchInput.bind(this));
  1505. InputHandlerTBS.setOnTouchCancelCallback(this.placementPhaseOnInputCancel.bind(this));
  1506. InputHandlerTBS.setOnOkCallback(this.placementPhaseOnInputOk.bind(this));
  1507. InputHandlerTBS.setOnCancelCallback(this.placementPhaseOnInputCancel.bind(this));
  1508. InputHandlerTBS.setOnRightCallback(this.placementPhaseOnInputRight.bind(this));
  1509. InputHandlerTBS.setOnLeftCallback(this.placementPhaseOnInputLeft.bind(this));
  1510. InputHandlerTBS.setOnDownCallback(this.placementPhaseOnInputDown.bind(this));
  1511. InputHandlerTBS.setOnUpCallback(this.placementPhaseOnInputUp.bind(this));
  1512. };
  1513.  
  1514. BattleManagerTBS.placementPhaseOnTouchInput = function (selectedCell) {
  1515. switch (this._subPhase) {
  1516. case "input":
  1517. this.selectStartCellByTouch(selectedCell);
  1518. break;
  1519. case "directionSelector_input":
  1520. this.setDirectionSelectionDirByTouch(selectedCell);
  1521. break;
  1522. }
  1523. };
  1524.  
  1525. BattleManagerTBS.placementPhaseOnInputOk = function () {
  1526. switch (this._subPhase) {
  1527. case "input":
  1528. this.placementPhaseOk();
  1529. break;
  1530. case "directionSelector_input":
  1531. this.directionSelectorValidatePlacement();
  1532. break;
  1533. }
  1534. };
  1535.  
  1536. BattleManagerTBS.placementPhaseOnInputCancel = function () {
  1537. switch (this._subPhase) {
  1538. case "input":
  1539. this.placementPhaseCancel();
  1540. break;
  1541. case "directionSelector_input":
  1542. this.directionSelectorCancelPlacement();
  1543. break;
  1544. }
  1545. };
  1546.  
  1547. BattleManagerTBS.placementPhaseOnInputLeft = function () {
  1548. switch (this._subPhase) {
  1549. case "input":
  1550. this.selectStartCellByDir("left");
  1551. break;
  1552. case "directionSelector_input":
  1553. this.setDirectionSelectorLeft();
  1554. break;
  1555. }
  1556. };
  1557.  
  1558. BattleManagerTBS.placementPhaseOnInputRight = function () {
  1559. switch (this._subPhase) {
  1560. case "input":
  1561. this.selectStartCellByDir("right");
  1562. break;
  1563. case "directionSelector_input":
  1564. this.setDirectionSelectorRight();
  1565. break;
  1566. }
  1567. };
  1568.  
  1569. BattleManagerTBS.placementPhaseOnInputDown = function () {
  1570. switch (this._subPhase) {
  1571. case "input":
  1572. this.selectStartCellByDir("down");
  1573. break;
  1574. case "directionSelector_input":
  1575. this.setDirectionSelectorDown();
  1576. break;
  1577. }
  1578. };
  1579.  
  1580. BattleManagerTBS.placementPhaseOnInputUp = function () {
  1581. switch (this._subPhase) {
  1582. case "input":
  1583. this.selectStartCellByDir("up");
  1584. break;
  1585. case "directionSelector_input":
  1586. this.setDirectionSelectorUp();
  1587. break;
  1588. }
  1589. };
  1590.  
  1591. BattleManagerTBS.updatePlacementPhase = function () {
  1592. if (this._subPhase === "troop") {
  1593. if (!this.getLayer("animations").isAnimationPlaying()) {
  1594. if (this._placeEnemies.length === 0)
  1595. this.processAllyPlacement();
  1596. else
  1597. this.placeNextEnemy();
  1598. }
  1599. }
  1600. };
  1601.  
  1602. BattleManagerTBS.processEnemyPlacement = function () {
  1603. this._subPhase = "troop";
  1604. this.placeNextEnemy();
  1605. };
  1606.  
  1607. BattleManagerTBS.placeNextEnemy = function () {
  1608. var enemy = this._placeEnemies.shift();
  1609. var cells = this.enemyStartCells().filter(function (c) {
  1610. return Number(c._event.note) === enemy.index() + 1 && this.isCellFree(c);
  1611. }.bind(this));
  1612. var cell = LeUtilities.getRandomValueInArray(cells);
  1613. if (cell) {
  1614. cell.select();
  1615. this.centerActiveCell();
  1616. this.updateCursor();
  1617. var entity = new TBSEntity(enemy, this.getLayer("battlers"));
  1618. this.getLayer("animations").newAnimation(Lecode.S_TBS.placedBattlerAnim, false, 0, cell, entity._sprite);
  1619. entity.setCell(cell);
  1620. this._battlerEntities.push(entity);
  1621. }
  1622. };
  1623.  
  1624. BattleManagerTBS.processAllyPlacement = function () {
  1625. InputHandlerTBS.setActive(true);
  1626. this._subPhase = "input";
  1627. this.placementSelect(this.allyStartCells()[0]);
  1628. };
  1629.  
  1630. BattleManagerTBS.placementSelect = function (cell) {
  1631. cell.select();
  1632. this.centerActiveCell();
  1633. this.updateCursor();
  1634. var battler = this._placeAllies[0];
  1635. LeUtilities.getScene().showPlacementWindow(cell, battler);
  1636. };
  1637.  
  1638. BattleManagerTBS.selectStartCellByDir = function (dir) {
  1639. var cell = this._activeCell;
  1640. var cells = this.allyStartCells().filter(function (c) {
  1641. return c != cell;
  1642. });
  1643. var found = null;
  1644. switch (dir) {
  1645. case "up":
  1646. cells = cells.filter(function (c) {
  1647. return c.y < cell.y;
  1648. });
  1649. found = LeUtilities.closestByDistance(cell, cells);
  1650. break;
  1651. case "down":
  1652. cells = cells.filter(function (c) {
  1653. return c.y > cell.y;
  1654. });
  1655. found = LeUtilities.closestByDistance(cell, cells);
  1656. break;
  1657. case "right":
  1658. cells = cells.filter(function (c) {
  1659. return c.x > cell.x;
  1660. });
  1661. found = LeUtilities.closestByDistance(cell, cells);
  1662. break;
  1663. case "left":
  1664. cells = cells.filter(function (c) {
  1665. return c.x < cell.x;
  1666. });
  1667. found = LeUtilities.closestByDistance(cell, cells);
  1668. break;
  1669. }
  1670. if (found && found != cell) {
  1671. this.placementSelect(found);
  1672. SoundManager.playCursor();
  1673. }
  1674. };
  1675.  
  1676. BattleManagerTBS.selectStartCellByTouch = function (cell) {
  1677. if (cell) {
  1678. var scope = this.allyStartCells();
  1679. var currentCell = this._activeCell;
  1680. if (this.isCellInScope(cell, scope)) {
  1681. if (currentCell.isSame(cell)) {
  1682. this.placementPhaseOk();
  1683. } else {
  1684. this.placementSelect(cell);
  1685. }
  1686. } else {
  1687. this.placementPhaseOk();
  1688. }
  1689. }
  1690. };
  1691.  
  1692. BattleManagerTBS.selectNextStartCell = function () {
  1693. var currentIndex = this.allyStartCells().indexOf(this._activeCell);
  1694. var cell = this._activeCell;
  1695. var currentEntity = cell.getEntity();
  1696. var index = currentIndex;
  1697. do {
  1698. if (currentIndex === this.allyStartCells().length - 1)
  1699. index = 0;
  1700. else
  1701. index += 1;
  1702. cell = this.allyStartCells()[index];
  1703. currentEntity = cell.getEntity();
  1704. } while (currentEntity);
  1705. this.placementSelect(cell);
  1706. SoundManager.playCursor();
  1707. };
  1708.  
  1709. BattleManagerTBS.selectPreviousStartCell = function () {
  1710. var currentIndex = this.allyStartCells().indexOf(this._activeCell);
  1711. var index = currentIndex === 0 ? this.allyStartCells().length - 1 : currentIndex - 1;
  1712. this.placementSelect(this.allyStartCells()[index]);
  1713. SoundManager.playCursor();
  1714. };
  1715.  
  1716. BattleManagerTBS.placementPhaseOk = function () {
  1717. var cell = this._activeCell;
  1718. var battler = this._placeAllies.shift();
  1719. var currentEntity = cell.getEntity();
  1720. if (currentEntity) {
  1721. this.removeBattlerEntity(currentEntity);
  1722. }
  1723. var entity = this.placeBattler(battler, cell);
  1724. this.callDirectionSelector(entity, cell);
  1725. };
  1726.  
  1727. BattleManagerTBS.placementPhaseCancel = function () {
  1728. var cell = this._activeCell;
  1729. var currentEntity = cell.getEntity();
  1730. if (currentEntity) {
  1731. this.removeBattlerEntity(currentEntity);
  1732. this.placementSelect(this._activeCell);
  1733. SoundManager.playCancel();
  1734. } else
  1735. SoundManager.playBuzzer();
  1736. };
  1737.  
  1738. BattleManagerTBS.placeBattler = function (battler, cell) {
  1739. var entity = new TBSEntity(battler, this.getLayer("battlers"));
  1740. this.getLayer("animations").newAnimation(Lecode.S_TBS.placedBattlerAnim, false, 0, cell, entity._sprite);
  1741. entity.setCell(cell);
  1742. this._battlerEntities.push(entity);
  1743. SoundManager.playOk();
  1744. this.updateEnemiesDirectionWhilePlacement();
  1745. return entity;
  1746. };
  1747.  
  1748. BattleManagerTBS.removeBattlerEntity = function (entity) {
  1749. this._placeAllies.unshift(entity._battler);
  1750. LeUtilities.removeInArray(this.allEntities(), entity);
  1751. this.getLayer("battlers").removeChild(entity._sprite);
  1752. };
  1753.  
  1754. BattleManagerTBS.updateEnemiesDirectionWhilePlacement = function () {
  1755. this.enemyEntities().forEach(function (ent) {
  1756. ent.lookClosestBattler(this.allyEntities());
  1757. }.bind(this));
  1758. };
  1759.  
  1760. BattleManagerTBS.callDirectionSelector = function (battler, cell) {
  1761. this._subPhase = "directionSelector_input";
  1762. this._directionSelector.set(cell, battler);
  1763. LeUtilities.getScene().hidePlacementWindow(cell, battler);
  1764. };
  1765.  
  1766. BattleManagerTBS.setDirectionSelectorUp = function () {
  1767. this._directionSelector.setDir(8);
  1768. };
  1769.  
  1770. BattleManagerTBS.setDirectionSelectorDown = function () {
  1771. this._directionSelector.setDir(2);
  1772. };
  1773.  
  1774. BattleManagerTBS.setDirectionSelectorLeft = function () {
  1775. this._directionSelector.setDir(4);
  1776. };
  1777.  
  1778. BattleManagerTBS.setDirectionSelectorRight = function () {
  1779. this._directionSelector.setDir(6);
  1780. };
  1781.  
  1782. BattleManagerTBS.directionSelectorValidatePlacement = function () {
  1783. SoundManager.playOk();
  1784. this._directionSelector.hide();
  1785. this._subPhase = "input";
  1786. if (this.canEndPlacementPhase())
  1787. this.placementPhaseEnd();
  1788. else
  1789. this.selectNextStartCell();
  1790. };
  1791.  
  1792. BattleManagerTBS.setDirectionSelectionDirByTouch = function (selectedCell) {
  1793. var entity = this._directionSelector._battlerEntity;
  1794. entity.lookAt(selectedCell);
  1795. this.directionSelectorValidatePlacement();
  1796. };
  1797.  
  1798. BattleManagerTBS.directionSelectorCancelPlacement = function () {
  1799. this._directionSelector.hide();
  1800. this._subPhase = "input";
  1801. this.placementPhaseCancel();
  1802. };
  1803.  
  1804. BattleManagerTBS.placementPhaseEnd = function () {
  1805. this._subPhase = "confirm";
  1806. Input.clear();
  1807. LeUtilities.getScene().showConfirmationWindow();
  1808. };
  1809.  
  1810. BattleManagerTBS.resumePlacementPhase = function () {
  1811. LeUtilities.getScene().hideConfirmationWindow();
  1812. this.placementPhaseCancel();
  1813. this._subPhase = "input";
  1814. };
  1815.  
  1816. BattleManagerTBS.onConfirmationWindowOK = function () {
  1817. switch (this._phase) {
  1818. case "placement":
  1819. this.battlebeginning();
  1820. break;
  1821. }
  1822. };
  1823.  
  1824. BattleManagerTBS.onConfirmationWindowCancel = function () {
  1825. switch (this._phase) {
  1826. case "placement":
  1827. this.resumePlacementPhase();
  1828. break;
  1829. }
  1830. };
  1831.  
  1832. BattleManagerTBS.battlebeginning = function () {
  1833. this._phase = "battle_beginning";
  1834. LeUtilities.getScene().hideConfirmationWindow();
  1835.  
  1836. this._startSprite.visible = true;
  1837. this._startSprite.x = Graphics.width / 2 - this._startSprite.width / 2;
  1838. this._startSprite.y = Graphics.height / 2 - this._startSprite.height / 2;
  1839. this._startSprite.opacity = 0;
  1840. this._subPhase = "in";
  1841. };
  1842.  
  1843. BattleManagerTBS.updateBeginningPhase = function () {
  1844. var opa;
  1845. if (this._subPhase == "in") {
  1846. opa = this._startSprite.opacity;
  1847. this._startSprite.opacity = (opa + 6).clamp(0, 255);
  1848. if (this._startSprite.opacity == 255) {
  1849. this._subPhase = "wait";
  1850. this.wait(Lecode.S_TBS.battleStartSpriteDelay);
  1851. }
  1852. } else if (this._subPhase == "wait") {
  1853. if (!this.isWaiting())
  1854. this._subPhase = "out";
  1855. } else if (this._subPhase == "out") {
  1856. opa = this._startSprite.opacity;
  1857. this._startSprite.opacity = (opa - 6).clamp(0, 255);
  1858. if (this._startSprite.opacity === 0) {
  1859. this.beginningPhaseEnd();
  1860. }
  1861. }
  1862. };
  1863.  
  1864. BattleManagerTBS.beginningPhaseEnd = function () {
  1865. this._startSprite.visible = false;
  1866. this.processBattle();
  1867. };
  1868.  
  1869. BattleManagerTBS.processBattle = function () {
  1870. this._phase = "battle_processing";
  1871. this._subPhase = "";
  1872.  
  1873. BattleManager.startBattle();
  1874. this.allEntities().forEach(function (entity) {
  1875. entity.onBattleStart();
  1876. }.bind(this));
  1877. this.hidePlacementCells();
  1878. this.determineTurnOrder();
  1879. $gameTroop.increaseTurn();
  1880. this.startTurn();
  1881.  
  1882. InputHandlerTBS.setOnTouchCallback(this.battlePhaseOnTouchInput.bind(this));
  1883. InputHandlerTBS.setOnTouchCancelCallback(this.battlePhaseOnInputCancel.bind(this));
  1884. InputHandlerTBS.setOnOkCallback(this.battlePhaseOnInputOk.bind(this));
  1885. InputHandlerTBS.setOnCancelCallback(this.battlePhaseOnInputCancel.bind(this));
  1886. InputHandlerTBS.setOnUpCallback(this.battlePhaseOnInputUp.bind(this));
  1887. InputHandlerTBS.setOnRightCallback(this.battlePhaseOnInputRight.bind(this));
  1888. InputHandlerTBS.setOnDownCallback(this.battlePhaseOnInputDown.bind(this));
  1889. InputHandlerTBS.setOnLeftCallback(this.battlePhaseOnInputLeft.bind(this));
  1890. };
  1891.  
  1892. BattleManagerTBS.battlePhaseOnTouchInput = function (selectedCell) {
  1893. switch (this._subPhase) {
  1894. case "move":
  1895. this.touchMoveSelection(selectedCell);
  1896. break;
  1897. case "directionSelector_input":
  1898. this.passByTouch(selectedCell);
  1899. break;
  1900. case "attack":
  1901. case "skill":
  1902. case "item":
  1903. this.touchActionSelection(selectedCell);
  1904. break;
  1905. }
  1906. };
  1907.  
  1908. BattleManagerTBS.battlePhaseOnInputOk = function () {
  1909. switch (this._subPhase) {
  1910. case "move":
  1911. this.validateMoveSelection();
  1912. break;
  1913. case "directionSelector_input":
  1914. this.validatePass();
  1915. break;
  1916. case "attack":
  1917. case "skill":
  1918. case "item":
  1919. this.validateActionSelection();
  1920. break;
  1921. }
  1922. };
  1923.  
  1924. BattleManagerTBS.battlePhaseOnInputCancel = function () {
  1925. switch (this._subPhase) {
  1926. case "move":
  1927. this.onMoveCancel();
  1928. break;
  1929. case "directionSelector_input":
  1930. this.cancelPass();
  1931. break;
  1932. case "attack":
  1933. case "skill":
  1934. case "item":
  1935. this.onActionCancel();
  1936. break;
  1937. }
  1938. };
  1939.  
  1940. BattleManagerTBS.battlePhaseOnInputLeft = function () {
  1941. switch (this._subPhase) {
  1942. case "directionSelector_input":
  1943. this.setDirectionSelectorLeft();
  1944. break;
  1945. case "move":
  1946. case "attack":
  1947. case "skill":
  1948. case "item":
  1949. case "examine":
  1950. this.moveCursor("left");
  1951. break;
  1952. }
  1953. };
  1954.  
  1955. BattleManagerTBS.battlePhaseOnInputRight = function () {
  1956. switch (this._subPhase) {
  1957. case "directionSelector_input":
  1958. this.setDirectionSelectorRight();
  1959. break;
  1960. case "move":
  1961. case "attack":
  1962. case "skill":
  1963. case "item":
  1964. case "examine":
  1965. this.moveCursor("right");
  1966. break;
  1967. }
  1968. };
  1969.  
  1970. BattleManagerTBS.battlePhaseOnInputDown = function () {
  1971. switch (this._subPhase) {
  1972. case "directionSelector_input":
  1973. this.setDirectionSelectorDown();
  1974. break;
  1975. case "move":
  1976. case "attack":
  1977. case "skill":
  1978. case "item":
  1979. case "examine":
  1980. this.moveCursor("down");
  1981. break;
  1982. }
  1983. };
  1984.  
  1985. BattleManagerTBS.battlePhaseOnInputUp = function () {
  1986. switch (this._subPhase) {
  1987. case "directionSelector_input":
  1988. this.setDirectionSelectorUp();
  1989. break;
  1990. case "move":
  1991. case "attack":
  1992. case "skill":
  1993. case "item":
  1994. case "examine":
  1995. this.moveCursor("up");
  1996. break;
  1997. }
  1998. };
  1999.  
  2000. BattleManagerTBS.updateBattleProcessing = function () {
  2001. this.updateSequences();
  2002. if (this._subPhase == "moving") {
  2003. if (!this.activeEntity().isMoving() && !this.isWaiting())
  2004. this.onActiveEntityMoveEnd();
  2005. } else if (this._subPhase == "obj_invokation") {
  2006. if (!this.anySequenceRunning())
  2007. this.onActionEnd();
  2008. } else if (this._subPhase == "ai") {
  2009. this._aiManager.update();
  2010. } else if (this._subPhase == "turn_end")
  2011. this.updateEndOfTurnEvents();
  2012. };
  2013.  
  2014. BattleManagerTBS.hidePlacementCells = function () {
  2015. this.getLayer("scopes").clear();
  2016. };
  2017.  
  2018. BattleManagerTBS.determineTurnOrder = function () {
  2019. if (Lecode.S_TBS.turnOrderFairRepartition)
  2020. this.determineTurnOrderFair();
  2021. else
  2022. this.determineTurnOrderSimple();
  2023. };
  2024.  
  2025. BattleManagerTBS.determineTurnOrderSimple = function () {
  2026. var array = [];
  2027. this._turnOrder = [];
  2028. this._activeIndex = 0;
  2029.  
  2030. this.allEntities().forEach(function (entity) {
  2031. array.push(entity);
  2032. });
  2033. array = array.sort(function (a, b) {
  2034. return (a._battler.agi > b._battler.agi) ? 1 : ((a._battler.agi < b._battler.agi) ? -1 : 0);
  2035. });
  2036. array.reverse();
  2037.  
  2038. this._turnOrder = array;
  2039. this._turnOrderVisual.set(this._turnOrder);
  2040. };
  2041.  
  2042. BattleManagerTBS.determineTurnOrderFair = function () {
  2043. var array = [];
  2044. var actors = [];
  2045. var enemies = [];
  2046. this._turnOrder = [];
  2047. this._activeIndex = 0;
  2048.  
  2049. this.allyEntities().forEach(function (entity) {
  2050. actors.push(entity);
  2051. });
  2052. actors = actors.sort(function (a, b) {
  2053. return (a._battler.agi > b._battler.agi) ? 1 : ((a._battler.agi < b._battler.agi) ? -1 : 0);
  2054. });
  2055. actors.reverse();
  2056.  
  2057. this.enemyEntities().forEach(function (entity) {
  2058. enemies.push(entity);
  2059. });
  2060. enemies = enemies.sort(function (a, b) {
  2061. return (a._battler.agi > b._battler.agi) ? 1 : ((a._battler.agi < b._battler.agi) ? -1 : 0);
  2062. });
  2063. enemies.reverse();
  2064.  
  2065. if (actors[0]._battler.agi >= enemies[0]._battler.agi)
  2066. array.push(actors.shift());
  2067. else
  2068. array.push(enemies.shift());
  2069. var max = actors.length + enemies.length;
  2070. for (var i = 1; i <= max; i++) {
  2071. var last = array.leU_last();
  2072. if (last._battler.isActor()) {
  2073. if (enemies.length > 0)
  2074. array.push(enemies.shift());
  2075. else
  2076. array.push(actors.shift());
  2077. } else {
  2078. if (actors.length > 0)
  2079. array.push(actors.shift());
  2080. else
  2081. array.push(enemies.shift());
  2082. }
  2083. }
  2084.  
  2085. this._turnOrder = array;
  2086. this._turnOrderVisual.set(this._turnOrder);
  2087. };
  2088.  
  2089. BattleManagerTBS.activeEntity = function () {
  2090. return this._turnOrder[this._activeIndex];
  2091. };
  2092.  
  2093. BattleManagerTBS.activeBattler = function () {
  2094. return this.activeEntity()._battler;
  2095. };
  2096.  
  2097. BattleManagerTBS.startTurn = function () {
  2098. this._subPhase = "";
  2099. var entity = this.activeEntity();
  2100. entity.onTurnStart();
  2101.  
  2102. var battler = this.activeBattler();
  2103. this.newAction(battler);
  2104. LeUtilities.getScene().showStatusWindow(battler);
  2105.  
  2106. var cell = entity.getCell();
  2107. this.setCursorCell(cell);
  2108.  
  2109. if (battler.isActor()) {
  2110. LeUtilities.getScene().showCommandWindow();
  2111. } else {
  2112. this._subPhase = "ai";
  2113. this._aiManager.process(entity);
  2114. }
  2115. };
  2116.  
  2117. BattleManagerTBS.updateSequences = function () {
  2118. this.allEntities().forEach(function (entity) {
  2119. entity._sequenceManager.update();
  2120. });
  2121. };
  2122.  
  2123. BattleManagerTBS.anySequenceRunning = function () {
  2124. return this.allEntities().some(function (entity) {
  2125. return entity._sequenceManager.isRunning();
  2126. });
  2127. };
  2128.  
  2129. BattleManagerTBS.newAction = function (battler) {
  2130. this._activeAction = new Game_Action(battler, false);
  2131. };
  2132.  
  2133. BattleManagerTBS.moveCursor = function (dir) {
  2134. var x = this._activeCell.x,
  2135. y = this._activeCell.y;
  2136. switch (dir) {
  2137. case "up":
  2138. y--;
  2139. break;
  2140. case "down":
  2141. y++;
  2142. break;
  2143. case "right":
  2144. x++;
  2145. break;
  2146. case "left":
  2147. x--;
  2148. break;
  2149. }
  2150. var cell = this.getCellAt(x, y);
  2151. this.setCursorCell(cell);
  2152. SoundManager.playCursor();
  2153. };
  2154.  
  2155. BattleManagerTBS.setCursorCell = function (cell) {
  2156. if (!cell) return;
  2157. cell.select();
  2158. this.centerCell(cell);
  2159. this.updateCursor();
  2160. this.updateScopeSelection();
  2161. this.updateTargetStatus();
  2162. };
  2163.  
  2164. BattleManagerTBS.updateScopeSelection = function () {
  2165. if (this.cursorOnMoveScope())
  2166. this.updateMoveSelection();
  2167. else if (this.cursorOnActionScope()) {
  2168. this.updateActionSelection();
  2169. } else {
  2170. this.clearActionSelection();
  2171. this.clearMoveSelection();
  2172. }
  2173. };
  2174.  
  2175. BattleManagerTBS.updateTargetStatus = function () {
  2176. var cell = this._activeCell;
  2177. var entity = cell.getEntity();
  2178. var scene = LeUtilities.getScene();
  2179. if (entity) {
  2180. scene.showStatusWindow(entity._battler);
  2181. } else {
  2182. scene.showStatusWindow(this.activeBattler());
  2183. }
  2184. };
  2185.  
  2186. BattleManagerTBS.onCommandInput = function (command) {
  2187. switch (command) {
  2188. case "move":
  2189. this.processCommandMove();
  2190. break;
  2191. case "attack":
  2192. this.processCommandAttack();
  2193. break;
  2194. case "skill":
  2195. this.processCommandSkill();
  2196. break;
  2197. case "item":
  2198. this.processCommandItem();
  2199. break;
  2200. case "pass":
  2201. this.processCommandPass();
  2202. break;
  2203. case "cancel":
  2204. this.processCommandCancel();
  2205. break;
  2206. }
  2207. };
  2208.  
  2209. BattleManagerTBS.processCommandMove = function () {
  2210. this._subPhase = "move";
  2211. var points = this.activeEntity().getMovePoints();
  2212. this.drawMoveScope(this.activeEntity(), points);
  2213. };
  2214.  
  2215. BattleManagerTBS.drawMoveScope = function (entity, points) {
  2216. var center = entity.getCell().toCoords();
  2217. var param = this.makeMoveScopeParam(entity);
  2218. var data = entity.getMoveScopeData();
  2219. var scope = this.getScopeFromData(data, center, param, points);
  2220. var color = Lecode.S_TBS.moveColorCell;
  2221. var opa = Lecode.S_TBS.moveCellOpacity;
  2222. var invalidOpa = Lecode.S_TBS.moveInvalidCellOpacity;
  2223. var invalidCondition = "!cell._walkable";
  2224. this.getLayer("scopes").clear();
  2225. this.drawScope(scope, color, opa, invalidOpa, invalidCondition);
  2226. this._moveScope = {};
  2227. this._moveScope.cells = scope;
  2228. this._moveScope.center = center;
  2229. };
  2230.  
  2231. BattleManagerTBS.makeMoveScopeParam = function (entity) {
  2232. var param = {
  2233. dir: entity.getDir(),
  2234. exclude_center: true,
  2235. can_select_obstacles: false,
  2236. cells_reachable: true,
  2237. };
  2238. var data = entity.getMoveScopeParamData();
  2239. data = LeUtilities.stringSplit(data, ",");
  2240. data.forEach(function (arg) {
  2241. if (arg.match(/through_obstacles/i))
  2242. param.cells_reachable = false;
  2243. }.bind(this));
  2244. return param;
  2245. };
  2246.  
  2247. BattleManagerTBS.cursorOnMoveScope = function () {
  2248. if (!this.isMoveScopeAvailable()) return false;
  2249. for (var i = 0; i < this.moveScope().cells.length; i++) {
  2250. var cell = this.moveScope().cells[i];
  2251. if (cell._walkable) // && !cell.isObstacle())
  2252. if (cell.x == this.cursor().cellX && cell.y == this.cursor().cellY)
  2253. return true;
  2254. }
  2255. return false;
  2256. };
  2257.  
  2258. BattleManagerTBS.updateMoveSelection = function () {
  2259. var sx = this.moveScope().center.x,
  2260. sy = this.moveScope().center.y,
  2261. dx = this.cursor().cellX,
  2262. dy = this.cursor().cellY;
  2263. this._movePath = this.getPathFromAToB(sx, sy, dx, dy, "walkable");
  2264. this.drawMoveSelection();
  2265. };
  2266.  
  2267. BattleManagerTBS.drawMoveSelection = function () {
  2268. this.clearMoveSelection();
  2269. var color = Lecode.S_TBS.moveColorCell;
  2270. var opacity = Lecode.S_TBS.moveSelectedCellOpacity;
  2271. for (var i = 0; i < this.movePath().length; i++) {
  2272. var cell = this.movePath()[i];
  2273. this.getLayer("scopes").drawSelectionCell(cell.x, cell.y, opacity, color);
  2274. }
  2275. };
  2276.  
  2277. BattleManagerTBS.clearMoveSelection = function () {
  2278. this.getLayer("scopes").clearSelection();
  2279. };
  2280.  
  2281. BattleManagerTBS.validateMoveSelection = function () {
  2282. if (!this.cursorOnMoveScope()) {
  2283. SoundManager.playBuzzer();
  2284. return;
  2285. }
  2286. SoundManager.playOk();
  2287. this.activeEntity().processMovement(this.movePath());
  2288. this._subPhase = "moving";
  2289. };
  2290.  
  2291. BattleManagerTBS.touchMoveSelection = function (selectedCell) {
  2292. var oldActiveCell = this._activeCell;
  2293. this.setCursorCell(selectedCell);
  2294. if (this.cursorOnMoveScope() && InputHandlerTBS.lastSelectedCell().isSame(selectedCell)) {
  2295. this.validateMoveSelection();
  2296. }
  2297. };
  2298.  
  2299. BattleManagerTBS.onActiveEntityMoveEnd = function () {
  2300. this._subPhase = "";
  2301. this.getLayer("scopes").clear();
  2302. this.clearMoveSelection();
  2303. this._moveScope = {};
  2304.  
  2305. this.activeEntity()._movePerformed = true;
  2306. if (this.activeBattler().isActor()) {
  2307. if (Lecode.S_TBS.autoPass && !this.activeEntity().canMoveCommand() && this.activeEntity()._actionPerformed)
  2308. this.processCommandPass();
  2309. else
  2310. LeUtilities.getScene().showCommandWindow();
  2311. }
  2312. LeUtilities.getScene().showStatusWindow(this.activeBattler());
  2313. var cell = this.activeEntity().getCell();
  2314. this.setCursorCell(cell);
  2315.  
  2316. this.updateEndOfActionEvents();
  2317. };
  2318.  
  2319. BattleManagerTBS.onMoveCancel = function () {
  2320. this._subPhase = "";
  2321. this.getLayer("scopes").clear();
  2322. this.clearMoveSelection();
  2323. this._moveScope = {};
  2324.  
  2325. LeUtilities.getScene().showCommandWindow();
  2326. var cell = this.activeEntity().getCell();
  2327. this.setCursorCell(cell);
  2328. Input.clear();
  2329.  
  2330. SoundManager.playCancel();
  2331. };
  2332.  
  2333. BattleManagerTBS.isMoveScopeAvailable = function () {
  2334. return this.moveScope() && this.moveScope().cells && this.moveScope().center;
  2335. };
  2336.  
  2337. BattleManagerTBS.processCommandAttack = function () {
  2338. this._subPhase = "attack";
  2339. this.activeAction().setAttack();
  2340. this.drawAttackScope(this.activeEntity());
  2341. };
  2342.  
  2343. BattleManagerTBS.drawAttackScope = function (entity) {
  2344. var data = entity.getAttackScopeData();
  2345. this._actionScopeParam = {
  2346. color: Lecode.S_TBS.attackColorCell,
  2347. opacity: Lecode.S_TBS.attackCellOpacity,
  2348. invalidOpa: Lecode.S_TBS.attackInvalidCellOpacity
  2349. };
  2350. this.drawActionScope(entity, data);
  2351. this.updateScopeSelection();
  2352. };
  2353.  
  2354. BattleManagerTBS.updateAttackSelection = function () {
  2355. this._actionAoE = this.getAttackAoE();
  2356. this.drawActionSelection();
  2357. };
  2358.  
  2359. BattleManagerTBS.getAttackAoE = function () {
  2360. var data = this.activeEntity().getAttackAoEData();
  2361. var center = this._activeCell.toCoords();
  2362. var param = this.makeObjAoEParam(null, this.activeEntity(), center);
  2363. return this.getScopeFromData(data, center, param);
  2364. };
  2365.  
  2366. BattleManagerTBS.processCommandSkill = function () {
  2367. LeUtilities.getScene().showSkillWindow();
  2368. };
  2369.  
  2370. BattleManagerTBS.onSkillInput = function (command) {
  2371. switch (command) {
  2372. case "ok":
  2373. this.onSkillSelected();
  2374. break;
  2375. case "cancel":
  2376. this.onActionCancel();
  2377. break;
  2378. }
  2379. };
  2380.  
  2381. BattleManagerTBS.onSkillSelected = function () {
  2382. var skill = LeUtilities.getScene()._windowSkill.item();
  2383. if (skill) {
  2384. this._subPhase = "skill";
  2385. this.activeAction().setItemObject(skill);
  2386. this.drawSkillScope(this.activeEntity());
  2387. }
  2388. };
  2389.  
  2390. BattleManagerTBS.drawSkillScope = function (entity) {
  2391. var obj = this.activeAction().item();
  2392. var data = entity.getObjectScopeData(obj);
  2393. this._actionScopeParam = {
  2394. color: Lecode.S_TBS.skillColorCell,
  2395. opacity: Lecode.S_TBS.skillCellOpacity,
  2396. invalidOpa: Lecode.S_TBS.skillInvalidCellOpacity,
  2397. selectedOpacity: Lecode.S_TBS.skillSelectedCellOpacity
  2398. };
  2399. this.drawActionScope(entity, data);
  2400. this.updateScopeSelection();
  2401. };
  2402.  
  2403. BattleManagerTBS.processCommandItem = function () {
  2404. LeUtilities.getScene().showItemWindow();
  2405. };
  2406.  
  2407. BattleManagerTBS.onItemInput = function (command) {
  2408. switch (command) {
  2409. case "ok":
  2410. this.onItemSelected();
  2411. break;
  2412. case "cancel":
  2413. this.onActionCancel();
  2414. break;
  2415. }
  2416. };
  2417.  
  2418. BattleManagerTBS.onItemSelected = function () {
  2419. var item = LeUtilities.getScene()._windowItem.item();
  2420. if (item) {
  2421. this._subPhase = "item";
  2422. this.activeAction().setItemObject(item);
  2423. this.drawItemScope(this.activeEntity());
  2424. }
  2425. };
  2426.  
  2427. BattleManagerTBS.drawItemScope = function (entity) {
  2428. var obj = this.activeAction().item();
  2429. var data = entity.getObjectScopeData(obj);
  2430. this._actionScopeParam = {
  2431. color: Lecode.S_TBS.ItemColorCell,
  2432. opacity: Lecode.S_TBS.ItemCellOpacity,
  2433. invalidOpa: Lecode.S_TBS.ItemInvalidCellOpacity,
  2434. selectedOpacity: Lecode.S_TBS.ItemSelectedCellOpacity
  2435. };
  2436. this.drawActionScope(entity, data);
  2437. this.updateScopeSelection();
  2438. };
  2439.  
  2440. BattleManagerTBS.updateActionSelection = function () {
  2441. this._actionAoE = this.getActionAoE();
  2442. this.drawActionSelection();
  2443. };
  2444.  
  2445. BattleManagerTBS.getActionAoE = function () {
  2446. var obj = this.activeAction().item();
  2447. var data = this.activeEntity().getObjectAoEData(obj);
  2448. var center = this._activeCell.toCoords();
  2449. var param = this.makeObjAoEParam(obj, this.activeEntity(), center);
  2450. return this.getScopeFromData(data, center, param);
  2451. };
  2452.  
  2453. BattleManagerTBS.validateActionSelection = function () {
  2454. if (!this.cursorOnActionScope()) {
  2455. SoundManager.playBuzzer();
  2456. return;
  2457. }
  2458. SoundManager.playOk();
  2459.  
  2460. this.getLayer("scopes").clear();
  2461. this.clearActionSelection();
  2462.  
  2463. var cell = this.getCellAt(this.cursor().cellX, this.cursor().cellY);
  2464. this.activeEntity().lookAt(cell);
  2465. this.processAction();
  2466. };
  2467.  
  2468. BattleManagerTBS.touchActionSelection = function (selectedCell) {
  2469. var oldActiveCell = this._activeCell;
  2470. this.setCursorCell(selectedCell);
  2471. if (this.cursorOnActionScope() && InputHandlerTBS.lastSelectedCell().isSame(selectedCell)) {
  2472. this.validateActionSelection();
  2473. }
  2474. };
  2475.  
  2476. BattleManagerTBS.onActionCancel = function () {
  2477. this._subPhase = "";
  2478. this.getLayer("scopes").clear();
  2479. this.clearActionSelection();
  2480. this._actionScope = {};
  2481.  
  2482. LeUtilities.getScene().showCommandWindow();
  2483. var cell = this.activeEntity().getCell();
  2484. this.setCursorCell(cell);
  2485.  
  2486. Input.clear();
  2487. SoundManager.playCancel();
  2488. };
  2489.  
  2490. BattleManagerTBS.isActionScopeAvailable = function () {
  2491. return this.actionScope() && this.actionScope().cells && this.actionScope().center;
  2492. };
  2493.  
  2494. BattleManagerTBS.processAction = function () {
  2495. this._subPhase = "obj_invokation";
  2496. var action = this.activeAction();
  2497. var item = action.item();
  2498. var entity = this.activeEntity();
  2499. var id = action.isAttack() ? entity.getWeaponSequenceData() : entity.getObjectSequenceData(item);
  2500. this.activeBattler().useItem(item);
  2501. action.applyGlobal();
  2502. entity.startSequence(id, action);
  2503. };
  2504.  
  2505. BattleManagerTBS.applyObjEffects = function (user, item, targets, hitAnim, animDelay) {
  2506. this.activeAction().setItemObject(item);
  2507. this.prepareDirectionalDamageBonus(user, targets, item);
  2508. targets.forEach(function (target) {
  2509. this.activeAction().apply(target.battler());
  2510. if (target.battler().result().isHit()) {
  2511. if (hitAnim) {
  2512. var cell = target.getCell();
  2513. this.getLayer("animations").newAnimation(hitAnim, false, animDelay, cell, target._sprite);
  2514. }
  2515. if (target.battler().result().hpDamage > 0)
  2516. target.callSequence("damaged");
  2517. } else {
  2518. target.callSequence("evaded");
  2519. }
  2520. target.addPopup();
  2521. target.checkDeath();
  2522. }.bind(this));
  2523. this.resetDirectionalDamageBonus(targets);
  2524. this.refreshBattlersStatus();
  2525. };
  2526.  
  2527. BattleManagerTBS.applyObjEffectsOnMap = function (user, item, cellTargets, hitAnim, animDelay) {
  2528. this.activeAction().setItemObject(item);
  2529. item = this.activeAction().item();
  2530. cellTargets.forEach(function (cell) {
  2531. var target = cell.getEntity();
  2532. var sprite;
  2533. if (target) {
  2534. this.prepareDirectionalDamageBonus(user, [target], item);
  2535. this.activeAction().apply(target.battler());
  2536. if (target.battler().result().isHit()) {
  2537. sprite = target._sprite;
  2538. if (target.battler().result().hpDamage > 0)
  2539. target.callSequence("damaged");
  2540. } else {
  2541. target.callSequence("evaded");
  2542. }
  2543. target.addPopup();
  2544. target.checkDeath();
  2545. this.resetDirectionalDamageBonus([target]);
  2546. }
  2547. if (hitAnim)
  2548. this.getLayer("animations").newAnimation(hitAnim, false, animDelay, cell, sprite);
  2549. }.bind(this));
  2550. this.refreshBattlersStatus();
  2551. };
  2552.  
  2553. BattleManagerTBS.applyFloatingDamage = function (amount, target) {
  2554. target.battler().gainHp(-amount);
  2555. target.addPopup();
  2556. target.callSequence("damaged");
  2557. target.checkDeath();
  2558. };
  2559.  
  2560. BattleManagerTBS.refreshBattlersStatus = function () {
  2561. LeUtilities.getScene()._windowStatus.refresh();
  2562. };
  2563.  
  2564. BattleManagerTBS.onActionEnd = function () {
  2565. this._subPhase = "";
  2566. this._actionScope = {};
  2567. var cell = this.activeEntity().getCell();
  2568. this.setCursorCell(cell);
  2569. Input.clear();
  2570. this.activeEntity()._actionPerformed = true;
  2571. LeUtilities.getScene().showStatusWindow(this.activeBattler());
  2572.  
  2573. var obj = this.activeAction().item();
  2574. if (this.activeEntity().passAfterObjUse(obj))
  2575. this.processCommandPass();
  2576. else if (this.activeBattler().isActor()) {
  2577. if (Lecode.S_TBS.autoPass && !this.activeEntity().canMoveCommand())
  2578. this.processCommandPass();
  2579. else
  2580. LeUtilities.getScene().showCommandWindow();
  2581. }
  2582.  
  2583. this.getLayer("scopes").clear();
  2584. this.getLayer("scopes").clearSelection();
  2585.  
  2586. this.updateEndOfActionEvents();
  2587. };
  2588.  
  2589. BattleManagerTBS.processCommandPass = function () {
  2590. var entity = this.activeEntity();
  2591. var cell = entity.getCell();
  2592. if (this.activeBattler().isActor() && Lecode.S_TBS.enableDirectionalFacing) {
  2593. this._subPhase = "directionSelector_input";
  2594. this._beforePassDir = entity.getDir();
  2595. this._directionSelector.set(cell, entity);
  2596. } else {
  2597. this.validatePass();
  2598. }
  2599. };
  2600.  
  2601. BattleManagerTBS.cancelPass = function () {
  2602. this._subPhase = "";
  2603. this._directionSelector.hide();
  2604. LeUtilities.getScene().showCommandWindow();
  2605. Input.clear();
  2606. SoundManager.playCancel();
  2607. this.activeEntity().setDir(this._beforePassDir);
  2608. };
  2609.  
  2610. BattleManagerTBS.validatePass = function () {
  2611. this._directionSelector.hide();
  2612. this.turnEnd();
  2613. };
  2614.  
  2615. BattleManagerTBS.passByTouch = function (selectedCell) {
  2616. var entity = this._directionSelector._battlerEntity;
  2617. entity.lookAt(selectedCell);
  2618. this.validatePass();
  2619. };
  2620.  
  2621. BattleManagerTBS.turnEnd = function () {
  2622. this._subPhase = "turn_end";
  2623. this.activeEntity().onTurnEnd();
  2624. };
  2625.  
  2626. BattleManagerTBS.updateEndOfActionEvents = function () {
  2627. this.checkDeathAndVictory();
  2628. };
  2629.  
  2630. BattleManagerTBS.updateEndOfTurnEvents = function () {
  2631. var canContinue = this.updateEvents() && this.checkDeathAndVictory();
  2632. if (canContinue) {
  2633. this.nextTurn();
  2634. }
  2635. };
  2636.  
  2637. BattleManagerTBS.updateEvents = function () {
  2638. $gameTroop.updateInterpreter();
  2639. $gameParty.requestMotionRefresh();
  2640. if ($gameTroop.isEventRunning()) {
  2641. return false;
  2642. }
  2643. $gameTroop.setupBattleEvent();
  2644. if ($gameTroop.isEventRunning() || SceneManager.isSceneChanging()) {
  2645. return false;
  2646. }
  2647. return true;
  2648. };
  2649.  
  2650. BattleManagerTBS.nextTurn = function () {
  2651. do {
  2652. if (this._activeIndex === 0)
  2653. $gameTroop.increaseTurn();
  2654. this._activeIndex++;
  2655. if (this._activeIndex >= this._turnOrder.length)
  2656. this._activeIndex = 0;
  2657. } while (this.activeEntity()._dead);
  2658. this._turnOrderVisual.updateOnNextTurn(this._turnOrder, this._activeIndex);
  2659. this.startTurn();
  2660. };
  2661.  
  2662. BattleManagerTBS.processCommandCancel = function () {
  2663. LeUtilities.getScene().showEndCommandWindow();
  2664. };
  2665.  
  2666. BattleManagerTBS.onEndCommandInput = function (command) {
  2667. switch (command) {
  2668. case "options":
  2669. break;
  2670. case "escape":
  2671. this.processEscape();
  2672. break;
  2673. case "cancel":
  2674. this.resumeBattle();
  2675. break;
  2676. }
  2677. };
  2678.  
  2679. BattleManagerTBS.resumeBattle = function () {
  2680. LeUtilities.getScene().showCommandWindow();
  2681. Input.clear();
  2682. };
  2683.  
  2684. BattleManagerTBS.processEscape = function () {
  2685. $gameParty.performEscape();
  2686. var success = BattleManager._preemptive ? true : (Math.random() < BattleManager._escapeRatio);
  2687. if (success) {
  2688. BattleManager._escaped = true;
  2689. SoundManager.playEscape();
  2690. this.prepareAbort();
  2691. } else {
  2692. var audio = {};
  2693. audio.name = Lecode.S_TBS.escapeSound;
  2694. audio.pitch = 100;
  2695. audio.volume = 90;
  2696. audio.pan = 0;
  2697. AudioManager.playSe(audio);
  2698. BattleManager._escapeRatio += 0.1;
  2699. this.resumeBattle();
  2700. this.nextTurn();
  2701. }
  2702. };
  2703.  
  2704. BattleManagerTBS.checkDeathAndVictory = function () {
  2705. if ($gameParty.isAllDead()) {
  2706. this.prepareDefeat();
  2707. return false;
  2708. } else if ($gameTroop.isAllDead()) {
  2709. this.prepareVictory();
  2710. return false;
  2711. }
  2712. return true;
  2713. };
  2714.  
  2715. BattleManagerTBS.prepareAbort = function () {
  2716. this._battleStopStatus = "abort";
  2717. this.stopBattle();
  2718. };
  2719.  
  2720. BattleManagerTBS.prepareDefeat = function () {
  2721. this._battleStopStatus = "defeat";
  2722. this.stopBattle();
  2723. };
  2724.  
  2725. BattleManagerTBS.prepareVictory = function () {
  2726. this._battleStopStatus = "victory";
  2727. this.stopBattle();
  2728. this.allyEntities().forEach(function (entity) {
  2729. entity.startSequence("victory");
  2730. });
  2731. };
  2732.  
  2733. BattleManagerTBS.processDefeat = function () {
  2734. BattleManager.processDefeat();
  2735. this._phase = "battle_end";
  2736. this.enemyEntities().forEach(function (entity) {
  2737. entity.startSequence("victory");
  2738. });
  2739. };
  2740.  
  2741. BattleManagerTBS.processAbort = function () {
  2742. BattleManager.processAbort();
  2743. this._phase = "battle_end";
  2744. };
  2745.  
  2746. BattleManagerTBS.processVictory = function () {
  2747. BattleManager.processVictory();
  2748. this._phase = "battle_end";
  2749. };
  2750.  
  2751. BattleManagerTBS.stopBattle = function () {
  2752. InputHandlerTBS.setActive(false);
  2753. this._phase = "battle_stopping";
  2754. this.wait(Lecode.S_TBS.endOfBattleWait);
  2755. };
  2756.  
  2757. BattleManagerTBS.updateBattleStopping = function () {
  2758. LeUtilities.getScene()._windowCommand.close();
  2759. this._directionSelector.hide();
  2760. var waiting = this.isWaiting();
  2761. switch (this._battleStopStatus) {
  2762. case "abort":
  2763. waiting = waiting || this.isWaitingForAbortEvents();
  2764. break;
  2765. case "victory":
  2766. waiting = waiting || this.isWaitingForVictoryEvents();
  2767. break;
  2768. case "defeat":
  2769. waiting = waiting || this.isWaitingForDefeatEvents();
  2770. break;
  2771. }
  2772. if (!waiting) {
  2773. switch (this._battleStopStatus) {
  2774. case "abort":
  2775. this.processAbort();
  2776. break;
  2777. case "victory":
  2778. this.processVictory();
  2779. break;
  2780. case "defeat":
  2781. this.processDefeat();
  2782. break;
  2783. }
  2784. }
  2785. };
  2786.  
  2787. BattleManagerTBS.isWaitingForAbortEvents = function () {
  2788. return false;
  2789. };
  2790.  
  2791. BattleManagerTBS.isWaitingForVictoryEvents = function () {
  2792. return false;
  2793. };
  2794.  
  2795. BattleManagerTBS.isWaitingForDefeatEvents = function () {
  2796. return false;
  2797. };
  2798.  
  2799. BattleManagerTBS.updateBattleEnd = function () {
  2800. BattleManager.updateBattleEnd();
  2801. this._phase = null;
  2802. };
  2803.  
  2804. BattleManagerTBS.onEntityDeath = function (entity) {
  2805. if (this.activeEntity() === entity)
  2806. this.turnEnd();
  2807. this._turnOrderVisual.updateOnEntityDeath(this._turnOrder, this._activeIndex);
  2808. };
  2809.  
  2810.  
  2811.  
  2812. BattleManagerTBS.drawActionScope = function (entity, data) {
  2813. var center = entity.getCell().toCoords();
  2814. var color = this._actionScopeParam.color;
  2815. var opacity = this._actionScopeParam.opacity;
  2816. var invalidOpa = this._actionScopeParam.invalidOpa;
  2817. var param = this.makeObjScopeParam(null, entity, center);
  2818. var scope = this.getScopeFromData(data, center, param);
  2819. var invalidCondition = "!cell._scopeVisible || (cell.isObstacle() && !cell.isThereEntity())";
  2820. this.getLayer("scopes").clear();
  2821. this.drawScope(scope, color, opacity, invalidOpa, invalidCondition);
  2822. this._actionScope = {};
  2823. this._actionScope.cells = scope;
  2824. this._actionScope.center = center;
  2825. };
  2826.  
  2827. BattleManagerTBS.makeObjScopeParam = function (obj, entity, center) {
  2828. obj = obj || this.activeAction().item();
  2829. var param = {
  2830. user: entity,
  2831. dir: dir = entity.getDirectionTo(center),
  2832. need_check_los: true,
  2833. exclude_center: true,
  2834. line_of_sight: true,
  2835. remove_nonvisibleCells: false
  2836. };
  2837. if (!obj) return param;
  2838. var data = obj.leTbs_scopeParam;
  2839. data = LeUtilities.stringSplit(data, ",");
  2840. data.forEach(function (arg) {
  2841. if (arg.match(/include_center/i))
  2842. param.exclude_center = false;
  2843. else if (arg.match(/through_obstacles/i))
  2844. param.line_of_sight = false;
  2845. else if (arg.match(/need_free_cell/i))
  2846. param.need_free_cells = true;
  2847. }.bind(this));
  2848. return param;
  2849. };
  2850.  
  2851. BattleManagerTBS.makeObjAoEParam = function (obj, entity, center) {
  2852. obj = obj || this.activeAction().item();
  2853. var param = {
  2854. user: entity,
  2855. dir: dir = entity.getDirectionTo(center)
  2856. };
  2857. return param;
  2858. };
  2859.  
  2860. BattleManagerTBS.cursorOnActionScope = function () {
  2861. if (!this.isActionScopeAvailable()) return false;
  2862. for (var i = 0; i < this.actionScope().cells.length; i++) {
  2863. var cell = this.actionScope().cells[i];
  2864. if (cell._scopeVisible && !(cell.isObstacle() && !cell.isThereEntity())) {
  2865. if (cell.x == this.cursor().cellX && cell.y == this.cursor().cellY) {
  2866. console.log("Visible: ", cell.x, " ", cell.y);
  2867. return true;
  2868. }
  2869. }
  2870. }
  2871. return false;
  2872. };
  2873.  
  2874. BattleManagerTBS.drawActionSelection = function () {
  2875. this.clearActionSelection();
  2876. var color = this._actionScopeParam.color;
  2877. var opacity = this._actionScopeParam.selectedOpacity;
  2878. for (var i = 0; i < this._actionAoE.length; i++) {
  2879. var cell = this._actionAoE[i];
  2880. this.getLayer("scopes").drawSelectionCell(cell.x, cell.y, opacity, color);
  2881. }
  2882. };
  2883.  
  2884. BattleManagerTBS.clearActionSelection = function () {
  2885. this.getLayer("scopes").clearSelection();
  2886. };
  2887.  
  2888. BattleManagerTBS.getScopeFromData = function (data, center, param, points) {
  2889. var scope = [];
  2890. if (data.match(/custom\((.+)\)/i)) {
  2891. var scopeData = Lecode.S_TBS.Config.Custom_Scopes[String(RegExp.$1)];
  2892. scope = this.getScopeFromRawData(scopeData, center, param);
  2893. } else if (data.match(/circle\((.+)\)/i)) {
  2894. scope = this.makeCircleScope(center, Number(RegExp.$1), param, points);
  2895. } else if (data.match(/line\((.+)\)/i)) {
  2896. scope = this.makeLineScope(center, Number(RegExp.$1), param, points);
  2897. } else if (data.match(/square\((.+)\)/i)) {
  2898. scope = this.makeSquareScope(center, Number(RegExp.$1), param, points);
  2899. } else if (data.match(/path/i)) {
  2900. scope = this.makePathScope(param);
  2901. } else {
  2902. var cx = center.x;
  2903. var cy = center.y;
  2904. var aoe = eval("[" + data + "]");
  2905. for (var i = 0; i < aoe.length; i++) {
  2906. var cell = this.getCellAt(aoe[i][0], aoe[i][1]);
  2907. if (cell)
  2908. scope.push(cell);
  2909. }
  2910. }
  2911. scope = LeUtilities.uniqArray(scope);
  2912. scope = this.applyParamToScope(scope, center, points, param);
  2913. return scope;
  2914. };
  2915.  
  2916. BattleManagerTBS.getScopeFromRawData = function (scopeData, center, param) {
  2917. var scope = [];
  2918. var cx = center.x;
  2919. var cy = center.y;
  2920. var ux = this.activeEntity()._cellX;
  2921. var uy = this.activeEntity()._cellY;
  2922. var dir = param.dir;
  2923. var dirData = eval("scopeData.data_" + LeUtilities.directionCodeToText(dir));
  2924. var data = dirData ? dirData : scopeData.data;
  2925. var array = eval("[" + data + "]");
  2926. array.forEach(function (arr) {
  2927. var cell = this.getCellAt(arr[0], arr[1]);
  2928. if (cell)
  2929. scope.push(cell);
  2930. }.bind(this));
  2931. return LeUtilities.uniqArray(scope);
  2932. };
  2933.  
  2934. BattleManagerTBS.makeCircleScope = function (center, range, param, points) {
  2935. points = points || range;
  2936. var cells = [];
  2937. var start = param.exclude_center ? 1 : 0;
  2938. var x = center.x,
  2939. y = center.y;
  2940. for (var i = start; i <= range; i++) {
  2941. cells.push(this.getCellAt(x + i, y));
  2942. cells.push(this.getCellAt(x - i, y));
  2943. cells.push(this.getCellAt(x, y + i));
  2944. cells.push(this.getCellAt(x, y - i));
  2945. for (var a = start; a <= range - i; a++) {
  2946. cells.push(this.getCellAt(x - i, y - a));
  2947. cells.push(this.getCellAt(x - i, y + a));
  2948. cells.push(this.getCellAt(x + i, y - a));
  2949. cells.push(this.getCellAt(x + i, y + a));
  2950. }
  2951. }
  2952. return cells;
  2953. };
  2954.  
  2955. BattleManagerTBS.makeSquareScope = function (center, range, param, points) {
  2956. points = points || range;
  2957. var cells = [];
  2958. var x = center.x,
  2959. y = center.y;
  2960. for (var i = -range; i <= range; i++) {
  2961. for (var j = -range; j <= range; j++) {
  2962. if (param.exclude_center && i === 0 && j === 0)
  2963. continue;
  2964. cells.push(this.getCellAt(x + i, y + j));
  2965. }
  2966. }
  2967. return cells;
  2968. };
  2969.  
  2970. BattleManagerTBS.makeLineScope = function (center, range, param, points) {
  2971. points = points || range;
  2972. var cells = [];
  2973. var start = param.exclude_center ? 1 : 0;
  2974. var x = center.x,
  2975. y = center.y;
  2976. for (var i = start; i <= range; i++) {
  2977. cells.push(this.getCellAt(x + i, y));
  2978. cells.push(this.getCellAt(x - i, y));
  2979. cells.push(this.getCellAt(x, y + i));
  2980. cells.push(this.getCellAt(x, y - i));
  2981. }
  2982. return cells;
  2983. };
  2984.  
  2985. BattleManagerTBS.makeCrossScope = function (center, range, param, points) {
  2986. points = points || range;
  2987. var cells = [];
  2988. var start = param.exclude_center ? 1 : 0;
  2989. var x = center.x,
  2990. y = center.y;
  2991. for (var i = start; i <= range; i++) {
  2992. cells.push(this.getCellAt(x + i, y + i));
  2993. cells.push(this.getCellAt(x + i, y - i));
  2994. cells.push(this.getCellAt(x - i, y + i));
  2995. cells.push(this.getCellAt(x - i, y - i));
  2996. }
  2997. return cells;
  2998. };
  2999.  
  3000. BattleManagerTBS.makePathScope = function (param) {
  3001. var sx = param.user.getCell().x;
  3002. var sy = param.user.getCell().y;
  3003. var dx = this._activeCell.x;
  3004. var dy = this._activeCell.y;
  3005. return this.getPathFromAToB(sx, sy, dx, dy, "free");
  3006. };
  3007.  
  3008. BattleManagerTBS.applyParamToScope = function (cells, center, points, param) {
  3009. cells = this.removeInvalidCells(cells);
  3010. if (!param.can_select_obstacles) {
  3011. if (param.remove_obstacles)
  3012. cells = this.removeObstaclesFromScope(cells);
  3013. }
  3014. if (param.cells_reachable) {
  3015. this.checkScopeWalkable(cells, points, center);
  3016. if (param.remove_unreachableCells)
  3017. cells = this.makeScopeReachable(cells, points, center);
  3018. }
  3019. if (param.need_check_los) {
  3020. cells.forEach(function (cell) {
  3021. cell._scopeVisible = true;
  3022. }.bind(this));
  3023. if (param.line_of_sight) {
  3024. this.checkScopeVisibility(cells, center);
  3025. if (param.remove_nonvisibleCells)
  3026. cells = this.makeScopeVisible(cells, center);
  3027. }
  3028. }
  3029. if (param.need_free_cells) {
  3030. cells = this.removeObstaclesFromScope(cells);
  3031. cells = this.removeEntitiesFromScope(cells);
  3032. }
  3033. return cells;
  3034. };
  3035.  
  3036. BattleManagerTBS.removeInvalidCells = function (cells) {
  3037. return cells.filter(function (cell) {
  3038. return cell;
  3039. });
  3040. };
  3041.  
  3042. BattleManagerTBS.removeObstaclesFromScope = function (cells) {
  3043. return cells.filter(function (cell) {
  3044. return !cell.isObstacle();
  3045. });
  3046. };
  3047.  
  3048. BattleManagerTBS.removeEntitiesFromScope = function (cells) {
  3049. return cells.filter(function (cell) {
  3050. return !cell.isThereEntity();
  3051. });
  3052. };
  3053.  
  3054. BattleManagerTBS.checkScopeWalkable = function (cells, range, center) {
  3055. for (var i = 0; i < cells.length; i++) {
  3056. cells[i]._walkable = false;
  3057. }
  3058.  
  3059. var grid = this.getWalkableGridForEasyStar();
  3060. this._easystar.setGrid(grid);
  3061. this._easystar.setAcceptableTiles([0]);
  3062. this._easystar.enableSync();
  3063.  
  3064. var scope = cells.sort(function (cella, cellb) {
  3065. var cellaDist = LeUtilities.distanceBetween(cella, center);
  3066. var cellbDist = LeUtilities.distanceBetween(cellb, center);
  3067. return (cellaDist > cellbDist) ? 1 : ((cellaDist < cellbDist) ? -1 : 0);
  3068. });
  3069. scope.reverse();
  3070. var reachables = [];
  3071. for (i = 0; i < scope.length; i++) {
  3072. var cell = scope[i];
  3073. var isReachable = false;
  3074. for (var j = 0; j < reachables.length; j++) {
  3075. var coord = reachables[j];
  3076. if (coord[0] == cell.x && coord[1] == cell.y) {
  3077. isReachable = true;
  3078. break;
  3079. }
  3080. }
  3081. if (isReachable)
  3082. cell._walkable = true;
  3083. else
  3084. cell._walkable = this.isCellReachable(cell, range, center, reachables);
  3085. reachables = LeUtilities.uniqArray(reachables);
  3086. }
  3087. };
  3088.  
  3089. BattleManagerTBS.makeScopeReachable = function (cells, range, center) {
  3090. return cells.filter(function (cell) {
  3091. return cell._walkable;
  3092. }.bind(this));
  3093. };
  3094.  
  3095. BattleManagerTBS.isCellReachable = function (cell, range, center, reachables) {
  3096. if (cell.getEntity()) {
  3097. if (!cell.getEntity().entitiesCanLayOnMe())
  3098. return false;
  3099. } else if (cell.isObstacle())
  3100. return false;
  3101. var path = [];
  3102. var pathResult = null;
  3103. var sx = center.x;
  3104. var sy = center.y;
  3105. var dx = cell.x;
  3106. var dy = cell.y;
  3107. this._easystar.findPath(sx, sy, dx, dy, function (result) {
  3108. pathResult = result;
  3109. });
  3110. this._easystar.calculate();
  3111. if (!pathResult)
  3112. return false;
  3113. pathResult.shift();
  3114. if (pathResult.length > range)
  3115. return false;
  3116. return true;
  3117. };
  3118.  
  3119. BattleManagerTBS.checkScopeVisibility = function (cells, center) {
  3120. var w = $gameMap.tileWidth();
  3121. var h = $gameMap.tileHeight();
  3122. var cx = center.x * w + w / 2;
  3123. var cy = center.y * h + h / 2;
  3124. var obstacles = [];
  3125. var boundaries = this.getScopeBoundaries(cells);
  3126. for (var x = boundaries.left; x <= boundaries.right; x++) {
  3127. for (var y = boundaries.top; y <= boundaries.bottom; y++) {
  3128. var cell = this.getCellAt(x, y);
  3129. if (cell.isObstacle())
  3130. obstacles.push(cell);
  3131. }
  3132. }
  3133. /*for (var k = 0; k < cells.length; k++) {
  3134. if (cells[k].isObstacle())
  3135. obstacles.push(cells[k]);
  3136. }*/
  3137. var nonVisible = [];
  3138.  
  3139. for (var i = 0; i < cells.length; i++) {
  3140. cells[i]._scopeVisible = true;
  3141. }
  3142.  
  3143. for (i = 0; i < obstacles.length; i++) {
  3144. var cellsToCheck = this.cellsToCheckNearObstacle(obstacles[i], cells, center);
  3145. for (var j = 0; j < cellsToCheck.length; j++) {
  3146. var cellToCheck = cellsToCheck[j];
  3147. if (obstacles[i].x == cellToCheck.x && obstacles[i].y == cellToCheck.y)
  3148. continue;
  3149. var dx = cellToCheck.x * w + w / 2;
  3150. var dy = cellToCheck.y * h + h / 2;
  3151. //- var sprite = SceneManager._scene._spriteset._debugLayer;
  3152. var pixels = LeUtilities.getPixelsOfLine(cx, cy, dx, dy);
  3153. for (var k = 0; k < obstacles.length; k++) {
  3154. var obstacle = obstacles[k];
  3155. if (obstacle.x == center.x && obstacle.y == center.y)
  3156. continue;
  3157. if (obstacle.isSame(cellToCheck))
  3158. continue;
  3159. var x = obstacle.x * w;
  3160. var y = obstacle.y * h;
  3161. for (var m = 0; m < pixels.length; m++) {
  3162. if (LeUtilities.doesRectIncludeCoord(x, y, w, h, pixels[m])) {
  3163. nonVisible.push([cellToCheck.x, cellToCheck.y]);
  3164. m = pixels.length;
  3165. }
  3166. }
  3167. }
  3168. }
  3169. }
  3170.  
  3171. for (i = 0; i < nonVisible.length; i++) {
  3172. for (var j = 0; j < cells.length; j++) {
  3173. if (cells[j].x === nonVisible[i][0] && cells[j].y === nonVisible[i][1]) {
  3174. cells[j]._scopeVisible = false;
  3175. }
  3176. }
  3177. }
  3178. };
  3179.  
  3180. BattleManagerTBS.checkSingleCellVisibility = function (cell, center) {
  3181. var w = $gameMap.tileWidth();
  3182. var h = $gameMap.tileHeight();
  3183. var cx = center.x * w + w / 2;
  3184. var cy = center.y * h + h / 2;
  3185.  
  3186. var obstacles = [];
  3187. for (var i = 0; i < this._groundCells.length; i++) {
  3188. if (this._groundCells[i].isObstacle())
  3189. obstacles.push(this._groundCells[i]);
  3190. }
  3191. cell._scopeVisible = true;
  3192.  
  3193. var dx = cell.x * w + w / 2;
  3194. var dy = cell.y * h + h / 2;
  3195. var pixels = LeUtilities.getPixelsOfLine(cx, cy, dx, dy);
  3196. for (var k = 0; k < obstacles.length; k++) {
  3197. var obstacle = obstacles[k];
  3198. if (obstacle.x === center.x && obstacle.y === center.y)
  3199. continue;
  3200. if (obstacle.isSame(cell))
  3201. continue;
  3202. var x = obstacle.x * w;
  3203. var y = obstacle.y * h;
  3204. for (var m = 0; m < pixels.length; m++) {
  3205. if (LeUtilities.doesRectIncludeCoord(x, y, w, h, pixels[m])) {
  3206. cell._scopeVisible = false;
  3207. return;
  3208. }
  3209. }
  3210. }
  3211. };
  3212.  
  3213. BattleManagerTBS.cellsToCheckNearObstacle = function (obstacle, cells, center) {
  3214. var cx = center.x,
  3215. cy = center.y;
  3216. var result = [];
  3217. var condition;
  3218. if (obstacle.y > cy && obstacle.x > cx)
  3219. condition = "cell.x >= obstacle.x && cell.y >= obstacle.y";
  3220. else if (obstacle.y > cy && obstacle.x < cx)
  3221. condition = "cell.x <= obstacle.x && cell.y >= obstacle.y";
  3222. else if (obstacle.y < cy && obstacle.x > cx)
  3223. condition = "cell.x >= obstacle.x && cell.y <= obstacle.y";
  3224. else if (obstacle.y < cy && obstacle.x < cx)
  3225. condition = "cell.x <= obstacle.x && cell.y <= obstacle.y";
  3226. else if (obstacle.y == cy && obstacle.x < cx)
  3227. condition = "cell.x <= obstacle.x";
  3228. else if (obstacle.y == cy && obstacle.x > cx)
  3229. condition = "cell.x >= obstacle.x";
  3230. else if (obstacle.x == cx && obstacle.y < cy)
  3231. condition = "cell.y <= obstacle.y";
  3232. else if (obstacle.x == cx && obstacle.y > cy)
  3233. condition = "cell.y >= obstacle.y";
  3234. for (var i = 0; i < cells.length; i++) {
  3235. var cell = cells[i];
  3236. if (eval(condition))
  3237. result.push(cell);
  3238. }
  3239. return result;
  3240. };
  3241.  
  3242. BattleManagerTBS.makeScopeVisible = function (cells, center) {
  3243. return cells.filter(function (cell) {
  3244. return !!cell._scopeVisible;
  3245. }.bind(this));
  3246. };
  3247.  
  3248. BattleManagerTBS.getScopeBoundaries = function (cells) {
  3249. var cellsByX = cells.sort(function (cellA, cellB) {
  3250. return (cellA.x > cellB.x) ? 1 : ((cellA.x < cellB.x) ? -1 : 0);
  3251. });
  3252. var rightCell = cellsByX.leU_last();
  3253. var leftCell = cellsByX[0];
  3254. var cellsByY = cells.sort(function (cellA, cellB) {
  3255. return (cellA.y > cellB.y) ? 1 : ((cellA.y < cellB.y) ? -1 : 0);
  3256. });
  3257. var bottomCell = cellsByY.leU_last();
  3258. var topCell = cellsByY[0];
  3259. return {
  3260. left: leftCell.x,
  3261. right: rightCell.x,
  3262. top: topCell.y,
  3263. bottom: bottomCell.y
  3264. };
  3265. };
  3266.  
  3267. BattleManagerTBS.getPathFromAToB = function (sx, sy, dx, dy, gridType) {
  3268. var path = [];
  3269. var pathResult = null;
  3270. var grid = this.getGridForEasyStar();
  3271. if (gridType === "walkable")
  3272. grid = this.getWalkableGridForEasyStar();
  3273. else if (gridType === "free")
  3274. grid = this.getFreeGridForEasyStar();
  3275. this._easystar.setGrid(grid);
  3276. this._easystar.setAcceptableTiles([0]);
  3277. this._easystar.enableSync();
  3278. this._easystar.findPath(sx, sy, dx, dy, function (result) {
  3279. pathResult = result;
  3280. });
  3281. this._easystar.calculate();
  3282. if (!pathResult) return [];
  3283. pathResult.shift();
  3284. for (var i = 0; i < pathResult.length; i++) {
  3285. var cellArr = pathResult[i];
  3286. var cell = this.getCellAt(cellArr.x, cellArr.y);
  3287. path.push(cell);
  3288. }
  3289. return path;
  3290. };
  3291.  
  3292. BattleManagerTBS.getGridForEasyStar = function () {
  3293. var grid = [];
  3294. for (var y = 0; y < $gameMap.height(); y++) {
  3295. var arr = [];
  3296. for (var x = 0; x < $gameMap.width(); x++) {
  3297. var cell = this.getCellAt(x, y);
  3298. if (!cell || cell.isObstacle())
  3299. arr.push(1);
  3300. else
  3301. arr.push(0);
  3302. }
  3303. grid.push(arr);
  3304. }
  3305. return grid;
  3306. };
  3307.  
  3308. BattleManagerTBS.getFreeGridForEasyStar = function () {
  3309. var grid = [];
  3310. for (var y = 0; y < $gameMap.height(); y++) {
  3311. var arr = [];
  3312. for (var x = 0; x < $gameMap.width(); x++) {
  3313. var cell = this.getCellAt(x, y);
  3314. if (!cell)
  3315. arr.push(1);
  3316. else
  3317. arr.push(0);
  3318. }
  3319. grid.push(arr);
  3320. }
  3321. return grid;
  3322. };
  3323.  
  3324. BattleManagerTBS.getWalkableGridForEasyStar = function () {
  3325. var grid = [];
  3326. for (var y = 0; y < $gameMap.height(); y++) {
  3327. var arr = [];
  3328. for (var x = 0; x < $gameMap.width(); x++) {
  3329. var cell = this.getCellAt(x, y);
  3330. if (cell) {
  3331. var entity = cell.getEntity();
  3332. if (entity) {
  3333. arr.push(entity.isPassable() ? 0 : 1);
  3334. } else {
  3335. arr.push(cell.isObstacle() ? 1 : 0);
  3336. }
  3337. } else
  3338. arr.push(1);
  3339. }
  3340. grid.push(arr);
  3341. }
  3342. return grid;
  3343. };
  3344.  
  3345. BattleManagerTBS.drawScope = function (cells, color, opa, invalidOpa, invalidCondition) {
  3346. for (var i = 0; i < cells.length; i++) {
  3347. var cell = cells[i];
  3348. var opacity;
  3349. if (eval(invalidCondition))
  3350. opacity = invalidOpa;
  3351. else
  3352. opacity = opa;
  3353. this.getLayer("scopes").drawCell(cell.x, cell.y, opacity, color);
  3354. }
  3355. };
  3356.  
  3357. BattleManagerTBS.isCellInScope = function (cell, scope) {
  3358. for (var i = 0; i < scope.length; i++) {
  3359. if (scope[i].isSame(cell))
  3360. return true;
  3361. }
  3362. return false;
  3363. };
  3364.  
  3365. BattleManagerTBS.getEntitiesInScope = function (scope) {
  3366. var entities = [];
  3367. for (var i = 0; i < scope.length; i++) {
  3368. var cell = scope[i];
  3369. var entity = cell.getEntity();
  3370. if (entity)
  3371. entities.push(entity);
  3372. }
  3373. return entities;
  3374. };
  3375.  
  3376. BattleManagerTBS.processCollisionEffects = function (entity) {
  3377. var collisionData = entity._collisionData;
  3378. if (!collisionData.endCell) return;
  3379.  
  3380. var distance = collisionData.distance;
  3381. var covered = collisionData.covered;
  3382. var user = collisionData.user;
  3383. var obj = collisionData.obj;
  3384. var a = user.battler();
  3385. var b = entity.battler();
  3386. var formula = Lecode.S_TBS.defaultCollisionFormula;
  3387. if (obj && obj.leTbs_collisionFormula) {
  3388. formula = obj.leTbs_collisionFormula;
  3389. }
  3390. var damage = Math.floor(eval(formula));
  3391. var dmgBonus = user.getCollisionDamageBonus(damage);
  3392. var dmgMinus = entity.getCollisionDamageReduction(damage);
  3393. damage += dmgBonus - dmgMinus;
  3394. if (damage < 0) damage = 0;
  3395. this.applyFloatingDamage(Math.floor(damage), entity);
  3396.  
  3397. var endCell = collisionData.endCell;
  3398. var next = endCell.getEntity();
  3399. while (next) {
  3400. damage -= damage * Lecode.S_TBS.collissionDamageChainRate;
  3401. this.applyFloatingDamage(Math.floor(damage), next);
  3402. var oldDir = next.getDir();
  3403. next.setDir(collisionData.dir);
  3404. endCell = next.getForwardCell();
  3405. next.setDir(oldDir);
  3406. next = endCell.getEntity();
  3407. }
  3408. entity._collisionData = null;
  3409. };
  3410.  
  3411. BattleManagerTBS.prepareDirectionalDamageBonus = function (user, targets, item) {
  3412. var oldUserDir = user.getDir();
  3413. for (var i = 0; i < targets.length; i++) {
  3414. var entity = targets[i];
  3415. if (entity === user) continue;
  3416. var dir = entity.getDir();
  3417. var effects = 0;
  3418. user.lookAt(entity.getCell());
  3419. if (user.getDir() === dir) {
  3420. effects = Lecode.S_TBS.backDirectionalDamageEffects;
  3421. effects += item.leTbs_directionalDmgBonus.back;
  3422. effects += user.getDirectionalDmgBonus("back");
  3423. effects -= entity.getDirectionalDmgReduction("back");
  3424. } else if (user.getDir() === 2 && dir === 8 || user.getDir() === 8 && dir === 2 ||
  3425. user.getDir() === 4 && dir === 6 || user.getDir() === 6 && dir === 4) {
  3426. effects = Lecode.S_TBS.faceDirectionalDamageEffects;
  3427. effects += item.leTbs_directionalDmgBonus.face;
  3428. effects += user.getDirectionalDmgBonus("face");
  3429. effects -= entity.getDirectionalDmgReduction("face");
  3430. } else {
  3431. effects = Lecode.S_TBS.sideDirectionalDamageEffects;
  3432. effects += item.leTbs_directionalDmgBonus.side;
  3433. effects += user.getDirectionalDmgBonus("side");
  3434. effects -= entity.getDirectionalDmgReduction("side");
  3435. }
  3436. entity.battler().leTBS_setDirectionalDmgEffects(effects * 0.01);
  3437. }
  3438. user.setDir(oldUserDir);
  3439. };
  3440.  
  3441. BattleManagerTBS.resetDirectionalDamageBonus = function (targets) {
  3442. for (var i = 0; i < targets.length; i++) {
  3443. targets[i].battler().leTBS_setDirectionalDmgEffects(0);
  3444. }
  3445. };
  3446.  
  3447.  
  3448. BattleManagerTBS.allyStartCells = function () {
  3449. return this._startCells.filter(function (cell) {
  3450. return cell._type === "ally";
  3451. });
  3452. };
  3453.  
  3454. BattleManagerTBS.enemyStartCells = function () {
  3455. return this._startCells.filter(function (cell) {
  3456. return cell._type === "enemy";
  3457. });
  3458. };
  3459.  
  3460. BattleManagerTBS.allyEntities = function () {
  3461. return this.allEntities().filter(function (ent) {
  3462. return ent._battler.isActor();
  3463. });
  3464. };
  3465.  
  3466. BattleManagerTBS.enemyEntities = function () {
  3467. return this.allEntities().filter(function (ent) {
  3468. return !ent._battler.isActor();
  3469. });
  3470. };
  3471.  
  3472. BattleManagerTBS.isCellFree = function (cell) {
  3473. if (cell == null) return true;
  3474. return cell.getEntity() == null;
  3475. };
  3476.  
  3477. BattleManagerTBS.getEntityCell = function (entity) {
  3478. return this._groundCells.leU_find(function (c) {
  3479. return entity._cellX === c.x && entity._cellY === c.y;
  3480. }.bind(this));
  3481. };
  3482.  
  3483. BattleManagerTBS.getCellAt = function (x, y) {
  3484. return this._groundCells.leU_find(function (c) {
  3485. return x == c.x && y == c.y;
  3486. }.bind(this));
  3487. };
  3488.  
  3489. BattleManagerTBS.getEntitiesXY = function (excludeActive) {
  3490. var arr = [];
  3491. if (!this.allEntities()) return arr;
  3492. for (var i = 0; i < this.allEntities().length; i++) {
  3493. var entity = this.allEntities()[i];
  3494. if (!(excludeActive && entity == this.activeEntity()))
  3495. arr.push([entity._cellX, entity._cellY]);
  3496. }
  3497. return arr;
  3498. };
  3499.  
  3500. BattleManagerTBS.battlerEntities = function () {
  3501. return this.allEntities();
  3502. };
  3503.  
  3504. BattleManagerTBS.getEntityByBattler = function (battler) {
  3505. var entities = this.allEntities();
  3506. for (var i = 0; i < entities.length; i++) {
  3507. var entity = entities[i];
  3508. if (entity.battler() === battler)
  3509. return entity;
  3510. }
  3511. };
  3512.  
  3513. BattleManagerTBS.canEndPlacementPhase = function () {
  3514. return this._placeAllies.length === 0;
  3515. };
  3516.  
  3517. BattleManagerTBS.centerActiveCell = function () {
  3518. this.centerCell(this._activeCell);
  3519. };
  3520.  
  3521. BattleManagerTBS.centerCell = function (cell) {
  3522. var oldX = $gameMap._displayX;
  3523. var oldY = $gameMap._displayY;
  3524. $gamePlayer.center(cell.x, cell.y);
  3525. this.adaptLayersPos();
  3526. this.adaptMapVisuals(oldX, oldY);
  3527. };
  3528.  
  3529. BattleManagerTBS.scrollRight = function (distance) {
  3530. var oldX = $gameMap._displayX;
  3531. var oldY = $gameMap._displayY;
  3532. $gameMap.setDisplayPos(oldX + distance, oldY);
  3533. this.adaptLayersPos();
  3534. this.adaptMapVisuals(oldX, oldY);
  3535. };
  3536.  
  3537. BattleManagerTBS.scrollDown = function (distance) {
  3538. var oldX = $gameMap._displayX;
  3539. var oldY = $gameMap._displayY;
  3540. $gameMap.setDisplayPos(oldX, oldY + distance);
  3541. this.adaptLayersPos();
  3542. this.adaptMapVisuals(oldX, oldY);
  3543. };
  3544.  
  3545. BattleManagerTBS.scrollLeft = function (distance) {
  3546. this.scrollRight(-distance);
  3547. };
  3548.  
  3549. BattleManagerTBS.scrollUp = function (distance) {
  3550. this.scrollDown(-distance);
  3551. };
  3552.  
  3553. BattleManagerTBS.adaptLayersPos = function () {
  3554. this.movableLayers().forEach(function (layer) {
  3555. layer.x = -$gameMap._displayX * $gameMap.tileWidth();
  3556. layer.y = -$gameMap._displayY * $gameMap.tileHeight();
  3557. });
  3558. };
  3559.  
  3560. BattleManagerTBS.adaptMapVisuals = function (oldX, oldY) {
  3561. var diffX = oldX - $gameMap._displayX;
  3562. var diffY = oldY - $gameMap._displayY;
  3563. this.mapVisuals().forEach(function (visual) {
  3564. visual.x += diffX * $gameMap.tileWidth();
  3565. visual.y += diffY * $gameMap.tileHeight();
  3566. });
  3567. };
  3568.  
  3569. BattleManagerTBS.movableLayers = function () {
  3570. return [this.getLayer("scopes"), this.getLayer("ground"), this.getLayer("groundEntities"), this.getLayer("battlers"),
  3571. this.getLayer("animations"), this.getLayer("movableInfo")
  3572. ];
  3573. };
  3574.  
  3575. BattleManagerTBS.mapVisuals = function () {
  3576. var scene = LeUtilities.getScene();
  3577. return [scene._windowPlacement, scene._windowCommand, scene._windowSkill, scene._windowItem];
  3578. };
  3579.  
  3580.  
  3581. /*-------------------------------------------------------------------------
  3582. * AI Manager
  3583. -------------------------------------------------------------------------*/
  3584. function TBSAiManager() {
  3585. this.initialize.call(this, arguments);
  3586. }
  3587.  
  3588. TBSAiManager.prototype.initialize = function () {
  3589. this._entity = null;
  3590. this._battler = null;
  3591. this._commandRunning = null;
  3592. this._ifArray = [];
  3593. this._targetData = null;
  3594. this._cellTarget = null;
  3595. this._failureCode = "";
  3596. this._actionData = null;
  3597. };
  3598.  
  3599. TBSAiManager.prototype.process = function (entity) {
  3600. this._entity = entity;
  3601. this._battler = entity._battler;
  3602. this._phase = 0;
  3603. this._commands = this.getBehavior().slice();
  3604. this._commandNextPhaseCallBack = null;
  3605. this._commandExtraData = {};
  3606. this.makeOffenseData();
  3607. };
  3608.  
  3609. TBSAiManager.prototype.makeOffenseData = function () {
  3610. this._commandPhase = "making_offense_data";
  3611. this._construction = {};
  3612. var user = this._battler;
  3613. var entity = this._entity;
  3614. var center = entity.getCell().toCoords();
  3615. var enemies = this.getEnemiesOf(user, true);
  3616. var movePoints = entity.getMovePoints();
  3617. var skills = this.getUsableSkills(user);
  3618.  
  3619. this._construction.offenses = [];
  3620. this._construction.offenseData = [];
  3621.  
  3622. for (var i = 0; i < skills.length; i++) {
  3623. var skill = skills[i];
  3624. if (skill.id === user.attackSkillId() || skill.leTbs_aiOffenseType) {
  3625. this._construction.offenses.push(skill);
  3626. }
  3627. }
  3628.  
  3629. this._construction.enemies = enemies.sort(function (enta, entb) {
  3630. var cellaDist = LeUtilities.distanceBetween(enta, entity);
  3631. var cellbDist = LeUtilities.distanceBetween(entb, entity);
  3632. return (cellaDist > cellbDist) ? 1 : ((cellaDist < cellbDist) ? -1 : 0);
  3633. });
  3634. };
  3635.  
  3636. TBSAiManager.prototype.updateOffenseData = function () {
  3637. var enemy = this._construction.enemies.shift();
  3638. if (enemy) {
  3639. var offenses = this._construction.offenses;
  3640. var entity = this._entity;
  3641. var center = entity.getCell().toCoords();
  3642.  
  3643. for (var i = 0; i < offenses.length; i++) {
  3644. var offense = offenses[i];
  3645. var cellToMoveTo = this.getCellToMoveToForAction(entity, enemy, offense, center);
  3646. if (cellToMoveTo) {
  3647. var action = {};
  3648. var reqMp = LeUtilities.distanceBetweenCells(entity.getCell(), cellToMoveTo);
  3649. action.requiredMp = reqMp;
  3650. action.cellToMoveTo = cellToMoveTo;
  3651. action.target = enemy;
  3652. action.userCell = entity.getCell();
  3653. action.obj = offense;
  3654. this._construction.offenseData.push(action);
  3655. }
  3656. }
  3657. } else {
  3658. this._offenseData = this._construction.offenseData;
  3659. this._commandPhase = "init";
  3660. }
  3661. };
  3662.  
  3663. TBSAiManager.prototype.getClosestActionCellToTarget = function (target, obj, center) {
  3664. var entity = this._entity;
  3665. var data = obj.id === entity._battler.attackSkillId() ? entity.getAttackScopeData() : entity.getObjectScopeData(obj);
  3666. var param = this.BM().makeObjScopeParam(obj, entity, center);
  3667. var scope = this.BM().getScopeFromData(data, center, param);
  3668. var closestCell = LeUtilities.closestByDistance(target.getCell(), scope);
  3669.  
  3670. var aoeData = obj.id === entity._battler.attackSkillId() ? entity.getAttackAoEData() : entity.getObjectAoEData(obj);
  3671. var aoeCenter = closestCell.toCoords();
  3672. param = this.BM().makeObjAoEParam(obj, entity, aoeCenter);
  3673. var aoe = this.BM().getScopeFromData(aoeData, aoeCenter, param);
  3674. var closestCellInAoE = LeUtilities.closestByDistance(target.getCell(), aoe);
  3675. return closestCellInAoE;
  3676. };
  3677.  
  3678. TBSAiManager.prototype.getCellToMoveToForAction = function (entity, target, obj, center) {
  3679. var movePoints = entity.getMovePoints();
  3680. var moveParam = this.BM().makeMoveScopeParam(entity);
  3681. var moveData = entity.getMoveScopeData();
  3682. var scope = this.BM().getScopeFromData(moveData, center, moveParam, movePoints);
  3683.  
  3684. var closestCell = this.getClosestActionCellToTarget(target, obj, entity.getCell());
  3685. var exactDistance = LeUtilities.distanceBetweenCells(closestCell, target.getCell());
  3686.  
  3687. scope = scope.filter(function (cell) {
  3688. return cell._walkable && LeUtilities.distanceBetweenCells(cell, entity.getCell()) === exactDistance;
  3689. }.bind(this));
  3690.  
  3691. //- Sort by closest cell to the user
  3692. var cellsToCheck = scope.sort(function (a, b) {
  3693. var obj_aDist = LeUtilities.distanceBetweenCells(a, entity.getCell());
  3694. var obj_bDist = LeUtilities.distanceBetweenCells(b, entity.getCell());
  3695. return (obj_aDist > obj_bDist) ? 1 : ((obj_aDist < obj_bDist) ? -1 : 0);
  3696. }.bind(this));
  3697.  
  3698. var cellToMoveTo = null;
  3699. while (cellsToCheck.length > 0) {
  3700. var cell = cellsToCheck.shift();
  3701. var currentCenter = cell.toCoords();
  3702. var oldCell = entity.getCell();
  3703. entity.setCell(cell);
  3704. //- This call set the los BTW
  3705. closestCell = this.getClosestActionCellToTarget(target, obj, currentCenter);
  3706. entity.setCell(oldCell);
  3707. if (closestCell.isSame(target.getCell()) && closestCell._scopeVisible) {
  3708. cellToMoveTo = cell;
  3709. break;
  3710. }
  3711. }
  3712. return cellToMoveTo;
  3713. };
  3714.  
  3715. TBSAiManager.prototype.getBehavior = function () {
  3716. return Lecode.S_TBS.Config.AI["attack"];
  3717. };
  3718.  
  3719. TBSAiManager.prototype.currentCommand = function () {
  3720. return this._commands[this._phase];
  3721. };
  3722.  
  3723. TBSAiManager.prototype.nextCommand = function () {
  3724. this._phase++;
  3725. this._commandRunning = null;
  3726. this._commandPhase = "init";
  3727. this._commandNextPhaseCallBack = null;
  3728. this._commandExtraData = {};
  3729. };
  3730.  
  3731. TBSAiManager.prototype.areConditionsOkay = function () {
  3732. if (this._ifArray.length === 0) return true;
  3733. for (var i = 0; i < this._ifArray.length; i++) {
  3734. if (!this._ifArray[i]) return false;
  3735. }
  3736. return true;
  3737. };
  3738.  
  3739. TBSAiManager.prototype.update = function () {
  3740. if (this._commandPhase === "making_offense_data") {
  3741. this.updateOffenseData();
  3742. return;
  3743. }
  3744. if (this._commandRunning) {
  3745. this.updateRunningCommand();
  3746. return;
  3747. }
  3748. var command = this.currentCommand();
  3749. if (command) {
  3750. this.runCommand(command);
  3751. } else
  3752. this.forceEnd();
  3753. };
  3754.  
  3755. TBSAiManager.prototype.forceEnd = function () {
  3756. this.BM().processCommandPass();
  3757. };
  3758.  
  3759. TBSAiManager.prototype.runCommand = function (command) {
  3760. if (command === "else") {
  3761. this.commandElse();
  3762. this.nextCommand();
  3763. return;
  3764. } else if (command === "endif") {
  3765. this.commandEndIf();
  3766. this.nextCommand();
  3767. return;
  3768. }
  3769.  
  3770. if (!command.match(/(.+)\s?:\s?(.+)/i)) {
  3771. this.nextCommand();
  3772. return;
  3773. }
  3774.  
  3775. var main = String(RegExp.$1).trim();
  3776. var paramStr = String(RegExp.$2).trim();
  3777. var param = LeUtilities.stringSplit(paramStr, ",");
  3778. param.forEach(function (p) {
  3779. p = p.trim().replace(" ", "");
  3780. }.bind(this));
  3781.  
  3782. if (main === "if") {
  3783. this.commandIf(paramStr);
  3784. this.nextCommand();
  3785. return;
  3786. }
  3787.  
  3788. if (this.areConditionsOkay()) {
  3789. var functionName = LeUtilities.shrinkTextWithUnderscores(main);
  3790. var func = eval("this.command" + functionName + ".bind(this,param)");
  3791. func();
  3792. this._commandRunning = main;
  3793. } else {
  3794. this.nextCommand();
  3795. }
  3796. };
  3797.  
  3798. TBSAiManager.prototype.commandIf = function (condition) {
  3799. var user = this._battler;
  3800. var entity = this._entity;
  3801. var canUseOffense = this.func_CanUseOffense.bind(this);
  3802. var isTargetValid = this.func_IsTargetValid.bind(this);
  3803. var chance = this.func_Chance.bind(this);
  3804. var failureCode = this.func_FailureCode.bind(this);
  3805. var battlerInRange = this.func_BattlerInRange.bind(this);
  3806. var distanceBetween = this.func_DistanceBetween.bind(this);
  3807. var isInMeleeWith = this.func_IsInMeleeWith.bind(this);
  3808. var pattern = function (str) {
  3809. return this.func_GetPattern() === str;
  3810. }.bind(this);
  3811.  
  3812. var result = eval(condition);
  3813. this._ifArray.push(result);
  3814. };
  3815.  
  3816. TBSAiManager.prototype.commandElse = function () {
  3817. this._ifArray[this._ifArray.length - 1] = !this._ifArray.leU_last();
  3818. };
  3819.  
  3820. TBSAiManager.prototype.commandEndIf = function () {
  3821. this._ifArray.pop();
  3822. };
  3823.  
  3824. TBSAiManager.prototype.commandWait = function (param) {
  3825. var value = Number(param[0]);
  3826. this.BM().wait(value);
  3827. };
  3828.  
  3829. TBSAiManager.prototype.commandCallBehavior = function (param) {
  3830. var id = param[0].trim();
  3831. var commands = Lecode.S_TBS.Config.AI[id].slice();
  3832. commands.reverse();
  3833. for (var i = 0; i < commands.length; i++) {
  3834. this._commands.splice(this._phase + 1, 0, commands[i]);
  3835. }
  3836. };
  3837.  
  3838. TBSAiManager.prototype.commandSearchTarget = function (param) {
  3839. var search = param[0];
  3840. var maxPm = param[1];
  3841.  
  3842. if (maxPm.match(/(.+)%/i))
  3843. maxPm = Number(RegExp.$1) * 0.01 * this._entity.getMovePoints();
  3844. else
  3845. maxPm = Number(maxPm);
  3846. maxPm = Math.floor(maxPm);
  3847. if (LeUtilities.isNumeric(maxPm)) {
  3848. maxPm = Math.floor(maxPm);
  3849. if (maxPm < 1)
  3850. maxPm = 1;
  3851. if (maxPm > this._entity.getMovePoints())
  3852. maxPm = this._entity.getMovePoints();
  3853. }
  3854.  
  3855. var data;
  3856. if (search.match(/enemy/i))
  3857. data = this._offenseData;
  3858.  
  3859. var group = this.getGroupFromActionData(data, maxPm);
  3860. if (!group || group.length === 0) {
  3861. this._targetData = null;
  3862. return;
  3863. }
  3864.  
  3865. if (search.match(/lowest/i)) {
  3866. group = group.sort(function (a, b) {
  3867. a = a._battler;
  3868. b = b._battler;
  3869. return (a.hpRate() > b.hpRate()) ? 1 : ((a.hpRate() < b.hpRate()) ? -1 : 0);
  3870. });
  3871. } else if (search.match(/closest/i)) {
  3872. group = group.sort(function (a, b) {
  3873. var obj_aDist = LeUtilities.distanceBetween(a, this._entity);
  3874. var obj_bDist = LeUtilities.distanceBetween(b, this._entity);
  3875. return (obj_aDist > obj_bDist) ? 1 : ((obj_aDist < obj_bDist) ? -1 : 0);
  3876. }.bind(this));
  3877. }
  3878.  
  3879. this._targetData = null;
  3880. //- Make sure the target is reachable (previously calculated, taken into account when making action data)
  3881. var entity = group[0];
  3882. //console.log("SELECTED TARGET = ", entity._battler.name());
  3883. for (var i = 0; i < data.length; i++) {
  3884. var action = data[i];
  3885. if (action.target === entity) {
  3886. this._targetData = {};
  3887. this._targetData.userCell = action.userCell;
  3888. this._targetData.entity = entity;
  3889. break;
  3890. }
  3891. }
  3892. };
  3893.  
  3894. TBSAiManager.prototype.commandDrawMoveScope = function (param) {
  3895. this.BM().drawMoveScope(this._entity, this._entity.getMovePoints());
  3896. };
  3897.  
  3898. TBSAiManager.prototype.commandMove = function (param) {
  3899. var search = param[0];
  3900. var maxPm = param[1];
  3901.  
  3902. if (!this._entity.canMoveCommand()) return;
  3903.  
  3904. if (maxPm.match(/(.+)%/i))
  3905. maxPm = Number(RegExp.$1) * 0.01 * this._entity.getMovePoints();
  3906. else if (maxPm.match(/minimum/i))
  3907. maxPm = "minimum";
  3908. else
  3909. maxPm = Number(maxPm);
  3910. if (LeUtilities.isNumeric(maxPm)) {
  3911. maxPm = Math.floor(maxPm);
  3912. if (maxPm < 1)
  3913. maxPm = 1;
  3914. if (maxPm > this._entity.getMovePoints())
  3915. maxPm = this._entity.getMovePoints();
  3916. }
  3917.  
  3918. this.commandDrawMoveScope();
  3919. var wait = Lecode.S_TBS.aiWaitTime;
  3920. this.BM().wait(wait);
  3921.  
  3922. this._commandPhase = "move_scope_wait";
  3923. this._commandNextPhaseCallBack = this.commandMoveP2.bind(this, param, search, maxPm);
  3924. };
  3925.  
  3926. TBSAiManager.prototype.commandMoveP2 = function (param, search, maxPm) {
  3927. var target;
  3928. if (search.match(/toward_target/i))
  3929. target = this._targetData.entity;
  3930. else if (search.match(/enemies/i)) {
  3931. target = LeUtilities.closestByDistance(this._entity, this.getEnemiesOf(this._battler, true));
  3932. } else if (search.match(/allies/i)) {
  3933. target = LeUtilities.closestByDistance(this._entity, this.getAlliesOf(this._battler, true));
  3934. }
  3935.  
  3936. if (maxPm === "minimum") {
  3937. maxPm = this._actionData.requiredMp;
  3938. }
  3939.  
  3940. var scope = this.BM().moveScope().cells;
  3941. scope = scope.filter(function (cell) {
  3942. return cell._walkable && LeUtilities.distanceBetweenCells(cell, this._entity.getCell()) <= maxPm;
  3943. }.bind(this));
  3944.  
  3945. var closestCell;
  3946. if (search.match(/toward/i))
  3947. closestCell = LeUtilities.closestByDistance(target.getCell(), scope);
  3948. else
  3949. closestCell = LeUtilities.farthestByDistance(target.getCell(), scope);
  3950.  
  3951. this.BM().setCursorCell(closestCell);
  3952. var wait = Lecode.S_TBS.aiWaitTime;
  3953. this.BM().wait(wait);
  3954.  
  3955. this._commandPhase = "move_selection_wait";
  3956. this._commandNextPhaseCallBack = this.commandMoveP3.bind(this);
  3957. this._commandExtraData.destCell = closestCell;
  3958. this._commandExtraData.savedParams = param.splice();
  3959. };
  3960.  
  3961. TBSAiManager.prototype.commandMoveP3 = function () {
  3962. this._entity.processMovement(this.BM().movePath());
  3963. this._commandPhase = "moving";
  3964. };
  3965.  
  3966. TBSAiManager.prototype.commandMoveForAction = function (param) {
  3967. var cellToMoveTo = this._actionData.cellToMoveTo;
  3968. if (cellToMoveTo.isSame(this._entity.getCell()))
  3969. return;
  3970. this.commandDrawMoveScope();
  3971. var wait = Lecode.S_TBS.aiWaitTime;
  3972. this.BM().wait(wait);
  3973.  
  3974. this._commandPhase = "move_scope_wait";
  3975. this._commandNextPhaseCallBack = this.commandMoveForActionP2.bind(this, param);
  3976. };
  3977.  
  3978. TBSAiManager.prototype.commandMoveForActionP2 = function (param) {
  3979. var cellToMoveTo = this._actionData.cellToMoveTo;
  3980.  
  3981. this.BM().setCursorCell(cellToMoveTo);
  3982. var wait = Lecode.S_TBS.aiWaitTime;
  3983. this.BM().wait(wait);
  3984.  
  3985. this._commandPhase = "move_selection_wait";
  3986. this._commandNextPhaseCallBack = this.commandMoveP3.bind(this);
  3987. this._commandExtraData.destCell = cellToMoveTo;
  3988. this._commandExtraData.savedParams = param;
  3989. };
  3990.  
  3991. TBSAiManager.prototype.commandSetAction = function (param) {
  3992. var type = param[0];
  3993. var priority = param[1];
  3994.  
  3995. var searchedTarget = this._targetData.entity;
  3996. var possibilities = [];
  3997.  
  3998. if (type.match(/damage/i)) {
  3999. var data = this._offenseData;
  4000. for (var i = 0; i < data.length; i++) {
  4001. var action = data[i];
  4002. if (action.target === searchedTarget) {
  4003. possibilities.push(action);
  4004. }
  4005. }
  4006. possibilities = this.sortActionsByDmg(possibilities);
  4007. }
  4008.  
  4009. var action;
  4010. if (type.match(/average/i)) {
  4011. if (possibilities.length < 2) {
  4012. action = possibilities[0];
  4013. } else {
  4014. var array = [];
  4015. for (var i = 1; i < possibilities.length - 1; i++) {
  4016. array.push(possibilities[i]);
  4017. }
  4018. action = LeUtilities.getRandomValueInArray(array);
  4019. }
  4020. } else if (type.match(/best/i)) {
  4021. action = possibilities[0];
  4022. } else {
  4023. action = possibilities.leU_last();
  4024. }
  4025.  
  4026. this._actionData = action;
  4027. };
  4028.  
  4029. TBSAiManager.prototype.sortActionsByDmg = function (actionsData) {
  4030. return actionsData.sort(function (data1, data2) {
  4031. var obj1 = data1.obj;
  4032. var obj2 = data2.obj;
  4033. var dummyAction1 = new Game_Action(this._battler, false);
  4034. dummyAction1.setItemObject(obj1);
  4035. var dummyAction2 = new Game_Action(this._battler, false);
  4036. dummyAction2.setItemObject(obj2);
  4037. var value1 = dummyAction1.evaluate();
  4038. var value2 = dummyAction2.evaluate();
  4039. return (value1 < value2) ? 1 : ((value1 > value2) ? -1 : 0);
  4040. }.bind(this));
  4041. };
  4042.  
  4043. TBSAiManager.prototype.commandUse = function (param) {
  4044. var info = param[0];
  4045.  
  4046. if (!this._entity.canObjCommand()) return;
  4047.  
  4048. var obj;
  4049. if (info.match(/defined_action/i))
  4050. obj = this._actionData.obj;
  4051.  
  4052. if (obj) {
  4053. this.BM().activeAction().setItemObject(obj);
  4054. if (this.BM().activeAction().isAttack())
  4055. this.BM().drawAttackScope(this._entity);
  4056. else
  4057. this.BM().drawSkillScope(this._entity, obj);
  4058. var wait = 40;
  4059. this.BM().wait(wait);
  4060.  
  4061. this._commandPhase = "obj_scope_wait";
  4062. this._commandNextPhaseCallBack = this.commandUseP2.bind(this, obj);
  4063. }
  4064. };
  4065.  
  4066. TBSAiManager.prototype.commandUseP2 = function (obj) {
  4067. var enemy = this._targetData.entity;
  4068. var center = this._entity.getCell().toCoords();
  4069. var cell = this.getClosestActionCellToTarget(enemy, obj, center);
  4070.  
  4071. this.BM().setCursorCell(cell);
  4072. this.BM().updateActionSelection();
  4073. this._entity.lookAt(cell);
  4074. var wait = Lecode.S_TBS.aiWaitTime;
  4075. this.BM().wait(wait);
  4076.  
  4077. this._commandPhase = "obj_selection_wait";
  4078. this._commandNextPhaseCallBack = this.commandUseP3.bind(this, obj);
  4079. };
  4080.  
  4081. TBSAiManager.prototype.commandUseP3 = function (obj) {
  4082. this.BM().getLayer("scopes").clear();
  4083. this.BM().clearActionSelection();
  4084. this.BM().processAction();
  4085. BattleManagerTBS._subPhase = "ai";
  4086. this._commandPhase = "invoking";
  4087. };
  4088.  
  4089. TBSAiManager.prototype.commandPass = function (param) {
  4090. var look = param[0];
  4091. switch (look) {
  4092. case "look_closest_enemy":
  4093. this._entity.lookClosestBattler(this.getEnemiesOf(this._battler, true));
  4094. break;
  4095. case "look_closest_ally":
  4096. this._entity.lookClosestBattler(this.getAlliesOf(this._battler, true));
  4097. break;
  4098. }
  4099. this.BM().processCommandPass();
  4100. };
  4101.  
  4102. TBSAiManager.prototype.commandScript = function (param) {
  4103. var script = param[0];
  4104. eval(script);
  4105. };
  4106.  
  4107. TBSAiManager.prototype.updateRunningCommand = function () {
  4108. var functionName = LeUtilities.shrinkTextWithUnderscores(this._commandRunning);
  4109. var func = eval("this.updateCommand" + functionName);
  4110. if (func) {
  4111. func.call(this);
  4112. } else {
  4113. this.nextCommand();
  4114. }
  4115. /*switch(this._commandRunning) {
  4116. case "wait":
  4117. this.updateCommandWait();
  4118. break;
  4119. case "move":
  4120. this.updateCommandMove();
  4121. break;
  4122. case "move_for_action":
  4123. this.updateCommandMoveForAction();
  4124. break;
  4125. case "use":
  4126. this.updateCommandUse();
  4127. break;
  4128. default:
  4129. this.nextCommand();
  4130. break;
  4131. }*/
  4132. };
  4133.  
  4134. TBSAiManager.prototype.updateCommandWait = function () {
  4135. if (!this.BM().isWaiting())
  4136. this.nextCommand();
  4137. };
  4138.  
  4139. TBSAiManager.prototype.updateCommandMove = function () {
  4140. var phase = this._commandPhase;
  4141. switch (phase) {
  4142. case "move_scope_wait":
  4143. case "move_selection_wait":
  4144. if (!this.BM().isWaiting())
  4145. this._commandNextPhaseCallBack();
  4146. break;
  4147. case "moving":
  4148. if (!this._entity.isMoving()) {
  4149. this.BM().onActiveEntityMoveEnd();
  4150. this.BM()._subPhase = "ai";
  4151. if (this._entity.getCell() === this._commandExtraData.destCell)
  4152. this.nextCommand();
  4153. else
  4154. this.commandMove(this._commandExtraData.savedParams);
  4155. }
  4156. break;
  4157. default:
  4158. this.nextCommand();
  4159. break;
  4160. }
  4161. };
  4162.  
  4163. TBSAiManager.prototype.updateCommandMoveForAction = function () {
  4164. var phase = this._commandPhase;
  4165. switch (phase) {
  4166. case "move_scope_wait":
  4167. case "move_selection_wait":
  4168. if (!this.BM().isWaiting())
  4169. this._commandNextPhaseCallBack();
  4170. break;
  4171. case "moving":
  4172. if (!this._entity.isMoving()) {
  4173. this.BM().onActiveEntityMoveEnd();
  4174. this.BM()._subPhase = "ai";
  4175. if (this._entity.getCell() === this._commandExtraData.destCell)
  4176. this.nextCommand();
  4177. else
  4178. this.commandMoveForAction();
  4179. }
  4180. break;
  4181. default:
  4182. this.nextCommand();
  4183. break;
  4184. }
  4185. };
  4186.  
  4187. TBSAiManager.prototype.updateCommandUse = function () {
  4188. var phase = this._commandPhase;
  4189. switch (phase) {
  4190. case "obj_scope_wait":
  4191. case "obj_selection_wait":
  4192. if (!this.BM().isWaiting())
  4193. this._commandNextPhaseCallBack();
  4194. break;
  4195. case "invoking":
  4196. if (!this.BM().anySequenceRunning()) {
  4197. this.BM().onActionEnd();
  4198. this.BM()._subPhase = "ai";
  4199. this.nextCommand();
  4200. }
  4201. break;
  4202. default:
  4203. this.nextCommand();
  4204. break;
  4205. }
  4206. };
  4207.  
  4208. TBSAiManager.prototype.BM = function () {
  4209. return BattleManagerTBS;
  4210. };
  4211.  
  4212. TBSAiManager.prototype.func_Chance = function (value) {
  4213. return Math.random() < value * 0.01;
  4214. };
  4215.  
  4216. TBSAiManager.prototype.func_IsTargetValid = function () {
  4217. return this._targetData != null;
  4218. };
  4219.  
  4220. TBSAiManager.prototype.func_FailureCode = function () {
  4221. console.log("Code: ", this._failureCode);
  4222. return this._failureCode;
  4223. };
  4224.  
  4225. TBSAiManager.prototype.func_CanUseOffense = function () {
  4226. //this._failureCode = "";
  4227. if (this.getUsableSkills(this._battler).length === 0) {
  4228. this._failureCode = "no_usable_skill";
  4229. return false;
  4230. }
  4231. if (this._offenseData.length <= 0) {
  4232. this._failureCode = "out_of_range";
  4233. return false;
  4234. }
  4235. return true;
  4236. };
  4237.  
  4238. TBSAiManager.prototype.func_BattlerInRange = function (target, action) {
  4239. var entity, obj;
  4240. if (action.match(/defined_action/i)) {
  4241. if (this._actionData)
  4242. obj = this._actionData.obj;
  4243. else
  4244. return false;
  4245. }
  4246. if (target.match(/defined_target/i)) {
  4247. if (this._targetData)
  4248. entity = this._targetData.entity;
  4249. else
  4250. return false;
  4251. }
  4252.  
  4253. var data = (obj.id === this._battler.attackSkillId()) ? this._entity.getAttackScopeData() : this._entity.getObjectScopeData(obj);
  4254. var center = this._entity.getCell().toCoords();
  4255. var param = this.BM().makeObjScopeParam(obj, this._entity, center);
  4256. var scope = this.BM().getScopeFromData(data, center, param);
  4257. for (var i = 0; i < scope.length; i++) {
  4258. var cell = scope[i];
  4259. if (entity.getCell().isSame(cell)) {
  4260. return true;
  4261. }
  4262. }
  4263. return false;
  4264. };
  4265.  
  4266. TBSAiManager.prototype.func_DistanceBetween = function (target) {
  4267. var entity;
  4268. if (target.match(/defined_target/i)) {
  4269. if (this._targetData)
  4270. entity = this._targetData.entity;
  4271. else
  4272. return false;
  4273. }
  4274. return LeUtilities.distanceBetweenCells(entity.getCell(), this._entity.getCell());
  4275. };
  4276.  
  4277. TBSAiManager.prototype.func_IsInMeleeWith = function (target) {
  4278. return this.func_DistanceBetween(target) <= 1;
  4279. };
  4280.  
  4281. TBSAiManager.prototype.func_GetPattern = function () {
  4282. return this._entity.getAiPattern();
  4283. };
  4284.  
  4285. TBSAiManager.prototype.getEnemiesOf = function (battler, needAlive) {
  4286. var group = battler.isActor() ? this.BM().enemyEntities() : this.BM().allyEntities();
  4287. if (needAlive) {
  4288. return group.filter(function (ent) {
  4289. return !ent.battler().isDead();
  4290. });
  4291. } else {
  4292. return group;
  4293. }
  4294. };
  4295.  
  4296. TBSAiManager.prototype.getAlliesOf = function (battler) {
  4297. var group = battler.isEnemy() ? this.BM().enemyEntities() : this.BM().allyEntities();
  4298. if (needAlive) {
  4299. return group.filter(function (ent) {
  4300. return !ent.battler().isDead();
  4301. });
  4302. } else {
  4303. return group;
  4304. }
  4305. };
  4306.  
  4307. TBSAiManager.prototype.getUsableSkills = function (user) {
  4308. if (user.isActor())
  4309. return user.usableSkills();
  4310. var actionList = user.enemy().actions.filter(function (a) {
  4311. return user.isActionValid(a);
  4312. });
  4313. var skills = [];
  4314. for (var i = 0; i < actionList.length; i++) {
  4315. var action = actionList[i];
  4316. skills.push($dataSkills[action.skillId]);
  4317. }
  4318. return skills;
  4319. };
  4320.  
  4321. TBSAiManager.prototype.getGroupFromActionData = function (data, maxPm) {
  4322. var group = [];
  4323. for (var i = 0; i < data.length; i++) {
  4324. if (data[i].requiredMp <= maxPm) {
  4325. var target = data[i].target;
  4326. if (!target._battler.isDead())
  4327. group.push(data[i].target);
  4328. }
  4329. }
  4330. return group;
  4331. };
  4332.  
  4333.  
  4334. /*-------------------------------------------------------------------------
  4335. * Sequence Manager
  4336. -------------------------------------------------------------------------*/
  4337. function TBSSequenceManager() {
  4338. this.initialize.call(this, arguments);
  4339. }
  4340.  
  4341. TBSSequenceManager.prototype.initialize = function () {
  4342. this._sequence = null;
  4343. this._commandRunning = null;
  4344. this._waitRequested = false;
  4345. this._users = [];
  4346. this._lastBattlerTargets = [];
  4347. this._lastCellTargets = [];
  4348. this._savedEntities = {};
  4349. this._savedCells = {};
  4350. this._sequenceQueue = [];
  4351. this._obj = null;
  4352. };
  4353.  
  4354. TBSSequenceManager.prototype.start = function (sequence, user, action) {
  4355. this._sequence = this.parseSequence(sequence).slice();
  4356. this._commandRunning = null;
  4357. this._sequenceQueue = [];
  4358. this._users = [user];
  4359. if (action)
  4360. this._obj = action.item();
  4361. };
  4362.  
  4363. TBSSequenceManager.prototype.append = function (sequence, user) {
  4364. this._sequenceQueue.push([sequence, user]);
  4365. };
  4366.  
  4367. TBSSequenceManager.prototype.getUser = function () {
  4368. return this._users.leU_last();
  4369. };
  4370.  
  4371. TBSSequenceManager.prototype.getObj = function () {
  4372. return this._obj;
  4373. };
  4374.  
  4375. TBSSequenceManager.prototype.parseSequence = function (sequence) {
  4376. if (sequence instanceof Array) return sequence;
  4377. sequence = sequence.replace("\n", "");
  4378. return LeUtilities.stringSplit(sequence, ";");
  4379. };
  4380.  
  4381. TBSSequenceManager.prototype.update = function () {
  4382. if (!this.isRunning()) return;
  4383. if (this._commandRunning) {
  4384. this.updateRunningCommand();
  4385. return;
  4386. }
  4387. var command = this._sequence.shift();
  4388. if (command) {
  4389. this.runCommand(command);
  4390. } else
  4391. this.endOfSequence();
  4392. };
  4393.  
  4394. TBSSequenceManager.prototype.runCommand = function (command) {
  4395. if (!command.match(/(.+)\s?:\s?(.+)/i)) return;
  4396. var main = String(RegExp.$1).trim(),
  4397. param = LeUtilities.stringSplit(String(RegExp.$2).trim(), ",");
  4398. for (var i = 0; i < param.length; i++) {
  4399. param[i] = param[i].trim();
  4400. }
  4401.  
  4402. this._waitRequested = false;
  4403. var functionName = LeUtilities.shrinkTextWithUnderscores(main);
  4404. var func = function () {};
  4405. try {
  4406. func = eval("this.command" + functionName + ".bind(this,param)");
  4407. } catch (e) {
  4408. console.log("[LeTBS] Can't find command \"", functionName);
  4409. console.log(e);
  4410. }
  4411. func();
  4412.  
  4413. this._commandRunning = main;
  4414. };
  4415.  
  4416. TBSSequenceManager.prototype.commandPlayPose = function (param) {
  4417. var targetData = param[0];
  4418. var pose = param[1];
  4419. var afterPose = param[2];
  4420. var wait = false;
  4421. if (afterPose === "true") {
  4422. wait = true;
  4423. afterPose = null;
  4424. }
  4425. var targets = this.readTargets(targetData);
  4426.  
  4427. targets.forEach(function (target) {
  4428. target.requestPlayPose();
  4429. target.setPose(pose, afterPose);
  4430. }.bind(this));
  4431.  
  4432. this._waitRequested = wait;
  4433. };
  4434.  
  4435. TBSSequenceManager.prototype.commandSetFrame = function (param) {
  4436. var targetData = param[0];
  4437. var pose = param[1];
  4438. var frame = param[2];
  4439. var targets = this.readTargets(targetData);
  4440.  
  4441. targets.forEach(function (target) {
  4442. target.setFixedPose(pose, frame);
  4443. }.bind(this));
  4444. };
  4445.  
  4446. TBSSequenceManager.prototype.commandSetSpeed = function (param) {
  4447. var targetData = param[0];
  4448. var value = param[1];
  4449. var targets = this.readTargets(targetData);
  4450.  
  4451. if (value === "reset") {
  4452. targets.forEach(function (target) {
  4453. target.initializeSpeed();
  4454. }.bind(this));
  4455. } else if (value.match(/\+(.+)/i)) {
  4456. targets.forEach(function (target) {
  4457. target.changeSpeed(Number(RegExp.$1));
  4458. }.bind(this));
  4459. } else if (value.match(/\-(.+)/i)) {
  4460. targets.forEach(function (target) {
  4461. target.changeSpeed(-Number(RegExp.$1));
  4462. }.bind(this));
  4463. } else {
  4464. targets.forEach(function (target) {
  4465. target.setSpeed(Number(value));
  4466. }.bind(this));
  4467. }
  4468. };
  4469.  
  4470. TBSSequenceManager.prototype.commandSetFrameDelay = function (param) {
  4471. var targetData = param[0];
  4472. var value = param[1];
  4473. var targets = this.readTargets(targetData);
  4474.  
  4475.  
  4476. if (value === "reset") {
  4477. targets.forEach(function (target) {
  4478. target.sprite().initializeFrameDelay();
  4479. }.bind(this));
  4480. } else if (value.match(/\+(.+)/i)) {
  4481. targets.forEach(function (target) {
  4482. target.sprite().changeFrameDelay(Number(RegExp.$1));
  4483. }.bind(this));
  4484. } else if (value.match(/\-(.+)/i)) {
  4485. targets.forEach(function (target) {
  4486. target.sprite().changeFrameDelay(-Number(RegExp.$1));
  4487. }.bind(this));
  4488. } else {
  4489. targets.forEach(function (target) {
  4490. target.sprite().setFrameDelay(Number(value));
  4491. }.bind(this));
  4492. }
  4493. };
  4494.  
  4495. TBSSequenceManager.prototype.commandSpriteShake = function (param) {
  4496. var targetData = param[0];
  4497. var power = Number(param[1]);
  4498. var duration = Number(param[2]);
  4499. var wait = (param[3] === "true");
  4500. var targets = this.readTargets(targetData);
  4501.  
  4502. for (var i = 0; i < targets.length; i++) {
  4503. targets[i].startShake(power, duration);
  4504. }
  4505. if (wait) {
  4506. this.commandWait([duration]);
  4507. }
  4508. };
  4509.  
  4510. TBSSequenceManager.prototype.commandWait = function (param) {
  4511. var duration = Number(param[0]);
  4512.  
  4513. BattleManagerTBS.wait(duration);
  4514. };
  4515.  
  4516. TBSSequenceManager.prototype.commandEffects = function (param) {
  4517. var targetData = param[0];
  4518. var objData = param[1];
  4519. var obj = this.readObject(objData);
  4520. var hitAnim = param[2] || null;
  4521. var animDelay = Number(param[3] || 0);
  4522. var wait = String(param[4] || "false");
  4523. wait = (wait === "true");
  4524. var targets = this.readTargets(targetData);
  4525.  
  4526. if (hitAnim && hitAnim.match(/obj_anim/i)) {
  4527. if (BattleManagerTBS.activeAction().isAttack())
  4528. hitAnim = BattleManagerTBS.activeEntity().getAttackAnimation();
  4529. else
  4530. hitAnim = BattleManagerTBS.activeAction().item().animationId;
  4531. }
  4532. BattleManagerTBS.applyObjEffects(this.getUser(), obj, targets, hitAnim, animDelay);
  4533.  
  4534. this._waitRequested = wait;
  4535. };
  4536.  
  4537. TBSSequenceManager.prototype.commandMapEffects = function (param) {
  4538. var targetData = param[0];
  4539. var objData = param[1];
  4540. var obj = this.readObject(objData);
  4541. var hitAnim = param[2] || null;
  4542. var animDelay = Number(param[3] || 0);
  4543. var wait = String(param[4] || "false");
  4544. wait = (wait == "true");
  4545. var cellTargets = this.readCellTargets(targetData);
  4546.  
  4547. if (hitAnim && hitAnim.match(/obj_anim/i)) {
  4548. if (BattleManagerTBS.activeAction().isAttack())
  4549. hitAnim = BattleManagerTBS.activeEntity().getAttackAnimation();
  4550. else
  4551. hitAnim = BattleManagerTBS.activeAction().item().animationId;
  4552. }
  4553. BattleManagerTBS.applyObjEffectsOnMap(this.getUser(), obj, cellTargets, hitAnim, animDelay);
  4554.  
  4555. this._waitRequested = wait;
  4556. };
  4557.  
  4558. TBSSequenceManager.prototype.commandPerformCollapse = function (param) {
  4559. var targetData = param[0];
  4560. var targets = this.readTargets(targetData);
  4561.  
  4562. for (var i = 0; i < targets.length; i++) {
  4563. targets[i].battler().performCollapse();
  4564. }
  4565. };
  4566.  
  4567. TBSSequenceManager.prototype.commandAnim = function (param) {
  4568. var targetData = param[0];
  4569. var anim = param[1];
  4570. var animDelay = Number(param[2] || 0);
  4571. var wait = String(param[3] || "false");
  4572. wait = (wait == "true");
  4573. var targets = this.readTargets(targetData);
  4574.  
  4575. if (anim.match(/obj_anim/i)) {
  4576. if (BattleManagerTBS.activeAction().isAttack())
  4577. anim = BattleManagerTBS.activeEntity().getAttackAnimation();
  4578. else
  4579. anim = BattleManagerTBS.activeAction().item().animationId;
  4580. } else if (anim.match(/collapse_anim/i)) {
  4581. var collapse_anim = true;
  4582. } else {
  4583. anim = Number(anim);
  4584. }
  4585.  
  4586. targets.forEach(function (target) {
  4587. if (collapse_anim)
  4588. anim = target.getCollapseAnimation();
  4589. BattleManagerTBS.getLayer("animations").newAnimation(anim, false, animDelay, target.getCell(), target._sprite);
  4590. }.bind(this));
  4591.  
  4592. this._waitRequested = wait;
  4593. };
  4594.  
  4595. TBSSequenceManager.prototype.commandMapAnim = function (param) {
  4596. var targetData = param[0];
  4597. var anim = param[1];
  4598. var animDelay = Number(param[2] || 0);
  4599. var wait = String(param[3] || "false");
  4600. wait = (wait == "true");
  4601. var cellTargets = this.readCellTargets(targetData);
  4602.  
  4603. if (anim.match(/obj_anim/i)) {
  4604. if (BattleManagerTBS.activeAction().isAttack())
  4605. anim = BattleManagerTBS.activeEntity().getAttackAnimation();
  4606. else
  4607. anim = BattleManagerTBS.activeAction().item().animationId;
  4608. } else {
  4609. anim = Number(anim);
  4610. }
  4611. cellTargets.forEach(function (cell) {
  4612. BattleManagerTBS.getLayer("animations").newAnimation(anim, false, animDelay, cell);
  4613. }.bind(this));
  4614.  
  4615. this._waitRequested = wait;
  4616. };
  4617.  
  4618. TBSSequenceManager.prototype.commandDirectionalAnim = function (param) {
  4619. var targetData1 = param[0];
  4620. var targetData2 = param[1];
  4621. var anim_2 = param[2];
  4622. var anim_4 = param[3];
  4623. var anim_6 = param[4];
  4624. var anim_8 = param[5];
  4625. var animDelay = Number(param[6] || 0);
  4626. var wait = String(param[7] || "false");
  4627. var targets1 = this.readTargets(targetData1);
  4628.  
  4629. if (targets1.length > 0) {
  4630. var anim;
  4631. switch (targets1[0].getDir()) {
  4632. case 2:
  4633. anim = anim_2;
  4634. break;
  4635. case 4:
  4636. anim = anim_4;
  4637. break;
  4638. case 6:
  4639. anim = anim_6;
  4640. break;
  4641. case 8:
  4642. anim = anim_8;
  4643. break;
  4644. }
  4645. param[0] = targetData2;
  4646. param[1] = anim;
  4647. param[2] = animDelay;
  4648. param[3] = wait;
  4649. this.commandAnim(param);
  4650. }
  4651. };
  4652.  
  4653. TBSSequenceManager.prototype.commandLookAt = function (param) {
  4654. var targetData = param[0];
  4655. var cellTargetData = param[1];
  4656. var targets = this.readTargets(targetData);
  4657. var cellTargets = this.readCellTargets(cellTargetData);
  4658.  
  4659. if (cellTargets.length > 0) {
  4660. var cell = cellTargets[0];
  4661. targets.forEach(function (target) {
  4662. target.lookAt(cell);
  4663. }.bind(this));
  4664. }
  4665. };
  4666.  
  4667. TBSSequenceManager.prototype.commandLookAway = function (param) {
  4668. var targetData = param[0];
  4669. var cellTargetData = param[1];
  4670. var targets = this.readTargets(targetData);
  4671. var cellTargets = this.readCellTargets(cellTargetData);
  4672.  
  4673. if (cellTargets.length > 0) {
  4674. var cell = cellTargets[0];
  4675. targets.forEach(function (target) {
  4676. target.lookAway(cell);
  4677. }.bind(this));
  4678. }
  4679. };
  4680.  
  4681. TBSSequenceManager.prototype.commandMoveToCell = function (param) {
  4682. var targetData = param[0];
  4683. var cellTargetData = param[1];
  4684. var isInstant = String(param[2] || "false");
  4685. isInstant = (isInstant.match(/true/i));
  4686. var targets = this.readTargets(targetData);
  4687. var cellTargets = this.readCellTargets(cellTargetData);
  4688.  
  4689. if (targets.length > 0 && cellTargetData.length > 0) {
  4690. var target = targets[0];
  4691. var cell = cellTargets[0];
  4692. if (isInstant) {
  4693. target.teleport(cell);
  4694. } else {
  4695. var path = BattleManagerTBS.getPathFromAToB(target._cellX, target._cellY, cell.x, cell.y, "walkable");
  4696. target.processMovement(path);
  4697. this._waitRequested = true;
  4698. }
  4699. }
  4700. };
  4701.  
  4702. TBSSequenceManager.prototype.commandJumpToCell = function (param) {
  4703. var targetData = param[0];
  4704. var cellTargetData = param[1];
  4705. var height = param[2] || 120;
  4706. var targets = this.readTargets(targetData);
  4707. var cellTargets = this.readCellTargets(cellTargetData);
  4708.  
  4709. if (targets.length > 0 && cellTargetData.length > 0) {
  4710. var target = targets[0];
  4711. var cell = cellTargets[0];
  4712. var sx = target.x;
  4713. var sy = target.y;
  4714. var dx = cell.x * $gameMap.tileWidth();
  4715. var dy = cell.y * $gameMap.tileHeight();
  4716. var trajectory = LeUtilities.getPixelsOfJump(sx, sy, dx, dy, height);
  4717. target.followTrajectory(trajectory, cell);
  4718. this._waitRequested = true;
  4719. }
  4720.  
  4721. };
  4722.  
  4723. TBSSequenceManager.prototype.commandMoveStraight = function (param) {
  4724. var targetData = param[0];
  4725. var nbr = Number(param[1] || 1);
  4726. var targets = this.readTargets(targetData);
  4727.  
  4728. targets.forEach(function (target) {
  4729. target.forceMoveStraight(nbr, false);
  4730. }.bind(this));
  4731. this._waitRequested = true;
  4732. };
  4733.  
  4734. TBSSequenceManager.prototype.commandPush = function (param) {
  4735. var targetData = param[0];
  4736. var targetData2 = param[1];
  4737. var distance = Number(param[2]);
  4738. var damage = !param[3] || param[3] === "false";
  4739. var targets = this.readTargets(targetData);
  4740. var sourceCell = this.readCellTargets(targetData2)[0];
  4741.  
  4742. for (var i = 0; i < targets.length; i++) {
  4743. var entity = targets[i];
  4744. entity.forcePush(this.getUser(), sourceCell, distance, this.getObj(), damage);
  4745. }
  4746. };
  4747.  
  4748. TBSSequenceManager.prototype.commandPull = function (param) {
  4749. var targetData = param[0];
  4750. var targetData2 = param[1];
  4751. var distance = Number(param[2]);
  4752. var damage = !param[3] || param[3] === "false";
  4753. var targets = this.readTargets(targetData);
  4754. var sourceCell = this.readCellTargets(targetData2)[0];
  4755.  
  4756. for (var i = 0; i < targets.length; i++) {
  4757. var entity = targets[i];
  4758. entity.forcePull(this.getUser(), sourceCell, distance, this.getObj(), damage);
  4759. }
  4760. };
  4761.  
  4762. TBSSequenceManager.prototype.commandProjectile = function (param) {
  4763. var id = param[0];
  4764. var cellTargetData1 = param[1];
  4765. var cellTargetData2 = param[2];
  4766. var cellTargets1 = this.readCellTargets(cellTargetData1);
  4767. var cellTargets2 = this.readCellTargets(cellTargetData2);
  4768.  
  4769. if (cellTargets1.length > 0 && cellTargets2.length > 0) {
  4770. var cellStart = cellTargets1[0];
  4771. var cellEnd = cellTargets2[0];
  4772. var w = $gameMap.tileWidth();
  4773. var h = $gameMap.tileHeight();
  4774. var sx = cellStart.x * w + w / 2;
  4775. var sy = cellStart.y * h + h / 2;
  4776. var dx = cellEnd.x * w + w / 2;
  4777. var dy = cellEnd.y * h + h / 2;
  4778. BattleManagerTBS._projectilesManager.newProjectile(id, [sx, sy], [dx, dy]);
  4779. }
  4780. };
  4781.  
  4782. TBSSequenceManager.prototype.commandSetBattlerTargets = function (param) {
  4783. var targetData = param[0];
  4784. var targets = this.readTargets(targetData);
  4785. this._lastBattlerTargets = targets;
  4786. };
  4787.  
  4788. TBSSequenceManager.prototype.commandSetCellTargets = function (param) {
  4789. var targetData = param[0];
  4790. var targets = this.readCellTargets(targetData);
  4791. this._lastCellTargets = targets;
  4792. };
  4793.  
  4794. TBSSequenceManager.prototype.commandSaveEntities = function (param) {
  4795. var id = param[0];
  4796. var targetData = param[1];
  4797. var option = param[2];
  4798. var targets = this.readTargets(targetData);
  4799. this._savedEntities[id] = targets;
  4800. if (option === "shift") {
  4801. this._savedEntities[id] = [targets.shift()];
  4802. } else {
  4803. this._savedEntities[id] = targets;
  4804. }
  4805. };
  4806.  
  4807. TBSSequenceManager.prototype.commandSaveCells = function (param) {
  4808. var id = param[0];
  4809. var targetData = param[1];
  4810. var option = param[2];
  4811. var targets = this.readCellTargets(targetData);
  4812. if (option === "shift") {
  4813. this._savedCells[id] = [targets.shift()];
  4814. } else {
  4815. this._savedCells[id] = targets;
  4816. }
  4817. };
  4818.  
  4819. TBSSequenceManager.prototype.commandCall = function (param) {
  4820. var seq = param[0];
  4821. var times = Number(param[1] || 1);
  4822.  
  4823. var seqArray = Lecode.S_TBS.Config.Sequences[seq].slice();
  4824. for (var i = 0; i < times; i++) {
  4825. for (var j = seqArray.length - 1; j >= 0; j--) {
  4826. var command = seqArray[j];
  4827. this._sequence.unshift(command);
  4828. }
  4829. }
  4830. };
  4831.  
  4832. TBSSequenceManager.prototype.commandCallForEveryCell = function (param) {
  4833. var seq = param[0];
  4834. var targetData = param[1];
  4835. var sortType = param[2];
  4836. var targets = this.readCellTargets(targetData);
  4837.  
  4838. var aoe = this.readCellTargets("aoe");
  4839. if (sortType === "close->far") {
  4840. aoe = aoe.sort(function (a, b) {
  4841. var obj_aDist = LeUtilities.distanceBetween(a, this.getUser());
  4842. var obj_bDist = LeUtilities.distanceBetween(b, this.getUser());
  4843. return (obj_aDist > obj_bDist) ? 1 : ((obj_aDist < obj_bDist) ? -1 : 0);
  4844. }.bind(this));
  4845. } else if (sortType === "far->close") {
  4846. aoe = aoe.sort(function (a, b) {
  4847. var obj_aDist = LeUtilities.distanceBetween(a, this.getUser());
  4848. var obj_bDist = LeUtilities.distanceBetween(b, this.getUser());
  4849. return (obj_aDist > obj_bDist) ? -1 : ((obj_aDist < obj_bDist) ? 1 : 0);
  4850. }.bind(this));
  4851. } else if (sortType === "random") {
  4852. aoe = aoe.filter(function (cell) {
  4853. return true;
  4854. });
  4855. }
  4856. if (aoe.length > 0) {
  4857. this._savedCells["every_cell_base"] = aoe;
  4858. //this._savedCells["every_cell"] = aoe.shift();
  4859.  
  4860. var seqArray = Lecode.S_TBS.Config.Sequences[seq].slice();
  4861. for (var i = 0; i < aoe.length; i++) {
  4862. for (var j = seqArray.length - 1; j >= 0; j--) {
  4863. var command = seqArray[j];
  4864. this._sequence.unshift(command);
  4865. }
  4866. this._sequence.unshift("save_cells: every_cell, saved(every_cell_base), shift");
  4867. }
  4868. }
  4869. };
  4870.  
  4871. TBSSequenceManager.prototype.commandDelegateCall = function (param) {
  4872. var seq = param[0];
  4873. var targetData = param[1];
  4874. var targets = this.readTargets(targetData);
  4875.  
  4876. if (targets.length > 0) {
  4877. this._users.push(targets[0]);
  4878. param[1] = 1;
  4879. this.commandCall(param);
  4880. }
  4881. };
  4882.  
  4883. TBSSequenceManager.prototype.commandEndDelegatedCall = function () {
  4884. this._users.pop();
  4885. };
  4886.  
  4887. TBSSequenceManager.prototype.commandAskCall = function (param) {
  4888. var seq = param[0];
  4889. var targetData = param[1];
  4890. var targets = this.readTargets(targetData);
  4891.  
  4892. for (var i = 0; i < targets.length; i++) {
  4893. targets[i].startSequence(seq);
  4894. }
  4895. };
  4896.  
  4897. TBSSequenceManager.prototype.commandScript = function (param) {
  4898. var code = param[0];
  4899. var user = this.getUser();
  4900. eval(code);
  4901. };
  4902.  
  4903. TBSSequenceManager.prototype.updateRunningCommand = function () {
  4904. var command = this._commandRunning;
  4905. switch (command) {
  4906. case "wait":
  4907. this.updateCommandWait();
  4908. break;
  4909. case "play_pose":
  4910. this.updateCommandPlayPose();
  4911. break;
  4912. case "anim":
  4913. case "map_anim":
  4914. case "effects":
  4915. case "map_effects":
  4916. this.updateCommandAnim();
  4917. break;
  4918. case "move_to_cell":
  4919. this.updateCommandMoveToCell();
  4920. break;
  4921. case "move_straight":
  4922. this.updateCommandMoveStraight();
  4923. break;
  4924. case "jump_to_cell":
  4925. this.updateCommandJumpToCell();
  4926. break;
  4927. case "projectile":
  4928. this.updateCommandProjectile();
  4929. break;
  4930. default:
  4931. this._commandRunning = null;
  4932. break;
  4933. }
  4934. };
  4935.  
  4936. TBSSequenceManager.prototype.updateCommandWait = function () {
  4937. if (!BattleManagerTBS.isWaiting())
  4938. this._commandRunning = null;
  4939. };
  4940.  
  4941. TBSSequenceManager.prototype.updateCommandPlayPose = function () {
  4942. if (this._waitRequested) {
  4943. var entities = BattleManagerTBS.battlerEntities();
  4944. for (var i = 0; i < entities.length; i++) {
  4945. var entity = entities[i];
  4946. if (!entity.isRequestedPosePlayed())
  4947. return;
  4948. }
  4949. this._commandRunning = null;
  4950. this.update();
  4951. } else
  4952. this._commandRunning = null;
  4953. };
  4954.  
  4955. TBSSequenceManager.prototype.updateCommandAnim = function () {
  4956. if (this._waitRequested) {
  4957. if (!BattleManagerTBS.getLayer("animations").isAnimationPlaying())
  4958. this._commandRunning = null;
  4959. } else
  4960. this._commandRunning = null;
  4961. };
  4962.  
  4963. TBSSequenceManager.prototype.updateCommandMoveToCell = function () {
  4964. if (this._waitRequested) {
  4965. var entities = BattleManagerTBS.battlerEntities();
  4966. for (var i = 0; i < entities.length; i++) {
  4967. var entity = entities[i];
  4968. if (entity.isMoving())
  4969. return;
  4970. }
  4971. this._commandRunning = null;
  4972. } else
  4973. this._commandRunning = null;
  4974. };
  4975.  
  4976. TBSSequenceManager.prototype.updateCommandMoveStraight = function () {
  4977. if (this._waitRequested) {
  4978. var entities = BattleManagerTBS.battlerEntities();
  4979. for (var i = 0; i < entities.length; i++) {
  4980. var entity = entities[i];
  4981. if (entity.isMoving())
  4982. return;
  4983. }
  4984. this._commandRunning = null;
  4985. } else
  4986. this._commandRunning = null;
  4987. };
  4988.  
  4989. TBSSequenceManager.prototype.updateCommandJumpToCell = function () {
  4990. if (this._waitRequested) {
  4991. var entities = BattleManagerTBS.battlerEntities();
  4992. for (var i = 0; i < entities.length; i++) {
  4993. var entity = entities[i];
  4994. if (entity._sprite.hasTrajectory())
  4995. return;
  4996. }
  4997. this._commandRunning = null;
  4998. } else
  4999. this._commandRunning = null;
  5000. };
  5001.  
  5002. TBSSequenceManager.prototype.updateCommandProjectile = function () {
  5003. if (!BattleManagerTBS._projectilesManager.isRunning())
  5004. this._commandRunning = null;
  5005. };
  5006.  
  5007. TBSSequenceManager.prototype.readTargets = function (data) {
  5008. var targets = [];
  5009. if (data.match(/aoe_all_(.+)/i)) {
  5010. var info = String(RegExp.$1);
  5011. BattleManagerTBS._actionAoE.forEach(function (cell) {
  5012. var target = cell.getEntity();
  5013. if (target != null) {
  5014. if (info.match(/battlers/i) || info.match(/allies/i) && target.battler().isActor() || info.match(/enemies/i) && !target.battler().isActor())
  5015. targets.push(target);
  5016. }
  5017. }.bind(this));
  5018. } else if (data.match(/(\d+)_random_battlers_in_aoe/i)) {
  5019. var battlersInAoe = [];
  5020. BattleManagerTBS._actionAoE.forEach(function (cell) {
  5021. var entity = cell.getEntity();
  5022. if (entity)
  5023. battlersInAoe.push(entity);
  5024. }.bind(this));
  5025. targets = LeUtilities.getXRandomValuesInArray(battlersInAoe, Number(RegExp.$1));
  5026. } else if (data.match(/battler_toward_user/i)) {
  5027. var cell = this.getUser().getForwardCell();
  5028. if (cell) {
  5029. var target = cell.getEntity();
  5030. if (target)
  5031. targets = [target];
  5032. }
  5033. } else if (data.match(/user/i)) {
  5034. targets = [this.getUser()];
  5035. } else if (data.match(/last_battler_targets/i)) {
  5036. targets = this._lastBattlerTargets;
  5037. } else if (data.match(/saved\((.+)\)/i)) {
  5038. targets = this._savedEntities[RegExp.$1] || [];
  5039. } else if (data.match(/(.+)_at_distance_(.+)_from_(.+)/i)) {
  5040. var info = String(RegExp.$1);
  5041. var maxDist = Number(RegExp.$2);
  5042. var cell = this.readCellTargets(String(RegExp.$3))[0];
  5043. BattleManagerTBS.allEntities().forEach(function (entity) {
  5044. if (info.match(/battlers/i) || info.match(/allies/i) && entity.battler().isActor() || info.match(/enemies/i) && !entity.battler().isActor()) {
  5045. var distance = LeUtilities.distanceBetweenCells(cell, entity.getCell());
  5046. if (distance <= maxDist)
  5047. targets.push(entity);
  5048. }
  5049. });
  5050. }
  5051.  
  5052. if (data.match(/-user/i)) {
  5053. var ux = this.getUser()._cellX;
  5054. var uy = this.getUser()._cellY;
  5055. targets = targets.filter(function (entity) {
  5056. return entity._cellX != ux || entity._cellY != uy;
  5057. }.bind(this));
  5058. }
  5059. this._lastBattlerTargets = targets;
  5060. return targets;
  5061. };
  5062.  
  5063. TBSSequenceManager.prototype.readCellTargets = function (data) {
  5064. var targets = [];
  5065. if (data.match(/(\d+)_random_cells_in_aoe/i)) {
  5066. var cells = BattleManagerTBS._actionAoE;
  5067. var randomCells = LeUtilities.getXRandomValuesInArray(cells, Number(RegExp.$1));
  5068. targets = randomCells;
  5069. } else if (data.match(/last_cell_targets/i)) {
  5070. targets = this._lastCellTargets;
  5071. } else if (data.match(/saved\((.+)\)/i)) {
  5072. console.log("Saved(", RegExp.$1, "): ", this._savedCells[RegExp.$1]);
  5073. targets = this._savedCells[RegExp.$1] || [];
  5074. } else if (data.match(/aoe/i)) {
  5075. targets = BattleManagerTBS._actionAoE;
  5076. } else if (data.match(/cursor_cell/i)) {
  5077. var x = BattleManagerTBS.cursor().cellX;
  5078. var y = BattleManagerTBS.cursor().cellY;
  5079. targets = [BattleManagerTBS.getCellAt(x, y)];
  5080. } else if (data.match(/user_cell/i)) {
  5081. var x = this.getUser()._cellX;
  5082. var y = this.getUser()._cellY;
  5083. targets = [BattleManagerTBS.getCellAt(x, y)];
  5084. }
  5085.  
  5086. if (data.match(/-user_cell/i)) {
  5087. targets = targets.filter(function (cell) {
  5088. return !this.getUser().getCell().isSame(cell);
  5089. }.bind(this));
  5090. }
  5091. this._lastCellTargets = targets;
  5092. return targets;
  5093. };
  5094.  
  5095. TBSSequenceManager.prototype.readObject = function (data) {
  5096. if (data.match(/current_obj/i))
  5097. return BattleManagerTBS.activeAction().item();
  5098. return null;
  5099. };
  5100.  
  5101. TBSSequenceManager.prototype.endOfSequence = function () {
  5102. this._sequence = null;
  5103. this._savedEntities = {};
  5104. this._savedCells = {};
  5105. var data = this._sequenceQueue.shift();
  5106. if (data) {
  5107. this.start(data[0], data[1]);
  5108. this.update();
  5109. }
  5110. };
  5111.  
  5112. TBSSequenceManager.prototype.isRunning = function () {
  5113. return this._sequence != null;
  5114. };
  5115.  
  5116. /*-------------------------------------------------------------------------
  5117. * TBSProjectilesManager
  5118. -------------------------------------------------------------------------*/
  5119. function TBSProjectilesManager() {
  5120. this.initialize.apply(this, arguments);
  5121. }
  5122.  
  5123. TBSProjectilesManager.prototype.initialize = function (layer) {
  5124. this._layer = layer;
  5125. this._projectiles = [];
  5126. this._running = false;
  5127. };
  5128.  
  5129. TBSProjectilesManager.prototype.isRunning = function () {
  5130. return this._projectiles.length > 0;
  5131. };
  5132.  
  5133. TBSProjectilesManager.prototype.newProjectile = function (id, start, end) {
  5134. var proj = new TBSProjectileSprite(id, start, end);
  5135. this._projectiles.push(proj);
  5136. this._layer.addChild(proj);
  5137. };
  5138.  
  5139. TBSProjectilesManager.prototype.update = function () {
  5140. //this.updateProjectiles();
  5141. this.destoryProjectiles();
  5142. };
  5143.  
  5144. TBSProjectilesManager.prototype.updateProjectiles = function () {
  5145. for (var i = 0; i < this._projectiles.length; i++) {
  5146. this._projectiles[i].update();
  5147. }
  5148. };
  5149.  
  5150. TBSProjectilesManager.prototype.destoryProjectiles = function () {
  5151. this._projectiles = this._projectiles.filter(function (proj) {
  5152. if (proj.finished()) {
  5153. this._layer.removeChild(proj);
  5154. return false;
  5155. }
  5156. return true;
  5157. }.bind(this));
  5158. };
  5159.  
  5160. /*-------------------------------------------------------------------------
  5161. * TBSProjectileSprite
  5162. -------------------------------------------------------------------------*/
  5163. function TBSProjectileSprite() {
  5164. this.initialize.apply(this, arguments);
  5165. }
  5166. TBSProjectileSprite.prototype = Object.create(Sprite_Base.prototype);
  5167. TBSProjectileSprite.prototype.constructor = TBSProjectileSprite;
  5168.  
  5169. TBSProjectileSprite.prototype.initialize = function (id, start, end) {
  5170. Sprite_Base.prototype.initialize.call(this);
  5171. this._start = start;
  5172. this._end = end;
  5173. this._trajectory = [];
  5174. this._speedFrame = 0;
  5175. this.readData(id);
  5176. this.iniPositions();
  5177. this.makeTrajectory();
  5178. };
  5179.  
  5180. TBSProjectileSprite.prototype.readData = function (id) {
  5181. var data = Lecode.S_TBS.Config.Projectiles[id];
  5182. if (data.filename) {
  5183. var bitmap = ImageManager.loadLeTBSProjectile(data.filename);
  5184. this.bitmap = bitmap;
  5185. } else if (data.anim) {
  5186. this.bitmap = new Bitmap(data.anim[1], data.anim[2]);
  5187. this.startAnimation(data.anim[0]);
  5188. }
  5189. this._speed = data.speed || 3;
  5190. this._adaptAngle = false || data.adapt_angle;
  5191. this._jump = data.jump || 0;
  5192. this.anchor.x = 0.5;
  5193. this.anchor.y = 0.5;
  5194. };
  5195.  
  5196. TBSProjectileSprite.prototype.iniPositions = function () {
  5197. this.x = this._start[0];
  5198. this.y = this._start[1];
  5199. };
  5200.  
  5201. TBSProjectileSprite.prototype.makeTrajectory = function () {
  5202. var sx = this._start[0];
  5203. var sy = this._start[1];
  5204. var dx = this._end[0];
  5205. var dy = this._end[1];
  5206. if (this._jump != 0) {
  5207. this._trajectory = LeUtilities.getPixelsOfJump(sx, sy, dx, dy, this._jump);
  5208. } else {
  5209. this._trajectory = LeUtilities.getPixelsOfLine(sx, sy, dx, dy);
  5210. }
  5211. if (this._trajectory[0][0] === dx && this._trajectory[0][1] === dy)
  5212. this._trajectory = this._trajectory.reverse();
  5213. };
  5214.  
  5215. TBSProjectileSprite.prototype.update = function () {
  5216. Sprite_Base.prototype.update.call(this);
  5217. if (!this.finished()) {
  5218. this.updateAngle();
  5219. this.updateMove();
  5220. }
  5221. };
  5222.  
  5223. TBSProjectileSprite.prototype.updateMove = function () {
  5224. var frame = this._speedFrame;
  5225. if (frame >= this._trajectory.length - 1) {
  5226. frame = this._trajectory.length - 1;
  5227. this._finished = true;
  5228. }
  5229. var newPos = this._trajectory[frame];
  5230. this.x = newPos[0];
  5231. this.y = newPos[1];
  5232. this._speedFrame += this._speed;
  5233. };
  5234.  
  5235. TBSProjectileSprite.prototype.updateAngle = function () {
  5236. if (this._adaptAngle) {
  5237. var sx, sy, dx, dy;
  5238. sx = this.x;
  5239. sy = this.y;
  5240. if (this._jump === 0) {
  5241. dx = this._end[0];
  5242. dy = this._end[1];
  5243. } else {
  5244. var topFrame = parseInt(this._trajectory.length / 2);
  5245. if (this._speedFrame > topFrame) {
  5246. dx = this._end[0];
  5247. dy = this._end[1];
  5248. } else {
  5249. var topCoord = this._trajectory[topFrame];
  5250. dx = topCoord[0];
  5251. dy = topCoord[1];
  5252. }
  5253. }
  5254. var rotation = Math.atan2(dy - sy, dx - sx);
  5255. this.rotation = rotation;
  5256. }
  5257. };
  5258.  
  5259. TBSProjectileSprite.prototype.startAnimation = function (animation) {
  5260. animation = $dataAnimations[animation];
  5261. var sprite = new Sprite_ProjectileAnimation();
  5262. sprite.setup(this, animation);
  5263. this.addChild(sprite);
  5264. this._animationSprites.push(sprite);
  5265. };
  5266.  
  5267. TBSProjectileSprite.prototype.finished = function () {
  5268. return this._finished;
  5269. };
  5270.  
  5271. /*-------------------------------------------------------------------------
  5272. * Sprite_ProjectileAnimation
  5273. -------------------------------------------------------------------------*/
  5274. function Sprite_ProjectileAnimation() {
  5275. this.initialize.apply(this, arguments);
  5276. }
  5277. Sprite_ProjectileAnimation.prototype = Object.create(Sprite_Animation.prototype);
  5278. Sprite_ProjectileAnimation.prototype.constructor = Sprite_ProjectileAnimation;
  5279.  
  5280. Sprite_ProjectileAnimation.prototype.initialize = function () {
  5281. Sprite_Animation.prototype.initialize.call(this);
  5282. };
  5283.  
  5284. Sprite_ProjectileAnimation.prototype.update = function () {
  5285. Sprite_Animation.prototype.update.call(this);
  5286. if (!this.isPlaying() && this._animation)
  5287. this.setupDuration();
  5288. };
  5289.  
  5290. Sprite_ProjectileAnimation.prototype.setup = function (target, animation) {
  5291. this._target = target;
  5292. this._animation = animation;
  5293. this._mirror = false;
  5294. this._delay = false;
  5295. if (this._animation) {
  5296. this.remove();
  5297. this.setupRate();
  5298. this.setupDuration();
  5299. this.loadBitmaps();
  5300. this.createSprites();
  5301. }
  5302. };
  5303.  
  5304. Sprite_ProjectileAnimation.prototype.updatePosition = function () {
  5305. this.x = 0; //this._target.x;
  5306. this.y = 0; //this._target.y;
  5307. };
  5308.  
  5309. Sprite_ProjectileAnimation.prototype.updateCellSprite = function (sprite, cell) {
  5310. Sprite_Animation.prototype.updateCellSprite.call(this, sprite, cell);
  5311. sprite.rotation += this._target.rotation * Math.PI / 180;
  5312. };
  5313.  
  5314.  
  5315. /*-------------------------------------------------------------------------
  5316. * Cell entity
  5317. -------------------------------------------------------------------------*/
  5318. function TBSCell(x, y) {
  5319. this.x = x;
  5320. this.y = y;
  5321. this._regionId = -1;
  5322. this._type = null;
  5323. this._event = null;
  5324. this._visible = false;
  5325. this._opacity = 0;
  5326. this._color = "";
  5327. }
  5328.  
  5329. TBSCell.prototype.isSame = function (otherCell) {
  5330. return this.x === otherCell.x && this.y === otherCell.y;
  5331. };
  5332.  
  5333. TBSCell.prototype.select = function () {
  5334. BattleManagerTBS._activeCell = this;
  5335. };
  5336.  
  5337. TBSCell.prototype.isImpassableTile = function () {
  5338. var x = this.x,
  5339. y = this.y;
  5340. if (!$gameMap.isValid(x, y)) return true;
  5341. if (!$gameMap.isPassable(x, y, 2)) return true;
  5342. if (!$gameMap.isPassable(x, y, 4)) return true;
  5343. if (!$gameMap.isPassable(x, y, 6)) return true;
  5344. if (!$gameMap.isPassable(x, y, 8)) return true;
  5345. return false;
  5346. };
  5347.  
  5348. TBSCell.prototype.isObstacle = function () {
  5349. if (this.isThereEntity()) return true;
  5350. if (this._regionId == Lecode.S_TBS.obstacleRegionId) return true;
  5351. return false;
  5352. };
  5353.  
  5354. TBSCell.prototype.isThereEntity = function () {
  5355. return this.getEntity() != null;
  5356. };
  5357.  
  5358. TBSCell.prototype.getEntity = function () {
  5359. return BattleManagerTBS.allEntities().leU_find(function (entity) {
  5360. return entity._cellX == this.x && entity._cellY == this.y;
  5361. }.bind(this));
  5362. };
  5363.  
  5364. TBSCell.prototype.toCoords = function () {
  5365. return {
  5366. x: this.x,
  5367. y: this.y
  5368. };
  5369. };
  5370.  
  5371. /*-------------------------------------------------------------------------
  5372. * SpriteCursorTBS
  5373. -------------------------------------------------------------------------*/
  5374. function SpriteCursorTBS() {
  5375. this.initialize.apply(this, arguments);
  5376. }
  5377.  
  5378. SpriteCursorTBS.prototype = Object.create(Sprite.prototype);
  5379. SpriteCursorTBS.prototype.constructor = SpriteCursorTBS;
  5380.  
  5381. SpriteCursorTBS.prototype.initialize = function (bitmap) {
  5382. Sprite.prototype.initialize.call(this, bitmap);
  5383. this.cellX = this.cellY = 0;
  5384. this._leU_loopFlash = true;
  5385. this._leU_loopFlashData = {
  5386. color: [255, 255, 255, 255],
  5387. duration: 30
  5388. };
  5389. };
  5390.  
  5391. /*-------------------------------------------------------------------------
  5392. * TBSTurnOrderVisual
  5393. -------------------------------------------------------------------------*/
  5394. function TBSTurnOrderVisual() {
  5395. this.initialize.apply(this, arguments);
  5396. }
  5397.  
  5398.  
  5399. /*-------------------------------------------------------------------------
  5400. * TBSEntity
  5401. -------------------------------------------------------------------------*/
  5402. function TBSEntity() {
  5403. this.initialize.apply(this, arguments);
  5404.  
  5405. Object.defineProperty(this, 'x', {
  5406. get: function () {
  5407. return this._posX;
  5408. },
  5409. set: function (value) {
  5410. this.setPosition(value, this.y);
  5411. },
  5412. configurable: true
  5413. });
  5414.  
  5415. Object.defineProperty(this, 'y', {
  5416. get: function () {
  5417. return this._posY;
  5418. },
  5419. set: function (value) {
  5420. this.setPosition(this.x, value);
  5421. },
  5422. configurable: true
  5423. });
  5424. }
  5425.  
  5426. TBSEntity.prototype.initialize = function (battler, layer) {
  5427. this._battler = battler;
  5428. this._cell = null;
  5429. this._cellX = 0;
  5430. this._cellY = 0;
  5431. this._moving = false;
  5432. this._movePoints = 0;
  5433. this._movingDistance = [0, 0];
  5434. this._movePath = [];
  5435. this._movingNextCell = null;
  5436. this._moveReducePoints = false;
  5437. this._movePerformed = false;
  5438. this._actionPerformed = false;
  5439. this._dead = false;
  5440. this.createSprite(battler, layer);
  5441. this.createComponents();
  5442. this.setMovePoints();
  5443. this.initializeSpeed();
  5444. };
  5445.  
  5446. TBSEntity.prototype.createSprite = function (battler, layer) {
  5447. this._sprite = new TBSEntity_Sprite(battler, this);
  5448. this._posX = 0;
  5449. this._posY = 0;
  5450. this._dir = 2;
  5451. this._lastDir = 2;
  5452. this._pose = "idle";
  5453. this._afterPose = "idle";
  5454. this._poseLoop = false;
  5455. this._fixedPose = null;
  5456. layer.addChild(this._sprite);
  5457. };
  5458.  
  5459. TBSEntity.prototype.createComponents = function () {
  5460. this._sequenceManager = new TBSSequenceManager();
  5461. };
  5462.  
  5463. TBSEntity.prototype.initializeSpeed = function () {
  5464. this.setSpeed(Lecode.S_TBS.battlersMoveSpeed);
  5465. };
  5466.  
  5467. TBSEntity.prototype.setSpeed = function (speed) {
  5468. this._speed = speed;
  5469. };
  5470.  
  5471. TBSEntity.prototype.changeSpeed = function (speed) {
  5472. this._speed += speed;
  5473. };
  5474.  
  5475. TBSEntity.prototype.startSequence = function (id, action) {
  5476. var sequence = Lecode.S_TBS.Config.Sequences[id];
  5477. this._sequenceManager.start(sequence, this, action);
  5478. };
  5479.  
  5480. TBSEntity.prototype.callSequence = function (id) {
  5481. if (this._sequenceManager.isRunning()) {
  5482. this._sequenceManager.commandCall([id, 1]);
  5483. } else {
  5484. this.startSequence(id);
  5485. }
  5486. };
  5487.  
  5488. TBSEntity.prototype.appendSequence = function (id) {
  5489. if (this._sequenceManager.isRunning()) {
  5490. var sequence = Lecode.S_TBS.Config.Sequences[id];
  5491. this._sequenceManager.append(sequence, this);
  5492. } else {
  5493. this.startSequence(id);
  5494. }
  5495. };
  5496.  
  5497. TBSEntity.prototype.requestPlayPose = function () {
  5498. this._requestPlayPose = true;
  5499. };
  5500.  
  5501. TBSEntity.prototype.isRequestedPosePlayed = function () {
  5502. return !this._requestPlayPose;
  5503. };
  5504.  
  5505. TBSEntity.prototype.setPose = function (pose, afterPose) {
  5506. this._fixedPose = null;
  5507. this._pose = pose;
  5508. this._afterPose = afterPose || "idle";
  5509. this._poseLoop = (afterPose === pose);
  5510. this._sprite.updatePose();
  5511. this._sprite.resetFrameCount();
  5512. this._sprite.setFixedFrame(null);
  5513. this._sprite.updateBitmap();
  5514. this._sprite.updatePosition();
  5515. };
  5516.  
  5517. TBSEntity.prototype.setFixedPose = function (pose, frame) {
  5518. this._pose = pose;
  5519. this._sprite.updatePose();
  5520. if (frame === "last")
  5521. frame = this._sprite._maxFrame[this._sprite.getPose()];
  5522. this._fixedPose = pose;
  5523. this._afterPose = null;
  5524. this._poseLoop = false;
  5525. this._sprite.resetFrameCount();
  5526. this._sprite.setFixedFrame(Number(frame));
  5527. this._sprite.updateBitmap();
  5528. this._sprite.updatePosition();
  5529. };
  5530.  
  5531. TBSEntity.prototype.onPosePlayed = function (oldPose) {
  5532. if (this._fixedPose) {
  5533. this._pose = this._fixedPose;
  5534. this._sprite.updatePose();
  5535. return;
  5536. }
  5537. if (this._poseLoop) {
  5538. this.setPose(oldPose, oldPose);
  5539. } else {
  5540. this.setPose(this._afterPose);
  5541. this._afterPose = "idle";
  5542. }
  5543. this._requestPlayPose = false;
  5544. };
  5545.  
  5546. TBSEntity.prototype.setDir = function (dir) {
  5547. if (![2, 4, 6, 8].contains(dir)) return;
  5548. this._lastDir = this.getDir();
  5549. this._dir = dir;
  5550. this._sprite.update();
  5551. };
  5552.  
  5553. TBSEntity.prototype.getDir = function () {
  5554. return this._dir;
  5555. };
  5556.  
  5557. TBSEntity.prototype.setCell = function (cell) {
  5558. var x = cell.x * $gameMap.tileWidth();
  5559. var y = cell.y * $gameMap.tileHeight();
  5560. this.setPosition(x, y);
  5561. this._cellX = cell.x;
  5562. this._cellY = cell.y;
  5563. this._cell = cell;
  5564. };
  5565.  
  5566. TBSEntity.prototype.setPosition = function (x, y) {
  5567. this._posX = x;
  5568. this._posY = y;
  5569. };
  5570.  
  5571. TBSEntity.prototype.shiftPosition = function (x, y) {
  5572. this._posX += x;
  5573. this._posY += y;
  5574. };
  5575.  
  5576. TBSEntity.prototype.update = function () {
  5577. this.checkDeath();
  5578. this.updateMove();
  5579. };
  5580.  
  5581. TBSEntity.prototype.checkDeath = function () {
  5582. if (this._battler.isDead() && !this._dead) {
  5583. this.onDeath();
  5584. } else {
  5585. this.onRevive();
  5586. }
  5587. };
  5588.  
  5589. TBSEntity.prototype.onBattleStart = function () {
  5590. this._battler.onBattleStart();
  5591. this.setMovePoints();
  5592. };
  5593.  
  5594. TBSEntity.prototype.onTurnStart = function () {
  5595. if (this._battler.onTurnStart) //- Compatibility for YEA
  5596. this._battler.onTurnStart();
  5597. this.setMovePoints();
  5598. this.callSequence("turn_start");
  5599. };
  5600.  
  5601. TBSEntity.prototype.onTurnEnd = function () {
  5602. this._battler.onTurnEnd();
  5603. this.addPopup();
  5604. this.setMovePoints();
  5605. this._movePerformed = false;
  5606. this._actionPerformed = false;
  5607. };
  5608.  
  5609. TBSEntity.prototype.onDeath = function () {
  5610. this._dead = true;
  5611. this.appendSequence("dead");
  5612. BattleManagerTBS.onEntityDeath(this);
  5613. };
  5614.  
  5615. TBSEntity.prototype.onRevive = function () {
  5616.  
  5617. };
  5618.  
  5619. TBSEntity.prototype.lookAt = function (cell) {
  5620. var downD = cell.y - this._cellY;
  5621. var upD = this._cellY - cell.y;
  5622. var rightD = cell.x - this._cellX;
  5623. var leftD = this._cellX - cell.x;
  5624. var maxD = LeUtilities.getMaxInArray([downD, upD, rightD, leftD]);
  5625. switch (maxD) {
  5626. case downD:
  5627. this.setDir(2);
  5628. break;
  5629. case upD:
  5630. this.setDir(8);
  5631. break;
  5632. case leftD:
  5633. this.setDir(4);
  5634. break;
  5635. case rightD:
  5636. this.setDir(6);
  5637. break;
  5638. }
  5639. };
  5640.  
  5641. TBSEntity.prototype.lookAway = function (cell) {
  5642. this.lookAt(cell);
  5643. switch (this.getDir()) {
  5644. case 2:
  5645. this.setDir(8);
  5646. break;
  5647. case 4:
  5648. this.setDir(6);
  5649. break;
  5650. case 6:
  5651. this.setDir(4);
  5652. break;
  5653. case 8:
  5654. this.setDir(2);
  5655. break;
  5656. }
  5657. };
  5658.  
  5659. TBSEntity.prototype.getDirectionTo = function (cell) {
  5660. var oldDir = this.getDir();
  5661. this.lookAt(cell);
  5662. var dir = this.getDir();
  5663. this.setDir(oldDir);
  5664. return dir;
  5665. };
  5666.  
  5667. TBSEntity.prototype.getDirectionAwayFrom = function (cell) {
  5668. var oldDir = this.getDir();
  5669. this.lookAway(cell);
  5670. var dir = this.getDir();
  5671. this.setDir(oldDir);
  5672. return dir;
  5673. };
  5674.  
  5675. TBSEntity.prototype.startShake = function (power, duration) {
  5676. this._sprite._shakeEffect = {
  5677. power: power,
  5678. duration: duration
  5679. };
  5680. };
  5681.  
  5682. TBSEntity.prototype.lookClosestBattler = function (entities) {
  5683. if (entities.length === 0) return;
  5684. var entity = LeUtilities.closestByDistance(this, entities);
  5685. var cell = BattleManagerTBS.getEntityCell(entity);
  5686. this.lookAt(cell);
  5687. };
  5688.  
  5689. TBSEntity.prototype.processMovement = function (path) {
  5690. if (path.length === 0) return;
  5691. this._moving = true;
  5692. this._movePath = path;
  5693. this._movePath.reverse();
  5694. this.setPose("move", "move");
  5695. this._moveReducePoints = true;
  5696. this._moveUpdateDir = true;
  5697. };
  5698.  
  5699. TBSEntity.prototype.forceMoveStraight = function (nbrCells, checkCollision) {
  5700. this._movePath = [];
  5701. var cx = this._cellX;
  5702. var cy = this._cellY;
  5703. this._collisionData = {
  5704. distance: nbrCells,
  5705. covered: 0,
  5706. dir: this.getDir(),
  5707. endCell: null
  5708. };
  5709. for (var i = 0; i < nbrCells; i++) {
  5710. var cell = this.getForwardCell(cx, cy);
  5711. if (!cell || cell.isObstacle()) { // || cell.isImpassableTile()
  5712. this._collisionData.endCell = cell;
  5713. break;
  5714. }
  5715. this._collisionData.covered++;
  5716. this._movePath.push(cell);
  5717. switch (this.getDir()) {
  5718. case 2:
  5719. cy++;
  5720. break;
  5721. case 4:
  5722. cx--;
  5723. break;
  5724. case 6:
  5725. cx++;
  5726. break;
  5727. case 8:
  5728. cy--;
  5729. break;
  5730. }
  5731. }
  5732. if (!checkCollision) this._collisionData = null;
  5733. if (this._movePath.length === 0) return;
  5734. this._moving = true;
  5735. this._movingStraight = true;
  5736. this._movePath.reverse();
  5737. this._moveReducePoints = false;
  5738. this._moveUpdateDir = true;
  5739. };
  5740.  
  5741. TBSEntity.prototype.forcePush = function (user, sourceCell, distance, obj, damage) {
  5742. if (this.isImmuneToKnockback())
  5743. return;
  5744. distance += user.getKnockbackBonus() - this.getKnockbackReduction();
  5745. var old = this.getDir();
  5746. this.lookAway(sourceCell);
  5747. this.forceMoveStraight(distance, damage);
  5748. this.setDir(old);
  5749. this._moveUpdateDir = false;
  5750. if (this._collisionData) {
  5751. this._collisionData.user = user;
  5752. this._collisionData.obj = obj;
  5753. }
  5754.  
  5755. if (this._movePath.length === 0 && this._collisionData)
  5756. BattleManagerTBS.processCollisionEffects(this);
  5757. };
  5758.  
  5759. TBSEntity.prototype.forcePull = function (user, sourceCell, distance, obj, damage) {
  5760. var old = this.getDir();
  5761. this.lookAt(sourceCell);
  5762. this.forceMoveStraight(distance, damage);
  5763. this.setDir(old);
  5764. this._moveUpdateDir = false;
  5765. if (this._collisionData) {
  5766. this._collisionData.user = user;
  5767. this._collisionData.obj = obj;
  5768. }
  5769.  
  5770. if (this._movePath.length === 0 && this._collisionData)
  5771. BattleManagerTBS.processCollisionEffects(this);
  5772. };
  5773.  
  5774. TBSEntity.prototype.getForwardCell = function (cx, cy) {
  5775. cx = cx || this._cellX;
  5776. cy = cy || this._cellY;
  5777. switch (this.getDir()) {
  5778. case 2:
  5779. return BattleManagerTBS.getCellAt(cx, cy + 1);
  5780. case 4:
  5781. return BattleManagerTBS.getCellAt(cx - 1, cy);
  5782. case 6:
  5783. return BattleManagerTBS.getCellAt(cx + 1, cy);
  5784. case 8:
  5785. return BattleManagerTBS.getCellAt(cx, cy - 1);
  5786. }
  5787. return null;
  5788. };
  5789.  
  5790. TBSEntity.prototype.updateMove = function () {
  5791. if (!this._moving) return;
  5792. if (!this._movingNextCell) {
  5793. this._movingNextCell = this._movePath.pop();
  5794. this._movingDistance = [0, 0];
  5795. }
  5796. var cell = this._movingNextCell;
  5797. var oldDir = this.getDir();
  5798. this.lookAt(cell);
  5799. this.moveForward(cell);
  5800. if (!this._moveUpdateDir)
  5801. this.setDir(oldDir);
  5802. if (this._cellX == cell.x && this._cellY == cell.y) {
  5803. var stop = this.onCellCovered();
  5804. if (this._movePath.length === 0 || stop)
  5805. this.onMoveEnd(!stop);
  5806. }
  5807. };
  5808.  
  5809. TBSEntity.prototype.onCellCovered = function () {
  5810. // When returning true, the movement is stoped
  5811. this._movingNextCell = null;
  5812. if (this._moveReducePoints) {
  5813. this._movePoints--;
  5814. if (this.getMovePoints() === 0)
  5815. return true;
  5816. }
  5817. return false;
  5818. };
  5819.  
  5820. TBSEntity.prototype.moveForward = function (cell) {
  5821. var speed = this._speed;
  5822. var dir = this._sprite._dir;
  5823. switch (dir) {
  5824. case 2:
  5825. this.shiftPosition(0, speed);
  5826. this._movingDistance[1] += speed;
  5827. break;
  5828. case 4:
  5829. this.shiftPosition(-speed, 0);
  5830. this._movingDistance[0] += speed;
  5831. break;
  5832. case 6:
  5833. this.shiftPosition(speed, 0);
  5834. this._movingDistance[0] += speed;
  5835. break;
  5836. case 8:
  5837. this.shiftPosition(0, -speed);
  5838. this._movingDistance[1] += speed;
  5839. break;
  5840. }
  5841. if (this._movingDistance[0] >= $gameMap.tileWidth() || this._movingDistance[1] >= $gameMap.tileHeight())
  5842. this.setCell(cell);
  5843. };
  5844.  
  5845. TBSEntity.prototype.onMoveEnd = function () {
  5846. this._moving = false;
  5847. if (this._dead)
  5848. this.setPose("dead", "dead");
  5849. else
  5850. this.setPose("idle");
  5851. this._moveReducePoints = false;
  5852.  
  5853. if (this._collisionData)
  5854. BattleManagerTBS.processCollisionEffects(this);
  5855. this._collisionData = null;
  5856. this._movingStraight = false;
  5857. };
  5858.  
  5859. TBSEntity.prototype.teleport = function (cell) {
  5860. this.setCell(cell);
  5861. };
  5862.  
  5863. TBSEntity.prototype.followTrajectory = function (trajectory, cell) {
  5864. if (cell.x < this.getCell().x) {
  5865. trajectory = trajectory.reverse();
  5866. }
  5867. this._sprite.setTrajectory(trajectory, cell);
  5868. };
  5869.  
  5870. TBSEntity.prototype.setMovePoints = function () {
  5871. var obj = this._battler.isActor() ? this._battler.actor() : this._battler.enemy();
  5872. this._movePoints = obj.leTbs_movePoints;
  5873. this._battler.states().forEach(function (state) {
  5874. if (state)
  5875. this._movePoints += state.leTbs_movePointsPlus;
  5876. }.bind(this));
  5877. if (this._battler.isActor()) {
  5878. this._battler.equips().forEach(function (equip) {
  5879. if (equip)
  5880. this._movePoints += equip.leTbs_movePointsPlus;
  5881. }.bind(this));
  5882. }
  5883. };
  5884.  
  5885. TBSEntity.prototype.changeMovePoints = function (plus) {
  5886. this._movePoints += plus;
  5887. };
  5888.  
  5889. TBSEntity.prototype.getMovePoints = function () {
  5890. return this._movePoints.clamp(0, this._movePoints);
  5891. };
  5892.  
  5893. TBSEntity.prototype.canMoveCommand = function () {
  5894. if (this.getMovePoints() === 0) return false;
  5895. if (this.oneTimeMove() && this._movePerformed) return false;
  5896. return true;
  5897. };
  5898.  
  5899. TBSEntity.prototype.canAttackCommand = function () {
  5900. if (!this._battler.canAttack()) return false;
  5901. if (!this.canObjCommand()) return false;
  5902. return true;
  5903. };
  5904.  
  5905. TBSEntity.prototype.canSkillCommand = function () {
  5906. if (!this.canObjCommand()) return false;
  5907. return true;
  5908. };
  5909.  
  5910. TBSEntity.prototype.canItemCommand = function () {
  5911. if (!this.canObjCommand()) return false;
  5912. return true;
  5913. };
  5914.  
  5915. TBSEntity.prototype.canObjCommand = function () {
  5916. if (this.oneTimeOffense() && this._actionPerformed) return false;
  5917. return true;
  5918. };
  5919.  
  5920. TBSEntity.prototype.getAttackAnimation = function () {
  5921. if (this._battler.isActor()) {
  5922. return this._battler.attackAnimationId1();
  5923. } else {
  5924. return this._battler.enemy().leTbs_atkAnim;
  5925. }
  5926. };
  5927.  
  5928. TBSEntity.prototype.getAttackScopeData = function () {
  5929. if (this._battler.isEnemy())
  5930. return this._battler.enemy().leTbs_atkScopeData;
  5931. else {
  5932. for (var i = 0; i < this._battler.weapons().length; i++) {
  5933. var weapon = this._battler.weapons()[i];
  5934. if (weapon && weapon.leTbs_scopeData)
  5935. return weapon.leTbs_scopeData;
  5936. }
  5937. return this._battler.actor().leTbs_atkScopeData;
  5938. }
  5939. };
  5940.  
  5941. TBSEntity.prototype.getObjectScopeData = function (obj) {
  5942. var defaultScope = DataManager.isSkill(obj) ? Lecode.S_TBS.defaultSkillScope : Lecode.S_TBS.defaultItemScope;
  5943. return obj.leTbs_scopeData || defaultScope;
  5944. };
  5945.  
  5946. TBSEntity.prototype.getAttackAoEData = function () {
  5947. if (this._battler.isEnemy())
  5948. return this._battler.enemy().leTbs_atkAoeData;
  5949. else {
  5950. for (var i = 0; i < this._battler.weapons().length; i++) {
  5951. var weapon = this._battler.weapons()[i];
  5952. if (weapon && weapon.leTbs_aoeData)
  5953. return weapon.leTbs_aoeData;
  5954. }
  5955. return this._battler.actor().leTbs_atkAoeData;
  5956. }
  5957. };
  5958.  
  5959. TBSEntity.prototype.getObjectAoEData = function (obj) {
  5960. var defaultAoe = DataManager.isSkill(obj) ? Lecode.S_TBS.defaultSkillAoE : Lecode.S_TBS.defaultItemAoE;
  5961. return obj.leTbs_aoeData || defaultAoe;
  5962. };
  5963.  
  5964. TBSEntity.prototype.getMoveScopeData = function () {
  5965. return this.getMoveScopeRawData().replace("_mp_", String(this.getMovePoints()));
  5966. };
  5967.  
  5968. TBSEntity.prototype.getMoveScopeRawData = function () {
  5969. for (var i = 0; i < this._battler.states().length; i++) {
  5970. var state = this._battler.states()[i];
  5971. if (state && state.leTbs_moveScopeData)
  5972. return state.leTbs_moveScopeData;
  5973. }
  5974. if (this._battler.isEnemy())
  5975. return this._battler.enemy().leTbs_moveScopeData;
  5976. else {
  5977. for (var i = 0; i < this._battler.equips().length; i++) {
  5978. var equip = this._battler.equips()[i];
  5979. if (equip && equip.leTbs_moveScopeData)
  5980. return equip.leTbs_moveScopeData;
  5981. }
  5982. return this._battler.actor().leTbs_moveScopeData;
  5983. }
  5984. };
  5985.  
  5986. TBSEntity.prototype.getMoveScopeParamData = function () {
  5987. for (var i = 0; i < this._battler.states().length; i++) {
  5988. var state = this._battler.states()[i];
  5989. if (state && state.leTbs_moveScopeParam)
  5990. return state.leTbs_moveScopeParam;
  5991. }
  5992. if (this._battler.isEnemy())
  5993. return this._battler.enemy().leTbs_moveScopeParam;
  5994. else {
  5995. for (var i = 0; i < this._battler.equips().length; i++) {
  5996. var equip = this._battler.equips()[i];
  5997. if (equip && equip.leTbs_moveScopeParam)
  5998. return equip.leTbs_moveScopeParam;
  5999. }
  6000. return this._battler.actor().leTbs_moveScopeParam;
  6001. }
  6002. };
  6003.  
  6004. TBSEntity.prototype.getWeaponSequenceData = function () {
  6005. if (this._battler.isEnemy())
  6006. return this._battler.enemy().leTbs_atkSequenceData;
  6007. else {
  6008. for (var i = 0; i < this._battler.weapons().length; i++) {
  6009. var weapon = this._battler.weapons()[i];
  6010. if (weapon && weapon.leTbs_sequenceData)
  6011. return weapon.leTbs_sequenceData;
  6012. }
  6013. return this._battler.actor().leTbs_atkSequenceData;
  6014. }
  6015. };
  6016.  
  6017. TBSEntity.prototype.getObjectSequenceData = function (obj) {
  6018. var defaultSeqId = DataManager.isSkill(obj) ? Lecode.S_TBS.defaultSkillSequence : Lecode.S_TBS.defaultItemSequence;
  6019. return obj.leTbs_sequenceData || defaultSeqId;
  6020. };
  6021.  
  6022. TBSEntity.prototype.passAfterObjUse = function (obj) {
  6023. if (DataManager.isSkill(obj)) {
  6024. if (this._battler.isEnemy())
  6025. return !!this._battler.leTbs_passOnAtkUse;
  6026. if (obj.id == this._battler.attackSkillId()) {
  6027. if (this._battler.weapons().length > 0)
  6028. return !!this._battler.weapons()[0].leTbs_passOnUse;
  6029. }
  6030. }
  6031. return !!obj.leTbs_passOnUse;
  6032. };
  6033.  
  6034. TBSEntity.prototype.oneTimeMove = function () {
  6035. return this.rpgObject().leTbs_oneTimeMove;
  6036. };
  6037.  
  6038. TBSEntity.prototype.oneTimeOffense = function () {
  6039. return this.rpgObject().leTbs_oneTimeOffense;
  6040. };
  6041.  
  6042. TBSEntity.prototype.getCollapseAnimation = function () {
  6043. return this.rpgObject().leTbs_collapseAnim;
  6044. };
  6045.  
  6046. TBSEntity.prototype.getAiPattern = function () {
  6047. return this.rpgObject().leTbs_aiPattern;
  6048. };
  6049.  
  6050. TBSEntity.prototype.isPassableOnDeath = function () {
  6051. var test = this.battler().states().some(function (state) {
  6052. return state && state.leTbs_passableOnDeath;
  6053. });
  6054. if (test) return true;
  6055. return this.rpgObject().leTbs_passableOnDeath;
  6056. };
  6057.  
  6058. TBSEntity.prototype.isPassable = function () {
  6059. var test = this._battler.isDead() && this.isPassableOnDeath();
  6060. if (test) return true;
  6061. test = this.battler().states().some(function (state) {
  6062. return state && state.leTbs_passable;
  6063. });
  6064. if (test) return true;
  6065. return this.rpgObject().leTbs_passable;
  6066. };
  6067.  
  6068. TBSEntity.prototype.entitiesCanLayOnMe = function () {
  6069. var test = this._battler.isDead() && this.isPassableOnDeath();
  6070. if (test) return true;
  6071. test = this.battler().states().some(function (state) {
  6072. return state && state.leTbs_canLayOnMe;
  6073. });
  6074. if (test) return true;
  6075. return this.rpgObject().leTbs_canLayOnMe;
  6076. };
  6077.  
  6078. TBSEntity.prototype.getCollisionDamageBonus = function (damage) {
  6079. var bonus = 0;
  6080. this.battler().states().forEach(function (state) {
  6081. if (state) {
  6082. bonus += state.leTbs_collisionDmgBonus;
  6083. bonus += state.leTbs_collisionDmgBonusRate * 0.01 * damage;
  6084. }
  6085. });
  6086. if (this.battler().isActor()) {
  6087. this.battler().equips().forEach(function (equip) {
  6088. if (equip) {
  6089. bonus += equip.leTbs_collisionDmgBonus;
  6090. bonus += equip.leTbs_collisionDmgBonusRate * 0.01 * damage;
  6091. }
  6092. });
  6093. }
  6094. return bonus;
  6095. };
  6096.  
  6097. TBSEntity.prototype.getCollisionDamageReduction = function (damage) {
  6098. var reduction = 0;
  6099. this.battler().states().forEach(function (state) {
  6100. if (state) {
  6101. reduction += state.leTbs_collisionDmgReduction;
  6102. reduction += state.leTbs_collisionDmgReductionRate * 0.01 * damage;
  6103. }
  6104. });
  6105. if (this.battler().isActor()) {
  6106. this.battler().equips().forEach(function (equip) {
  6107. if (equip) {
  6108. reduction += equip.leTbs_collisionDmgReduction;
  6109. reduction += equip.leTbs_collisionDmgReductionRate * 0.01 * damage;
  6110. }
  6111. });
  6112. }
  6113. return reduction;
  6114. };
  6115.  
  6116. TBSEntity.prototype.getDirectionalDmgBonus = function (type) {
  6117. var value = this.rpgObject().leTbs_directionalDmgBonus[type];
  6118. this.battler().states().forEach(function (state) {
  6119. if (state) {
  6120. value += state.leTbs_directionalDmgBonus[type];
  6121. }
  6122. });
  6123. if (this.battler().isActor()) {
  6124. this.battler().equips().forEach(function (equip) {
  6125. if (equip) {
  6126. value += equip.leTbs_directionalDmgBonus[type];
  6127. }
  6128. });
  6129. }
  6130. return value;
  6131. };
  6132.  
  6133. TBSEntity.prototype.getDirectionalDmgReduction = function (type) {
  6134. var value = this.rpgObject().leTbs_directionalDmgReduction[type];
  6135. this.battler().states().forEach(function (state) {
  6136. if (state) {
  6137. value += state.leTbs_directionalDmgReduction[type];
  6138. }
  6139. });
  6140. if (this.battler().isActor()) {
  6141. this.battler().equips().forEach(function (equip) {
  6142. if (equip) {
  6143. value += equip.leTbs_directionalDmgReduction[type];
  6144. }
  6145. });
  6146. }
  6147. return value;
  6148. };
  6149.  
  6150. TBSEntity.prototype.isImmuneToKnockback = function () {
  6151. return this.rpgObject().leTbs_immuneKnockback;
  6152. };
  6153.  
  6154. TBSEntity.prototype.getKnockbackBonus = function () {
  6155. var bonus = 0;
  6156. bonus += this.rpgObject().leTbs_knockbackBonus;
  6157. this.battler().states().forEach(function (state) {
  6158. if (state) {
  6159. bonus += state.leTbs_knockbackBonus;
  6160. }
  6161. });
  6162. if (this.battler().isActor()) {
  6163. this.battler().equips().forEach(function (equip) {
  6164. if (equip) {
  6165. bonus += equip.leTbs_knockbackBonus;
  6166. }
  6167. });
  6168. }
  6169. return bonus;
  6170. };
  6171.  
  6172. TBSEntity.prototype.getKnockbackReduction = function () {
  6173. var reduction = 0;
  6174. reduction += this.rpgObject().leTbs_knockbackReduction;
  6175. this.battler().states().forEach(function (state) {
  6176. if (state) {
  6177. reduction += state.leTbs_knockbackReduction;
  6178. }
  6179. });
  6180. if (this.battler().isActor()) {
  6181. this.battler().equips().forEach(function (equip) {
  6182. if (equip) {
  6183. reduction += equip.leTbs_knockbackReduction;
  6184. }
  6185. });
  6186. }
  6187. return reduction;
  6188. };
  6189.  
  6190.  
  6191. TBSEntity.prototype.addPopup = function () {
  6192. this._sprite.addPopup();
  6193. };
  6194.  
  6195. TBSEntity.prototype.battler = function () {
  6196. return this._battler;
  6197. };
  6198.  
  6199. TBSEntity.prototype.sprite = function () {
  6200. return this._sprite;
  6201. };
  6202.  
  6203. TBSEntity.prototype.width = function () {
  6204. return this._sprite.width;
  6205. };
  6206.  
  6207. TBSEntity.prototype.height = function () {
  6208. return this._sprite.height;
  6209. };
  6210.  
  6211. TBSEntity.prototype.getCell = function () {
  6212. return this._cell;
  6213. };
  6214.  
  6215. TBSEntity.prototype.isMoving = function () {
  6216. return this._moving;
  6217. };
  6218.  
  6219. TBSEntity.prototype.rpgObject = function () {
  6220. return this.battler().isActor() ? this.battler().actor() : this.battler().enemy();
  6221. };
  6222.  
  6223. /*-------------------------------------------------------------------------
  6224. * TBSEntity_Sprite
  6225. -------------------------------------------------------------------------*/
  6226. function TBSEntity_Sprite() {
  6227. this.initialize.apply(this, arguments);
  6228. }
  6229.  
  6230. TBSEntity_Sprite.prototype = Object.create(Sprite_Base.prototype);
  6231. TBSEntity_Sprite.prototype.constructor = TBSEntity_Sprite;
  6232.  
  6233. TBSEntity_Sprite.prototype.initialize = function (battler, entity) {
  6234. Sprite_Base.prototype.initialize.call(this);
  6235. this._battler = battler;
  6236. this._entity = entity;
  6237. this._bitmaps = {};
  6238. this._frameCount = 0;
  6239. this._maxFrame = {};
  6240. this._fixedFrame = null;
  6241. this._updateCount = 0;
  6242. this._poses = [];
  6243. this._frameLoaded = 0;
  6244. this._popups = [];
  6245. this._shakeEffect = {
  6246. power: 0,
  6247. duration: 0
  6248. };
  6249. this._trajectoryIndex = 0;
  6250. this._trajectory = [];
  6251. this._trajectoryEndCell = null;
  6252. this.initializeFrameDelay();
  6253. this.createBitmaps(battler);
  6254. };
  6255.  
  6256. TBSEntity_Sprite.prototype.initializeFrameDelay = function () {
  6257. this.setFrameDelay(Lecode.S_TBS.battlersFrameDelay);
  6258. };
  6259.  
  6260. TBSEntity_Sprite.prototype.setFrameDelay = function (delay) {
  6261. this._frameDelay = delay;
  6262. };
  6263.  
  6264. TBSEntity_Sprite.prototype.changeFrameDelay = function (delay) {
  6265. this._frameDelay += delay;
  6266. };
  6267.  
  6268. TBSEntity_Sprite.prototype.onPosePlayed = function () {
  6269. this._frameCount = 0;
  6270. this._entity.onPosePlayed(this.getPose());
  6271. };
  6272.  
  6273. TBSEntity_Sprite.prototype.resetFrameCount = function () {
  6274. this._frameCount = 0;
  6275. };
  6276.  
  6277. TBSEntity_Sprite.prototype.setFixedFrame = function (frame) {
  6278. this._fixedFrame = frame;
  6279. };
  6280.  
  6281. TBSEntity_Sprite.prototype.setTrajectory = function (trajectory, cell) {
  6282. this._trajectoryIndex = 0;
  6283. this._trajectory = trajectory;
  6284. this._trajectoryEndCell = cell;
  6285. };
  6286.  
  6287. TBSEntity_Sprite.prototype.hasTrajectory = function () {
  6288. return !!this._trajectory[this._trajectoryIndex];
  6289. };
  6290.  
  6291. TBSEntity_Sprite.prototype.update = function () {
  6292. Sprite_Base.prototype.update.call(this);
  6293. if (!this.isReady()) return;
  6294. this.updateDirection();
  6295. this.updatePose();
  6296. this.updateFrameDelay();
  6297. this.updatePosition();
  6298. this.updatePopups();
  6299. };
  6300.  
  6301. TBSEntity_Sprite.prototype.updateFrameDelay = function () {
  6302. this._updateCount++;
  6303. if (this._updateCount === this._frameDelay) {
  6304. this._updateCount = 0;
  6305. this.onNextFrame();
  6306. }
  6307. };
  6308.  
  6309. TBSEntity_Sprite.prototype.onNextFrame = function () {
  6310. this.updateBitmap();
  6311. this.updateFrameCount();
  6312. };
  6313.  
  6314. TBSEntity_Sprite.prototype.updateDirection = function () {
  6315. this._dir = this._entity._dir;
  6316. };
  6317.  
  6318. TBSEntity_Sprite.prototype.updatePose = function () {
  6319. this._pose = this._entity._pose;
  6320. };
  6321.  
  6322. TBSEntity_Sprite.prototype.updatePosition = function () {
  6323. this.updateTrajectoryMove();
  6324. this.x = this._entity._posX;
  6325. this.y = this._entity._posY;
  6326. if (this.bitmap) {
  6327. var w = this.bitmap.width / (this._maxFrame[this.getPose()] + 1);
  6328. var h = this.bitmap.height / 4;
  6329. this.x += $gameMap.tileWidth() / 2 - w / 2;
  6330. this.y += $gameMap.tileHeight() - h;
  6331. }
  6332. this.updateShakeEffect();
  6333. };
  6334.  
  6335. TBSEntity_Sprite.prototype.updateTrajectoryMove = function () {
  6336. if (this.hasTrajectory()) {
  6337. var pos = this._trajectory[this._trajectoryIndex];
  6338. this._trajectoryIndex += this._entity._speed;
  6339. if (!this.hasTrajectory()) {
  6340. this._entity.setCell(this._trajectoryEndCell);
  6341. } else {
  6342. this._entity.setPosition(pos[0], pos[1]);
  6343. }
  6344. }
  6345. };
  6346.  
  6347. TBSEntity_Sprite.prototype.updateShakeEffect = function () {
  6348. var min = this._shakeEffect.power * 0.6;
  6349. var max = this._shakeEffect.power * 1.6;
  6350. var d = this._shakeEffect.duration--;
  6351. if (d > 0) {
  6352. this.x += LeUtilities.randValueBetween(min, max) * LeUtilities.randValueBetween(-1, 1);
  6353. this.y += LeUtilities.randValueBetween(min, max) * LeUtilities.randValueBetween(-1, 1);
  6354. }
  6355. };
  6356.  
  6357. TBSEntity_Sprite.prototype.updateBitmap = function () {
  6358. var pose = this.getPose();
  6359. this.bitmap = this._bitmaps[pose];
  6360. var w = this.bitmap.width / (this._maxFrame[pose] + 1);
  6361. var h = this.bitmap.height / 4;
  6362. var x;
  6363. var y;
  6364. var frame = this._fixedFrame != null ? this._fixedFrame : this._frameCount;
  6365. x = w * frame;
  6366. y = (h * this._dir) / 2 - h;
  6367. this.setFrame(x, y, w, h);
  6368. };
  6369.  
  6370. TBSEntity_Sprite.prototype.updateFrameCount = function () {
  6371. var pose = this.getPose();
  6372. if (this._frameCount > this._maxFrame[pose]) {
  6373. this.onPosePlayed();
  6374. } else {
  6375. this._frameCount++;
  6376. }
  6377. };
  6378.  
  6379. TBSEntity_Sprite.prototype.updatePopups = function () {
  6380. if (this._popups.length === 0) return;
  6381. this._popups.forEach(function (popup) {
  6382. popup.update();
  6383. }.bind(this));
  6384. if (!this._popups[0].isPlaying()) {
  6385. this.removePopup(this._popups[0]);
  6386. }
  6387. };
  6388.  
  6389. TBSEntity_Sprite.prototype.removePopup = function (popup) {
  6390. BattleManagerTBS.getLayer("movableInfo").removeChild(popup);
  6391. this._popups.shift();
  6392. };
  6393.  
  6394. TBSEntity_Sprite.prototype.createBitmaps = function (battler) {
  6395. var config = this.getConfig(battler);
  6396. config.forEach(function (info) {
  6397. var pose = info[0];
  6398. var filename = this.filenameID(battler) + info[1];
  6399. var hue = info[3] || 0;
  6400. this._poses.push(pose);
  6401. var fullBitmap = ImageManager.loadLeTBSBattler(filename, hue);
  6402. fullBitmap.addLoadListener(this.createPoseBitmaps.bind(this, fullBitmap, pose, info));
  6403. }.bind(this));
  6404. };
  6405.  
  6406. TBSEntity_Sprite.prototype.createPoseBitmaps = function (fbitmap, pose, info) {
  6407. var frames = info[2];
  6408. this._maxFrame[pose] = frames - 1;
  6409. this._bitmaps[pose] = fbitmap;
  6410. this._frameLoaded++;
  6411. };
  6412.  
  6413. TBSEntity_Sprite.prototype.addPopup = function () {
  6414. var sprite = new Sprite_Damage();
  6415. sprite.x = this.x + this.width / 2;
  6416. sprite.y = this.y;
  6417. sprite.setup(this._battler);
  6418. this._popups.push(sprite);
  6419. BattleManagerTBS.getLayer("movableInfo").addChild(sprite);
  6420. };
  6421.  
  6422. TBSEntity_Sprite.prototype.isReady = function () {
  6423. return this._frameLoaded === this._poses.length;
  6424. };
  6425.  
  6426. TBSEntity_Sprite.prototype.getPose = function () {
  6427. return this.isValidPose(this._pose) ? this._pose : "idle";
  6428. };
  6429.  
  6430. TBSEntity_Sprite.prototype.getConfig = function (battler) {
  6431. var id = battler.isActor() ? battler.name() : battler.originalName();
  6432. var config = Lecode.S_TBS.Config.Battler_Sprites[id];
  6433. if (!config) config = Lecode.S_TBS.Config.Battler_Sprites["Default"];
  6434. return config;
  6435. };
  6436.  
  6437. TBSEntity_Sprite.prototype.isValidPose = function (pose) {
  6438. return this._poses.indexOf(pose) >= 0;
  6439. };
  6440.  
  6441. TBSEntity_Sprite.prototype.filenameID = function (battler) {
  6442. if (battler.isActor()) return battler.name();
  6443. return battler.originalName();
  6444. };
  6445.  
  6446. /*-------------------------------------------------------------------------
  6447. * TBSDirectionSelector
  6448. -------------------------------------------------------------------------*/
  6449. function TBSDirectionSelector() {
  6450. this.initialize.apply(this, arguments);
  6451. }
  6452.  
  6453. TBSDirectionSelector.prototype.initialize = function (layer) {
  6454. this._cell = null;
  6455. this._battlerEntity = null;
  6456. this.createSprite(layer);
  6457. };
  6458.  
  6459. TBSDirectionSelector.prototype.createSprite = function (layer) {
  6460. var bitmap = ImageManager.loadLeTBS("DirectionSelector", 0);
  6461. this._sprite = new Sprite(bitmap);
  6462. this._sprite.anchor.x = 0.5;
  6463. this._sprite.anchor.y = 0.5;
  6464. this._sprite.opacity = 0;
  6465. layer.addChild(this._sprite);
  6466. };
  6467.  
  6468. TBSDirectionSelector.prototype.set = function (cell, battler) {
  6469. this._cell = cell;
  6470. this._battlerEntity = battler;
  6471. this._sprite.x = cell.x * $gameMap.tileWidth() + $gameMap.tileWidth() / 2;
  6472. this._sprite.y = cell.y * $gameMap.tileHeight() + $gameMap.tileHeight() / 2;
  6473. this._sprite.opacity = 255;
  6474. this.setDir(battler.getDir());
  6475. };
  6476.  
  6477. TBSDirectionSelector.prototype.setDir = function (dir) {
  6478. this._battlerEntity.setDir(dir);
  6479. var r = 0;
  6480. switch (dir) {
  6481. case 2:
  6482. r = 0;
  6483. break;
  6484. case 4:
  6485. r = 90;
  6486. break;
  6487. case 6:
  6488. r = 90 * 3;
  6489. break;
  6490. case 8:
  6491. r = 90 * 2;
  6492. break;
  6493. }
  6494. this._sprite.rotation = r * Math.PI / 180;
  6495. SoundManager.playCursor();
  6496. };
  6497.  
  6498. TBSDirectionSelector.prototype.hide = function () {
  6499. this._sprite.opacity = 0;
  6500. };
  6501.  
  6502.  
  6503. /*-------------------------------------------------------------------------
  6504. * Window_TBSConfirm
  6505. -------------------------------------------------------------------------*/
  6506. function Window_TBSConfirm() {
  6507. this.initialize.apply(this, arguments);
  6508. }
  6509.  
  6510. /*-------------------------------------------------------------------------
  6511. * Window_TBSPlacementInfo
  6512. -------------------------------------------------------------------------*/
  6513.  
  6514. function Window_TBSPlacementInfo() {
  6515. this.initialize.apply(this, arguments);
  6516. }
  6517. /*-------------------------------------------------------------------------
  6518. * Window_TBSStatus
  6519. -------------------------------------------------------------------------*/
  6520. function Window_TBSStatus() {
  6521. this.initialize.apply(this, arguments);
  6522. }
  6523.  
  6524. /*-------------------------------------------------------------------------
  6525. * Window_TBSCommand
  6526. -------------------------------------------------------------------------*/
  6527. function Window_TBSCommand() {
  6528. this.initialize.apply(this, arguments);
  6529. }
  6530.  
  6531. /*-------------------------------------------------------------------------
  6532. * Window_TBSEndCommand
  6533. -------------------------------------------------------------------------*/
  6534. function Window_TBSEndCommand() {
  6535. this.initialize.apply(this, arguments);
  6536. }
  6537.  
  6538.  
  6539. /*=========================================================================
  6540. * RTPs MODIFS
  6541. =========================================================================*/
  6542.  
  6543.  
  6544. /*-------------------------------------------------------------------------
  6545. * Game_Battler
  6546. -------------------------------------------------------------------------*/
  6547. Lecode.S_TBS.oldGameBattler_initMembers = Game_Battler.prototype.initMembers;
  6548. Game_Battler.prototype.initMembers = function () {
  6549. Lecode.S_TBS.oldGameBattler_initMembers.call(this);
  6550. this._leTbsDirectionalDmg = 0;
  6551. };
  6552.  
  6553. Game_Battler.prototype.leTBS_setDirectionalDmgEffects = function (amount) {
  6554. this._leTbsDirectionalDmg = amount;
  6555. };
  6556.  
  6557. Lecode.S_TBS.oldGameBattler_addNewState = Game_Battler.prototype.addNewState;
  6558. Game_Battler.prototype.addNewState = function (stateId) {
  6559. if (LeUtilities.isScene("Scene_Battle") && Lecode.S_TBS.commandOn) {
  6560. var state = $dataStates[stateId];
  6561. var entity = BattleManagerTBS.getEntityByBattler(this);
  6562. entity.changeMovePoints(state.leTbs_movePointsPlus);
  6563. }
  6564. Lecode.S_TBS.oldGameBattler_addNewState.call(this, stateId);
  6565. };
  6566.  
  6567.  
  6568. /*-------------------------------------------------------------------------
  6569. * Game_Action
  6570. -------------------------------------------------------------------------*/
  6571. Lecode.S_TBS.oldGameAction_executeDamage = Game_Action.prototype.executeDamage;
  6572. Game_Action.prototype.executeDamage = function (target, value) {
  6573. value += value * target._leTbsDirectionalDmg;
  6574. Lecode.S_TBS.oldGameAction_executeDamage.call(this, target, Math.floor(value));
  6575. };
  6576.  
  6577.  
  6578. /*-------------------------------------------------------------------------
  6579. * Game_Interpreter
  6580. -------------------------------------------------------------------------*/
  6581. Lecode.S_TBS.old_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  6582. Game_Interpreter.prototype.pluginCommand = function (command, args) {
  6583. Lecode.S_TBS.old_pluginCommand.call(this, command, args);
  6584. if (command === 'LeTBS') {
  6585. switch (args[0]) {
  6586. case 'ON':
  6587. Lecode.S_TBS.commandOn = true;
  6588. break;
  6589. case 'OFF':
  6590. Lecode.S_TBS.commandOn = false;
  6591. break;
  6592. }
  6593. }
  6594. };
  6595.  
  6596. /*-------------------------------------------------------------------------
  6597. * DataManager
  6598. -------------------------------------------------------------------------*/
  6599. Lecode.S_TBS.oldDMisDatabaseLoaded_method = DataManager.isDatabaseLoaded;
  6600. DataManager.isDatabaseLoaded = function () {
  6601. if (!Lecode.S_TBS.oldDMisDatabaseLoaded_method.call(this)) return false;
  6602. this.processLeTBSTags();
  6603. return true;
  6604. };
  6605.  
  6606. DataManager.processLeTBSTags = function () {
  6607. this.processLeTBSTagsForBattlers();
  6608. this.processLeTBSTagsForEquipmentsAndStates();
  6609. this.processLeTBSTagsForObjects();
  6610. };
  6611.  
  6612. DataManager.processLeTBSTagsForBattlers = function () {
  6613. var groups = [$dataActors, $dataEnemies, $dataClasses];
  6614. for (var i = 0; i < groups.length; i++) {
  6615. var group = groups[i];
  6616. for (var j = 1; j < group.length; j++) {
  6617. var obj = group[j];
  6618. var notedata = obj.note.split(/[\r\n]+/);
  6619. var letbs = false;
  6620.  
  6621. obj.leTbs_movePoints = Lecode.S_TBS.defaultMovePoints;
  6622. obj.leTbs_moveScopeData = Lecode.S_TBS.defaultMoveScope;
  6623. obj.leTbs_moveScopeParam = "";
  6624. obj.leTbs_atkAnim = Lecode.S_TBS.defaultAttackAnimation;
  6625. obj.leTbs_atkScopeData = Lecode.S_TBS.defaultAttackScope;
  6626. obj.leTbs_atkAoeData = Lecode.S_TBS.defaultAttackAoE;
  6627. obj.leTbs_atkSequenceData = Lecode.S_TBS.defaultAttackSequence;
  6628. obj.leTbs_oneTimeMove = Lecode.S_TBS.oneTimeMove;
  6629. obj.leTbs_oneTimeOffense = Lecode.S_TBS.oneTimeOffense;
  6630. obj.leTbs_collapseAnim = Lecode.S_TBS.collapseAnimation;
  6631. obj.leTbs_passOnAtkUse = false;
  6632. obj.leTbs_aiPattern = Lecode.S_TBS.defaultAiPattern;
  6633. obj.leTbs_passable = false;
  6634. obj.leTbs_passableOnDeath = false;
  6635. obj.leTbs_canLayOnMe = false;
  6636. obj.leTbs_collisionDmgBonus = 0;
  6637. obj.leTbs_collisionDmgBonusRate = 0;
  6638. obj.leTbs_collisionDmgReduction = 0;
  6639. obj.leTbs_collisionDmgReductionRate = 0;
  6640. obj.leTbs_immuneKnockback = false;
  6641. obj.leTbs_knockbackBonus = 0;
  6642. obj.leTbs_knockbackReduction = 0;
  6643. obj.leTbs_directionalDmgBonus = {
  6644. face: 0,
  6645. back: 0,
  6646. side: 0
  6647. };
  6648. obj.leTbs_directionalDmgReduction = {
  6649. face: 0,
  6650. back: 0,
  6651. side: 0
  6652. };
  6653.  
  6654. for (var k = 0; k < notedata.length; k++) {
  6655. var line = notedata[k];
  6656. if (line.match(/<letbs>/i))
  6657. letbs = true;
  6658. else if (line.match(/<\/letbs>/i))
  6659. letbs = false;
  6660.  
  6661. if (letbs) {
  6662. if (line.match(/move_points\s?:\s?(.+)/i))
  6663. obj.leTbs_movePoints = Number(RegExp.$1);
  6664. else if (line.match(/move_scope\s?:\s?(.+)/i))
  6665. obj.leTbs_moveScopeData = String(RegExp.$1);
  6666. else if (line.match(/move_scope_options\s?:\s?((.|\n)*)/i))
  6667. obj.leTbs_moveScopeParam = String(RegExp.$1);
  6668. else if (line.match(/atk_anim\s?:\s?(.+)/i))
  6669. obj.leTbs_atkAnim = Number(RegExp.$1);
  6670. else if (line.match(/atk_scope\s?:\s?(.+)/i))
  6671. obj.leTbs_atkScopeData = String(RegExp.$1);
  6672. else if (line.match(/atk_aoe\s?:\s?(.+)/i))
  6673. obj.leTbs_atkAoeData = String(RegExp.$1);
  6674. else if (line.match(/atk_sequence\s?:\s?(.+)/i))
  6675. obj.leTbs_atkSequence = String(RegExp.$1);
  6676. else if (line.match(/one_time_move/i))
  6677. obj.leTbs_oneTimeMove = true;
  6678. else if (line.match(/one_time_offense/i))
  6679. obj.leTbs_oneTimeOffense = true;
  6680. else if (line.match(/collapse_anim\s?:\s?(.+)/i))
  6681. obj.leTbs_collapseAnim = Number(RegExp.$1);
  6682. else if (line.match(/pass_on_atk_use/i))
  6683. obj.leTbs_passOnAtkUse = true;
  6684. else if (line.match(/ai_pattern\s?:\s?(.+)/i))
  6685. obj.leTbs_aiPattern = String(RegExp.$1);
  6686. else if (line.match(/passable_on_death/i))
  6687. obj.leTbs_passableOnDeath = true;
  6688. else if (line.match(/passable/i))
  6689. obj.leTbs_passable = true;
  6690. else if (line.match(/entities_can_lay_on_me/i))
  6691. obj.leTbs_canLayOnMe = true;
  6692. else if (line.match(/collision_damage_bonus\s?:\s?(.+)/i))
  6693. obj.leTbs_collisionDmgBonus = Number(RegExp.$1);
  6694. else if (line.match(/collision_damage_bonus\%\s?:\s?(.+)/i))
  6695. obj.leTbs_collisionDmgBonusRate = Number(RegExp.$1);
  6696. else if (line.match(/collision_damage_reduction\s?:\s?(.+)/i))
  6697. obj.leTbs_collisionDmgReduction = Number(RegExp.$1);
  6698. else if (line.match(/collision_damage_reduction\%\s?:\s?(.+)/i))
  6699. obj.leTbs_collisionDmgReductionRate = Number(RegExp.$1);
  6700. else if (line.match(/immune_knockback/i))
  6701. obj.leTbs_immuneKnockback = true;
  6702. else if (line.match(/knockback_bonus\s?:\s?(.+)/i))
  6703. obj.leTbs_knockbackBonus = Number(RegExp.$1);
  6704. else if (line.match(/knockback_reduction\s?:\s?(.+)/i))
  6705. obj.leTbs_knockbackReduction = Number(RegExp.$1);
  6706. else if (line.match(/back_dmg_bonus\s?:\s?(.+)/i))
  6707. obj.leTbs_directionalDmgBonus.back = Number(RegExp.$1);
  6708. else if (line.match(/back_dmg_reduction\s?:\s?(.+)/i))
  6709. obj.leTbs_directionalDmgReduction.back = Number(RegExp.$1);
  6710. else if (line.match(/face_dmg_bonus\s?:\s?(.+)/i))
  6711. obj.leTbs_directionalDmgBonus.face = Number(RegExp.$1);
  6712. else if (line.match(/face_dmg_reduction\s?:\s?(.+)/i))
  6713. obj.leTbs_directionalDmgReduction.face = Number(RegExp.$1);
  6714. else if (line.match(/side_dmg_bonus\s?:\s?(.+)/i))
  6715. obj.leTbs_directionalDmgBonus.side = Number(RegExp.$1);
  6716. else if (line.match(/side_dmg_reduction\s?:\s?(.+)/i))
  6717. obj.leTbs_directionalDmgReduction.side = Number(RegExp.$1);
  6718. }
  6719. }
  6720. }
  6721. }
  6722. };
  6723.  
  6724. DataManager.processLeTBSTagsForEquipmentsAndStates = function () {
  6725. var groups = [$dataWeapons, $dataArmors, $dataStates];
  6726. for (var i = 0; i < groups.length; i++) {
  6727. var group = groups[i];
  6728. for (var j = 1; j < group.length; j++) {
  6729. var obj = group[j];
  6730. var notedata = obj.note.split(/[\r\n]+/);
  6731. var letbs = false;
  6732.  
  6733. obj.leTbs_movePointsPlus = 0;
  6734. obj.leTbs_scopeData = Lecode.S_TBS.defaultAttackScope;
  6735. obj.leTbs_aoeData = null;
  6736. obj.leTbs_sequenceData = null;
  6737. obj.leTbs_moveScopeData = null;
  6738. obj.leTbs_moveScopeParam = null;
  6739. obj.leTbs_passable = false;
  6740. obj.leTbs_passableOnDeath = false;
  6741. obj.leTbs_canLayOnMe = false;
  6742. obj.leTbs_collisionDmgBonus = 0;
  6743. obj.leTbs_collisionDmgBonusRate = 0;
  6744. obj.leTbs_collisionDmgReduction = 0;
  6745. obj.leTbs_collisionDmgReductionRate = 0;
  6746. obj.leTbs_immuneKnockback = false;
  6747. obj.leTbs_knockbackBonus = 0;
  6748. obj.leTbs_knockbackReduction = 0;
  6749. obj.leTbs_directionalDmgBonus = {
  6750. face: 0,
  6751. back: 0,
  6752. side: 0
  6753. };
  6754. obj.leTbs_directionalDmgReduction = {
  6755. face: 0,
  6756. back: 0,
  6757. side: 0
  6758. };
  6759.  
  6760. for (var k = 0; k < notedata.length; k++) {
  6761. var line = notedata[k];
  6762. if (line.match(/<letbs>/i))
  6763. letbs = true;
  6764. else if (line.match(/<\/letbs>/i))
  6765. letbs = false;
  6766.  
  6767. if (letbs) {
  6768. if (line.match(/move_points_plus\s?:\s?(.+)/i))
  6769. obj.leTbs_movePointsPlus = Number(RegExp.$1);
  6770. else if (line.match(/scope\s?:\s?(.+)/i))
  6771. obj.leTbs_scopeData = String(RegExp.$1);
  6772. else if (line.match(/aoe\s?:\s?(.+)/i))
  6773. obj.leTbs_aoeData = String(RegExp.$1);
  6774. else if (line.match(/sequence\s?:\s?(.+)/i))
  6775. obj.leTbs_sequenceData = String(RegExp.$1);
  6776. else if (line.match(/move_scope\s?:\s?(.+)/i))
  6777. obj.leTbs_moveScopeData = String(RegExp.$1);
  6778. else if (line.match(/move_scope_options\s?:\s?((.|\n)*)/i))
  6779. obj.leTbs_moveScopeParam = String(RegExp.$1);
  6780. else if (line.match(/passable_on_death/i))
  6781. obj.leTbs_passableOnDeath = true;
  6782. else if (line.match(/passable/i))
  6783. obj.leTbs_passable = true;
  6784. else if (line.match(/entities_can_lay_on_me/i))
  6785. obj.leTbs_canLayOnMe = true;
  6786. else if (line.match(/collision_damage_bonus\s?:\s?(.+)/i))
  6787. obj.leTbs_collisionDmgBonus = Number(RegExp.$1);
  6788. else if (line.match(/collision_damage_bonus\%\s?:\s?(.+)/i))
  6789. obj.leTbs_collisionDmgBonusRate = Number(RegExp.$1);
  6790. else if (line.match(/collision_damage_reduction\s?:\s?(.+)/i))
  6791. obj.leTbs_collisionDmgReduction = Number(RegExp.$1);
  6792. else if (line.match(/collision_damage_reduction\%\s?:\s?(.+)/i))
  6793. obj.leTbs_collisionDmgReductionRate = Number(RegExp.$1);
  6794. else if (line.match(/immune_knockback/i))
  6795. obj.leTbs_immuneKnockback = true;
  6796. else if (line.match(/knockback_bonus\s?:\s?(.+)/i))
  6797. obj.leTbs_knockbackBonus = Number(RegExp.$1);
  6798. else if (line.match(/knockback_reduction\s?:\s?(.+)/i))
  6799. obj.leTbs_knockbackReduction = Number(RegExp.$1);
  6800. else if (line.match(/knockback_bonus\s?:\s?(.+)/i))
  6801. obj.leTbs_knockbackBonus = Number(RegExp.$1);
  6802. else if (line.match(/knockback_reduction\s?:\s?(.+)/i))
  6803. obj.leTbs_knockbackReduction = Number(RegExp.$1);
  6804. else if (line.match(/back_dmg_bonus\s?:\s?(.+)/i))
  6805. obj.leTbs_directionalDmgBonus.back = Number(RegExp.$1);
  6806. else if (line.match(/back_dmg_reduction\s?:\s?(.+)/i))
  6807. obj.leTbs_directionalDmgReduction.back = Number(RegExp.$1);
  6808. else if (line.match(/face_dmg_bonus\s?:\s?(.+)/i))
  6809. obj.leTbs_directionalDmgBonus.face = Number(RegExp.$1);
  6810. else if (line.match(/face_dmg_reduction\s?:\s?(.+)/i))
  6811. obj.leTbs_directionalDmgReduction.face = Number(RegExp.$1);
  6812. else if (line.match(/side_dmg_bonus\s?:\s?(.+)/i))
  6813. obj.leTbs_directionalDmgBonus.side = Number(RegExp.$1);
  6814. else if (line.match(/side_dmg_reduction\s?:\s?(.+)/i))
  6815. obj.leTbs_directionalDmgReduction.side = Number(RegExp.$1);
  6816. }
  6817. }
  6818. }
  6819. }
  6820. };
  6821.  
  6822. DataManager.processLeTBSTagsForObjects = function () {
  6823. var groups = [$dataSkills, $dataItems, $dataWeapons];
  6824. for (var i = 0; i < groups.length; i++) {
  6825. var group = groups[i];
  6826. for (var j = 1; j < group.length; j++) {
  6827. var obj = group[j];
  6828. var notedata = obj.note.split(/[\r\n]+/);
  6829. var letbs = false;
  6830.  
  6831. obj.leTbs_scopeData = null;
  6832. obj.leTbs_aoeData = null;
  6833. obj.leTbs_sequenceData = null;
  6834. obj.leTbs_passOnUse = false;
  6835. obj.leTbs_maxUse = 1;
  6836. obj.leTbs_scopeParam = [];
  6837. obj.leTbs_aiOffenseType = null;
  6838. obj.leTbs_collisionFormula = null;
  6839. obj.leTbs_directionalDmgBonus = {
  6840. face: 0,
  6841. back: 0,
  6842. side: 0
  6843. };
  6844. obj.leTbs_directionalDmgReduction = {
  6845. face: 0,
  6846. back: 0,
  6847. side: 0
  6848. };
  6849.  
  6850. for (var k = 0; k < notedata.length; k++) {
  6851. var line = notedata[k];
  6852. if (line.match(/<letbs>/i))
  6853. letbs = true;
  6854. else if (line.match(/<\/letbs>/i))
  6855. letbs = false;
  6856.  
  6857. if (letbs) {
  6858. if (line.match(/scope\s?:\s?(.+)/i))
  6859. obj.leTbs_scopeData = String(RegExp.$1);
  6860. else if (line.match(/aoe\s?:\s?(.+)/i))
  6861. obj.leTbs_aoeData = String(RegExp.$1);
  6862. else if (line.match(/sequence\s?:\s?(.+)/i))
  6863. obj.leTbs_sequenceData = String(RegExp.$1);
  6864. else if (line.match(/pass_on_use/i))
  6865. obj.leTbs_passOnUse = true;
  6866. else if (line.match(/max_use:\s?:\s?(.+)/i))
  6867. obj.leTbs_maxUse = Number(RegExp.$1);
  6868. else if (line.match(/scope_options\s?:\s?((.|\n)*)/i))
  6869. obj.leTbs_scopeParam = String(RegExp.$1);
  6870. else if (line.match(/ai_offense_type/i))
  6871. obj.leTbs_aiOffenseType = true;
  6872. else if (line.match(/collision_formula\s?:\s?(.+)/i))
  6873. obj.leTbs_collisionFormula = String(RegExp.$1);
  6874. else if (line.match(/knockback_bonus\s?:\s?(.+)/i))
  6875. obj.leTbs_knockbackBonus = Number(RegExp.$1);
  6876. else if (line.match(/knockback_reduction\s?:\s?(.+)/i))
  6877. obj.leTbs_knockbackReduction = Number(RegExp.$1);
  6878. else if (line.match(/back_dmg_bonus\s?:\s?(.+)/i))
  6879. obj.leTbs_directionalDmgBonus.back = Number(RegExp.$1);
  6880. else if (line.match(/back_dmg_reduction\s?:\s?(.+)/i))
  6881. obj.leTbs_directionalDmgReduction.back = Number(RegExp.$1);
  6882. else if (line.match(/face_dmg_bonus\s?:\s?(.+)/i))
  6883. obj.leTbs_directionalDmgBonus.face = Number(RegExp.$1);
  6884. else if (line.match(/face_dmg_reduction\s?:\s?(.+)/i))
  6885. obj.leTbs_directionalDmgReduction.face = Number(RegExp.$1);
  6886. else if (line.match(/side_dmg_bonus\s?:\s?(.+)/i))
  6887. obj.leTbs_directionalDmgBonus.side = Number(RegExp.$1);
  6888. else if (line.match(/side_dmg_reduction\s?:\s?(.+)/i))
  6889. obj.leTbs_directionalDmgReduction.side = Number(RegExp.$1);
  6890. }
  6891. }
  6892. }
  6893. }
  6894. };
  6895.  
  6896. /*-------------------------------------------------------------------------
  6897. * ImageManager
  6898. -------------------------------------------------------------------------*/
  6899. ImageManager.loadLeTBS = function (filename, hue) {
  6900. return this.loadBitmap('img/leTBS/', filename, hue, true);
  6901. };
  6902.  
  6903. ImageManager.loadLeTBSTurnOrder = function (filename, hue) {
  6904. return this.loadBitmap('img/leTBS/TurnOrder/', filename, hue, true);
  6905. };
  6906.  
  6907. ImageManager.loadLeTBSBattler = function (filename, hue) {
  6908. return this.loadBitmap('img/leTBS/Battlers/', filename, hue, true);
  6909. };
  6910.  
  6911. ImageManager.loadLeTBSStatus = function (filename, hue) {
  6912. return this.loadBitmap('img/leTBS/Status/', filename, hue, true);
  6913. };
  6914.  
  6915. ImageManager.loadLeTBSProjectile = function (filename, hue) {
  6916. return this.loadBitmap('img/leTBS/Projectiles/', filename, hue, true);
  6917. };
  6918.  
  6919. ImageManager.loadLeTBS("Battle_Start");
  6920.  
  6921. /*-------------------------------------------------------------------------
  6922. * Game_Map
  6923. -------------------------------------------------------------------------*/
  6924. Lecode.S_TBS.oldIsPassable_method = Game_Map.prototype.isPassable;
  6925. Game_Map.prototype.isPassable = function (x, y, d) {
  6926. var result = Lecode.S_TBS.oldIsPassable_method.call(this, x, y, d);
  6927. if (LeUtilities.isScene("Scene_Battle") && BattleManagerTBS.activeEntity()) {
  6928. var entityCell = BattleManagerTBS.activeEntity().getCell();
  6929. var cell = BattleManagerTBS.getCellAt(x, y);
  6930. if (cell && !(entityCell.x == x && entityCell.y == y) && cell.isThereEntity())
  6931. return false;
  6932. }
  6933. return result;
  6934. };
  6935.  
  6936.  
  6937. /*-------------------------------------------------------------------------
  6938. * TBS_FloatingAction
  6939. -------------------------------------------------------------------------*/
  6940. function TBS_FloatingAction() {
  6941. this.initialize.apply(this, arguments);
  6942. }
  6943. TBS_FloatingAction.prototype = Object.create(Game_Action.prototype);
  6944. TBS_FloatingAction.prototype.constructor = TBS_FloatingAction;
  6945.  
  6946. TBS_FloatingAction.prototype.initialize = function () {
  6947. Game_Action.prototype.initialize.call(this, arguments);
  6948. };
  6949.  
  6950. TBS_FloatingAction.prototype.setSubject = function (subject) {
  6951. this._subject = subject;
  6952. };
  6953.  
  6954. TBS_FloatingAction.prototype.subject = function () {
  6955. return this._subject;
  6956. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement