Advertisement
Guest User

rpg_objects

a guest
Nov 9th, 2016
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // rpg_objects.js v1.3.3
  3. //=============================================================================
  4.  
  5. //-----------------------------------------------------------------------------
  6. // Game_Temp
  7. //
  8. // The game object class for temporary data that is not included in save data.
  9.  
  10. function Game_Temp() {
  11.     this.initialize.apply(this, arguments);
  12. }
  13.  
  14. Game_Temp.prototype.initialize = function() {
  15.     this._isPlaytest = Utils.isOptionValid('test');
  16.     this._commonEventId = 0;
  17.     this._destinationX = null;
  18.     this._destinationY = null;
  19. };
  20.  
  21. Game_Temp.prototype.isPlaytest = function() {
  22.     return this._isPlaytest;
  23. };
  24.  
  25. Game_Temp.prototype.reserveCommonEvent = function(commonEventId) {
  26.     this._commonEventId = commonEventId;
  27. };
  28.  
  29. Game_Temp.prototype.clearCommonEvent = function() {
  30.     this._commonEventId = 0;
  31. };
  32.  
  33. Game_Temp.prototype.isCommonEventReserved = function() {
  34.     return this._commonEventId > 0;
  35. };
  36.  
  37. Game_Temp.prototype.reservedCommonEvent = function() {
  38.     return $dataCommonEvents[this._commonEventId];
  39. };
  40.  
  41. Game_Temp.prototype.setDestination = function(x, y) {
  42.     this._destinationX = x;
  43.     this._destinationY = y;
  44. };
  45.  
  46. Game_Temp.prototype.clearDestination = function() {
  47.     this._destinationX = null;
  48.     this._destinationY = null;
  49. };
  50.  
  51. Game_Temp.prototype.isDestinationValid = function() {
  52.     return this._destinationX !== null;
  53. };
  54.  
  55. Game_Temp.prototype.destinationX = function() {
  56.     return this._destinationX;
  57. };
  58.  
  59. Game_Temp.prototype.destinationY = function() {
  60.     return this._destinationY;
  61. };
  62.  
  63. //-----------------------------------------------------------------------------
  64. // Game_System
  65. //
  66. // The game object class for the system data.
  67.  
  68. function Game_System() {
  69.     this.initialize.apply(this, arguments);
  70. }
  71.  
  72. Game_System.prototype.initialize = function() {
  73.     this._saveEnabled = true;
  74.     this._menuEnabled = true;
  75.     this._encounterEnabled = true;
  76.     this._formationEnabled = true;
  77.     this._battleCount = 0;
  78.     this._winCount = 0;
  79.     this._escapeCount = 0;
  80.     this._saveCount = 0;
  81.     this._versionId = 0;
  82.     this._framesOnSave = 0;
  83.     this._bgmOnSave = null;
  84.     this._bgsOnSave = null;
  85.     this._windowTone = null;
  86.     this._battleBgm = null;
  87.     this._victoryMe = null;
  88.     this._defeatMe = null;
  89.     this._savedBgm = null;
  90.     this._walkingBgm = null;
  91. };
  92.  
  93. Game_System.prototype.isJapanese = function() {
  94.     return $dataSystem.locale.match(/^ja/);
  95. };
  96.  
  97. Game_System.prototype.isChinese = function() {
  98.     return $dataSystem.locale.match(/^zh/);
  99. };
  100.  
  101. Game_System.prototype.isKorean = function() {
  102.     return $dataSystem.locale.match(/^ko/);
  103. };
  104.  
  105. Game_System.prototype.isCJK = function() {
  106.     return $dataSystem.locale.match(/^(ja|zh|ko)/);
  107. };
  108.  
  109. Game_System.prototype.isRussian = function() {
  110.     return $dataSystem.locale.match(/^ru/);
  111. };
  112.  
  113. Game_System.prototype.isSideView = function() {
  114.     return $dataSystem.optSideView;
  115. };
  116.  
  117. Game_System.prototype.isSaveEnabled = function() {
  118.     return this._saveEnabled;
  119. };
  120.  
  121. Game_System.prototype.disableSave = function() {
  122.     this._saveEnabled = false;
  123. };
  124.  
  125. Game_System.prototype.enableSave = function() {
  126.     this._saveEnabled = true;
  127. };
  128.  
  129. Game_System.prototype.isMenuEnabled = function() {
  130.     return this._menuEnabled;
  131. };
  132.  
  133. Game_System.prototype.disableMenu = function() {
  134.     this._menuEnabled = false;
  135. };
  136.  
  137. Game_System.prototype.enableMenu = function() {
  138.     this._menuEnabled = true;
  139. };
  140.  
  141. Game_System.prototype.isEncounterEnabled = function() {
  142.     return this._encounterEnabled;
  143. };
  144.  
  145. Game_System.prototype.disableEncounter = function() {
  146.     this._encounterEnabled = false;
  147. };
  148.  
  149. Game_System.prototype.enableEncounter = function() {
  150.     this._encounterEnabled = true;
  151. };
  152.  
  153. Game_System.prototype.isFormationEnabled = function() {
  154.     return this._formationEnabled;
  155. };
  156.  
  157. Game_System.prototype.disableFormation = function() {
  158.     this._formationEnabled = false;
  159. };
  160.  
  161. Game_System.prototype.enableFormation = function() {
  162.     this._formationEnabled = true;
  163. };
  164.  
  165. Game_System.prototype.battleCount = function() {
  166.     return this._battleCount;
  167. };
  168.  
  169. Game_System.prototype.winCount = function() {
  170.     return this._winCount;
  171. };
  172.  
  173. Game_System.prototype.escapeCount = function() {
  174.     return this._escapeCount;
  175. };
  176.  
  177. Game_System.prototype.saveCount = function() {
  178.     return this._saveCount;
  179. };
  180.  
  181. Game_System.prototype.versionId = function() {
  182.     return this._versionId;
  183. };
  184.  
  185. Game_System.prototype.windowTone = function() {
  186.     return this._windowTone || $dataSystem.windowTone;
  187. };
  188.  
  189. Game_System.prototype.setWindowTone = function(value) {
  190.     this._windowTone = value;
  191. };
  192.  
  193. Game_System.prototype.battleBgm = function() {
  194.     return this._battleBgm || $dataSystem.battleBgm;
  195. };
  196.  
  197. Game_System.prototype.setBattleBgm = function(value) {
  198.     this._battleBgm = value;
  199. };
  200.  
  201. Game_System.prototype.victoryMe = function() {
  202.     return this._victoryMe || $dataSystem.victoryMe;
  203. };
  204.  
  205. Game_System.prototype.setVictoryMe = function(value) {
  206.     this._victoryMe = value;
  207. };
  208.  
  209. Game_System.prototype.defeatMe = function() {
  210.     return this._defeatMe || $dataSystem.defeatMe;
  211. };
  212.  
  213. Game_System.prototype.setDefeatMe = function(value) {
  214.     this._defeatMe = value;
  215. };
  216.  
  217. Game_System.prototype.onBattleStart = function() {
  218.     this._battleCount++;
  219. };
  220.  
  221. Game_System.prototype.onBattleWin = function() {
  222.     this._winCount++;
  223. };
  224.  
  225. Game_System.prototype.onBattleEscape = function() {
  226.     this._escapeCount++;
  227. };
  228.  
  229. Game_System.prototype.onBeforeSave = function() {
  230.     this._saveCount++;
  231.     this._versionId = $dataSystem.versionId;
  232.     this._framesOnSave = Graphics.frameCount;
  233.     this._bgmOnSave = AudioManager.saveBgm();
  234.     this._bgsOnSave = AudioManager.saveBgs();
  235. };
  236.  
  237. Game_System.prototype.onAfterLoad = function() {
  238.     Graphics.frameCount = this._framesOnSave;
  239.     AudioManager.playBgm(this._bgmOnSave);
  240.     AudioManager.playBgs(this._bgsOnSave);
  241. };
  242.  
  243. Game_System.prototype.playtime = function() {
  244.     return Math.floor(Graphics.frameCount / 60);
  245. };
  246.  
  247. Game_System.prototype.playtimeText = function() {
  248.     var hour = Math.floor(this.playtime() / 60 / 60);
  249.     var min = Math.floor(this.playtime() / 60) % 60;
  250.     var sec = this.playtime() % 60;
  251.     return hour.padZero(2) + ':' + min.padZero(2) + ':' + sec.padZero(2);
  252. };
  253.  
  254. Game_System.prototype.saveBgm = function() {
  255.     this._savedBgm = AudioManager.saveBgm();
  256. };
  257.  
  258. Game_System.prototype.replayBgm = function() {
  259.     if (this._savedBgm) {
  260.         AudioManager.replayBgm(this._savedBgm);
  261.     }
  262. };
  263.  
  264. Game_System.prototype.saveWalkingBgm = function() {
  265.     this._walkingBgm = AudioManager.saveBgm();
  266. };
  267.  
  268. Game_System.prototype.replayWalkingBgm = function() {
  269.     if (this._walkingBgm) {
  270.         AudioManager.playBgm(this._walkingBgm);
  271.     }
  272. };
  273.  
  274. //-----------------------------------------------------------------------------
  275. // Game_Timer
  276. //
  277. // The game object class for the timer.
  278.  
  279. function Game_Timer() {
  280.     this.initialize.apply(this, arguments);
  281. }
  282.  
  283. Game_Timer.prototype.initialize = function() {
  284.     this._frames = 0;
  285.     this._working = false;
  286. };
  287.  
  288. Game_Timer.prototype.update = function(sceneActive) {
  289.     if (sceneActive && this._working && this._frames > 0) {
  290.         this._frames--;
  291.         if (this._frames === 0) {
  292.             this.onExpire();
  293.         }
  294.     }
  295. };
  296.  
  297. Game_Timer.prototype.start = function(count) {
  298.     this._frames = count;
  299.     this._working = true;
  300. };
  301.  
  302. Game_Timer.prototype.stop = function() {
  303.     this._working = false;
  304. };
  305.  
  306. Game_Timer.prototype.isWorking = function() {
  307.     return this._working;
  308. };
  309.  
  310. Game_Timer.prototype.seconds = function() {
  311.     return Math.floor(this._frames / 60);
  312. };
  313.  
  314. Game_Timer.prototype.onExpire = function() {
  315.     BattleManager.abort();
  316. };
  317.  
  318. //-----------------------------------------------------------------------------
  319. // Game_Message
  320. //
  321. // The game object class for the state of the message window that displays text
  322. // or selections, etc.
  323.  
  324. function Game_Message() {
  325.     this.initialize.apply(this, arguments);
  326. }
  327.  
  328. Game_Message.prototype.initialize = function() {
  329.     this.clear();
  330. };
  331.  
  332. Game_Message.prototype.clear = function() {
  333.     this._texts = [];
  334.     this._choices = [];
  335.     this._faceName = '';
  336.     this._faceIndex = 0;
  337.     this._background = 0;
  338.     this._positionType = 2;
  339.     this._choiceDefaultType = 0;
  340.     this._choiceCancelType = 0;
  341.     this._choiceBackground = 0;
  342.     this._choicePositionType = 2;
  343.     this._numInputVariableId = 0;
  344.     this._numInputMaxDigits = 0;
  345.     this._itemChoiceVariableId = 0;
  346.     this._itemChoiceItypeId = 0;
  347.     this._scrollMode = false;
  348.     this._scrollSpeed = 2;
  349.     this._scrollNoFast = false;
  350.     this._choiceCallback = null;
  351. };
  352.  
  353. Game_Message.prototype.choices = function() {
  354.     return this._choices;
  355. };
  356.  
  357. Game_Message.prototype.faceName = function() {
  358.     return this._faceName;
  359. };
  360.  
  361. Game_Message.prototype.faceIndex = function() {
  362.     return this._faceIndex;
  363. };
  364.  
  365. Game_Message.prototype.background = function() {
  366.     return this._background;
  367. };
  368.  
  369. Game_Message.prototype.positionType = function() {
  370.     return this._positionType;
  371. };
  372.  
  373. Game_Message.prototype.choiceDefaultType = function() {
  374.     return this._choiceDefaultType;
  375. };
  376.  
  377. Game_Message.prototype.choiceCancelType = function() {
  378.     return this._choiceCancelType;
  379. };
  380.  
  381. Game_Message.prototype.choiceBackground = function() {
  382.     return this._choiceBackground;
  383. };
  384.  
  385. Game_Message.prototype.choicePositionType = function() {
  386.     return this._choicePositionType;
  387. };
  388.  
  389. Game_Message.prototype.numInputVariableId = function() {
  390.     return this._numInputVariableId;
  391. };
  392.  
  393. Game_Message.prototype.numInputMaxDigits = function() {
  394.     return this._numInputMaxDigits;
  395. };
  396.  
  397. Game_Message.prototype.itemChoiceVariableId = function() {
  398.     return this._itemChoiceVariableId;
  399. };
  400.  
  401. Game_Message.prototype.itemChoiceItypeId = function() {
  402.     return this._itemChoiceItypeId;
  403. };
  404.  
  405. Game_Message.prototype.scrollMode = function() {
  406.     return this._scrollMode;
  407. };
  408.  
  409. Game_Message.prototype.scrollSpeed = function() {
  410.     return this._scrollSpeed;
  411. };
  412.  
  413. Game_Message.prototype.scrollNoFast = function() {
  414.     return this._scrollNoFast;
  415. };
  416.  
  417. Game_Message.prototype.add = function(text) {
  418.     this._texts.push(text);
  419. };
  420.  
  421. Game_Message.prototype.setFaceImage = function(faceName, faceIndex) {
  422.     this._faceName = faceName;
  423.     this._faceIndex = faceIndex;
  424. };
  425.  
  426. Game_Message.prototype.setBackground = function(background) {
  427.     this._background = background;
  428. };
  429.  
  430. Game_Message.prototype.setPositionType = function(positionType) {
  431.     this._positionType = positionType;
  432. };
  433.  
  434. Game_Message.prototype.setChoices = function(choices, defaultType, cancelType) {
  435.     this._choices = choices;
  436.     this._choiceDefaultType = defaultType;
  437.     this._choiceCancelType = cancelType;
  438. };
  439.  
  440. Game_Message.prototype.setChoiceBackground = function(background) {
  441.     this._choiceBackground = background;
  442. };
  443.  
  444. Game_Message.prototype.setChoicePositionType = function(positionType) {
  445.     this._choicePositionType = positionType;
  446. };
  447.  
  448. Game_Message.prototype.setNumberInput = function(variableId, maxDigits) {
  449.     this._numInputVariableId = variableId;
  450.     this._numInputMaxDigits = maxDigits;
  451. };
  452.  
  453. Game_Message.prototype.setItemChoice = function(variableId, itemType) {
  454.     this._itemChoiceVariableId = variableId;
  455.     this._itemChoiceItypeId = itemType;
  456. };
  457.  
  458. Game_Message.prototype.setScroll = function(speed, noFast) {
  459.     this._scrollMode = true;
  460.     this._scrollSpeed = speed;
  461.     this._scrollNoFast = noFast;
  462. };
  463.  
  464. Game_Message.prototype.setChoiceCallback = function(callback) {
  465.     this._choiceCallback = callback;
  466. };
  467.  
  468. Game_Message.prototype.onChoice = function(n) {
  469.     if (this._choiceCallback) {
  470.         this._choiceCallback(n);
  471.         this._choiceCallback = null;
  472.     }
  473. };
  474.  
  475. Game_Message.prototype.hasText = function() {
  476.     return this._texts.length > 0;
  477. };
  478.  
  479. Game_Message.prototype.isChoice = function() {
  480.     return this._choices.length > 0;
  481. };
  482.  
  483. Game_Message.prototype.isNumberInput = function() {
  484.     return this._numInputVariableId > 0;
  485. };
  486.  
  487. Game_Message.prototype.isItemChoice = function() {
  488.     return this._itemChoiceVariableId > 0;
  489. };
  490.  
  491. Game_Message.prototype.isBusy = function() {
  492.     return (this.hasText() || this.isChoice() ||
  493.             this.isNumberInput() || this.isItemChoice());
  494. };
  495.  
  496. Game_Message.prototype.newPage = function() {
  497.     if (this._texts.length > 0) {
  498.         this._texts[this._texts.length - 1] += '\f';
  499.     }
  500. };
  501.  
  502. Game_Message.prototype.allText = function() {
  503.     return this._texts.reduce(function(previousValue, currentValue) {
  504.         return previousValue + '\n' + currentValue;
  505.     });
  506. };
  507.  
  508. //-----------------------------------------------------------------------------
  509. // Game_Switches
  510. //
  511. // The game object class for switches.
  512.  
  513. function Game_Switches() {
  514.     this.initialize.apply(this, arguments);
  515. }
  516.  
  517. Game_Switches.prototype.initialize = function() {
  518.     this.clear();
  519. };
  520.  
  521. Game_Switches.prototype.clear = function() {
  522.     this._data = [];
  523. };
  524.  
  525. Game_Switches.prototype.value = function(switchId) {
  526.     return !!this._data[switchId];
  527. };
  528.  
  529. Game_Switches.prototype.setValue = function(switchId, value) {
  530.     if (switchId > 0 && switchId < $dataSystem.switches.length) {
  531.         this._data[switchId] = value;
  532.         this.onChange();
  533.     }
  534. };
  535.  
  536. Game_Switches.prototype.onChange = function() {
  537.     $gameMap.requestRefresh();
  538. };
  539.  
  540. //-----------------------------------------------------------------------------
  541. // Game_Variables
  542. //
  543. // The game object class for variables.
  544.  
  545. function Game_Variables() {
  546.     this.initialize.apply(this, arguments);
  547. }
  548.  
  549. Game_Variables.prototype.initialize = function() {
  550.     this.clear();
  551. };
  552.  
  553. Game_Variables.prototype.clear = function() {
  554.     this._data = [];
  555. };
  556.  
  557. Game_Variables.prototype.value = function(variableId) {
  558.     return this._data[variableId] || 0;
  559. };
  560.  
  561. Game_Variables.prototype.setValue = function(variableId, value) {
  562.     if (variableId > 0 && variableId < $dataSystem.variables.length) {
  563.         if (typeof value === 'number') {
  564.             value = Math.floor(value);
  565.         }
  566.         this._data[variableId] = value;
  567.         this.onChange();
  568.     }
  569. };
  570.  
  571. Game_Variables.prototype.onChange = function() {
  572.     $gameMap.requestRefresh();
  573. };
  574.  
  575. //-----------------------------------------------------------------------------
  576. // Game_SelfSwitches
  577. //
  578. // The game object class for self switches.
  579.  
  580. function Game_SelfSwitches() {
  581.     this.initialize.apply(this, arguments);
  582. }
  583.  
  584. Game_SelfSwitches.prototype.initialize = function() {
  585.     this.clear();
  586. };
  587.  
  588. Game_SelfSwitches.prototype.clear = function() {
  589.     this._data = {};
  590. };
  591.  
  592. Game_SelfSwitches.prototype.value = function(key) {
  593.     return !!this._data[key];
  594. };
  595.  
  596. Game_SelfSwitches.prototype.setValue = function(key, value) {
  597.     if (value) {
  598.         this._data[key] = true;
  599.     } else {
  600.         delete this._data[key];
  601.     }
  602.     this.onChange();
  603. };
  604.  
  605. Game_SelfSwitches.prototype.onChange = function() {
  606.     $gameMap.requestRefresh();
  607. };
  608.  
  609. //-----------------------------------------------------------------------------
  610. // Game_Screen
  611. //
  612. // The game object class for screen effect data, such as changes in color tone
  613. // and flashes.
  614.  
  615. function Game_Screen() {
  616.     this.initialize.apply(this, arguments);
  617. }
  618.  
  619. Game_Screen.prototype.initialize = function() {
  620.     this.clear();
  621. };
  622.  
  623. Game_Screen.prototype.clear = function() {
  624.     this.clearFade();
  625.     this.clearTone();
  626.     this.clearFlash();
  627.     this.clearShake();
  628.     this.clearZoom();
  629.     this.clearWeather();
  630.     this.clearPictures();
  631. };
  632.  
  633. Game_Screen.prototype.onBattleStart = function() {
  634.     this.clearFade();
  635.     this.clearFlash();
  636.     this.clearShake();
  637.     this.clearZoom();
  638.     this.eraseBattlePictures();
  639. };
  640.  
  641. Game_Screen.prototype.brightness = function() {
  642.     return this._brightness;
  643. };
  644.  
  645. Game_Screen.prototype.tone = function() {
  646.     return this._tone;
  647. };
  648.  
  649. Game_Screen.prototype.flashColor = function() {
  650.     return this._flashColor;
  651. };
  652.  
  653. Game_Screen.prototype.shake = function() {
  654.     return this._shake;
  655. };
  656.  
  657. Game_Screen.prototype.zoomX = function() {
  658.     return this._zoomX;
  659. };
  660.  
  661. Game_Screen.prototype.zoomY = function() {
  662.     return this._zoomY;
  663. };
  664.  
  665. Game_Screen.prototype.zoomScale = function() {
  666.     return this._zoomScale;
  667. };
  668.  
  669. Game_Screen.prototype.weatherType = function() {
  670.     return this._weatherType;
  671. };
  672.  
  673. Game_Screen.prototype.weatherPower = function() {
  674.     return this._weatherPower;
  675. };
  676.  
  677. Game_Screen.prototype.picture = function(pictureId) {
  678.     var realPictureId = this.realPictureId(pictureId);
  679.     return this._pictures[realPictureId];
  680. };
  681.  
  682. Game_Screen.prototype.realPictureId = function(pictureId) {
  683.     if ($gameParty.inBattle()) {
  684.         return pictureId + this.maxPictures();
  685.     } else {
  686.         return pictureId;
  687.     }
  688. };
  689.  
  690. Game_Screen.prototype.clearFade = function() {
  691.     this._brightness = 255;
  692.     this._fadeOutDuration = 0;
  693.     this._fadeInDuration = 0;
  694. };
  695.  
  696. Game_Screen.prototype.clearTone = function() {
  697.     this._tone = [0, 0, 0, 0];
  698.     this._toneTarget = [0, 0, 0, 0];
  699.     this._toneDuration = 0;
  700. };
  701.  
  702. Game_Screen.prototype.clearFlash = function() {
  703.     this._flashColor = [0, 0, 0, 0];
  704.     this._flashDuration = 0;
  705. };
  706.  
  707. Game_Screen.prototype.clearShake = function() {
  708.     this._shakePower = 0;
  709.     this._shakeSpeed = 0;
  710.     this._shakeDuration = 0;
  711.     this._shakeDirection = 1;
  712.     this._shake = 0;
  713. };
  714.  
  715. Game_Screen.prototype.clearZoom = function() {
  716.     this._zoomX = 0;
  717.     this._zoomY = 0;
  718.     this._zoomScale = 1;
  719.     this._zoomScaleTarget = 1;
  720.     this._zoomDuration = 0;
  721. };
  722.  
  723. Game_Screen.prototype.clearWeather = function() {
  724.     this._weatherType = 'none';
  725.     this._weatherPower = 0;
  726.     this._weatherPowerTarget = 0;
  727.     this._weatherDuration = 0;
  728. };
  729.  
  730. Game_Screen.prototype.clearPictures = function() {
  731.     this._pictures = [];
  732. };
  733.  
  734. Game_Screen.prototype.eraseBattlePictures = function() {
  735.     this._pictures = this._pictures.slice(0, this.maxPictures() + 1);
  736. };
  737.  
  738. Game_Screen.prototype.maxPictures = function() {
  739.     return 100;
  740. };
  741.  
  742. Game_Screen.prototype.startFadeOut = function(duration) {
  743.     this._fadeOutDuration = duration;
  744.     this._fadeInDuration = 0;
  745. };
  746.  
  747. Game_Screen.prototype.startFadeIn = function(duration) {
  748.     this._fadeInDuration = duration;
  749.     this._fadeOutDuration = 0;
  750. };
  751.  
  752. Game_Screen.prototype.startTint = function(tone, duration) {
  753.     this._toneTarget = tone.clone();
  754.     this._toneDuration = duration;
  755.     if (this._toneDuration === 0) {
  756.         this._tone = this._toneTarget.clone();
  757.     }
  758. };
  759.  
  760. Game_Screen.prototype.startFlash = function(color, duration) {
  761.     this._flashColor = color.clone();
  762.     this._flashDuration = duration;
  763. };
  764.  
  765. Game_Screen.prototype.startShake = function(power, speed, duration) {
  766.     this._shakePower = power;
  767.     this._shakeSpeed = speed;
  768.     this._shakeDuration = duration;
  769. };
  770.  
  771. Game_Screen.prototype.startZoom = function(x, y, scale, duration) {
  772.     this._zoomX = x;
  773.     this._zoomY = y;
  774.     this._zoomScaleTarget = scale;
  775.     this._zoomDuration = duration;
  776. };
  777.  
  778. Game_Screen.prototype.setZoom = function(x, y, scale) {
  779.     this._zoomX = x;
  780.     this._zoomY = y;
  781.     this._zoomScale = scale;
  782. };
  783.  
  784. Game_Screen.prototype.changeWeather = function(type, power, duration) {
  785.     if (type !== 'none' || duration === 0) {
  786.         this._weatherType = type;
  787.     }
  788.     this._weatherPowerTarget = type === 'none' ? 0 : power;
  789.     this._weatherDuration = duration;
  790.     if (duration === 0) {
  791.         this._weatherPower = this._weatherPowerTarget;
  792.     }
  793. };
  794.  
  795. Game_Screen.prototype.update = function() {
  796.     this.updateFadeOut();
  797.     this.updateFadeIn();
  798.     this.updateTone();
  799.     this.updateFlash();
  800.     this.updateShake();
  801.     this.updateZoom();
  802.     this.updateWeather();
  803.     this.updatePictures();
  804. };
  805.  
  806. Game_Screen.prototype.updateFadeOut = function() {
  807.     if (this._fadeOutDuration > 0) {
  808.         var d = this._fadeOutDuration;
  809.         this._brightness = (this._brightness * (d - 1)) / d;
  810.         this._fadeOutDuration--;
  811.     }
  812. };
  813.  
  814. Game_Screen.prototype.updateFadeIn = function() {
  815.     if (this._fadeInDuration > 0) {
  816.         var d = this._fadeInDuration;
  817.         this._brightness = (this._brightness * (d - 1) + 255) / d;
  818.         this._fadeInDuration--;
  819.     }
  820. };
  821.  
  822. Game_Screen.prototype.updateTone = function() {
  823.     if (this._toneDuration > 0) {
  824.         var d = this._toneDuration;
  825.         for (var i = 0; i < 4; i++) {
  826.             this._tone[i] = (this._tone[i] * (d - 1) + this._toneTarget[i]) / d;
  827.         }
  828.         this._toneDuration--;
  829.     }
  830. };
  831.  
  832. Game_Screen.prototype.updateFlash = function() {
  833.     if (this._flashDuration > 0) {
  834.         var d = this._flashDuration;
  835.         this._flashColor[3] *= (d - 1) / d;
  836.         this._flashDuration--;
  837.     }
  838. };
  839.  
  840. Game_Screen.prototype.updateShake = function() {
  841.     if (this._shakeDuration > 0 || this._shake !== 0) {
  842.         var delta = (this._shakePower * this._shakeSpeed * this._shakeDirection) / 10;
  843.         if (this._shakeDuration <= 1 && this._shake * (this._shake + delta) < 0) {
  844.             this._shake = 0;
  845.         } else {
  846.             this._shake += delta;
  847.         }
  848.         if (this._shake > this._shakePower * 2) {
  849.             this._shakeDirection = -1;
  850.         }
  851.         if (this._shake < - this._shakePower * 2) {
  852.             this._shakeDirection = 1;
  853.         }
  854.         this._shakeDuration--;
  855.     }
  856. };
  857.  
  858. Game_Screen.prototype.updateZoom = function() {
  859.     if (this._zoomDuration > 0) {
  860.         var d = this._zoomDuration;
  861.         var t = this._zoomScaleTarget;
  862.         this._zoomScale = (this._zoomScale * (d - 1) + t) / d;
  863.         this._zoomDuration--;
  864.     }
  865. };
  866.  
  867. Game_Screen.prototype.updateWeather = function() {
  868.     if (this._weatherDuration > 0) {
  869.         var d = this._weatherDuration;
  870.         var t = this._weatherPowerTarget;
  871.         this._weatherPower = (this._weatherPower * (d - 1) + t) / d;
  872.         this._weatherDuration--;
  873.         if (this._weatherDuration === 0 && this._weatherPowerTarget === 0) {
  874.             this._weatherType = 'none';
  875.         }
  876.     }
  877. };
  878.  
  879. Game_Screen.prototype.updatePictures = function() {
  880.     this._pictures.forEach(function(picture) {
  881.         if (picture) {
  882.             picture.update();
  883.         }
  884.     });
  885. };
  886.  
  887. Game_Screen.prototype.startFlashForDamage = function() {
  888.     this.startFlash([255, 0, 0, 128], 8);
  889. };
  890.  
  891. Game_Screen.prototype.showPicture = function(pictureId, name, origin, x, y,
  892.                                              scaleX, scaleY, opacity, blendMode) {
  893.     var realPictureId = this.realPictureId(pictureId);
  894.     var picture = new Game_Picture();
  895.     picture.show(name, origin, x, y, scaleX, scaleY, opacity, blendMode);
  896.     this._pictures[realPictureId] = picture;
  897. };
  898.  
  899. Game_Screen.prototype.movePicture = function(pictureId, origin, x, y, scaleX,
  900.                                              scaleY, opacity, blendMode, duration) {
  901.     var picture = this.picture(pictureId);
  902.     if (picture) {
  903.         picture.move(origin, x, y, scaleX, scaleY, opacity, blendMode, duration);
  904.     }
  905. };
  906.  
  907. Game_Screen.prototype.rotatePicture = function(pictureId, speed) {
  908.     var picture = this.picture(pictureId);
  909.     if (picture) {
  910.         picture.rotate(speed);
  911.     }
  912. };
  913.  
  914. Game_Screen.prototype.tintPicture = function(pictureId, tone, duration) {
  915.     var picture = this.picture(pictureId);
  916.     if (picture) {
  917.         picture.tint(tone, duration);
  918.     }
  919. };
  920.  
  921. Game_Screen.prototype.erasePicture = function(pictureId) {
  922.     var realPictureId = this.realPictureId(pictureId);
  923.     this._pictures[realPictureId] = null;
  924. };
  925.  
  926. //-----------------------------------------------------------------------------
  927. // Game_Picture
  928. //
  929. // The game object class for a picture.
  930.  
  931. function Game_Picture() {
  932.     this.initialize.apply(this, arguments);
  933. }
  934.  
  935. Game_Picture.prototype.initialize = function() {
  936.     this.initBasic();
  937.     this.initTarget();
  938.     this.initTone();
  939.     this.initRotation();
  940. };
  941.  
  942. Game_Picture.prototype.name = function() {
  943.     return this._name;
  944. };
  945.  
  946. Game_Picture.prototype.origin = function() {
  947.     return this._origin;
  948. };
  949.  
  950. Game_Picture.prototype.x = function() {
  951.     return this._x;
  952. };
  953.  
  954. Game_Picture.prototype.y = function() {
  955.     return this._y;
  956. };
  957.  
  958. Game_Picture.prototype.scaleX = function() {
  959.     return this._scaleX;
  960. };
  961.  
  962. Game_Picture.prototype.scaleY = function() {
  963.     return this._scaleY;
  964. };
  965.  
  966. Game_Picture.prototype.opacity = function() {
  967.     return this._opacity;
  968. };
  969.  
  970. Game_Picture.prototype.blendMode = function() {
  971.     return this._blendMode;
  972. };
  973.  
  974. Game_Picture.prototype.tone = function() {
  975.     return this._tone;
  976. };
  977.  
  978. Game_Picture.prototype.angle = function() {
  979.     return this._angle;
  980. };
  981.  
  982. Game_Picture.prototype.initBasic = function() {
  983.     this._name = '';
  984.     this._origin = 0;
  985.     this._x = 0;
  986.     this._y = 0;
  987.     this._scaleX = 100;
  988.     this._scaleY = 100;
  989.     this._opacity = 255;
  990.     this._blendMode = 0;
  991. };
  992.  
  993. Game_Picture.prototype.initTarget = function() {
  994.     this._targetX = this._x;
  995.     this._targetY = this._y;
  996.     this._targetScaleX = this._scaleX;
  997.     this._targetScaleY = this._scaleY;
  998.     this._targetOpacity = this._opacity;
  999.     this._duration = 0;
  1000. };
  1001.  
  1002. Game_Picture.prototype.initTone = function() {
  1003.     this._tone = null;
  1004.     this._toneTarget = null;
  1005.     this._toneDuration = 0;
  1006. };
  1007.  
  1008. Game_Picture.prototype.initRotation = function() {
  1009.     this._angle = 0;
  1010.     this._rotationSpeed = 0;
  1011. };
  1012.  
  1013. Game_Picture.prototype.show = function(name, origin, x, y, scaleX,
  1014.                                        scaleY, opacity, blendMode) {
  1015.     this._name = name;
  1016.     this._origin = origin;
  1017.     this._x = x;
  1018.     this._y = y;
  1019.     this._scaleX = scaleX;
  1020.     this._scaleY = scaleY;
  1021.     this._opacity = opacity;
  1022.     this._blendMode = blendMode;
  1023.     this.initTarget();
  1024.     this.initTone();
  1025.     this.initRotation();
  1026. };
  1027.  
  1028. Game_Picture.prototype.move = function(origin, x, y, scaleX, scaleY,
  1029.                                        opacity, blendMode, duration) {
  1030.     this._origin = origin;
  1031.     this._targetX = x;
  1032.     this._targetY = y;
  1033.     this._targetScaleX = scaleX;
  1034.     this._targetScaleY = scaleY;
  1035.     this._targetOpacity = opacity;
  1036.     this._blendMode = blendMode;
  1037.     this._duration = duration;
  1038. };
  1039.  
  1040. Game_Picture.prototype.rotate = function(speed) {
  1041.     this._rotationSpeed = speed;
  1042. };
  1043.  
  1044. Game_Picture.prototype.tint = function(tone, duration) {
  1045.     if (!this._tone) {
  1046.         this._tone = [0, 0, 0, 0];
  1047.     }
  1048.     this._toneTarget = tone.clone();
  1049.     this._toneDuration = duration;
  1050.     if (this._toneDuration === 0) {
  1051.         this._tone = this._toneTarget.clone();
  1052.     }
  1053. };
  1054.  
  1055. Game_Picture.prototype.erase = function() {
  1056.     this._name = '';
  1057.     this._origin = 0;
  1058.     this.initTarget();
  1059.     this.initTone();
  1060.     this.initRotation();
  1061. };
  1062.  
  1063. Game_Picture.prototype.update = function() {
  1064.     this.updateMove();
  1065.     this.updateTone();
  1066.     this.updateRotation();
  1067. };
  1068.  
  1069. Game_Picture.prototype.updateMove = function() {
  1070.     if (this._duration > 0) {
  1071.         var d = this._duration;
  1072.         this._x = (this._x * (d - 1) + this._targetX) / d;
  1073.         this._y = (this._y * (d - 1) + this._targetY) / d;
  1074.         this._scaleX  = (this._scaleX  * (d - 1) + this._targetScaleX)  / d;
  1075.         this._scaleY  = (this._scaleY  * (d - 1) + this._targetScaleY)  / d;
  1076.         this._opacity = (this._opacity * (d - 1) + this._targetOpacity) / d;
  1077.         this._duration--;
  1078.     }
  1079. };
  1080.  
  1081. Game_Picture.prototype.updateTone = function() {
  1082.     if (this._toneDuration > 0) {
  1083.         var d = this._toneDuration;
  1084.         for (var i = 0; i < 4; i++) {
  1085.             this._tone[i] = (this._tone[i] * (d - 1) + this._toneTarget[i]) / d;
  1086.         }
  1087.         this._toneDuration--;
  1088.     }
  1089. };
  1090.  
  1091. Game_Picture.prototype.updateRotation = function() {
  1092.     if (this._rotationSpeed !== 0) {
  1093.         this._angle += this._rotationSpeed / 2;
  1094.     }
  1095. };
  1096.  
  1097. //-----------------------------------------------------------------------------
  1098. // Game_Item
  1099. //
  1100. // The game object class for handling skills, items, weapons, and armor. It is
  1101. // required because save data should not include the database object itself.
  1102.  
  1103. function Game_Item() {
  1104.     this.initialize.apply(this, arguments);
  1105. }
  1106.  
  1107. Game_Item.prototype.initialize = function(item) {
  1108.     this._dataClass = '';
  1109.     this._itemId = 0;
  1110.     if (item) {
  1111.         this.setObject(item);
  1112.     }
  1113. };
  1114.  
  1115. Game_Item.prototype.isSkill = function() {
  1116.     return this._dataClass === 'skill';
  1117. };
  1118.  
  1119. Game_Item.prototype.isItem = function() {
  1120.     return this._dataClass === 'item';
  1121. };
  1122.  
  1123. Game_Item.prototype.isUsableItem = function() {
  1124.     return this.isSkill() || this.isItem();
  1125. };
  1126.  
  1127. Game_Item.prototype.isWeapon = function() {
  1128.     return this._dataClass === 'weapon';
  1129. };
  1130.  
  1131. Game_Item.prototype.isArmor = function() {
  1132.     return this._dataClass === 'armor';
  1133. };
  1134.  
  1135. Game_Item.prototype.isEquipItem = function() {
  1136.     return this.isWeapon() || this.isArmor();
  1137. };
  1138.  
  1139. Game_Item.prototype.isNull = function() {
  1140.     return this._dataClass === '';
  1141. };
  1142.  
  1143. Game_Item.prototype.itemId = function() {
  1144.     return this._itemId;
  1145. };
  1146.  
  1147. Game_Item.prototype.object = function() {
  1148.     if (this.isSkill()) {
  1149.         return $dataSkills[this._itemId];
  1150.     } else if (this.isItem()) {
  1151.         return $dataItems[this._itemId];
  1152.     } else if (this.isWeapon()) {
  1153.         return $dataWeapons[this._itemId];
  1154.     } else if (this.isArmor()) {
  1155.         return $dataArmors[this._itemId];
  1156.     } else {
  1157.         return null;
  1158.     }
  1159. };
  1160.  
  1161. Game_Item.prototype.setObject = function(item) {
  1162.     if (DataManager.isSkill(item)) {
  1163.         this._dataClass = 'skill';
  1164.     } else if (DataManager.isItem(item)) {
  1165.         this._dataClass = 'item';
  1166.     } else if (DataManager.isWeapon(item)) {
  1167.         this._dataClass = 'weapon';
  1168.     } else if (DataManager.isArmor(item)) {
  1169.         this._dataClass = 'armor';
  1170.     } else {
  1171.         this._dataClass = '';
  1172.     }
  1173.     this._itemId = item ? item.id : 0;
  1174. };
  1175.  
  1176. Game_Item.prototype.setEquip = function(isWeapon, itemId) {
  1177.     this._dataClass = isWeapon ? 'weapon' : 'armor';
  1178.     this._itemId = itemId;
  1179. };
  1180.  
  1181. //-----------------------------------------------------------------------------
  1182. // Game_Action
  1183. //
  1184. // The game object class for a battle action.
  1185.  
  1186. function Game_Action() {
  1187.     this.initialize.apply(this, arguments);
  1188. }
  1189.  
  1190. Game_Action.EFFECT_RECOVER_HP       = 11;
  1191. Game_Action.EFFECT_RECOVER_MP       = 12;
  1192. Game_Action.EFFECT_GAIN_TP          = 13;
  1193. Game_Action.EFFECT_ADD_STATE        = 21;
  1194. Game_Action.EFFECT_REMOVE_STATE     = 22;
  1195. Game_Action.EFFECT_ADD_BUFF         = 31;
  1196. Game_Action.EFFECT_ADD_DEBUFF       = 32;
  1197. Game_Action.EFFECT_REMOVE_BUFF      = 33;
  1198. Game_Action.EFFECT_REMOVE_DEBUFF    = 34;
  1199. Game_Action.EFFECT_SPECIAL          = 41;
  1200. Game_Action.EFFECT_GROW             = 42;
  1201. Game_Action.EFFECT_LEARN_SKILL      = 43;
  1202. Game_Action.EFFECT_COMMON_EVENT     = 44;
  1203. Game_Action.SPECIAL_EFFECT_ESCAPE   = 0;
  1204. Game_Action.HITTYPE_CERTAIN         = 0;
  1205. Game_Action.HITTYPE_PHYSICAL        = 1;
  1206. Game_Action.HITTYPE_MAGICAL         = 2;
  1207.  
  1208. Game_Action.prototype.initialize = function(subject, forcing) {
  1209.     this._subjectActorId = 0;
  1210.     this._subjectEnemyIndex = -1;
  1211.     this._forcing = forcing || false;
  1212.     this.setSubject(subject);
  1213.     this.clear();
  1214. };
  1215.  
  1216. Game_Action.prototype.clear = function() {
  1217.     this._item = new Game_Item();
  1218.     this._targetIndex = -1;
  1219. };
  1220.  
  1221. Game_Action.prototype.setSubject = function(subject) {
  1222.     if (subject.isActor()) {
  1223.         this._subjectActorId = subject.actorId();
  1224.         this._subjectEnemyIndex = -1;
  1225.     } else {
  1226.         this._subjectEnemyIndex = subject.index();
  1227.         this._subjectActorId = 0;
  1228.     }
  1229. };
  1230.  
  1231. Game_Action.prototype.subject = function() {
  1232.     if (this._subjectActorId > 0) {
  1233.         return $gameActors.actor(this._subjectActorId);
  1234.     } else {
  1235.         return $gameTroop.members()[this._subjectEnemyIndex];
  1236.     }
  1237. };
  1238.  
  1239. Game_Action.prototype.friendsUnit = function() {
  1240.     return this.subject().friendsUnit();
  1241. };
  1242.  
  1243. Game_Action.prototype.opponentsUnit = function() {
  1244.     return this.subject().opponentsUnit();
  1245. };
  1246.  
  1247. Game_Action.prototype.setEnemyAction = function(action) {
  1248.     if (action) {
  1249.         this.setSkill(action.skillId);
  1250.     } else {
  1251.         this.clear();
  1252.     }
  1253. };
  1254.  
  1255. Game_Action.prototype.setAttack = function() {
  1256.     this.setSkill(this.subject().attackSkillId());
  1257. };
  1258.  
  1259. Game_Action.prototype.setGuard = function() {
  1260.     this.setSkill(this.subject().guardSkillId());
  1261. };
  1262.  
  1263. Game_Action.prototype.setSkill = function(skillId) {
  1264.     this._item.setObject($dataSkills[skillId]);
  1265. };
  1266.  
  1267. Game_Action.prototype.setItem = function(itemId) {
  1268.     this._item.setObject($dataItems[itemId]);
  1269. };
  1270.  
  1271. Game_Action.prototype.setItemObject = function(object) {
  1272.     this._item.setObject(object);
  1273. };
  1274.  
  1275. Game_Action.prototype.setTarget = function(targetIndex) {
  1276.     this._targetIndex = targetIndex;
  1277. };
  1278.  
  1279. Game_Action.prototype.item = function() {
  1280.     return this._item.object();
  1281. };
  1282.  
  1283. Game_Action.prototype.isSkill = function() {
  1284.     return this._item.isSkill();
  1285. };
  1286.  
  1287. Game_Action.prototype.isItem = function() {
  1288.     return this._item.isItem();
  1289. };
  1290.  
  1291. Game_Action.prototype.numRepeats = function() {
  1292.     var repeats = this.item().repeats;
  1293.     if (this.isAttack()) {
  1294.         repeats += this.subject().attackTimesAdd();
  1295.     }
  1296.     return Math.floor(repeats);
  1297. };
  1298.  
  1299. Game_Action.prototype.checkItemScope = function(list) {
  1300.     return list.contains(this.item().scope);
  1301. };
  1302.  
  1303. Game_Action.prototype.isForOpponent = function() {
  1304.     return this.checkItemScope([1, 2, 3, 4, 5, 6]);
  1305. };
  1306.  
  1307. Game_Action.prototype.isForFriend = function() {
  1308.     return this.checkItemScope([7, 8, 9, 10, 11]);
  1309. };
  1310.  
  1311. Game_Action.prototype.isForDeadFriend = function() {
  1312.     return this.checkItemScope([9, 10]);
  1313. };
  1314.  
  1315. Game_Action.prototype.isForUser = function() {
  1316.     return this.checkItemScope([11]);
  1317. };
  1318.  
  1319. Game_Action.prototype.isForOne = function() {
  1320.     return this.checkItemScope([1, 3, 7, 9, 11]);
  1321. };
  1322.  
  1323. Game_Action.prototype.isForRandom = function() {
  1324.     return this.checkItemScope([3, 4, 5, 6]);
  1325. };
  1326.  
  1327. Game_Action.prototype.isForAll = function() {
  1328.     return this.checkItemScope([2, 8, 10]);
  1329. };
  1330.  
  1331. Game_Action.prototype.needsSelection = function() {
  1332.     return this.checkItemScope([1, 7, 9]);
  1333. };
  1334.  
  1335. Game_Action.prototype.numTargets = function() {
  1336.     return this.isForRandom() ? this.item().scope - 2 : 0;
  1337. };
  1338.  
  1339. Game_Action.prototype.checkDamageType = function(list) {
  1340.     return list.contains(this.item().damage.type);
  1341. };
  1342.  
  1343. Game_Action.prototype.isHpEffect = function() {
  1344.     return this.checkDamageType([1, 3, 5]);
  1345. };
  1346.  
  1347. Game_Action.prototype.isMpEffect = function() {
  1348.     return this.checkDamageType([2, 4, 6]);
  1349. };
  1350.  
  1351. Game_Action.prototype.isDamage = function() {
  1352.     return this.checkDamageType([1, 2]);
  1353. };
  1354.  
  1355. Game_Action.prototype.isRecover = function() {
  1356.     return this.checkDamageType([3, 4]);
  1357. };
  1358.  
  1359. Game_Action.prototype.isDrain = function() {
  1360.     return this.checkDamageType([5, 6]);
  1361. };
  1362.  
  1363. Game_Action.prototype.isHpRecover = function() {
  1364.     return this.checkDamageType([3]);
  1365. };
  1366.  
  1367. Game_Action.prototype.isMpRecover = function() {
  1368.     return this.checkDamageType([4]);
  1369. };
  1370.  
  1371. Game_Action.prototype.isCertainHit = function() {
  1372.     return this.item().hitType === Game_Action.HITTYPE_CERTAIN;
  1373. };
  1374.  
  1375. Game_Action.prototype.isPhysical = function() {
  1376.     return this.item().hitType === Game_Action.HITTYPE_PHYSICAL;
  1377. };
  1378.  
  1379. Game_Action.prototype.isMagical = function() {
  1380.     return this.item().hitType === Game_Action.HITTYPE_MAGICAL;
  1381. };
  1382.  
  1383. Game_Action.prototype.isAttack = function() {
  1384.     return this.item() === $dataSkills[this.subject().attackSkillId()];
  1385. };
  1386.  
  1387. Game_Action.prototype.isGuard = function() {
  1388.     return this.item() === $dataSkills[this.subject().guardSkillId()];
  1389. };
  1390.  
  1391. Game_Action.prototype.isMagicSkill = function() {
  1392.     if (this.isSkill()) {
  1393.         return $dataSystem.magicSkills.contains(this.item().stypeId);
  1394.     } else {
  1395.         return false;
  1396.     }
  1397. };
  1398.  
  1399. Game_Action.prototype.decideRandomTarget = function() {
  1400.     var target;
  1401.     if (this.isForDeadFriend()) {
  1402.         target = this.friendsUnit().randomDeadTarget();
  1403.     } else if (this.isForFriend()) {
  1404.         target = this.friendsUnit().randomTarget();
  1405.     } else {
  1406.         target = this.opponentsUnit().randomTarget();
  1407.     }
  1408.     if (target) {
  1409.         this._targetIndex = target.index();
  1410.     } else {
  1411.         this.clear();
  1412.     }
  1413. };
  1414.  
  1415. Game_Action.prototype.setConfusion = function() {
  1416.     this.setAttack();
  1417. };
  1418.  
  1419. Game_Action.prototype.prepare = function() {
  1420.     if (this.subject().isConfused() && !this._forcing) {
  1421.         this.setConfusion();
  1422.     }
  1423. };
  1424.  
  1425. Game_Action.prototype.isValid = function() {
  1426.     return (this._forcing && this.item()) || this.subject().canUse(this.item());
  1427. };
  1428.  
  1429. Game_Action.prototype.speed = function() {
  1430.     var agi = this.subject().agi;
  1431.     var speed = agi + Math.randomInt(Math.floor(5 + agi / 4));
  1432.     if (this.item()) {
  1433.         speed += this.item().speed;
  1434.     }
  1435.     if (this.isAttack()) {
  1436.         speed += this.subject().attackSpeed();
  1437.     }
  1438.     return speed;
  1439. };
  1440.  
  1441. Game_Action.prototype.makeTargets = function() {
  1442.     var targets = [];
  1443.     if (!this._forcing && this.subject().isConfused()) {
  1444.         targets = [this.confusionTarget()];
  1445.     } else if (this.isForOpponent()) {
  1446.         targets = this.targetsForOpponents();
  1447.     } else if (this.isForFriend()) {
  1448.         targets = this.targetsForFriends();
  1449.     }
  1450.     return this.repeatTargets(targets);
  1451. };
  1452.  
  1453. Game_Action.prototype.repeatTargets = function(targets) {
  1454.     var repeatedTargets = [];
  1455.     var repeats = this.numRepeats();
  1456.     for (var i = 0; i < targets.length; i++) {
  1457.         var target = targets[i];
  1458.         if (target) {
  1459.             for (var j = 0; j < repeats; j++) {
  1460.                 repeatedTargets.push(target);
  1461.             }
  1462.         }
  1463.     }
  1464.     return repeatedTargets;
  1465. };
  1466.  
  1467. Game_Action.prototype.confusionTarget = function() {
  1468.     switch (this.subject().confusionLevel()) {
  1469.     case 1:
  1470.         return this.opponentsUnit().randomTarget();
  1471.     case 2:
  1472.         if (Math.randomInt(2) === 0) {
  1473.             return this.opponentsUnit().randomTarget();
  1474.         }
  1475.         return this.friendsUnit().randomTarget();
  1476.     default:
  1477.         return this.friendsUnit().randomTarget();
  1478.     }
  1479. };
  1480.  
  1481. Game_Action.prototype.targetsForOpponents = function() {
  1482.     var targets = [];
  1483.     var unit = this.opponentsUnit();
  1484.     if (this.isForRandom()) {
  1485.         for (var i = 0; i < this.numTargets(); i++) {
  1486.             targets.push(unit.randomTarget());
  1487.         }
  1488.     } else if (this.isForOne()) {
  1489.         if (this._targetIndex < 0) {
  1490.             targets.push(unit.randomTarget());
  1491.         } else {
  1492.             targets.push(unit.smoothTarget(this._targetIndex));
  1493.         }
  1494.     } else {
  1495.         targets = unit.aliveMembers();
  1496.     }
  1497.     return targets;
  1498. };
  1499.  
  1500. Game_Action.prototype.targetsForFriends = function() {
  1501.     var targets = [];
  1502.     var unit = this.friendsUnit();
  1503.     if (this.isForUser()) {
  1504.         return [this.subject()];
  1505.     } else if (this.isForDeadFriend()) {
  1506.         if (this.isForOne()) {
  1507.             targets.push(unit.smoothDeadTarget(this._targetIndex));
  1508.         } else {
  1509.             targets = unit.deadMembers();
  1510.         }
  1511.     } else if (this.isForOne()) {
  1512.         if (this._targetIndex < 0) {
  1513.             targets.push(unit.randomTarget());
  1514.         } else {
  1515.             targets.push(unit.smoothTarget(this._targetIndex));
  1516.         }
  1517.     } else {
  1518.         targets = unit.aliveMembers();
  1519.     }
  1520.     return targets;
  1521. };
  1522.  
  1523. Game_Action.prototype.evaluate = function() {
  1524.     var value = 0;
  1525.     this.itemTargetCandidates().forEach(function(target) {
  1526.         var targetValue = this.evaluateWithTarget(target);
  1527.         if (this.isForAll()) {
  1528.             value += targetValue;
  1529.         } else if (targetValue > value) {
  1530.             value = targetValue;
  1531.             this._targetIndex = target.index();
  1532.         }
  1533.     }, this);
  1534.     value *= this.numRepeats();
  1535.     if (value > 0) {
  1536.         value += Math.random();
  1537.     }
  1538.     return value;
  1539. };
  1540.  
  1541. Game_Action.prototype.itemTargetCandidates = function() {
  1542.     if (!this.isValid()) {
  1543.         return [];
  1544.     } else if (this.isForOpponent()) {
  1545.         return this.opponentsUnit().aliveMembers();
  1546.     } else if (this.isForUser()) {
  1547.         return [this.subject()];
  1548.     } else if (this.isForDeadFriend()) {
  1549.         return this.friendsUnit().deadMembers();
  1550.     } else {
  1551.         return this.friendsUnit().aliveMembers();
  1552.     }
  1553. };
  1554.  
  1555. Game_Action.prototype.evaluateWithTarget = function(target) {
  1556.     if (this.isHpEffect()) {
  1557.         var value = this.makeDamageValue(target, false);
  1558.         if (this.isForOpponent()) {
  1559.             return value / Math.max(target.hp, 1);
  1560.         } else {
  1561.             var recovery = Math.min(-value, target.mhp - target.hp);
  1562.             return recovery / target.mhp;
  1563.         }
  1564.     }
  1565. };
  1566.  
  1567. Game_Action.prototype.testApply = function(target) {
  1568.     return (this.isForDeadFriend() === target.isDead() &&
  1569.             ($gameParty.inBattle() || this.isForOpponent() ||
  1570.             (this.isHpRecover() && target.hp < target.mhp) ||
  1571.             (this.isMpRecover() && target.mp < target.mmp) ||
  1572.             (this.hasItemAnyValidEffects(target))));
  1573. };
  1574.  
  1575. Game_Action.prototype.hasItemAnyValidEffects = function(target) {
  1576.     return this.item().effects.some(function(effect) {
  1577.         return this.testItemEffect(target, effect);
  1578.     }, this);
  1579. };
  1580.  
  1581. Game_Action.prototype.testItemEffect = function(target, effect) {
  1582.     switch (effect.code) {
  1583.     case Game_Action.EFFECT_RECOVER_HP:
  1584.         return target.hp < target.mhp || effect.value1 < 0 || effect.value2 < 0;
  1585.     case Game_Action.EFFECT_RECOVER_MP:
  1586.         return target.mp < target.mmp || effect.value1 < 0 || effect.value2 < 0;
  1587.     case Game_Action.EFFECT_ADD_STATE:
  1588.         return !target.isStateAffected(effect.dataId);
  1589.     case Game_Action.EFFECT_REMOVE_STATE:
  1590.         return target.isStateAffected(effect.dataId);
  1591.     case Game_Action.EFFECT_ADD_BUFF:
  1592.         return !target.isMaxBuffAffected(effect.dataId);
  1593.     case Game_Action.EFFECT_ADD_DEBUFF:
  1594.         return !target.isMaxDebuffAffected(effect.dataId);
  1595.     case Game_Action.EFFECT_REMOVE_BUFF:
  1596.         return target.isBuffAffected(effect.dataId);
  1597.     case Game_Action.EFFECT_REMOVE_DEBUFF:
  1598.         return target.isDebuffAffected(effect.dataId);
  1599.     case Game_Action.EFFECT_LEARN_SKILL:
  1600.         return target.isActor() && !target.isLearnedSkill(effect.dataId);
  1601.     default:
  1602.         return true;
  1603.     }
  1604. };
  1605.  
  1606. Game_Action.prototype.itemCnt = function(target) {
  1607.     if (this.isPhysical() && target.canMove()) {
  1608.         return target.cnt;
  1609.     } else {
  1610.         return 0;
  1611.     }
  1612. };
  1613.  
  1614. Game_Action.prototype.itemMrf = function(target) {
  1615.     if (this.isMagical()) {
  1616.         return target.mrf;
  1617.     } else {
  1618.         return 0;
  1619.     }
  1620. };
  1621.  
  1622. Game_Action.prototype.itemHit = function(target) {
  1623.     if (this.isPhysical()) {
  1624.         return this.item().successRate * 0.01 * this.subject().hit;
  1625.     } else {
  1626.         return this.item().successRate * 0.01;
  1627.     }
  1628. };
  1629.  
  1630. Game_Action.prototype.itemEva = function(target) {
  1631.     if (this.isPhysical()) {
  1632.         return target.eva;
  1633.     } else if (this.isMagical()) {
  1634.         return target.mev;
  1635.     } else {
  1636.         return 0;
  1637.     }
  1638. };
  1639.  
  1640. Game_Action.prototype.itemCri = function(target) {
  1641.     return this.item().damage.critical ? this.subject().cri * (1 - target.cev) : 0;
  1642. };
  1643.  
  1644. Game_Action.prototype.apply = function(target) {
  1645.     var result = target.result();
  1646.     this.subject().clearResult();
  1647.     result.clear();
  1648.     result.used = this.testApply(target);
  1649.     result.missed = (result.used && Math.random() >= this.itemHit(target));
  1650.     result.evaded = (!result.missed && Math.random() < this.itemEva(target));
  1651.     result.physical = this.isPhysical();
  1652.     result.drain = this.isDrain();
  1653.     if (result.isHit()) {
  1654.         if (this.item().damage.type > 0) {
  1655.             result.critical = (Math.random() < this.itemCri(target));
  1656.             var value = this.makeDamageValue(target, result.critical);
  1657.             this.executeDamage(target, value);
  1658.         }
  1659.         this.item().effects.forEach(function(effect) {
  1660.             this.applyItemEffect(target, effect);
  1661.         }, this);
  1662.         this.applyItemUserEffect(target);
  1663.     }
  1664. };
  1665.  
  1666. Game_Action.prototype.makeDamageValue = function(target, critical) {
  1667.     var item = this.item();
  1668.     var baseValue = this.evalDamageFormula(target);
  1669.     var value = baseValue * this.calcElementRate(target);
  1670.     if (this.isPhysical()) {
  1671.         value *= target.pdr;
  1672.     }
  1673.     if (this.isMagical()) {
  1674.         value *= target.mdr;
  1675.     }
  1676.     if (baseValue < 0) {
  1677.         value *= target.rec;
  1678.     }
  1679.     if (critical) {
  1680.         value = this.applyCritical(value);
  1681.     }
  1682.     value = this.applyVariance(value, item.damage.variance);
  1683.     value = this.applyGuard(value, target);
  1684.     value = Math.round(value);
  1685.     return value;
  1686. };
  1687.  
  1688. Game_Action.prototype.evalDamageFormula = function(target) {
  1689.     try {
  1690.         var item = this.item();
  1691.         var a = this.subject();
  1692.         var b = target;
  1693.         var v = $gameVariables._data;
  1694.         var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
  1695.         var value = Math.max(eval(item.damage.formula), 0) * sign;
  1696.         if (isNaN(value)) value = 0;
  1697.         return value;
  1698.     } catch (e) {
  1699.         return 0;
  1700.     }
  1701. };
  1702.  
  1703. Game_Action.prototype.calcElementRate = function(target) {
  1704.     if (this.item().damage.elementId < 0) {
  1705.         return this.elementsMaxRate(target, this.subject().attackElements());
  1706.     } else {
  1707.         return target.elementRate(this.item().damage.elementId);
  1708.     }
  1709. };
  1710.  
  1711. Game_Action.prototype.elementsMaxRate = function(target, elements) {
  1712.     if (elements.length > 0) {
  1713.         return Math.max.apply(null, elements.map(function(elementId) {
  1714.             return target.elementRate(elementId);
  1715.         }, this));
  1716.     } else {
  1717.         return 1;
  1718.     }
  1719. };
  1720.  
  1721. Game_Action.prototype.applyCritical = function(damage) {
  1722.     return damage * 3;
  1723. };
  1724.  
  1725. Game_Action.prototype.applyVariance = function(damage, variance) {
  1726.     var amp = Math.floor(Math.max(Math.abs(damage) * variance / 100, 0));
  1727.     var v = Math.randomInt(amp + 1) + Math.randomInt(amp + 1) - amp;
  1728.     return damage >= 0 ? damage + v : damage - v;
  1729. };
  1730.  
  1731. Game_Action.prototype.applyGuard = function(damage, target) {
  1732.     return damage / (damage > 0 && target.isGuard() ? 2 * target.grd : 1);
  1733. };
  1734.  
  1735. Game_Action.prototype.executeDamage = function(target, value) {
  1736.     var result = target.result();
  1737.     if (value === 0) {
  1738.         result.critical = false;
  1739.     }
  1740.     if (this.isHpEffect()) {
  1741.         this.executeHpDamage(target, value);
  1742.     }
  1743.     if (this.isMpEffect()) {
  1744.         this.executeMpDamage(target, value);
  1745.     }
  1746. };
  1747.  
  1748. Game_Action.prototype.executeHpDamage = function(target, value) {
  1749.     if (this.isDrain()) {
  1750.         value = Math.min(target.hp, value);
  1751.     }
  1752.     this.makeSuccess(target);
  1753.     target.gainHp(-value);
  1754.     if (value > 0) {
  1755.         target.onDamage(value);
  1756.     }
  1757.     this.gainDrainedHp(value);
  1758. };
  1759.  
  1760. Game_Action.prototype.executeMpDamage = function(target, value) {
  1761.     if (!this.isMpRecover()) {
  1762.         value = Math.min(target.mp, value);
  1763.     }
  1764.     if (value !== 0) {
  1765.         this.makeSuccess(target);
  1766.     }
  1767.     target.gainMp(-value);
  1768.     this.gainDrainedMp(value);
  1769. };
  1770.  
  1771. Game_Action.prototype.gainDrainedHp = function(value) {
  1772.     if (this.isDrain()) {
  1773.        var gainTarget = this.subject();
  1774.        if (this._reflectionTarget !== undefined) {
  1775.             gainTarget = this._reflectionTarget;
  1776.         }
  1777.        gainTarget.gainHp(value);
  1778.     }
  1779. };
  1780.  
  1781. Game_Action.prototype.gainDrainedMp = function(value) {
  1782.     if (this.isDrain()) {
  1783.        var gainTarget = this.subject();
  1784.        if (this._reflectionTarget !== undefined) {
  1785.            gainTarget = this._reflectionTarget;
  1786.        }
  1787.        gainTarget.gainMp(value);
  1788.     }
  1789. };
  1790.  
  1791. Game_Action.prototype.applyItemEffect = function(target, effect) {
  1792.     switch (effect.code) {
  1793.     case Game_Action.EFFECT_RECOVER_HP:
  1794.         this.itemEffectRecoverHp(target, effect);
  1795.         break;
  1796.     case Game_Action.EFFECT_RECOVER_MP:
  1797.         this.itemEffectRecoverMp(target, effect);
  1798.         break;
  1799.     case Game_Action.EFFECT_GAIN_TP:
  1800.         this.itemEffectGainTp(target, effect);
  1801.         break;
  1802.     case Game_Action.EFFECT_ADD_STATE:
  1803.         this.itemEffectAddState(target, effect);
  1804.         break;
  1805.     case Game_Action.EFFECT_REMOVE_STATE:
  1806.         this.itemEffectRemoveState(target, effect);
  1807.         break;
  1808.     case Game_Action.EFFECT_ADD_BUFF:
  1809.         this.itemEffectAddBuff(target, effect);
  1810.         break;
  1811.     case Game_Action.EFFECT_ADD_DEBUFF:
  1812.         this.itemEffectAddDebuff(target, effect);
  1813.         break;
  1814.     case Game_Action.EFFECT_REMOVE_BUFF:
  1815.         this.itemEffectRemoveBuff(target, effect);
  1816.         break;
  1817.     case Game_Action.EFFECT_REMOVE_DEBUFF:
  1818.         this.itemEffectRemoveDebuff(target, effect);
  1819.         break;
  1820.     case Game_Action.EFFECT_SPECIAL:
  1821.         this.itemEffectSpecial(target, effect);
  1822.         break;
  1823.     case Game_Action.EFFECT_GROW:
  1824.         this.itemEffectGrow(target, effect);
  1825.         break;
  1826.     case Game_Action.EFFECT_LEARN_SKILL:
  1827.         this.itemEffectLearnSkill(target, effect);
  1828.         break;
  1829.     case Game_Action.EFFECT_COMMON_EVENT:
  1830.         this.itemEffectCommonEvent(target, effect);
  1831.         break;
  1832.     }
  1833. };
  1834.  
  1835. Game_Action.prototype.itemEffectRecoverHp = function(target, effect) {
  1836.     var value = (target.mhp * effect.value1 + effect.value2) * target.rec;
  1837.     if (this.isItem()) {
  1838.         value *= this.subject().pha;
  1839.     }
  1840.     value = Math.floor(value);
  1841.     if (value !== 0) {
  1842.         target.gainHp(value);
  1843.         this.makeSuccess(target);
  1844.     }
  1845. };
  1846.  
  1847. Game_Action.prototype.itemEffectRecoverMp = function(target, effect) {
  1848.     var value = (target.mmp * effect.value1 + effect.value2) * target.rec;
  1849.     if (this.isItem()) {
  1850.         value *= this.subject().pha;
  1851.     }
  1852.     value = Math.floor(value);
  1853.     if (value !== 0) {
  1854.         target.gainMp(value);
  1855.         this.makeSuccess(target);
  1856.     }
  1857. };
  1858.  
  1859. Game_Action.prototype.itemEffectGainTp = function(target, effect) {
  1860.     var value = Math.floor(effect.value1);
  1861.     if (value !== 0) {
  1862.         target.gainTp(value);
  1863.         this.makeSuccess(target);
  1864.     }
  1865. };
  1866.  
  1867. Game_Action.prototype.itemEffectAddState = function(target, effect) {
  1868.     if (effect.dataId === 0) {
  1869.         this.itemEffectAddAttackState(target, effect);
  1870.     } else {
  1871.         this.itemEffectAddNormalState(target, effect);
  1872.     }
  1873. };
  1874.  
  1875. Game_Action.prototype.itemEffectAddAttackState = function(target, effect) {
  1876.     this.subject().attackStates().forEach(function(stateId) {
  1877.         var chance = effect.value1;
  1878.         chance *= target.stateRate(stateId);
  1879.         chance *= this.subject().attackStatesRate(stateId);
  1880.         chance *= this.lukEffectRate(target);
  1881.         if (Math.random() < chance) {
  1882.             target.addState(stateId);
  1883.             this.makeSuccess(target);
  1884.         }
  1885.     }.bind(this), target);
  1886. };
  1887.  
  1888. Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
  1889.     var chance = effect.value1;
  1890.     if (!this.isCertainHit()) {
  1891.         chance *= target.stateRate(effect.dataId);
  1892.         chance *= this.lukEffectRate(target);
  1893.     }
  1894.     if (Math.random() < chance) {
  1895.         target.addState(effect.dataId);
  1896.         this.makeSuccess(target);
  1897.     }
  1898. };
  1899.  
  1900. Game_Action.prototype.itemEffectRemoveState = function(target, effect) {
  1901.     var chance = effect.value1;
  1902.     if (Math.random() < chance) {
  1903.         target.removeState(effect.dataId);
  1904.         this.makeSuccess(target);
  1905.     }
  1906. };
  1907.  
  1908. Game_Action.prototype.itemEffectAddBuff = function(target, effect) {
  1909.     target.addBuff(effect.dataId, effect.value1);
  1910.     this.makeSuccess(target);
  1911. };
  1912.  
  1913. Game_Action.prototype.itemEffectAddDebuff = function(target, effect) {
  1914.     var chance = target.debuffRate(effect.dataId) * this.lukEffectRate(target);
  1915.     if (Math.random() < chance) {
  1916.         target.addDebuff(effect.dataId, effect.value1);
  1917.         this.makeSuccess(target);
  1918.     }
  1919. };
  1920.  
  1921. Game_Action.prototype.itemEffectRemoveBuff = function(target, effect) {
  1922.     if (target.isBuffAffected(effect.dataId)) {
  1923.         target.removeBuff(effect.dataId);
  1924.         this.makeSuccess(target);
  1925.     }
  1926. };
  1927.  
  1928. Game_Action.prototype.itemEffectRemoveDebuff = function(target, effect) {
  1929.     if (target.isDebuffAffected(effect.dataId)) {
  1930.         target.removeBuff(effect.dataId);
  1931.         this.makeSuccess(target);
  1932.     }
  1933. };
  1934.  
  1935. Game_Action.prototype.itemEffectSpecial = function(target, effect) {
  1936.     if (effect.dataId === Game_Action.SPECIAL_EFFECT_ESCAPE) {
  1937.         target.escape();
  1938.         this.makeSuccess(target);
  1939.     }
  1940. };
  1941.  
  1942. Game_Action.prototype.itemEffectGrow = function(target, effect) {
  1943.     target.addParam(effect.dataId, Math.floor(effect.value1));
  1944.     this.makeSuccess(target);
  1945. };
  1946.  
  1947. Game_Action.prototype.itemEffectLearnSkill = function(target, effect) {
  1948.     if (target.isActor()) {
  1949.         target.learnSkill(effect.dataId);
  1950.         this.makeSuccess(target);
  1951.     }
  1952. };
  1953.  
  1954. Game_Action.prototype.itemEffectCommonEvent = function(target, effect) {
  1955. };
  1956.  
  1957. Game_Action.prototype.makeSuccess = function(target) {
  1958.     target.result().success = true;
  1959. };
  1960.  
  1961. Game_Action.prototype.applyItemUserEffect = function(target) {
  1962.     var value = Math.floor(this.item().tpGain * this.subject().tcr);
  1963.     this.subject().gainSilentTp(value);
  1964. };
  1965.  
  1966. Game_Action.prototype.lukEffectRate = function(target) {
  1967.     return Math.max(1.0 + (this.subject().luk - target.luk) * 0.001, 0.0);
  1968. };
  1969.  
  1970. Game_Action.prototype.applyGlobal = function() {
  1971.     this.item().effects.forEach(function(effect) {
  1972.         if (effect.code === Game_Action.EFFECT_COMMON_EVENT) {
  1973.             $gameTemp.reserveCommonEvent(effect.dataId);
  1974.         }
  1975.     }, this);
  1976. };
  1977.  
  1978. //-----------------------------------------------------------------------------
  1979. // Game_ActionResult
  1980. //
  1981. // The game object class for a result of a battle action. For convinience, all
  1982. // member variables in this class are public.
  1983.  
  1984. function Game_ActionResult() {
  1985.     this.initialize.apply(this, arguments);
  1986. }
  1987.  
  1988. Game_ActionResult.prototype.initialize = function() {
  1989.     this.clear();
  1990. };
  1991.  
  1992. Game_ActionResult.prototype.clear = function() {
  1993.     this.used = false;
  1994.     this.missed = false;
  1995.     this.evaded = false;
  1996.     this.physical = false;
  1997.     this.drain = false;
  1998.     this.critical = false;
  1999.     this.success = false;
  2000.     this.hpAffected = false;
  2001.     this.hpDamage = 0;
  2002.     this.mpDamage = 0;
  2003.     this.tpDamage = 0;
  2004.     this.addedStates = [];
  2005.     this.removedStates = [];
  2006.     this.addedBuffs = [];
  2007.     this.addedDebuffs = [];
  2008.     this.removedBuffs = [];
  2009. };
  2010.  
  2011. Game_ActionResult.prototype.addedStateObjects = function() {
  2012.     return this.addedStates.map(function(id) {
  2013.         return $dataStates[id];
  2014.     });
  2015. };
  2016.  
  2017. Game_ActionResult.prototype.removedStateObjects = function() {
  2018.     return this.removedStates.map(function(id) {
  2019.         return $dataStates[id];
  2020.     });
  2021. };
  2022.  
  2023. Game_ActionResult.prototype.isStatusAffected = function() {
  2024.     return (this.addedStates.length > 0 || this.removedStates.length > 0 ||
  2025.             this.addedBuffs.length > 0 || this.addedDebuffs.length > 0 ||
  2026.             this.removedBuffs.length > 0);
  2027. };
  2028.  
  2029. Game_ActionResult.prototype.isHit = function() {
  2030.     return this.used && !this.missed && !this.evaded;
  2031. };
  2032.  
  2033. Game_ActionResult.prototype.isStateAdded = function(stateId) {
  2034.     return this.addedStates.contains(stateId);
  2035. };
  2036.  
  2037. Game_ActionResult.prototype.pushAddedState = function(stateId) {
  2038.     if (!this.isStateAdded(stateId)) {
  2039.         this.addedStates.push(stateId);
  2040.     }
  2041. };
  2042.  
  2043. Game_ActionResult.prototype.isStateRemoved = function(stateId) {
  2044.     return this.removedStates.contains(stateId);
  2045. };
  2046.  
  2047. Game_ActionResult.prototype.pushRemovedState = function(stateId) {
  2048.     if (!this.isStateRemoved(stateId)) {
  2049.         this.removedStates.push(stateId);
  2050.     }
  2051. };
  2052.  
  2053. Game_ActionResult.prototype.isBuffAdded = function(paramId) {
  2054.     return this.addedBuffs.contains(paramId);
  2055. };
  2056.  
  2057. Game_ActionResult.prototype.pushAddedBuff = function(paramId) {
  2058.     if (!this.isBuffAdded(paramId)) {
  2059.         this.addedBuffs.push(paramId);
  2060.     }
  2061. };
  2062.  
  2063. Game_ActionResult.prototype.isDebuffAdded = function(paramId) {
  2064.     return this.addedDebuffs.contains(paramId);
  2065. };
  2066.  
  2067. Game_ActionResult.prototype.pushAddedDebuff = function(paramId) {
  2068.     if (!this.isDebuffAdded(paramId)) {
  2069.         this.addedDebuffs.push(paramId);
  2070.     }
  2071. };
  2072.  
  2073. Game_ActionResult.prototype.isBuffRemoved = function(paramId) {
  2074.     return this.removedBuffs.contains(paramId);
  2075. };
  2076.  
  2077. Game_ActionResult.prototype.pushRemovedBuff = function(paramId) {
  2078.     if (!this.isBuffRemoved(paramId)) {
  2079.         this.removedBuffs.push(paramId);
  2080.     }
  2081. };
  2082.  
  2083. //-----------------------------------------------------------------------------
  2084. // Game_BattlerBase
  2085. //
  2086. // The superclass of Game_Battler. It mainly contains parameters calculation.
  2087.  
  2088. function Game_BattlerBase() {
  2089.     this.initialize.apply(this, arguments);
  2090. }
  2091.  
  2092. Game_BattlerBase.TRAIT_ELEMENT_RATE   = 11;
  2093. Game_BattlerBase.TRAIT_DEBUFF_RATE    = 12;
  2094. Game_BattlerBase.TRAIT_STATE_RATE     = 13;
  2095. Game_BattlerBase.TRAIT_STATE_RESIST   = 14;
  2096. Game_BattlerBase.TRAIT_PARAM          = 21;
  2097. Game_BattlerBase.TRAIT_XPARAM         = 22;
  2098. Game_BattlerBase.TRAIT_SPARAM         = 23;
  2099. Game_BattlerBase.TRAIT_ATTACK_ELEMENT = 31;
  2100. Game_BattlerBase.TRAIT_ATTACK_STATE   = 32;
  2101. Game_BattlerBase.TRAIT_ATTACK_SPEED   = 33;
  2102. Game_BattlerBase.TRAIT_ATTACK_TIMES   = 34;
  2103. Game_BattlerBase.TRAIT_STYPE_ADD      = 41;
  2104. Game_BattlerBase.TRAIT_STYPE_SEAL     = 42;
  2105. Game_BattlerBase.TRAIT_SKILL_ADD      = 43;
  2106. Game_BattlerBase.TRAIT_SKILL_SEAL     = 44;
  2107. Game_BattlerBase.TRAIT_EQUIP_WTYPE    = 51;
  2108. Game_BattlerBase.TRAIT_EQUIP_ATYPE    = 52;
  2109. Game_BattlerBase.TRAIT_EQUIP_LOCK     = 53;
  2110. Game_BattlerBase.TRAIT_EQUIP_SEAL     = 54;
  2111. Game_BattlerBase.TRAIT_SLOT_TYPE      = 55;
  2112. Game_BattlerBase.TRAIT_ACTION_PLUS    = 61;
  2113. Game_BattlerBase.TRAIT_SPECIAL_FLAG   = 62;
  2114. Game_BattlerBase.TRAIT_COLLAPSE_TYPE  = 63;
  2115. Game_BattlerBase.TRAIT_PARTY_ABILITY  = 64;
  2116. Game_BattlerBase.FLAG_ID_AUTO_BATTLE  = 0;
  2117. Game_BattlerBase.FLAG_ID_GUARD        = 1;
  2118. Game_BattlerBase.FLAG_ID_SUBSTITUTE   = 2;
  2119. Game_BattlerBase.FLAG_ID_PRESERVE_TP  = 3;
  2120. Game_BattlerBase.ICON_BUFF_START      = 32;
  2121. Game_BattlerBase.ICON_DEBUFF_START    = 48;
  2122.  
  2123. Object.defineProperties(Game_BattlerBase.prototype, {
  2124.     // Hit Points
  2125.     hp: { get: function() { return this._hp; }, configurable: true },
  2126.     // Magic Points
  2127.     mp: { get: function() { return this._mp; }, configurable: true },
  2128.     // Tactical Points
  2129.     tp: { get: function() { return this._tp; }, configurable: true },
  2130.     // Maximum Hit Points
  2131.     mhp: { get: function() { return this.param(0); }, configurable: true },
  2132.     // Maximum Magic Points
  2133.     mmp: { get: function() { return this.param(1); }, configurable: true },
  2134.     // ATtacK power
  2135.     atk: { get: function() { return this.param(2); }, configurable: true },
  2136.     // DEFense power
  2137.     def: { get: function() { return this.param(3); }, configurable: true },
  2138.     // Magic ATtack power
  2139.     mat: { get: function() { return this.param(4); }, configurable: true },
  2140.     // Magic DeFense power
  2141.     mdf: { get: function() { return this.param(5); }, configurable: true },
  2142.     // AGIlity
  2143.     agi: { get: function() { return this.param(6); }, configurable: true },
  2144.     // LUcK
  2145.     luk: { get: function() { return this.param(7); }, configurable: true },
  2146.     // HIT rate
  2147.     hit: { get: function() { return this.xparam(0); }, configurable: true },
  2148.     // EVAsion rate
  2149.     eva: { get: function() { return this.xparam(1); }, configurable: true },
  2150.     // CRItical rate
  2151.     cri: { get: function() { return this.xparam(2); }, configurable: true },
  2152.     // Critical EVasion rate
  2153.     cev: { get: function() { return this.xparam(3); }, configurable: true },
  2154.     // Magic EVasion rate
  2155.     mev: { get: function() { return this.xparam(4); }, configurable: true },
  2156.     // Magic ReFlection rate
  2157.     mrf: { get: function() { return this.xparam(5); }, configurable: true },
  2158.     // CouNTer attack rate
  2159.     cnt: { get: function() { return this.xparam(6); }, configurable: true },
  2160.     // Hp ReGeneration rate
  2161.     hrg: { get: function() { return this.xparam(7); }, configurable: true },
  2162.     // Mp ReGeneration rate
  2163.     mrg: { get: function() { return this.xparam(8); }, configurable: true },
  2164.     // Tp ReGeneration rate
  2165.     trg: { get: function() { return this.xparam(9); }, configurable: true },
  2166.     // TarGet Rate
  2167.     tgr: { get: function() { return this.sparam(0); }, configurable: true },
  2168.     // GuaRD effect rate
  2169.     grd: { get: function() { return this.sparam(1); }, configurable: true },
  2170.     // RECovery effect rate
  2171.     rec: { get: function() { return this.sparam(2); }, configurable: true },
  2172.     // PHArmacology
  2173.     pha: { get: function() { return this.sparam(3); }, configurable: true },
  2174.     // Mp Cost Rate
  2175.     mcr: { get: function() { return this.sparam(4); }, configurable: true },
  2176.     // Tp Charge Rate
  2177.     tcr: { get: function() { return this.sparam(5); }, configurable: true },
  2178.     // Physical Damage Rate
  2179.     pdr: { get: function() { return this.sparam(6); }, configurable: true },
  2180.     // Magical Damage Rate
  2181.     mdr: { get: function() { return this.sparam(7); }, configurable: true },
  2182.     // Floor Damage Rate
  2183.     fdr: { get: function() { return this.sparam(8); }, configurable: true },
  2184.     // EXperience Rate
  2185.     exr: { get: function() { return this.sparam(9); }, configurable: true }
  2186. });
  2187.  
  2188. Game_BattlerBase.prototype.initialize = function() {
  2189.     this.initMembers();
  2190. };
  2191.  
  2192. Game_BattlerBase.prototype.initMembers = function() {
  2193.     this._hp = 1;
  2194.     this._mp = 0;
  2195.     this._tp = 0;
  2196.     this._hidden = false;
  2197.     this.clearParamPlus();
  2198.     this.clearStates();
  2199.     this.clearBuffs();
  2200. };
  2201.  
  2202. Game_BattlerBase.prototype.clearParamPlus = function() {
  2203.     this._paramPlus = [0,0,0,0,0,0,0,0];
  2204. };
  2205.  
  2206. Game_BattlerBase.prototype.clearStates = function() {
  2207.     this._states = [];
  2208.     this._stateTurns = {};
  2209. };
  2210.  
  2211. Game_BattlerBase.prototype.eraseState = function(stateId) {
  2212.     var index = this._states.indexOf(stateId);
  2213.     if (index >= 0) {
  2214.         this._states.splice(index, 1);
  2215.     }
  2216.     delete this._stateTurns[stateId];
  2217. };
  2218.  
  2219. Game_BattlerBase.prototype.isStateAffected = function(stateId) {
  2220.     return this._states.contains(stateId);
  2221. };
  2222.  
  2223. Game_BattlerBase.prototype.isDeathStateAffected = function() {
  2224.     return this.isStateAffected(this.deathStateId());
  2225. };
  2226.  
  2227. Game_BattlerBase.prototype.deathStateId = function() {
  2228.     return 1;
  2229. };
  2230.  
  2231. Game_BattlerBase.prototype.resetStateCounts = function(stateId) {
  2232.     var state = $dataStates[stateId];
  2233.     var variance = 1 + Math.max(state.maxTurns - state.minTurns, 0);
  2234.     this._stateTurns[stateId] = state.minTurns + Math.randomInt(variance);
  2235. };
  2236.  
  2237. Game_BattlerBase.prototype.isStateExpired = function(stateId) {
  2238.     return this._stateTurns[stateId] === 0;
  2239. };
  2240.  
  2241. Game_BattlerBase.prototype.updateStateTurns = function() {
  2242.     this._states.forEach(function(stateId) {
  2243.         if (this._stateTurns[stateId] > 0) {
  2244.             this._stateTurns[stateId]--;
  2245.         }
  2246.     }, this);
  2247. };
  2248.  
  2249. Game_BattlerBase.prototype.clearBuffs = function() {
  2250.     this._buffs = [0,0,0,0,0,0,0,0];
  2251.     this._buffTurns = [0,0,0,0,0,0,0,0];
  2252. };
  2253.  
  2254. Game_BattlerBase.prototype.eraseBuff = function(paramId) {
  2255.     this._buffs[paramId] = 0;
  2256.     this._buffTurns[paramId] = 0;
  2257. };
  2258.  
  2259. Game_BattlerBase.prototype.buffLength = function() {
  2260.     return this._buffs.length;
  2261. };
  2262.  
  2263. Game_BattlerBase.prototype.buff = function(paramId) {
  2264.     return this._buffs[paramId];
  2265. };
  2266.  
  2267. Game_BattlerBase.prototype.isBuffAffected = function(paramId) {
  2268.     return this._buffs[paramId] > 0;
  2269. };
  2270.  
  2271. Game_BattlerBase.prototype.isDebuffAffected = function(paramId) {
  2272.     return this._buffs[paramId] < 0;
  2273. };
  2274.  
  2275. Game_BattlerBase.prototype.isBuffOrDebuffAffected = function(paramId) {
  2276.     return this._buffs[paramId] !== 0;
  2277. };
  2278.  
  2279. Game_BattlerBase.prototype.isMaxBuffAffected = function(paramId) {
  2280.     return this._buffs[paramId] === 2;
  2281. };
  2282.  
  2283. Game_BattlerBase.prototype.isMaxDebuffAffected = function(paramId) {
  2284.     return this._buffs[paramId] === -2;
  2285. };
  2286.  
  2287. Game_BattlerBase.prototype.increaseBuff = function(paramId) {
  2288.     if (!this.isMaxBuffAffected(paramId)) {
  2289.         this._buffs[paramId]++;
  2290.     }
  2291. };
  2292.  
  2293. Game_BattlerBase.prototype.decreaseBuff = function(paramId) {
  2294.     if (!this.isMaxDebuffAffected(paramId)) {
  2295.         this._buffs[paramId]--;
  2296.     }
  2297. };
  2298.  
  2299. Game_BattlerBase.prototype.overwriteBuffTurns = function(paramId, turns) {
  2300.     if (this._buffTurns[paramId] < turns) {
  2301.         this._buffTurns[paramId] = turns;
  2302.     }
  2303. };
  2304.  
  2305. Game_BattlerBase.prototype.isBuffExpired = function(paramId) {
  2306.     return this._buffTurns[paramId] === 0;
  2307. };
  2308.  
  2309. Game_BattlerBase.prototype.updateBuffTurns = function() {
  2310.     for (var i = 0; i < this._buffTurns.length; i++) {
  2311.         if (this._buffTurns[i] > 0) {
  2312.             this._buffTurns[i]--;
  2313.         }
  2314.     }
  2315. };
  2316.  
  2317. Game_BattlerBase.prototype.die = function() {
  2318.     this._hp = 0;
  2319.     this.clearStates();
  2320.     this.clearBuffs();
  2321. };
  2322.  
  2323. Game_BattlerBase.prototype.revive = function() {
  2324.     if (this._hp === 0) {
  2325.         this._hp = 1;
  2326.     }
  2327. };
  2328.  
  2329. Game_BattlerBase.prototype.states = function() {
  2330.     return this._states.map(function(id) {
  2331.         return $dataStates[id];
  2332.     });
  2333. };
  2334.  
  2335. Game_BattlerBase.prototype.stateIcons = function() {
  2336.     return this.states().map(function(state) {
  2337.         return state.iconIndex;
  2338.     }).filter(function(iconIndex) {
  2339.         return iconIndex > 0;
  2340.     });
  2341. };
  2342.  
  2343. Game_BattlerBase.prototype.buffIcons = function() {
  2344.     var icons = [];
  2345.     for (var i = 0; i < this._buffs.length; i++) {
  2346.         if (this._buffs[i] !== 0) {
  2347.             icons.push(this.buffIconIndex(this._buffs[i], i));
  2348.         }
  2349.     }
  2350.     return icons;
  2351. };
  2352.  
  2353. Game_BattlerBase.prototype.buffIconIndex = function(buffLevel, paramId) {
  2354.     if (buffLevel > 0) {
  2355.         return Game_BattlerBase.ICON_BUFF_START + (buffLevel - 1) * 8 + paramId;
  2356.     } else if (buffLevel < 0) {
  2357.         return Game_BattlerBase.ICON_DEBUFF_START + (-buffLevel - 1) * 8 + paramId;
  2358.     } else {
  2359.         return 0;
  2360.     }
  2361. };
  2362.  
  2363. Game_BattlerBase.prototype.allIcons = function() {
  2364.     return this.stateIcons().concat(this.buffIcons());
  2365. };
  2366.  
  2367. Game_BattlerBase.prototype.traitObjects = function() {
  2368.     // Returns an array of the all objects having traits. States only here.
  2369.     return this.states();
  2370. };
  2371.  
  2372. Game_BattlerBase.prototype.allTraits = function() {
  2373.     return this.traitObjects().reduce(function(r, obj) {
  2374.         return r.concat(obj.traits);
  2375.     }, []);
  2376. };
  2377.  
  2378. Game_BattlerBase.prototype.traits = function(code) {
  2379.     return this.allTraits().filter(function(trait) {
  2380.         return trait.code === code;
  2381.     });
  2382. };
  2383.  
  2384. Game_BattlerBase.prototype.traitsWithId = function(code, id) {
  2385.     return this.allTraits().filter(function(trait) {
  2386.         return trait.code === code && trait.dataId === id;
  2387.     });
  2388. };
  2389.  
  2390. Game_BattlerBase.prototype.traitsPi = function(code, id) {
  2391.     return this.traitsWithId(code, id).reduce(function(r, trait) {
  2392.         return r * trait.value;
  2393.     }, 1);
  2394. };
  2395.  
  2396. Game_BattlerBase.prototype.traitsSum = function(code, id) {
  2397.     return this.traitsWithId(code, id).reduce(function(r, trait) {
  2398.         return r + trait.value;
  2399.     }, 0);
  2400. };
  2401.  
  2402. Game_BattlerBase.prototype.traitsSumAll = function(code) {
  2403.     return this.traits(code).reduce(function(r, trait) {
  2404.         return r + trait.value;
  2405.     }, 0);
  2406. };
  2407.  
  2408. Game_BattlerBase.prototype.traitsSet = function(code) {
  2409.     return this.traits(code).reduce(function(r, trait) {
  2410.         return r.concat(trait.dataId);
  2411.     }, []);
  2412. };
  2413.  
  2414. Game_BattlerBase.prototype.paramBase = function(paramId) {
  2415.     return 0;
  2416. };
  2417.  
  2418. Game_BattlerBase.prototype.paramPlus = function(paramId) {
  2419.     return this._paramPlus[paramId];
  2420. };
  2421.  
  2422. Game_BattlerBase.prototype.paramMin = function(paramId) {
  2423.     if (paramId === 1) {
  2424.         return 0;   // MMP
  2425.     } else {
  2426.         return 1;
  2427.     }
  2428. };
  2429.  
  2430. Game_BattlerBase.prototype.paramMax = function(paramId) {
  2431.     if (paramId === 0) {
  2432.         return 999999;  // MHP
  2433.     } else if (paramId === 1) {
  2434.         return 9999;    // MMP
  2435.     } else {
  2436.         return 999;
  2437.     }
  2438. };
  2439.  
  2440. Game_BattlerBase.prototype.paramRate = function(paramId) {
  2441.     return this.traitsPi(Game_BattlerBase.TRAIT_PARAM, paramId);
  2442. };
  2443.  
  2444. Game_BattlerBase.prototype.paramBuffRate = function(paramId) {
  2445.     return this._buffs[paramId] * 0.25 + 1.0;
  2446. };
  2447.  
  2448. Game_BattlerBase.prototype.param = function(paramId) {
  2449.     var value = this.paramBase(paramId) + this.paramPlus(paramId);
  2450.     value *= this.paramRate(paramId) * this.paramBuffRate(paramId);
  2451.     var maxValue = this.paramMax(paramId);
  2452.     var minValue = this.paramMin(paramId);
  2453.     return Math.round(value.clamp(minValue, maxValue));
  2454. };
  2455.  
  2456. Game_BattlerBase.prototype.xparam = function(xparamId) {
  2457.     return this.traitsSum(Game_BattlerBase.TRAIT_XPARAM, xparamId);
  2458. };
  2459.  
  2460. Game_BattlerBase.prototype.sparam = function(sparamId) {
  2461.     return this.traitsPi(Game_BattlerBase.TRAIT_SPARAM, sparamId);
  2462. };
  2463.  
  2464. Game_BattlerBase.prototype.elementRate = function(elementId) {
  2465.     return this.traitsPi(Game_BattlerBase.TRAIT_ELEMENT_RATE, elementId);
  2466. };
  2467.  
  2468. Game_BattlerBase.prototype.debuffRate = function(paramId) {
  2469.     return this.traitsPi(Game_BattlerBase.TRAIT_DEBUFF_RATE, paramId);
  2470. };
  2471.  
  2472. Game_BattlerBase.prototype.stateRate = function(stateId) {
  2473.     return this.traitsPi(Game_BattlerBase.TRAIT_STATE_RATE, stateId);
  2474. };
  2475.  
  2476. Game_BattlerBase.prototype.stateResistSet = function() {
  2477.     return this.traitsSet(Game_BattlerBase.TRAIT_STATE_RESIST);
  2478. };
  2479.  
  2480. Game_BattlerBase.prototype.isStateResist = function(stateId) {
  2481.     return this.stateResistSet().contains(stateId);
  2482. };
  2483.  
  2484. Game_BattlerBase.prototype.attackElements = function() {
  2485.     return this.traitsSet(Game_BattlerBase.TRAIT_ATTACK_ELEMENT);
  2486. };
  2487.  
  2488. Game_BattlerBase.prototype.attackStates = function() {
  2489.     return this.traitsSet(Game_BattlerBase.TRAIT_ATTACK_STATE);
  2490. };
  2491.  
  2492. Game_BattlerBase.prototype.attackStatesRate = function(stateId) {
  2493.     return this.traitsSum(Game_BattlerBase.TRAIT_ATTACK_STATE, stateId);
  2494. };
  2495.  
  2496. Game_BattlerBase.prototype.attackSpeed = function() {
  2497.     return this.traitsSumAll(Game_BattlerBase.TRAIT_ATTACK_SPEED);
  2498. };
  2499.  
  2500. Game_BattlerBase.prototype.attackTimesAdd = function() {
  2501.     return Math.max(this.traitsSumAll(Game_BattlerBase.TRAIT_ATTACK_TIMES), 0);
  2502. };
  2503.  
  2504. Game_BattlerBase.prototype.addedSkillTypes = function() {
  2505.     return this.traitsSet(Game_BattlerBase.TRAIT_STYPE_ADD);
  2506. };
  2507.  
  2508. Game_BattlerBase.prototype.isSkillTypeSealed = function(stypeId) {
  2509.     return this.traitsSet(Game_BattlerBase.TRAIT_STYPE_SEAL).contains(stypeId);
  2510. };
  2511.  
  2512. Game_BattlerBase.prototype.addedSkills = function() {
  2513.     return this.traitsSet(Game_BattlerBase.TRAIT_SKILL_ADD);
  2514. };
  2515.  
  2516. Game_BattlerBase.prototype.isSkillSealed = function(skillId) {
  2517.     return this.traitsSet(Game_BattlerBase.TRAIT_SKILL_SEAL).contains(skillId);
  2518. };
  2519.  
  2520. Game_BattlerBase.prototype.isEquipWtypeOk = function(wtypeId) {
  2521.     return this.traitsSet(Game_BattlerBase.TRAIT_EQUIP_WTYPE).contains(wtypeId);
  2522. };
  2523.  
  2524. Game_BattlerBase.prototype.isEquipAtypeOk = function(atypeId) {
  2525.     return this.traitsSet(Game_BattlerBase.TRAIT_EQUIP_ATYPE).contains(atypeId);
  2526. };
  2527.  
  2528. Game_BattlerBase.prototype.isEquipTypeLocked = function(etypeId) {
  2529.     return this.traitsSet(Game_BattlerBase.TRAIT_EQUIP_LOCK).contains(etypeId);
  2530. };
  2531.  
  2532. Game_BattlerBase.prototype.isEquipTypeSealed = function(etypeId) {
  2533.     return this.traitsSet(Game_BattlerBase.TRAIT_EQUIP_SEAL).contains(etypeId);
  2534. };
  2535.  
  2536. Game_BattlerBase.prototype.slotType = function() {
  2537.     var set = this.traitsSet(Game_BattlerBase.TRAIT_SLOT_TYPE);
  2538.     return set.length > 0 ? Math.max.apply(null, set) : 0;
  2539. };
  2540.  
  2541. Game_BattlerBase.prototype.isDualWield = function() {
  2542.     return this.slotType() === 1;
  2543. };
  2544.  
  2545. Game_BattlerBase.prototype.actionPlusSet = function() {
  2546.     return this.traits(Game_BattlerBase.TRAIT_ACTION_PLUS).map(function(trait) {
  2547.         return trait.value;
  2548.     });
  2549. };
  2550.  
  2551. Game_BattlerBase.prototype.specialFlag = function(flagId) {
  2552.     return this.traits(Game_BattlerBase.TRAIT_SPECIAL_FLAG).some(function(trait) {
  2553.         return trait.dataId === flagId;
  2554.     });
  2555. };
  2556.  
  2557. Game_BattlerBase.prototype.collapseType = function() {
  2558.     var set = this.traitsSet(Game_BattlerBase.TRAIT_COLLAPSE_TYPE);
  2559.     return set.length > 0 ? Math.max.apply(null, set) : 0;
  2560. };
  2561.  
  2562. Game_BattlerBase.prototype.partyAbility = function(abilityId) {
  2563.     return this.traits(Game_BattlerBase.TRAIT_PARTY_ABILITY).some(function(trait) {
  2564.         return trait.dataId === abilityId;
  2565.     });
  2566. };
  2567.  
  2568. Game_BattlerBase.prototype.isAutoBattle = function() {
  2569.     return this.specialFlag(Game_BattlerBase.FLAG_ID_AUTO_BATTLE);
  2570. };
  2571.  
  2572. Game_BattlerBase.prototype.isGuard = function() {
  2573.     return this.specialFlag(Game_BattlerBase.FLAG_ID_GUARD) && this.canMove();
  2574. };
  2575.  
  2576. Game_BattlerBase.prototype.isSubstitute = function() {
  2577.     return this.specialFlag(Game_BattlerBase.FLAG_ID_SUBSTITUTE) && this.canMove();
  2578. };
  2579.  
  2580. Game_BattlerBase.prototype.isPreserveTp = function() {
  2581.     return this.specialFlag(Game_BattlerBase.FLAG_ID_PRESERVE_TP);
  2582. };
  2583.  
  2584. Game_BattlerBase.prototype.addParam = function(paramId, value) {
  2585.     this._paramPlus[paramId] += value;
  2586.     this.refresh();
  2587. };
  2588.  
  2589. Game_BattlerBase.prototype.setHp = function(hp) {
  2590.     this._hp = hp;
  2591.     this.refresh();
  2592. };
  2593.  
  2594. Game_BattlerBase.prototype.setMp = function(mp) {
  2595.     this._mp = mp;
  2596.     this.refresh();
  2597. };
  2598.  
  2599. Game_BattlerBase.prototype.setTp = function(tp) {
  2600.     this._tp = tp;
  2601.     this.refresh();
  2602. };
  2603.  
  2604. Game_BattlerBase.prototype.maxTp = function() {
  2605.     return 100;
  2606. };
  2607.  
  2608. Game_BattlerBase.prototype.refresh = function() {
  2609.     this.stateResistSet().forEach(function(stateId) {
  2610.         this.eraseState(stateId);
  2611.     }, this);
  2612.     this._hp = this._hp.clamp(0, this.mhp);
  2613.     this._mp = this._mp.clamp(0, this.mmp);
  2614.     this._tp = this._tp.clamp(0, this.maxTp());
  2615. };
  2616.  
  2617. Game_BattlerBase.prototype.recoverAll = function() {
  2618.     this.clearStates();
  2619.     this._hp = this.mhp;
  2620.     this._mp = this.mmp;
  2621. };
  2622.  
  2623. Game_BattlerBase.prototype.hpRate = function() {
  2624.     return this.hp / this.mhp;
  2625. };
  2626.  
  2627. Game_BattlerBase.prototype.mpRate = function() {
  2628.     return this.mmp > 0 ? this.mp / this.mmp : 0;
  2629. };
  2630.  
  2631. Game_BattlerBase.prototype.tpRate = function() {
  2632.     return this.tp / this.maxTp();
  2633. };
  2634.  
  2635. Game_BattlerBase.prototype.hide = function() {
  2636.     this._hidden = true;
  2637. };
  2638.  
  2639. Game_BattlerBase.prototype.appear = function() {
  2640.     this._hidden = false;
  2641. };
  2642.  
  2643. Game_BattlerBase.prototype.isHidden = function() {
  2644.     return this._hidden;
  2645. };
  2646.  
  2647. Game_BattlerBase.prototype.isAppeared = function() {
  2648.     return !this.isHidden();
  2649. };
  2650.  
  2651. Game_BattlerBase.prototype.isDead = function() {
  2652.     return this.isAppeared() && this.isDeathStateAffected();
  2653. };
  2654.  
  2655. Game_BattlerBase.prototype.isAlive = function() {
  2656.     return this.isAppeared() && !this.isDeathStateAffected();
  2657. };
  2658.  
  2659. Game_BattlerBase.prototype.isDying = function() {
  2660.     return this.isAlive() && this._hp < this.mhp / 4;
  2661. };
  2662.  
  2663. Game_BattlerBase.prototype.isRestricted = function() {
  2664.     return this.isAppeared() && this.restriction() > 0;
  2665. };
  2666.  
  2667. Game_BattlerBase.prototype.canInput = function() {
  2668.     return this.isAppeared() && !this.isRestricted() && !this.isAutoBattle();
  2669. };
  2670.  
  2671. Game_BattlerBase.prototype.canMove = function() {
  2672.     return this.isAppeared() && this.restriction() < 4;
  2673. };
  2674.  
  2675. Game_BattlerBase.prototype.isConfused = function() {
  2676.     return this.isAppeared() && this.restriction() >= 1 && this.restriction() <= 3;
  2677. };
  2678.  
  2679. Game_BattlerBase.prototype.confusionLevel = function() {
  2680.     return this.isConfused() ? this.restriction() : 0;
  2681. };
  2682.  
  2683. Game_BattlerBase.prototype.isActor = function() {
  2684.     return false;
  2685. };
  2686.  
  2687. Game_BattlerBase.prototype.isEnemy = function() {
  2688.     return false;
  2689. };
  2690.  
  2691. Game_BattlerBase.prototype.sortStates = function() {
  2692.     this._states.sort(function(a, b) {
  2693.         var p1 = $dataStates[a].priority;
  2694.         var p2 = $dataStates[b].priority;
  2695.         if (p1 !== p2) {
  2696.             return p2 - p1;
  2697.         }
  2698.         return a - b;
  2699.     });
  2700. };
  2701.  
  2702. Game_BattlerBase.prototype.restriction = function() {
  2703.     return Math.max.apply(null, this.states().map(function(state) {
  2704.         return state.restriction;
  2705.     }).concat(0));
  2706. };
  2707.  
  2708. Game_BattlerBase.prototype.addNewState = function(stateId) {
  2709.     if (stateId === this.deathStateId()) {
  2710.         this.die();
  2711.     }
  2712.     var restricted = this.isRestricted();
  2713.     this._states.push(stateId);
  2714.     this.sortStates();
  2715.     if (!restricted && this.isRestricted()) {
  2716.         this.onRestrict();
  2717.     }
  2718. };
  2719.  
  2720. Game_BattlerBase.prototype.onRestrict = function() {
  2721. };
  2722.  
  2723. Game_BattlerBase.prototype.mostImportantStateText = function() {
  2724.     var states = this.states();
  2725.     for (var i = 0; i < states.length; i++) {
  2726.         if (states[i].message3) {
  2727.             return states[i].message3;
  2728.         }
  2729.     }
  2730.     return '';
  2731. };
  2732.  
  2733. Game_BattlerBase.prototype.stateMotionIndex = function() {
  2734.     var states = this.states();
  2735.     if (states.length > 0) {
  2736.         return states[0].motion;
  2737.     } else {
  2738.         return 0;
  2739.     }
  2740. };
  2741.  
  2742. Game_BattlerBase.prototype.stateOverlayIndex = function() {
  2743.     var states = this.states();
  2744.     if (states.length > 0) {
  2745.         return states[0].overlay;
  2746.     } else {
  2747.         return 0;
  2748.     }
  2749. };
  2750.  
  2751. Game_BattlerBase.prototype.isSkillWtypeOk = function(skill) {
  2752.     return true;
  2753. };
  2754.  
  2755. Game_BattlerBase.prototype.skillMpCost = function(skill) {
  2756.     return Math.floor(skill.mpCost * this.mcr);
  2757. };
  2758.  
  2759. Game_BattlerBase.prototype.skillTpCost = function(skill) {
  2760.     return skill.tpCost;
  2761. };
  2762.  
  2763. Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
  2764.     return this._tp >= this.skillTpCost(skill) && this._mp >= this.skillMpCost(skill);
  2765. };
  2766.  
  2767. Game_BattlerBase.prototype.paySkillCost = function(skill) {
  2768.     this._mp -= this.skillMpCost(skill);
  2769.     this._tp -= this.skillTpCost(skill);
  2770. };
  2771.  
  2772. Game_BattlerBase.prototype.isOccasionOk = function(item) {
  2773.     if ($gameParty.inBattle()) {
  2774.         return item.occasion === 0 || item.occasion === 1;
  2775.     } else {
  2776.         return item.occasion === 0 || item.occasion === 2;
  2777.     }
  2778. };
  2779.  
  2780. Game_BattlerBase.prototype.meetsUsableItemConditions = function(item) {
  2781.     return this.canMove() && this.isOccasionOk(item);
  2782. };
  2783.  
  2784. Game_BattlerBase.prototype.meetsSkillConditions = function(skill) {
  2785.     return (this.meetsUsableItemConditions(skill) &&
  2786.             this.isSkillWtypeOk(skill) && this.canPaySkillCost(skill) &&
  2787.             !this.isSkillSealed(skill.id) && !this.isSkillTypeSealed(skill.stypeId));
  2788. };
  2789.  
  2790. Game_BattlerBase.prototype.meetsItemConditions = function(item) {
  2791.     return this.meetsUsableItemConditions(item) && $gameParty.hasItem(item);
  2792. };
  2793.  
  2794. Game_BattlerBase.prototype.canUse = function(item) {
  2795.     if (!item) {
  2796.         return false;
  2797.     } else if (DataManager.isSkill(item)) {
  2798.         return this.meetsSkillConditions(item);
  2799.     } else if (DataManager.isItem(item)) {
  2800.         return this.meetsItemConditions(item);
  2801.     } else {
  2802.         return false;
  2803.     }
  2804. };
  2805.  
  2806. Game_BattlerBase.prototype.canEquip = function(item) {
  2807.     if (!item) {
  2808.         return false;
  2809.     } else if (DataManager.isWeapon(item)) {
  2810.         return this.canEquipWeapon(item);
  2811.     } else if (DataManager.isArmor(item)) {
  2812.         return this.canEquipArmor(item);
  2813.     } else {
  2814.         return false;
  2815.     }
  2816. };
  2817.  
  2818. Game_BattlerBase.prototype.canEquipWeapon = function(item) {
  2819.     return this.isEquipWtypeOk(item.wtypeId) && !this.isEquipTypeSealed(item.etypeId);
  2820. };
  2821.  
  2822. Game_BattlerBase.prototype.canEquipArmor = function(item) {
  2823.     return this.isEquipAtypeOk(item.atypeId) && !this.isEquipTypeSealed(item.etypeId);
  2824. };
  2825.  
  2826. Game_BattlerBase.prototype.attackSkillId = function() {
  2827.     return 1;
  2828. };
  2829.  
  2830. Game_BattlerBase.prototype.guardSkillId = function() {
  2831.     return 2;
  2832. };
  2833.  
  2834. Game_BattlerBase.prototype.canAttack = function() {
  2835.     return this.canUse($dataSkills[this.attackSkillId()]);
  2836. };
  2837.  
  2838. Game_BattlerBase.prototype.canGuard = function() {
  2839.     return this.canUse($dataSkills[this.guardSkillId()]);
  2840. };
  2841.  
  2842. //-----------------------------------------------------------------------------
  2843. // Game_Battler
  2844. //
  2845. // The superclass of Game_Actor and Game_Enemy. It contains methods for sprites
  2846. // and actions.
  2847.  
  2848. function Game_Battler() {
  2849.     this.initialize.apply(this, arguments);
  2850. }
  2851.  
  2852. Game_Battler.prototype = Object.create(Game_BattlerBase.prototype);
  2853. Game_Battler.prototype.constructor = Game_Battler;
  2854.  
  2855. Game_Battler.prototype.initialize = function() {
  2856.     Game_BattlerBase.prototype.initialize.call(this);
  2857. };
  2858.  
  2859. Game_Battler.prototype.initMembers = function() {
  2860.     Game_BattlerBase.prototype.initMembers.call(this);
  2861.     this._actions = [];
  2862.     this._speed = 0;
  2863.     this._result = new Game_ActionResult();
  2864.     this._actionState = '';
  2865.     this._lastTargetIndex = 0;
  2866.     this._animations = [];
  2867.     this._damagePopup = false;
  2868.     this._effectType = null;
  2869.     this._motionType = null;
  2870.     this._weaponImageId = 0;
  2871.     this._motionRefresh = false;
  2872.     this._selected = false;
  2873. };
  2874.  
  2875. Game_Battler.prototype.clearAnimations = function() {
  2876.     this._animations = [];
  2877. };
  2878.  
  2879. Game_Battler.prototype.clearDamagePopup = function() {
  2880.     this._damagePopup = false;
  2881. };
  2882.  
  2883. Game_Battler.prototype.clearWeaponAnimation = function() {
  2884.     this._weaponImageId = 0;
  2885. };
  2886.  
  2887. Game_Battler.prototype.clearEffect = function() {
  2888.     this._effectType = null;
  2889. };
  2890.  
  2891. Game_Battler.prototype.clearMotion = function() {
  2892.     this._motionType = null;
  2893.     this._motionRefresh = false;
  2894. };
  2895.  
  2896. Game_Battler.prototype.requestEffect = function(effectType) {
  2897.     this._effectType = effectType;
  2898. };
  2899.  
  2900. Game_Battler.prototype.requestMotion = function(motionType) {
  2901.     this._motionType = motionType;
  2902. };
  2903.  
  2904. Game_Battler.prototype.requestMotionRefresh = function() {
  2905.     this._motionRefresh = true;
  2906. };
  2907.  
  2908. Game_Battler.prototype.select = function() {
  2909.     this._selected = true;
  2910. };
  2911.  
  2912. Game_Battler.prototype.deselect = function() {
  2913.     this._selected = false;
  2914. };
  2915.  
  2916. Game_Battler.prototype.isAnimationRequested = function() {
  2917.     return this._animations.length > 0;
  2918. };
  2919.  
  2920. Game_Battler.prototype.isDamagePopupRequested = function() {
  2921.     return this._damagePopup;
  2922. };
  2923.  
  2924. Game_Battler.prototype.isEffectRequested = function() {
  2925.     return !!this._effectType;
  2926. };
  2927.  
  2928. Game_Battler.prototype.isMotionRequested = function() {
  2929.     return !!this._motionType;
  2930. };
  2931.  
  2932. Game_Battler.prototype.isWeaponAnimationRequested = function() {
  2933.     return this._weaponImageId > 0;
  2934. };
  2935.  
  2936. Game_Battler.prototype.isMotionRefreshRequested = function() {
  2937.     return this._motionRefresh;
  2938. };
  2939.  
  2940. Game_Battler.prototype.isSelected = function() {
  2941.     return this._selected;
  2942. };
  2943.  
  2944. Game_Battler.prototype.effectType = function() {
  2945.     return this._effectType;
  2946. };
  2947.  
  2948. Game_Battler.prototype.motionType = function() {
  2949.     return this._motionType;
  2950. };
  2951.  
  2952. Game_Battler.prototype.weaponImageId = function() {
  2953.     return this._weaponImageId;
  2954. };
  2955.  
  2956. Game_Battler.prototype.shiftAnimation = function() {
  2957.     return this._animations.shift();
  2958. };
  2959.  
  2960. Game_Battler.prototype.startAnimation = function(animationId, mirror, delay) {
  2961.     var data = { animationId: animationId, mirror: mirror, delay: delay };
  2962.     this._animations.push(data);
  2963. };
  2964.  
  2965. Game_Battler.prototype.startDamagePopup = function() {
  2966.     this._damagePopup = true;
  2967. };
  2968.  
  2969. Game_Battler.prototype.startWeaponAnimation = function(weaponImageId) {
  2970.     this._weaponImageId = weaponImageId;
  2971. };
  2972.  
  2973. Game_Battler.prototype.action = function(index) {
  2974.     return this._actions[index];
  2975. };
  2976.  
  2977. Game_Battler.prototype.setAction = function(index, action) {
  2978.     this._actions[index] = action;
  2979. };
  2980.  
  2981. Game_Battler.prototype.numActions = function() {
  2982.     return this._actions.length;
  2983. };
  2984.  
  2985. Game_Battler.prototype.clearActions = function() {
  2986.     this._actions = [];
  2987. };
  2988.  
  2989. Game_Battler.prototype.result = function() {
  2990.     return this._result;
  2991. };
  2992.  
  2993. Game_Battler.prototype.clearResult = function() {
  2994.     this._result.clear();
  2995. };
  2996.  
  2997. Game_Battler.prototype.refresh = function() {
  2998.     Game_BattlerBase.prototype.refresh.call(this);
  2999.     if (this.hp === 0) {
  3000.         this.addState(this.deathStateId());
  3001.     } else {
  3002.         this.removeState(this.deathStateId());
  3003.     }
  3004. };
  3005.  
  3006. Game_Battler.prototype.addState = function(stateId) {
  3007.     if (this.isStateAddable(stateId)) {
  3008.         if (!this.isStateAffected(stateId)) {
  3009.             this.addNewState(stateId);
  3010.             this.refresh();
  3011.         }
  3012.         this.resetStateCounts(stateId);
  3013.         this._result.pushAddedState(stateId);
  3014.     }
  3015. };
  3016.  
  3017. Game_Battler.prototype.isStateAddable = function(stateId) {
  3018.     return (this.isAlive() && $dataStates[stateId] &&
  3019.             !this.isStateResist(stateId) &&
  3020.             !this._result.isStateRemoved(stateId) &&
  3021.             !this.isStateRestrict(stateId));
  3022. };
  3023.  
  3024. Game_Battler.prototype.isStateRestrict = function(stateId) {
  3025.     return $dataStates[stateId].removeByRestriction && this.isRestricted();
  3026. };
  3027.  
  3028. Game_Battler.prototype.onRestrict = function() {
  3029.     Game_BattlerBase.prototype.onRestrict.call(this);
  3030.     this.clearActions();
  3031.     this.states().forEach(function(state) {
  3032.         if (state.removeByRestriction) {
  3033.             this.removeState(state.id);
  3034.         }
  3035.     }, this);
  3036. };
  3037.  
  3038. Game_Battler.prototype.removeState = function(stateId) {
  3039.     if (this.isStateAffected(stateId)) {
  3040.         if (stateId === this.deathStateId()) {
  3041.             this.revive();
  3042.         }
  3043.         this.eraseState(stateId);
  3044.         this.refresh();
  3045.         this._result.pushRemovedState(stateId);
  3046.     }
  3047. };
  3048.  
  3049. Game_Battler.prototype.escape = function() {
  3050.     if ($gameParty.inBattle()) {
  3051.         this.hide();
  3052.     }
  3053.     this.clearActions();
  3054.     this.clearStates();
  3055.     SoundManager.playEscape();
  3056. };
  3057.  
  3058. Game_Battler.prototype.addBuff = function(paramId, turns) {
  3059.     if (this.isAlive()) {
  3060.         this.increaseBuff(paramId);
  3061.         if (this.isBuffAffected(paramId)) {
  3062.             this.overwriteBuffTurns(paramId, turns);
  3063.         }
  3064.         this._result.pushAddedBuff(paramId);
  3065.         this.refresh();
  3066.     }
  3067. };
  3068.  
  3069. Game_Battler.prototype.addDebuff = function(paramId, turns) {
  3070.     if (this.isAlive()) {
  3071.         this.decreaseBuff(paramId);
  3072.         if (this.isDebuffAffected(paramId)) {
  3073.             this.overwriteBuffTurns(paramId, turns);
  3074.         }
  3075.         this._result.pushAddedDebuff(paramId);
  3076.         this.refresh();
  3077.     }
  3078. };
  3079.  
  3080. Game_Battler.prototype.removeBuff = function(paramId) {
  3081.     if (this.isAlive() && this.isBuffOrDebuffAffected(paramId)) {
  3082.         this.eraseBuff(paramId);
  3083.         this._result.pushRemovedBuff(paramId);
  3084.         this.refresh();
  3085.     }
  3086. };
  3087.  
  3088. Game_Battler.prototype.removeBattleStates = function() {
  3089.     this.states().forEach(function(state) {
  3090.         if (state.removeAtBattleEnd) {
  3091.             this.removeState(state.id);
  3092.         }
  3093.     }, this);
  3094. };
  3095.  
  3096. Game_Battler.prototype.removeAllBuffs = function() {
  3097.     for (var i = 0; i < this.buffLength(); i++) {
  3098.         this.removeBuff(i);
  3099.     }
  3100. };
  3101.  
  3102. Game_Battler.prototype.removeStatesAuto = function(timing) {
  3103.     this.states().forEach(function(state) {
  3104.         if (this.isStateExpired(state.id) && state.autoRemovalTiming === timing) {
  3105.             this.removeState(state.id);
  3106.         }
  3107.     }, this);
  3108. };
  3109.  
  3110. Game_Battler.prototype.removeBuffsAuto = function() {
  3111.     for (var i = 0; i < this.buffLength(); i++) {
  3112.         if (this.isBuffExpired(i)) {
  3113.             this.removeBuff(i);
  3114.         }
  3115.     }
  3116. };
  3117.  
  3118. Game_Battler.prototype.removeStatesByDamage = function() {
  3119.     this.states().forEach(function(state) {
  3120.         if (state.removeByDamage && Math.randomInt(100) < state.chanceByDamage) {
  3121.             this.removeState(state.id);
  3122.         }
  3123.     }, this);
  3124. };
  3125.  
  3126. Game_Battler.prototype.makeActionTimes = function() {
  3127.     return this.actionPlusSet().reduce(function(r, p) {
  3128.         return Math.random() < p ? r + 1 : r;
  3129.     }, 1);
  3130. };
  3131.  
  3132. Game_Battler.prototype.makeActions = function() {
  3133.     this.clearActions();
  3134.     if (this.canMove()) {
  3135.         var actionTimes = this.makeActionTimes();
  3136.         this._actions = [];
  3137.         for (var i = 0; i < actionTimes; i++) {
  3138.             this._actions.push(new Game_Action(this));
  3139.         }
  3140.     }
  3141. };
  3142.  
  3143. Game_Battler.prototype.speed = function() {
  3144.     return this._speed;
  3145. };
  3146.  
  3147. Game_Battler.prototype.makeSpeed = function() {
  3148.     this._speed = Math.min.apply(null, this._actions.map(function(action) {
  3149.         return action.speed();
  3150.     })) || 0;
  3151. };
  3152.  
  3153. Game_Battler.prototype.currentAction = function() {
  3154.     return this._actions[0];
  3155. };
  3156.  
  3157. Game_Battler.prototype.removeCurrentAction = function() {
  3158.     this._actions.shift();
  3159. };
  3160.  
  3161. Game_Battler.prototype.setLastTarget = function(target) {
  3162.     if (target) {
  3163.         this._lastTargetIndex = target.index();
  3164.     } else {
  3165.         this._lastTargetIndex = 0;
  3166.     }
  3167. };
  3168.  
  3169. Game_Battler.prototype.forceAction = function(skillId, targetIndex) {
  3170.     this.clearActions();
  3171.     var action = new Game_Action(this, true);
  3172.     action.setSkill(skillId);
  3173.     if (targetIndex === -2) {
  3174.         action.setTarget(this._lastTargetIndex);
  3175.     } else if (targetIndex === -1) {
  3176.         action.decideRandomTarget();
  3177.     } else {
  3178.         action.setTarget(targetIndex);
  3179.     }
  3180.     if (action._targetIndex >= 0) this._actions.push(action);
  3181. };
  3182.  
  3183. Game_Battler.prototype.useItem = function(item) {
  3184.     if (DataManager.isSkill(item)) {
  3185.         this.paySkillCost(item);
  3186.     } else if (DataManager.isItem(item)) {
  3187.         this.consumeItem(item);
  3188.     }
  3189. };
  3190.  
  3191. Game_Battler.prototype.consumeItem = function(item) {
  3192.     $gameParty.consumeItem(item);
  3193. };
  3194.  
  3195. Game_Battler.prototype.gainHp = function(value) {
  3196.     this._result.hpDamage = -value;
  3197.     this._result.hpAffected = true;
  3198.     this.setHp(this.hp + value);
  3199. };
  3200.  
  3201. Game_Battler.prototype.gainMp = function(value) {
  3202.     this._result.mpDamage = -value;
  3203.     this.setMp(this.mp + value);
  3204. };
  3205.  
  3206. Game_Battler.prototype.gainTp = function(value) {
  3207.     this._result.tpDamage = -value;
  3208.     this.setTp(this.tp + value);
  3209. };
  3210.  
  3211. Game_Battler.prototype.gainSilentTp = function(value) {
  3212.     this.setTp(this.tp + value);
  3213. };
  3214.  
  3215. Game_Battler.prototype.initTp = function() {
  3216.     this.setTp(Math.randomInt(25));
  3217. };
  3218.  
  3219. Game_Battler.prototype.clearTp = function() {
  3220.     this.setTp(0);
  3221. };
  3222.  
  3223. Game_Battler.prototype.chargeTpByDamage = function(damageRate) {
  3224.     var value = Math.floor(50 * damageRate * this.tcr);
  3225.     this.gainSilentTp(value);
  3226. };
  3227.  
  3228. Game_Battler.prototype.regenerateHp = function() {
  3229.     var value = Math.floor(this.mhp * this.hrg);
  3230.     value = Math.max(value, -this.maxSlipDamage());
  3231.     if (value !== 0) {
  3232.         this.gainHp(value);
  3233.     }
  3234. };
  3235.  
  3236. Game_Battler.prototype.maxSlipDamage = function() {
  3237.     return $dataSystem.optSlipDeath ? this.hp : Math.max(this.hp - 1, 0);
  3238. };
  3239.  
  3240. Game_Battler.prototype.regenerateMp = function() {
  3241.     var value = Math.floor(this.mmp * this.mrg);
  3242.     if (value !== 0) {
  3243.         this.gainMp(value);
  3244.     }
  3245. };
  3246.  
  3247. Game_Battler.prototype.regenerateTp = function() {
  3248.     var value = Math.floor(100 * this.trg);
  3249.     this.gainSilentTp(value);
  3250. };
  3251.  
  3252. Game_Battler.prototype.regenerateAll = function() {
  3253.     if (this.isAlive()) {
  3254.         this.regenerateHp();
  3255.         this.regenerateMp();
  3256.         this.regenerateTp();
  3257.     }
  3258. };
  3259.  
  3260. Game_Battler.prototype.onBattleStart = function() {
  3261.     this.setActionState('undecided');
  3262.     this.clearMotion();
  3263.     if (!this.isPreserveTp()) {
  3264.         this.initTp();
  3265.     }
  3266. };
  3267.  
  3268. Game_Battler.prototype.onAllActionsEnd = function() {
  3269.     this.clearResult();
  3270.     this.removeStatesAuto(1);
  3271.     this.removeBuffsAuto();
  3272. };
  3273.  
  3274. Game_Battler.prototype.onTurnEnd = function() {
  3275.     this.clearResult();
  3276.     this.regenerateAll();
  3277.     this.updateStateTurns();
  3278.     this.updateBuffTurns();
  3279.     this.removeStatesAuto(2);
  3280. };
  3281.  
  3282. Game_Battler.prototype.onBattleEnd = function() {
  3283.     this.clearResult();
  3284.     this.removeBattleStates();
  3285.     this.removeAllBuffs();
  3286.     this.clearActions();
  3287.     if (!this.isPreserveTp()) {
  3288.         this.clearTp();
  3289.     }
  3290.     this.appear();
  3291. };
  3292.  
  3293. Game_Battler.prototype.onDamage = function(value) {
  3294.     this.removeStatesByDamage();
  3295.     this.chargeTpByDamage(value / this.mhp);
  3296. };
  3297.  
  3298. Game_Battler.prototype.setActionState = function(actionState) {
  3299.     this._actionState = actionState;
  3300.     this.requestMotionRefresh();
  3301. };
  3302.  
  3303. Game_Battler.prototype.isUndecided = function() {
  3304.     return this._actionState === 'undecided';
  3305. };
  3306.  
  3307. Game_Battler.prototype.isInputting = function() {
  3308.     return this._actionState === 'inputting';
  3309. };
  3310.  
  3311. Game_Battler.prototype.isWaiting = function() {
  3312.     return this._actionState === 'waiting';
  3313. };
  3314.  
  3315. Game_Battler.prototype.isActing = function() {
  3316.     return this._actionState === 'acting';
  3317. };
  3318.  
  3319. Game_Battler.prototype.isChanting = function() {
  3320.     if (this.isWaiting()) {
  3321.         return this._actions.some(function(action) {
  3322.             return action.isMagicSkill();
  3323.         });
  3324.     }
  3325.     return false;
  3326. };
  3327.  
  3328. Game_Battler.prototype.isGuardWaiting = function() {
  3329.     if (this.isWaiting()) {
  3330.         return this._actions.some(function(action) {
  3331.             return action.isGuard();
  3332.         });
  3333.     }
  3334.     return false;
  3335. };
  3336.  
  3337. Game_Battler.prototype.performActionStart = function(action) {
  3338.     if (!action.isGuard()) {
  3339.         this.setActionState('acting');
  3340.     }
  3341. };
  3342.  
  3343. Game_Battler.prototype.performAction = function(action) {
  3344. };
  3345.  
  3346. Game_Battler.prototype.performActionEnd = function() {
  3347.     this.setActionState('done');
  3348. };
  3349.  
  3350. Game_Battler.prototype.performDamage = function() {
  3351. };
  3352.  
  3353. Game_Battler.prototype.performMiss = function() {
  3354.     SoundManager.playMiss();
  3355. };
  3356.  
  3357. Game_Battler.prototype.performRecovery = function() {
  3358.     SoundManager.playRecovery();
  3359. };
  3360.  
  3361. Game_Battler.prototype.performEvasion = function() {
  3362.     SoundManager.playEvasion();
  3363. };
  3364.  
  3365. Game_Battler.prototype.performMagicEvasion = function() {
  3366.     SoundManager.playMagicEvasion();
  3367. };
  3368.  
  3369. Game_Battler.prototype.performCounter = function() {
  3370.     SoundManager.playEvasion();
  3371. };
  3372.  
  3373. Game_Battler.prototype.performReflection = function() {
  3374.     SoundManager.playReflection();
  3375. };
  3376.  
  3377. Game_Battler.prototype.performSubstitute = function(target) {
  3378. };
  3379.  
  3380. Game_Battler.prototype.performCollapse = function() {
  3381. };
  3382.  
  3383. //-----------------------------------------------------------------------------
  3384. // Game_Actor
  3385. //
  3386. // The game object class for an actor.
  3387.  
  3388. function Game_Actor() {
  3389.     this.initialize.apply(this, arguments);
  3390. }
  3391.  
  3392. Game_Actor.prototype = Object.create(Game_Battler.prototype);
  3393. Game_Actor.prototype.constructor = Game_Actor;
  3394.  
  3395. Object.defineProperty(Game_Actor.prototype, 'level', {
  3396.     get: function() {
  3397.         return this._level;
  3398.     },
  3399.     configurable: true
  3400. });
  3401.  
  3402. Game_Actor.prototype.initialize = function(actorId) {
  3403.     Game_Battler.prototype.initialize.call(this);
  3404.     this.setup(actorId);
  3405. };
  3406.  
  3407. Game_Actor.prototype.initMembers = function() {
  3408.     Game_Battler.prototype.initMembers.call(this);
  3409.     this._actorId = 0;
  3410.     this._name = '';
  3411.     this._nickname = '';
  3412.     this._classId = 0;
  3413.     this._level = 0;
  3414.     this._characterName = '';
  3415.     this._characterIndex = 0;
  3416.     this._faceName = '';
  3417.     this._faceIndex = 0;
  3418.     this._battlerName = '';
  3419.     this._exp = {};
  3420.     this._skills = [];
  3421.     this._equips = [];
  3422.     this._actionInputIndex = 0;
  3423.     this._lastMenuSkill = new Game_Item();
  3424.     this._lastBattleSkill  = new Game_Item();
  3425.     this._lastCommandSymbol = '';
  3426. };
  3427.  
  3428. Game_Actor.prototype.setup = function(actorId) {
  3429.     var actor = $dataActors[actorId];
  3430.     this._actorId = actorId;
  3431.     this._name = actor.name;
  3432.     this._nickname = actor.nickname;
  3433.     this._profile = actor.profile;
  3434.     this._classId = actor.classId;
  3435.     this._level = actor.initialLevel;
  3436.     this.initImages();
  3437.     this.initExp();
  3438.     this.initSkills();
  3439.     this.initEquips(actor.equips);
  3440.     this.clearParamPlus();
  3441.     this.recoverAll();
  3442. };
  3443.  
  3444. Game_Actor.prototype.actorId = function() {
  3445.     return this._actorId;
  3446. };
  3447.  
  3448. Game_Actor.prototype.actor = function() {
  3449.     return $dataActors[this._actorId];
  3450. };
  3451.  
  3452. Game_Actor.prototype.name = function() {
  3453.     return this._name;
  3454. };
  3455.  
  3456. Game_Actor.prototype.setName = function(name) {
  3457.     this._name = name;
  3458. };
  3459.  
  3460. Game_Actor.prototype.nickname = function() {
  3461.     return this._nickname;
  3462. };
  3463.  
  3464. Game_Actor.prototype.setNickname = function(nickname) {
  3465.     this._nickname = nickname;
  3466. };
  3467.  
  3468. Game_Actor.prototype.profile = function() {
  3469.     return this._profile;
  3470. };
  3471.  
  3472. Game_Actor.prototype.setProfile = function(profile) {
  3473.     this._profile = profile;
  3474. };
  3475.  
  3476. Game_Actor.prototype.characterName = function() {
  3477.     return this._characterName;
  3478. };
  3479.  
  3480. Game_Actor.prototype.characterIndex = function() {
  3481.     return this._characterIndex;
  3482. };
  3483.  
  3484. Game_Actor.prototype.faceName = function() {
  3485.     return this._faceName;
  3486. };
  3487.  
  3488. Game_Actor.prototype.faceIndex = function() {
  3489.     return this._faceIndex;
  3490. };
  3491.  
  3492. Game_Actor.prototype.battlerName = function() {
  3493.     return this._battlerName;
  3494. };
  3495.  
  3496. Game_Actor.prototype.clearStates = function() {
  3497.     Game_Battler.prototype.clearStates.call(this);
  3498.     this._stateSteps = {};
  3499. };
  3500.  
  3501. Game_Actor.prototype.eraseState = function(stateId) {
  3502.     Game_Battler.prototype.eraseState.call(this, stateId);
  3503.     delete this._stateSteps[stateId];
  3504. };
  3505.  
  3506. Game_Actor.prototype.resetStateCounts = function(stateId) {
  3507.     Game_Battler.prototype.resetStateCounts.call(this, stateId);
  3508.     this._stateSteps[stateId] = $dataStates[stateId].stepsToRemove;
  3509. };
  3510.  
  3511. Game_Actor.prototype.initImages = function() {
  3512.     var actor = this.actor();
  3513.     this._characterName = actor.characterName;
  3514.     this._characterIndex = actor.characterIndex;
  3515.     this._faceName = actor.faceName;
  3516.     this._faceIndex = actor.faceIndex;
  3517.     this._battlerName = actor.battlerName;
  3518. };
  3519.  
  3520. Game_Actor.prototype.expForLevel = function(level) {
  3521.     var c = this.currentClass();
  3522.     var basis = c.expParams[0];
  3523.     var extra = c.expParams[1];
  3524.     var acc_a = c.expParams[2];
  3525.     var acc_b = c.expParams[3];
  3526.     return Math.round(basis*(Math.pow(level-1, 0.9+acc_a/250))*level*
  3527.             (level+1)/(6+Math.pow(level,2)/50/acc_b)+(level-1)*extra);
  3528. };
  3529.  
  3530. Game_Actor.prototype.initExp = function() {
  3531.     this._exp[this._classId] = this.currentLevelExp();
  3532. };
  3533.  
  3534. Game_Actor.prototype.currentExp = function() {
  3535.     return this._exp[this._classId];
  3536. };
  3537.  
  3538. Game_Actor.prototype.currentLevelExp = function() {
  3539.     return this.expForLevel(this._level);
  3540. };
  3541.  
  3542. Game_Actor.prototype.nextLevelExp = function() {
  3543.     return this.expForLevel(this._level + 1);
  3544. };
  3545.  
  3546. Game_Actor.prototype.nextRequiredExp = function() {
  3547.     return this.nextLevelExp() - this.currentExp();
  3548. };
  3549.  
  3550. Game_Actor.prototype.maxLevel = function() {
  3551.     return this.actor().maxLevel;
  3552. };
  3553.  
  3554. Game_Actor.prototype.isMaxLevel = function() {
  3555.     return this._level >= this.maxLevel();
  3556. };
  3557.  
  3558. Game_Actor.prototype.initSkills = function() {
  3559.     this._skills = [];
  3560.     this.currentClass().learnings.forEach(function(learning) {
  3561.         if (learning.level <= this._level) {
  3562.             this.learnSkill(learning.skillId);
  3563.         }
  3564.     }, this);
  3565. };
  3566.  
  3567. Game_Actor.prototype.initEquips = function(equips) {
  3568.     var slots = this.equipSlots();
  3569.     var maxSlots = slots.length;
  3570.     this._equips = [];
  3571.     for (var i = 0; i < maxSlots; i++) {
  3572.         this._equips[i] = new Game_Item();
  3573.     }
  3574.     for (var j = 0; j < equips.length; j++) {
  3575.         if (j < maxSlots) {
  3576.             this._equips[j].setEquip(slots[j] === 1, equips[j]);
  3577.         }
  3578.     }
  3579.     this.releaseUnequippableItems(true);
  3580.     this.refresh();
  3581. };
  3582.  
  3583. Game_Actor.prototype.equipSlots = function() {
  3584.     var slots = [];
  3585.     for (var i = 1; i < $dataSystem.equipTypes.length; i++) {
  3586.         slots.push(i);
  3587.     }
  3588.     if (slots.length >= 2 && this.isDualWield()) {
  3589.         slots[1] = 1;
  3590.     }
  3591.     return slots;
  3592. };
  3593.  
  3594. Game_Actor.prototype.equips = function() {
  3595.     return this._equips.map(function(item) {
  3596.         return item.object();
  3597.     });
  3598. };
  3599.  
  3600. Game_Actor.prototype.weapons = function() {
  3601.     return this.equips().filter(function(item) {
  3602.         return item && DataManager.isWeapon(item);
  3603.     });
  3604. };
  3605.  
  3606. Game_Actor.prototype.armors = function() {
  3607.     return this.equips().filter(function(item) {
  3608.         return item && DataManager.isArmor(item);
  3609.     });
  3610. };
  3611.  
  3612. Game_Actor.prototype.hasWeapon = function(weapon) {
  3613.     return this.weapons().contains(weapon);
  3614. };
  3615.  
  3616. Game_Actor.prototype.hasArmor = function(armor) {
  3617.     return this.armors().contains(armor);
  3618. };
  3619.  
  3620. Game_Actor.prototype.isEquipChangeOk = function(slotId) {
  3621.     return (!this.isEquipTypeLocked(this.equipSlots()[slotId]) &&
  3622.             !this.isEquipTypeSealed(this.equipSlots()[slotId]));
  3623. };
  3624.  
  3625. Game_Actor.prototype.changeEquip = function(slotId, item) {
  3626.     if (this.tradeItemWithParty(item, this.equips()[slotId]) &&
  3627.             (!item || this.equipSlots()[slotId] === item.etypeId)) {
  3628.         this._equips[slotId].setObject(item);
  3629.         this.refresh();
  3630.     }
  3631. };
  3632.  
  3633. Game_Actor.prototype.forceChangeEquip = function(slotId, item) {
  3634.     this._equips[slotId].setObject(item);
  3635.     this.releaseUnequippableItems(true);
  3636.     this.refresh();
  3637. };
  3638.  
  3639. Game_Actor.prototype.tradeItemWithParty = function(newItem, oldItem) {
  3640.     if (newItem && !$gameParty.hasItem(newItem)) {
  3641.         return false;
  3642.     } else {
  3643.         $gameParty.gainItem(oldItem, 1);
  3644.         $gameParty.loseItem(newItem, 1);
  3645.         return true;
  3646.     }
  3647. };
  3648.  
  3649. Game_Actor.prototype.changeEquipById = function(etypeId, itemId) {
  3650.     var slotId = etypeId - 1;
  3651.     if (this.equipSlots()[slotId] === 1) {
  3652.         this.changeEquip(slotId, $dataWeapons[itemId]);
  3653.     } else {
  3654.         this.changeEquip(slotId, $dataArmors[itemId]);
  3655.     }
  3656. };
  3657.  
  3658. Game_Actor.prototype.isEquipped = function(item) {
  3659.     return this.equips().contains(item);
  3660. };
  3661.  
  3662. Game_Actor.prototype.discardEquip = function(item) {
  3663.     var slotId = this.equips().indexOf(item);
  3664.     if (slotId >= 0) {
  3665.         this._equips[slotId].setObject(null);
  3666.     }
  3667. };
  3668.  
  3669. Game_Actor.prototype.releaseUnequippableItems = function(forcing) {
  3670.     for (;;) {
  3671.         var slots = this.equipSlots();
  3672.         var equips = this.equips();
  3673.         var changed = false;
  3674.         for (var i = 0; i < equips.length; i++) {
  3675.             var item = equips[i];
  3676.             if (item && (!this.canEquip(item) || item.etypeId !== slots[i])) {
  3677.                 if (!forcing) {
  3678.                     this.tradeItemWithParty(null, item);
  3679.                 }
  3680.                 this._equips[i].setObject(null);
  3681.                 changed = true;
  3682.             }
  3683.         }
  3684.         if (!changed) {
  3685.             break;
  3686.         }
  3687.     }
  3688. };
  3689.  
  3690. Game_Actor.prototype.clearEquipments = function() {
  3691.     var maxSlots = this.equipSlots().length;
  3692.     for (var i = 0; i < maxSlots; i++) {
  3693.         if (this.isEquipChangeOk(i)) {
  3694.             this.changeEquip(i, null);
  3695.         }
  3696.     }
  3697. };
  3698.  
  3699. Game_Actor.prototype.optimizeEquipments = function() {
  3700.     var maxSlots = this.equipSlots().length;
  3701.     this.clearEquipments();
  3702.     for (var i = 0; i < maxSlots; i++) {
  3703.         if (this.isEquipChangeOk(i)) {
  3704.             this.changeEquip(i, this.bestEquipItem(i));
  3705.         }
  3706.     }
  3707. };
  3708.  
  3709. Game_Actor.prototype.bestEquipItem = function(slotId) {
  3710.     var etypeId = this.equipSlots()[slotId];
  3711.     var items = $gameParty.equipItems().filter(function(item) {
  3712.         return item.etypeId === etypeId && this.canEquip(item);
  3713.     }, this);
  3714.     var bestItem = null;
  3715.     var bestPerformance = -1000;
  3716.     for (var i = 0; i < items.length; i++) {
  3717.         var performance = this.calcEquipItemPerformance(items[i]);
  3718.         if (performance > bestPerformance) {
  3719.             bestPerformance = performance;
  3720.             bestItem = items[i];
  3721.         }
  3722.     }
  3723.     return bestItem;
  3724. };
  3725.  
  3726. Game_Actor.prototype.calcEquipItemPerformance = function(item) {
  3727.     return item.params.reduce(function(a, b) {
  3728.         return a + b;
  3729.     });
  3730. };
  3731.  
  3732. Game_Actor.prototype.isSkillWtypeOk = function(skill) {
  3733.     var wtypeId1 = skill.requiredWtypeId1;
  3734.     var wtypeId2 = skill.requiredWtypeId2;
  3735.     if ((wtypeId1 === 0 && wtypeId2 === 0) ||
  3736.             (wtypeId1 > 0 && this.isWtypeEquipped(wtypeId1)) ||
  3737.             (wtypeId2 > 0 && this.isWtypeEquipped(wtypeId2))) {
  3738.         return true;
  3739.     } else {
  3740.         return false;
  3741.     }
  3742. };
  3743.  
  3744. Game_Actor.prototype.isWtypeEquipped = function(wtypeId) {
  3745.     return this.weapons().some(function(weapon) {
  3746.         return weapon.wtypeId === wtypeId;
  3747.     });
  3748. };
  3749.  
  3750. Game_Actor.prototype.refresh = function() {
  3751.     this.releaseUnequippableItems(false);
  3752.     Game_Battler.prototype.refresh.call(this);
  3753. };
  3754.  
  3755. Game_Actor.prototype.isActor = function() {
  3756.     return true;
  3757. };
  3758.  
  3759. Game_Actor.prototype.friendsUnit = function() {
  3760.     return $gameParty;
  3761. };
  3762.  
  3763. Game_Actor.prototype.opponentsUnit = function() {
  3764.     return $gameTroop;
  3765. };
  3766.  
  3767. Game_Actor.prototype.index = function() {
  3768.     return $gameParty.members().indexOf(this);
  3769. };
  3770.  
  3771. Game_Actor.prototype.isBattleMember = function() {
  3772.     return $gameParty.battleMembers().contains(this);
  3773. };
  3774.  
  3775. Game_Actor.prototype.isFormationChangeOk = function() {
  3776.     return true;
  3777. };
  3778.  
  3779. Game_Actor.prototype.currentClass = function() {
  3780.     return $dataClasses[this._classId];
  3781. };
  3782.  
  3783. Game_Actor.prototype.isClass = function(gameClass) {
  3784.     return gameClass && this._classId === gameClass.id;
  3785. };
  3786.  
  3787. Game_Actor.prototype.skills = function() {
  3788.     var list = [];
  3789.     this._skills.concat(this.addedSkills()).forEach(function(id) {
  3790.         if (!list.contains($dataSkills[id])) {
  3791.             list.push($dataSkills[id]);
  3792.         }
  3793.     });
  3794.     return list;
  3795. };
  3796.  
  3797. Game_Actor.prototype.usableSkills = function() {
  3798.     return this.skills().filter(function(skill) {
  3799.         return this.canUse(skill);
  3800.     }, this);
  3801. };
  3802.  
  3803. Game_Actor.prototype.traitObjects = function() {
  3804.     var objects = Game_Battler.prototype.traitObjects.call(this);
  3805.     objects = objects.concat([this.actor(), this.currentClass()]);
  3806.     var equips = this.equips();
  3807.     for (var i = 0; i < equips.length; i++) {
  3808.         var item = equips[i];
  3809.         if (item) {
  3810.             objects.push(item);
  3811.         }
  3812.     }
  3813.     return objects;
  3814. };
  3815.  
  3816. Game_Actor.prototype.attackElements = function() {
  3817.     var set = Game_Battler.prototype.attackElements.call(this);
  3818.     if (this.hasNoWeapons() && !set.contains(this.bareHandsElementId())) {
  3819.         set.push(this.bareHandsElementId());
  3820.     }
  3821.     return set;
  3822. };
  3823.  
  3824. Game_Actor.prototype.hasNoWeapons = function() {
  3825.     return this.weapons().length === 0;
  3826. };
  3827.  
  3828. Game_Actor.prototype.bareHandsElementId = function() {
  3829.     return 1;
  3830. };
  3831.  
  3832. Game_Actor.prototype.paramMax = function(paramId) {
  3833.     if (paramId === 0) {
  3834.         return 9999;    // MHP
  3835.     }
  3836.     return Game_Battler.prototype.paramMax.call(this, paramId);
  3837. };
  3838.  
  3839. Game_Actor.prototype.paramBase = function(paramId) {
  3840.     return this.currentClass().params[paramId][this._level];
  3841. };
  3842.  
  3843. Game_Actor.prototype.paramPlus = function(paramId) {
  3844.     var value = Game_Battler.prototype.paramPlus.call(this, paramId);
  3845.     var equips = this.equips();
  3846.     for (var i = 0; i < equips.length; i++) {
  3847.         var item = equips[i];
  3848.         if (item) {
  3849.             value += item.params[paramId];
  3850.         }
  3851.     }
  3852.     return value;
  3853. };
  3854.  
  3855. Game_Actor.prototype.attackAnimationId1 = function() {
  3856.     if (this.hasNoWeapons()) {
  3857.         return this.bareHandsAnimationId();
  3858.     } else {
  3859.         var weapons = this.weapons();
  3860.         return weapons[0] ? weapons[0].animationId : 0;
  3861.     }
  3862. };
  3863.  
  3864. Game_Actor.prototype.attackAnimationId2 = function() {
  3865.     var weapons = this.weapons();
  3866.     return weapons[1] ? weapons[1].animationId : 0;
  3867. };
  3868.  
  3869. Game_Actor.prototype.bareHandsAnimationId = function() {
  3870.     return 1;
  3871. };
  3872.  
  3873. Game_Actor.prototype.changeExp = function(exp, show) {
  3874.     this._exp[this._classId] = Math.max(exp, 0);
  3875.     var lastLevel = this._level;
  3876.     var lastSkills = this.skills();
  3877.     while (!this.isMaxLevel() && this.currentExp() >= this.nextLevelExp()) {
  3878.         this.levelUp();
  3879.     }
  3880.     while (this.currentExp() < this.currentLevelExp()) {
  3881.         this.levelDown();
  3882.     }
  3883.     if (show && this._level > lastLevel) {
  3884.         this.displayLevelUp(this.findNewSkills(lastSkills));
  3885.     }
  3886.     this.refresh();
  3887. };
  3888.  
  3889. Game_Actor.prototype.levelUp = function() {
  3890.     this._level++;
  3891.     this.currentClass().learnings.forEach(function(learning) {
  3892.         if (learning.level === this._level) {
  3893.             this.learnSkill(learning.skillId);
  3894.         }
  3895.     }, this);
  3896. };
  3897.  
  3898. Game_Actor.prototype.levelDown = function() {
  3899.     this._level--;
  3900. };
  3901.  
  3902. Game_Actor.prototype.findNewSkills = function(lastSkills) {
  3903.     var newSkills = this.skills();
  3904.     for (var i = 0; i < lastSkills.length; i++) {
  3905.         var index = newSkills.indexOf(lastSkills[i]);
  3906.         if (index >= 0) {
  3907.             newSkills.splice(index, 1);
  3908.         }
  3909.     }
  3910.     return newSkills;
  3911. };
  3912.  
  3913. Game_Actor.prototype.displayLevelUp = function(newSkills) {
  3914.     var text = TextManager.levelUp.format(this._name, TextManager.level, this._level);
  3915.     $gameMessage.newPage();
  3916.     $gameMessage.add(text);
  3917.     newSkills.forEach(function(skill) {
  3918.         $gameMessage.add(TextManager.obtainSkill.format(skill.name));
  3919.     });
  3920. };
  3921.  
  3922. Game_Actor.prototype.gainExp = function(exp) {
  3923.     var newExp = this.currentExp() + Math.round(exp * this.finalExpRate());
  3924.     this.changeExp(newExp, this.shouldDisplayLevelUp());
  3925. };
  3926.  
  3927. Game_Actor.prototype.finalExpRate = function() {
  3928.     return this.exr * (this.isBattleMember() ? 1 : this.benchMembersExpRate());
  3929. };
  3930.  
  3931. Game_Actor.prototype.benchMembersExpRate = function() {
  3932.     return $dataSystem.optExtraExp ? 1 : 0;
  3933. };
  3934.  
  3935. Game_Actor.prototype.shouldDisplayLevelUp = function() {
  3936.     return true;
  3937. };
  3938.  
  3939. Game_Actor.prototype.changeLevel = function(level, show) {
  3940.     level = level.clamp(1, this.maxLevel());
  3941.     this.changeExp(this.expForLevel(level), show);
  3942. };
  3943.  
  3944. Game_Actor.prototype.learnSkill = function(skillId) {
  3945.     if (!this.isLearnedSkill(skillId)) {
  3946.         this._skills.push(skillId);
  3947.         this._skills.sort(function(a, b) {
  3948.             return a - b;
  3949.         });
  3950.     }
  3951. };
  3952.  
  3953. Game_Actor.prototype.forgetSkill = function(skillId) {
  3954.     var index = this._skills.indexOf(skillId);
  3955.     if (index >= 0) {
  3956.         this._skills.splice(index, 1);
  3957.     }
  3958. };
  3959.  
  3960. Game_Actor.prototype.isLearnedSkill = function(skillId) {
  3961.     return this._skills.contains(skillId) || this.addedSkills().contains(skillId);
  3962. };
  3963.  
  3964. Game_Actor.prototype.changeClass = function(classId, keepExp) {
  3965.     if (keepExp) {
  3966.         this._exp[classId] = this.currentExp();
  3967.     }
  3968.     this._classId = classId;
  3969.     this.changeExp(this._exp[this._classId] || 0, false);
  3970.     this.refresh();
  3971. };
  3972.  
  3973. Game_Actor.prototype.setCharacterImage = function(characterName, characterIndex) {
  3974.     this._characterName = characterName;
  3975.     this._characterIndex = characterIndex;
  3976. };
  3977.  
  3978. Game_Actor.prototype.setFaceImage = function(faceName, faceIndex) {
  3979.     this._faceName = faceName;
  3980.     this._faceIndex = faceIndex;
  3981. };
  3982.  
  3983. Game_Actor.prototype.setBattlerImage = function(battlerName) {
  3984.     this._battlerName = battlerName;
  3985. };
  3986.  
  3987. Game_Actor.prototype.isSpriteVisible = function() {
  3988.     return $gameSystem.isSideView();
  3989. };
  3990.  
  3991. Game_Actor.prototype.startAnimation = function(animationId, mirror, delay) {
  3992.     mirror = !mirror;
  3993.     Game_Battler.prototype.startAnimation.call(this, animationId, mirror, delay);
  3994. };
  3995.  
  3996. Game_Actor.prototype.performActionStart = function(action) {
  3997.     Game_Battler.prototype.performActionStart.call(this, action);
  3998. };
  3999.  
  4000. Game_Actor.prototype.performAction = function(action) {
  4001.     Game_Battler.prototype.performAction.call(this, action);
  4002.     if (action.isAttack()) {
  4003.         this.performAttack();
  4004.     } else if (action.isGuard()) {
  4005.         this.requestMotion('guard');
  4006.     } else if (action.isMagicSkill()) {
  4007.         this.requestMotion('spell');
  4008.     } else if (action.isSkill()) {
  4009.         this.requestMotion('skill');
  4010.     } else if (action.isItem()) {
  4011.         this.requestMotion('item');
  4012.     }
  4013. };
  4014.  
  4015. Game_Actor.prototype.performActionEnd = function() {
  4016.     Game_Battler.prototype.performActionEnd.call(this);
  4017. };
  4018.  
  4019. Game_Actor.prototype.performAttack = function() {
  4020.     var weapons = this.weapons();
  4021.     var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
  4022.     var attackMotion = $dataSystem.attackMotions[wtypeId];
  4023.     if (attackMotion) {
  4024.         if (attackMotion.type === 0) {
  4025.             this.requestMotion('thrust');
  4026.         } else if (attackMotion.type === 1) {
  4027.             this.requestMotion('swing');
  4028.         } else if (attackMotion.type === 2) {
  4029.             this.requestMotion('missile');
  4030.         }
  4031.         this.startWeaponAnimation(attackMotion.weaponImageId);
  4032.     }
  4033. };
  4034.  
  4035. Game_Actor.prototype.performDamage = function() {
  4036.     Game_Battler.prototype.performDamage.call(this);
  4037.     if (this.isSpriteVisible()) {
  4038.         this.requestMotion('damage');
  4039.     } else {
  4040.         $gameScreen.startShake(5, 5, 10);
  4041.     }
  4042.     SoundManager.playActorDamage();
  4043. };
  4044.  
  4045. Game_Actor.prototype.performEvasion = function() {
  4046.     Game_Battler.prototype.performEvasion.call(this);
  4047.     this.requestMotion('evade');
  4048. };
  4049.  
  4050. Game_Actor.prototype.performMagicEvasion = function() {
  4051.     Game_Battler.prototype.performMagicEvasion.call(this);
  4052.     this.requestMotion('evade');
  4053. };
  4054.  
  4055. Game_Actor.prototype.performCounter = function() {
  4056.     Game_Battler.prototype.performCounter.call(this);
  4057.     this.performAttack();
  4058. };
  4059.  
  4060. Game_Actor.prototype.performCollapse = function() {
  4061.     Game_Battler.prototype.performCollapse.call(this);
  4062.     if ($gameParty.inBattle()) {
  4063.         SoundManager.playActorCollapse();
  4064.     }
  4065. };
  4066.  
  4067. Game_Actor.prototype.performVictory = function() {
  4068.     if (this.canMove()) {
  4069.         this.requestMotion('victory');
  4070.     }
  4071. };
  4072.  
  4073. Game_Actor.prototype.performEscape = function() {
  4074.     if (this.canMove()) {
  4075.         this.requestMotion('escape');
  4076.     }
  4077. };
  4078.  
  4079. Game_Actor.prototype.makeActionList = function() {
  4080.     var list = [];
  4081.     var action = new Game_Action(this);
  4082.     action.setAttack();
  4083.     list.push(action);
  4084.     this.usableSkills().forEach(function(skill) {
  4085.         action = new Game_Action(this);
  4086.         action.setSkill(skill.id);
  4087.         list.push(action);
  4088.     }, this);
  4089.     return list;
  4090. };
  4091.  
  4092. Game_Actor.prototype.makeAutoBattleActions = function() {
  4093.     for (var i = 0; i < this.numActions(); i++) {
  4094.         var list = this.makeActionList();
  4095.         var maxValue = Number.MIN_VALUE;
  4096.         for (var j = 0; j < list.length; j++) {
  4097.             var value = list[j].evaluate();
  4098.             if (value > maxValue) {
  4099.                 maxValue = value;
  4100.                 this.setAction(i, list[j]);
  4101.             }
  4102.         }
  4103.     }
  4104.     this.setActionState('waiting');
  4105. };
  4106.  
  4107. Game_Actor.prototype.makeConfusionActions = function() {
  4108.     for (var i = 0; i < this.numActions(); i++) {
  4109.         this.action(i).setConfusion();
  4110.     }
  4111.     this.setActionState('waiting');
  4112. };
  4113.  
  4114. Game_Actor.prototype.makeActions = function() {
  4115.     Game_Battler.prototype.makeActions.call(this);
  4116.     if (this.numActions() > 0) {
  4117.         this.setActionState('undecided');
  4118.     } else {
  4119.         this.setActionState('waiting');
  4120.     }
  4121.     if (this.isAutoBattle()) {
  4122.         this.makeAutoBattleActions();
  4123.     } else if (this.isConfused()) {
  4124.         this.makeConfusionActions();
  4125.     }
  4126. };
  4127.  
  4128. Game_Actor.prototype.onPlayerWalk = function() {
  4129.     this.clearResult();
  4130.     this.checkFloorEffect();
  4131.     if ($gamePlayer.isNormal()) {
  4132.         this.turnEndOnMap();
  4133.         this.states().forEach(function(state) {
  4134.             this.updateStateSteps(state);
  4135.         }, this);
  4136.         this.showAddedStates();
  4137.         this.showRemovedStates();
  4138.     }
  4139. };
  4140.  
  4141. Game_Actor.prototype.updateStateSteps = function(state) {
  4142.     if (state.removeByWalking) {
  4143.         if (this._stateSteps[state.id] > 0) {
  4144.             if (--this._stateSteps[state.id] === 0) {
  4145.                 this.removeState(state.id);
  4146.             }
  4147.         }
  4148.     }
  4149. };
  4150.  
  4151. Game_Actor.prototype.showAddedStates = function() {
  4152.     this.result().addedStateObjects().forEach(function(state) {
  4153.         if (state.message1) {
  4154.             $gameMessage.add(this._name + state.message1);
  4155.         }
  4156.     }, this);
  4157. };
  4158.  
  4159. Game_Actor.prototype.showRemovedStates = function() {
  4160.     this.result().removedStateObjects().forEach(function(state) {
  4161.         if (state.message4) {
  4162.             $gameMessage.add(this._name + state.message4);
  4163.         }
  4164.     }, this);
  4165. };
  4166.  
  4167. Game_Actor.prototype.stepsForTurn = function() {
  4168.     return 20;
  4169. };
  4170.  
  4171. Game_Actor.prototype.turnEndOnMap = function() {
  4172.     if ($gameParty.steps() % this.stepsForTurn() === 0) {
  4173.         this.onTurnEnd();
  4174.         if (this.result().hpDamage > 0) {
  4175.             this.performMapDamage();
  4176.         }
  4177.     }
  4178. };
  4179.  
  4180. Game_Actor.prototype.checkFloorEffect = function() {
  4181.     if ($gamePlayer.isOnDamageFloor()) {
  4182.         this.executeFloorDamage();
  4183.     }
  4184. };
  4185.  
  4186. Game_Actor.prototype.executeFloorDamage = function() {
  4187.     var damage = Math.floor(this.basicFloorDamage() * this.fdr);
  4188.     damage = Math.min(damage, this.maxFloorDamage());
  4189.     this.gainHp(-damage);
  4190.     if (damage > 0) {
  4191.         this.performMapDamage();
  4192.     }
  4193. };
  4194.  
  4195. Game_Actor.prototype.basicFloorDamage = function() {
  4196.     return 10;
  4197. };
  4198.  
  4199. Game_Actor.prototype.maxFloorDamage = function() {
  4200.     return $dataSystem.optFloorDeath ? this.hp : Math.max(this.hp - 1, 0);
  4201. };
  4202.  
  4203. Game_Actor.prototype.performMapDamage = function() {
  4204.     if (!$gameParty.inBattle()) {
  4205.         $gameScreen.startFlashForDamage();
  4206.     }
  4207. };
  4208.  
  4209. Game_Actor.prototype.clearActions = function() {
  4210.     Game_Battler.prototype.clearActions.call(this);
  4211.     this._actionInputIndex = 0;
  4212. };
  4213.  
  4214. Game_Actor.prototype.inputtingAction = function() {
  4215.     return this.action(this._actionInputIndex);
  4216. };
  4217.  
  4218. Game_Actor.prototype.selectNextCommand = function() {
  4219.     if (this._actionInputIndex < this.numActions() - 1) {
  4220.         this._actionInputIndex++;
  4221.         return true;
  4222.     } else {
  4223.         return false;
  4224.     }
  4225. };
  4226.  
  4227. Game_Actor.prototype.selectPreviousCommand = function() {
  4228.     if (this._actionInputIndex > 0) {
  4229.         this._actionInputIndex--;
  4230.         return true;
  4231.     } else {
  4232.         return false;
  4233.     }
  4234. };
  4235.  
  4236. Game_Actor.prototype.lastMenuSkill = function() {
  4237.     return this._lastMenuSkill.object();
  4238. };
  4239.  
  4240. Game_Actor.prototype.setLastMenuSkill = function(skill) {
  4241.     this._lastMenuSkill.setObject(skill);
  4242. };
  4243.  
  4244. Game_Actor.prototype.lastBattleSkill = function() {
  4245.     return this._lastBattleSkill.object();
  4246. };
  4247.  
  4248. Game_Actor.prototype.setLastBattleSkill = function(skill) {
  4249.     this._lastBattleSkill.setObject(skill);
  4250. };
  4251.  
  4252. Game_Actor.prototype.lastCommandSymbol = function() {
  4253.     return this._lastCommandSymbol;
  4254. };
  4255.  
  4256. Game_Actor.prototype.setLastCommandSymbol = function(symbol) {
  4257.     this._lastCommandSymbol = symbol;
  4258. };
  4259.  
  4260. //-----------------------------------------------------------------------------
  4261. // Game_Enemy
  4262. //
  4263. // The game object class for an enemy.
  4264.  
  4265. function Game_Enemy() {
  4266.     this.initialize.apply(this, arguments);
  4267. }
  4268.  
  4269. Game_Enemy.prototype = Object.create(Game_Battler.prototype);
  4270. Game_Enemy.prototype.constructor = Game_Enemy;
  4271.  
  4272. Game_Enemy.prototype.initialize = function(enemyId, x, y) {
  4273.     Game_Battler.prototype.initialize.call(this);
  4274.     this.setup(enemyId, x, y);
  4275. };
  4276.  
  4277. Game_Enemy.prototype.initMembers = function() {
  4278.     Game_Battler.prototype.initMembers.call(this);
  4279.     this._enemyId = 0;
  4280.     this._letter = '';
  4281.     this._plural = false;
  4282.     this._screenX = 0;
  4283.     this._screenY = 0;
  4284. };
  4285.  
  4286. Game_Enemy.prototype.setup = function(enemyId, x, y) {
  4287.     this._enemyId = enemyId;
  4288.     this._screenX = x;
  4289.     this._screenY = y;
  4290.     this.recoverAll();
  4291. };
  4292.  
  4293. Game_Enemy.prototype.isEnemy = function() {
  4294.     return true;
  4295. };
  4296.  
  4297. Game_Enemy.prototype.friendsUnit = function() {
  4298.     return $gameTroop;
  4299. };
  4300.  
  4301. Game_Enemy.prototype.opponentsUnit = function() {
  4302.     return $gameParty;
  4303. };
  4304.  
  4305. Game_Enemy.prototype.index = function() {
  4306.     return $gameTroop.members().indexOf(this);
  4307. };
  4308.  
  4309. Game_Enemy.prototype.isBattleMember = function() {
  4310.     return this.index() >= 0;
  4311. };
  4312.  
  4313. Game_Enemy.prototype.enemyId = function() {
  4314.     return this._enemyId;
  4315. };
  4316.  
  4317. Game_Enemy.prototype.enemy = function() {
  4318.     return $dataEnemies[this._enemyId];
  4319. };
  4320.  
  4321. Game_Enemy.prototype.traitObjects = function() {
  4322.     return Game_Battler.prototype.traitObjects.call(this).concat(this.enemy());
  4323. };
  4324.  
  4325. Game_Enemy.prototype.paramBase = function(paramId) {
  4326.     return this.enemy().params[paramId];
  4327. };
  4328.  
  4329. Game_Enemy.prototype.exp = function() {
  4330.     return this.enemy().exp;
  4331. };
  4332.  
  4333. Game_Enemy.prototype.gold = function() {
  4334.     return this.enemy().gold;
  4335. };
  4336.  
  4337. Game_Enemy.prototype.makeDropItems = function() {
  4338.     return this.enemy().dropItems.reduce(function(r, di) {
  4339.         if (di.kind > 0 && Math.random() * di.denominator < this.dropItemRate()) {
  4340.             return r.concat(this.itemObject(di.kind, di.dataId));
  4341.         } else {
  4342.             return r;
  4343.         }
  4344.     }.bind(this), []);
  4345. };
  4346.  
  4347. Game_Enemy.prototype.dropItemRate = function() {
  4348.     return $gameParty.hasDropItemDouble() ? 2 : 1;
  4349. };
  4350.  
  4351. Game_Enemy.prototype.itemObject = function(kind, dataId) {
  4352.     if (kind === 1) {
  4353.         return $dataItems[dataId];
  4354.     } else if (kind === 2) {
  4355.         return $dataWeapons[dataId];
  4356.     } else if (kind === 3) {
  4357.         return $dataArmors[dataId];
  4358.     } else {
  4359.         return null;
  4360.     }
  4361. };
  4362.  
  4363. Game_Enemy.prototype.isSpriteVisible = function() {
  4364.     return true;
  4365. };
  4366.  
  4367. Game_Enemy.prototype.screenX = function() {
  4368.     return this._screenX;
  4369. };
  4370.  
  4371. Game_Enemy.prototype.screenY = function() {
  4372.     return this._screenY;
  4373. };
  4374.  
  4375. Game_Enemy.prototype.battlerName = function() {
  4376.     return this.enemy().battlerName;
  4377. };
  4378.  
  4379. Game_Enemy.prototype.battlerHue = function() {
  4380.     return this.enemy().battlerHue;
  4381. };
  4382.  
  4383. Game_Enemy.prototype.originalName = function() {
  4384.     return this.enemy().name;
  4385. };
  4386.  
  4387. Game_Enemy.prototype.name = function() {
  4388.     return this.originalName() + (this._plural ? this._letter : '');
  4389. };
  4390.  
  4391. Game_Enemy.prototype.isLetterEmpty = function() {
  4392.     return this._letter === '';
  4393. };
  4394.  
  4395. Game_Enemy.prototype.setLetter = function(letter) {
  4396.     this._letter = letter;
  4397. };
  4398.  
  4399. Game_Enemy.prototype.setPlural = function(plural) {
  4400.     this._plural = plural;
  4401. };
  4402.  
  4403. Game_Enemy.prototype.performActionStart = function(action) {
  4404.     Game_Battler.prototype.performActionStart.call(this, action);
  4405.     this.requestEffect('whiten');
  4406. };
  4407.  
  4408. Game_Enemy.prototype.performAction = function(action) {
  4409.     Game_Battler.prototype.performAction.call(this, action);
  4410. };
  4411.  
  4412. Game_Enemy.prototype.performActionEnd = function() {
  4413.     Game_Battler.prototype.performActionEnd.call(this);
  4414. };
  4415.  
  4416. Game_Enemy.prototype.performDamage = function() {
  4417.     Game_Battler.prototype.performDamage.call(this);
  4418.     SoundManager.playEnemyDamage();
  4419.     this.requestEffect('blink');
  4420. };
  4421.  
  4422. Game_Enemy.prototype.performCollapse = function() {
  4423.     Game_Battler.prototype.performCollapse.call(this);
  4424.     switch (this.collapseType()) {
  4425.     case 0:
  4426.         this.requestEffect('collapse');
  4427.         SoundManager.playEnemyCollapse();
  4428.         break;
  4429.     case 1:
  4430.         this.requestEffect('bossCollapse');
  4431.         SoundManager.playBossCollapse1();
  4432.         break;
  4433.     case 2:
  4434.         this.requestEffect('instantCollapse');
  4435.         break;
  4436.     }
  4437. };
  4438.  
  4439. Game_Enemy.prototype.transform = function(enemyId) {
  4440.     var name = this.originalName();
  4441.     this._enemyId = enemyId;
  4442.     if (this.originalName() !== name) {
  4443.         this._letter = '';
  4444.         this._plural = false;
  4445.     }
  4446.     this.refresh();
  4447.     if (this.numActions() > 0) {
  4448.         this.makeActions();
  4449.     }
  4450. };
  4451.  
  4452. Game_Enemy.prototype.meetsCondition = function(action) {
  4453.     var param1 = action.conditionParam1;
  4454.     var param2 = action.conditionParam2;
  4455.     switch (action.conditionType) {
  4456.     case 1:
  4457.         return this.meetsTurnCondition(param1, param2);
  4458.     case 2:
  4459.         return this.meetsHpCondition(param1, param2);
  4460.     case 3:
  4461.         return this.meetsMpCondition(param1, param2);
  4462.     case 4:
  4463.         return this.meetsStateCondition(param1);
  4464.     case 5:
  4465.         return this.meetsPartyLevelCondition(param1);
  4466.     case 6:
  4467.         return this.meetsSwitchCondition(param1);
  4468.     default:
  4469.         return true;
  4470.     }
  4471. };
  4472.  
  4473. Game_Enemy.prototype.meetsTurnCondition = function(param1, param2) {
  4474.     var n = $gameTroop.turnCount();
  4475.     if (param2 === 0) {
  4476.         return n === param1;
  4477.     } else {
  4478.         return n > 0 && n >= param1 && n % param2 === param1 % param2;
  4479.     }
  4480. };
  4481.  
  4482. Game_Enemy.prototype.meetsHpCondition = function(param1, param2) {
  4483.     return this.hpRate() >= param1 && this.hpRate() <= param2;
  4484. };
  4485.  
  4486. Game_Enemy.prototype.meetsMpCondition = function(param1, param2) {
  4487.     return this.mpRate() >= param1 && this.mpRate() <= param2;
  4488. };
  4489.  
  4490. Game_Enemy.prototype.meetsStateCondition = function(param) {
  4491.     return this.isStateAffected(param);
  4492. };
  4493.  
  4494. Game_Enemy.prototype.meetsPartyLevelCondition = function(param) {
  4495.     return $gameParty.highestLevel() >= param;
  4496. };
  4497.  
  4498. Game_Enemy.prototype.meetsSwitchCondition = function(param) {
  4499.     return $gameSwitches.value(param);
  4500. };
  4501.  
  4502. Game_Enemy.prototype.isActionValid = function(action) {
  4503.     return this.meetsCondition(action) && this.canUse($dataSkills[action.skillId]);
  4504. };
  4505.  
  4506. Game_Enemy.prototype.selectAction = function(actionList, ratingZero) {
  4507.     var sum = actionList.reduce(function(r, a) {
  4508.         return r + a.rating - ratingZero;
  4509.     }, 0);
  4510.     if (sum > 0) {
  4511.         var value = Math.randomInt(sum);
  4512.         for (var i = 0; i < actionList.length; i++) {
  4513.             var action = actionList[i];
  4514.             value -= action.rating - ratingZero;
  4515.             if (value < 0) {
  4516.                 return action;
  4517.             }
  4518.         }
  4519.     } else {
  4520.         return null;
  4521.     }
  4522. };
  4523.  
  4524. Game_Enemy.prototype.selectAllActions = function(actionList) {
  4525.     var ratingMax = Math.max.apply(null, actionList.map(function(a) {
  4526.         return a.rating;
  4527.     }));
  4528.     var ratingZero = ratingMax - 3;
  4529.     actionList = actionList.filter(function(a) {
  4530.         return a.rating > ratingZero;
  4531.     });
  4532.     for (var i = 0; i < this.numActions(); i++) {
  4533.         this.action(i).setEnemyAction(this.selectAction(actionList, ratingZero));
  4534.     }
  4535. };
  4536.  
  4537. Game_Enemy.prototype.makeActions = function() {
  4538.     Game_Battler.prototype.makeActions.call(this);
  4539.     if (this.numActions() > 0) {
  4540.         var actionList = this.enemy().actions.filter(function(a) {
  4541.             return this.isActionValid(a);
  4542.         }, this);
  4543.         if (actionList.length > 0) {
  4544.             this.selectAllActions(actionList);
  4545.         }
  4546.     }
  4547.     this.setActionState('waiting');
  4548. };
  4549.  
  4550. //-----------------------------------------------------------------------------
  4551. // Game_Actors
  4552. //
  4553. // The wrapper class for an actor array.
  4554.  
  4555. function Game_Actors() {
  4556.     this.initialize.apply(this, arguments);
  4557. }
  4558.  
  4559. Game_Actors.prototype.initialize = function() {
  4560.     this._data = [];
  4561. };
  4562.  
  4563. Game_Actors.prototype.actor = function(actorId) {
  4564.     if ($dataActors[actorId]) {
  4565.         if (!this._data[actorId]) {
  4566.             this._data[actorId] = new Game_Actor(actorId);
  4567.         }
  4568.         return this._data[actorId];
  4569.     }
  4570.     return null;
  4571. };
  4572.  
  4573. //-----------------------------------------------------------------------------
  4574. // Game_Unit
  4575. //
  4576. // The superclass of Game_Party and Game_Troop.
  4577.  
  4578. function Game_Unit() {
  4579.     this.initialize.apply(this, arguments);
  4580. }
  4581.  
  4582. Game_Unit.prototype.initialize = function() {
  4583.     this._inBattle = false;
  4584. };
  4585.  
  4586. Game_Unit.prototype.inBattle = function() {
  4587.     return this._inBattle;
  4588. };
  4589.  
  4590. Game_Unit.prototype.members = function() {
  4591.     return [];
  4592. };
  4593.  
  4594. Game_Unit.prototype.aliveMembers = function() {
  4595.     return this.members().filter(function(member) {
  4596.         return member.isAlive();
  4597.     });
  4598. };
  4599.  
  4600. Game_Unit.prototype.deadMembers = function() {
  4601.     return this.members().filter(function(member) {
  4602.         return member.isDead();
  4603.     });
  4604. };
  4605.  
  4606. Game_Unit.prototype.movableMembers = function() {
  4607.     return this.members().filter(function(member) {
  4608.         return member.canMove();
  4609.     });
  4610. };
  4611.  
  4612. Game_Unit.prototype.clearActions = function() {
  4613.     return this.members().forEach(function(member) {
  4614.         return member.clearActions();
  4615.     });
  4616. };
  4617.  
  4618. Game_Unit.prototype.agility = function() {
  4619.     var members = this.members();
  4620.     if (members.length === 0) {
  4621.         return 1;
  4622.     }
  4623.     var sum = members.reduce(function(r, member) {
  4624.         return r + member.agi;
  4625.     }, 0);
  4626.     return sum / members.length;
  4627. };
  4628.  
  4629. Game_Unit.prototype.tgrSum = function() {
  4630.     return this.aliveMembers().reduce(function(r, member) {
  4631.         return r + member.tgr;
  4632.     }, 0);
  4633. };
  4634.  
  4635. Game_Unit.prototype.randomTarget = function() {
  4636.     var tgrRand = Math.random() * this.tgrSum();
  4637.     var target = null;
  4638.     this.aliveMembers().forEach(function(member) {
  4639.         tgrRand -= member.tgr;
  4640.         if (tgrRand <= 0 && !target) {
  4641.             target = member;
  4642.         }
  4643.     });
  4644.     return target;
  4645. };
  4646.  
  4647. Game_Unit.prototype.randomDeadTarget = function() {
  4648.     var members = this.deadMembers();
  4649.     if (members.length === 0) {
  4650.         return null;
  4651.     }
  4652.     return members[Math.floor(Math.random() * members.length)];
  4653. };
  4654.  
  4655. Game_Unit.prototype.smoothTarget = function(index) {
  4656.     if (index < 0) {
  4657.         index = 0;
  4658.     }
  4659.     var member = this.members()[index];
  4660.     return (member && member.isAlive()) ? member : this.aliveMembers()[0];
  4661. };
  4662.  
  4663. Game_Unit.prototype.smoothDeadTarget = function(index) {
  4664.     if (index < 0) {
  4665.         index = 0;
  4666.     }
  4667.     var member = this.members()[index];
  4668.     return (member && member.isDead()) ? member : this.deadMembers()[0];
  4669. };
  4670.  
  4671. Game_Unit.prototype.clearResults = function() {
  4672.     this.members().forEach(function(member) {
  4673.         member.clearResult();
  4674.     });
  4675. };
  4676.  
  4677. Game_Unit.prototype.onBattleStart = function() {
  4678.     this.members().forEach(function(member) {
  4679.         member.onBattleStart();
  4680.     });
  4681.     this._inBattle = true;
  4682. };
  4683.  
  4684. Game_Unit.prototype.onBattleEnd = function() {
  4685.     this._inBattle = false;
  4686.     this.members().forEach(function(member) {
  4687.         member.onBattleEnd();
  4688.     });
  4689. };
  4690.  
  4691. Game_Unit.prototype.makeActions = function() {
  4692.     this.members().forEach(function(member) {
  4693.         member.makeActions();
  4694.     });
  4695. };
  4696.  
  4697. Game_Unit.prototype.select = function(activeMember) {
  4698.     this.members().forEach(function(member) {
  4699.         if (member === activeMember) {
  4700.             member.select();
  4701.         } else {
  4702.             member.deselect();
  4703.         }
  4704.     });
  4705. };
  4706.  
  4707. Game_Unit.prototype.isAllDead = function() {
  4708.     return this.aliveMembers().length === 0;
  4709. };
  4710.  
  4711. Game_Unit.prototype.substituteBattler = function() {
  4712.     var members = this.members();
  4713.     for (var i = 0; i < members.length; i++) {
  4714.         if (members[i].isSubstitute()) {
  4715.             return members[i];
  4716.         }
  4717.     }
  4718. };
  4719.  
  4720. //-----------------------------------------------------------------------------
  4721. // Game_Party
  4722. //
  4723. // The game object class for the party. Information such as gold and items is
  4724. // included.
  4725.  
  4726. function Game_Party() {
  4727.     this.initialize.apply(this, arguments);
  4728. }
  4729.  
  4730. Game_Party.prototype = Object.create(Game_Unit.prototype);
  4731. Game_Party.prototype.constructor = Game_Party;
  4732.  
  4733. Game_Party.ABILITY_ENCOUNTER_HALF    = 0;
  4734. Game_Party.ABILITY_ENCOUNTER_NONE    = 1;
  4735. Game_Party.ABILITY_CANCEL_SURPRISE   = 2;
  4736. Game_Party.ABILITY_RAISE_PREEMPTIVE  = 3;
  4737. Game_Party.ABILITY_GOLD_DOUBLE       = 4;
  4738. Game_Party.ABILITY_DROP_ITEM_DOUBLE  = 5;
  4739.  
  4740. Game_Party.prototype.initialize = function() {
  4741.     Game_Unit.prototype.initialize.call(this);
  4742.     this._gold = 0;
  4743.     this._steps = 0;
  4744.     this._lastItem = new Game_Item();
  4745.     this._menuActorId = 0;
  4746.     this._targetActorId = 0;
  4747.     this._actors = [];
  4748.     this.initAllItems();
  4749. };
  4750.  
  4751. Game_Party.prototype.initAllItems = function() {
  4752.     this._items = {};
  4753.     this._weapons = {};
  4754.     this._armors = {};
  4755. };
  4756.  
  4757. Game_Party.prototype.exists = function() {
  4758.     return this._actors.length > 0;
  4759. };
  4760.  
  4761. Game_Party.prototype.size = function() {
  4762.     return this.members().length;
  4763. };
  4764.  
  4765. Game_Party.prototype.isEmpty = function() {
  4766.     return this.size() === 0;
  4767. };
  4768.  
  4769. Game_Party.prototype.members = function() {
  4770.     return this.inBattle() ? this.battleMembers() : this.allMembers();
  4771. };
  4772.  
  4773. Game_Party.prototype.allMembers = function() {
  4774.     return this._actors.map(function(id) {
  4775.         return $gameActors.actor(id);
  4776.     });
  4777. };
  4778.  
  4779. Game_Party.prototype.battleMembers = function() {
  4780.     return this.allMembers().slice(0, this.maxBattleMembers()).filter(function(actor) {
  4781.         return actor.isAppeared();
  4782.     });
  4783. };
  4784.  
  4785. Game_Party.prototype.maxBattleMembers = function() {
  4786.     return 4;
  4787. };
  4788.  
  4789. Game_Party.prototype.leader = function() {
  4790.     return this.battleMembers()[0];
  4791. };
  4792.  
  4793. Game_Party.prototype.reviveBattleMembers = function() {
  4794.     this.battleMembers().forEach(function(actor) {
  4795.         if (actor.isDead()) {
  4796.             actor.setHp(1);
  4797.         }
  4798.     });
  4799. };
  4800.  
  4801. Game_Party.prototype.items = function() {
  4802.     var list = [];
  4803.     for (var id in this._items) {
  4804.         list.push($dataItems[id]);
  4805.     }
  4806.     return list;
  4807. };
  4808.  
  4809. Game_Party.prototype.weapons = function() {
  4810.     var list = [];
  4811.     for (var id in this._weapons) {
  4812.         list.push($dataWeapons[id]);
  4813.     }
  4814.     return list;
  4815. };
  4816.  
  4817. Game_Party.prototype.armors = function() {
  4818.     var list = [];
  4819.     for (var id in this._armors) {
  4820.         list.push($dataArmors[id]);
  4821.     }
  4822.     return list;
  4823. };
  4824.  
  4825. Game_Party.prototype.equipItems = function() {
  4826.     return this.weapons().concat(this.armors());
  4827. };
  4828.  
  4829. Game_Party.prototype.allItems = function() {
  4830.     return this.items().concat(this.equipItems());
  4831. };
  4832.  
  4833. Game_Party.prototype.itemContainer = function(item) {
  4834.     if (!item) {
  4835.         return null;
  4836.     } else if (DataManager.isItem(item)) {
  4837.         return this._items;
  4838.     } else if (DataManager.isWeapon(item)) {
  4839.         return this._weapons;
  4840.     } else if (DataManager.isArmor(item)) {
  4841.         return this._armors;
  4842.     } else {
  4843.         return null;
  4844.     }
  4845. };
  4846.  
  4847. Game_Party.prototype.setupStartingMembers = function() {
  4848.     this._actors = [];
  4849.     $dataSystem.partyMembers.forEach(function(actorId) {
  4850.         if ($gameActors.actor(actorId)) {
  4851.             this._actors.push(actorId);
  4852.         }
  4853.     }, this);
  4854. };
  4855.  
  4856. Game_Party.prototype.name = function() {
  4857.     var numBattleMembers = this.battleMembers().length;
  4858.     if (numBattleMembers === 0) {
  4859.         return '';
  4860.     } else if (numBattleMembers === 1) {
  4861.         return this.leader().name();
  4862.     } else {
  4863.         return TextManager.partyName.format(this.leader().name());
  4864.     }
  4865. };
  4866.  
  4867. Game_Party.prototype.setupBattleTest = function() {
  4868.     this.setupBattleTestMembers();
  4869.     this.setupBattleTestItems();
  4870. };
  4871.  
  4872. Game_Party.prototype.setupBattleTestMembers = function() {
  4873.     $dataSystem.testBattlers.forEach(function(battler) {
  4874.         var actor = $gameActors.actor(battler.actorId);
  4875.         if (actor) {
  4876.             actor.changeLevel(battler.level, false);
  4877.             actor.initEquips(battler.equips);
  4878.             actor.recoverAll();
  4879.             this.addActor(battler.actorId);
  4880.         }
  4881.     }, this);
  4882. };
  4883.  
  4884. Game_Party.prototype.setupBattleTestItems = function() {
  4885.     $dataItems.forEach(function(item) {
  4886.         if (item && item.name.length > 0) {
  4887.             this.gainItem(item, this.maxItems(item));
  4888.         }
  4889.     }, this);
  4890. };
  4891.  
  4892. Game_Party.prototype.highestLevel = function() {
  4893.     return Math.max.apply(null, this.members().map(function(actor) {
  4894.         return actor.level;
  4895.     }));
  4896. };
  4897.  
  4898. Game_Party.prototype.addActor = function(actorId) {
  4899.     if (!this._actors.contains(actorId)) {
  4900.         this._actors.push(actorId);
  4901.         $gamePlayer.refresh();
  4902.         $gameMap.requestRefresh();
  4903.     }
  4904. };
  4905.  
  4906. Game_Party.prototype.removeActor = function(actorId) {
  4907.     if (this._actors.contains(actorId)) {
  4908.         this._actors.splice(this._actors.indexOf(actorId), 1);
  4909.         $gamePlayer.refresh();
  4910.         $gameMap.requestRefresh();
  4911.     }
  4912. };
  4913.  
  4914. Game_Party.prototype.gold = function() {
  4915.     return this._gold;
  4916. };
  4917.  
  4918. Game_Party.prototype.gainGold = function(amount) {
  4919.     this._gold = (this._gold + amount).clamp(0, this.maxGold());
  4920. };
  4921.  
  4922. Game_Party.prototype.loseGold = function(amount) {
  4923.     this.gainGold(-amount);
  4924. };
  4925.  
  4926. Game_Party.prototype.maxGold = function() {
  4927.     return 99999999;
  4928. };
  4929.  
  4930. Game_Party.prototype.steps = function() {
  4931.     return this._steps;
  4932. };
  4933.  
  4934. Game_Party.prototype.increaseSteps = function() {
  4935.     this._steps++;
  4936. };
  4937.  
  4938. Game_Party.prototype.numItems = function(item) {
  4939.     var container = this.itemContainer(item);
  4940.     return container ? container[item.id] || 0 : 0;
  4941. };
  4942.  
  4943. Game_Party.prototype.maxItems = function(item) {
  4944.     return 99;
  4945. };
  4946.  
  4947. Game_Party.prototype.hasMaxItems = function(item) {
  4948.     return this.numItems(item) >= this.maxItems(item);
  4949. };
  4950.  
  4951. Game_Party.prototype.hasItem = function(item, includeEquip) {
  4952.     if (includeEquip === undefined) {
  4953.         includeEquip = false;
  4954.     }
  4955.     if (this.numItems(item) > 0) {
  4956.         return true;
  4957.     } else if (includeEquip && this.isAnyMemberEquipped(item)) {
  4958.         return true;
  4959.     } else {
  4960.         return false;
  4961.     }
  4962. };
  4963.  
  4964. Game_Party.prototype.isAnyMemberEquipped = function(item) {
  4965.     return this.members().some(function(actor) {
  4966.         return actor.equips().contains(item);
  4967.     });
  4968. };
  4969.  
  4970. Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
  4971.     var container = this.itemContainer(item);
  4972.     if (container) {
  4973.         var lastNumber = this.numItems(item);
  4974.         var newNumber = lastNumber + amount;
  4975.         container[item.id] = newNumber.clamp(0, this.maxItems(item));
  4976.         if (container[item.id] === 0) {
  4977.             delete container[item.id];
  4978.         }
  4979.         if (includeEquip && newNumber < 0) {
  4980.             this.discardMembersEquip(item, -newNumber);
  4981.         }
  4982.         $gameMap.requestRefresh();
  4983.     }
  4984. };
  4985.  
  4986. Game_Party.prototype.discardMembersEquip = function(item, amount) {
  4987.     var n = amount;
  4988.     this.members().forEach(function(actor) {
  4989.         while (n > 0 && actor.isEquipped(item)) {
  4990.             actor.discardEquip(item);
  4991.             n--;
  4992.         }
  4993.     });
  4994. };
  4995.  
  4996. Game_Party.prototype.loseItem = function(item, amount, includeEquip) {
  4997.     this.gainItem(item, -amount, includeEquip);
  4998. };
  4999.  
  5000. Game_Party.prototype.consumeItem = function(item) {
  5001.     if (DataManager.isItem(item) && item.consumable) {
  5002.         this.loseItem(item, 1);
  5003.     }
  5004. };
  5005.  
  5006. Game_Party.prototype.canUse = function(item) {
  5007.     return this.members().some(function(actor) {
  5008.         return actor.canUse(item);
  5009.     });
  5010. };
  5011.  
  5012. Game_Party.prototype.canInput = function() {
  5013.     return this.members().some(function(actor) {
  5014.         return actor.canInput();
  5015.     });
  5016. };
  5017.  
  5018. Game_Party.prototype.isAllDead = function() {
  5019.     if (Game_Unit.prototype.isAllDead.call(this)) {
  5020.         return this.inBattle() || !this.isEmpty();
  5021.     } else {
  5022.         return false;
  5023.     }
  5024. };
  5025.  
  5026. Game_Party.prototype.onPlayerWalk = function() {
  5027.     this.members().forEach(function(actor) {
  5028.         return actor.onPlayerWalk();
  5029.     });
  5030. };
  5031.  
  5032. Game_Party.prototype.menuActor = function() {
  5033.     var actor = $gameActors.actor(this._menuActorId);
  5034.     if (!this.members().contains(actor)) {
  5035.         actor = this.members()[0];
  5036.     }
  5037.     return actor;
  5038. };
  5039.  
  5040. Game_Party.prototype.setMenuActor = function(actor) {
  5041.     this._menuActorId = actor.actorId();
  5042. };
  5043.  
  5044. Game_Party.prototype.makeMenuActorNext = function() {
  5045.     var index = this.members().indexOf(this.menuActor());
  5046.     if (index >= 0) {
  5047.         index = (index + 1) % this.members().length;
  5048.         this.setMenuActor(this.members()[index]);
  5049.     } else {
  5050.         this.setMenuActor(this.members()[0]);
  5051.     }
  5052. };
  5053.  
  5054. Game_Party.prototype.makeMenuActorPrevious = function() {
  5055.     var index = this.members().indexOf(this.menuActor());
  5056.     if (index >= 0) {
  5057.         index = (index + this.members().length - 1) % this.members().length;
  5058.         this.setMenuActor(this.members()[index]);
  5059.     } else {
  5060.         this.setMenuActor(this.members()[0]);
  5061.     }
  5062. };
  5063.  
  5064. Game_Party.prototype.targetActor = function() {
  5065.     var actor = $gameActors.actor(this._targetActorId);
  5066.     if (!this.members().contains(actor)) {
  5067.         actor = this.members()[0];
  5068.     }
  5069.     return actor;
  5070. };
  5071.  
  5072. Game_Party.prototype.setTargetActor = function(actor) {
  5073.     this._targetActorId = actor.actorId();
  5074. };
  5075.  
  5076. Game_Party.prototype.lastItem = function() {
  5077.     return this._lastItem.object();
  5078. };
  5079.  
  5080. Game_Party.prototype.setLastItem = function(item) {
  5081.     this._lastItem.setObject(item);
  5082. };
  5083.  
  5084. Game_Party.prototype.swapOrder = function(index1, index2) {
  5085.     var temp = this._actors[index1];
  5086.     this._actors[index1] = this._actors[index2];
  5087.     this._actors[index2] = temp;
  5088.     $gamePlayer.refresh();
  5089. };
  5090.  
  5091. Game_Party.prototype.charactersForSavefile = function() {
  5092.     return this.battleMembers().map(function(actor) {
  5093.         return [actor.characterName(), actor.characterIndex()];
  5094.     });
  5095. };
  5096.  
  5097. Game_Party.prototype.facesForSavefile = function() {
  5098.     return this.battleMembers().map(function(actor) {
  5099.         return [actor.faceName(), actor.faceIndex()];
  5100.     });
  5101. };
  5102.  
  5103. Game_Party.prototype.partyAbility = function(abilityId) {
  5104.     return this.battleMembers().some(function(actor) {
  5105.         return actor.partyAbility(abilityId);
  5106.     });
  5107. };
  5108.  
  5109. Game_Party.prototype.hasEncounterHalf = function() {
  5110.     return this.partyAbility(Game_Party.ABILITY_ENCOUNTER_HALF);
  5111. };
  5112.  
  5113. Game_Party.prototype.hasEncounterNone = function() {
  5114.     return this.partyAbility(Game_Party.ABILITY_ENCOUNTER_NONE);
  5115. };
  5116.  
  5117. Game_Party.prototype.hasCancelSurprise = function() {
  5118.     return this.partyAbility(Game_Party.ABILITY_CANCEL_SURPRISE);
  5119. };
  5120.  
  5121. Game_Party.prototype.hasRaisePreemptive = function() {
  5122.     return this.partyAbility(Game_Party.ABILITY_RAISE_PREEMPTIVE);
  5123. };
  5124.  
  5125. Game_Party.prototype.hasGoldDouble = function() {
  5126.     return this.partyAbility(Game_Party.ABILITY_GOLD_DOUBLE);
  5127. };
  5128.  
  5129. Game_Party.prototype.hasDropItemDouble = function() {
  5130.     return this.partyAbility(Game_Party.ABILITY_DROP_ITEM_DOUBLE);
  5131. };
  5132.  
  5133. Game_Party.prototype.ratePreemptive = function(troopAgi) {
  5134.     var rate = this.agility() >= troopAgi ? 0.05 : 0.03;
  5135.     if (this.hasRaisePreemptive()) {
  5136.         rate *= 4;
  5137.     }
  5138.     return rate;
  5139. };
  5140.  
  5141. Game_Party.prototype.rateSurprise = function(troopAgi) {
  5142.     var rate = this.agility() >= troopAgi ? 0.03 : 0.05;
  5143.     if (this.hasCancelSurprise()) {
  5144.         rate = 0;
  5145.     }
  5146.     return rate;
  5147. };
  5148.  
  5149. Game_Party.prototype.performVictory = function() {
  5150.     this.members().forEach(function(actor) {
  5151.         actor.performVictory();
  5152.     });
  5153. };
  5154.  
  5155. Game_Party.prototype.performEscape = function() {
  5156.     this.members().forEach(function(actor) {
  5157.         actor.performEscape();
  5158.     });
  5159. };
  5160.  
  5161. Game_Party.prototype.removeBattleStates = function() {
  5162.     this.members().forEach(function(actor) {
  5163.         actor.removeBattleStates();
  5164.     });
  5165. };
  5166.  
  5167. Game_Party.prototype.requestMotionRefresh = function() {
  5168.     this.members().forEach(function(actor) {
  5169.         actor.requestMotionRefresh();
  5170.     });
  5171. };
  5172.  
  5173. //-----------------------------------------------------------------------------
  5174. // Game_Troop
  5175. //
  5176. // The game object class for a troop and the battle-related data.
  5177.  
  5178. function Game_Troop() {
  5179.     this.initialize.apply(this, arguments);
  5180. }
  5181.  
  5182. Game_Troop.prototype = Object.create(Game_Unit.prototype);
  5183. Game_Troop.prototype.constructor = Game_Troop;
  5184.  
  5185. Game_Troop.LETTER_TABLE_HALF = [
  5186.     ' A',' B',' C',' D',' E',' F',' G',' H',' I',' J',' K',' L',' M',
  5187.     ' N',' O',' P',' Q',' R',' S',' T',' U',' V',' W',' X',' Y',' Z'
  5188. ];
  5189. Game_Troop.LETTER_TABLE_FULL = [
  5190.     'A','ï¼¢','ï¼£','D','ï¼¥','F','G','H','I','J','K','L','ï¼­',
  5191.     'ï¼®','O','ï¼°','ï¼±','ï¼²','ï¼³','ï¼´','ï¼µ','V','ï¼·','X','ï¼¹','Z'
  5192. ];
  5193.  
  5194. Game_Troop.prototype.initialize = function() {
  5195.     Game_Unit.prototype.initialize.call(this);
  5196.     this._interpreter = new Game_Interpreter();
  5197.     this.clear();
  5198. };
  5199.  
  5200. Game_Troop.prototype.isEventRunning = function() {
  5201.     return this._interpreter.isRunning();
  5202. };
  5203.  
  5204. Game_Troop.prototype.updateInterpreter = function() {
  5205.     this._interpreter.update();
  5206. };
  5207.  
  5208. Game_Troop.prototype.turnCount = function() {
  5209.     return this._turnCount;
  5210. };
  5211.  
  5212. Game_Troop.prototype.members = function() {
  5213.     return this._enemies;
  5214. };
  5215.  
  5216. Game_Troop.prototype.clear = function() {
  5217.     this._interpreter.clear();
  5218.     this._troopId = 0;
  5219.     this._eventFlags = {};
  5220.     this._enemies = [];
  5221.     this._turnCount = 0;
  5222.     this._namesCount = {};
  5223. };
  5224.  
  5225. Game_Troop.prototype.troop = function() {
  5226.     return $dataTroops[this._troopId];
  5227. };
  5228.  
  5229. Game_Troop.prototype.setup = function(troopId) {
  5230.     this.clear();
  5231.     this._troopId = troopId;
  5232.     this._enemies = [];
  5233.     this.troop().members.forEach(function(member) {
  5234.         if ($dataEnemies[member.enemyId]) {
  5235.             var enemyId = member.enemyId;
  5236.             var x = member.x;
  5237.             var y = member.y;
  5238.             var enemy = new Game_Enemy(enemyId, x, y);
  5239.             if (member.hidden) {
  5240.                 enemy.hide();
  5241.             }
  5242.             this._enemies.push(enemy);
  5243.         }
  5244.     }, this);
  5245.     this.makeUniqueNames();
  5246. };
  5247.  
  5248. Game_Troop.prototype.makeUniqueNames = function() {
  5249.     var table = this.letterTable();
  5250.     this.members().forEach(function(enemy) {
  5251.         if (enemy.isAlive() && enemy.isLetterEmpty()) {
  5252.             var name = enemy.originalName();
  5253.             var n = this._namesCount[name] || 0;
  5254.             enemy.setLetter(table[n % table.length]);
  5255.             this._namesCount[name] = n + 1;
  5256.         }
  5257.     }, this);
  5258.     this.members().forEach(function(enemy) {
  5259.         var name = enemy.originalName();
  5260.         if (this._namesCount[name] >= 2) {
  5261.             enemy.setPlural(true);
  5262.         }
  5263.     }, this);
  5264. };
  5265.  
  5266. Game_Troop.prototype.letterTable = function() {
  5267.     return $gameSystem.isCJK() ? Game_Troop.LETTER_TABLE_FULL :
  5268.             Game_Troop.LETTER_TABLE_HALF;
  5269. };
  5270.  
  5271. Game_Troop.prototype.enemyNames = function() {
  5272.     var names = [];
  5273.     this.members().forEach(function(enemy) {
  5274.         var name = enemy.originalName();
  5275.         if (enemy.isAlive() && !names.contains(name)) {
  5276.             names.push(name);
  5277.         }
  5278.     });
  5279.     return names;
  5280. };
  5281.  
  5282. Game_Troop.prototype.meetsConditions = function(page) {
  5283.     var c = page.conditions;
  5284.     if (!c.turnEnding && !c.turnValid && !c.enemyValid &&
  5285.             !c.actorValid && !c.switchValid) {
  5286.         return false;  // Conditions not set
  5287.     }
  5288.     if (c.turnEnding) {
  5289.         if (!BattleManager.isTurnEnd()) {
  5290.             return false;
  5291.         }
  5292.     }
  5293.     if (c.turnValid) {
  5294.         var n = this._turnCount;
  5295.         var a = c.turnA;
  5296.         var b = c.turnB;
  5297.         if ((b === 0 && n !== a)) {
  5298.             return false;
  5299.         }
  5300.         if ((b > 0 && (n < 1 || n < a || n % b !== a % b))) {
  5301.             return false;
  5302.         }
  5303.     }
  5304.     if (c.enemyValid) {
  5305.         var enemy = $gameTroop.members()[c.enemyIndex];
  5306.         if (!enemy || enemy.hpRate() * 100 > c.enemyHp) {
  5307.             return false;
  5308.         }
  5309.     }
  5310.     if (c.actorValid) {
  5311.         var actor = $gameActors.actor(c.actorId);
  5312.         if (!actor || actor.hpRate() * 100 > c.actorHp) {
  5313.             return false;
  5314.         }
  5315.     }
  5316.     if (c.switchValid) {
  5317.         if (!$gameSwitches.value(c.switchId)) {
  5318.             return false;
  5319.         }
  5320.     }
  5321.     return true;
  5322. };
  5323.  
  5324. Game_Troop.prototype.setupBattleEvent = function() {
  5325.     if (!this._interpreter.isRunning()) {
  5326.         if (this._interpreter.setupReservedCommonEvent()) {
  5327.             return;
  5328.         }
  5329.         var pages = this.troop().pages;
  5330.         for (var i = 0; i < pages.length; i++) {
  5331.             var page = pages[i];
  5332.             if (this.meetsConditions(page) && !this._eventFlags[i]) {
  5333.                 this._interpreter.setup(page.list);
  5334.                 if (page.span <= 1) {
  5335.                     this._eventFlags[i] = true;
  5336.                 }
  5337.                 break;
  5338.             }
  5339.         }
  5340.     }
  5341. };
  5342.  
  5343. Game_Troop.prototype.increaseTurn = function() {
  5344.     var pages = this.troop().pages;
  5345.     for (var i = 0; i < pages.length; i++) {
  5346.         var page = pages[i];
  5347.         if (page.span === 1) {
  5348.             this._eventFlags[i] = false;
  5349.         }
  5350.     }
  5351.     this._turnCount++;
  5352. };
  5353.  
  5354. Game_Troop.prototype.expTotal = function() {
  5355.     return this.deadMembers().reduce(function(r, enemy) {
  5356.         return r + enemy.exp();
  5357.     }, 0);
  5358. };
  5359.  
  5360. Game_Troop.prototype.goldTotal = function() {
  5361.     return this.deadMembers().reduce(function(r, enemy) {
  5362.         return r + enemy.gold();
  5363.     }, 0) * this.goldRate();
  5364. };
  5365.  
  5366. Game_Troop.prototype.goldRate = function() {
  5367.     return $gameParty.hasGoldDouble() ? 2 : 1;
  5368. };
  5369.  
  5370. Game_Troop.prototype.makeDropItems = function() {
  5371.     return this.deadMembers().reduce(function(r, enemy) {
  5372.         return r.concat(enemy.makeDropItems());
  5373.     }, []);
  5374. };
  5375.  
  5376. //-----------------------------------------------------------------------------
  5377. // Game_Map
  5378. //
  5379. // The game object class for a map. It contains scrolling and passage
  5380. // determination functions.
  5381.  
  5382. function Game_Map() {
  5383.     this.initialize.apply(this, arguments);
  5384. }
  5385.  
  5386. Game_Map.prototype.initialize = function() {
  5387.     this._interpreter = new Game_Interpreter();
  5388.     this._mapId = 0;
  5389.     this._tilesetId = 0;
  5390.     this._events = [];
  5391.     this._commonEvents = [];
  5392.     this._vehicles = [];
  5393.     this._displayX = 0;
  5394.     this._displayY = 0;
  5395.     this._nameDisplay = true;
  5396.     this._scrollDirection = 2;
  5397.     this._scrollRest = 0;
  5398.     this._scrollSpeed = 4;
  5399.     this._parallaxName = '';
  5400.     this._parallaxZero = false;
  5401.     this._parallaxLoopX = false;
  5402.     this._parallaxLoopY = false;
  5403.     this._parallaxSx = 0;
  5404.     this._parallaxSy = 0;
  5405.     this._parallaxX = 0;
  5406.     this._parallaxY = 0;
  5407.     this._battleback1Name = null;
  5408.     this._battleback2Name = null;
  5409.     this.createVehicles();
  5410. };
  5411.  
  5412. Game_Map.prototype.setup = function(mapId) {
  5413.     if (!$dataMap) {
  5414.         throw new Error('The map data is not available');
  5415.     }
  5416.     this._mapId = mapId;
  5417.     this._tilesetId = $dataMap.tilesetId;
  5418.     this._displayX = 0;
  5419.     this._displayY = 0;
  5420.     this.refereshVehicles();
  5421.     this.setupEvents();
  5422.     this.setupScroll();
  5423.     this.setupParallax();
  5424.     this.setupBattleback();
  5425.     this._needsRefresh = false;
  5426. };
  5427.  
  5428. Game_Map.prototype.isEventRunning = function() {
  5429.     return this._interpreter.isRunning() || this.isAnyEventStarting();
  5430. };
  5431.  
  5432. Game_Map.prototype.tileWidth = function() {
  5433.     return 48;
  5434. };
  5435.  
  5436. Game_Map.prototype.tileHeight = function() {
  5437.     return 48;
  5438. };
  5439.  
  5440. Game_Map.prototype.mapId = function() {
  5441.     return this._mapId;
  5442. };
  5443.  
  5444. Game_Map.prototype.tilesetId = function() {
  5445.     return this._tilesetId;
  5446. };
  5447.  
  5448. Game_Map.prototype.displayX = function() {
  5449.     return this._displayX;
  5450. };
  5451.  
  5452. Game_Map.prototype.displayY = function() {
  5453.     return this._displayY;
  5454. };
  5455.  
  5456. Game_Map.prototype.parallaxName = function() {
  5457.     return this._parallaxName;
  5458. };
  5459.  
  5460. Game_Map.prototype.battleback1Name = function() {
  5461.     return this._battleback1Name;
  5462. };
  5463.  
  5464. Game_Map.prototype.battleback2Name = function() {
  5465.     return this._battleback2Name;
  5466. };
  5467.  
  5468. Game_Map.prototype.requestRefresh = function(mapId) {
  5469.     this._needsRefresh = true;
  5470. };
  5471.  
  5472. Game_Map.prototype.isNameDisplayEnabled = function() {
  5473.     return this._nameDisplay;
  5474. };
  5475.  
  5476. Game_Map.prototype.disableNameDisplay = function() {
  5477.     this._nameDisplay = false;
  5478. };
  5479.  
  5480. Game_Map.prototype.enableNameDisplay = function() {
  5481.     this._nameDisplay = true;
  5482. };
  5483.  
  5484. Game_Map.prototype.createVehicles = function() {
  5485.     this._vehicles = [];
  5486.     this._vehicles[0] = new Game_Vehicle('boat');
  5487.     this._vehicles[1] = new Game_Vehicle('ship');
  5488.     this._vehicles[2] = new Game_Vehicle('airship');
  5489. };
  5490.  
  5491. Game_Map.prototype.refereshVehicles = function() {
  5492.     this._vehicles.forEach(function(vehicle) {
  5493.         vehicle.refresh();
  5494.     });
  5495. };
  5496.  
  5497. Game_Map.prototype.vehicles = function() {
  5498.     return this._vehicles;
  5499. };
  5500.  
  5501. Game_Map.prototype.vehicle = function(type) {
  5502.     if (type ===  0 || type === 'boat') {
  5503.         return this.boat();
  5504.     } else if (type ===  1 || type === 'ship') {
  5505.         return this.ship();
  5506.     } else if (type ===  2 || type === 'airship') {
  5507.         return this.airship();
  5508.     } else {
  5509.         return null;
  5510.     }
  5511. };
  5512.  
  5513. Game_Map.prototype.boat = function() {
  5514.     return this._vehicles[0];
  5515. };
  5516.  
  5517. Game_Map.prototype.ship = function() {
  5518.     return this._vehicles[1];
  5519. };
  5520.  
  5521. Game_Map.prototype.airship = function() {
  5522.     return this._vehicles[2];
  5523. };
  5524.  
  5525. Game_Map.prototype.setupEvents = function() {
  5526.     this._events = [];
  5527.     for (var i = 0; i < $dataMap.events.length; i++) {
  5528.         if ($dataMap.events[i]) {
  5529.             this._events[i] = new Game_Event(this._mapId, i);
  5530.         }
  5531.     }
  5532.     this._commonEvents = this.parallelCommonEvents().map(function(commonEvent) {
  5533.         return new Game_CommonEvent(commonEvent.id);
  5534.     });
  5535.     this.refreshTileEvents();
  5536. };
  5537.  
  5538. Game_Map.prototype.events = function() {
  5539.     return this._events.filter(function(event) {
  5540.         return !!event;
  5541.     });
  5542. };
  5543.  
  5544. Game_Map.prototype.event = function(eventId) {
  5545.     return this._events[eventId];
  5546. };
  5547.  
  5548. Game_Map.prototype.eraseEvent = function(eventId) {
  5549.     this._events[eventId].erase();
  5550. };
  5551.  
  5552. Game_Map.prototype.parallelCommonEvents = function() {
  5553.     return $dataCommonEvents.filter(function(commonEvent) {
  5554.         return commonEvent && commonEvent.trigger === 2;
  5555.     });
  5556. };
  5557.  
  5558. Game_Map.prototype.setupScroll = function() {
  5559.     this._scrollDirection = 2;
  5560.     this._scrollRest = 0;
  5561.     this._scrollSpeed = 4;
  5562. };
  5563.  
  5564. Game_Map.prototype.setupParallax = function() {
  5565.     this._parallaxName = $dataMap.parallaxName || '';
  5566.     this._parallaxZero = ImageManager.isZeroParallax(this._parallaxName);
  5567.     this._parallaxLoopX = $dataMap.parallaxLoopX;
  5568.     this._parallaxLoopY = $dataMap.parallaxLoopY;
  5569.     this._parallaxSx = $dataMap.parallaxSx;
  5570.     this._parallaxSy = $dataMap.parallaxSy;
  5571.     this._parallaxX = 0;
  5572.     this._parallaxY = 0;
  5573. };
  5574.  
  5575. Game_Map.prototype.setupBattleback = function() {
  5576.     if ($dataMap.specifyBattleback) {
  5577.         this._battleback1Name = $dataMap.battleback1Name;
  5578.         this._battleback2Name = $dataMap.battleback2Name;
  5579.     } else {
  5580.         this._battleback1Name = null;
  5581.         this._battleback2Name = null;
  5582.     }
  5583. };
  5584.  
  5585. Game_Map.prototype.setDisplayPos = function(x, y) {
  5586.     if (this.isLoopHorizontal()) {
  5587.         this._displayX = x.mod(this.width());
  5588.         this._parallaxX = x;
  5589.     } else {
  5590.         var endX = this.width() - this.screenTileX();
  5591.         this._displayX = endX < 0 ? endX / 2 : x.clamp(0, endX);
  5592.         this._parallaxX = this._displayX;
  5593.     }
  5594.     if (this.isLoopVertical()) {
  5595.         this._displayY = y.mod(this.height());
  5596.         this._parallaxY = y;
  5597.     } else {
  5598.         var endY = this.height() - this.screenTileY();
  5599.         this._displayY = endY < 0 ? endY / 2 : y.clamp(0, endY);
  5600.         this._parallaxY = this._displayY;
  5601.     }
  5602. };
  5603.  
  5604. Game_Map.prototype.parallaxOx = function() {
  5605.     if (this._parallaxZero) {
  5606.         return this._parallaxX * this.tileWidth();
  5607.     } else if (this._parallaxLoopX) {
  5608.         return this._parallaxX * this.tileWidth() / 2;
  5609.     } else {
  5610.         return 0;
  5611.     }
  5612. };
  5613.  
  5614. Game_Map.prototype.parallaxOy = function() {
  5615.     if (this._parallaxZero) {
  5616.         return this._parallaxY * this.tileHeight();
  5617.     } else if (this._parallaxLoopY) {
  5618.         return this._parallaxY * this.tileHeight() / 2;
  5619.     } else {
  5620.         return 0;
  5621.     }
  5622. };
  5623.  
  5624. Game_Map.prototype.tileset = function() {
  5625.     return $dataTilesets[this._tilesetId];
  5626. };
  5627.  
  5628. Game_Map.prototype.tilesetFlags = function() {
  5629.     var tileset = this.tileset();
  5630.     if (tileset) {
  5631.         return tileset.flags;
  5632.     } else {
  5633.         return [];
  5634.     }
  5635. };
  5636.  
  5637. Game_Map.prototype.displayName = function() {
  5638.     return $dataMap.displayName;
  5639. };
  5640.  
  5641. Game_Map.prototype.width = function() {
  5642.     return $dataMap.width;
  5643. };
  5644.  
  5645. Game_Map.prototype.height = function() {
  5646.     return $dataMap.height;
  5647. };
  5648.  
  5649. Game_Map.prototype.data = function() {
  5650.     return $dataMap.data;
  5651. };
  5652.  
  5653. Game_Map.prototype.isLoopHorizontal = function() {
  5654.     return $dataMap.scrollType === 2 || $dataMap.scrollType === 3;
  5655. };
  5656.  
  5657. Game_Map.prototype.isLoopVertical = function() {
  5658.     return $dataMap.scrollType === 1 || $dataMap.scrollType === 3;
  5659. };
  5660.  
  5661. Game_Map.prototype.isDashDisabled = function() {
  5662.     return $dataMap.disableDashing;
  5663. };
  5664.  
  5665. Game_Map.prototype.encounterList = function() {
  5666.     return $dataMap.encounterList;
  5667. };
  5668.  
  5669. Game_Map.prototype.encounterStep = function() {
  5670.     return $dataMap.encounterStep;
  5671. };
  5672.  
  5673. Game_Map.prototype.isOverworld = function() {
  5674.     return this.tileset() && this.tileset().mode === 0;
  5675. };
  5676.  
  5677. Game_Map.prototype.screenTileX = function() {
  5678.     return Graphics.width / this.tileWidth();
  5679. };
  5680.  
  5681. Game_Map.prototype.screenTileY = function() {
  5682.     return Graphics.height / this.tileHeight();
  5683. };
  5684.  
  5685. Game_Map.prototype.adjustX = function(x) {
  5686.     if (this.isLoopHorizontal() && x < this._displayX -
  5687.             (this.width() - this.screenTileX()) / 2) {
  5688.         return x - this._displayX + $dataMap.width;
  5689.     } else {
  5690.         return x - this._displayX;
  5691.     }
  5692. };
  5693.  
  5694. Game_Map.prototype.adjustY = function(y) {
  5695.     if (this.isLoopVertical() && y < this._displayY -
  5696.             (this.height() - this.screenTileY()) / 2) {
  5697.         return y - this._displayY + $dataMap.height;
  5698.     } else {
  5699.         return y - this._displayY;
  5700.     }
  5701. };
  5702.  
  5703. Game_Map.prototype.roundX = function(x) {
  5704.     return this.isLoopHorizontal() ? x.mod(this.width()) : x;
  5705. };
  5706.  
  5707. Game_Map.prototype.roundY = function(y) {
  5708.     return this.isLoopVertical() ? y.mod(this.height()) : y;
  5709. };
  5710.  
  5711. Game_Map.prototype.xWithDirection = function(x, d) {
  5712.     return x + (d === 6 ? 1 : d === 4 ? -1 : 0);
  5713. };
  5714.  
  5715. Game_Map.prototype.yWithDirection = function(y, d) {
  5716.     return y + (d === 2 ? 1 : d === 8 ? -1 : 0);
  5717. };
  5718.  
  5719. Game_Map.prototype.roundXWithDirection = function(x, d) {
  5720.     return this.roundX(x + (d === 6 ? 1 : d === 4 ? -1 : 0));
  5721. };
  5722.  
  5723. Game_Map.prototype.roundYWithDirection = function(y, d) {
  5724.     return this.roundY(y + (d === 2 ? 1 : d === 8 ? -1 : 0));
  5725. };
  5726.  
  5727. Game_Map.prototype.deltaX = function(x1, x2) {
  5728.     var result = x1 - x2;
  5729.     if (this.isLoopHorizontal() && Math.abs(result) > this.width() / 2) {
  5730.         if (result < 0) {
  5731.             result += this.width();
  5732.         } else {
  5733.             result -= this.width();
  5734.         }
  5735.     }
  5736.     return result;
  5737. };
  5738.  
  5739. Game_Map.prototype.deltaY = function(y1, y2) {
  5740.     var result = y1 - y2;
  5741.     if (this.isLoopVertical() && Math.abs(result) > this.height() / 2) {
  5742.         if (result < 0) {
  5743.             result += this.height();
  5744.         } else {
  5745.             result -= this.height();
  5746.         }
  5747.     }
  5748.     return result;
  5749. };
  5750.  
  5751. Game_Map.prototype.distance = function(x1, y1, x2, y2) {
  5752.     return Math.abs(this.deltaX(x1, x2)) + Math.abs(this.deltaY(y1, y2));
  5753. };
  5754.  
  5755. Game_Map.prototype.canvasToMapX = function(x) {
  5756.     var tileWidth = this.tileWidth();
  5757.     var originX = this._displayX * tileWidth;
  5758.     var mapX = Math.floor((originX + x) / tileWidth);
  5759.     return this.roundX(mapX);
  5760. };
  5761.  
  5762. Game_Map.prototype.canvasToMapY = function(y) {
  5763.     var tileHeight = this.tileHeight();
  5764.     var originY = this._displayY * tileHeight;
  5765.     var mapY = Math.floor((originY + y) / tileHeight);
  5766.     return this.roundY(mapY);
  5767. };
  5768.  
  5769. Game_Map.prototype.autoplay = function() {
  5770.     if ($dataMap.autoplayBgm) {
  5771.         AudioManager.playBgm($dataMap.bgm);
  5772.     }
  5773.     if ($dataMap.autoplayBgs) {
  5774.         AudioManager.playBgs($dataMap.bgs);
  5775.     }
  5776. };
  5777.  
  5778. Game_Map.prototype.refreshIfNeeded = function() {
  5779.     if (this._needsRefresh) {
  5780.         this.refresh();
  5781.     }
  5782. };
  5783.  
  5784. Game_Map.prototype.refresh = function() {
  5785.     this.events().forEach(function(event) {
  5786.         event.refresh();
  5787.     });
  5788.     this._commonEvents.forEach(function(event) {
  5789.         event.refresh();
  5790.     });
  5791.     this.refreshTileEvents();
  5792.     this._needsRefresh = false;
  5793. };
  5794.  
  5795. Game_Map.prototype.refreshTileEvents = function() {
  5796.     this.tileEvents = this.events().filter(function(event) {
  5797.         return event.isTile();
  5798.     });
  5799. };
  5800.  
  5801. Game_Map.prototype.eventsXy = function(x, y) {
  5802.     return this.events().filter(function(event) {
  5803.         return event.pos(x, y);
  5804.     });
  5805. };
  5806.  
  5807. Game_Map.prototype.eventsXyNt = function(x, y) {
  5808.     return this.events().filter(function(event) {
  5809.         return event.posNt(x, y);
  5810.     });
  5811. };
  5812.  
  5813. Game_Map.prototype.tileEventsXy = function(x, y) {
  5814.     return this.tileEvents.filter(function(event) {
  5815.         return event.posNt(x, y);
  5816.     });
  5817. };
  5818.  
  5819. Game_Map.prototype.eventIdXy = function(x, y) {
  5820.     var list = this.eventsXy(x, y);
  5821.     return list.length === 0 ? 0 : list[0].eventId();
  5822. };
  5823.  
  5824. Game_Map.prototype.scrollDown = function(distance) {
  5825.     if (this.isLoopVertical()) {
  5826.         this._displayY += distance;
  5827.         this._displayY %= $dataMap.height;
  5828.         if (this._parallaxLoopY) {
  5829.             this._parallaxY += distance;
  5830.         }
  5831.     } else if (this.height() >= this.screenTileY()) {
  5832.         var lastY = this._displayY;
  5833.         this._displayY = Math.min(this._displayY + distance,
  5834.             this.height() - this.screenTileY());
  5835.         this._parallaxY += this._displayY - lastY;
  5836.     }
  5837. };
  5838.  
  5839. Game_Map.prototype.scrollLeft = function(distance) {
  5840.     if (this.isLoopHorizontal()) {
  5841.         this._displayX += $dataMap.width - distance;
  5842.         this._displayX %= $dataMap.width;
  5843.         if (this._parallaxLoopX) {
  5844.             this._parallaxX -= distance;
  5845.         }
  5846.     } else if (this.width() >= this.screenTileX()) {
  5847.         var lastX = this._displayX;
  5848.         this._displayX = Math.max(this._displayX - distance, 0);
  5849.         this._parallaxX += this._displayX - lastX;
  5850.     }
  5851. };
  5852.  
  5853. Game_Map.prototype.scrollRight = function(distance) {
  5854.     if (this.isLoopHorizontal()) {
  5855.         this._displayX += distance;
  5856.         this._displayX %= $dataMap.width;
  5857.         if (this._parallaxLoopX) {
  5858.             this._parallaxX += distance;
  5859.         }
  5860.     } else if (this.width() >= this.screenTileX()) {
  5861.         var lastX = this._displayX;
  5862.         this._displayX = Math.min(this._displayX + distance,
  5863.             this.width() - this.screenTileX());
  5864.         this._parallaxX += this._displayX - lastX;
  5865.     }
  5866. };
  5867.  
  5868. Game_Map.prototype.scrollUp = function(distance) {
  5869.     if (this.isLoopVertical()) {
  5870.         this._displayY += $dataMap.height - distance;
  5871.         this._displayY %= $dataMap.height;
  5872.         if (this._parallaxLoopY) {
  5873.             this._parallaxY -= distance;
  5874.         }
  5875.     } else if (this.height() >= this.screenTileY()) {
  5876.         var lastY = this._displayY;
  5877.         this._displayY = Math.max(this._displayY - distance, 0);
  5878.         this._parallaxY += this._displayY - lastY;
  5879.     }
  5880. };
  5881.  
  5882. Game_Map.prototype.isValid = function(x, y) {
  5883.     return x >= 0 && x < this.width() && y >= 0 && y < this.height();
  5884. };
  5885.  
  5886. Game_Map.prototype.checkPassage = function(x, y, bit) {
  5887.     var flags = this.tilesetFlags();
  5888.     var tiles = this.allTiles(x, y);
  5889.     for (var i = 0; i < tiles.length; i++) {
  5890.         var flag = flags[tiles[i]];
  5891.         if ((flag & 0x10) !== 0)  // [*] No effect on passage
  5892.             continue;
  5893.         if ((flag & bit) === 0)   // [o] Passable
  5894.             return true;
  5895.         if ((flag & bit) === bit) // [x] Impassable
  5896.             return false;
  5897.     }
  5898.     return false;
  5899. };
  5900.  
  5901. Game_Map.prototype.tileId = function(x, y, z) {
  5902.     var width = $dataMap.width;
  5903.     var height = $dataMap.height;
  5904.     return $dataMap.data[(z * height + y) * width + x] || 0;
  5905. };
  5906.  
  5907. Game_Map.prototype.layeredTiles = function(x, y) {
  5908.     var tiles = [];
  5909.     for (var i = 0; i < 4; i++) {
  5910.         tiles.push(this.tileId(x, y, 3 - i));
  5911.     }
  5912.     return tiles;
  5913. };
  5914.  
  5915. Game_Map.prototype.allTiles = function(x, y) {
  5916.     var tiles = this.tileEventsXy(x, y).map(function(event) {
  5917.         return event.tileId();
  5918.     });
  5919.     return tiles.concat(this.layeredTiles(x, y));
  5920. };
  5921.  
  5922. Game_Map.prototype.autotileType = function(x, y, z) {
  5923.     var tileId = this.tileId(x, y, z);
  5924.     return tileId >= 2048 ? Math.floor((tileId - 2048) / 48) : -1;
  5925. };
  5926.  
  5927. Game_Map.prototype.isPassable = function(x, y, d) {
  5928.     return this.checkPassage(x, y, (1 << (d / 2 - 1)) & 0x0f);
  5929. };
  5930.  
  5931. Game_Map.prototype.isBoatPassable = function(x, y) {
  5932.     return this.checkPassage(x, y, 0x0200);
  5933. };
  5934.  
  5935. Game_Map.prototype.isShipPassable = function(x, y) {
  5936.     return this.checkPassage(x, y, 0x0400);
  5937. };
  5938.  
  5939. Game_Map.prototype.isAirshipLandOk = function(x, y) {
  5940.     return this.checkPassage(x, y, 0x0800) && this.checkPassage(x, y, 0x0f);
  5941. };
  5942.  
  5943. Game_Map.prototype.checkLayeredTilesFlags = function(x, y, bit) {
  5944.     var flags = this.tilesetFlags();
  5945.     return this.layeredTiles(x, y).some(function(tileId) {
  5946.         return (flags[tileId] & bit) !== 0;
  5947.     });
  5948. };
  5949.  
  5950. Game_Map.prototype.isLadder = function(x, y) {
  5951.     return this.isValid(x, y) && this.checkLayeredTilesFlags(x, y, 0x20);
  5952. };
  5953.  
  5954. Game_Map.prototype.isBush = function(x, y) {
  5955.     return this.isValid(x, y) && this.checkLayeredTilesFlags(x, y, 0x40);
  5956. };
  5957.  
  5958. Game_Map.prototype.isCounter = function(x, y) {
  5959.     return this.isValid(x, y) && this.checkLayeredTilesFlags(x, y, 0x80);
  5960. };
  5961.  
  5962. Game_Map.prototype.isDamageFloor = function(x, y) {
  5963.     return this.isValid(x, y) && this.checkLayeredTilesFlags(x, y, 0x100);
  5964. };
  5965.  
  5966. Game_Map.prototype.terrainTag = function(x, y) {
  5967.     if (this.isValid(x, y)) {
  5968.         var flags = this.tilesetFlags();
  5969.         var tiles = this.layeredTiles(x, y);
  5970.         for (var i = 0; i < tiles.length; i++) {
  5971.             var tag = flags[tiles[i]] >> 12;
  5972.             if (tag > 0) {
  5973.                 return tag;
  5974.             }
  5975.         }
  5976.     }
  5977.     return 0;
  5978. };
  5979.  
  5980. Game_Map.prototype.regionId = function(x, y) {
  5981.     return this.isValid(x, y) ? this.tileId(x, y, 5) : 0;
  5982. };
  5983.  
  5984. Game_Map.prototype.startScroll = function(direction, distance, speed) {
  5985.     this._scrollDirection = direction;
  5986.     this._scrollRest = distance;
  5987.     this._scrollSpeed = speed;
  5988. };
  5989.  
  5990. Game_Map.prototype.isScrolling = function() {
  5991.     return this._scrollRest > 0;
  5992. };
  5993.  
  5994. Game_Map.prototype.update = function(sceneActive) {
  5995.     this.refreshIfNeeded();
  5996.     if (sceneActive) {
  5997.         this.updateInterpreter();
  5998.     }
  5999.     this.updateScroll();
  6000.     this.updateEvents();
  6001.     this.updateVehicles();
  6002.     this.updateParallax();
  6003. };
  6004.  
  6005. Game_Map.prototype.updateScroll = function() {
  6006.     if (this.isScrolling()) {
  6007.         var lastX = this._displayX;
  6008.         var lastY = this._displayY;
  6009.         this.doScroll(this._scrollDirection, this.scrollDistance());
  6010.         if (this._displayX === lastX && this._displayY === lastY) {
  6011.             this._scrollRest = 0;
  6012.         } else {
  6013.             this._scrollRest -= this.scrollDistance();
  6014.         }
  6015.     }
  6016. };
  6017.  
  6018. Game_Map.prototype.scrollDistance = function() {
  6019.     return Math.pow(2, this._scrollSpeed) / 256;
  6020. };
  6021.  
  6022. Game_Map.prototype.doScroll = function(direction, distance) {
  6023.     switch (direction) {
  6024.     case 2:
  6025.         this.scrollDown(distance);
  6026.         break;
  6027.     case 4:
  6028.         this.scrollLeft(distance);
  6029.         break;
  6030.     case 6:
  6031.         this.scrollRight(distance);
  6032.         break;
  6033.     case 8:
  6034.         this.scrollUp(distance);
  6035.         break;
  6036.     }
  6037. };
  6038.  
  6039. Game_Map.prototype.updateEvents = function() {
  6040.     this.events().forEach(function(event) {
  6041.         event.update();
  6042.     });
  6043.     this._commonEvents.forEach(function(event) {
  6044.         event.update();
  6045.     });
  6046. };
  6047.  
  6048. Game_Map.prototype.updateVehicles = function() {
  6049.     this._vehicles.forEach(function(vehicle) {
  6050.         vehicle.update();
  6051.     });
  6052. };
  6053.  
  6054. Game_Map.prototype.updateParallax = function() {
  6055.     if (this._parallaxLoopX) {
  6056.         this._parallaxX += this._parallaxSx / this.tileWidth() / 2;
  6057.     }
  6058.     if (this._parallaxLoopY) {
  6059.         this._parallaxY += this._parallaxSy / this.tileHeight() / 2;
  6060.     }
  6061. };
  6062.  
  6063. Game_Map.prototype.changeTileset = function(tilesetId) {
  6064.     this._tilesetId = tilesetId;
  6065.     this.refresh();
  6066. };
  6067.  
  6068. Game_Map.prototype.changeBattleback = function(battleback1Name, battleback2Name) {
  6069.     this._battleback1Name = battleback1Name;
  6070.     this._battleback2Name = battleback2Name;
  6071. };
  6072.  
  6073. Game_Map.prototype.changeParallax = function(name, loopX, loopY, sx, sy) {
  6074.     this._parallaxName = name;
  6075.     this._parallaxZero = ImageManager.isZeroParallax(this._parallaxName);
  6076.     if (this._parallaxLoopX && !loopX) {
  6077.         this._parallaxX = 0;
  6078.     }
  6079.     if (this._parallaxLoopY && !loopY) {
  6080.         this._parallaxY = 0;
  6081.     }
  6082.     this._parallaxLoopX = loopX;
  6083.     this._parallaxLoopY = loopY;
  6084.     this._parallaxSx = sx;
  6085.     this._parallaxSy = sy;
  6086. };
  6087.  
  6088. Game_Map.prototype.updateInterpreter = function() {
  6089.     for (;;) {
  6090.         this._interpreter.update();
  6091.         if (this._interpreter.isRunning()) {
  6092.             return;
  6093.         }
  6094.         if (this._interpreter.eventId() > 0) {
  6095.             this.unlockEvent(this._interpreter.eventId());
  6096.             this._interpreter.clear();
  6097.         }
  6098.         if (!this.setupStartingEvent()) {
  6099.             return;
  6100.         }
  6101.     }
  6102. };
  6103.  
  6104. Game_Map.prototype.unlockEvent = function(eventId) {
  6105.     if (this._events[eventId]) {
  6106.         this._events[eventId].unlock();
  6107.     }
  6108. };
  6109.  
  6110. Game_Map.prototype.setupStartingEvent = function() {
  6111.     this.refreshIfNeeded();
  6112.     if (this._interpreter.setupReservedCommonEvent()) {
  6113.         return true;
  6114.     }
  6115.     if (this.setupTestEvent()) {
  6116.         return true;
  6117.     }
  6118.     if (this.setupStartingMapEvent()) {
  6119.         return true;
  6120.     }
  6121.     if (this.setupAutorunCommonEvent()) {
  6122.         return true;
  6123.     }
  6124.     return false;
  6125. };
  6126.  
  6127. Game_Map.prototype.setupTestEvent = function() {
  6128.     if ($testEvent) {
  6129.         this._interpreter.setup($testEvent, 0);
  6130.         $testEvent = null;
  6131.         return true;
  6132.     }
  6133.     return false;
  6134. };
  6135.  
  6136. Game_Map.prototype.setupStartingMapEvent = function() {
  6137.     var events = this.events();
  6138.     for (var i = 0; i < events.length; i++) {
  6139.         var event = events[i];
  6140.         if (event.isStarting()) {
  6141.             event.clearStartingFlag();
  6142.             this._interpreter.setup(event.list(), event.eventId());
  6143.             return true;
  6144.         }
  6145.     }
  6146.     return false;
  6147. };
  6148.  
  6149. Game_Map.prototype.setupAutorunCommonEvent = function() {
  6150.     for (var i = 0; i < $dataCommonEvents.length; i++) {
  6151.         var event = $dataCommonEvents[i];
  6152.         if (event && event.trigger === 1 && $gameSwitches.value(event.switchId)) {
  6153.             this._interpreter.setup(event.list);
  6154.             return true;
  6155.         }
  6156.     }
  6157.     return false;
  6158. };
  6159.  
  6160. Game_Map.prototype.isAnyEventStarting = function() {
  6161.     return this.events().some(function(event) {
  6162.         return event.isStarting();
  6163.     });
  6164. };
  6165.  
  6166. //-----------------------------------------------------------------------------
  6167. // Game_CommonEvent
  6168. //
  6169. // The game object class for a common event. It contains functionality for
  6170. // running parallel process events.
  6171.  
  6172. function Game_CommonEvent() {
  6173.     this.initialize.apply(this, arguments);
  6174. }
  6175.  
  6176. Game_CommonEvent.prototype.initialize = function(commonEventId) {
  6177.     this._commonEventId = commonEventId;
  6178.     this.refresh();
  6179. };
  6180.  
  6181. Game_CommonEvent.prototype.event = function() {
  6182.     return $dataCommonEvents[this._commonEventId];
  6183. };
  6184.  
  6185. Game_CommonEvent.prototype.list = function() {
  6186.     return this.event().list;
  6187. };
  6188.  
  6189. Game_CommonEvent.prototype.refresh = function() {
  6190.     if (this.isActive()) {
  6191.         if (!this._interpreter) {
  6192.             this._interpreter = new Game_Interpreter();
  6193.         }
  6194.     } else {
  6195.         this._interpreter = null;
  6196.     }
  6197. };
  6198.  
  6199. Game_CommonEvent.prototype.isActive = function() {
  6200.     var event = this.event();
  6201.     return event.trigger === 2 && $gameSwitches.value(event.switchId);
  6202. };
  6203.  
  6204. Game_CommonEvent.prototype.update = function() {
  6205.     if (this._interpreter) {
  6206.         if (!this._interpreter.isRunning()) {
  6207.             this._interpreter.setup(this.list());
  6208.         }
  6209.         this._interpreter.update();
  6210.     }
  6211. };
  6212.  
  6213. //-----------------------------------------------------------------------------
  6214. // Game_CharacterBase
  6215. //
  6216. // The superclass of Game_Character. It handles basic information, such as
  6217. // coordinates and images, shared by all characters.
  6218.  
  6219. function Game_CharacterBase() {
  6220.     this.initialize.apply(this, arguments);
  6221. }
  6222.  
  6223. Object.defineProperties(Game_CharacterBase.prototype, {
  6224.     x: { get: function() { return this._x; }, configurable: true },
  6225.     y: { get: function() { return this._y; }, configurable: true }
  6226. });
  6227.  
  6228. Game_CharacterBase.prototype.initialize = function() {
  6229.     this.initMembers();
  6230. };
  6231.  
  6232. Game_CharacterBase.prototype.initMembers = function() {
  6233.     this._x = 0;
  6234.     this._y = 0;
  6235.     this._realX = 0;
  6236.     this._realY = 0;
  6237.     this._moveSpeed = 4;
  6238.     this._moveFrequency = 6;
  6239.     this._opacity = 255;
  6240.     this._blendMode = 0;
  6241.     this._direction = 2;
  6242.     this._pattern = 1;
  6243.     this._priorityType = 1;
  6244.     this._tileId = 0;
  6245.     this._characterName = '';
  6246.     this._characterIndex = 0;
  6247.     this._isObjectCharacter = false;
  6248.     this._walkAnime = true;
  6249.     this._stepAnime = false;
  6250.     this._directionFix = false;
  6251.     this._through = false;
  6252.     this._transparent = false;
  6253.     this._bushDepth = 0;
  6254.     this._animationId = 0;
  6255.     this._balloonId = 0;
  6256.     this._animationPlaying = false;
  6257.     this._balloonPlaying = false;
  6258.     this._animationCount = 0;
  6259.     this._stopCount = 0;
  6260.     this._jumpCount = 0;
  6261.     this._jumpPeak = 0;
  6262.     this._movementSuccess = true;
  6263. };
  6264.  
  6265. Game_CharacterBase.prototype.pos = function(x, y) {
  6266.     return this._x === x && this._y === y;
  6267. };
  6268.  
  6269. Game_CharacterBase.prototype.posNt = function(x, y) {
  6270.     // No through
  6271.     return this.pos(x, y) && !this.isThrough();
  6272. };
  6273.  
  6274. Game_CharacterBase.prototype.moveSpeed = function() {
  6275.     return this._moveSpeed;
  6276. };
  6277.  
  6278. Game_CharacterBase.prototype.setMoveSpeed = function(moveSpeed) {
  6279.     this._moveSpeed = moveSpeed;
  6280. };
  6281.  
  6282. Game_CharacterBase.prototype.moveFrequency = function() {
  6283.     return this._moveFrequency;
  6284. };
  6285.  
  6286. Game_CharacterBase.prototype.setMoveFrequency = function(moveFrequency) {
  6287.     this._moveFrequency = moveFrequency;
  6288. };
  6289.  
  6290. Game_CharacterBase.prototype.opacity = function() {
  6291.     return this._opacity;
  6292. };
  6293.  
  6294. Game_CharacterBase.prototype.setOpacity = function(opacity) {
  6295.     this._opacity = opacity;
  6296. };
  6297.  
  6298. Game_CharacterBase.prototype.blendMode = function() {
  6299.     return this._blendMode;
  6300. };
  6301.  
  6302. Game_CharacterBase.prototype.setBlendMode = function(blendMode) {
  6303.     this._blendMode = blendMode;
  6304. };
  6305.  
  6306. Game_CharacterBase.prototype.isNormalPriority = function() {
  6307.     return this._priorityType === 1;
  6308. };
  6309.  
  6310. Game_CharacterBase.prototype.setPriorityType = function(priorityType) {
  6311.     this._priorityType = priorityType;
  6312. };
  6313.  
  6314. Game_CharacterBase.prototype.isMoving = function() {
  6315.     return this._realX !== this._x || this._realY !== this._y;
  6316. };
  6317.  
  6318. Game_CharacterBase.prototype.isJumping = function() {
  6319.     return this._jumpCount > 0;
  6320. };
  6321.  
  6322. Game_CharacterBase.prototype.jumpHeight = function() {
  6323.     return (this._jumpPeak * this._jumpPeak -
  6324.             Math.pow(Math.abs(this._jumpCount - this._jumpPeak), 2)) / 2;
  6325. };
  6326.  
  6327. Game_CharacterBase.prototype.isStopping = function() {
  6328.     return !this.isMoving() && !this.isJumping();
  6329. };
  6330.  
  6331. Game_CharacterBase.prototype.checkStop = function(threshold) {
  6332.     return this._stopCount > threshold;
  6333. };
  6334.  
  6335. Game_CharacterBase.prototype.resetStopCount = function() {
  6336.     this._stopCount = 0;
  6337. };
  6338.  
  6339. Game_CharacterBase.prototype.realMoveSpeed = function() {
  6340.     return this._moveSpeed + (this.isDashing() ? 1 : 0);
  6341. };
  6342.  
  6343. Game_CharacterBase.prototype.distancePerFrame = function() {
  6344.     return Math.pow(2, this.realMoveSpeed()) / 256;
  6345. };
  6346.  
  6347. Game_CharacterBase.prototype.isDashing = function() {
  6348.     return false;
  6349. };
  6350.  
  6351. Game_CharacterBase.prototype.isDebugThrough = function() {
  6352.     return false;
  6353. };
  6354.  
  6355. Game_CharacterBase.prototype.straighten = function() {
  6356.     if (this.hasWalkAnime() || this.hasStepAnime()) {
  6357.         this._pattern = 1;
  6358.     }
  6359.     this._animationCount = 0;
  6360. };
  6361.  
  6362. Game_CharacterBase.prototype.reverseDir = function(d) {
  6363.     return 10 - d;
  6364. };
  6365.  
  6366. Game_CharacterBase.prototype.canPass = function(x, y, d) {
  6367.     var x2 = $gameMap.roundXWithDirection(x, d);
  6368.     var y2 = $gameMap.roundYWithDirection(y, d);
  6369.     if (!$gameMap.isValid(x2, y2)) {
  6370.         return false;
  6371.     }
  6372.     if (this.isThrough() || this.isDebugThrough()) {
  6373.         return true;
  6374.     }
  6375.     if (!this.isMapPassable(x, y, d)) {
  6376.         return false;
  6377.     }
  6378.     if (this.isCollidedWithCharacters(x2, y2)) {
  6379.         return false;
  6380.     }
  6381.     return true;
  6382. };
  6383.  
  6384. Game_CharacterBase.prototype.canPassDiagonally = function(x, y, horz, vert) {
  6385.     var x2 = $gameMap.roundXWithDirection(x, horz);
  6386.     var y2 = $gameMap.roundYWithDirection(y, vert);
  6387.     if (this.canPass(x, y, vert) && this.canPass(x, y2, horz)) {
  6388.         return true;
  6389.     }
  6390.     if (this.canPass(x, y, horz) && this.canPass(x2, y, vert)) {
  6391.         return true;
  6392.     }
  6393.     return false;
  6394. };
  6395.  
  6396. Game_CharacterBase.prototype.isMapPassable = function(x, y, d) {
  6397.     var x2 = $gameMap.roundXWithDirection(x, d);
  6398.     var y2 = $gameMap.roundYWithDirection(y, d);
  6399.     var d2 = this.reverseDir(d);
  6400.     return $gameMap.isPassable(x, y, d) && $gameMap.isPassable(x2, y2, d2);
  6401. };
  6402.  
  6403. Game_CharacterBase.prototype.isCollidedWithCharacters = function(x, y) {
  6404.     return this.isCollidedWithEvents(x, y) || this.isCollidedWithVehicles(x, y);
  6405. };
  6406.  
  6407. Game_CharacterBase.prototype.isCollidedWithEvents = function(x, y) {
  6408.     var events = $gameMap.eventsXyNt(x, y);
  6409.     return events.some(function(event) {
  6410.         return event.isNormalPriority();
  6411.     });
  6412. };
  6413.  
  6414. Game_CharacterBase.prototype.isCollidedWithVehicles = function(x, y) {
  6415.     return $gameMap.boat().posNt(x, y) || $gameMap.ship().posNt(x, y);
  6416. };
  6417.  
  6418. Game_CharacterBase.prototype.setPosition = function(x, y) {
  6419.     this._x = Math.round(x);
  6420.     this._y = Math.round(y);
  6421.     this._realX = x;
  6422.     this._realY = y;
  6423. };
  6424.  
  6425. Game_CharacterBase.prototype.copyPosition = function(character) {
  6426.     this._x = character._x;
  6427.     this._y = character._y;
  6428.     this._realX = character._realX;
  6429.     this._realY = character._realY;
  6430.     this._direction = character._direction;
  6431. };
  6432.  
  6433. Game_CharacterBase.prototype.locate = function(x, y) {
  6434.     this.setPosition(x, y);
  6435.     this.straighten();
  6436.     this.refreshBushDepth();
  6437. };
  6438.  
  6439. Game_CharacterBase.prototype.direction = function() {
  6440.     return this._direction;
  6441. };
  6442.  
  6443. Game_CharacterBase.prototype.setDirection = function(d) {
  6444.     if (!this.isDirectionFixed() && d) {
  6445.         this._direction = d;
  6446.     }
  6447.     this.resetStopCount();
  6448. };
  6449.  
  6450. Game_CharacterBase.prototype.isTile = function() {
  6451.     return this._tileId > 0 && this._priorityType === 0;
  6452. };
  6453.  
  6454. Game_CharacterBase.prototype.isObjectCharacter = function() {
  6455.     return this._isObjectCharacter;
  6456. };
  6457.  
  6458. Game_CharacterBase.prototype.shiftY = function() {
  6459.     return this.isObjectCharacter() ? 0 : 6;
  6460. };
  6461.  
  6462. Game_CharacterBase.prototype.scrolledX = function() {
  6463.     return $gameMap.adjustX(this._realX);
  6464. };
  6465.  
  6466. Game_CharacterBase.prototype.scrolledY = function() {
  6467.     return $gameMap.adjustY(this._realY);
  6468. };
  6469.  
  6470. Game_CharacterBase.prototype.screenX = function() {
  6471.     var tw = $gameMap.tileWidth();
  6472.     return Math.round(this.scrolledX() * tw + tw / 2);
  6473. };
  6474.  
  6475. Game_CharacterBase.prototype.screenY = function() {
  6476.     var th = $gameMap.tileHeight();
  6477.     return Math.round(this.scrolledY() * th + th -
  6478.                       this.shiftY() - this.jumpHeight());
  6479. };
  6480.  
  6481. Game_CharacterBase.prototype.screenZ = function() {
  6482.     return this._priorityType * 2 + 1;
  6483. };
  6484.  
  6485. Game_CharacterBase.prototype.isNearTheScreen = function() {
  6486.     var gw = Graphics.width;
  6487.     var gh = Graphics.height;
  6488.     var tw = $gameMap.tileWidth();
  6489.     var th = $gameMap.tileHeight();
  6490.     var px = this.scrolledX() * tw + tw / 2 - gw / 2;
  6491.     var py = this.scrolledY() * th + th / 2 - gh / 2;
  6492.     return px >= -gw && px <= gw && py >= -gh && py <= gh;
  6493. };
  6494.  
  6495. Game_CharacterBase.prototype.update = function() {
  6496.     if (this.isStopping()) {
  6497.         this.updateStop();
  6498.     }
  6499.     if (this.isJumping()) {
  6500.         this.updateJump();
  6501.     } else if (this.isMoving()) {
  6502.         this.updateMove();
  6503.     }
  6504.     this.updateAnimation();
  6505. };
  6506.  
  6507. Game_CharacterBase.prototype.updateStop = function() {
  6508.     this._stopCount++;
  6509. };
  6510.  
  6511. Game_CharacterBase.prototype.updateJump = function() {
  6512.     this._jumpCount--;
  6513.     this._realX = (this._realX * this._jumpCount + this._x) / (this._jumpCount + 1.0);
  6514.     this._realY = (this._realY * this._jumpCount + this._y) / (this._jumpCount + 1.0);
  6515.     this.refreshBushDepth();
  6516.     if (this._jumpCount === 0) {
  6517.         this._realX = this._x = $gameMap.roundX(this._x);
  6518.         this._realY = this._y = $gameMap.roundY(this._y);
  6519.     }
  6520. };
  6521.  
  6522. Game_CharacterBase.prototype.updateMove = function() {
  6523.     if (this._x < this._realX) {
  6524.         this._realX = Math.max(this._realX - this.distancePerFrame(), this._x);
  6525.     }
  6526.     if (this._x > this._realX) {
  6527.         this._realX = Math.min(this._realX + this.distancePerFrame(), this._x);
  6528.     }
  6529.     if (this._y < this._realY) {
  6530.         this._realY = Math.max(this._realY - this.distancePerFrame(), this._y);
  6531.     }
  6532.     if (this._y > this._realY) {
  6533.         this._realY = Math.min(this._realY + this.distancePerFrame(), this._y);
  6534.     }
  6535.     if (!this.isMoving()) {
  6536.         this.refreshBushDepth();
  6537.     }
  6538. };
  6539.  
  6540. Game_CharacterBase.prototype.updateAnimation = function() {
  6541.     this.updateAnimationCount();
  6542.     if (this._animationCount >= this.animationWait()) {
  6543.         this.updatePattern();
  6544.         this._animationCount = 0;
  6545.     }
  6546. };
  6547.  
  6548. Game_CharacterBase.prototype.animationWait = function() {
  6549.     return (9 - this.realMoveSpeed()) * 3;
  6550. };
  6551.  
  6552. Game_CharacterBase.prototype.updateAnimationCount = function() {
  6553.     if (this.isMoving() && this.hasWalkAnime()) {
  6554.         this._animationCount += 1.5;
  6555.     } else if (this.hasStepAnime() || !this.isOriginalPattern()) {
  6556.         this._animationCount++;
  6557.     }
  6558. };
  6559.  
  6560. Game_CharacterBase.prototype.updatePattern = function() {
  6561.     if (!this.hasStepAnime() && this._stopCount > 0) {
  6562.         this.resetPattern();
  6563.     } else {
  6564.         this._pattern = (this._pattern + 1) % this.maxPattern();
  6565.     }
  6566. };
  6567.  
  6568. Game_CharacterBase.prototype.maxPattern = function() {
  6569.     return 4;
  6570. };
  6571.  
  6572. Game_CharacterBase.prototype.pattern = function() {
  6573.     return this._pattern < 3 ? this._pattern : 1;
  6574. };
  6575.  
  6576. Game_CharacterBase.prototype.setPattern = function(pattern) {
  6577.     this._pattern = pattern;
  6578. };
  6579.  
  6580. Game_CharacterBase.prototype.isOriginalPattern = function() {
  6581.     return this.pattern() === 1;
  6582. };
  6583.  
  6584. Game_CharacterBase.prototype.resetPattern = function() {
  6585.     this.setPattern(1);
  6586. };
  6587.  
  6588. Game_CharacterBase.prototype.refreshBushDepth = function() {
  6589.     if (this.isNormalPriority() && !this.isObjectCharacter() &&
  6590.             this.isOnBush() && !this.isJumping()) {
  6591.         if (!this.isMoving()) {
  6592.             this._bushDepth = 12;
  6593.         }
  6594.     } else {
  6595.         this._bushDepth = 0;
  6596.     }
  6597. };
  6598.  
  6599. Game_CharacterBase.prototype.isOnLadder = function() {
  6600.     return $gameMap.isLadder(this._x, this._y);
  6601. };
  6602.  
  6603. Game_CharacterBase.prototype.isOnBush = function() {
  6604.     return $gameMap.isBush(this._x, this._y);
  6605. };
  6606.  
  6607. Game_CharacterBase.prototype.terrainTag = function() {
  6608.     return $gameMap.terrainTag(this._x, this._y);
  6609. };
  6610.  
  6611. Game_CharacterBase.prototype.regionId = function() {
  6612.     return $gameMap.regionId(this._x, this._y);
  6613. };
  6614.  
  6615. Game_CharacterBase.prototype.increaseSteps = function() {
  6616.     if (this.isOnLadder()) {
  6617.         this.setDirection(8);
  6618.     }
  6619.     this.resetStopCount();
  6620.     this.refreshBushDepth();
  6621. };
  6622.  
  6623. Game_CharacterBase.prototype.tileId = function() {
  6624.     return this._tileId;
  6625. };
  6626.  
  6627. Game_CharacterBase.prototype.characterName = function() {
  6628.     return this._characterName;
  6629. };
  6630.  
  6631. Game_CharacterBase.prototype.characterIndex = function() {
  6632.     return this._characterIndex;
  6633. };
  6634.  
  6635. Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
  6636.     this._tileId = 0;
  6637.     this._characterName = characterName;
  6638.     this._characterIndex = characterIndex;
  6639.     this._isObjectCharacter = ImageManager.isObjectCharacter(characterName);
  6640. };
  6641.  
  6642. Game_CharacterBase.prototype.setTileImage = function(tileId) {
  6643.     this._tileId = tileId;
  6644.     this._characterName = '';
  6645.     this._characterIndex = 0;
  6646.     this._isObjectCharacter = true;
  6647. };
  6648.  
  6649. Game_CharacterBase.prototype.checkEventTriggerTouchFront = function(d) {
  6650.     var x2 = $gameMap.roundXWithDirection(this._x, d);
  6651.     var y2 = $gameMap.roundYWithDirection(this._y, d);
  6652.     this.checkEventTriggerTouch(x2, y2);
  6653. };
  6654.  
  6655. Game_CharacterBase.prototype.checkEventTriggerTouch = function(x, y) {
  6656.     return false;
  6657. };
  6658.  
  6659. Game_CharacterBase.prototype.isMovementSucceeded = function(x, y) {
  6660.     return this._movementSuccess;
  6661. };
  6662.  
  6663. Game_CharacterBase.prototype.setMovementSuccess = function(success) {
  6664.     this._movementSuccess = success;
  6665. };
  6666.  
  6667. Game_CharacterBase.prototype.moveStraight = function(d) {
  6668.     this.setMovementSuccess(this.canPass(this._x, this._y, d));
  6669.     if (this.isMovementSucceeded()) {
  6670.         this.setDirection(d);
  6671.         this._x = $gameMap.roundXWithDirection(this._x, d);
  6672.         this._y = $gameMap.roundYWithDirection(this._y, d);
  6673.         this._realX = $gameMap.xWithDirection(this._x, this.reverseDir(d));
  6674.         this._realY = $gameMap.yWithDirection(this._y, this.reverseDir(d));
  6675.         this.increaseSteps();
  6676.     } else {
  6677.         this.setDirection(d);
  6678.         this.checkEventTriggerTouchFront(d);
  6679.     }
  6680. };
  6681.  
  6682. Game_CharacterBase.prototype.moveDiagonally = function(horz, vert) {
  6683.     this.setMovementSuccess(this.canPassDiagonally(this._x, this._y, horz, vert));
  6684.     if (this.isMovementSucceeded()) {
  6685.         this._x = $gameMap.roundXWithDirection(this._x, horz);
  6686.         this._y = $gameMap.roundYWithDirection(this._y, vert);
  6687.         this._realX = $gameMap.xWithDirection(this._x, this.reverseDir(horz));
  6688.         this._realY = $gameMap.yWithDirection(this._y, this.reverseDir(vert));
  6689.         this.increaseSteps();
  6690.     }
  6691.     if (this._direction === this.reverseDir(horz)) {
  6692.         this.setDirection(horz);
  6693.     }
  6694.     if (this._direction === this.reverseDir(vert)) {
  6695.         this.setDirection(vert);
  6696.     }
  6697. };
  6698.  
  6699. Game_CharacterBase.prototype.jump = function(xPlus, yPlus) {
  6700.     if (Math.abs(xPlus) > Math.abs(yPlus)) {
  6701.         if (xPlus !== 0) {
  6702.             this.setDirection(xPlus < 0 ? 4 : 6);
  6703.         }
  6704.     } else {
  6705.         if (yPlus !== 0) {
  6706.             this.setDirection(yPlus < 0 ? 8 : 2);
  6707.         }
  6708.     }
  6709.     this._x += xPlus;
  6710.     this._y += yPlus;
  6711.     var distance = Math.round(Math.sqrt(xPlus * xPlus + yPlus * yPlus));
  6712.     this._jumpPeak = 10 + distance - this._moveSpeed;
  6713.     this._jumpCount = this._jumpPeak * 2;
  6714.     this.resetStopCount();
  6715.     this.straighten();
  6716. };
  6717.  
  6718. Game_CharacterBase.prototype.hasWalkAnime = function() {
  6719.     return this._walkAnime;
  6720. };
  6721.  
  6722. Game_CharacterBase.prototype.setWalkAnime = function(walkAnime) {
  6723.     this._walkAnime = walkAnime;
  6724. };
  6725.  
  6726. Game_CharacterBase.prototype.hasStepAnime = function() {
  6727.     return this._stepAnime;
  6728. };
  6729.  
  6730. Game_CharacterBase.prototype.setStepAnime = function(stepAnime) {
  6731.     this._stepAnime = stepAnime;
  6732. };
  6733.  
  6734. Game_CharacterBase.prototype.isDirectionFixed = function() {
  6735.     return this._directionFix;
  6736. };
  6737.  
  6738. Game_CharacterBase.prototype.setDirectionFix = function(directionFix) {
  6739.     this._directionFix = directionFix;
  6740. };
  6741.  
  6742. Game_CharacterBase.prototype.isThrough = function() {
  6743.     return this._through;
  6744. };
  6745.  
  6746. Game_CharacterBase.prototype.setThrough = function(through) {
  6747.     this._through = through;
  6748. };
  6749.  
  6750. Game_CharacterBase.prototype.isTransparent = function() {
  6751.     return this._transparent;
  6752. };
  6753.  
  6754. Game_CharacterBase.prototype.bushDepth = function() {
  6755.     return this._bushDepth;
  6756. };
  6757.  
  6758. Game_CharacterBase.prototype.setTransparent = function(transparent) {
  6759.     this._transparent = transparent;
  6760. };
  6761.  
  6762. Game_CharacterBase.prototype.requestAnimation = function(animationId) {
  6763.     this._animationId = animationId;
  6764. };
  6765.  
  6766. Game_CharacterBase.prototype.requestBalloon = function(balloonId) {
  6767.     this._balloonId = balloonId;
  6768. };
  6769.  
  6770. Game_CharacterBase.prototype.animationId = function() {
  6771.     return this._animationId;
  6772. };
  6773.  
  6774. Game_CharacterBase.prototype.balloonId = function() {
  6775.     return this._balloonId;
  6776. };
  6777.  
  6778. Game_CharacterBase.prototype.startAnimation = function() {
  6779.     this._animationId = 0;
  6780.     this._animationPlaying = true;
  6781. };
  6782.  
  6783. Game_CharacterBase.prototype.startBalloon = function() {
  6784.     this._balloonId = 0;
  6785.     this._balloonPlaying = true;
  6786. };
  6787.  
  6788. Game_CharacterBase.prototype.isAnimationPlaying = function() {
  6789.     return this._animationId > 0 || this._animationPlaying;
  6790. };
  6791.  
  6792. Game_CharacterBase.prototype.isBalloonPlaying = function() {
  6793.     return this._balloonId > 0 || this._balloonPlaying;
  6794. };
  6795.  
  6796. Game_CharacterBase.prototype.endAnimation = function() {
  6797.     this._animationPlaying = false;
  6798. };
  6799.  
  6800. Game_CharacterBase.prototype.endBalloon = function() {
  6801.     this._balloonPlaying = false;
  6802. };
  6803.  
  6804. //-----------------------------------------------------------------------------
  6805. // Game_Character
  6806. //
  6807. // The superclass of Game_Player, Game_Follower, GameVehicle, and Game_Event.
  6808.  
  6809. function Game_Character() {
  6810.     this.initialize.apply(this, arguments);
  6811. }
  6812.  
  6813. Game_Character.prototype = Object.create(Game_CharacterBase.prototype);
  6814. Game_Character.prototype.constructor = Game_Character;
  6815.  
  6816. Game_Character.ROUTE_END               = 0;
  6817. Game_Character.ROUTE_MOVE_DOWN         = 1;
  6818. Game_Character.ROUTE_MOVE_LEFT         = 2;
  6819. Game_Character.ROUTE_MOVE_RIGHT        = 3;
  6820. Game_Character.ROUTE_MOVE_UP           = 4;
  6821. Game_Character.ROUTE_MOVE_LOWER_L      = 5;
  6822. Game_Character.ROUTE_MOVE_LOWER_R      = 6;
  6823. Game_Character.ROUTE_MOVE_UPPER_L      = 7;
  6824. Game_Character.ROUTE_MOVE_UPPER_R      = 8;
  6825. Game_Character.ROUTE_MOVE_RANDOM       = 9;
  6826. Game_Character.ROUTE_MOVE_TOWARD       = 10;
  6827. Game_Character.ROUTE_MOVE_AWAY         = 11;
  6828. Game_Character.ROUTE_MOVE_FORWARD      = 12;
  6829. Game_Character.ROUTE_MOVE_BACKWARD     = 13;
  6830. Game_Character.ROUTE_JUMP              = 14;
  6831. Game_Character.ROUTE_WAIT              = 15;
  6832. Game_Character.ROUTE_TURN_DOWN         = 16;
  6833. Game_Character.ROUTE_TURN_LEFT         = 17;
  6834. Game_Character.ROUTE_TURN_RIGHT        = 18;
  6835. Game_Character.ROUTE_TURN_UP           = 19;
  6836. Game_Character.ROUTE_TURN_90D_R        = 20;
  6837. Game_Character.ROUTE_TURN_90D_L        = 21;
  6838. Game_Character.ROUTE_TURN_180D         = 22;
  6839. Game_Character.ROUTE_TURN_90D_R_L      = 23;
  6840. Game_Character.ROUTE_TURN_RANDOM       = 24;
  6841. Game_Character.ROUTE_TURN_TOWARD       = 25;
  6842. Game_Character.ROUTE_TURN_AWAY         = 26;
  6843. Game_Character.ROUTE_SWITCH_ON         = 27;
  6844. Game_Character.ROUTE_SWITCH_OFF        = 28;
  6845. Game_Character.ROUTE_CHANGE_SPEED      = 29;
  6846. Game_Character.ROUTE_CHANGE_FREQ       = 30;
  6847. Game_Character.ROUTE_WALK_ANIME_ON     = 31;
  6848. Game_Character.ROUTE_WALK_ANIME_OFF    = 32;
  6849. Game_Character.ROUTE_STEP_ANIME_ON     = 33;
  6850. Game_Character.ROUTE_STEP_ANIME_OFF    = 34;
  6851. Game_Character.ROUTE_DIR_FIX_ON        = 35;
  6852. Game_Character.ROUTE_DIR_FIX_OFF       = 36;
  6853. Game_Character.ROUTE_THROUGH_ON        = 37;
  6854. Game_Character.ROUTE_THROUGH_OFF       = 38;
  6855. Game_Character.ROUTE_TRANSPARENT_ON    = 39;
  6856. Game_Character.ROUTE_TRANSPARENT_OFF   = 40;
  6857. Game_Character.ROUTE_CHANGE_IMAGE      = 41;
  6858. Game_Character.ROUTE_CHANGE_OPACITY    = 42;
  6859. Game_Character.ROUTE_CHANGE_BLEND_MODE = 43;
  6860. Game_Character.ROUTE_PLAY_SE           = 44;
  6861. Game_Character.ROUTE_SCRIPT            = 45;
  6862.  
  6863. Game_Character.prototype.initialize = function() {
  6864.     Game_CharacterBase.prototype.initialize.call(this);
  6865. };
  6866.  
  6867. Game_Character.prototype.initMembers = function() {
  6868.     Game_CharacterBase.prototype.initMembers.call(this);
  6869.     this._moveRouteForcing = false;
  6870.     this._moveRoute = null;
  6871.     this._moveRouteIndex = 0;
  6872.     this._originalMoveRoute = null;
  6873.     this._originalMoveRouteIndex = 0;
  6874.     this._waitCount = 0;
  6875. };
  6876.  
  6877. Game_Character.prototype.memorizeMoveRoute = function() {
  6878.     this._originalMoveRoute       = this._moveRoute;
  6879.     this._originalMoveRouteIndex  = this._moveRouteIndex;
  6880. };
  6881.  
  6882. Game_Character.prototype.restoreMoveRoute = function() {
  6883.     this._moveRoute          = this._originalMoveRoute;
  6884.     this._moveRouteIndex     = this._originalMoveRouteIndex;
  6885.     this._originalMoveRoute  = null;
  6886. };
  6887.  
  6888. Game_Character.prototype.isMoveRouteForcing = function() {
  6889.     return this._moveRouteForcing;
  6890. };
  6891.  
  6892. Game_Character.prototype.setMoveRoute = function(moveRoute) {
  6893.     this._moveRoute = moveRoute;
  6894.     this._moveRouteIndex = 0;
  6895.     this._moveRouteForcing = false;
  6896. };
  6897.  
  6898. Game_Character.prototype.forceMoveRoute = function(moveRoute) {
  6899.     if (!this._originalMoveRoute) {
  6900.         this.memorizeMoveRoute();
  6901.     }
  6902.     this._moveRoute = moveRoute;
  6903.     this._moveRouteIndex = 0;
  6904.     this._moveRouteForcing = true;
  6905.     this._waitCount = 0;
  6906. };
  6907.  
  6908. Game_Character.prototype.updateStop = function() {
  6909.     Game_CharacterBase.prototype.updateStop.call(this);
  6910.     if (this._moveRouteForcing) {
  6911.         this.updateRoutineMove();
  6912.     }
  6913. };
  6914.  
  6915. Game_Character.prototype.updateRoutineMove = function() {
  6916.     if (this._waitCount > 0) {
  6917.         this._waitCount--;
  6918.     } else {
  6919.         this.setMovementSuccess(true);
  6920.         var command = this._moveRoute.list[this._moveRouteIndex];
  6921.         if (command) {
  6922.             this.processMoveCommand(command);
  6923.             this.advanceMoveRouteIndex();
  6924.         }
  6925.     }
  6926. };
  6927.  
  6928. Game_Character.prototype.processMoveCommand = function(command) {
  6929.     var gc = Game_Character;
  6930.     var params = command.parameters;
  6931.     switch (command.code) {
  6932.     case gc.ROUTE_END:
  6933.         this.processRouteEnd();
  6934.         break;
  6935.     case gc.ROUTE_MOVE_DOWN:
  6936.         this.moveStraight(2);
  6937.         break;
  6938.     case gc.ROUTE_MOVE_LEFT:
  6939.         this.moveStraight(4);
  6940.         break;
  6941.     case gc.ROUTE_MOVE_RIGHT:
  6942.         this.moveStraight(6);
  6943.         break;
  6944.     case gc.ROUTE_MOVE_UP:
  6945.         this.moveStraight(8);
  6946.         break;
  6947.     case gc.ROUTE_MOVE_LOWER_L:
  6948.         this.moveDiagonally(4, 2);
  6949.         break;
  6950.     case gc.ROUTE_MOVE_LOWER_R:
  6951.         this.moveDiagonally(6, 2);
  6952.         break;
  6953.     case gc.ROUTE_MOVE_UPPER_L:
  6954.         this.moveDiagonally(4, 8);
  6955.         break;
  6956.     case gc.ROUTE_MOVE_UPPER_R:
  6957.         this.moveDiagonally(6, 8);
  6958.         break;
  6959.     case gc.ROUTE_MOVE_RANDOM:
  6960.         this.moveRandom();
  6961.         break;
  6962.     case gc.ROUTE_MOVE_TOWARD:
  6963.         this.moveTowardPlayer();
  6964.         break;
  6965.     case gc.ROUTE_MOVE_AWAY:
  6966.         this.moveAwayFromPlayer();
  6967.         break;
  6968.     case gc.ROUTE_MOVE_FORWARD:
  6969.         this.moveForward();
  6970.         break;
  6971.     case gc.ROUTE_MOVE_BACKWARD:
  6972.         this.moveBackward();
  6973.         break;
  6974.     case gc.ROUTE_JUMP:
  6975.         this.jump(params[0], params[1]);
  6976.         break;
  6977.     case gc.ROUTE_WAIT:
  6978.         this._waitCount = params[0] - 1;
  6979.         break;
  6980.     case gc.ROUTE_TURN_DOWN:
  6981.         this.setDirection(2);
  6982.         break;
  6983.     case gc.ROUTE_TURN_LEFT:
  6984.         this.setDirection(4);
  6985.         break;
  6986.     case gc.ROUTE_TURN_RIGHT:
  6987.         this.setDirection(6);
  6988.         break;
  6989.     case gc.ROUTE_TURN_UP:
  6990.         this.setDirection(8);
  6991.         break;
  6992.     case gc.ROUTE_TURN_90D_R:
  6993.         this.turnRight90();
  6994.         break;
  6995.     case gc.ROUTE_TURN_90D_L:
  6996.         this.turnLeft90();
  6997.         break;
  6998.     case gc.ROUTE_TURN_180D:
  6999.         this.turn180();
  7000.         break;
  7001.     case gc.ROUTE_TURN_90D_R_L:
  7002.         this.turnRightOrLeft90();
  7003.         break;
  7004.     case gc.ROUTE_TURN_RANDOM:
  7005.         this.turnRandom();
  7006.         break;
  7007.     case gc.ROUTE_TURN_TOWARD:
  7008.         this.turnTowardPlayer();
  7009.         break;
  7010.     case gc.ROUTE_TURN_AWAY:
  7011.         this.turnAwayFromPlayer();
  7012.         break;
  7013.     case gc.ROUTE_SWITCH_ON:
  7014.         $gameSwitches.setValue(params[0], true);
  7015.         break;
  7016.     case gc.ROUTE_SWITCH_OFF:
  7017.         $gameSwitches.setValue(params[0], false);
  7018.         break;
  7019.     case gc.ROUTE_CHANGE_SPEED:
  7020.         this.setMoveSpeed(params[0]);
  7021.         break;
  7022.     case gc.ROUTE_CHANGE_FREQ:
  7023.         this.setMoveFrequency(params[0]);
  7024.         break;
  7025.     case gc.ROUTE_WALK_ANIME_ON:
  7026.         this.setWalkAnime(true);
  7027.         break;
  7028.     case gc.ROUTE_WALK_ANIME_OFF:
  7029.         this.setWalkAnime(false);
  7030.         break;
  7031.     case gc.ROUTE_STEP_ANIME_ON:
  7032.         this.setStepAnime(true);
  7033.         break;
  7034.     case gc.ROUTE_STEP_ANIME_OFF:
  7035.         this.setStepAnime(false);
  7036.         break;
  7037.     case gc.ROUTE_DIR_FIX_ON:
  7038.         this.setDirectionFix(true);
  7039.         break;
  7040.     case gc.ROUTE_DIR_FIX_OFF:
  7041.         this.setDirectionFix(false);
  7042.         break;
  7043.     case gc.ROUTE_THROUGH_ON:
  7044.         this.setThrough(true);
  7045.         break;
  7046.     case gc.ROUTE_THROUGH_OFF:
  7047.         this.setThrough(false);
  7048.         break;
  7049.     case gc.ROUTE_TRANSPARENT_ON:
  7050.         this.setTransparent(true);
  7051.         break;
  7052.     case gc.ROUTE_TRANSPARENT_OFF:
  7053.         this.setTransparent(false);
  7054.         break;
  7055.     case gc.ROUTE_CHANGE_IMAGE:
  7056.         this.setImage(params[0], params[1]);
  7057.         break;
  7058.     case gc.ROUTE_CHANGE_OPACITY:
  7059.         this.setOpacity(params[0]);
  7060.         break;
  7061.     case gc.ROUTE_CHANGE_BLEND_MODE:
  7062.         this.setBlendMode(params[0]);
  7063.         break;
  7064.     case gc.ROUTE_PLAY_SE:
  7065.         AudioManager.playSe(params[0]);
  7066.         break;
  7067.     case gc.ROUTE_SCRIPT:
  7068.         eval(params[0]);
  7069.         break;
  7070.     }
  7071. };
  7072.  
  7073. Game_Character.prototype.deltaXFrom = function(x) {
  7074.     return $gameMap.deltaX(this.x, x);
  7075. };
  7076.  
  7077. Game_Character.prototype.deltaYFrom = function(y) {
  7078.     return $gameMap.deltaY(this.y, y);
  7079. };
  7080.  
  7081. Game_Character.prototype.moveRandom = function() {
  7082.     var d = 2 + Math.randomInt(4) * 2;
  7083.     if (this.canPass(this.x, this.y, d)) {
  7084.         this.moveStraight(d);
  7085.     }
  7086. };
  7087.  
  7088. Game_Character.prototype.moveTowardCharacter = function(character) {
  7089.     var sx = this.deltaXFrom(character.x);
  7090.     var sy = this.deltaYFrom(character.y);
  7091.     if (Math.abs(sx) > Math.abs(sy)) {
  7092.         this.moveStraight(sx > 0 ? 4 : 6);
  7093.         if (!this.isMovementSucceeded() && sy !== 0) {
  7094.             this.moveStraight(sy > 0 ? 8 : 2);
  7095.         }
  7096.     } else if (sy !== 0) {
  7097.         this.moveStraight(sy > 0 ? 8 : 2);
  7098.         if (!this.isMovementSucceeded() && sx !== 0) {
  7099.             this.moveStraight(sx > 0 ? 4 : 6);
  7100.         }
  7101.     }
  7102. };
  7103.  
  7104. Game_Character.prototype.moveAwayFromCharacter = function(character) {
  7105.     var sx = this.deltaXFrom(character.x);
  7106.     var sy = this.deltaYFrom(character.y);
  7107.     if (Math.abs(sx) > Math.abs(sy)) {
  7108.         this.moveStraight(sx > 0 ? 6 : 4);
  7109.         if (!this.isMovementSucceeded() && sy !== 0) {
  7110.             this.moveStraight(sy > 0 ? 2 : 8);
  7111.         }
  7112.     } else if (sy !== 0) {
  7113.         this.moveStraight(sy > 0 ? 2 : 8);
  7114.         if (!this.isMovementSucceeded() && sx !== 0) {
  7115.             this.moveStraight(sx > 0 ? 6 : 4);
  7116.         }
  7117.     }
  7118. };
  7119.  
  7120. Game_Character.prototype.turnTowardCharacter = function(character) {
  7121.     var sx = this.deltaXFrom(character.x);
  7122.     var sy = this.deltaYFrom(character.y);
  7123.     if (Math.abs(sx) > Math.abs(sy)) {
  7124.         this.setDirection(sx > 0 ? 4 : 6);
  7125.     } else if (sy !== 0) {
  7126.         this.setDirection(sy > 0 ? 8 : 2);
  7127.     }
  7128. };
  7129.  
  7130. Game_Character.prototype.turnAwayFromCharacter = function(character) {
  7131.     var sx = this.deltaXFrom(character.x);
  7132.     var sy = this.deltaYFrom(character.y);
  7133.     if (Math.abs(sx) > Math.abs(sy)) {
  7134.         this.setDirection(sx > 0 ? 6 : 4);
  7135.     } else if (sy !== 0) {
  7136.         this.setDirection(sy > 0 ? 2 : 8);
  7137.     }
  7138. };
  7139.  
  7140. Game_Character.prototype.turnTowardPlayer = function() {
  7141.     this.turnTowardCharacter($gamePlayer);
  7142. };
  7143.  
  7144. Game_Character.prototype.turnAwayFromPlayer = function() {
  7145.     this.turnAwayFromCharacter($gamePlayer);
  7146. };
  7147.  
  7148. Game_Character.prototype.moveTowardPlayer = function() {
  7149.     this.moveTowardCharacter($gamePlayer);
  7150. };
  7151.  
  7152. Game_Character.prototype.moveAwayFromPlayer = function() {
  7153.     this.moveAwayFromCharacter($gamePlayer);
  7154. };
  7155.  
  7156. Game_Character.prototype.moveForward = function() {
  7157.     this.moveStraight(this.direction());
  7158. };
  7159.  
  7160. Game_Character.prototype.moveBackward = function() {
  7161.     var lastDirectionFix = this.isDirectionFixed();
  7162.     this.setDirectionFix(true);
  7163.     this.moveStraight(this.reverseDir(this.direction()));
  7164.     this.setDirectionFix(lastDirectionFix);
  7165. };
  7166.  
  7167. Game_Character.prototype.processRouteEnd = function() {
  7168.     if (this._moveRoute.repeat) {
  7169.         this._moveRouteIndex = -1;
  7170.     } else if (this._moveRouteForcing) {
  7171.         this._moveRouteForcing = false;
  7172.         this.restoreMoveRoute();
  7173.     }
  7174. };
  7175.  
  7176. Game_Character.prototype.advanceMoveRouteIndex = function() {
  7177.     var moveRoute = this._moveRoute;
  7178.     if (moveRoute && (this.isMovementSucceeded() || moveRoute.skippable)) {
  7179.         var numCommands = moveRoute.list.length - 1;
  7180.         this._moveRouteIndex++;
  7181.         if (moveRoute.repeat && this._moveRouteIndex >= numCommands) {
  7182.             this._moveRouteIndex = 0;
  7183.         }
  7184.     }
  7185. };
  7186.  
  7187. Game_Character.prototype.turnRight90 = function() {
  7188.     switch (this.direction()) {
  7189.     case 2:
  7190.         this.setDirection(4);
  7191.         break;
  7192.     case 4:
  7193.         this.setDirection(8);
  7194.         break;
  7195.     case 6:
  7196.         this.setDirection(2);
  7197.         break;
  7198.     case 8:
  7199.         this.setDirection(6);
  7200.         break;
  7201.     }
  7202. };
  7203.  
  7204. Game_Character.prototype.turnLeft90 = function() {
  7205.     switch (this.direction()) {
  7206.     case 2:
  7207.         this.setDirection(6);
  7208.         break;
  7209.     case 4:
  7210.         this.setDirection(2);
  7211.         break;
  7212.     case 6:
  7213.         this.setDirection(8);
  7214.         break;
  7215.     case 8:
  7216.         this.setDirection(4);
  7217.         break;
  7218.     }
  7219. };
  7220.  
  7221. Game_Character.prototype.turn180 = function() {
  7222.     this.setDirection(this.reverseDir(this.direction()));
  7223. };
  7224.  
  7225. Game_Character.prototype.turnRightOrLeft90 = function() {
  7226.     switch (Math.randomInt(2)) {
  7227.     case 0:
  7228.         this.turnRight90();
  7229.         break;
  7230.     case 1:
  7231.         this.turnLeft90();
  7232.         break;
  7233.     }
  7234. };
  7235.  
  7236. Game_Character.prototype.turnRandom = function() {
  7237.     this.setDirection(2 + Math.randomInt(4) * 2);
  7238. };
  7239.  
  7240. Game_Character.prototype.swap = function(character) {
  7241.     var newX = character.x;
  7242.     var newY = character.y;
  7243.     character.locate(this.x, this.y);
  7244.     this.locate(newX, newY);
  7245. };
  7246.  
  7247. Game_Character.prototype.findDirectionTo = function(goalX, goalY) {
  7248.     var searchLimit = this.searchLimit();
  7249.     var mapWidth = $gameMap.width();
  7250.     var nodeList = [];
  7251.     var openList = [];
  7252.     var closedList = [];
  7253.     var start = {};
  7254.     var best = start;
  7255.  
  7256.     if (this.x === goalX && this.y === goalY) {
  7257.         return 0;
  7258.     }
  7259.  
  7260.     start.parent = null;
  7261.     start.x = this.x;
  7262.     start.y = this.y;
  7263.     start.g = 0;
  7264.     start.f = $gameMap.distance(start.x, start.y, goalX, goalY);
  7265.     nodeList.push(start);
  7266.     openList.push(start.y * mapWidth + start.x);
  7267.  
  7268.     while (nodeList.length > 0) {
  7269.         var bestIndex = 0;
  7270.         for (var i = 0; i < nodeList.length; i++) {
  7271.             if (nodeList[i].f < nodeList[bestIndex].f) {
  7272.                 bestIndex = i;
  7273.             }
  7274.         }
  7275.  
  7276.         var current = nodeList[bestIndex];
  7277.         var x1 = current.x;
  7278.         var y1 = current.y;
  7279.         var pos1 = y1 * mapWidth + x1;
  7280.         var g1 = current.g;
  7281.  
  7282.         nodeList.splice(bestIndex, 1);
  7283.         openList.splice(openList.indexOf(pos1), 1);
  7284.         closedList.push(pos1);
  7285.  
  7286.         if (current.x === goalX && current.y === goalY) {
  7287.             best = current;
  7288.             goaled = true;
  7289.             break;
  7290.         }
  7291.  
  7292.         if (g1 >= searchLimit) {
  7293.             continue;
  7294.         }
  7295.  
  7296.         for (var j = 0; j < 4; j++) {
  7297.             var direction = 2 + j * 2;
  7298.             var x2 = $gameMap.roundXWithDirection(x1, direction);
  7299.             var y2 = $gameMap.roundYWithDirection(y1, direction);
  7300.             var pos2 = y2 * mapWidth + x2;
  7301.  
  7302.             if (closedList.contains(pos2)) {
  7303.                 continue;
  7304.             }
  7305.             if (!this.canPass(x1, y1, direction)) {
  7306.                 continue;
  7307.             }
  7308.  
  7309.             var g2 = g1 + 1;
  7310.             var index2 = openList.indexOf(pos2);
  7311.  
  7312.             if (index2 < 0 || g2 < nodeList[index2].g) {
  7313.                 var neighbor;
  7314.                 if (index2 >= 0) {
  7315.                     neighbor = nodeList[index2];
  7316.                 } else {
  7317.                     neighbor = {};
  7318.                     nodeList.push(neighbor);
  7319.                     openList.push(pos2);
  7320.                 }
  7321.                 neighbor.parent = current;
  7322.                 neighbor.x = x2;
  7323.                 neighbor.y = y2;
  7324.                 neighbor.g = g2;
  7325.                 neighbor.f = g2 + $gameMap.distance(x2, y2, goalX, goalY);
  7326.                 if (!best || neighbor.f - neighbor.g < best.f - best.g) {
  7327.                     best = neighbor;
  7328.                 }
  7329.             }
  7330.         }
  7331.     }
  7332.  
  7333.     var node = best;
  7334.     while (node.parent && node.parent !== start) {
  7335.         node = node.parent;
  7336.     }
  7337.  
  7338.     var deltaX1 = $gameMap.deltaX(node.x, start.x);
  7339.     var deltaY1 = $gameMap.deltaY(node.y, start.y);
  7340.     if (deltaY1 > 0) {
  7341.         return 2;
  7342.     } else if (deltaX1 < 0) {
  7343.         return 4;
  7344.     } else if (deltaX1 > 0) {
  7345.         return 6;
  7346.     } else if (deltaY1 < 0) {
  7347.         return 8;
  7348.     }
  7349.  
  7350.     var deltaX2 = this.deltaXFrom(goalX);
  7351.     var deltaY2 = this.deltaYFrom(goalY);
  7352.     if (Math.abs(deltaX2) > Math.abs(deltaY2)) {
  7353.         return deltaX2 > 0 ? 4 : 6;
  7354.     } else if (deltaY2 !== 0) {
  7355.         return deltaY2 > 0 ? 8 : 2;
  7356.     }
  7357.  
  7358.     return 0;
  7359. };
  7360.  
  7361. Game_Character.prototype.searchLimit = function() {
  7362.     return 12;
  7363. };
  7364.  
  7365. //-----------------------------------------------------------------------------
  7366. // Game_Player
  7367. //
  7368. // The game object class for the player. It contains event starting
  7369. // determinants and map scrolling functions.
  7370.  
  7371. function Game_Player() {
  7372.     this.initialize.apply(this, arguments);
  7373. }
  7374.  
  7375. Game_Player.prototype = Object.create(Game_Character.prototype);
  7376. Game_Player.prototype.constructor = Game_Player;
  7377.  
  7378. Game_Player.prototype.initialize = function() {
  7379.     Game_Character.prototype.initialize.call(this);
  7380.     this.setTransparent($dataSystem.optTransparent);
  7381. };
  7382.  
  7383. Game_Player.prototype.initMembers = function() {
  7384.     Game_Character.prototype.initMembers.call(this);
  7385.     this._vehicleType = 'walk';
  7386.     this._vehicleGettingOn = false;
  7387.     this._vehicleGettingOff = false;
  7388.     this._dashing = false;
  7389.     this._needsMapReload = false;
  7390.     this._transferring = false;
  7391.     this._newMapId = 0;
  7392.     this._newX = 0;
  7393.     this._newY = 0;
  7394.     this._newDirection = 0;
  7395.     this._fadeType = 0;
  7396.     this._followers = new Game_Followers();
  7397.     this._encounterCount = 0;
  7398. };
  7399.  
  7400. Game_Player.prototype.clearTransferInfo = function() {
  7401.     this._transferring = false;
  7402.     this._newMapId = 0;
  7403.     this._newX = 0;
  7404.     this._newY = 0;
  7405.     this._newDirection = 0;
  7406. };
  7407.  
  7408. Game_Player.prototype.followers = function() {
  7409.     return this._followers;
  7410. };
  7411.  
  7412. Game_Player.prototype.refresh = function() {
  7413.     var actor = $gameParty.leader();
  7414.     var characterName = actor ? actor.characterName() : '';
  7415.     var characterIndex = actor ? actor.characterIndex() : 0;
  7416.     this.setImage(characterName, characterIndex);
  7417.     this._followers.refresh();
  7418. };
  7419.  
  7420. Game_Player.prototype.isStopping = function() {
  7421.     if (this._vehicleGettingOn || this._vehicleGettingOff) {
  7422.         return false;
  7423.     }
  7424.     return Game_Character.prototype.isStopping.call(this);
  7425. };
  7426.  
  7427. Game_Player.prototype.reserveTransfer = function(mapId, x, y, d, fadeType) {
  7428.     this._transferring = true;
  7429.     this._newMapId = mapId;
  7430.     this._newX = x;
  7431.     this._newY = y;
  7432.     this._newDirection = d;
  7433.     this._fadeType = fadeType;
  7434. };
  7435.  
  7436. Game_Player.prototype.requestMapReload = function() {
  7437.     this._needsMapReload = true;
  7438. };
  7439.  
  7440. Game_Player.prototype.isTransferring = function() {
  7441.     return this._transferring;
  7442. };
  7443.  
  7444. Game_Player.prototype.newMapId = function() {
  7445.     return this._newMapId;
  7446. };
  7447.  
  7448. Game_Player.prototype.fadeType = function() {
  7449.     return this._fadeType;
  7450. };
  7451.  
  7452. Game_Player.prototype.performTransfer = function() {
  7453.     if (this.isTransferring()) {
  7454.         this.setDirection(this._newDirection);
  7455.         if (this._newMapId !== $gameMap.mapId() || this._needsMapReload) {
  7456.             $gameMap.setup(this._newMapId);
  7457.             this._needsMapReload = false;
  7458.         }
  7459.         this.locate(this._newX, this._newY);
  7460.         this.refresh();
  7461.         this.clearTransferInfo();
  7462.     }
  7463. };
  7464.  
  7465. Game_Player.prototype.isMapPassable = function(x, y, d) {
  7466.     var vehicle = this.vehicle();
  7467.     if (vehicle) {
  7468.         return vehicle.isMapPassable(x, y, d);
  7469.     } else {
  7470.         return Game_Character.prototype.isMapPassable.call(this, x, y, d);
  7471.     }
  7472. };
  7473.  
  7474. Game_Player.prototype.vehicle = function() {
  7475.     return $gameMap.vehicle(this._vehicleType);
  7476. };
  7477.  
  7478. Game_Player.prototype.isInBoat = function() {
  7479.     return this._vehicleType === 'boat';
  7480. };
  7481.  
  7482. Game_Player.prototype.isInShip = function() {
  7483.     return this._vehicleType === 'ship';
  7484. };
  7485.  
  7486. Game_Player.prototype.isInAirship = function() {
  7487.     return this._vehicleType === 'airship';
  7488. };
  7489.  
  7490. Game_Player.prototype.isInVehicle = function() {
  7491.     return this.isInBoat() || this.isInShip() || this.isInAirship();
  7492. };
  7493.  
  7494. Game_Player.prototype.isNormal = function() {
  7495.     return this._vehicleType === 'walk' && !this.isMoveRouteForcing();
  7496. };
  7497.  
  7498. Game_Player.prototype.isDashing = function() {
  7499.     return this._dashing;
  7500. };
  7501.  
  7502. Game_Player.prototype.isDebugThrough = function() {
  7503.     return Input.isPressed('control') && $gameTemp.isPlaytest();
  7504. };
  7505.  
  7506. Game_Player.prototype.isCollided = function(x, y) {
  7507.     if (this.isThrough()) {
  7508.         return false;
  7509.     } else {
  7510.         return this.pos(x, y) || this._followers.isSomeoneCollided(x, y);
  7511.     }
  7512. };
  7513.  
  7514. Game_Player.prototype.centerX = function() {
  7515.     return (Graphics.width / $gameMap.tileWidth() - 1) / 2.0;
  7516. };
  7517.  
  7518. Game_Player.prototype.centerY = function() {
  7519.     return (Graphics.height / $gameMap.tileHeight() - 1) / 2.0;
  7520. };
  7521.  
  7522. Game_Player.prototype.center = function(x, y) {
  7523.     return $gameMap.setDisplayPos(x - this.centerX(), y - this.centerY());
  7524. };
  7525.  
  7526. Game_Player.prototype.locate = function(x, y) {
  7527.     Game_Character.prototype.locate.call(this, x, y);
  7528.     this.center(x, y);
  7529.     this.makeEncounterCount();
  7530.     if (this.isInVehicle()) {
  7531.         this.vehicle().refresh();
  7532.     }
  7533.     this._followers.synchronize(x, y, this.direction());
  7534. };
  7535.  
  7536. Game_Player.prototype.increaseSteps = function() {
  7537.     Game_Character.prototype.increaseSteps.call(this);
  7538.     if (this.isNormal()) {
  7539.         $gameParty.increaseSteps();
  7540.     }
  7541. };
  7542.  
  7543. Game_Player.prototype.makeEncounterCount = function() {
  7544.     var n = $gameMap.encounterStep();
  7545.     this._encounterCount = Math.randomInt(n) + Math.randomInt(n) + 1;
  7546. };
  7547.  
  7548. Game_Player.prototype.makeEncounterTroopId = function() {
  7549.     var encounterList = [];
  7550.     var weightSum = 0;
  7551.     $gameMap.encounterList().forEach(function(encounter) {
  7552.         if (this.meetsEncounterConditions(encounter)) {
  7553.             encounterList.push(encounter);
  7554.             weightSum += encounter.weight;
  7555.         }
  7556.     }, this);
  7557.     if (weightSum > 0) {
  7558.         var value = Math.randomInt(weightSum);
  7559.         for (var i = 0; i < encounterList.length; i++) {
  7560.             value -= encounterList[i].weight;
  7561.             if (value < 0) {
  7562.                 return encounterList[i].troopId;
  7563.             }
  7564.         }
  7565.     }
  7566.     return 0;
  7567. };
  7568.  
  7569. Game_Player.prototype.meetsEncounterConditions = function(encounter) {
  7570.     return (encounter.regionSet.length === 0 ||
  7571.             encounter.regionSet.contains(this.regionId()));
  7572. };
  7573.  
  7574. Game_Player.prototype.executeEncounter = function() {
  7575.     if (!$gameMap.isEventRunning() && this._encounterCount <= 0) {
  7576.         this.makeEncounterCount();
  7577.         var troopId = this.makeEncounterTroopId();
  7578.         if ($dataTroops[troopId]) {
  7579.             BattleManager.setup(troopId, true, false);
  7580.             BattleManager.onEncounter();
  7581.             return true;
  7582.         } else {
  7583.             return false;
  7584.         }
  7585.     } else {
  7586.         return false;
  7587.     }
  7588. };
  7589.  
  7590. Game_Player.prototype.startMapEvent = function(x, y, triggers, normal) {
  7591.     if (!$gameMap.isEventRunning()) {
  7592.         $gameMap.eventsXy(x, y).forEach(function(event) {
  7593.             if (event.isTriggerIn(triggers) && event.isNormalPriority() === normal) {
  7594.                 event.start();
  7595.             }
  7596.         });
  7597.     }
  7598. };
  7599.  
  7600. Game_Player.prototype.moveByInput = function() {
  7601.     if (!this.isMoving() && this.canMove()) {
  7602.         var direction = this.getInputDirection();
  7603.         if (direction > 0) {
  7604.             $gameTemp.clearDestination();
  7605.         } else if ($gameTemp.isDestinationValid()){
  7606.             var x = $gameTemp.destinationX();
  7607.             var y = $gameTemp.destinationY();
  7608.             direction = this.findDirectionTo(x, y);
  7609.         }
  7610.         if (direction > 0) {
  7611.             this.executeMove(direction);
  7612.         }
  7613.     }
  7614. };
  7615.  
  7616. Game_Player.prototype.canMove = function() {
  7617.     if ($gameMap.isEventRunning() || $gameMessage.isBusy()) {
  7618.         return false;
  7619.     }
  7620.     if (this.isMoveRouteForcing() || this.areFollowersGathering()) {
  7621.         return false;
  7622.     }
  7623.     if (this._vehicleGettingOn || this._vehicleGettingOff) {
  7624.         return false;
  7625.     }
  7626.     if (this.isInVehicle() && !this.vehicle().canMove()) {
  7627.         return false;
  7628.     }
  7629.     return true;
  7630. };
  7631.  
  7632. Game_Player.prototype.getInputDirection = function() {
  7633.     return Input.dir4;
  7634. };
  7635.  
  7636. Game_Player.prototype.executeMove = function(direction) {
  7637.     this.moveStraight(direction);
  7638. };
  7639.  
  7640. Game_Player.prototype.update = function(sceneActive) {
  7641.     var lastScrolledX = this.scrolledX();
  7642.     var lastScrolledY = this.scrolledY();
  7643.     var wasMoving = this.isMoving();
  7644.     this.updateDashing();
  7645.     if (sceneActive) {
  7646.         this.moveByInput();
  7647.     }
  7648.     Game_Character.prototype.update.call(this);
  7649.     this.updateScroll(lastScrolledX, lastScrolledY);
  7650.     this.updateVehicle();
  7651.     if (!this.isMoving()) {
  7652.         this.updateNonmoving(wasMoving);
  7653.     }
  7654.     this._followers.update();
  7655. };
  7656.  
  7657. Game_Player.prototype.updateDashing = function() {
  7658.     if (this.isMoving()) {
  7659.         return;
  7660.     }
  7661.     if (this.canMove() && !this.isInVehicle() && !$gameMap.isDashDisabled()) {
  7662.         this._dashing = this.isDashButtonPressed() || $gameTemp.isDestinationValid();
  7663.     } else {
  7664.         this._dashing = false;
  7665.     }
  7666. };
  7667.  
  7668. Game_Player.prototype.isDashButtonPressed = function() {
  7669.     var shift = Input.isPressed('shift');
  7670.     if (ConfigManager.alwaysDash) {
  7671.         return !shift;
  7672.     } else {
  7673.         return shift;
  7674.     }
  7675. };
  7676.  
  7677. Game_Player.prototype.updateScroll = function(lastScrolledX, lastScrolledY) {
  7678.     var x1 = lastScrolledX;
  7679.     var y1 = lastScrolledY;
  7680.     var x2 = this.scrolledX();
  7681.     var y2 = this.scrolledY();
  7682.     if (y2 > y1 && y2 > this.centerY()) {
  7683.         $gameMap.scrollDown(y2 - y1);
  7684.     }
  7685.     if (x2 < x1 && x2 < this.centerX()) {
  7686.         $gameMap.scrollLeft(x1 - x2);
  7687.     }
  7688.     if (x2 > x1 && x2 > this.centerX()) {
  7689.         $gameMap.scrollRight(x2 - x1);
  7690.     }
  7691.     if (y2 < y1 && y2 < this.centerY()) {
  7692.         $gameMap.scrollUp(y1 - y2);
  7693.     }
  7694. };
  7695.  
  7696. Game_Player.prototype.updateVehicle = function() {
  7697.     if (this.isInVehicle() && !this.areFollowersGathering()) {
  7698.         if (this._vehicleGettingOn) {
  7699.             this.updateVehicleGetOn();
  7700.         } else if (this._vehicleGettingOff) {
  7701.             this.updateVehicleGetOff();
  7702.         } else {
  7703.             this.vehicle().syncWithPlayer();
  7704.         }
  7705.     }
  7706. };
  7707.  
  7708. Game_Player.prototype.updateVehicleGetOn = function() {
  7709.     if (!this.areFollowersGathering() && !this.isMoving()) {
  7710.         this.setDirection(this.vehicle().direction());
  7711.         this.setMoveSpeed(this.vehicle().moveSpeed());
  7712.         this._vehicleGettingOn = false;
  7713.         this.setTransparent(true);
  7714.         if (this.isInAirship()) {
  7715.             this.setThrough(true);
  7716.         }
  7717.         this.vehicle().getOn();
  7718.     }
  7719. };
  7720.  
  7721. Game_Player.prototype.updateVehicleGetOff = function() {
  7722.     if (!this.areFollowersGathering() && this.vehicle().isLowest()) {
  7723.         this._vehicleGettingOff = false;
  7724.         this._vehicleType = 'walk';
  7725.         this.setTransparent(false);
  7726.     }
  7727. };
  7728.  
  7729. Game_Player.prototype.updateNonmoving = function(wasMoving) {
  7730.     if (!$gameMap.isEventRunning()) {
  7731.         if (wasMoving) {
  7732.             $gameParty.onPlayerWalk();
  7733.             this.checkEventTriggerHere([1,2]);
  7734.             if ($gameMap.setupStartingEvent()) {
  7735.                 return;
  7736.             }
  7737.         }
  7738.         if (this.triggerAction()) {
  7739.             return;
  7740.         }
  7741.         if (wasMoving) {
  7742.             this.updateEncounterCount();
  7743.         } else {
  7744.             $gameTemp.clearDestination();
  7745.         }
  7746.     }
  7747. };
  7748.  
  7749. Game_Player.prototype.triggerAction = function() {
  7750.     if (this.canMove()) {
  7751.         if (this.triggerButtonAction()) {
  7752.             return true;
  7753.         }
  7754.         if (this.triggerTouchAction()) {
  7755.             return true;
  7756.         }
  7757.     }
  7758.     return false;
  7759. };
  7760.  
  7761. Game_Player.prototype.triggerButtonAction = function() {
  7762.     if (Input.isTriggered('ok')) {
  7763.         if (this.getOnOffVehicle()) {
  7764.             return true;
  7765.         }
  7766.         this.checkEventTriggerHere([0]);
  7767.         if ($gameMap.setupStartingEvent()) {
  7768.             return true;
  7769.         }
  7770.         this.checkEventTriggerThere([0,1,2]);
  7771.         if ($gameMap.setupStartingEvent()) {
  7772.             return true;
  7773.         }
  7774.     }
  7775.     return false;
  7776. };
  7777.  
  7778. Game_Player.prototype.triggerTouchAction = function() {
  7779.     if ($gameTemp.isDestinationValid()){
  7780.         var direction = this.direction();
  7781.         var x1 = this.x;
  7782.         var y1 = this.y;
  7783.         var x2 = $gameMap.roundXWithDirection(x1, direction);
  7784.         var y2 = $gameMap.roundYWithDirection(y1, direction);
  7785.         var x3 = $gameMap.roundXWithDirection(x2, direction);
  7786.         var y3 = $gameMap.roundYWithDirection(y2, direction);
  7787.         var destX = $gameTemp.destinationX();
  7788.         var destY = $gameTemp.destinationY();
  7789.         if (destX === x1 && destY === y1) {
  7790.             return this.triggerTouchActionD1(x1, y1);
  7791.         } else if (destX === x2 && destY === y2) {
  7792.             return this.triggerTouchActionD2(x2, y2);
  7793.         } else if (destX === x3 && destY === y3) {
  7794.             return this.triggerTouchActionD3(x2, y2);
  7795.         }
  7796.     }
  7797.     return false;
  7798. };
  7799.  
  7800. Game_Player.prototype.triggerTouchActionD1 = function(x1, y1) {
  7801.     if ($gameMap.airship().pos(x1, y1)) {
  7802.         if (TouchInput.isTriggered() && this.getOnOffVehicle()) {
  7803.             return true;
  7804.         }
  7805.     }
  7806.     this.checkEventTriggerHere([0]);
  7807.     return $gameMap.setupStartingEvent();
  7808. };
  7809.  
  7810. Game_Player.prototype.triggerTouchActionD2 = function(x2, y2) {
  7811.     if ($gameMap.boat().pos(x2, y2) || $gameMap.ship().pos(x2, y2)) {
  7812.         if (TouchInput.isTriggered() && this.getOnVehicle()) {
  7813.             return true;
  7814.         }
  7815.     }
  7816.     if (this.isInBoat() || this.isInShip()) {
  7817.         if (TouchInput.isTriggered() && this.getOffVehicle()) {
  7818.             return true;
  7819.         }
  7820.     }
  7821.     this.checkEventTriggerThere([0,1,2]);
  7822.     return $gameMap.setupStartingEvent();
  7823. };
  7824.  
  7825. Game_Player.prototype.triggerTouchActionD3 = function(x2, y2) {
  7826.     if ($gameMap.isCounter(x2, y2)) {
  7827.         this.checkEventTriggerThere([0,1,2]);
  7828.     }
  7829.     return $gameMap.setupStartingEvent();
  7830. };
  7831.  
  7832. Game_Player.prototype.updateEncounterCount = function() {
  7833.     if (this.canEncounter()) {
  7834.         this._encounterCount -= this.encounterProgressValue();
  7835.     }
  7836. };
  7837.  
  7838. Game_Player.prototype.canEncounter = function() {
  7839.     return (!$gameParty.hasEncounterNone() && $gameSystem.isEncounterEnabled() &&
  7840.             !this.isInAirship() && !this.isMoveRouteForcing() && !this.isDebugThrough());
  7841. };
  7842.  
  7843. Game_Player.prototype.encounterProgressValue = function() {
  7844.     var value = $gameMap.isBush(this.x, this.y) ? 2 : 1;
  7845.     if ($gameParty.hasEncounterHalf()) {
  7846.         value *= 0.5;
  7847.     }
  7848.     if (this.isInShip()) {
  7849.         value *= 0.5;
  7850.     }
  7851.     return value;
  7852. };
  7853.  
  7854. Game_Player.prototype.checkEventTriggerHere = function(triggers) {
  7855.     if (this.canStartLocalEvents()) {
  7856.         this.startMapEvent(this.x, this.y, triggers, false);
  7857.     }
  7858. };
  7859.  
  7860. Game_Player.prototype.checkEventTriggerThere = function(triggers) {
  7861.     if (this.canStartLocalEvents()) {
  7862.         var direction = this.direction();
  7863.         var x1 = this.x;
  7864.         var y1 = this.y;
  7865.         var x2 = $gameMap.roundXWithDirection(x1, direction);
  7866.         var y2 = $gameMap.roundYWithDirection(y1, direction);
  7867.         this.startMapEvent(x2, y2, triggers, true);
  7868.         if (!$gameMap.isAnyEventStarting() && $gameMap.isCounter(x2, y2)) {
  7869.             var x3 = $gameMap.roundXWithDirection(x2, direction);
  7870.             var y3 = $gameMap.roundYWithDirection(y2, direction);
  7871.             this.startMapEvent(x3, y3, triggers, true);
  7872.         }
  7873.     }
  7874. };
  7875.  
  7876. Game_Player.prototype.checkEventTriggerTouch = function(x, y) {
  7877.     if (this.canStartLocalEvents()) {
  7878.         this.startMapEvent(x, y, [1,2], true);
  7879.     }
  7880. };
  7881.  
  7882. Game_Player.prototype.canStartLocalEvents = function() {
  7883.     return !this.isInAirship();
  7884. };
  7885.  
  7886. Game_Player.prototype.getOnOffVehicle = function() {
  7887.     if (this.isInVehicle()) {
  7888.         return this.getOffVehicle();
  7889.     } else {
  7890.         return this.getOnVehicle();
  7891.     }
  7892. };
  7893.  
  7894. Game_Player.prototype.getOnVehicle = function() {
  7895.     var direction = this.direction();
  7896.     var x1 = this.x;
  7897.     var y1 = this.y;
  7898.     var x2 = $gameMap.roundXWithDirection(x1, direction);
  7899.     var y2 = $gameMap.roundYWithDirection(y1, direction);
  7900.     if ($gameMap.airship().pos(x1, y1)) {
  7901.         this._vehicleType = 'airship';
  7902.     } else if ($gameMap.ship().pos(x2, y2)) {
  7903.         this._vehicleType = 'ship';
  7904.     } else if ($gameMap.boat().pos(x2, y2)) {
  7905.         this._vehicleType = 'boat';
  7906.     }
  7907.     if (this.isInVehicle()) {
  7908.         this._vehicleGettingOn = true;
  7909.         if (!this.isInAirship()) {
  7910.             this.forceMoveForward();
  7911.         }
  7912.         this.gatherFollowers();
  7913.     }
  7914.     return this._vehicleGettingOn;
  7915. };
  7916.  
  7917. Game_Player.prototype.getOffVehicle = function() {
  7918.     if (this.vehicle().isLandOk(this.x, this.y, this.direction())) {
  7919.         if (this.isInAirship()) {
  7920.             this.setDirection(2);
  7921.         }
  7922.         this._followers.synchronize(this.x, this.y, this.direction());
  7923.         this.vehicle().getOff();
  7924.         if (!this.isInAirship()) {
  7925.             this.forceMoveForward();
  7926.             this.setTransparent(false);
  7927.         }
  7928.         this._vehicleGettingOff = true;
  7929.         this.setMoveSpeed(4);
  7930.         this.setThrough(false);
  7931.         this.makeEncounterCount();
  7932.         this.gatherFollowers();
  7933.     }
  7934.     return this._vehicleGettingOff;
  7935. };
  7936.  
  7937. Game_Player.prototype.forceMoveForward = function() {
  7938.     this.setThrough(true);
  7939.     this.moveForward();
  7940.     this.setThrough(false);
  7941. };
  7942.  
  7943. Game_Player.prototype.isOnDamageFloor = function() {
  7944.     return $gameMap.isDamageFloor(this.x, this.y) && !this.isInAirship();
  7945. };
  7946.  
  7947. Game_Player.prototype.moveStraight = function(d) {
  7948.     if (this.canPass(this.x, this.y, d)) {
  7949.         this._followers.updateMove();
  7950.     }
  7951.     Game_Character.prototype.moveStraight.call(this, d);
  7952. };
  7953.  
  7954. Game_Player.prototype.moveDiagonally = function(horz, vert) {
  7955.     if (this.canPassDiagonally(this.x, this.y, horz, vert)) {
  7956.         this._followers.updateMove();
  7957.     }
  7958.     Game_Character.prototype.moveDiagonally.call(this, horz, vert);
  7959. };
  7960.  
  7961. Game_Player.prototype.jump = function(xPlus, yPlus) {
  7962.     Game_Character.prototype.jump.call(this, xPlus, yPlus);
  7963.     this._followers.jumpAll();
  7964. };
  7965.  
  7966. Game_Player.prototype.showFollowers = function() {
  7967.     this._followers.show();
  7968. };
  7969.  
  7970. Game_Player.prototype.hideFollowers = function() {
  7971.     this._followers.hide();
  7972. };
  7973.  
  7974. Game_Player.prototype.gatherFollowers = function() {
  7975.     this._followers.gather();
  7976. };
  7977.  
  7978. Game_Player.prototype.areFollowersGathering = function() {
  7979.     return this._followers.areGathering();
  7980. };
  7981.  
  7982. Game_Player.prototype.areFollowersGathered = function() {
  7983.     return this._followers.areGathered();
  7984. };
  7985.  
  7986. //-----------------------------------------------------------------------------
  7987. // Game_Follower
  7988. //
  7989. // The game object class for a follower. A follower is an allied character,
  7990. // other than the front character, displayed in the party.
  7991.  
  7992. function Game_Follower() {
  7993.     this.initialize.apply(this, arguments);
  7994. }
  7995.  
  7996. Game_Follower.prototype = Object.create(Game_Character.prototype);
  7997. Game_Follower.prototype.constructor = Game_Follower;
  7998.  
  7999. Game_Follower.prototype.initialize = function(memberIndex) {
  8000.     Game_Character.prototype.initialize.call(this);
  8001.     this._memberIndex = memberIndex;
  8002.     this.setTransparent($dataSystem.optTransparent);
  8003.     this.setThrough(true);
  8004. };
  8005.  
  8006. Game_Follower.prototype.refresh = function() {
  8007.     var characterName = this.isVisible() ? this.actor().characterName() : '';
  8008.     var characterIndex = this.isVisible() ? this.actor().characterIndex() : 0;
  8009.     this.setImage(characterName, characterIndex);
  8010. };
  8011.  
  8012. Game_Follower.prototype.actor = function() {
  8013.     return $gameParty.battleMembers()[this._memberIndex];
  8014. };
  8015.  
  8016. Game_Follower.prototype.isVisible = function() {
  8017.     return this.actor() && $gamePlayer.followers().isVisible();
  8018. };
  8019.  
  8020. Game_Follower.prototype.update = function() {
  8021.     Game_Character.prototype.update.call(this);
  8022.     this.setMoveSpeed($gamePlayer.realMoveSpeed());
  8023.     this.setOpacity($gamePlayer.opacity());
  8024.     this.setBlendMode($gamePlayer.blendMode());
  8025.     this.setWalkAnime($gamePlayer.hasWalkAnime());
  8026.     this.setStepAnime($gamePlayer.hasStepAnime());
  8027.     this.setDirectionFix($gamePlayer.isDirectionFixed());
  8028.     this.setTransparent($gamePlayer.isTransparent());
  8029. };
  8030.  
  8031. Game_Follower.prototype.chaseCharacter = function(character) {
  8032.     var sx = this.deltaXFrom(character.x);
  8033.     var sy = this.deltaYFrom(character.y);
  8034.     if (sx !== 0 && sy !== 0) {
  8035.         this.moveDiagonally(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2);
  8036.     } else if (sx !== 0) {
  8037.         this.moveStraight(sx > 0 ? 4 : 6);
  8038.     } else if (sy !== 0) {
  8039.         this.moveStraight(sy > 0 ? 8 : 2);
  8040.     }
  8041.     this.setMoveSpeed($gamePlayer.realMoveSpeed());
  8042. };
  8043.  
  8044. //-----------------------------------------------------------------------------
  8045. // Game_Followers
  8046. //
  8047. // The wrapper class for a follower array.
  8048.  
  8049. function Game_Followers() {
  8050.     this.initialize.apply(this, arguments);
  8051. }
  8052.  
  8053. Game_Followers.prototype.initialize = function() {
  8054.     this._visible = $dataSystem.optFollowers;
  8055.     this._gathering = false;
  8056.     this._data = [];
  8057.     for (var i = 1; i < $gameParty.maxBattleMembers(); i++) {
  8058.         this._data.push(new Game_Follower(i));
  8059.     }
  8060. };
  8061.  
  8062. Game_Followers.prototype.isVisible = function() {
  8063.     return this._visible;
  8064. };
  8065.  
  8066. Game_Followers.prototype.show = function() {
  8067.     this._visible = true;
  8068. };
  8069.  
  8070. Game_Followers.prototype.hide = function() {
  8071.     this._visible = false;
  8072. };
  8073.  
  8074. Game_Followers.prototype.follower = function(index) {
  8075.     return this._data[index];
  8076. };
  8077.  
  8078. Game_Followers.prototype.forEach = function(callback, thisObject) {
  8079.     this._data.forEach(callback, thisObject);
  8080. };
  8081.  
  8082. Game_Followers.prototype.reverseEach = function(callback, thisObject) {
  8083.     this._data.reverse();
  8084.     this._data.forEach(callback, thisObject);
  8085.     this._data.reverse();
  8086. };
  8087.  
  8088. Game_Followers.prototype.refresh = function() {
  8089.     this.forEach(function(follower) {
  8090.         return follower.refresh();
  8091.     }, this);
  8092. };
  8093.  
  8094. Game_Followers.prototype.update = function() {
  8095.     if (this.areGathering()) {
  8096.         if (!this.areMoving()) {
  8097.             this.updateMove();
  8098.         }
  8099.         if (this.areGathered()) {
  8100.             this._gathering = false;
  8101.         }
  8102.     }
  8103.     this.forEach(function(follower) {
  8104.         follower.update();
  8105.     }, this);
  8106. };
  8107.  
  8108. Game_Followers.prototype.updateMove = function() {
  8109.     for (var i = this._data.length - 1; i >= 0; i--) {
  8110.         var precedingCharacter = (i > 0 ? this._data[i - 1] : $gamePlayer);
  8111.         this._data[i].chaseCharacter(precedingCharacter);
  8112.     }
  8113. };
  8114.  
  8115. Game_Followers.prototype.jumpAll = function() {
  8116.     if ($gamePlayer.isJumping()) {
  8117.         for (var i = 0; i < this._data.length; i++) {
  8118.             var follower = this._data[i];
  8119.             var sx = $gamePlayer.deltaXFrom(follower.x);
  8120.             var sy = $gamePlayer.deltaYFrom(follower.y);
  8121.             follower.jump(sx, sy);
  8122.         }
  8123.     }
  8124. };
  8125.  
  8126. Game_Followers.prototype.synchronize = function(x, y, d) {
  8127.     this.forEach(function(follower) {
  8128.         follower.locate(x, y);
  8129.         follower.setDirection(d);
  8130.     }, this);
  8131. };
  8132.  
  8133. Game_Followers.prototype.gather = function() {
  8134.     this._gathering = true;
  8135. };
  8136.  
  8137. Game_Followers.prototype.areGathering = function() {
  8138.     return this._gathering;
  8139. };
  8140.  
  8141. Game_Followers.prototype.visibleFollowers = function() {
  8142.     return this._data.filter(function(follower) {
  8143.         return follower.isVisible();
  8144.     }, this);
  8145. };
  8146.  
  8147. Game_Followers.prototype.areMoving = function() {
  8148.     return this.visibleFollowers().some(function(follower) {
  8149.         return follower.isMoving();
  8150.     }, this);
  8151. };
  8152.  
  8153. Game_Followers.prototype.areGathered = function() {
  8154.     return this.visibleFollowers().every(function(follower) {
  8155.         return !follower.isMoving() && follower.pos($gamePlayer.x, $gamePlayer.y);
  8156.     }, this);
  8157. };
  8158.  
  8159. Game_Followers.prototype.isSomeoneCollided = function(x, y) {
  8160.     return this.visibleFollowers().some(function(follower) {
  8161.         return follower.pos(x, y);
  8162.     }, this);
  8163. };
  8164.  
  8165. //-----------------------------------------------------------------------------
  8166. // Game_Vehicle
  8167. //
  8168. // The game object class for a vehicle.
  8169.  
  8170. function Game_Vehicle() {
  8171.     this.initialize.apply(this, arguments);
  8172. }
  8173.  
  8174. Game_Vehicle.prototype = Object.create(Game_Character.prototype);
  8175. Game_Vehicle.prototype.constructor = Game_Vehicle;
  8176.  
  8177. Game_Vehicle.prototype.initialize = function(type) {
  8178.     Game_Character.prototype.initialize.call(this);
  8179.     this._type = type;
  8180.     this.resetDirection();
  8181.     this.initMoveSpeed();
  8182.     this.loadSystemSettings();
  8183. };
  8184.  
  8185. Game_Vehicle.prototype.initMembers = function() {
  8186.     Game_Character.prototype.initMembers.call(this);
  8187.     this._type = '';
  8188.     this._mapId = 0;
  8189.     this._altitude = 0;
  8190.     this._driving = false;
  8191.     this._bgm = null;
  8192. };
  8193.  
  8194. Game_Vehicle.prototype.isBoat = function() {
  8195.     return this._type === 'boat';
  8196. };
  8197.  
  8198. Game_Vehicle.prototype.isShip = function() {
  8199.     return this._type === 'ship';
  8200. };
  8201.  
  8202. Game_Vehicle.prototype.isAirship = function() {
  8203.     return this._type === 'airship';
  8204. };
  8205.  
  8206. Game_Vehicle.prototype.resetDirection = function() {
  8207.     this.setDirection(4);
  8208. };
  8209.  
  8210. Game_Vehicle.prototype.initMoveSpeed = function() {
  8211.     if (this.isBoat()) {
  8212.         this.setMoveSpeed(4);
  8213.     } else if (this.isShip()) {
  8214.         this.setMoveSpeed(5);
  8215.     } else if (this.isAirship()) {
  8216.         this.setMoveSpeed(6);
  8217.     }
  8218. };
  8219.  
  8220. Game_Vehicle.prototype.vehicle = function() {
  8221.     if (this.isBoat()) {
  8222.         return $dataSystem.boat;
  8223.     } else if (this.isShip()) {
  8224.         return $dataSystem.ship;
  8225.     } else if (this.isAirship()) {
  8226.         return $dataSystem.airship;
  8227.     } else {
  8228.         return null;
  8229.     }
  8230. };
  8231.  
  8232. Game_Vehicle.prototype.loadSystemSettings = function() {
  8233.     var vehicle = this.vehicle();
  8234.     this._mapId = vehicle.startMapId;
  8235.     this.setPosition(vehicle.startX, vehicle.startY);
  8236.     this.setImage(vehicle.characterName, vehicle.characterIndex);
  8237. };
  8238.  
  8239. Game_Vehicle.prototype.refresh = function() {
  8240.     if (this._driving) {
  8241.         this._mapId = $gameMap.mapId();
  8242.         this.syncWithPlayer();
  8243.     } else if (this._mapId === $gameMap.mapId()) {
  8244.         this.locate(this.x, this.y);
  8245.     }
  8246.     if (this.isAirship()) {
  8247.         this.setPriorityType(this._driving ? 2 : 0);
  8248.     } else {
  8249.         this.setPriorityType(1);
  8250.     }
  8251.     this.setWalkAnime(this._driving);
  8252.     this.setStepAnime(this._driving);
  8253.     this.setTransparent(this._mapId !== $gameMap.mapId());
  8254. };
  8255.  
  8256. Game_Vehicle.prototype.setLocation = function(mapId, x, y) {
  8257.     this._mapId = mapId;
  8258.     this.setPosition(x, y);
  8259.     this.refresh();
  8260. };
  8261.  
  8262. Game_Vehicle.prototype.pos = function(x, y) {
  8263.     if (this._mapId === $gameMap.mapId()) {
  8264.         return Game_Character.prototype.pos.call(this, x, y);
  8265.     } else {
  8266.         return false;
  8267.     }
  8268. };
  8269.  
  8270. Game_Vehicle.prototype.isMapPassable = function(x, y, d) {
  8271.     var x2 = $gameMap.roundXWithDirection(x, d);
  8272.     var y2 = $gameMap.roundYWithDirection(y, d);
  8273.     if (this.isBoat()) {
  8274.         return $gameMap.isBoatPassable(x2, y2);
  8275.     } else if (this.isShip()) {
  8276.         return $gameMap.isShipPassable(x2, y2);
  8277.     } else if (this.isAirship()) {
  8278.         return true;
  8279.     } else {
  8280.         return false;
  8281.     }
  8282. };
  8283.  
  8284. Game_Vehicle.prototype.getOn = function() {
  8285.     this._driving = true;
  8286.     this.setWalkAnime(true);
  8287.     this.setStepAnime(true);
  8288.     $gameSystem.saveWalkingBgm();
  8289.     this.playBgm();
  8290. };
  8291.  
  8292. Game_Vehicle.prototype.getOff = function() {
  8293.     this._driving = false;
  8294.     this.setWalkAnime(false);
  8295.     this.setStepAnime(false);
  8296.     this.resetDirection();
  8297.     $gameSystem.replayWalkingBgm();
  8298. };
  8299.  
  8300. Game_Vehicle.prototype.setBgm = function(bgm) {
  8301.     this._bgm = bgm;
  8302. };
  8303.  
  8304. Game_Vehicle.prototype.playBgm = function() {
  8305.     AudioManager.playBgm(this._bgm || this.vehicle().bgm);
  8306. };
  8307.  
  8308. Game_Vehicle.prototype.syncWithPlayer = function() {
  8309.     this.copyPosition($gamePlayer);
  8310.     this.refreshBushDepth();
  8311. };
  8312.  
  8313. Game_Vehicle.prototype.screenY = function() {
  8314.     return Game_Character.prototype.screenY.call(this) - this._altitude;
  8315. };
  8316.  
  8317. Game_Vehicle.prototype.shadowX = function() {
  8318.     return this.screenX();
  8319. };
  8320.  
  8321. Game_Vehicle.prototype.shadowY = function() {
  8322.     return this.screenY() + this._altitude;
  8323. };
  8324.  
  8325. Game_Vehicle.prototype.shadowOpacity = function() {
  8326.     return 255 * this._altitude / this.maxAltitude();
  8327. };
  8328.  
  8329. Game_Vehicle.prototype.canMove = function() {
  8330.     if (this.isAirship()) {
  8331.         return this.isHighest();
  8332.     } else {
  8333.         return true;
  8334.     }
  8335. };
  8336.  
  8337. Game_Vehicle.prototype.update = function() {
  8338.     Game_Character.prototype.update.call(this);
  8339.     if (this.isAirship()) {
  8340.         this.updateAirship();
  8341.     }
  8342. };
  8343.  
  8344. Game_Vehicle.prototype.updateAirship = function() {
  8345.     this.updateAirshipAltitude();
  8346.     this.setStepAnime(this.isHighest());
  8347.     this.setPriorityType(this.isLowest() ? 0 : 2);
  8348. };
  8349.  
  8350. Game_Vehicle.prototype.updateAirshipAltitude = function() {
  8351.     if (this._driving && !this.isHighest()) {
  8352.         this._altitude++;
  8353.     }
  8354.     if (!this._driving && !this.isLowest()) {
  8355.         this._altitude--;
  8356.     }
  8357. };
  8358.  
  8359. Game_Vehicle.prototype.maxAltitude = function() {
  8360.     return 48;
  8361. };
  8362.  
  8363. Game_Vehicle.prototype.isLowest = function() {
  8364.     return this._altitude <= 0;
  8365. };
  8366.  
  8367. Game_Vehicle.prototype.isHighest = function() {
  8368.     return this._altitude >= this.maxAltitude();
  8369. };
  8370.  
  8371. Game_Vehicle.prototype.isTakeoffOk = function() {
  8372.     return $gamePlayer.areFollowersGathered();
  8373. };
  8374.  
  8375. Game_Vehicle.prototype.isLandOk = function(x, y, d) {
  8376.     if (this.isAirship()) {
  8377.         if (!$gameMap.isAirshipLandOk(x, y)) {
  8378.             return false;
  8379.         }
  8380.         if ($gameMap.eventsXy(x, y).length > 0) {
  8381.             return false;
  8382.         }
  8383.     } else {
  8384.         var x2 = $gameMap.roundXWithDirection(x, d);
  8385.         var y2 = $gameMap.roundYWithDirection(y, d);
  8386.         if (!$gameMap.isValid(x2, y2)) {
  8387.             return false;
  8388.         }
  8389.         if (!$gameMap.isPassable(x2, y2, this.reverseDir(d))) {
  8390.             return false;
  8391.         }
  8392.         if (this.isCollidedWithCharacters(x2, y2)) {
  8393.             return false;
  8394.         }
  8395.     }
  8396.     return true;
  8397. };
  8398.  
  8399. //-----------------------------------------------------------------------------
  8400. // Game_Event
  8401. //
  8402. // The game object class for an event. It contains functionality for event page
  8403. // switching and running parallel process events.
  8404.  
  8405. function Game_Event() {
  8406.     this.initialize.apply(this, arguments);
  8407. }
  8408.  
  8409. Game_Event.prototype = Object.create(Game_Character.prototype);
  8410. Game_Event.prototype.constructor = Game_Event;
  8411.  
  8412. Game_Event.prototype.initialize = function(mapId, eventId) {
  8413.     Game_Character.prototype.initialize.call(this);
  8414.     this._mapId = mapId;
  8415.     this._eventId = eventId;
  8416.     this.locate(this.event().x, this.event().y);
  8417.     this.refresh();
  8418. };
  8419.  
  8420. Game_Event.prototype.initMembers = function() {
  8421.     Game_Character.prototype.initMembers.call(this);
  8422.     this._moveType = 0;
  8423.     this._trigger = 0;
  8424.     this._starting = false;
  8425.     this._erased = false;
  8426.     this._pageIndex = -2;
  8427.     this._originalPattern = 1;
  8428.     this._originalDirection = 2;
  8429.     this._prelockDirection = 0;
  8430.     this._locked = false;
  8431. };
  8432.  
  8433. Game_Event.prototype.eventId = function() {
  8434.     return this._eventId;
  8435. };
  8436.  
  8437. Game_Event.prototype.event = function() {
  8438.     return $dataMap.events[this._eventId];
  8439. };
  8440.  
  8441. Game_Event.prototype.page = function() {
  8442.     return this.event().pages[this._pageIndex];
  8443. };
  8444.  
  8445. Game_Event.prototype.list = function() {
  8446.     return this.page().list;
  8447. };
  8448.  
  8449. Game_Event.prototype.isCollidedWithCharacters = function(x, y) {
  8450.     return (Game_Character.prototype.isCollidedWithCharacters.call(this, x, y) ||
  8451.             this.isCollidedWithPlayerCharacters(x, y));
  8452. };
  8453.  
  8454. Game_Event.prototype.isCollidedWithEvents = function(x, y) {
  8455.     var events = $gameMap.eventsXyNt(x, y);
  8456.     return events.length > 0;
  8457. };
  8458.  
  8459. Game_Event.prototype.isCollidedWithPlayerCharacters = function(x, y) {
  8460.     return this.isNormalPriority() && $gamePlayer.isCollided(x, y);
  8461. };
  8462.  
  8463. Game_Event.prototype.lock = function() {
  8464.     if (!this._locked) {
  8465.         this._prelockDirection = this.direction();
  8466.         this.turnTowardPlayer();
  8467.         this._locked = true;
  8468.     }
  8469. };
  8470.  
  8471. Game_Event.prototype.unlock = function() {
  8472.     if (this._locked) {
  8473.         this._locked = false;
  8474.         this.setDirection(this._prelockDirection);
  8475.     }
  8476. };
  8477.  
  8478. Game_Event.prototype.updateStop = function() {
  8479.     if (this._locked) {
  8480.         this.resetStopCount();
  8481.     }
  8482.     Game_Character.prototype.updateStop.call(this);
  8483.     if (!this.isMoveRouteForcing()) {
  8484.         this.updateSelfMovement();
  8485.     }
  8486. };
  8487.  
  8488. Game_Event.prototype.updateSelfMovement = function() {
  8489.     if (!this._locked && this.isNearTheScreen() &&
  8490.             this.checkStop(this.stopCountThreshold())) {
  8491.         switch (this._moveType) {
  8492.         case 1:
  8493.             this.moveTypeRandom();
  8494.             break;
  8495.         case 2:
  8496.             this.moveTypeTowardPlayer();
  8497.             break;
  8498.         case 3:
  8499.             this.moveTypeCustom();
  8500.             break;
  8501.         }
  8502.     }
  8503. };
  8504.  
  8505. Game_Event.prototype.stopCountThreshold = function() {
  8506.     return 30 * (5 - this.moveFrequency());
  8507. };
  8508.  
  8509. Game_Event.prototype.moveTypeRandom = function() {
  8510.     switch (Math.randomInt(6)) {
  8511.     case 0: case 1:
  8512.         this.moveRandom();
  8513.         break;
  8514.     case 2: case 3: case 4:
  8515.         this.moveForward();
  8516.         break;
  8517.     case 5:
  8518.         this.resetStopCount();
  8519.         break;
  8520.     }
  8521. };
  8522.  
  8523. Game_Event.prototype.moveTypeTowardPlayer = function() {
  8524.     if (this.isNearThePlayer()) {
  8525.         switch (Math.randomInt(6)) {
  8526.         case 0: case 1: case 2: case 3:
  8527.             this.moveTowardPlayer();
  8528.             break;
  8529.         case 4:
  8530.             this.moveRandom();
  8531.             break;
  8532.         case 5:
  8533.             this.moveForward();
  8534.             break;
  8535.         }
  8536.     } else {
  8537.         this.moveRandom();
  8538.     }
  8539. };
  8540.  
  8541. Game_Event.prototype.isNearThePlayer = function() {
  8542.     var sx = Math.abs(this.deltaXFrom($gamePlayer.x));
  8543.     var sy = Math.abs(this.deltaYFrom($gamePlayer.y));
  8544.     return sx + sy < 20;
  8545. };
  8546.  
  8547. Game_Event.prototype.moveTypeCustom = function() {
  8548.     this.updateRoutineMove();
  8549. };
  8550.  
  8551. Game_Event.prototype.isStarting = function() {
  8552.     return this._starting;
  8553. };
  8554.  
  8555. Game_Event.prototype.clearStartingFlag = function() {
  8556.     this._starting = false;
  8557. };
  8558.  
  8559. Game_Event.prototype.isTriggerIn = function(triggers) {
  8560.     return triggers.contains(this._trigger);
  8561. };
  8562.  
  8563. Game_Event.prototype.start = function() {
  8564.     var list = this.list();
  8565.     if (list && list.length > 1) {
  8566.         this._starting = true;
  8567.         if (this.isTriggerIn([0,1,2])) {
  8568.             this.lock();
  8569.         }
  8570.     }
  8571. };
  8572.  
  8573. Game_Event.prototype.erase = function() {
  8574.     this._erased = true;
  8575.     this.refresh();
  8576. };
  8577.  
  8578. Game_Event.prototype.refresh = function() {
  8579.     var newPageIndex = this._erased ? -1 : this.findProperPageIndex();
  8580.     if (this._pageIndex !== newPageIndex) {
  8581.         this._pageIndex = newPageIndex;
  8582.         this.setupPage();
  8583.     }
  8584. };
  8585.  
  8586. Game_Event.prototype.findProperPageIndex = function() {
  8587.     var pages = this.event().pages;
  8588.     for (var i = pages.length - 1; i >= 0; i--) {
  8589.         var page = pages[i];
  8590.         if (this.meetsConditions(page)) {
  8591.             return i;
  8592.         }
  8593.     }
  8594.     return -1;
  8595. };
  8596.  
  8597. Game_Event.prototype.meetsConditions = function(page) {
  8598.     var c = page.conditions;
  8599.     if (c.switch1Valid) {
  8600.         if (!$gameSwitches.value(c.switch1Id)) {
  8601.             return false;
  8602.         }
  8603.     }
  8604.     if (c.switch2Valid) {
  8605.         if (!$gameSwitches.value(c.switch2Id)) {
  8606.             return false;
  8607.         }
  8608.     }
  8609.     if (c.variableValid) {
  8610.         if ($gameVariables.value(c.variableId) < c.variableValue) {
  8611.             return false;
  8612.         }
  8613.     }
  8614.     if (c.selfSwitchValid) {
  8615.         var key = [this._mapId, this._eventId, c.selfSwitchCh];
  8616.         if ($gameSelfSwitches.value(key) !== true) {
  8617.             return false;
  8618.         }
  8619.     }
  8620.     if (c.itemValid) {
  8621.         var item = $dataItems[c.itemId];
  8622.         if (!$gameParty.hasItem(item)) {
  8623.             return false;
  8624.         }
  8625.     }
  8626.     if (c.actorValid) {
  8627.         var actor = $gameActors.actor(c.actorId);
  8628.         if (!$gameParty.members().contains(actor)) {
  8629.             return false;
  8630.         }
  8631.     }
  8632.     return true;
  8633. };
  8634.  
  8635. Game_Event.prototype.setupPage = function() {
  8636.     if (this._pageIndex >= 0) {
  8637.         this.setupPageSettings();
  8638.     } else {
  8639.         this.clearPageSettings();
  8640.     }
  8641.     this.refreshBushDepth();
  8642.     this.clearStartingFlag();
  8643.     this.checkEventTriggerAuto();
  8644. };
  8645.  
  8646. Game_Event.prototype.clearPageSettings = function() {
  8647.     this.setImage('', 0);
  8648.     this._moveType = 0;
  8649.     this._trigger = null;
  8650.     this._interpreter = null;
  8651.     this.setThrough(true);
  8652. };
  8653.  
  8654. Game_Event.prototype.setupPageSettings = function() {
  8655.     var page = this.page();
  8656.     var image = page.image;
  8657.     if (image.tileId > 0) {
  8658.         this.setTileImage(image.tileId);
  8659.     } else {
  8660.         this.setImage(image.characterName, image.characterIndex);
  8661.     }
  8662.     if (this._originalDirection !== image.direction) {
  8663.         this._originalDirection = image.direction;
  8664.         this._prelockDirection = 0;
  8665.         this.setDirectionFix(false);
  8666.         this.setDirection(image.direction);
  8667.     }
  8668.     if (this._originalPattern !== image.pattern) {
  8669.         this._originalPattern = image.pattern;
  8670.         this.setPattern(image.pattern);
  8671.     }
  8672.     this.setMoveSpeed(page.moveSpeed);
  8673.     this.setMoveFrequency(page.moveFrequency);
  8674.     this.setPriorityType(page.priorityType);
  8675.     this.setWalkAnime(page.walkAnime);
  8676.     this.setStepAnime(page.stepAnime);
  8677.     this.setDirectionFix(page.directionFix);
  8678.     this.setThrough(page.through);
  8679.     this.setMoveRoute(page.moveRoute);
  8680.     this._moveType = page.moveType;
  8681.     this._trigger = page.trigger;
  8682.     if (this._trigger === 4) {
  8683.         this._interpreter = new Game_Interpreter();
  8684.     } else {
  8685.         this._interpreter = null;
  8686.     }
  8687. };
  8688.  
  8689. Game_Event.prototype.isOriginalPattern = function() {
  8690.     return this.pattern() === this._originalPattern;
  8691. };
  8692.  
  8693. Game_Event.prototype.resetPattern = function() {
  8694.     this.setPattern(this._originalPattern);
  8695. };
  8696.  
  8697. Game_Event.prototype.checkEventTriggerTouch = function(x, y) {
  8698.     if (!$gameMap.isEventRunning()) {
  8699.         if (this._trigger === 2 && $gamePlayer.pos(x, y)) {
  8700.             if (!this.isJumping() && this.isNormalPriority()) {
  8701.                 this.start();
  8702.             }
  8703.         }
  8704.     }
  8705. };
  8706.  
  8707. Game_Event.prototype.checkEventTriggerAuto = function() {
  8708.     if (this._trigger === 3) {
  8709.         this.start();
  8710.     }
  8711. };
  8712.  
  8713. Game_Event.prototype.update = function() {
  8714.     Game_Character.prototype.update.call(this);
  8715.     this.checkEventTriggerAuto();
  8716.     this.updateParallel();
  8717. };
  8718.  
  8719. Game_Event.prototype.updateParallel = function() {
  8720.     if (this._interpreter) {
  8721.         if (!this._interpreter.isRunning()) {
  8722.             this._interpreter.setup(this.list(), this._eventId);
  8723.         }
  8724.         this._interpreter.update();
  8725.     }
  8726. };
  8727.  
  8728. Game_Event.prototype.locate = function(x, y) {
  8729.     Game_Character.prototype.locate.call(this, x, y);
  8730.     this._prelockDirection = 0;
  8731. };
  8732.  
  8733. Game_Event.prototype.forceMoveRoute = function(moveRoute) {
  8734.     Game_Character.prototype.forceMoveRoute.call(this, moveRoute);
  8735.     this._prelockDirection = 0;
  8736. };
  8737.  
  8738. //-----------------------------------------------------------------------------
  8739. // Game_Interpreter
  8740. //
  8741. // The interpreter for running event commands.
  8742.  
  8743. function Game_Interpreter() {
  8744.     this.initialize.apply(this, arguments);
  8745. }
  8746.  
  8747. Game_Interpreter.prototype.initialize = function(depth) {
  8748.     this._depth = depth || 0;
  8749.     this.checkOverflow();
  8750.     this.clear();
  8751.     this._branch = {};
  8752.     this._params = [];
  8753.     this._indent = 0;
  8754.     this._frameCount = 0;
  8755.     this._freezeChecker = 0;
  8756. };
  8757.  
  8758. Game_Interpreter.prototype.checkOverflow = function() {
  8759.     if (this._depth >= 100) {
  8760.         throw new Error('Common event calls exceeded the limit');
  8761.     }
  8762. };
  8763.  
  8764. Game_Interpreter.prototype.clear = function() {
  8765.     this._mapId = 0;
  8766.     this._eventId = 0;
  8767.     this._list = null;
  8768.     this._index = 0;
  8769.     this._waitCount = 0;
  8770.     this._waitMode = '';
  8771.     this._comments = '';
  8772.     this._character = null;
  8773.     this._childInterpreter = null;
  8774. };
  8775.  
  8776. Game_Interpreter.prototype.setup = function(list, eventId) {
  8777.     this.clear();
  8778.     this._mapId = $gameMap.mapId();
  8779.     this._eventId = eventId || 0;
  8780.     this._list = list;
  8781. };
  8782.  
  8783. Game_Interpreter.prototype.eventId = function() {
  8784.     return this._eventId;
  8785. };
  8786.  
  8787. Game_Interpreter.prototype.isOnCurrentMap = function() {
  8788.     return this._mapId === $gameMap.mapId();
  8789. };
  8790.  
  8791. Game_Interpreter.prototype.setupReservedCommonEvent = function() {
  8792.     if ($gameTemp.isCommonEventReserved()) {
  8793.         this.setup($gameTemp.reservedCommonEvent().list);
  8794.         $gameTemp.clearCommonEvent();
  8795.         return true;
  8796.     } else {
  8797.         return false;
  8798.     }
  8799. };
  8800.  
  8801. Game_Interpreter.prototype.isRunning = function() {
  8802.     return !!this._list;
  8803. };
  8804.  
  8805. Game_Interpreter.prototype.update = function() {
  8806.     while (this.isRunning()) {
  8807.         if (this.updateChild() || this.updateWait()) {
  8808.             break;
  8809.         }
  8810.         if (SceneManager.isSceneChanging()) {
  8811.             break;
  8812.         }
  8813.         if (!this.executeCommand()) {
  8814.             break;
  8815.         }
  8816.         if (this.checkFreeze()) {
  8817.             break;
  8818.         }
  8819.     }
  8820. };
  8821.  
  8822. Game_Interpreter.prototype.updateChild = function() {
  8823.     if (this._childInterpreter) {
  8824.         this._childInterpreter.update();
  8825.         if (this._childInterpreter.isRunning()) {
  8826.             return true;
  8827.         } else {
  8828.             this._childInterpreter = null;
  8829.         }
  8830.     }
  8831.     return false;
  8832. };
  8833.  
  8834. Game_Interpreter.prototype.updateWait = function() {
  8835.     return this.updateWaitCount() || this.updateWaitMode();
  8836. };
  8837.  
  8838. Game_Interpreter.prototype.updateWaitCount = function() {
  8839.     if (this._waitCount > 0) {
  8840.         this._waitCount--;
  8841.         return true;
  8842.     }
  8843.     return false;
  8844. };
  8845.  
  8846. Game_Interpreter.prototype.updateWaitMode = function() {
  8847.     var waiting = false;
  8848.     switch (this._waitMode) {
  8849.     case 'message':
  8850.         waiting = $gameMessage.isBusy();
  8851.         break;
  8852.     case 'transfer':
  8853.         waiting = $gamePlayer.isTransferring();
  8854.         break;
  8855.     case 'scroll':
  8856.         waiting = $gameMap.isScrolling();
  8857.         break;
  8858.     case 'route':
  8859.         waiting = this._character.isMoveRouteForcing();
  8860.         break;
  8861.     case 'animation':
  8862.         waiting = this._character.isAnimationPlaying();
  8863.         break;
  8864.     case 'balloon':
  8865.         waiting = this._character.isBalloonPlaying();
  8866.         break;
  8867.     case 'gather':
  8868.         waiting = $gamePlayer.areFollowersGathering();
  8869.         break;
  8870.     case 'action':
  8871.         waiting = BattleManager.isActionForced();
  8872.         break;
  8873.     case 'video':
  8874.         waiting = Graphics.isVideoPlaying();
  8875.         break;
  8876.     case 'image':
  8877.         waiting = !ImageManager.isReady();
  8878.         break;
  8879.     }
  8880.     if (!waiting) {
  8881.         this._waitMode = '';
  8882.     }
  8883.     return waiting;
  8884. };
  8885.  
  8886. Game_Interpreter.prototype.setWaitMode = function(waitMode) {
  8887.     this._waitMode = waitMode;
  8888. };
  8889.  
  8890. Game_Interpreter.prototype.wait = function(duration) {
  8891.     this._waitCount = duration;
  8892. };
  8893.  
  8894. Game_Interpreter.prototype.fadeSpeed = function() {
  8895.     return 24;
  8896. };
  8897.  
  8898. Game_Interpreter.prototype.executeCommand = function() {
  8899.     var command = this.currentCommand();
  8900.     if (command) {
  8901.         this._params = command.parameters;
  8902.         this._indent = command.indent;
  8903.         var methodName = 'command' + command.code;
  8904.         if (typeof this[methodName] === 'function') {
  8905.             if (!this[methodName]()) {
  8906.                 return false;
  8907.             }
  8908.         }
  8909.         this._index++;
  8910.     } else {
  8911.         this.terminate();
  8912.     }
  8913.     return true;
  8914. };
  8915.  
  8916. Game_Interpreter.prototype.checkFreeze = function() {
  8917.     if (this._frameCount !== Graphics.frameCount) {
  8918.         this._frameCount = Graphics.frameCount;
  8919.         this._freezeChecker = 0;
  8920.     }
  8921.     if (this._freezeChecker++ >= 100000) {
  8922.         return true;
  8923.     } else {
  8924.         return false;
  8925.     }
  8926. };
  8927.  
  8928. Game_Interpreter.prototype.terminate = function() {
  8929.     this._list = null;
  8930.     this._comments = '';
  8931. };
  8932.  
  8933. Game_Interpreter.prototype.skipBranch = function() {
  8934.     while (this._list[this._index + 1].indent > this._indent) {
  8935.         this._index++;
  8936.     }
  8937. };
  8938.  
  8939. Game_Interpreter.prototype.currentCommand = function() {
  8940.     return this._list[this._index];
  8941. };
  8942.  
  8943. Game_Interpreter.prototype.nextEventCode = function() {
  8944.     var command = this._list[this._index + 1];
  8945.     if (command) {
  8946.         return command.code;
  8947.     } else {
  8948.         return 0;
  8949.     }
  8950. };
  8951.  
  8952. Game_Interpreter.prototype.iterateActorId = function(param, callback) {
  8953.     if (param === 0) {
  8954.         $gameParty.members().forEach(callback);
  8955.     } else {
  8956.         var actor = $gameActors.actor(param);
  8957.         if (actor) {
  8958.             callback(actor);
  8959.         }
  8960.     }
  8961. };
  8962.  
  8963. Game_Interpreter.prototype.iterateActorEx = function(param1, param2, callback) {
  8964.     if (param1 === 0) {
  8965.         this.iterateActorId(param2, callback);
  8966.     } else {
  8967.         this.iterateActorId($gameVariables.value(param2), callback);
  8968.     }
  8969. };
  8970.  
  8971. Game_Interpreter.prototype.iterateActorIndex = function(param, callback) {
  8972.     if (param < 0) {
  8973.         $gameParty.members().forEach(callback);
  8974.     } else {
  8975.         var actor = $gameParty.members()[param];
  8976.         if (actor) {
  8977.             callback(actor);
  8978.         }
  8979.     }
  8980. };
  8981.  
  8982. Game_Interpreter.prototype.iterateEnemyIndex = function(param, callback) {
  8983.     if (param < 0) {
  8984.         $gameTroop.members().forEach(callback);
  8985.     } else {
  8986.         var enemy = $gameTroop.members()[param];
  8987.         if (enemy) {
  8988.             callback(enemy);
  8989.         }
  8990.     }
  8991. };
  8992.  
  8993. Game_Interpreter.prototype.iterateBattler = function(param1, param2, callback) {
  8994.     if ($gameParty.inBattle()) {
  8995.         if (param1 === 0) {
  8996.             this.iterateEnemyIndex(param2, callback);
  8997.         } else {
  8998.             this.iterateActorId(param2, callback);
  8999.         }
  9000.     }
  9001. };
  9002.  
  9003. Game_Interpreter.prototype.character = function(param) {
  9004.     if ($gameParty.inBattle()) {
  9005.         return null;
  9006.     } else if (param < 0) {
  9007.         return $gamePlayer;
  9008.     } else if (this.isOnCurrentMap()) {
  9009.         return $gameMap.event(param > 0 ? param : this._eventId);
  9010.     } else {
  9011.         return null;
  9012.     }
  9013. };
  9014.  
  9015. Game_Interpreter.prototype.operateValue = function(operation, operandType, operand) {
  9016.     var value = operandType === 0 ? operand : $gameVariables.value(operand);
  9017.     return operation === 0 ? value : -value;
  9018. };
  9019.  
  9020. Game_Interpreter.prototype.changeHp = function(target, value, allowDeath) {
  9021.     if (target.isAlive()) {
  9022.         if (!allowDeath && target.hp <= -value) {
  9023.             value = 1 - target.hp;
  9024.         }
  9025.         target.gainHp(value);
  9026.         if (target.isDead()) {
  9027.             target.performCollapse();
  9028.         }
  9029.     }
  9030. };
  9031.  
  9032. // Show Text
  9033. Game_Interpreter.prototype.command101 = function() {
  9034.     if (!$gameMessage.isBusy()) {
  9035.         $gameMessage.setFaceImage(this._params[0], this._params[1]);
  9036.         $gameMessage.setBackground(this._params[2]);
  9037.         $gameMessage.setPositionType(this._params[3]);
  9038.         while (this.nextEventCode() === 401) {  // Text data
  9039.             this._index++;
  9040.             $gameMessage.add(this.currentCommand().parameters[0]);
  9041.         }
  9042.         switch (this.nextEventCode()) {
  9043.         case 102:  // Show Choices
  9044.             this._index++;
  9045.             this.setupChoices(this.currentCommand().parameters);
  9046.             break;
  9047.         case 103:  // Input Number
  9048.             this._index++;
  9049.             this.setupNumInput(this.currentCommand().parameters);
  9050.             break;
  9051.         case 104:  // Select Item
  9052.             this._index++;
  9053.             this.setupItemChoice(this.currentCommand().parameters);
  9054.             break;
  9055.         }
  9056.         this._index++;
  9057.         this.setWaitMode('message');
  9058.     }
  9059.     return false;
  9060. };
  9061.  
  9062. // Show Choices
  9063. Game_Interpreter.prototype.command102 = function() {
  9064.     if (!$gameMessage.isBusy()) {
  9065.         this.setupChoices(this._params);
  9066.         this._index++;
  9067.         this.setWaitMode('message');
  9068.     }
  9069.     return false;
  9070. };
  9071.  
  9072. Game_Interpreter.prototype.setupChoices = function(params) {
  9073.     var choices = params[0].clone();
  9074.     var cancelType = params[1];
  9075.     var defaultType = params.length > 2 ? params[2] : 0;
  9076.     var positionType = params.length > 3 ? params[3] : 2;
  9077.     var background = params.length > 4 ? params[4] : 0;
  9078.     if (cancelType >= choices.length) {
  9079.         cancelType = -2;
  9080.     }
  9081.     $gameMessage.setChoices(choices, defaultType, cancelType);
  9082.     $gameMessage.setChoiceBackground(background);
  9083.     $gameMessage.setChoicePositionType(positionType);
  9084.     $gameMessage.setChoiceCallback(function(n) {
  9085.         this._branch[this._indent] = n;
  9086.     }.bind(this));
  9087. };
  9088.  
  9089. // When [**]
  9090. Game_Interpreter.prototype.command402 = function() {
  9091.     if (this._branch[this._indent] !== this._params[0]) {
  9092.         this.skipBranch();
  9093.     }
  9094.     return true;
  9095. };
  9096.  
  9097. // When Cancel
  9098. Game_Interpreter.prototype.command403 = function() {
  9099.     if (this._branch[this._indent] >= 0) {
  9100.         this.skipBranch();
  9101.     }
  9102.     return true;
  9103. };
  9104.  
  9105. // Input Number
  9106. Game_Interpreter.prototype.command103 = function() {
  9107.     if (!$gameMessage.isBusy()) {
  9108.         this.setupNumInput(this._params);
  9109.         this._index++;
  9110.         this.setWaitMode('message');
  9111.     }
  9112.     return false;
  9113. };
  9114.  
  9115. Game_Interpreter.prototype.setupNumInput = function(params) {
  9116.     $gameMessage.setNumberInput(params[0], params[1]);
  9117. };
  9118.  
  9119. // Select Item
  9120. Game_Interpreter.prototype.command104 = function() {
  9121.     if (!$gameMessage.isBusy()) {
  9122.         this.setupItemChoice(this._params);
  9123.         this._index++;
  9124.         this.setWaitMode('message');
  9125.     }
  9126.     return false;
  9127. };
  9128.  
  9129. Game_Interpreter.prototype.setupItemChoice = function(params) {
  9130.     $gameMessage.setItemChoice(params[0], params[1] || 2);
  9131. };
  9132.  
  9133. // Show Scrolling Text
  9134. Game_Interpreter.prototype.command105 = function() {
  9135.     if (!$gameMessage.isBusy()) {
  9136.         $gameMessage.setScroll(this._params[0], this._params[1]);
  9137.         while (this.nextEventCode() === 405) {
  9138.             this._index++;
  9139.             $gameMessage.add(this.currentCommand().parameters[0]);
  9140.         }
  9141.         this._index++;
  9142.         this.setWaitMode('message');
  9143.     }
  9144.     return false;
  9145. };
  9146.  
  9147. // Comment
  9148. Game_Interpreter.prototype.command108 = function() {
  9149.     this._comments = [this._params[0]];
  9150.     while (this.nextEventCode() === 408) {
  9151.         this._index++;
  9152.         this._comments.push(this.currentCommand().parameters[0]);
  9153.     }
  9154.     return true;
  9155. };
  9156.  
  9157. // Conditional Branch
  9158. Game_Interpreter.prototype.command111 = function() {
  9159.     var result = false;
  9160.     switch (this._params[0]) {
  9161.     case 0:  // Switch
  9162.         result = ($gameSwitches.value(this._params[1]) === (this._params[2] === 0));
  9163.         break;
  9164.     case 1:  // Variable
  9165.         var value1 = $gameVariables.value(this._params[1]);
  9166.         var value2;
  9167.         if (this._params[2] === 0) {
  9168.             value2 = this._params[3];
  9169.         } else {
  9170.             value2 = $gameVariables.value(this._params[3]);
  9171.         }
  9172.         switch (this._params[4]) {
  9173.         case 0:  // Equal to
  9174.             result = (value1 === value2);
  9175.             break;
  9176.         case 1:  // Greater than or Equal to
  9177.             result = (value1 >= value2);
  9178.             break;
  9179.         case 2:  // Less than or Equal to
  9180.             result = (value1 <= value2);
  9181.             break;
  9182.         case 3:  // Greater than
  9183.             result = (value1 > value2);
  9184.             break;
  9185.         case 4:  // Less than
  9186.             result = (value1 < value2);
  9187.             break;
  9188.         case 5:  // Not Equal to
  9189.             result = (value1 !== value2);
  9190.             break;
  9191.         }
  9192.         break;
  9193.     case 2:  // Self Switch
  9194.         if (this._eventId > 0) {
  9195.             var key = [this._mapId, this._eventId, this._params[1]];
  9196.             result = ($gameSelfSwitches.value(key) === (this._params[2] === 0));
  9197.         }
  9198.         break;
  9199.     case 3:  // Timer
  9200.         if ($gameTimer.isWorking()) {
  9201.             if (this._params[2] === 0) {
  9202.                 result = ($gameTimer.seconds() >= this._params[1]);
  9203.             } else {
  9204.                 result = ($gameTimer.seconds() <= this._params[1]);
  9205.             }
  9206.         }
  9207.         break;
  9208.     case 4:  // Actor
  9209.         var actor = $gameActors.actor(this._params[1]);
  9210.         if (actor) {
  9211.             var n = this._params[3];
  9212.             switch (this._params[2]) {
  9213.             case 0:  // In the Party
  9214.                 result = $gameParty.members().contains(actor);
  9215.                 break;
  9216.             case 1:  // Name
  9217.                 result = (actor.name() === n);
  9218.                 break;
  9219.             case 2:  // Class
  9220.                 result = actor.isClass($dataClasses[n]);
  9221.                 break;
  9222.             case 3:  // Skill
  9223.                 result = actor.isLearnedSkill(n);
  9224.                 break;
  9225.             case 4:  // Weapon
  9226.                 result = actor.hasWeapon($dataWeapons[n]);
  9227.                 break;
  9228.             case 5:  // Armor
  9229.                 result = actor.hasArmor($dataArmors[n]);
  9230.                 break;
  9231.             case 6:  // State
  9232.                 result = actor.isStateAffected(n);
  9233.                 break;
  9234.             }
  9235.         }
  9236.         break;
  9237.     case 5:  // Enemy
  9238.         var enemy = $gameTroop.members()[this._params[1]];
  9239.         if (enemy) {
  9240.             switch (this._params[2]) {
  9241.             case 0:  // Appeared
  9242.                 result = enemy.isAlive();
  9243.                 break;
  9244.             case 1:  // State
  9245.                 result = enemy.isStateAffected(this._params[3]);
  9246.                 break;
  9247.             }
  9248.         }
  9249.         break;
  9250.     case 6:  // Character
  9251.         var character = this.character(this._params[1]);
  9252.         if (character) {
  9253.             result = (character.direction() === this._params[2]);
  9254.         }
  9255.         break;
  9256.     case 7:  // Gold
  9257.         switch (this._params[2]) {
  9258.         case 0:  // Greater than or equal to
  9259.             result = ($gameParty.gold() >= this._params[1]);
  9260.             break;
  9261.         case 1:  // Less than or equal to
  9262.             result = ($gameParty.gold() <= this._params[1]);
  9263.             break;
  9264.         case 2:  // Less than
  9265.             result = ($gameParty.gold() < this._params[1]);
  9266.             break;
  9267.         }
  9268.         break;
  9269.     case 8:  // Item
  9270.         result = $gameParty.hasItem($dataItems[this._params[1]]);
  9271.         break;
  9272.     case 9:  // Weapon
  9273.         result = $gameParty.hasItem($dataWeapons[this._params[1]], this._params[2]);
  9274.         break;
  9275.     case 10:  // Armor
  9276.         result = $gameParty.hasItem($dataArmors[this._params[1]], this._params[2]);
  9277.         break;
  9278.     case 11:  // Button
  9279.         result = Input.isPressed(this._params[1]);
  9280.         break;
  9281.     case 12:  // Script
  9282.         result = !!eval(this._params[1]);
  9283.         break;
  9284.     case 13:  // Vehicle
  9285.         result = ($gamePlayer.vehicle() === $gameMap.vehicle(this._params[1]));
  9286.         break;
  9287.     }
  9288.     this._branch[this._indent] = result;
  9289.     if (this._branch[this._indent] === false) {
  9290.         this.skipBranch();
  9291.     }
  9292.     return true;
  9293. };
  9294.  
  9295. // Else
  9296. Game_Interpreter.prototype.command411 = function() {
  9297.     if (this._branch[this._indent] !== false) {
  9298.         this.skipBranch();
  9299.     }
  9300.     return true;
  9301. };
  9302.  
  9303. // Loop
  9304. Game_Interpreter.prototype.command112 = function() {
  9305.     return true;
  9306. };
  9307.  
  9308. // Repeat Above
  9309. Game_Interpreter.prototype.command413 = function() {
  9310.     do {
  9311.         this._index--;
  9312.     } while (this.currentCommand().indent !== this._indent);
  9313.     return true;
  9314. };
  9315.  
  9316. // Break Loop
  9317. Game_Interpreter.prototype.command113 = function() {
  9318.     while (this._index < this._list.length - 1) {
  9319.         this._index++;
  9320.         var command = this.currentCommand();
  9321.         if (command.code === 413 && command.indent < this._indent) {
  9322.             break;
  9323.         }
  9324.     }
  9325.     return true;
  9326. };
  9327.  
  9328. // Exit Event Processing
  9329. Game_Interpreter.prototype.command115 = function() {
  9330.     this._index = this._list.length;
  9331.     return true;
  9332. };
  9333.  
  9334. // Common Event
  9335. Game_Interpreter.prototype.command117 = function() {
  9336.     var commonEvent = $dataCommonEvents[this._params[0]];
  9337.     if (commonEvent) {
  9338.         var eventId = this.isOnCurrentMap() ? this._eventId : 0;
  9339.         this.setupChild(commonEvent.list, eventId);
  9340.     }
  9341.     return true;
  9342. };
  9343.  
  9344. Game_Interpreter.prototype.setupChild = function(list, eventId) {
  9345.     this._childInterpreter = new Game_Interpreter(this._depth + 1);
  9346.     this._childInterpreter.setup(list, eventId);
  9347. };
  9348.  
  9349. // Label
  9350. Game_Interpreter.prototype.command118 = function() {
  9351.     return true;
  9352. };
  9353.  
  9354. // Jump to Label
  9355. Game_Interpreter.prototype.command119 = function() {
  9356.     var labelName = this._params[0];
  9357.     for (var i = 0; i < this._list.length; i++) {
  9358.         var command = this._list[i];
  9359.         if (command.code === 118 && command.parameters[0] === labelName) {
  9360.             this.jumpTo(i);
  9361.             return;
  9362.         }
  9363.     }
  9364.     return true;
  9365. };
  9366.  
  9367. Game_Interpreter.prototype.jumpTo = function(index) {
  9368.     var lastIndex = this._index;
  9369.     var startIndex = Math.min(index, lastIndex);
  9370.     var endIndex = Math.max(index, lastIndex);
  9371.     var indent = this._indent;
  9372.     for (var i = startIndex; i <= endIndex; i++) {
  9373.         var newIndent = this._list[i].indent;
  9374.         if (newIndent !== indent) {
  9375.             this._branch[indent] = null;
  9376.             indent = newIndent;
  9377.         }
  9378.     }
  9379.     this._index = index;
  9380. };
  9381.  
  9382. // Control Switches
  9383. Game_Interpreter.prototype.command121 = function() {
  9384.     for (var i = this._params[0]; i <= this._params[1]; i++) {
  9385.         $gameSwitches.setValue(i, this._params[2] === 0);
  9386.     }
  9387.     return true;
  9388. };
  9389.  
  9390. // Control Variables
  9391. Game_Interpreter.prototype.command122 = function() {
  9392.     var value = 0;
  9393.     switch (this._params[3]) {  // Operand
  9394.     case 0:  // Constant
  9395.         value = this._params[4];
  9396.         break;
  9397.     case 1:  // Variable
  9398.         value = $gameVariables.value(this._params[4]);
  9399.         break;
  9400.     case 2:  // Random
  9401.         value = this._params[4] + Math.randomInt(this._params[5] - this._params[4] + 1);
  9402.         break;
  9403.     case 3:  // Game Data
  9404.         value = this.gameDataOperand(this._params[4], this._params[5], this._params[6]);
  9405.         break;
  9406.     case 4:  // Script
  9407.         value = eval(this._params[4]);
  9408.         break;
  9409.     }
  9410.     for (var i = this._params[0]; i <= this._params[1]; i++) {
  9411.         this.operateVariable(i, this._params[2], value);
  9412.     }
  9413.     return true;
  9414. };
  9415.  
  9416. Game_Interpreter.prototype.gameDataOperand = function(type, param1, param2) {
  9417.     switch (type) {
  9418.     case 0:  // Item
  9419.         return $gameParty.numItems($dataItems[param1]);
  9420.     case 1:  // Weapon
  9421.         return $gameParty.numItems($dataWeapons[param1]);
  9422.     case 2:  // Armor
  9423.         return $gameParty.numItems($dataArmors[param1]);
  9424.     case 3:  // Actor
  9425.         var actor = $gameActors.actor(param1);
  9426.         if (actor) {
  9427.             switch (param2) {
  9428.             case 0:  // Level
  9429.                 return actor.level;
  9430.             case 1:  // EXP
  9431.                 return actor.currentExp();
  9432.             case 2:  // HP
  9433.                 return actor.hp;
  9434.             case 3:  // MP
  9435.                 return actor.mp;
  9436.             default:    // Parameter
  9437.                 if (param2 >= 4 && param2 <= 11) {
  9438.                     return actor.param(param2 - 4);
  9439.                 }
  9440.             }
  9441.         }
  9442.         break;
  9443.     case 4:  // Enemy
  9444.         var enemy = $gameTroop.members()[param1];
  9445.         if (enemy) {
  9446.             switch (param2) {
  9447.             case 0:  // HP
  9448.                 return enemy.hp;
  9449.             case 1:  // MP
  9450.                 return enemy.mp;
  9451.             default:    // Parameter
  9452.                 if (param2 >= 2 && param2 <= 9) {
  9453.                     return enemy.param(param2 - 2);
  9454.                 }
  9455.             }
  9456.         }
  9457.         break;
  9458.     case 5:  // Character
  9459.         var character = this.character(param1);
  9460.         if (character) {
  9461.             switch (param2) {
  9462.             case 0:  // Map X
  9463.                 return character.x;
  9464.             case 1:  // Map Y
  9465.                 return character.y;
  9466.             case 2:  // Direction
  9467.                 return character.direction();
  9468.             case 3:  // Screen X
  9469.                 return character.screenX();
  9470.             case 4:  // Screen Y
  9471.                 return character.screenY();
  9472.             }
  9473.         }
  9474.         break;
  9475.     case 6:  // Party
  9476.         actor = $gameParty.members()[param1];
  9477.         return actor ? actor.actorId() : 0;
  9478.     case 7:  // Other
  9479.         switch (param1) {
  9480.         case 0:  // Map ID
  9481.             return $gameMap.mapId();
  9482.         case 1:  // Party Members
  9483.             return $gameParty.size();
  9484.         case 2:  // Gold
  9485.             return $gameParty.gold();
  9486.         case 3:  // Steps
  9487.             return $gameParty.steps();
  9488.         case 4:  // Play Time
  9489.             return $gameSystem.playtime();
  9490.         case 5:  // Timer
  9491.             return $gameTimer.seconds();
  9492.         case 6:  // Save Count
  9493.             return $gameSystem.saveCount();
  9494.         case 7:  // Battle Count
  9495.             return $gameSystem.battleCount();
  9496.         case 8:  // Win Count
  9497.             return $gameSystem.winCount();
  9498.         case 9:  // Escape Count
  9499.             return $gameSystem.escapeCount();
  9500.         }
  9501.         break;
  9502.     }
  9503.     return 0;
  9504. };
  9505.  
  9506. Game_Interpreter.prototype.operateVariable = function(variableId, operationType, value) {
  9507.     try {
  9508.         var oldValue = $gameVariables.value(variableId);
  9509.         switch (operationType) {
  9510.         case 0:  // Set
  9511.             $gameVariables.setValue(variableId, oldValue = value);
  9512.             break;
  9513.         case 1:  // Add
  9514.             $gameVariables.setValue(variableId, oldValue + value);
  9515.             break;
  9516.         case 2:  // Sub
  9517.             $gameVariables.setValue(variableId, oldValue - value);
  9518.             break;
  9519.         case 3:  // Mul
  9520.             $gameVariables.setValue(variableId, oldValue * value);
  9521.             break;
  9522.         case 4:  // Div
  9523.             $gameVariables.setValue(variableId, oldValue / value);
  9524.             break;
  9525.         case 5:  // Mod
  9526.             $gameVariables.setValue(variableId, oldValue % value);
  9527.             break;
  9528.         }
  9529.     } catch (e) {
  9530.         $gameVariables.setValue(variableId, 0);
  9531.     }
  9532. };
  9533.  
  9534. // Control Self Switch
  9535. Game_Interpreter.prototype.command123 = function() {
  9536.     if (this._eventId > 0) {
  9537.         var key = [this._mapId, this._eventId, this._params[0]];
  9538.         $gameSelfSwitches.setValue(key, this._params[1] === 0);
  9539.     }
  9540.     return true;
  9541. };
  9542.  
  9543. // Control Timer
  9544. Game_Interpreter.prototype.command124 = function() {
  9545.     if (this._params[0] === 0) {  // Start
  9546.         $gameTimer.start(this._params[1] * 60);
  9547.     } else {  // Stop
  9548.         $gameTimer.stop();
  9549.     }
  9550.     return true;
  9551. };
  9552.  
  9553. // Change Gold
  9554. Game_Interpreter.prototype.command125 = function() {
  9555.     var value = this.operateValue(this._params[0], this._params[1], this._params[2]);
  9556.     $gameParty.gainGold(value);
  9557.     return true;
  9558. };
  9559.  
  9560. // Change Items
  9561. Game_Interpreter.prototype.command126 = function() {
  9562.     var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
  9563.     $gameParty.gainItem($dataItems[this._params[0]], value);
  9564.     return true;
  9565. };
  9566.  
  9567. // Change Weapons
  9568. Game_Interpreter.prototype.command127 = function() {
  9569.     var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
  9570.     $gameParty.gainItem($dataWeapons[this._params[0]], value, this._params[4]);
  9571.     return true;
  9572. };
  9573.  
  9574. // Change Armors
  9575. Game_Interpreter.prototype.command128 = function() {
  9576.     var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
  9577.     $gameParty.gainItem($dataArmors[this._params[0]], value, this._params[4]);
  9578.     return true;
  9579. };
  9580.  
  9581. // Change Party Member
  9582. Game_Interpreter.prototype.command129 = function() {
  9583.     var actor = $gameActors.actor(this._params[0]);
  9584.     if (actor) {
  9585.         if (this._params[1] === 0) {  // Add
  9586.             if (this._params[2]) {   // Initialize
  9587.                 $gameActors.actor(this._params[0]).setup(this._params[0]);
  9588.             }
  9589.             $gameParty.addActor(this._params[0]);
  9590.         } else {  // Remove
  9591.             $gameParty.removeActor(this._params[0]);
  9592.         }
  9593.     }
  9594.     return true;
  9595. };
  9596.  
  9597. // Change Battle BGM
  9598. Game_Interpreter.prototype.command132 = function() {
  9599.     $gameSystem.setBattleBgm(this._params[0]);
  9600.     return true;
  9601. };
  9602.  
  9603. // Change Victory ME
  9604. Game_Interpreter.prototype.command133 = function() {
  9605.     $gameSystem.setVictoryMe(this._params[0]);
  9606.     return true;
  9607. };
  9608.  
  9609. // Change Save Access
  9610. Game_Interpreter.prototype.command134 = function() {
  9611.     if (this._params[0] === 0) {
  9612.         $gameSystem.disableSave();
  9613.     } else {
  9614.         $gameSystem.enableSave();
  9615.     }
  9616.     return true;
  9617. };
  9618.  
  9619. // Change Menu Access
  9620. Game_Interpreter.prototype.command135 = function() {
  9621.     if (this._params[0] === 0) {
  9622.         $gameSystem.disableMenu();
  9623.     } else {
  9624.         $gameSystem.enableMenu();
  9625.     }
  9626.     return true;
  9627. };
  9628.  
  9629. // Change Encounter Disable
  9630. Game_Interpreter.prototype.command136 = function() {
  9631.     if (this._params[0] === 0) {
  9632.         $gameSystem.disableEncounter();
  9633.     } else {
  9634.         $gameSystem.enableEncounter();
  9635.     }
  9636.     $gamePlayer.makeEncounterCount();
  9637.     return true;
  9638. };
  9639.  
  9640. // Change Formation Access
  9641. Game_Interpreter.prototype.command137 = function() {
  9642.     if (this._params[0] === 0) {
  9643.         $gameSystem.disableFormation();
  9644.     } else {
  9645.         $gameSystem.enableFormation();
  9646.     }
  9647.     return true;
  9648. };
  9649.  
  9650. // Change Window Color
  9651. Game_Interpreter.prototype.command138 = function() {
  9652.     $gameSystem.setWindowTone(this._params[0]);
  9653.     return true;
  9654. };
  9655.  
  9656. // Change Defeat ME
  9657. Game_Interpreter.prototype.command139 = function() {
  9658.     $gameSystem.setDefeatMe(this._params[0]);
  9659.     return true;
  9660. };
  9661.  
  9662. // Change Vehicle BGM
  9663. Game_Interpreter.prototype.command140 = function() {
  9664.     var vehicle = $gameMap.vehicle(this._params[0]);
  9665.     if (vehicle) {
  9666.         vehicle.setBgm(this._params[1]);
  9667.     }
  9668.     return true;
  9669. };
  9670.  
  9671. // Transfer Player
  9672. Game_Interpreter.prototype.command201 = function() {
  9673.     if (!$gameParty.inBattle() && !$gameMessage.isBusy()) {
  9674.         var mapId, x, y;
  9675.         if (this._params[0] === 0) {  // Direct designation
  9676.             mapId = this._params[1];
  9677.             x = this._params[2];
  9678.             y = this._params[3];
  9679.         } else {  // Designation with variables
  9680.             mapId = $gameVariables.value(this._params[1]);
  9681.             x = $gameVariables.value(this._params[2]);
  9682.             y = $gameVariables.value(this._params[3]);
  9683.         }
  9684.         $gamePlayer.reserveTransfer(mapId, x, y, this._params[4], this._params[5]);
  9685.         this.setWaitMode('transfer');
  9686.         this._index++;
  9687.     }
  9688.     return false;
  9689. };
  9690.  
  9691. // Set Vehicle Location
  9692. Game_Interpreter.prototype.command202 = function() {
  9693.     var mapId, x, y;
  9694.     if (this._params[1] === 0) {  // Direct designation
  9695.         mapId = this._params[2];
  9696.         x = this._params[3];
  9697.         y = this._params[4];
  9698.     } else {  // Designation with variables
  9699.         mapId = $gameVariables.value(this._params[2]);
  9700.         x = $gameVariables.value(this._params[3]);
  9701.         y = $gameVariables.value(this._params[4]);
  9702.     }
  9703.     var vehicle = $gameMap.vehicle(this._params[0]);
  9704.     if (vehicle) {
  9705.         vehicle.setLocation(mapId, x, y);
  9706.     }
  9707.     return true;
  9708. };
  9709.  
  9710. // Set Event Location
  9711. Game_Interpreter.prototype.command203 = function() {
  9712.     var character = this.character(this._params[0]);
  9713.     if (character) {
  9714.         if (this._params[1] === 0) {  // Direct designation
  9715.             character.locate(this._params[2], this._params[3]);
  9716.         } else if (this._params[1] === 1) {  // Designation with variables
  9717.             var x = $gameVariables.value(this._params[2]);
  9718.             var y = $gameVariables.value(this._params[3]);
  9719.             character.locate(x, y);
  9720.         } else {  // Exchange with another event
  9721.             var character2 = this.character(this._params[2]);
  9722.             if (character2) {
  9723.                 character.swap(character2);
  9724.             }
  9725.         }
  9726.         if (this._params[4] > 0) {
  9727.             character.setDirection(this._params[4]);
  9728.         }
  9729.     }
  9730.     return true;
  9731. };
  9732.  
  9733. // Scroll Map
  9734. Game_Interpreter.prototype.command204 = function() {
  9735.     if (!$gameParty.inBattle()) {
  9736.         if ($gameMap.isScrolling()) {
  9737.             this.setWaitMode('scroll');
  9738.             return false;
  9739.         }
  9740.         $gameMap.startScroll(this._params[0], this._params[1], this._params[2]);
  9741.     }
  9742.     return true;
  9743. };
  9744.  
  9745. // Set Movement Route
  9746. Game_Interpreter.prototype.command205 = function() {
  9747.     $gameMap.refreshIfNeeded();
  9748.     this._character = this.character(this._params[0]);
  9749.     if (this._character) {
  9750.         this._character.forceMoveRoute(this._params[1]);
  9751.         if (this._params[1].wait) {
  9752.             this.setWaitMode('route');
  9753.         }
  9754.     }
  9755.     return true;
  9756. };
  9757.  
  9758. // Getting On and Off Vehicles
  9759. Game_Interpreter.prototype.command206 = function() {
  9760.     $gamePlayer.getOnOffVehicle();
  9761.     return true;
  9762. };
  9763.  
  9764. // Change Transparency
  9765. Game_Interpreter.prototype.command211 = function() {
  9766.     $gamePlayer.setTransparent(this._params[0] === 0);
  9767.     return true;
  9768. };
  9769.  
  9770. // Show Animation
  9771. Game_Interpreter.prototype.command212 = function() {
  9772.     this._character = this.character(this._params[0]);
  9773.     if (this._character) {
  9774.         this._character.requestAnimation(this._params[1]);
  9775.         if (this._params[2]) {
  9776.             this.setWaitMode('animation');
  9777.         }
  9778.     }
  9779.     return true;
  9780. };
  9781.  
  9782. // Show Balloon Icon
  9783. Game_Interpreter.prototype.command213 = function() {
  9784.     this._character = this.character(this._params[0]);
  9785.     if (this._character) {
  9786.         this._character.requestBalloon(this._params[1]);
  9787.         if (this._params[2]) {
  9788.             this.setWaitMode('balloon');
  9789.         }
  9790.     }
  9791.     return true;
  9792. };
  9793.  
  9794. // Erase Event
  9795. Game_Interpreter.prototype.command214 = function() {
  9796.     if (this.isOnCurrentMap() && this._eventId > 0) {
  9797.         $gameMap.eraseEvent(this._eventId);
  9798.     }
  9799.     return true;
  9800. };
  9801.  
  9802. // Change Player Followers
  9803. Game_Interpreter.prototype.command216 = function() {
  9804.     if (this._params[0] === 0) {
  9805.         $gamePlayer.showFollowers();
  9806.     } else {
  9807.         $gamePlayer.hideFollowers();
  9808.     }
  9809.     $gamePlayer.refresh();
  9810.     return true;
  9811. };
  9812.  
  9813. // Gather Followers
  9814. Game_Interpreter.prototype.command217 = function() {
  9815.     if (!$gameParty.inBattle()) {
  9816.         $gamePlayer.gatherFollowers();
  9817.         this.setWaitMode('gather');
  9818.     }
  9819.     return true;
  9820. };
  9821.  
  9822. // Fadeout Screen
  9823. Game_Interpreter.prototype.command221 = function() {
  9824.     if (!$gameMessage.isBusy()) {
  9825.         $gameScreen.startFadeOut(this.fadeSpeed());
  9826.         this.wait(this.fadeSpeed());
  9827.         this._index++;
  9828.     }
  9829.     return false;
  9830. };
  9831.  
  9832. // Fadein Screen
  9833. Game_Interpreter.prototype.command222 = function() {
  9834.     if (!$gameMessage.isBusy()) {
  9835.         $gameScreen.startFadeIn(this.fadeSpeed());
  9836.         this.wait(this.fadeSpeed());
  9837.         this._index++;
  9838.     }
  9839.     return false;
  9840. };
  9841.  
  9842. // Tint Screen
  9843. Game_Interpreter.prototype.command223 = function() {
  9844.     $gameScreen.startTint(this._params[0], this._params[1]);
  9845.     if (this._params[2]) {
  9846.         this.wait(this._params[1]);
  9847.     }
  9848.     return true;
  9849. };
  9850.  
  9851. // Flash Screen
  9852. Game_Interpreter.prototype.command224 = function() {
  9853.     $gameScreen.startFlash(this._params[0], this._params[1]);
  9854.     if (this._params[2]) {
  9855.         this.wait(this._params[1]);
  9856.     }
  9857.     return true;
  9858. };
  9859.  
  9860. // Shake Screen
  9861. Game_Interpreter.prototype.command225 = function() {
  9862.     $gameScreen.startShake(this._params[0], this._params[1], this._params[2]);
  9863.     if (this._params[3]) {
  9864.         this.wait(this._params[2]);
  9865.     }
  9866.     return true;
  9867. };
  9868.  
  9869. // Wait
  9870. Game_Interpreter.prototype.command230 = function() {
  9871.     this.wait(this._params[0]);
  9872.     return true;
  9873. };
  9874.  
  9875. // Show Picture
  9876. Game_Interpreter.prototype.command231 = function() {
  9877.     var x, y;
  9878.     if (this._params[3] === 0) {  // Direct designation
  9879.         x = this._params[4];
  9880.         y = this._params[5];
  9881.     } else {  // Designation with variables
  9882.         x = $gameVariables.value(this._params[4]);
  9883.         y = $gameVariables.value(this._params[5]);
  9884.     }
  9885.     $gameScreen.showPicture(this._params[0], this._params[1], this._params[2],
  9886.         x, y, this._params[6], this._params[7], this._params[8], this._params[9]);
  9887.     return true;
  9888. };
  9889.  
  9890. // Move Picture
  9891. Game_Interpreter.prototype.command232 = function() {
  9892.     var x, y;
  9893.     if (this._params[3] === 0) {  // Direct designation
  9894.         x = this._params[4];
  9895.         y = this._params[5];
  9896.     } else {  // Designation with variables
  9897.         x = $gameVariables.value(this._params[4]);
  9898.         y = $gameVariables.value(this._params[5]);
  9899.     }
  9900.     $gameScreen.movePicture(this._params[0], this._params[2], x, y, this._params[6],
  9901.         this._params[7], this._params[8], this._params[9], this._params[10]);
  9902.     if (this._params[11]) {
  9903.         this.wait(this._params[10]);
  9904.     }
  9905.     return true;
  9906. };
  9907.  
  9908. // Rotate Picture
  9909. Game_Interpreter.prototype.command233 = function() {
  9910.     $gameScreen.rotatePicture(this._params[0], this._params[1]);
  9911.     return true;
  9912. };
  9913.  
  9914. // Tint Picture
  9915. Game_Interpreter.prototype.command234 = function() {
  9916.     $gameScreen.tintPicture(this._params[0], this._params[1], this._params[2]);
  9917.     if (this._params[3]) {
  9918.         this.wait(this._params[2]);
  9919.     }
  9920.     return true;
  9921. };
  9922.  
  9923. // Erase Picture
  9924. Game_Interpreter.prototype.command235 = function() {
  9925.     $gameScreen.erasePicture(this._params[0]);
  9926.     return true;
  9927. };
  9928.  
  9929. // Set Weather Effect
  9930. Game_Interpreter.prototype.command236 = function() {
  9931.     if (!$gameParty.inBattle()) {
  9932.         $gameScreen.changeWeather(this._params[0], this._params[1], this._params[2]);
  9933.         if (this._params[3]) {
  9934.             this.wait(this._params[2]);
  9935.         }
  9936.     }
  9937.     return true;
  9938. };
  9939.  
  9940. // Play BGM
  9941. Game_Interpreter.prototype.command241 = function() {
  9942.     AudioManager.playBgm(this._params[0]);
  9943.     return true;
  9944. };
  9945.  
  9946. // Fadeout BGM
  9947. Game_Interpreter.prototype.command242 = function() {
  9948.     AudioManager.fadeOutBgm(this._params[0]);
  9949.     return true;
  9950. };
  9951.  
  9952. // Save BGM
  9953. Game_Interpreter.prototype.command243 = function() {
  9954.     $gameSystem.saveBgm();
  9955.     return true;
  9956. };
  9957.  
  9958. // Resume BGM
  9959. Game_Interpreter.prototype.command244 = function() {
  9960.     $gameSystem.replayBgm();
  9961.     return true;
  9962. };
  9963.  
  9964. // Play BGS
  9965. Game_Interpreter.prototype.command245 = function() {
  9966.     AudioManager.playBgs(this._params[0]);
  9967.     return true;
  9968. };
  9969.  
  9970. // Fadeout BGS
  9971. Game_Interpreter.prototype.command246 = function() {
  9972.     AudioManager.fadeOutBgs(this._params[0]);
  9973.     return true;
  9974. };
  9975.  
  9976. // Play ME
  9977. Game_Interpreter.prototype.command249 = function() {
  9978.     AudioManager.playMe(this._params[0]);
  9979.     return true;
  9980. };
  9981.  
  9982. // Play SE
  9983. Game_Interpreter.prototype.command250 = function() {
  9984.     AudioManager.playSe(this._params[0]);
  9985.     return true;
  9986. };
  9987.  
  9988. // Stop SE
  9989. Game_Interpreter.prototype.command251 = function() {
  9990.     AudioManager.stopSe();
  9991.     return true;
  9992. };
  9993.  
  9994. // Play Movie
  9995. Game_Interpreter.prototype.command261 = function() {
  9996.     if (!$gameMessage.isBusy()) {
  9997.         var name = this._params[0];
  9998.         if (name.length > 0) {
  9999.             var ext = this.videoFileExt();
  10000.             Graphics.playVideo('movies/' + name + ext);
  10001.             this.setWaitMode('video');
  10002.         }
  10003.         this._index++;
  10004.     }
  10005.     return false;
  10006. };
  10007.  
  10008. Game_Interpreter.prototype.videoFileExt = function() {
  10009.     if (Graphics.canPlayVideoType('video/webm') && !Utils.isMobileDevice()) {
  10010.         return '.webm';
  10011.     } else {
  10012.         return '.mp4';
  10013.     }
  10014. };
  10015.  
  10016. // Change Map Name Display
  10017. Game_Interpreter.prototype.command281 = function() {
  10018.     if (this._params[0] === 0) {
  10019.         $gameMap.enableNameDisplay();
  10020.     } else {
  10021.         $gameMap.disableNameDisplay();
  10022.     }
  10023.     return true;
  10024. };
  10025.  
  10026. // Change Tileset
  10027. Game_Interpreter.prototype.command282 = function() {
  10028.     var tileset = $dataTilesets[this._params[0]];
  10029.     for (var i = 0; i < tileset.tilesetNames.length; i++) {
  10030.         ImageManager.loadTileset(tileset.tilesetNames[i]);
  10031.     }
  10032.     if (ImageManager.isReady()) {
  10033.         $gameMap.changeTileset(this._params[0]);
  10034.         return true;
  10035.     } else {
  10036.         return false;
  10037.     }
  10038. };
  10039.  
  10040. // Change Battle Back
  10041. Game_Interpreter.prototype.command283 = function() {
  10042.     $gameMap.changeBattleback(this._params[0], this._params[1]);
  10043.     return true;
  10044. };
  10045.  
  10046. // Change Parallax
  10047. Game_Interpreter.prototype.command284 = function() {
  10048.     $gameMap.changeParallax(this._params[0], this._params[1],
  10049.         this._params[2], this._params[3], this._params[4]);
  10050.     return true;
  10051. };
  10052.  
  10053. // Get Location Info
  10054. Game_Interpreter.prototype.command285 = function() {
  10055.     var x, y, value;
  10056.     if (this._params[2] === 0) {  // Direct designation
  10057.         x = this._params[3];
  10058.         y = this._params[4];
  10059.     } else {  // Designation with variables
  10060.         x = $gameVariables.value(this._params[3]);
  10061.         y = $gameVariables.value(this._params[4]);
  10062.     }
  10063.     switch (this._params[1]) {
  10064.     case 0:     // Terrain Tag
  10065.         value = $gameMap.terrainTag(x, y);
  10066.         break;
  10067.     case 1:     // Event ID
  10068.         value = $gameMap.eventIdXy(x, y);
  10069.         break;
  10070.     case 2:     // Tile ID (Layer 1)
  10071.     case 3:     // Tile ID (Layer 2)
  10072.     case 4:     // Tile ID (Layer 3)
  10073.     case 5:     // Tile ID (Layer 4)
  10074.         value = $gameMap.tileId(x, y, this._params[1] - 2);
  10075.         break;
  10076.     default:    // Region ID
  10077.         value = $gameMap.regionId(x, y);
  10078.         break;
  10079.     }
  10080.     $gameVariables.setValue(this._params[0], value);
  10081.     return true;
  10082. };
  10083.  
  10084. // Battle Processing
  10085. Game_Interpreter.prototype.command301 = function() {
  10086.     if (!$gameParty.inBattle()) {
  10087.         var troopId;
  10088.         if (this._params[0] === 0) {  // Direct designation
  10089.             troopId = this._params[1];
  10090.         } else if (this._params[0] === 1) {  // Designation with a variable
  10091.             troopId = $gameVariables.value(this._params[1]);
  10092.         } else {  // Same as Random Encounter
  10093.             troopId = $gamePlayer.makeEncounterTroopId();
  10094.         }
  10095.         if ($dataTroops[troopId]) {
  10096.             BattleManager.setup(troopId, this._params[2], this._params[3]);
  10097.             BattleManager.setEventCallback(function(n) {
  10098.                 this._branch[this._indent] = n;
  10099.             }.bind(this));
  10100.             $gamePlayer.makeEncounterCount();
  10101.             SceneManager.push(Scene_Battle);
  10102.         }
  10103.     }
  10104.     return true;
  10105. };
  10106.  
  10107. // If Win
  10108. Game_Interpreter.prototype.command601 = function() {
  10109.     if (this._branch[this._indent] !== 0) {
  10110.         this.skipBranch();
  10111.     }
  10112.     return true;
  10113. };
  10114.  
  10115. // If Escape
  10116. Game_Interpreter.prototype.command602 = function() {
  10117.     if (this._branch[this._indent] !== 1) {
  10118.         this.skipBranch();
  10119.     }
  10120.     return true;
  10121. };
  10122.  
  10123. // If Lose
  10124. Game_Interpreter.prototype.command603 = function() {
  10125.     if (this._branch[this._indent] !== 2) {
  10126.         this.skipBranch();
  10127.     }
  10128.     return true;
  10129. };
  10130.  
  10131. // Shop Processing
  10132. Game_Interpreter.prototype.command302 = function() {
  10133.     if (!$gameParty.inBattle()) {
  10134.         var goods = [this._params];
  10135.         while (this.nextEventCode() === 605) {
  10136.             this._index++;
  10137.             goods.push(this.currentCommand().parameters);
  10138.         }
  10139.         SceneManager.push(Scene_Shop);
  10140.         SceneManager.prepareNextScene(goods, this._params[4]);
  10141.     }
  10142.     return true;
  10143. };
  10144.  
  10145. // Name Input Processing
  10146. Game_Interpreter.prototype.command303 = function() {
  10147.     if (!$gameParty.inBattle()) {
  10148.         if ($dataActors[this._params[0]]) {
  10149.             SceneManager.push(Scene_Name);
  10150.             SceneManager.prepareNextScene(this._params[0], this._params[1]);
  10151.         }
  10152.     }
  10153.     return true;
  10154. };
  10155.  
  10156. // Change HP
  10157. Game_Interpreter.prototype.command311 = function() {
  10158.     var value = this.operateValue(this._params[2], this._params[3], this._params[4]);
  10159.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10160.         this.changeHp(actor, value, this._params[5]);
  10161.     }.bind(this));
  10162.     return true;
  10163. };
  10164.  
  10165. // Change MP
  10166. Game_Interpreter.prototype.command312 = function() {
  10167.     var value = this.operateValue(this._params[2], this._params[3], this._params[4]);
  10168.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10169.         actor.gainMp(value);
  10170.     }.bind(this));
  10171.     return true;
  10172. };
  10173.  
  10174. // Change TP
  10175. Game_Interpreter.prototype.command326 = function() {
  10176.     var value = this.operateValue(this._params[2], this._params[3], this._params[4]);
  10177.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10178.         actor.gainTp(value);
  10179.     }.bind(this));
  10180.     return true;
  10181. };
  10182.  
  10183. // Change State
  10184. Game_Interpreter.prototype.command313 = function() {
  10185.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10186.         var alreadyDead = actor.isDead();
  10187.         if (this._params[2] === 0) {
  10188.             actor.addState(this._params[3]);
  10189.         } else {
  10190.             actor.removeState(this._params[3]);
  10191.         }
  10192.         if (actor.isDead() && !alreadyDead) {
  10193.             actor.performCollapse();
  10194.         }
  10195.         actor.clearResult();
  10196.     }.bind(this));
  10197.     return true;
  10198. };
  10199.  
  10200. // Recover All
  10201. Game_Interpreter.prototype.command314 = function() {
  10202.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10203.         actor.recoverAll();
  10204.     }.bind(this));
  10205.     return true;
  10206. };
  10207.  
  10208. // Change EXP
  10209. Game_Interpreter.prototype.command315 = function() {
  10210.     var value = this.operateValue(this._params[2], this._params[3], this._params[4]);
  10211.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10212.         actor.changeExp(actor.currentExp() + value, this._params[5]);
  10213.     }.bind(this));
  10214.     return true;
  10215. };
  10216.  
  10217. // Change Level
  10218. Game_Interpreter.prototype.command316 = function() {
  10219.     var value = this.operateValue(this._params[2], this._params[3], this._params[4]);
  10220.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10221.         actor.changeLevel(actor.level + value, this._params[5]);
  10222.     }.bind(this));
  10223.     return true;
  10224. };
  10225.  
  10226. // Change Parameter
  10227. Game_Interpreter.prototype.command317 = function() {
  10228.     var value = this.operateValue(this._params[3], this._params[4], this._params[5]);
  10229.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10230.         actor.addParam(this._params[2], value);
  10231.     }.bind(this));
  10232.     return true;
  10233. };
  10234.  
  10235. // Change Skill
  10236. Game_Interpreter.prototype.command318 = function() {
  10237.     this.iterateActorEx(this._params[0], this._params[1], function(actor) {
  10238.         if (this._params[2] === 0) {
  10239.             actor.learnSkill(this._params[3]);
  10240.         } else {
  10241.             actor.forgetSkill(this._params[3]);
  10242.         }
  10243.     }.bind(this));
  10244.     return true;
  10245. };
  10246.  
  10247. // Change Equipment
  10248. Game_Interpreter.prototype.command319 = function() {
  10249.     var actor = $gameActors.actor(this._params[0]);
  10250.     if (actor) {
  10251.         actor.changeEquipById(this._params[1], this._params[2]);
  10252.     }
  10253.     return true;
  10254. };
  10255.  
  10256. // Change Name
  10257. Game_Interpreter.prototype.command320 = function() {
  10258.     var actor = $gameActors.actor(this._params[0]);
  10259.     if (actor) {
  10260.         actor.setName(this._params[1]);
  10261.     }
  10262.     return true;
  10263. };
  10264.  
  10265. // Change Class
  10266. Game_Interpreter.prototype.command321 = function() {
  10267.     var actor = $gameActors.actor(this._params[0]);
  10268.     if (actor && $dataClasses[this._params[1]]) {
  10269.         actor.changeClass(this._params[1], this._params[2]);
  10270.     }
  10271.     return true;
  10272. };
  10273.  
  10274. // Change Actor Images
  10275. Game_Interpreter.prototype.command322 = function() {
  10276.     var actor = $gameActors.actor(this._params[0]);
  10277.     if (actor) {
  10278.         actor.setCharacterImage(this._params[1], this._params[2]);
  10279.         actor.setFaceImage(this._params[3], this._params[4]);
  10280.         actor.setBattlerImage(this._params[5]);
  10281.     }
  10282.     $gamePlayer.refresh();
  10283.     return true;
  10284. };
  10285.  
  10286. // Change Vehicle Image
  10287. Game_Interpreter.prototype.command323 = function() {
  10288.     var vehicle = $gameMap.vehicle(this._params[0]);
  10289.     if (vehicle) {
  10290.         vehicle.setImage(this._params[1], this._params[2]);
  10291.     }
  10292.     return true;
  10293. };
  10294.  
  10295. // Change Nickname
  10296. Game_Interpreter.prototype.command324 = function() {
  10297.     var actor = $gameActors.actor(this._params[0]);
  10298.     if (actor) {
  10299.         actor.setNickname(this._params[1]);
  10300.     }
  10301.     return true;
  10302. };
  10303.  
  10304. // Change Profile
  10305. Game_Interpreter.prototype.command325 = function() {
  10306.     var actor = $gameActors.actor(this._params[0]);
  10307.     if (actor) {
  10308.         actor.setProfile(this._params[1]);
  10309.     }
  10310.     return true;
  10311. };
  10312.  
  10313. // Change Enemy HP
  10314. Game_Interpreter.prototype.command331 = function() {
  10315.     var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
  10316.     this.iterateEnemyIndex(this._params[0], function(enemy) {
  10317.         this.changeHp(enemy, value, this._params[4]);
  10318.     }.bind(this));
  10319.     return true;
  10320. };
  10321.  
  10322. // Change Enemy MP
  10323. Game_Interpreter.prototype.command332 = function() {
  10324.     var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
  10325.     this.iterateEnemyIndex(this._params[0], function(enemy) {
  10326.         enemy.gainMp(value);
  10327.     }.bind(this));
  10328.     return true;
  10329. };
  10330.  
  10331. // Change Enemy TP
  10332. Game_Interpreter.prototype.command342 = function() {
  10333.     var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
  10334.     this.iterateEnemyIndex(this._params[0], function(enemy) {
  10335.         enemy.gainTp(value);
  10336.     }.bind(this));
  10337.     return true;
  10338. };
  10339.  
  10340. // Change Enemy State
  10341. Game_Interpreter.prototype.command333 = function() {
  10342.     this.iterateEnemyIndex(this._params[0], function(enemy) {
  10343.         var alreadyDead = enemy.isDead();
  10344.         if (this._params[1] === 0) {
  10345.             enemy.addState(this._params[2]);
  10346.         } else {
  10347.             enemy.removeState(this._params[2]);
  10348.         }
  10349.         if (enemy.isDead() && !alreadyDead) {
  10350.             enemy.performCollapse();
  10351.         }
  10352.         enemy.clearResult();
  10353.     }.bind(this));
  10354.     return true;
  10355. };
  10356.  
  10357. // Enemy Recover All
  10358. Game_Interpreter.prototype.command334 = function() {
  10359.     this.iterateEnemyIndex(this._params[0], function(enemy) {
  10360.         enemy.recoverAll();
  10361.     }.bind(this));
  10362.     return true;
  10363. };
  10364.  
  10365. // Enemy Appear
  10366. Game_Interpreter.prototype.command335 = function() {
  10367.     this.iterateEnemyIndex(this._params[0], function(enemy) {
  10368.         enemy.appear();
  10369.         $gameTroop.makeUniqueNames();
  10370.     }.bind(this));
  10371.     return true;
  10372. };
  10373.  
  10374. // Enemy Transform
  10375. Game_Interpreter.prototype.command336 = function() {
  10376.     this.iterateEnemyIndex(this._params[0], function(enemy) {
  10377.         enemy.transform(this._params[1]);
  10378.         $gameTroop.makeUniqueNames();
  10379.     }.bind(this));
  10380.     return true;
  10381. };
  10382.  
  10383. // Show Battle Animation
  10384. Game_Interpreter.prototype.command337 = function() {
  10385.     if (this._params[2] == true) {
  10386.         this.iterateEnemyIndex(-1,function(enemy) {
  10387.             if (enemy.isAlive()) {
  10388.                 enemy.startAnimation(this._params[1],false,0);
  10389.             }
  10390.         }.bind(this));
  10391.     } else {
  10392.         this.iterateEnemyIndex(this._params[0], function (enemy) {
  10393.             if (enemy.isAlive()) {
  10394.                 enemy.startAnimation(this._params[1], false, 0);
  10395.             }
  10396.         }.bind(this));
  10397.     }
  10398.     return true;
  10399. };
  10400.  
  10401. // Force Action
  10402. Game_Interpreter.prototype.command339 = function() {
  10403.     this.iterateBattler(this._params[0], this._params[1], function(battler) {
  10404.         if (!battler.isDeathStateAffected()) {
  10405.             battler.forceAction(this._params[2], this._params[3]);
  10406.             BattleManager.forceAction(battler);
  10407.             this.setWaitMode('action');
  10408.         }
  10409.     }.bind(this));
  10410.     return true;
  10411. };
  10412.  
  10413. // Abort Battle
  10414. Game_Interpreter.prototype.command340 = function() {
  10415.     BattleManager.abort();
  10416.     return true;
  10417. };
  10418.  
  10419. // Open Menu Screen
  10420. Game_Interpreter.prototype.command351 = function() {
  10421.     if (!$gameParty.inBattle()) {
  10422.         SceneManager.push(Scene_Menu);
  10423.         Window_MenuCommand.initCommandPosition();
  10424.     }
  10425.     return true;
  10426. };
  10427.  
  10428. // Open Save Screen
  10429. Game_Interpreter.prototype.command352 = function() {
  10430.     if (!$gameParty.inBattle()) {
  10431.         SceneManager.push(Scene_Save);
  10432.     }
  10433.     return true;
  10434. };
  10435.  
  10436. // Game Over
  10437. Game_Interpreter.prototype.command353 = function() {
  10438.     SceneManager.goto(Scene_Gameover);
  10439.     return true;
  10440. };
  10441.  
  10442. // Return to Title Screen
  10443. Game_Interpreter.prototype.command354 = function() {
  10444.     SceneManager.goto(Scene_Title);
  10445.     return true;
  10446. };
  10447.  
  10448. // Script
  10449. Game_Interpreter.prototype.command355 = function() {
  10450.     var script = this.currentCommand().parameters[0] + '\n';
  10451.     while (this.nextEventCode() === 655) {
  10452.         this._index++;
  10453.         script += this.currentCommand().parameters[0] + '\n';
  10454.     }
  10455.     eval(script);
  10456.     return true;
  10457. };
  10458.  
  10459. // Plugin Command
  10460. Game_Interpreter.prototype.command356 = function() {
  10461.     var args = this._params[0].split(" ");
  10462.     var command = args.shift();
  10463.     this.pluginCommand(command, args);
  10464.     return true;
  10465. };
  10466.  
  10467. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  10468.     // to be overridden by plugins
  10469. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement