PageSourceSearch

https://bdgalgame.github.io/js/rpg_scenes.js

js bdgalgame.github.io collected 2026-10-03 08:41:49 UTC 78,715 bytes, 2,689 lines download raw bytes

1//=============================================================================
2// rpg_scenes.js v1.5.1
3//=============================================================================
4
5//=============================================================================
6
7/**
8 * The Superclass of all scene within the game.
9 * 
10 * @class Scene_Base
11 * @constructor 
12 * @extends Stage
13 */
14function Scene_Base() {
15    this.initialize.apply(this, arguments);
16}
17
18Scene_Base.prototype = Object.create(Stage.prototype);
19Scene_Base.prototype.constructor = Scene_Base;
20
21
22/**
23 * Create a instance of Scene_Base.
24 * 
25 * @instance 
26 * @memberof Scene_Base
27 */
28Scene_Base.prototype.initialize = function() {
29    Stage.prototype.initialize.call(this);
30    this._active = false;
31    this._fadeSign = 0;
32    this._fadeDuration = 0;
33    this._fadeSprite = null;
34    this._imageReservationId = Utils.generateRuntimeId();
35};
36
37/**
38 * Attach a reservation to the reserve queue.
39 * 
40 * @method attachReservation
41 * @instance 
42 * @memberof Scene_Base
43 */
44Scene_Base.prototype.attachReservation = function() {
45    ImageManager.setDefaultReservationId(this._imageReservationId);
46};
47
48/**
49 * Remove the reservation from the Reserve queue.
50 * 
51 * @method detachReservation
52 * @instance 
53 * @memberof Scene_Base
54 */
55Scene_Base.prototype.detachReservation = function() {
56    ImageManager.releaseReservation(this._imageReservationId);
57};
58
59/**
60 * Create the components and add them to the rendering process.
61 * 
62 * @method create
63 * @instance 
64 * @memberof Scene_Base
65 */
66Scene_Base.prototype.create = function() {
67};
68
69/**
70 * Returns whether the scene is active or not.
71 * 
72 * @method isActive
73 * @instance 
74 * @memberof Scene_Base
75 * @return {Boolean} return true if the scene is active
76 */
77Scene_Base.prototype.isActive = function() {
78    return this._active;
79};
80
81/**
82 * Return whether the scene is ready to start or not.
83 * 
84 * @method isReady
85 * @instance 
86 * @memberof Scene_Base
87 * @return {Boolean} Return true if the scene is ready to start
88 */
89Scene_Base.prototype.isReady = function() {
90    return ImageManager.isReady();
91};
92
93/**
94 * Start the scene processing.
95 * 
96 * @method start
97 * @instance 
98 * @memberof Scene_Base
99 */
100Scene_Base.prototype.start = function() {
101    this._active = true;
102};
103
104/**
105 * Update the scene processing each new frame.
106 * 
107 * @method update
108 * @instance 
109 * @memberof Scene_Base
110 */
111Scene_Base.prototype.update = function() {
112    this.updateFade();
113    this.updateChildren();
114};
115
116/**
117 * Stop the scene processing.
118 * 
119 * @method stop
120 * @instance 
121 * @memberof Scene_Base
122 */
123Scene_Base.prototype.stop = function() {
124    this._active = false;
125};
126
127
128/**
129 * Return whether the scene is busy or not.
130 * 
131 * @method isBusy
132 * @instance
133 * @memberof Scene_Base
134 * @return {Boolean} Return true if the scene is currently busy
135 */
136Scene_Base.prototype.isBusy = function() {
137    return this._fadeDuration > 0;
138};
139
140/**
141 * Terminate the scene before switching to a another scene.
142 * 
143 * @method terminate
144 * @instance 
145 * @memberof Scene_Base
146 */
147Scene_Base.prototype.terminate = function() {
148};
149
150/**
151 * Create the layer for the windows children
152 * and add it to the rendering process.
153 * 
154 * @method createWindowLayer
155 * @instance 
156 * @memberof Scene_Base
157 */
158Scene_Base.prototype.createWindowLayer = function() {
159    var width = Graphics.boxWidth;
160    var height = Graphics.boxHeight;
161    var x = (Graphics.width - width) / 2;
162    var y = (Graphics.height - height) / 2;
163    this._windowLayer = new WindowLayer();
164    this._windowLayer.move(x, y, width, height);
165    this.addChild(this._windowLayer);
166};
167
168/**
169 * Add the children window to the windowLayer processing.
170 * 
171 * @method addWindow
172 * @instance 
173 * @memberof Scene_Base
174 */
175Scene_Base.prototype.addWindow = function(window) {
176    this._windowLayer.addChild(window);
177};
178
179/**
180 * Request a fadeIn screen process.
181 * 
182 * @method startFadeIn
183 * @param {Number} [duration=30] The time the process will take for fadeIn the screen
184 * @param {Boolean} [white=false] If true the fadein will be process with a white color else it's will be black
185 * 
186 * @instance 
187 * @memberof Scene_Base
188 */
189Scene_Base.prototype.startFadeIn = function(duration, white) {
190    this.createFadeSprite(white);
191    this._fadeSign = 1;
192    this._fadeDuration = duration || 30;
193    this._fadeSprite.opacity = 255;
194};
195
196/**
197 * Request a fadeOut screen process.
198 * 
199 * @method startFadeOut
200 * @param {Number} [duration=30] The time the process will take for fadeOut the screen
201 * @param {Boolean} [white=false] If true the fadeOut will be process with a white color else it's will be black
202 * 
203 * @instance 
204 * @memberof Scene_Base
205 */
206Scene_Base.prototype.startFadeOut = function(duration, white) {
207    this.createFadeSprite(white);
208    this._fadeSign = -1;
209    this._fadeDuration = duration || 30;
210    this._fadeSprite.opacity = 0;
211};
212
213/**
214 * Create a Screen sprite for the fadein and fadeOut purpose and
215 * add it to the rendering process.
216 * 
217 * @method createFadeSprite
218 * @instance 
219 * @memberof Scene_Base
220 */
221Scene_Base.prototype.createFadeSprite = function(white) {
222    if (!this._fadeSprite) {
223        this._fadeSprite = new ScreenSprite();
224        this.addChild(this._fadeSprite);
225    }
226    if (white) {
227        this._fadeSprite.setWhite();
228    } else {
229        this._fadeSprite.setBlack();
230    }
231};
232
233/**
234 * Update the screen fade processing.
235 * 
236 * @method updateFade
237 * @instance 
238 * @memberof Scene_Base
239 */
240Scene_Base.prototype.updateFade = function() {
241    if (this._fadeDuration > 0) {
242        var d = this._fadeDuration;
243        if (this._fadeSign > 0) {
244            this._fadeSprite.opacity -= this._fadeSprite.opacity / d;
245        } else {
246            this._fadeSprite.opacity += (255 - this._fadeSprite.opacity) / d;
247        }
248        this._fadeDuration--;
249    }
250};
251
252/**
253 * Update the children of the scene EACH frame.
254 * 
255 * @method updateChildren
256 * @instance 
257 * @memberof Scene_Base
258 */
259Scene_Base.prototype.updateChildren = function() {
260    this.children.forEach(function(child) {
261        if (child.update) {
262            child.update();
263        }
264    });
265};
266
267/**
268 * Pop the scene from the stack array and switch to the
269 * previous scene.
270 * 
271 * @method popScene
272 * @instance 
273 * @memberof Scene_Base
274 */
275Scene_Base.prototype.popScene = function() {
276    SceneManager.pop();
277};
278
279/**
280 * Check whether the game should be triggering a gameover.
281 * 
282 * @method checkGameover
283 * @instance 
284 * @memberof Scene_Base
285 */
286Scene_Base.prototype.checkGameover = function() {
287    if ($gameParty.isAllDead()) {
288        SceneManager.goto(Scene_Gameover);
289    }
290};
291
292/**
293 * Slowly fade out all the visual and audio of the scene.
294 * 
295 * @method fadeOutAll
296 * @instance 
297 * @memberof Scene_Base
298 */
299Scene_Base.prototype.fadeOutAll = function() {
300    var time = this.slowFadeSpeed() / 60;
301    AudioManager.fadeOutBgm(time);
302    AudioManager.fadeOutBgs(time);
303    AudioManager.fadeOutMe(time);
304    this.startFadeOut(this.slowFadeSpeed());
305};
306
307/**
308 * Return the screen fade speed value.
309 * 
310 * @method fadeSpeed
311 * @instance 
312 * @memberof Scene_Base
313 * @return {Number} Return the fade speed
314 */
315Scene_Base.prototype.fadeSpeed = function() {
316    return 24;
317};
318
319/**
320 * Return a slow screen fade speed value.
321 * 
322 * @method slowFadeSpeed
323 * @instance 
324 * @memberof Scene_Base
325 * @return {Number} Return the fade speed
326 */
327Scene_Base.prototype.slowFadeSpeed = function() {
328    return this.fadeSpeed() * 2;
329};
330
331//-----------------------------------------------------------------------------
332// Scene_Boot
333//
334// The scene class for initializing the entire game.
335
336function Scene_Boot() {
337    this.initialize.apply(this, arguments);
338}
339
340Scene_Boot.prototype = Object.create(Scene_Base.prototype);
341Scene_Boot.prototype.constructor = Scene_Boot;
342
343Scene_Boot.prototype.initialize = function() {
344    Scene_Base.prototype.initialize.call(this);
345    this._startDate = Date.now();
346};
347
348Scene_Boot.prototype.create = function() {
349    Scene_Base.prototype.create.call(this);
350    DataManager.loadDatabase();
351    ConfigManager.load();
352    this.loadSystemWindowImage();
353};
354
355Scene_Boot.prototype.loadSystemWindowImage = function() {
356    ImageManager.reserveSystem('Window');
357};
358
359Scene_Boot.loadSystemImages = function() {
360    ImageManager.reserveSystem('IconSet');
361    ImageManager.reserveSystem('Balloon');
362    ImageManager.reserveSystem('Shadow1');
363    ImageManager.reserveSystem('Shadow2');
364    ImageManager.reserveSystem('Damage');
365    ImageManager.reserveSystem('States');
366    ImageManager.reserveSystem('Weapons1');
367    ImageManager.reserveSystem('Weapons2');
368    ImageManager.reserveSystem('Weapons3');
369    ImageManager.reserveSystem('ButtonSet');
370};
371
372Scene_Boot.prototype.isReady = function() {
373    if (Scene_Base.prototype.isReady.call(this)) {
374        return DataManager.isDatabaseLoaded() && this.isGameFontLoaded();
375    } else {
376        return false;
377    }
378};
379
380Scene_Boot.prototype.isGameFontLoaded = function() {
381    if (Graphics.isFontLoaded('GameFont')) {
382        return true;
383    } else if (!Graphics.canUseCssFontLoading()){
384        var elapsed = Date.now() - this._startDate;
385        if (elapsed >= 60000) {
386            throw new Error('Failed to load GameFont');
387        }
388    }
389};
390
391Scene_Boot.prototype.start = function() {
392    Scene_Base.prototype.start.call(this);
393    SoundManager.preloadImportantSounds();
394    if (DataManager.isBattleTest()) {
395        DataManager.setupBattleTest();
396        SceneManager.goto(Scene_Battle);
397    } else if (DataManager.isEventTest()) {
398        DataManager.setupEventTest();
399        SceneManager.goto(Scene_Map);
400    } else {
401        this.checkPlayerLocation();
402        DataManager.setupNewGame();
403        SceneManager.goto(Scene_Title);
404        Window_TitleCommand.initCommandPosition();
405    }
406    this.updateDocumentTitle();
407};
408
409Scene_Boot.prototype.updateDocumentTitle = function() {
410    document.title = $dataSystem.gameTitle;
411};
412
413Scene_Boot.prototype.checkPlayerLocation = function() {
414    if ($dataSystem.startMapId === 0) {
415        throw new Error('Player\'s starting position is not set');
416    }
417};
418
419//-----------------------------------------------------------------------------
420// Scene_Title
421//
422// The scene class of the title screen.
423
424function Scene_Title() {
425    this.initialize.apply(this, arguments);
426}
427
428Scene_Title.prototype = Object.create(Scene_Base.prototype);
429Scene_Title.prototype.constructor = Scene_Title;
430
431Scene_Title.prototype.initialize = function() {
432    Scene_Base.prototype.initialize.call(this);
433};
434
435Scene_Title.prototype.create = function() {
436    Scene_Base.prototype.create.call(this);
437    this.createBackground();
438    this.createForeground();
439    this.createWindowLayer();
440    this.createCommandWindow();
441};
442
443Scene_Title.prototype.start = function() {
444    Scene_Base.prototype.start.call(this);
445    SceneManager.clearStack();
446    this.centerSprite(this._backSprite1);
447    this.centerSprite(this._backSprite2);
448    this.playTitleMusic();
449    this.startFadeIn(this.fadeSpeed(), false);
450};
451
452Scene_Title.prototype.update = function() {
453    if (!this.isBusy()) {
454        this._commandWindow.open();
455    }
456    Scene_Base.prototype.update.call(this);
457};
458
459Scene_Title.prototype.isBusy = function() {
460    return this._commandWindow.isClosing() || Scene_Base.prototype.isBusy.call(this);
461};
462
463Scene_Title.prototype.terminate = function() {
464    Scene_Base.prototype.terminate.call(this);
465    SceneManager.snapForBackground();
466};
467
468Scene_Title.prototype.createBackground = function() {
469    this._backSprite1 = new Sprite(ImageManager.loadTitle1($dataSystem.title1Name));
470    this._backSprite2 = new Sprite(ImageManager.loadTitle2($dataSystem.title2Name));
471    this.addChild(this._backSprite1);
472    this.addChild(this._backSprite2);
473};
474
475Scene_Title.prototype.createForeground = function() {
476    this._gameTitleSprite = new Sprite(new Bitmap(Graphics.width, Graphics.height));
477    this.addChild(this._gameTitleSprite);
478    if ($dataSystem.optDrawTitle) {
479        this.drawGameTitle();
480    }
481};
482
483Scene_Title.prototype.drawGameTitle = function() {
484    var x = 20;
485    var y = Graphics.height / 4;
486    var maxWidth = Graphics.width - x * 2;
487    var text = $dataSystem.gameTitle;
488    this._gameTitleSprite.bitmap.outlineColor = 'black';
489    this._gameTitleSprite.bitmap.outlineWidth = 8;
490    this._gameTitleSprite.bitmap.fontSize = 72;
491    this._gameTitleSprite.bitmap.drawText(text, x, y, maxWidth, 48, 'center');
492};
493
494Scene_Title.prototype.centerSprite = function(sprite) {
495    sprite.x = Graphics.width / 2;
496    sprite.y = Graphics.height / 2;
497    sprite.anchor.x = 0.5;
498    sprite.anchor.y = 0.5;
499};
500
501Scene_Title.prototype.createCommandWindow = function() {
502    this._commandWindow = new Window_TitleCommand();
503    this._commandWindow.setHandler('newGame',  this.commandNewGame.bind(this));
504    this._commandWindow.setHandler('continue', this.commandContinue.bind(this));
505    this._commandWindow.setHandler('options',  this.commandOptions.bind(this));
506    this.addWindow(this._commandWindow);
507};
508
509Scene_Title.prototype.commandNewGame = function() {
510    DataManager.setupNewGame();
511    this._commandWindow.close();
512    this.fadeOutAll();
513    SceneManager.goto(Scene_Map);
514};
515
516Scene_Title.prototype.commandContinue = function() {
517    this._commandWindow.close();
518    SceneManager.push(Scene_Load);
519};
520
521Scene_Title.prototype.commandOptions = function() {
522    this._commandWindow.close();
523    SceneManager.push(Scene_Options);
524};
525
526Scene_Title.prototype.playTitleMusic = function() {
527    AudioManager.playBgm($dataSystem.titleBgm);
528    AudioManager.stopBgs();
529    AudioManager.stopMe();
530};
531
532//-----------------------------------------------------------------------------
533// Scene_Map
534//
535// The scene class of the map screen.
536
537function Scene_Map() {
538    this.initialize.apply(this, arguments);
539}
540
541Scene_Map.prototype = Object.create(Scene_Base.prototype);
542Scene_Map.prototype.constructor = Scene_Map;
543
544Scene_Map.prototype.initialize = function() {
545    Scene_Base.prototype.initialize.call(this);
546    this._waitCount = 0;
547    this._encounterEffectDuration = 0;
548    this._mapLoaded = false;
549    this._touchCount = 0;
550};
551
552Scene_Map.prototype.create = function() {
553    Scene_Base.prototype.create.call(this);
554    this._transfer = $gamePlayer.isTransferring();
555    var mapId = this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId();
556    DataManager.loadMapData(mapId);
557};
558
559Scene_Map.prototype.isReady = function() {
560    if (!this._mapLoaded && DataManager.isMapLoaded()) {
561        this.onMapLoaded();
562        this._mapLoaded = true;
563    }
564    return this._mapLoaded && Scene_Base.prototype.isReady.call(this);
565};
566
567Scene_Map.prototype.onMapLoaded = function() {
568    if (this._transfer) {
569        $gamePlayer.performTransfer();
570    }
571    this.createDisplayObjects();
572};
573
574Scene_Map.prototype.start = function() {
575    Scene_Base.prototype.start.call(this);
576    SceneManager.clearStack();
577    if (this._transfer) {
578        this.fadeInForTransfer();
579        this._mapNameWindow.open();
580        $gameMap.autoplay();
581    } else if (this.needsFadeIn()) {
582        this.startFadeIn(this.fadeSpeed(), false);
583    }
584    this.menuCalling = false;
585};
586
587Scene_Map.prototype.update = function() {
588    this.updateDestination();
589    this.updateMainMultiply();
590    if (this.isSceneChangeOk()) {
591        this.updateScene();
592    } else if (SceneManager.isNextScene(Scene_Battle)) {
593        this.updateEncounterEffect();
594    }
595    this.updateWaitCount();
596    Scene_Base.prototype.update.call(this);
597};
598
599Scene_Map.prototype.updateMainMultiply = function() {
600    this.updateMain();
601    if (this.isFastForward()) {
602        this.updateMain();
603    }
604};
605
606Scene_Map.prototype.updateMain = function() {
607    var active = this.isActive();
608    $gameMap.update(active);
609    $gamePlayer.update(active);
610    $gameTimer.update(active);
611    $gameScreen.update();
612};
613
614Scene_Map.prototype.isFastForward = function() {
615    return ($gameMap.isEventRunning() && !SceneManager.isSceneChanging() &&
616            (Input.isLongPressed('ok') || TouchInput.isLongPressed()));
617};
618
619Scene_Map.prototype.stop = function() {
620    Scene_Base.prototype.stop.call(this);
621    $gamePlayer.straighten();
622    this._mapNameWindow.close();
623    if (this.needsSlowFadeOut()) {
624        this.startFadeOut(this.slowFadeSpeed(), false);
625    } else if (SceneManager.isNextScene(Scene_Map)) {
626        this.fadeOutForTransfer();
627    } else if (SceneManager.isNextScene(Scene_Battle)) {
628        this.launchBattle();
629    }
630};
631
632Scene_Map.prototype.isBusy = function() {
633    return ((this._messageWindow && this._messageWindow.isClosing()) ||
634            this._waitCount > 0 || this._encounterEffectDuration > 0 ||
635            Scene_Base.prototype.isBusy.call(this));
636};
637
638Scene_Map.prototype.terminate = function() {
639    Scene_Base.prototype.terminate.call(this);
640    if (!SceneManager.isNextScene(Scene_Battle)) {
641        this._spriteset.update();
642        this._mapNameWindow.hide();
643        SceneManager.snapForBackground();
644    } else {
645        ImageManager.clearRequest();
646    }
647
648    if (SceneManager.isNextScene(Scene_Map)) {
649        ImageManager.clearRequest();
650    }
651
652    $gameScreen.clearZoom();
653
654    this.removeChild(this._fadeSprite);
655    this.removeChild(this._mapNameWindow);
656    this.removeChild(this._windowLayer);
657    this.removeChild(this._spriteset);
658};
659
660Scene_Map.prototype.needsFadeIn = function() {
661    return (SceneManager.isPreviousScene(Scene_Battle) ||
662            SceneManager.isPreviousScene(Scene_Load));
663};
664
665Scene_Map.prototype.needsSlowFadeOut = function() {
666    return (SceneManager.isNextScene(Scene_Title) ||
667            SceneManager.isNextScene(Scene_Gameover));
668};
669
670Scene_Map.prototype.updateWaitCount = function() {
671    if (this._waitCount > 0) {
672        this._waitCount--;
673        return true;
674    }
675    return false;
676};
677
678Scene_Map.prototype.updateDestination = function() {
679    if (this.isMapTouchOk()) {
680        this.processMapTouch();
681    } else {
682        $gameTemp.clearDestination();
683        this._touchCount = 0;
684    }
685};
686
687Scene_Map.prototype.isMapTouchOk = function() {
688    return this.isActive() && $gamePlayer.canMove();
689};
690
691Scene_Map.prototype.processMapTouch = function() {
692    if (TouchInput.isTriggered() || this._touchCount > 0) {
693        if (TouchInput.isPressed()) {
694            if (this._touchCount === 0 || this._touchCount >= 15) {
695                var x = $gameMap.canvasToMapX(TouchInput.x);
696                var y = $gameMap.canvasToMapY(TouchInput.y);
697                $gameTemp.setDestination(x, y);
698            }
699            this._touchCount++;
700        } else {
701            this._touchCount = 0;
702        }
703    }
704};
705
706Scene_Map.prototype.isSceneChangeOk = function() {
707    return this.isActive() && !$gameMessage.isBusy();
708};
709
710Scene_Map.prototype.updateScene = function() {
711    this.checkGameover();
712    if (!SceneManager.isSceneChanging()) {
713        this.updateTransferPlayer();
714    }
715    if (!SceneManager.isSceneChanging()) {
716        this.updateEncounter();
717    }
718    if (!SceneManager.isSceneChanging()) {
719        this.updateCallMenu();
720    }
721    if (!SceneManager.isSceneChanging()) {
722        this.updateCallDebug();
723    }
724};
725
726Scene_Map.prototype.createDisplayObjects = function() {
727    this.createSpriteset();
728    this.createMapNameWindow();
729    this.createWindowLayer();
730    this.createAllWindows();
731};
732
733Scene_Map.prototype.createSpriteset = function() {
734    this._spriteset = new Spriteset_Map();
735    this.addChild(this._spriteset);
736};
737
738Scene_Map.prototype.createAllWindows = function() {
739    this.createMessageWindow();
740    this.createScrollTextWindow();
741};
742
743Scene_Map.prototype.createMapNameWindow = function() {
744    this._mapNameWindow = new Window_MapName();
745    this.addChild(this._mapNameWindow);
746};
747
748Scene_Map.prototype.createMessageWindow = function() {
749    this._messageWindow = new Window_Message();
750    this.addWindow(this._messageWindow);
751    this._messageWindow.subWindows().forEach(function(window) {
752        this.addWindow(window);
753    }, this);
754};
755
756Scene_Map.prototype.createScrollTextWindow = function() {
757    this._scrollTextWindow = new Window_ScrollText();
758    this.addWindow(this._scrollTextWindow);
759};
760
761Scene_Map.prototype.updateTransferPlayer = function() {
762    if ($gamePlayer.isTransferring()) {
763        SceneManager.goto(Scene_Map);
764    }
765};
766
767Scene_Map.prototype.updateEncounter = function() {
768   if ($gamePlayer.executeEncounter()) {
769       SceneManager.push(Scene_Battle);
770   }
771};
772
773Scene_Map.prototype.updateCallMenu = function() {
774    if (this.isMenuEnabled()) {
775        if (this.isMenuCalled()) {
776            this.menuCalling = true;
777        }
778        if (this.menuCalling && !$gamePlayer.isMoving()) {
779            this.callMenu();
780        }
781    } else {
782        this.menuCalling = false;
783    }
784};
785
786Scene_Map.prototype.isMenuEnabled = function() {
787    return $gameSystem.isMenuEnabled() && !$gameMap.isEventRunning();
788};
789
790Scene_Map.prototype.isMenuCalled = function() {
791    return Input.isTriggered('menu') || TouchInput.isCancelled();
792};
793
794Scene_Map.prototype.callMenu = function() {
795    SoundManager.playOk();
796    SceneManager.push(Scene_Menu);
797    Window_MenuCommand.initCommandPosition();
798    $gameTemp.clearDestination();
799    this._mapNameWindow.hide();
800    this._waitCount = 2;
801};
802
803Scene_Map.prototype.updateCallDebug = function() {
804    if (this.isDebugCalled()) {
805        SceneManager.push(Scene_Debug);
806    }
807};
808
809Scene_Map.prototype.isDebugCalled = function() {
810    return Input.isTriggered('debug') && $gameTemp.isPlaytest();
811};
812
813Scene_Map.prototype.fadeInForTransfer = function() {
814    var fadeType = $gamePlayer.fadeType();
815    switch (fadeType) {
816    case 0: case 1:
817        this.startFadeIn(this.fadeSpeed(), fadeType === 1);
818        break;
819    }
820};
821
822Scene_Map.prototype.fadeOutForTransfer = function() {
823    var fadeType = $gamePlayer.fadeType();
824    switch (fadeType) {
825    case 0: case 1:
826        this.startFadeOut(this.fadeSpeed(), fadeType === 1);
827        break;
828    }
829};
830
831Scene_Map.prototype.launchBattle = function() {
832    BattleManager.saveBgmAndBgs();
833    this.stopAudioOnBattleStart();
834    SoundManager.playBattleStart();
835    this.startEncounterEffect();
836    this._mapNameWindow.hide();
837};
838
839Scene_Map.prototype.stopAudioOnBattleStart = function() {
840    if (!AudioManager.isCurrentBgm($gameSystem.battleBgm())) {
841        AudioManager.stopBgm();
842    }
843    AudioManager.stopBgs();
844    AudioManager.stopMe();
845    AudioManager.stopSe();
846};
847
848Scene_Map.prototype.startEncounterEffect = function() {
849    this._spriteset.hideCharacters();
850    this._encounterEffectDuration = this.encounterEffectSpeed();
851};
852
853Scene_Map.prototype.updateEncounterEffect = function() {
854    if (this._encounterEffectDuration > 0) {
855        this._encounterEffectDuration--;
856        var speed = this.encounterEffectSpeed();
857        var n = speed - this._encounterEffectDuration;
858        var p = n / speed;
859        var q = ((p - 1) * 20 * p + 5) * p + 1;
860        var zoomX = $gamePlayer.screenX();
861        var zoomY = $gamePlayer.screenY() - 24;
862        if (n === 2) {
863            $gameScreen.setZoom(zoomX, zoomY, 1);
864            this.snapForBattleBackground();
865            this.startFlashForEncounter(speed / 2);
866        }
867        $gameScreen.setZoom(zoomX, zoomY, q);
868        if (n === Math.floor(speed / 6)) {
869            this.startFlashForEncounter(speed / 2);
870        }
871        if (n === Math.floor(speed / 2)) {
872            BattleManager.playBattleBgm();
873            this.startFadeOut(this.fadeSpeed());
874        }
875    }
876};
877
878Scene_Map.prototype.snapForBattleBackground = function() {
879    this._windowLayer.visible = false;
880    SceneManager.snapForBackground();
881    this._windowLayer.visible = true;
882};
883
884Scene_Map.prototype.startFlashForEncounter = function(duration) {
885    var color = [255, 255, 255, 255];
886    $gameScreen.startFlash(color, duration);
887};
888
889Scene_Map.prototype.encounterEffectSpeed = function() {
890    return 60;
891};
892
893//-----------------------------------------------------------------------------
894// Scene_MenuBase
895//
896// The superclass of all the menu-type scenes.
897
898function Scene_MenuBase() {
899    this.initialize.apply(this, arguments);
900}
901
902Scene_MenuBase.prototype = Object.create(Scene_Base.prototype);
903Scene_MenuBase.prototype.constructor = Scene_MenuBase;
904
905Scene_MenuBase.prototype.initialize = function() {
906    Scene_Base.prototype.initialize.call(this);
907};
908
909Scene_MenuBase.prototype.create = function() {
910    Scene_Base.prototype.create.call(this);
911    this.createBackground();
912    this.updateActor();
913    this.createWindowLayer();
914};
915
916Scene_MenuBase.prototype.actor = function() {
917    return this._actor;
918};
919
920Scene_MenuBase.prototype.updateActor = function() {
921    this._actor = $gameParty.menuActor();
922};
923
924Scene_MenuBase.prototype.createBackground = function() {
925    this._backgroundSprite = new Sprite();
926    this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
927    this.addChild(this._backgroundSprite);
928};
929
930Scene_MenuBase.prototype.setBackgroundOpacity = function(opacity) {
931    this._backgroundSprite.opacity = opacity;
932};
933
934Scene_MenuBase.prototype.createHelpWindow = function() {
935    this._helpWindow = new Window_Help();
936    this.addWindow(this._helpWindow);
937};
938
939Scene_MenuBase.prototype.nextActor = function() {
940    $gameParty.makeMenuActorNext();
941    this.updateActor();
942    this.onActorChange();
943};
944
945Scene_MenuBase.prototype.previousActor = function() {
946    $gameParty.makeMenuActorPrevious();
947    this.updateActor();
948    this.onActorChange();
949};
950
951Scene_MenuBase.prototype.onActorChange = function() {
952};
953
954//-----------------------------------------------------------------------------
955// Scene_Menu
956//
957// The scene class of the menu screen.
958
959function Scene_Menu() {
960    this.initialize.apply(this, arguments);
961}
962
963Scene_Menu.prototype = Object.create(Scene_MenuBase.prototype);
964Scene_Menu.prototype.constructor = Scene_Menu;
965
966Scene_Menu.prototype.initialize = function() {
967    Scene_MenuBase.prototype.initialize.call(this);
968};
969
970Scene_Menu.prototype.create = function() {
971    Scene_MenuBase.prototype.create.call(this);
972    this.createCommandWindow();
973    this.createGoldWindow();
974    this.createStatusWindow();
975};
976
977Scene_Menu.prototype.start = function() {
978    Scene_MenuBase.prototype.start.call(this);
979    this._statusWindow.refresh();
980};
981
982Scene_Menu.prototype.createCommandWindow = function() {
983    this._commandWindow = new Window_MenuCommand(0, 0);
984    this._commandWindow.setHandler('item',      this.commandItem.bind(this));
985    this._commandWindow.setHandler('skill',     this.commandPersonal.bind(this));
986    this._commandWindow.setHandler('equip',     this.commandPersonal.bind(this));
987    this._commandWindow.setHandler('status',    this.commandPersonal.bind(this));
988    this._commandWindow.setHandler('formation', this.commandFormation.bind(this));
989    this._commandWindow.setHandler('options',   this.commandOptions.bind(this));
990    this._commandWindow.setHandler('save',      this.commandSave.bind(this));
991    this._commandWindow.setHandler('gameEnd',   this.commandGameEnd.bind(this));
992    this._commandWindow.setHandler('cancel',    this.popScene.bind(this));
993    this.addWindow(this._commandWindow);
994};
995
996Scene_Menu.prototype.createGoldWindow = function() {
997    this._goldWindow = new Window_Gold(0, 0);
998    this._goldWindow.y = Graphics.boxHeight - this._goldWindow.height;
999    this.addWindow(this._goldWindow);
1000};
1001
1002Scene_Menu.prototype.createStatusWindow = function() {
1003    this._statusWindow = new Window_MenuStatus(this._commandWindow.width, 0);
1004    this._statusWindow.reserveFaceImages();
1005    this.addWindow(this._statusWindow);
1006};
1007
1008Scene_Menu.prototype.commandItem = function() {
1009    SceneManager.push(Scene_Item);
1010};
1011
1012Scene_Menu.prototype.commandPersonal = function() {
1013    this._statusWindow.setFormationMode(false);
1014    this._statusWindow.selectLast();
1015    this._statusWindow.activate();
1016    this._statusWindow.setHandler('ok',     this.onPersonalOk.bind(this));
1017    this._statusWindow.setHandler('cancel', this.onPersonalCancel.bind(this));
1018};
1019
1020Scene_Menu.prototype.commandFormation = function() {
1021    this._statusWindow.setFormationMode(true);
1022    this._statusWindow.selectLast();
1023    this._statusWindow.activate();
1024    this._statusWindow.setHandler('ok',     this.onFormationOk.bind(this));
1025    this._statusWindow.setHandler('cancel', this.onFormationCancel.bind(this));
1026};
1027
1028Scene_Menu.prototype.commandOptions = function() {
1029    SceneManager.push(Scene_Options);
1030};
1031
1032Scene_Menu.prototype.commandSave = function() {
1033    SceneManager.push(Scene_Save);
1034};
1035
1036Scene_Menu.prototype.commandGameEnd = function() {
1037    SceneManager.push(Scene_GameEnd);
1038};
1039
1040Scene_Menu.prototype.onPersonalOk = function() {
1041    switch (this._commandWindow.currentSymbol()) {
1042    case 'skill':
1043        SceneManager.push(Scene_Skill);
1044        break;
1045    case 'equip':
1046        SceneManager.push(Scene_Equip);
1047        break;
1048    case 'status':
1049        SceneManager.push(Scene_Status);
1050        break;
1051    }
1052};
1053
1054Scene_Menu.prototype.onPersonalCancel = function() {
1055    this._statusWindow.deselect();
1056    this._commandWindow.activate();
1057};
1058
1059Scene_Menu.prototype.onFormationOk = function() {
1060    var index = this._statusWindow.index();
1061    var actor = $gameParty.members()[index];
1062    var pendingIndex = this._statusWindow.pendingIndex();
1063    if (pendingIndex >= 0) {
1064        $gameParty.swapOrder(index, pendingIndex);
1065        this._statusWindow.setPendingIndex(-1);
1066        this._statusWindow.redrawItem(index);
1067    } else {
1068        this._statusWindow.setPendingIndex(index);
1069    }
1070    this._statusWindow.activate();
1071};
1072
1073Scene_Menu.prototype.onFormationCancel = function() {
1074    if (this._statusWindow.pendingIndex() >= 0) {
1075        this._statusWindow.setPendingIndex(-1);
1076        this._statusWindow.activate();
1077    } else {
1078        this._statusWindow.deselect();
1079        this._commandWindow.activate();
1080    }
1081};
1082
1083//-----------------------------------------------------------------------------
1084// Scene_ItemBase
1085//
1086// The superclass of Scene_Item and Scene_Skill.
1087
1088function Scene_ItemBase() {
1089    this.initialize.apply(this, arguments);
1090}
1091
1092Scene_ItemBase.prototype = Object.create(Scene_MenuBase.prototype);
1093Scene_ItemBase.prototype.constructor = Scene_ItemBase;
1094
1095Scene_ItemBase.prototype.initialize = function() {
1096    Scene_MenuBase.prototype.initialize.call(this);
1097};
1098
1099Scene_ItemBase.prototype.create = function() {
1100    Scene_MenuBase.prototype.create.call(this);
1101};
1102
1103Scene_ItemBase.prototype.createActorWindow = function() {
1104    this._actorWindow = new Window_MenuActor();
1105    this._actorWindow.setHandler('ok',     this.onActorOk.bind(this));
1106    this._actorWindow.setHandler('cancel', this.onActorCancel.bind(this));
1107    this.addWindow(this._actorWindow);
1108};
1109
1110Scene_ItemBase.prototype.item = function() {
1111    return this._itemWindow.item();
1112};
1113
1114Scene_ItemBase.prototype.user = function() {
1115    return null;
1116};
1117
1118Scene_ItemBase.prototype.isCursorLeft = function() {
1119    return this._itemWindow.index() % 2 === 0;
1120};
1121
1122Scene_ItemBase.prototype.showSubWindow = function(window) {
1123    window.x = this.isCursorLeft() ? Graphics.boxWidth - window.width : 0;
1124    window.show();
1125    window.activate();
1126};
1127
1128Scene_ItemBase.prototype.hideSubWindow = function(window) {
1129    window.hide();
1130    window.deactivate();
1131    this.activateItemWindow();
1132};
1133
1134Scene_ItemBase.prototype.onActorOk = function() {
1135    if (this.canUse()) {
1136        this.useItem();
1137    } else {
1138        SoundManager.playBuzzer();
1139    }
1140};
1141
1142Scene_ItemBase.prototype.onActorCancel = function() {
1143    this.hideSubWindow(this._actorWindow);
1144};
1145
1146Scene_ItemBase.prototype.determineItem = function() {
1147    var action = new Game_Action(this.user());
1148    var item = this.item();
1149    action.setItemObject(item);
1150    if (action.isForFriend()) {
1151        this.showSubWindow(this._actorWindow);
1152        this._actorWindow.selectForItem(this.item());
1153    } else {
1154        this.useItem();
1155        this.activateItemWindow();
1156    }
1157};
1158
1159Scene_ItemBase.prototype.useItem = function() {
1160    this.playSeForItem();
1161    this.user().useItem(this.item());
1162    this.applyItem();
1163    this.checkCommonEvent();
1164    this.checkGameover();
1165    this._actorWindow.refresh();
1166};
1167
1168Scene_ItemBase.prototype.activateItemWindow = function() {
1169    this._itemWindow.refresh();
1170    this._itemWindow.activate();
1171};
1172
1173Scene_ItemBase.prototype.itemTargetActors = function() {
1174    var action = new Game_Action(this.user());
1175    action.setItemObject(this.item());
1176    if (!action.isForFriend()) {
1177        return [];
1178    } else if (action.isForAll()) {
1179        return $gameParty.members();
1180    } else {
1181        return [$gameParty.members()[this._actorWindow.index()]];
1182    }
1183};
1184
1185Scene_ItemBase.prototype.canUse = function() {
1186    return this.user().canUse(this.item()) && this.isItemEffectsValid();
1187};
1188
1189Scene_ItemBase.prototype.isItemEffectsValid = function() {
1190    var action = new Game_Action(this.user());
1191    action.setItemObject(this.item());
1192    return this.itemTargetActors().some(function(target) {
1193        return action.testApply(target);
1194    }, this);
1195};
1196
1197Scene_ItemBase.prototype.applyItem = function() {
1198    var action = new Game_Action(this.user());
1199    action.setItemObject(this.item());
1200    this.itemTargetActors().forEach(function(target) {
1201        for (var i = 0; i < action.numRepeats(); i++) {
1202            action.apply(target);
1203        }
1204    }, this);
1205    action.applyGlobal();
1206};
1207
1208Scene_ItemBase.prototype.checkCommonEvent = function() {
1209    if ($gameTemp.isCommonEventReserved()) {
1210        SceneManager.goto(Scene_Map);
1211    }
1212};
1213
1214//-----------------------------------------------------------------------------
1215// Scene_Item
1216//
1217// The scene class of the item screen.
1218
1219function Scene_Item() {
1220    this.initialize.apply(this, arguments);
1221}
1222
1223Scene_Item.prototype = Object.create(Scene_ItemBase.prototype);
1224Scene_Item.prototype.constructor = Scene_Item;
1225
1226Scene_Item.prototype.initialize = function() {
1227    Scene_ItemBase.prototype.initialize.call(this);
1228};
1229
1230Scene_Item.prototype.create = function() {
1231    Scene_ItemBase.prototype.create.call(this);
1232    this.createHelpWindow();
1233    this.createCategoryWindow();
1234    this.createItemWindow();
1235    this.createActorWindow();
1236};
1237
1238Scene_Item.prototype.createCategoryWindow = function() {
1239    this._categoryWindow = new Window_ItemCategory();
1240    this._categoryWindow.setHelpWindow(this._helpWindow);
1241    this._categoryWindow.y = this._helpWindow.height;
1242    this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
1243    this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
1244    this.addWindow(this._categoryWindow);
1245};
1246
1247Scene_Item.prototype.createItemWindow = function() {
1248    var wy = this._categoryWindow.y + this._categoryWindow.height;
1249    var wh = Graphics.boxHeight - wy;
1250    this._itemWindow = new Window_ItemList(0, wy, Graphics.boxWidth, wh);
1251    this._itemWindow.setHelpWindow(this._helpWindow);
1252    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
1253    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
1254    this.addWindow(this._itemWindow);
1255    this._categoryWindow.setItemWindow(this._itemWindow);
1256};
1257
1258Scene_Item.prototype.user = function() {
1259    var members = $gameParty.movableMembers();
1260    var bestActor = members[0];
1261    var bestPha = 0;
1262    for (var i = 0; i < members.length; i++) {
1263        if (members[i].pha > bestPha) {
1264            bestPha = members[i].pha;
1265            bestActor = members[i];
1266        }
1267    }
1268    return bestActor;
1269};
1270
1271Scene_Item.prototype.onCategoryOk = function() {
1272    this._itemWindow.activate();
1273    this._itemWindow.selectLast();
1274};
1275
1276Scene_Item.prototype.onItemOk = function() {
1277    $gameParty.setLastItem(this.item());
1278    this.determineItem();
1279};
1280
1281Scene_Item.prototype.onItemCancel = function() {
1282    this._itemWindow.deselect();
1283    this._categoryWindow.activate();
1284};
1285
1286Scene_Item.prototype.playSeForItem = function() {
1287    SoundManager.playUseItem();
1288};
1289
1290Scene_Item.prototype.useItem = function() {
1291    Scene_ItemBase.prototype.useItem.call(this);
1292    this._itemWindow.redrawCurrentItem();
1293};
1294
1295//-----------------------------------------------------------------------------
1296// Scene_Skill
1297//
1298// The scene class of the skill screen.
1299
1300function Scene_Skill() {
1301    this.initialize.apply(this, arguments);
1302}
1303
1304Scene_Skill.prototype = Object.create(Scene_ItemBase.prototype);
1305Scene_Skill.prototype.constructor = Scene_Skill;
1306
1307Scene_Skill.prototype.initialize = function() {
1308    Scene_ItemBase.prototype.initialize.call(this);
1309};
1310
1311Scene_Skill.prototype.create = function() {
1312    Scene_ItemBase.prototype.create.call(this);
1313    this.createHelpWindow();
1314    this.createSkillTypeWindow();
1315    this.createStatusWindow();
1316    this.createItemWindow();
1317    this.createActorWindow();
1318};
1319
1320Scene_Skill.prototype.start = function() {
1321    Scene_ItemBase.prototype.start.call(this);
1322    this.refreshActor();
1323};
1324
1325Scene_Skill.prototype.createSkillTypeWindow = function() {
1326    var wy = this._helpWindow.height;
1327    this._skillTypeWindow = new Window_SkillType(0, wy);
1328    this._skillTypeWindow.setHelpWindow(this._helpWindow);
1329    this._skillTypeWindow.setHandler('skill',    this.commandSkill.bind(this));
1330    this._skillTypeWindow.setHandler('cancel',   this.popScene.bind(this));
1331    this._skillTypeWindow.setHandler('pagedown', this.nextActor.bind(this));
1332    this._skillTypeWindow.setHandler('pageup',   this.previousActor.bind(this));
1333    this.addWindow(this._skillTypeWindow);
1334};
1335
1336Scene_Skill.prototype.createStatusWindow = function() {
1337    var wx = this._skillTypeWindow.width;
1338    var wy = this._helpWindow.height;
1339    var ww = Graphics.boxWidth - wx;
1340    var wh = this._skillTypeWindow.height;
1341    this._statusWindow = new Window_SkillStatus(wx, wy, ww, wh);
1342    this._statusWindow.reserveFaceImages();
1343    this.addWindow(this._statusWindow);
1344};
1345
1346Scene_Skill.prototype.createItemWindow = function() {
1347    var wx = 0;
1348    var wy = this._statusWindow.y + this._statusWindow.height;
1349    var ww = Graphics.boxWidth;
1350    var wh = Graphics.boxHeight - wy;
1351    this._itemWindow = new Window_SkillList(wx, wy, ww, wh);
1352    this._itemWindow.setHelpWindow(this._helpWindow);
1353    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
1354    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
1355    this._skillTypeWindow.setSkillWindow(this._itemWindow);
1356    this.addWindow(this._itemWindow);
1357};
1358
1359Scene_Skill.prototype.refreshActor = function() {
1360    var actor = this.actor();
1361    this._skillTypeWindow.setActor(actor);
1362    this._statusWindow.setActor(actor);
1363    this._itemWindow.setActor(actor);
1364};
1365
1366Scene_Skill.prototype.user = function() {
1367    return this.actor();
1368};
1369
1370Scene_Skill.prototype.commandSkill = function() {
1371    this._itemWindow.activate();
1372    this._itemWindow.selectLast();
1373};
1374
1375Scene_Skill.prototype.onItemOk = function() {
1376    this.actor().setLastMenuSkill(this.item());
1377    this.determineItem();
1378};
1379
1380Scene_Skill.prototype.onItemCancel = function() {
1381    this._itemWindow.deselect();
1382    this._skillTypeWindow.activate();
1383};
1384
1385Scene_Skill.prototype.playSeForItem = function() {
1386    SoundManager.playUseSkill();
1387};
1388
1389Scene_Skill.prototype.useItem = function() {
1390    Scene_ItemBase.prototype.useItem.call(this);
1391    this._statusWindow.refresh();
1392    this._itemWindow.refresh();
1393};
1394
1395Scene_Skill.prototype.onActorChange = function() {
1396    this.refreshActor();
1397    this._skillTypeWindow.activate();
1398};
1399
1400//-----------------------------------------------------------------------------
1401// Scene_Equip
1402//
1403// The scene class of the equipment screen.
1404
1405function Scene_Equip() {
1406    this.initialize.apply(this, arguments);
1407}
1408
1409Scene_Equip.prototype = Object.create(Scene_MenuBase.prototype);
1410Scene_Equip.prototype.constructor = Scene_Equip;
1411
1412Scene_Equip.prototype.initialize = function() {
1413    Scene_MenuBase.prototype.initialize.call(this);
1414};
1415
1416Scene_Equip.prototype.create = function() {
1417    Scene_MenuBase.prototype.create.call(this);
1418    this.createHelpWindow();
1419    this.createStatusWindow();
1420    this.createCommandWindow();
1421    this.createSlotWindow();
1422    this.createItemWindow();
1423    this.refreshActor();
1424};
1425
1426Scene_Equip.prototype.createStatusWindow = function() {
1427    this._statusWindow = new Window_EquipStatus(0, this._helpWindow.height);
1428    this.addWindow(this._statusWindow);
1429};
1430
1431Scene_Equip.prototype.createCommandWindow = function() {
1432    var wx = this._statusWindow.width;
1433    var wy = this._helpWindow.height;
1434    var ww = Graphics.boxWidth - this._statusWindow.width;
1435    this._commandWindow = new Window_EquipCommand(wx, wy, ww);
1436    this._commandWindow.setHelpWindow(this._helpWindow);
1437    this._commandWindow.setHandler('equip',    this.commandEquip.bind(this));
1438    this._commandWindow.setHandler('optimize', this.commandOptimize.bind(this));
1439    this._commandWindow.setHandler('clear',    this.commandClear.bind(this));
1440    this._commandWindow.setHandler('cancel',   this.popScene.bind(this));
1441    this._commandWindow.setHandler('pagedown', this.nextActor.bind(this));
1442    this._commandWindow.setHandler('pageup',   this.previousActor.bind(this));
1443    this.addWindow(this._commandWindow);
1444};
1445
1446Scene_Equip.prototype.createSlotWindow = function() {
1447    var wx = this._statusWindow.width;
1448    var wy = this._commandWindow.y + this._commandWindow.height;
1449    var ww = Graphics.boxWidth - this._statusWindow.width;
1450    var wh = this._statusWindow.height - this._commandWindow.height;
1451    this._slotWindow = new Window_EquipSlot(wx, wy, ww, wh);
1452    this._slotWindow.setHelpWindow(this._helpWindow);
1453    this._slotWindow.setStatusWindow(this._statusWindow);
1454    this._slotWindow.setHandler('ok',       this.onSlotOk.bind(this));
1455    this._slotWindow.setHandler('cancel',   this.onSlotCancel.bind(this));
1456    this.addWindow(this._slotWindow);
1457};
1458
1459Scene_Equip.prototype.createItemWindow = function() {
1460    var wx = 0;
1461    var wy = this._statusWindow.y + this._statusWindow.height;
1462    var ww = Graphics.boxWidth;
1463    var wh = Graphics.boxHeight - wy;
1464    this._itemWindow = new Window_EquipItem(wx, wy, ww, wh);
1465    this._itemWindow.setHelpWindow(this._helpWindow);
1466    this._itemWindow.setStatusWindow(this._statusWindow);
1467    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
1468    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
1469    this._slotWindow.setItemWindow(this._itemWindow);
1470    this.addWindow(this._itemWindow);
1471};
1472
1473Scene_Equip.prototype.refreshActor = function() {
1474    var actor = this.actor();
1475    this._statusWindow.setActor(actor);
1476    this._slotWindow.setActor(actor);
1477    this._itemWindow.setActor(actor);
1478};
1479
1480Scene_Equip.prototype.commandEquip = function() {
1481    this._slotWindow.activate();
1482    this._slotWindow.select(0);
1483};
1484
1485Scene_Equip.prototype.commandOptimize = function() {
1486    SoundManager.playEquip();
1487    this.actor().optimizeEquipments();
1488    this._statusWindow.refresh();
1489    this._slotWindow.refresh();
1490    this._commandWindow.activate();
1491};
1492
1493Scene_Equip.prototype.commandClear = function() {
1494    SoundManager.playEquip();
1495    this.actor().clearEquipments();
1496    this._statusWindow.refresh();
1497    this._slotWindow.refresh();
1498    this._commandWindow.activate();
1499};
1500
1501Scene_Equip.prototype.onSlotOk = function() {
1502    this._itemWindow.activate();
1503    this._itemWindow.select(0);
1504};
1505
1506Scene_Equip.prototype.onSlotCancel = function() {
1507    this._slotWindow.deselect();
1508    this._commandWindow.activate();
1509};
1510
1511Scene_Equip.prototype.onItemOk = function() {
1512    SoundManager.playEquip();
1513    this.actor().changeEquip(this._slotWindow.index(), this._itemWindow.item());
1514    this._slotWindow.activate();
1515    this._slotWindow.refresh();
1516    this._itemWindow.deselect();
1517    this._itemWindow.refresh();
1518    this._statusWindow.refresh();
1519};
1520
1521Scene_Equip.prototype.onItemCancel = function() {
1522    this._slotWindow.activate();
1523    this._itemWindow.deselect();
1524};
1525
1526Scene_Equip.prototype.onActorChange = function() {
1527    this.refreshActor();
1528    this._commandWindow.activate();
1529};
1530
1531//-----------------------------------------------------------------------------
1532// Scene_Status
1533//
1534// The scene class of the status screen.
1535
1536function Scene_Status() {
1537    this.initialize.apply(this, arguments);
1538}
1539
1540Scene_Status.prototype = Object.create(Scene_MenuBase.prototype);
1541Scene_Status.prototype.constructor = Scene_Status;
1542
1543Scene_Status.prototype.initialize = function() {
1544    Scene_MenuBase.prototype.initialize.call(this);
1545};
1546
1547Scene_Status.prototype.create = function() {
1548    Scene_MenuBase.prototype.create.call(this);
1549    this._statusWindow = new Window_Status();
1550    this._statusWindow.setHandler('cancel',   this.popScene.bind(this));
1551    this._statusWindow.setHandler('pagedown', this.nextActor.bind(this));
1552    this._statusWindow.setHandler('pageup',   this.previousActor.bind(this));
1553    this._statusWindow.reserveFaceImages();
1554    this.addWindow(this._statusWindow);
1555};
1556
1557Scene_Status.prototype.start = function() {
1558    Scene_MenuBase.prototype.start.call(this);
1559    this.refreshActor();
1560};
1561
1562Scene_Status.prototype.refreshActor = function() {
1563    var actor = this.actor();
1564    this._statusWindow.setActor(actor);
1565};
1566
1567Scene_Status.prototype.onActorChange = function() {
1568    this.refreshActor();
1569    this._statusWindow.activate();
1570};
1571
1572//-----------------------------------------------------------------------------
1573// Scene_Options
1574//
1575// The scene class of the options screen.
1576
1577function Scene_Options() {
1578    this.initialize.apply(this, arguments);
1579}
1580
1581Scene_Options.prototype = Object.create(Scene_MenuBase.prototype);
1582Scene_Options.prototype.constructor = Scene_Options;
1583
1584Scene_Options.prototype.initialize = function() {
1585    Scene_MenuBase.prototype.initialize.call(this);
1586};
1587
1588Scene_Options.prototype.create = function() {
1589    Scene_MenuBase.prototype.create.call(this);
1590    this.createOptionsWindow();
1591};
1592
1593Scene_Options.prototype.terminate = function() {
1594    Scene_MenuBase.prototype.terminate.call(this);
1595    ConfigManager.save();
1596};
1597
1598Scene_Options.prototype.createOptionsWindow = function() {
1599    this._optionsWindow = new Window_Options();
1600    this._optionsWindow.setHandler('cancel', this.popScene.bind(this));
1601    this.addWindow(this._optionsWindow);
1602};
1603
1604//-----------------------------------------------------------------------------
1605// Scene_File
1606//
1607// The superclass of Scene_Save and Scene_Load.
1608
1609function Scene_File() {
1610    this.initialize.apply(this, arguments);
1611}
1612
1613Scene_File.prototype = Object.create(Scene_MenuBase.prototype);
1614Scene_File.prototype.constructor = Scene_File;
1615
1616Scene_File.prototype.initialize = function() {
1617    Scene_MenuBase.prototype.initialize.call(this);
1618};
1619
1620Scene_File.prototype.create = function() {
1621    Scene_MenuBase.prototype.create.call(this);
1622    DataManager.loadAllSavefileImages();
1623    this.createHelpWindow();
1624    this.createListWindow();
1625};
1626
1627Scene_File.prototype.start = function() {
1628    Scene_MenuBase.prototype.start.call(this);
1629    this._listWindow.refresh();
1630};
1631
1632Scene_File.prototype.savefileId = function() {
1633    return this._listWindow.index() + 1;
1634};
1635
1636Scene_File.prototype.createHelpWindow = function() {
1637    this._helpWindow = new Window_Help(1);
1638    this._helpWindow.setText(this.helpWindowText());
1639    this.addWindow(this._helpWindow);
1640};
1641
1642Scene_File.prototype.createListWindow = function() {
1643    var x = 0;
1644    var y = this._helpWindow.height;
1645    var width = Graphics.boxWidth;
1646    var height = Graphics.boxHeight - y;
1647    this._listWindow = new Window_SavefileList(x, y, width, height);
1648    this._listWindow.setHandler('ok',     this.onSavefileOk.bind(this));
1649    this._listWindow.setHandler('cancel', this.popScene.bind(this));
1650    this._listWindow.select(this.firstSavefileIndex());
1651    this._listWindow.setTopRow(this.firstSavefileIndex() - 2);
1652    this._listWindow.setMode(this.mode());
1653    this._listWindow.refresh();
1654    this.addWindow(this._listWindow);
1655};
1656
1657Scene_File.prototype.mode = function() {
1658    return null;
1659};
1660
1661Scene_File.prototype.activateListWindow = function() {
1662    this._listWindow.activate();
1663};
1664
1665Scene_File.prototype.helpWindowText = function() {
1666    return '';
1667};
1668
1669Scene_File.prototype.firstSavefileIndex = function() {
1670    return 0;
1671};
1672
1673Scene_File.prototype.onSavefileOk = function() {
1674};
1675
1676//-----------------------------------------------------------------------------
1677// Scene_Save
1678//
1679// The scene class of the save screen.
1680
1681function Scene_Save() {
1682    this.initialize.apply(this, arguments);
1683}
1684
1685Scene_Save.prototype = Object.create(Scene_File.prototype);
1686Scene_Save.prototype.constructor = Scene_Save;
1687
1688Scene_Save.prototype.initialize = function() {
1689    Scene_File.prototype.initialize.call(this);
1690};
1691
1692Scene_Save.prototype.mode = function() {
1693    return 'save';
1694};
1695
1696Scene_Save.prototype.helpWindowText = function() {
1697    return TextManager.saveMessage;
1698};
1699
1700Scene_Save.prototype.firstSavefileIndex = function() {
1701    return DataManager.lastAccessedSavefileId() - 1;
1702};
1703
1704Scene_Save.prototype.onSavefileOk = function() {
1705    Scene_File.prototype.onSavefileOk.call(this);
1706    $gameSystem.onBeforeSave();
1707    if (DataManager.saveGame(this.savefileId())) {
1708        this.onSaveSuccess();
1709    } else {
1710        this.onSaveFailure();
1711    }
1712};
1713
1714Scene_Save.prototype.onSaveSuccess = function() {
1715    SoundManager.playSave();
1716	StorageManager.cleanBackup(this.savefileId());
1717    this.popScene();
1718};
1719
1720Scene_Save.prototype.onSaveFailure = function() {
1721    SoundManager.playBuzzer();
1722    this.activateListWindow();
1723};
1724
1725//-----------------------------------------------------------------------------
1726// Scene_Load
1727//
1728// The scene class of the load screen.
1729
1730function Scene_Load() {
1731    this.initialize.apply(this, arguments);
1732}
1733
1734Scene_Load.prototype = Object.create(Scene_File.proto
1734type);
1735Scene_Load.prototype.constructor = Scene_Load;
1736
1737Scene_Load.prototype.initialize = function() {
1738    Scene_File.prototype.initialize.call(this);
1739    this._loadSuccess = false;
1740};
1741
1742Scene_Load.prototype.terminate = function() {
1743    Scene_File.prototype.terminate.call(this);
1744    if (this._loadSuccess) {
1745        $gameSystem.onAfterLoad();
1746    }
1747};
1748
1749Scene_Load.prototype.mode = function() {
1750    return 'load';
1751};
1752
1753Scene_Load.prototype.helpWindowText = function() {
1754    return TextManager.loadMessage;
1755};
1756
1757Scene_Load.prototype.firstSavefileIndex = function() {
1758    return DataManager.latestSavefileId() - 1;
1759};
1760
1761Scene_Load.prototype.onSavefileOk = function() {
1762    Scene_File.prototype.onSavefileOk.call(this);
1763    if (DataManager.loadGame(this.savefileId())) {
1764        this.onLoadSuccess();
1765    } else {
1766        this.onLoadFailure();
1767    }
1768};
1769
1770Scene_Load.prototype.onLoadSuccess = function() {
1771    SoundManager.playLoad();
1772    this.fadeOutAll();
1773    this.reloadMapIfUpdated();
1774    SceneManager.goto(Scene_Map);
1775    this._loadSuccess = true;
1776};
1777
1778Scene_Load.prototype.onLoadFailure = function() {
1779    SoundManager.playBuzzer();
1780    this.activateListWindow();
1781};
1782
1783Scene_Load.prototype.reloadMapIfUpdated = function() {
1784    if ($gameSystem.versionId() !== $dataSystem.versionId) {
1785        $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
1786        $gamePlayer.requestMapReload();
1787    }
1788};
1789
1790//-----------------------------------------------------------------------------
1791// Scene_GameEnd
1792//
1793// The scene class of the game end screen.
1794
1795function Scene_GameEnd() {
1796    this.initialize.apply(this, arguments);
1797}
1798
1799Scene_GameEnd.prototype = Object.create(Scene_MenuBase.prototype);
1800Scene_GameEnd.prototype.constructor = Scene_GameEnd;
1801
1802Scene_GameEnd.prototype.initialize = function() {
1803    Scene_MenuBase.prototype.initialize.call(this);
1804};
1805
1806Scene_GameEnd.prototype.create = function() {
1807    Scene_MenuBase.prototype.create.call(this);
1808    this.createCommandWindow();
1809};
1810
1811Scene_GameEnd.prototype.stop = function() {
1812    Scene_MenuBase.prototype.stop.call(this);
1813    this._commandWindow.close();
1814};
1815
1816Scene_GameEnd.prototype.createBackground = function() {
1817    Scene_MenuBase.prototype.createBackground.call(this);
1818    this.setBackgroundOpacity(128);
1819};
1820
1821Scene_GameEnd.prototype.createCommandWindow = function() {
1822    this._commandWindow = new Window_GameEnd();
1823    this._commandWindow.setHandler('toTitle',  this.commandToTitle.bind(this));
1824    this._commandWindow.setHandler('cancel',   this.popScene.bind(this));
1825    this.addWindow(this._commandWindow);
1826};
1827
1828Scene_GameEnd.prototype.commandToTitle = function() {
1829    this.fadeOutAll();
1830    SceneManager.goto(Scene_Title);
1831};
1832
1833//-----------------------------------------------------------------------------
1834// Scene_Shop
1835//
1836// The scene class of the shop screen.
1837
1838function Scene_Shop() {
1839    this.initialize.apply(this, arguments);
1840}
1841
1842Scene_Shop.prototype = Object.create(Scene_MenuBase.prototype);
1843Scene_Shop.prototype.constructor = Scene_Shop;
1844
1845Scene_Shop.prototype.initialize = function() {
1846    Scene_MenuBase.prototype.initialize.call(this);
1847};
1848
1849Scene_Shop.prototype.prepare = function(goods, purchaseOnly) {
1850    this._goods = goods;
1851    this._purchaseOnly = purchaseOnly;
1852    this._item = null;
1853};
1854
1855Scene_Shop.prototype.create = function() {
1856    Scene_MenuBase.prototype.create.call(this);
1857    this.createHelpWindow();
1858    this.createGoldWindow();
1859    this.createCommandWindow();
1860    this.createDummyWindow();
1861    this.createNumberWindow();
1862    this.createStatusWindow();
1863    this.createBuyWindow();
1864    this.createCategoryWindow();
1865    this.createSellWindow();
1866};
1867
1868Scene_Shop.prototype.createGoldWindow = function() {
1869    this._goldWindow = new Window_Gold(0, this._helpWindow.height);
1870    this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;
1871    this.addWindow(this._goldWindow);
1872};
1873
1874Scene_Shop.prototype.createCommandWindow = function() {
1875    this._commandWindow = new Window_ShopCommand(this._goldWindow.x, this._purchaseOnly);
1876    this._commandWindow.y = this._helpWindow.height;
1877    this._commandWindow.setHandler('buy',    this.commandBuy.bind(this));
1878    this._commandWindow.setHandler('sell',   this.commandSell.bind(this));
1879    this._commandWindow.setHandler('cancel', this.popScene.bind(this));
1880    this.addWindow(this._commandWindow);
1881};
1882
1883Scene_Shop.prototype.createDummyWindow = function() {
1884    var wy = this._commandWindow.y + this._commandWindow.height;
1885    var wh = Graphics.boxHeight - wy;
1886    this._dummyWindow = new Window_Base(0, wy, Graphics.boxWidth, wh);
1887    this.addWindow(this._dummyWindow);
1888};
1889
1890Scene_Shop.prototype.createNumberWindow = function() {
1891    var wy = this._dummyWindow.y;
1892    var wh = this._dummyWindow.height;
1893    this._numberWindow = new Window_ShopNumber(0, wy, wh);
1894    this._numberWindow.hide();
1895    this._numberWindow.setHandler('ok',     this.onNumberOk.bind(this));
1896    this._numberWindow.setHandler('cancel', this.onNumberCancel.bind(this));
1897    this.addWindow(this._numberWindow);
1898};
1899
1900Scene_Shop.prototype.createStatusWindow = function() {
1901    var wx = this._numberWindow.width;
1902    var wy = this._dummyWindow.y;
1903    var ww = Graphics.boxWidth - wx;
1904    var wh = this._dummyWindow.height;
1905    this._statusWindow = new Window_ShopStatus(wx, wy, ww, wh);
1906    this._statusWindow.hide();
1907    this.addWindow(this._statusWindow);
1908};
1909
1910Scene_Shop.prototype.createBuyWindow = function() {
1911    var wy = this._dummyWindow.y;
1912    var wh = this._dummyWindow.height;
1913    this._buyWindow = new Window_ShopBuy(0, wy, wh, this._goods);
1914    this._buyWindow.setHelpWindow(this._helpWindow);
1915    this._buyWindow.setStatusWindow(this._statusWindow);
1916    this._buyWindow.hide();
1917    this._buyWindow.setHandler('ok',     this.onBuyOk.bind(this));
1918    this._buyWindow.setHandler('cancel', this.onBuyCancel.bind(this));
1919    this.addWindow(this._buyWindow);
1920};
1921
1922Scene_Shop.prototype.createCategoryWindow = function() {
1923    this._categoryWindow = new Window_ItemCategory();
1924    this._categoryWindow.setHelpWindow(this._helpWindow);
1925    this._categoryWindow.y = this._dummyWindow.y;
1926    this._categoryWindow.hide();
1927    this._categoryWindow.deactivate();
1928    this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
1929    this._categoryWindow.setHandler('cancel', this.onCategoryCancel.bind(this));
1930    this.addWindow(this._categoryWindow);
1931};
1932
1933Scene_Shop.prototype.createSellWindow = function() {
1934    var wy = this._categoryWindow.y + this._categoryWindow.height;
1935    var wh = Graphics.boxHeight - wy;
1936    this._sellWindow = new Window_ShopSell(0, wy, Graphics.boxWidth, wh);
1937    this._sellWindow.setHelpWindow(this._helpWindow);
1938    this._sellWindow.hide();
1939    this._sellWindow.setHandler('ok',     this.onSellOk.bind(this));
1940    this._sellWindow.setHandler('cancel', this.onSellCancel.bind(this));
1941    this._categoryWindow.setItemWindow(this._sellWindow);
1942    this.addWindow(this._sellWindow);
1943};
1944
1945Scene_Shop.prototype.activateBuyWindow = function() {
1946    this._buyWindow.setMoney(this.money());
1947    this._buyWindow.show();
1948    this._buyWindow.activate();
1949    this._statusWindow.show();
1950};
1951
1952Scene_Shop.prototype.activateSellWindow = function() {
1953    this._categoryWindow.show();
1954    this._sellWindow.refresh();
1955    this._sellWindow.show();
1956    this._sellWindow.activate();
1957    this._statusWindow.hide();
1958};
1959
1960Scene_Shop.prototype.commandBuy = function() {
1961    this._dummyWindow.hide();
1962    this.activateBuyWindow();
1963};
1964
1965Scene_Shop.prototype.commandSell = function() {
1966    this._dummyWindow.hide();
1967    this._categoryWindow.show();
1968    this._categoryWindow.activate();
1969    this._sellWindow.show();
1970    this._sellWindow.deselect();
1971    this._sellWindow.refresh();
1972};
1973
1974Scene_Shop.prototype.onBuyOk = function() {
1975    this._item = this._buyWindow.item();
1976    this._buyWindow.hide();
1977    this._numberWindow.setup(this._item, this.maxBuy(), this.buyingPrice());
1978    this._numberWindow.setCurrencyUnit(this.currencyUnit());
1979    this._numberWindow.show();
1980    this._numberWindow.activate();
1981};
1982
1983Scene_Shop.prototype.onBuyCancel = function() {
1984    this._commandWindow.activate();
1985    this._dummyWindow.show();
1986    this._buyWindow.hide();
1987    this._statusWindow.hide();
1988    this._statusWindow.setItem(null);
1989    this._helpWindow.clear();
1990};
1991
1992Scene_Shop.prototype.onCategoryOk = function() {
1993    this.activateSellWindow();
1994    this._sellWindow.select(0);
1995};
1996
1997Scene_Shop.prototype.onCategoryCancel = function() {
1998    this._commandWindow.activate();
1999    this._dummyWindow.show();
2000    this._categoryWindow.hide();
2001    this._sellWindow.hide();
2002};
2003
2004Scene_Shop.prototype.onSellOk = function() {
2005    this._item = this._sellWindow.item();
2006    this._categoryWindow.hide();
2007    this._sellWindow.hide();
2008    this._numberWindow.setup(this._item, this.maxSell(), this.sellingPrice());
2009    this._numberWindow.setCurrencyUnit(this.currencyUnit());
2010    this._numberWindow.show();
2011    this._numberWindow.activate();
2012    this._statusWindow.setItem(this._item);
2013    this._statusWindow.show();
2014};
2015
2016Scene_Shop.prototype.onSellCancel = function() {
2017    this._sellWindow.deselect();
2018    this._categoryWindow.activate();
2019    this._statusWindow.setItem(null);
2020    this._helpWindow.clear();
2021};
2022
2023Scene_Shop.prototype.onNumberOk = function() {
2024    SoundManager.playShop();
2025    switch (this._commandWindow.currentSymbol()) {
2026    case 'buy':
2027        this.doBuy(this._numberWindow.number());
2028        break;
2029    case 'sell':
2030        this.doSell(this._numberWindow.number());
2031        break;
2032    }
2033    this.endNumberInput();
2034    this._goldWindow.refresh();
2035    this._statusWindow.refresh();
2036};
2037
2038Scene_Shop.prototype.onNumberCancel = function() {
2039    SoundManager.playCancel();
2040    this.endNumberInput();
2041};
2042
2043Scene_Shop.prototype.doBuy = function(number) {
2044    $gameParty.loseGold(number * this.buyingPrice());
2045    $gameParty.gainItem(this._item, number);
2046};
2047
2048Scene_Shop.prototype.doSell = function(number) {
2049    $gameParty.gainGold(number * this.sellingPrice());
2050    $gameParty.loseItem(this._item, number);
2051};
2052
2053Scene_Shop.prototype.endNumberInput = function() {
2054    this._numberWindow.hide();
2055    switch (this._commandWindow.currentSymbol()) {
2056    case 'buy':
2057        this.activateBuyWindow();
2058        break;
2059    case 'sell':
2060        this.activateSellWindow();
2061        break;
2062    }
2063};
2064
2065Scene_Shop.prototype.maxBuy = function() {
2066    var max = $gameParty.maxItems(this._item) - $gameParty.numItems(this._item);
2067    var price = this.buyingPrice();
2068    if (price > 0) {
2069        return Math.min(max, Math.floor(this.money() / price));
2070    } else {
2071        return max;
2072    }
2073};
2074
2075Scene_Shop.prototype.maxSell = function() {
2076    return $gameParty.numItems(this._item);
2077};
2078
2079Scene_Shop.prototype.money = function() {
2080    return this._goldWindow.value();
2081};
2082
2083Scene_Shop.prototype.currencyUnit = function() {
2084    return this._goldWindow.currencyUnit();
2085};
2086
2087Scene_Shop.prototype.buyingPrice = function() {
2088    return this._buyWindow.price(this._item);
2089};
2090
2091Scene_Shop.prototype.sellingPrice = function() {
2092    return Math.floor(this._item.price / 2);
2093};
2094
2095//-----------------------------------------------------------------------------
2096// Scene_Name
2097//
2098// The scene class of the name input screen.
2099
2100function Scene_Name() {
2101    this.initialize.apply(this, arguments);
2102}
2103
2104Scene_Name.prototype = Object.create(Scene_MenuBase.prototype);
2105Scene_Name.prototype.constructor = Scene_Name;
2106
2107Scene_Name.prototype.initialize = function() {
2108    Scene_MenuBase.prototype.initialize.call(this);
2109};
2110
2111Scene_Name.prototype.prepare = function(actorId, maxLength) {
2112    this._actorId = actorId;
2113    this._maxLength = maxLength;
2114};
2115
2116Scene_Name.prototype.create = function() {
2117    Scene_MenuBase.prototype.create.call(this);
2118    this._actor = $gameActors.actor(this._actorId);
2119    this.createEditWindow();
2120    this.createInputWindow();
2121};
2122
2123Scene_Name.prototype.start = function() {
2124    Scene_MenuBase.prototype.start.call(this);
2125    this._editWindow.refresh();
2126};
2127
2128Scene_Name.prototype.createEditWindow = function() {
2129    this._editWindow = new Window_NameEdit(this._actor, this._maxLength);
2130    this.addWindow(this._editWindow);
2131};
2132
2133Scene_Name.prototype.createInputWindow = function() {
2134    this._inputWindow = new Window_NameInput(this._editWindow);
2135    this._inputWindow.setHandler('ok', this.onInputOk.bind(this));
2136    this.addWindow(this._inputWindow);
2137};
2138
2139Scene_Name.prototype.onInputOk = function() {
2140    this._actor.setName(this._editWindow.name());
2141    this.popScene();
2142};
2143
2144//-----------------------------------------------------------------------------
2145// Scene_Debug
2146//
2147// The scene class of the debug screen.
2148
2149function Scene_Debug() {
2150    this.initialize.apply(this, arguments);
2151}
2152
2153Scene_Debug.prototype = Object.create(Scene_MenuBase.prototype);
2154Scene_Debug.prototype.constructor = Scene_Debug;
2155
2156Scene_Debug.prototype.initialize = function() {
2157    Scene_MenuBase.prototype.initialize.call(this);
2158};
2159
2160Scene_Debug.prototype.create = function() {
2161    Scene_MenuBase.prototype.create.call(this);
2162    this.createRangeWindow();
2163    this.createEditWindow();
2164    this.createDebugHelpWindow();
2165};
2166
2167Scene_Debug.prototype.createRangeWindow = function() {
2168    this._rangeWindow = new Window_DebugRange(0, 0);
2169    this._rangeWindow.setHandler('ok',     this.onRangeOk.bind(this));
2170    this._rangeWindow.setHandler('cancel', this.popScene.bind(this));
2171    this.addWindow(this._rangeWindow);
2172};
2173
2174Scene_Debug.prototype.createEditWindow = function() {
2175    var wx = this._rangeWindow.width;
2176    var ww = Graphics.boxWidth - wx;
2177    this._editWindow = new Window_DebugEdit(wx, 0, ww);
2178    this._editWindow.setHandler('cancel', this.onEditCancel.bind(this));
2179    this._rangeWindow.setEditWindow(this._editWindow);
2180    this.addWindow(this._editWindow);
2181};
2182
2183Scene_Debug.prototype.createDebugHelpWindow = function() {
2184    var wx = this._editWindow.x;
2185    var wy = this._editWindow.height;
2186    var ww = this._editWindow.width;
2187    var wh = Graphics.boxHeight - wy;
2188    this._debugHelpWindow = new Window_Base(wx, wy, ww, wh);
2189    this.addWindow(this._debugHelpWindow);
2190};
2191
2192Scene_Debug.prototype.onRangeOk = function() {
2193    this._editWindow.activate();
2194    this._editWindow.select(0);
2195    this.refreshHelpWindow();
2196};
2197
2198Scene_Debug.prototype.onEditCancel = function() {
2199    this._rangeWindow.activate();
2200    this._editWindow.deselect();
2201    this.refreshHelpWindow();
2202};
2203
2204Scene_Debug.prototype.refreshHelpWindow = function() {
2205    this._debugHelpWindow.contents.clear();
2206    if (this._editWindow.active) {
2207        this._debugHelpWindow.drawTextEx(this.helpText(), 4, 0);
2208    }
2209};
2210
2211Scene_Debug.prototype.helpText = function() {
2212    if (this._rangeWindow.mode() === 'switch') {
2213        return 'Enter : ON / OFF';
2214    } else {
2215        return ('Left     :  -1\n' +
2216                'Right    :  +1\n' +
2217                'Pageup   : -10\n' +
2218                'Pagedown : +10');
2219    }
2220};
2221
2222//-----------------------------------------------------------------------------
2223// Scene_Battle
2224//
2225// The scene class of the battle screen.
2226
2227function Scene_Battle() {
2228    this.initialize.apply(this, arguments);
2229}
2230
2231Scene_Battle.prototype = Object.create(Scene_Base.prototype);
2232Scene_Battle.prototype.constructor = Scene_Battle;
2233
2234Scene_Battle.prototype.initialize = function() {
2235    Scene_Base.prototype.initialize.call(this);
2236};
2237
2238Scene_Battle.prototype.create = function() {
2239    Scene_Base.prototype.create.call(this);
2240    this.createDisplayObjects();
2241};
2242
2243Scene_Battle.prototype.start = function() {
2244    Scene_Base.prototype.start.call(this);
2245    this.startFadeIn(this.fadeSpeed(), false);
2246    BattleManager.playBattleBgm();
2247    BattleManager.startBattle();
2248};
2249
2250Scene_Battle.prototype.update = function() {
2251    var active = this.isActive();
2252    $gameTimer.update(active);
2253    $gameScreen.update();
2254    this.updateStatusWindow();
2255    this.updateWindowPositions();
2256    if (active && !this.isBusy()) {
2257        this.updateBattleProcess();
2258    }
2259    Scene_Base.prototype.update.call(this);
2260};
2261
2262Scene_Battle.prototype.updateBattleProcess = function() {
2263    if (!this.isAnyInputWindowActive() || BattleManager.isAborting() ||
2264            BattleManager.isBattleEnd()) {
2265        BattleManager.update();
2266        this.changeInputWindow();
2267    }
2268};
2269
2270Scene_Battle.prototype.isAnyInputWindowActive = function() {
2271    return (this._partyCommandWindow.active ||
2272            this._actorCommandWindow.active ||
2273            this._skillWindow.active ||
2274            this._itemWindow.active ||
2275            this._actorWindow.active ||
2276            this._enemyWindow.active);
2277};
2278
2279Scene_Battle.prototype.changeInputWindow = function() {
2280    if (BattleManager.isInputting()) {
2281        if (BattleManager.actor()) {
2282            this.startActorCommandSelection();
2283        } else {
2284            this.startPartyCommandSelection();
2285        }
2286    } else {
2287        this.endCommandSelection();
2288    }
2289};
2290
2291Scene_Battle.prototype.stop = function() {
2292    Scene_Base.prototype.stop.call(this);
2293    if (this.needsSlowFadeOut()) {
2294        this.startFadeOut(this.slowFadeSpeed(), false);
2295    } else {
2296        this.startFadeOut(this.fadeSpeed(), false);
2297    }
2298    this._statusWindow.close();
2299    this._partyCommandWindow.close();
2300    this._actorCommandWindow.close();
2301};
2302
2303Scene_Battle.prototype.terminate = function() {
2304    Scene_Base.prototype.terminate.call(this);
2305    $gameParty.onBattleEnd();
2306    $gameTroop.onBattleEnd();
2307    AudioManager.stopMe();
2308
2309    ImageManager.clearRequest();
2310};
2311
2312Scene_Battle.prototype.needsSlowFadeOut = function() {
2313    return (SceneManager.isNextScene(Scene_Title) ||
2314            SceneManager.isNextScene(Scene_Gameover));
2315};
2316
2317Scene_Battle.prototype.updateStatusWindow = function() {
2318    if ($gameMessage.isBusy()) {
2319        this._statusWindow.close();
2320        this._partyCommandWindow.close();
2321        this._actorCommandWindow.close();
2322    } else if (this.isActive() && !this._messageWindow.isClosing()) {
2323        this._statusWindow.open();
2324    }
2325};
2326
2327Scene_Battle.prototype.updateWindowPositions = function() {
2328    var statusX = 0;
2329    if (BattleManager.isInputting()) {
2330        statusX = this._partyCommandWindow.width;
2331    } else {
2332        statusX = this._partyCommandWindow.width / 2;
2333    }
2334    if (this._statusWindow.x < statusX) {
2335        this._statusWindow.x += 16;
2336        if (this._statusWindow.x > statusX) {
2337            this._statusWindow.x = statusX;
2338        }
2339    }
2340    if (this._statusWindow.x > statusX) {
2341        this._statusWindow.x -= 16;
2342        if (this._statusWindow.x < statusX) {
2343            this._statusWindow.x = statusX;
2344        }
2345    }
2346};
2347
2348Scene_Battle.prototype.createDisplayObjects = function() {
2349    this.createSpriteset();
2350    this.createWindowLayer();
2351    this.createAllWindows();
2352    BattleManager.setLogWindow(this._logWindow);
2353    BattleManager.setStatusWindow(this._statusWindow);
2354    BattleManager.setSpriteset(this._spriteset);
2355    this._logWindow.setSpriteset(this._spriteset);
2356};
2357
2358Scene_Battle.prototype.createSpriteset = function() {
2359    this._spriteset = new Spriteset_Battle();
2360    this.addChild(this._spriteset);
2361};
2362
2363Scene_Battle.prototype.createAllWindows = function() {
2364    this.createLogWindow();
2365    this.createStatusWindow();
2366    this.createPartyCommandWindow();
2367    this.createActorCommandWindow();
2368    this.createHelpWindow();
2369    this.createSkillWindow();
2370    this.createItemWindow();
2371    this.createActorWindow();
2372    this.createEnemyWindow();
2373    this.createMessageWindow();
2374    this.createScrollTextWindow();
2375};
2376
2377Scene_Battle.prototype.createLogWindow = function() {
2378    this._logWindow = new Window_BattleLog();
2379    this.addWindow(this._logWindow);
2380};
2381
2382Scene_Battle.prototype.createStatusWindow = function() {
2383    this._statusWindow = new Window_BattleStatus();
2384    this.addWindow(this._statusWindow);
2385};
2386
2387Scene_Battle.prototype.createPartyCommandWindow = function() {
2388    this._partyCommandWindow = new Window_PartyCommand();
2389    this._partyCommandWindow.setHandler('fight',  this.commandFight.bind(this));
2390    this._partyCommandWindow.setHandler('escape', this.commandEscape.bind(this));
2391    this._partyCommandWindow.deselect();
2392    this.addWindow(this._partyCommandWindow);
2393};
2394
2395Scene_Battle.prototype.createActorCommandWindow = function() {
2396    this._actorCommandWindow = new Window_ActorCommand();
2397    this._actorCommandWindow.setHandler('attack', this.commandAttack.bind(this));
2398    this._actorCommandWindow.setHandler('skill',  this.commandSkill.bind(this));
2399    this._actorCommandWindow.setHandler('guard',  this.commandGuard.bind(this));
2400    this._actorCommandWindow.setHandler('item',   this.commandItem.bind(this));
2401    this._actorCommandWindow.setHandler('cancel', this.selectPreviousCommand.bind(this));
2402    this.addWindow(this._actorCommandWindow);
2403};
2404
2405Scene_Battle.prototype.createHelpWindow = function() {
2406    this._helpWindow = new Window_Help();
2407    this._helpWindow.visible = false;
2408    this.addWindow(this._helpWindow);
2409};
2410
2411Scene_Battle.prototype.createSkillWindow = function() {
2412    var wy = this._helpWindow.y + this._helpWindow.height;
2413    var wh = this._statusWindow.y - wy;
2414    this._skillWindow = new Window_BattleSkill(0, wy, Graphics.boxWidth, wh);
2415    this._skillWindow.setHelpWindow(this._helpWindow);
2416    this._skillWindow.setHandler('ok',     this.onSkillOk.bind(this));
2417    this._skillWindow.setHandler('cancel', this.onSkillCancel.bind(this));
2418    this.addWindow(this._skillWindow);
2419};
2420
2421Scene_Battle.prototype.createItemWindow = function() {
2422    var wy = this._helpWindow.y + this._helpWindow.height;
2423    var wh = this._statusWindow.y - wy;
2424    this._itemWindow = new Window_BattleItem(0, wy, Graphics.boxWidth, wh);
2425    this._itemWindow.setHelpWindow(this._helpWindow);
2426    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
2427    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
2428    this.addWindow(this._itemWindow);
2429};
2430
2431Scene_Battle.prototype.createActorWindow = function() {
2432    this._actorWindow = new Window_BattleActor(0, this._statusWindow.y);
2433    this._actorWindow.setHandler('ok',     this.onActorOk.bind(this));
2434    this._actorWindow.setHandler('cancel', this.onActorCancel.bind(this));
2435    this.addWindow(this._actorWindow);
2436};
2437
2438Scene_Battle.prototype.createEnemyWindow = function() {
2439    this._enemyWindow = new Window_BattleEnemy(0, this._statusWindow.y);
2440    this._enemyWindow.x = Graphics.boxWidth - this._enemyWindow.width;
2441    this._enemyWindow.setHandler('ok',     this.onEnemyOk.bind(this));
2442    this._enemyWindow.setHandler('cancel', this.onEnemyCancel.bind(this));
2443    this.addWindow(this._enemyWindow);
2444};
2445
2446Scene_Battle.prototype.createMessageWindow = function() {
2447    this._messageWindow = new Window_Message();
2448    this.addWindow(this._messageWindow);
2449    this._messageWindow.subWindows().forEach(function(window) {
2450        this.addWindow(window);
2451    }, this);
2452};
2453
2454Scene_Battle.prototype.createScrollTextWindow = function() {
2455    this._scrollTextWindow = new Window_ScrollText();
2456    this.addWindow(this._scrollTextWindow);
2457};
2458
2459Scene_Battle.prototype.refreshStatus = function() {
2460    this._statusWindow.refresh();
2461};
2462
2463Scene_Battle.prototype.startPartyCommandSelection = function() {
2464    this.refreshStatus();
2465    this._statusWindow.deselect();
2466    this._statusWindow.open();
2467    this._actorCommandWindow.close();
2468    this._partyCommandWindow.setup();
2469};
2470
2471Scene_Battle.prototype.commandFight = function() {
2472    this.selectNextCommand();
2473};
2474
2475Scene_Battle.prototype.commandEscape = function() {
2476    BattleManager.processEscape();
2477    this.changeInputWindow();
2478};
2479
2480Scene_Battle.prototype.startActorCommandSelection = function() {
2481    this._statusWindow.select(BattleManager.actor().index());
2482    this._partyCommandWindow.close();
2483    this._actorCommandWindow.setup(BattleManager.actor());
2484};
2485
2486Scene_Battle.prototype.commandAttack = function() {
2487    BattleManager.inputtingAction().setAttack();
2488    this.selectEnemySelection();
2489};
2490
2491Scene_Battle.prototype.commandSkill = function() {
2492    this._skillWindow.setActor(BattleManager.actor());
2493    this._skillWindow.setStypeId(this._actorCommandWindow.currentExt());
2494    this._skillWindow.refresh();
2495    this._skillWindow.show();
2496    this._skillWindow.activate();
2497};
2498
2499Scene_Battle.prototype.commandGuard = function() {
2500    BattleManager.inputtingAction().setGuard();
2501    this.selectNextCommand();
2502};
2503
2504Scene_Battle.prototype.commandItem = function() {
2505    this._itemWindow.refresh();
2506    this._itemWindow.show();
2507    this._itemWindow.activate();
2508};
2509
2510Scene_Battle.prototype.selectNextCommand = function() {
2511    BattleManager.selectNextCommand();
2512    this.changeInputWindow();
2513};
2514
2515Scene_Battle.prototype.selectPreviousCommand = function() {
2516    BattleManager.selectPreviousCommand();
2517    this.changeInputWindow();
2518};
2519
2520Scene_Battle.prototype.selectActorSelection = function() {
2521    this._actorWindow.refresh();
2522    this._actorWindow.show();
2523    this._actorWindow.activate();
2524};
2525
2526Scene_Battle.prototype.onActorOk = function() {
2527    var action = BattleManager.inputtingAction();
2528    action.setTarget(this._actorWindow.index());
2529    this._actorWindow.hide();
2530    this._skillWindow.hide();
2531    this._itemWindow.hide();
2532    this.selectNextCommand();
2533};
2534
2535Scene_Battle.prototype.onActorCancel = function() {
2536    this._actorWindow.hide();
2537    switch (this._actorCommandWindow.currentSymbol()) {
2538    case 'skill':
2539        this._skillWindow.show();
2540        this._skillWindow.activate();
2541        break;
2542    case 'item':
2543        this._itemWindow.show();
2544        this._itemWindow.activate();
2545        break;
2546    }
2547};
2548
2549Scene_Battle.prototype.selectEnemySelection = function() {
2550    this._enemyWindow.refresh();
2551    this._enemyWindow.show();
2552    this._enemyWindow.select(0);
2553    this._enemyWindow.activate();
2554};
2555
2556Scene_Battle.prototype.onEnemyOk = function() {
2557    var action = BattleManager.inputtingAction();
2558    action.setTarget(this._enemyWindow.enemyIndex());
2559    this._enemyWindow.hide();
2560    this._skillWindow.hide();
2561    this._itemWindow.hide();
2562    this.selectNextCommand();
2563};
2564
2565Scene_Battle.prototype.onEnemyCancel = function() {
2566    this._enemyWindow.hide();
2567    switch (this._actorCommandWindow.currentSymbol()) {
2568    case 'attack':
2569        this._actorCommandWindow.activate();
2570        break;
2571    case 'skill':
2572        this._skillWindow.show();
2573        this._skillWindow.activate();
2574        break;
2575    case 'item':
2576        this._itemWindow.show();
2577        this._itemWindow.activate();
2578        break;
2579    }
2580};
2581
2582Scene_Battle.prototype.onSkillOk = function() {
2583    var skill = this._skillWindow.item();
2584    var action = BattleManager.inputtingAction();
2585    action.setSkill(skill.id);
2586    BattleManager.actor().setLastBattleSkill(skill);
2587    this.onSelectAction();
2588};
2589
2590Scene_Battle.prototype.onSkillCancel = function() {
2591    this._skillWindow.hide();
2592    this._actorCommandWindow.activate();
2593};
2594
2595Scene_Battle.prototype.onItemOk = function() {
2596    var item = this._itemWindow.item();
2597    var action = BattleManager.inputtingAction();
2598    action.setItem(item.id);
2599    $gameParty.setLastItem(item);
2600    this.onSelectAction();
2601};
2602
2603Scene_Battle.prototype.onItemCancel = function() {
2604    this._itemWindow.hide();
2605    this._actorCommandWindow.activate();
2606};
2607
2608Scene_Battle.prototype.onSelectAction = function() {
2609    var action = BattleManager.inputtingAction();
2610    this._skillWindow.hide();
2611    this._itemWindow.hide();
2612    if (!action.needsSelection()) {
2613        this.selectNextCommand();
2614    } else if (action.isForOpponent()) {
2615        this.selectEnemySelection();
2616    } else {
2617        this.selectActorSelection();
2618    }
2619};
2620
2621Scene_Battle.prototype.endCommandSelection = function() {
2622    this._partyCommandWindow.close();
2623    this._actorCommandWindow.close();
2624    this._statusWindow.deselect();
2625};
2626
2627//-----------------------------------------------------------------------------
2628// Scene_Gameover
2629//
2630// The scene class of the game over screen.
2631
2632function Scene_Gameover() {
2633    this.initialize.apply(this, arguments);
2634}
2635
2636Scene_Gameover.prototype = Object.create(Scene_Base.prototype);
2637Scene_Gameover.prototype.constructor = Scene_Gameover;
2638
2639Scene_Gameover.prototype.initialize = function() {
2640    Scene_Base.prototype.initialize.call(this);
2641};
2642
2643Scene_Gameover.prototype.create = function() {
2644    Scene_Base.prototype.create.call(this);
2645    this.playGameoverMusic();
2646    this.createBackground();
2647};
2648
2649Scene_Gameover.prototype.start = function() {
2650    Scene_Base.prototype.start.call(this);
2651    this.startFadeIn(this.slowFadeSpeed(), false);
2652};
2653
2654Scene_Gameover.prototype.update = function() {
2655    if (this.isActive() && !this.isBusy() && this.isTriggered()) {
2656        this.gotoTitle();
2657    }
2658    Scene_Base.prototype.update.call(this);
2659};
2660
2661Scene_Gameover.prototype.stop = function() {
2662    Scene_Base.prototype.stop.call(this);
2663    this.fadeOutAll();
2664};
2665
2666Scene_Gameover.prototype.terminate = function() {
2667    Scene_Base.prototype.terminate.call(this);
2668    AudioManager.stopAll();
2669};
2670
2671Scene_Gameover.prototype.playGameoverMusic = function() {
2672    AudioManager.stopBgm();
2673    AudioManager.stopBgs();
2674    AudioManager.playMe($dataSystem.gameoverMe);
2675};
2676
2677Scene_Gameover.prototype.createBackground = function() {
2678    this._backSprite = new Sprite();
2679    this._backSprite.bitmap = ImageManager.loadSystem('GameOver');
2680    this.addChild(this._backSprite);
2681};
2682
2683Scene_Gameover.prototype.isTriggered = function() {
2684    return Input.isTriggered('ok') || TouchInput.isTriggered();
2685};
2686
2687Scene_Gameover.prototype.gotoTitle = function() {
2688    SceneManager.goto(Scene_Title);
2689};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.