New account registration is temporarily disabled.

[RMMV] ADDING A CHOICE WINDOW

Posts

Pages: 1
Hi,

This is an extension of my previous script, which works on fusing two party members. At the moment, the calculation processes are done... the only thing left is the windows, which I'm having trouble with. I need help with the following:

• Preventing input from invalid entries (not proceeding to the status screen for invalid entries)
• Displaying a choice for the user to select whether to proceed to fusion or not

Here's my code for reference... thanks!


//=============================================================================
//
// EdoTenseiFusion_Final.js
// [url]https://kinoar.github.io/rmmv-doc-web/index.html[/url]
//=============================================================================



/*:
 * @plugindesc Starts the fusion process, just like in SMT
 * @author Sai Hikawa
 *
 * @param none
 * @desc none
 * @default false
 *
 * @help
 *
 * Plugin Command:
 *
 * fusion - initiates the fusion thinggy
 *
 */


 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 // Global Variables
 // Fusion result array and selected demons
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

 var resultArray = [32];
	// 2 - Avatar
	resultArray[0] = [0,20,29,23,0,25,23,0,16,7,7,23,0,0,20,23,0,6,25,31,23,20,16,6,2,20,33,24,0,6,6,0,7];
	// 3 - Avian
	resultArray[1] = [20,0,13,23,25,29,16,0,0,27,29,5,0,0,23,25,0,25,24,0,23,24,0,6,3,13,25,23,0,0,23,0,27];
	// 4 - Beast
	resultArray[2] = [29,13,9,13,2,20,29,4,20,7,27,15,27,33,2,11,33,0,2,3,34,20,29,0,4,11,33,5,27,15,20,22,12];
	// 5 - Brute
	resultArray[3] = [23,23,13,9,23,34,27,5,16,27,0,4,18,33,0,7,15,0,3,23,0,0,0,0,5,23,16,0,18,18,0,11,13];
	// 6 - Deity
	resultArray[4] = [0,25,2,23,0,25,0,6,25,27,16,24,0,8,0,25,0,10,25,12,5,16,0,0,6,31,30,23,0,0,23,3,25];
	// 7 - Divine
	resultArray[5] = [25,29,20,34,25,9,25,7,25,0,31,4,31,11,0,25,22,25,0,0,27,0,0,0,7,29,15,11,31,12,20,12,29];
	// 8 - Dragon
	resultArray[6] = [23,16,29,27,0,25,0,0,24,29,29,27,0,29,0,20,0,20,30,29,23,16,28,0,8,13,0,24,0,29,24,3,2];
	// 9 - Element
	resultArray[7] = [0,0,4,5,6,7,0,26,0,11,12,13,0,15,16,0,18,0,20,0,22,23,24,25,9,27,0,29,30,31,0,33,34];
	// 10 - Entity
	resultArray[8] = [16,0,20,16,25,25,24,0,0,25,23,24,0,5,24,16,0,6,23,27,16,16,16,6,10,5,31,16,0,0,16,5,25];
	// 11 - Fairy
	resultArray[9] = [7,27,7,27,27,0,29,11,25,9,34,18,27,18,5,0,27,20,25,18,34,5,34,12,11,29,18,34,28,27,0,34,20];
	// 12 - Fallen
	resultArray[10] = [7,29,27,22,16,31,29,12,23,34,9,33,16,31,31,0,27,24,4,31,5,27,16,7,12,18,15,4,16,5,24,27,22];
	// 13 - Femme
	resultArray[11] = [23,5,15,0,24,4,27,13,24,18,33,9,24,33,24,27,15,0,24,0,33,24,23,11,13,22,15,23,24,5,8,12,5];
	// 14 - Fiend
	resultArray[12] = [0,0,27,4,0,31,0,0,0,27,16,24,0,0,6,34,0,10,21,0,33,0,8,0,14,24,0,5,0,0,0,0,27];
	// 15 - Foul
	resultArray[13] = [0,0,33,18,8,11,29,15,5,18,31,33,0,0,0,0,0,12,0,18,13,0,31,0,15,5,31,12,18,18,0,4,29];
	// 16 - Fury
	resultArray[14] = [20,23,2,24,0,6,0,16,24,5,31,24,6,0,0,24,0,31,23,23,13,24,31,6,16,24,30,23,6,30,6,0,20];
	// 17 - Genma
	resultArray[15] = [23,25,11,0,25,25,20,0,16,0,0,27,34,0,24,0,0,25,34,16,24,25,13,7,17,20,24,13,34,34,20,34,0];
	// 18 - Haunt
	resultArray[16] = [0,0,33,7,0,22,0,18,0,27,27,15,0,0,0,0,0,0,0,33,31,0,31,0,18,34,0,0,15,15,0,22,22];
	// 19 - Herald
	resultArray[17] = [6,25,0,15,10,25,20,0,6,20,24,0,10,12,31,25,0,9,7,12,0,7,6,6,19,12,0,8,12,7,23,0,25];
	// 20 - Holy
	resultArray[18] = [25,24,2,3,25,11,30,20,23,25,4,24,21,0,23,34,0,7,9,5,4,24,2,7,20,11,33,23,0,0,23,0,7];
	// 21 - Jaki
	resultArray[19] = [31,0,3,23,12,0,29,0,27,18,31,0,0,18,23,16,33,12,5,0,33,4,13,0,21,15,4,0,12,0,17,0,32];
	// 22 - Jirae
	resultArray[20] = [23,23,34,11,5,27,23,22,16,34,5,33,33,13,13,24,31,0,4,33,9,29,4,24,22,15,15,12,33,18,23,21,4];
	// 23 - Kishin
	resultArray[21] = [20,24,20,29,16,31,16,23,16,5,27,24,0,0,24,25,0,7,24,4,29,0,16,24,23,13,30,13,0,0,16,0,13];
	// 24 - Lady
	resultArray[22] = [16,0,29,16,0,25,28,24,16,34,16,23,8,31,31,13,31,6,2,13,4,16,0,0,24,23,23,13,0,0,23,18,27];
	// 25 - Megami
	resultArray[23] = [6,6,0,13,0,20,0,25,6,12,7,11,0,0,6,7,0,6,7,0,24,24,16,0,25,12,30,11,0,16,6,31,23];
	// 26 - Mitama
	resultArray[24] = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,27,28,29,30,31,32,33,34];
	// 27 - Night
	resultArray[25] = [20,13,11,0,31,29,13,27,5,29,18,22,24,5,24,20,34,12,11,15,15,13,23,12,27,9,31,0,24,24,0,4,7];
	// 28 - Raptor
	resultArray[26] = [33,25,33,23,30,15,0,0,31,18,15,15,0,31,30,24,0,0,33,4,15,30,23,30,28,31,0,15,16,16,0,31,18];
	// 29 - Snake
	resultArray[27] = [24,23,5,4,23,11,24,29,16,34,4,23,5,12,23,13,0,8,23,0,12,13,13,11,29,0,15,9,5,28,23,0,27];
	// 30 - Tyrant
	resultArray[28] = [0,0,27,0,0,31,0,30,0,28,16,24,0,18,6,34,15,12,0,12,33,0,0,0,30,24,16,5,0,16,0,27,27];
	// 31 - Vile
	resultArray[29] = [6,0,15,18,0,12,29,31,0,27,5,5,0,18,30,34,15,7,0,0,18,0,0,16,31,24,16,28,16,0,23,15,22];
	// 32 - Wargod
	resultArray[30] = [6,23,20,18,23,20,24,0,16,0,24,8,0,0,6,20,0,23,23,17,23,16,23,6,32,0,0,23,0,23,0,0,0];
	// 33 - Wilder
	resultArray[31] = [0,0,22,0,3,12,3,33,5,34,27,12,0,4,0,34,22,0,0,0,21,0,18,31,33,4,31,0,0,15,0,9,4];
	// 34 - Yoma
	resultArray[32] = [7,27,12,13,25,29,2,34,25,20,22,5,27,29,20,0,22,25,7,32,4,13,27,23,34,7,18,27,27,22,0,4,9];

// There should be another array for cursed fusions:


// Another array for elemental fusions:


// Temporary global variables for referencing selected items
var firstDemonClass = 8;
var secondDemonClass = 8;
var selectedDemon = 0;
var actor1Selected;


(function() {
	var _Scene_Map_createallwindows = Scene_Map.prototype.createAllWindows;
	var _Game_Message_isBusy = Game_Message.prototype.isBusy;
	var _Actor_List = Window_Selectable.prototype.start; //addition
	var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;

	// adds the 'fusion' plugin command
	Game_Interpreter.prototype.pluginCommand = function(command, args) {
		_Game_Interpreter_pluginCommand.call(this, command, args);
		if (command === 'fusion') {
			// As long as you're not in battle
			if (!$gameParty.inBattle()) {
				SceneManager._scene._myWindow.refresh();
				SceneManager._scene._myWindow.show();
				SceneManager._scene._myWindow.open();
				SceneManager._scene._myWindow.activate();
				SceneManager._scene._myWindow.select(1);
				SceneManager._scene._fusionHelpWindow.refresh();
				SceneManager._scene._fusionHelpWindow.show();
				SceneManager._scene._fusionHelpWindow.open();
			};
		}
	};

	Game_Message.prototype.isBusy = function() {
		if (SceneManager._scene._myWindow && SceneManager._scene._myWindow.isOpen()) {
			return true;
		}
		return _Game_Message_isBusy.call(this);
	};

	// Creates all window for the fusion
	Scene_Map.prototype.createAllWindows = function() {
		_Scene_Map_createallwindows.call(this);
		
		// This is the fusion window, which displays all party members
		// and possible results
		this._myWindow = new Fusion_Window(0, 0);
		this.addWindow(this._myWindow);
		this._myWindow.close();

		// This is the fusion window's help window
		this._fusionHelpWindow = new Fusion_Window_Help();
		this.addWindow(this._fusionHelpWindow);
		this._fusionHelpWindow.close();

		// This is the result window
		this._fusionResultWindow = new Result_Window_Status();
		this.addWindow(this._fusionResultWindow);
		this._fusionResultWindow.close();

		// This is the choice window displayed alongside the result window
		
		this._fusionChoiceWindow = new Fusion_Choice_Window();
		this.addWindow(this._fusionChoiceWindow);
		this._fusionChoiceWindow.close();
		
		// Declaring pseudo-parent-child relationships
		this._myWindow._fusionHelpWindow = this._fusionHelpWindow;
		this._myWindow._fusionResultWindow = this._fusionResultWindow;
		//this._myWindow._fusionChoiceWindow = this._fusionChoiceWindow;
	};

	
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 // Fusion Window
 // Define the Fusion window class
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	function Fusion_Window() {
		this.initialize.apply(this, arguments);
	}

	Fusion_Window.prototype = Object.create(Window_Selectable.prototype);
	Fusion_Window.prototype.constructor = Fusion_Window;
	
	Fusion_Window.prototype.windowWidth = function() {
		return 816;
	};

	Fusion_Window.prototype.standardFontSize = function() {
	    return 20;
	};
	
	Fusion_Window.prototype.maxItems = function() {
		return $gameParty.size();

	};

	Fusion_Window.prototype.numVisibleRows = function() {
		return Math.min(10,this.maxItems());
	};

	// This part draws the content
	// Also sets the help window.
	Fusion_Window.prototype.drawItem = function(index) {
		if (index == 0) {
			this.drawHeader();
		return;
		}
		this.setHelpWindow(this._fusionHelpWindow);
		
		var actor = $gameParty.members()[index];
		var rect = this.itemRectForText(index);
		var segmentWidth1 = rect.width/2;
		var segmentWidth2 = segmentWidth1/10;
		var segmentWidth3 = segmentWidth1/10;
		var actorClass = $gameParty.members()[index]._classId;

		// If there's already a selected demon
		if ( actor && actor1Selected ) {
			this.drawText(index, rect.x, rect.y, segmentWidth2);
			this.drawActorClass(actor, rect.x+segmentWidth2, rect.y, segmentWidth2*4);
			this.drawActorName(actor, rect.x+(segmentWidth2*4), rect.y, segmentWidth2*4);
			this.drawActorLevel(actor, rect.x+(segmentWidth2*8), rect.y, segmentWidth2*8);

			//This part shows whether they're fuseable or not
			//refers to the resultsArray above

			//Checks wether they are the same party member.
			if ( actor1Selected._actorId == actor._actorId){
				this.changeTextColor(this.deathColor());
				this.drawText( '----------', rect.x + segmentWidth3*10, rect.y, segmentWidth3*10);
				this.resetTextColor();
			}
			//If element
			else if ( resultArray[actor1Selected._classId - 2][ actor._classId - 2] == 9 ){
				this.changeTextColor(this.hpGaugeColor1());
				this.drawText( 'Element', rect.x + segmentWidth3*10, rect.y, segmentWidth3*10);
				this.resetTextColor();
			}
			//If not same party member, process the results
			else{
				// If the result is valid, after cross-checking the results array
				if( resultArray[actor1Selected._classId - 2][ actor._classId - 2] != 0 ){
					result = this.calculateFusionResult(actor, actor1Selected);
					// If player level is lower than resulting demon, cannot proceed to fusion
					if ($gameParty.members()[0].level <= result.initialLevel){
						this.changeTextColor(this.deathColor());
					}
					// else, it's fine.
					else{
						this.changeTextColor(this.crisisColor());
					}
					this.drawText( $dataClasses[result.classId].name + '   ' + result.name + '   ' + result.initialLevel, rect.x + segmentWidth3*10, rect.y, segmentWidth3*10);
					this.resetTextColor();
				}
				// If the result is invalid, after cross-checking the results array
				else{
					this.changeTextColor(this.deathColor());
					this.drawText( 'X', rect.x + segmentWidth3*10, rect.y, segmentWidth3*10);	
					this.resetTextColor();
				}
			}
		}
		// This should be the default screen, where no demon has been selected yet
		else {
			this.drawText(index, rect.x, rect.y, segmentWidth2);
			this.drawActorClass(actor, rect.x+segmentWidth2, rect.y, segmentWidth2*4);
			this.drawActorName(actor, rect.x+(segmentWidth2*4), rect.y, segmentWidth2*4);
			this.drawActorLevel(actor, rect.x+(segmentWidth2*8), rect.y, segmentWidth2*8);

			//This part shows whether they're fuseable or not
			//refers to the resultsArray above
			for (i = 0; i < this.maxItems()-1; i++){
				//Checks wether they are the same party member.
				if ( $gameParty.members()[i+1]._actorId == $gameParty.members()[index]._actorId){
					this.changeTextColor(this.deathColor());
					this.drawText( '-', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
					this.resetTextColor();
				}
				//If element
				else if ( resultArray[actorClass - 2][ $gameParty.members()[i+1]._classId - 2] == 9 ){
					this.changeTextColor(this.hpGaugeColor1());
					this.drawText( 'E', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
					this.resetTextColor();
				}
				//If not same party member, process the results
				else{
					if( resultArray[actorClass - 2][ $gameParty.members()[i+1]._classId - 2] != 0 ){
						this.changeTextColor(this.crisisColor());
						this.drawText( 'O', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
						this.resetTextColor();
					}
					
					else{
						this.changeTextColor(this.deathColor());
						this.drawText( 'X', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);	
						this.resetTextColor();
					}
				}
			}
		}
	};

	// refresh the window, including moving it into position, which is at the very bottom of the page
	Fusion_Window.prototype.refresh = function() {
		this.move(0, Graphics.boxHeight - this.fittingHeight(this.numVisibleRows()),this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
		this.contents.clear();
		this._fusionHelpWindow.contents.clear();
		this.createContents();
		this.drawAllItems();
	};

	//No need to display the term 'lvl'
	Fusion_Window.prototype.drawActorLevel = function(actor, x, y) {
	    this.drawText(actor.level, x, y, 36, 'left');
	};


	// draw the header text for each column
	Fusion_Window.prototype.drawHeader = function() {
		var rect = this.itemRectForText(0);
		//divide between the selection and the result
		var segmentWidth1 = rect.width/2;
		//partition of the selection part
		var segmentWidth2 = segmentWidth1/10;
		var segmentWidth3 = segmentWidth1/10;
		this.changeTextColor(this.systemColor());
		this.drawText('#', rect.x, rect.y, segmentWidth2);
		this.drawText('Class', rect.x+segmentWidth2, rect.y, segmentWidth2*4);
		this.drawText('Name', rect.x+(segmentWidth2*4), rect.y, segmentWidth2*4);
		this.drawText('LV', rect.x+(segmentWidth2*8), rect.y, segmentWidth2*8);

		// This part runs only if there's nothing selected yet.
		if ( actor1Selected ) {
		// This part runs only if there's already a selected demon
			this.drawText('Result', rect.x + segmentWidth1 + segmentWidth3*3, rect.y, segmentWidth3*10);
		}
		else{
			for (i = 0; i < this.maxItems()-1; i++){
				this.drawText( (i+1), rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
			}	
		}
		this.resetTextColor();
	};

	// the header text is on line 0, which is selectable but shouldn't be.
	// Modifying the cursor code means the cursor can't stop on it
	Fusion_Window.prototype.cursorDown = function(wrap) {
		Window_Selectable.prototype.cursorDown.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorDown.call(this,wrap);
		}
	};
	Fusion_Window.prototype.cursorUp = function(wrap) {
		Window_Selectable.prototype.cursorUp.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorUp.call(this,wrap);
		}
	};
	Fusion_Window.prototype.isOkEnabled = function() {
		return true;
	};
	Fusion_Window.prototype.isCancelEnabled = function() {
		return true;
	};
	Fusion_Window.prototype.callCancelHandler = function() {
		this.callHandler('cancel');
	};
	Fusion_Window.prototype.processCancel = function() {
		SoundManager.playCancel();
		this.updateInputData();
		this.deactivate();
		this.close();
		SceneManager._scene._fusionHelpWindow.close();
		SceneManager._scene._fusionResultWindow.close();
		console.log('Cancel triggered');
		actor1Selected = null;
		this.callCancelHandler();
	};
	Fusion_Window.prototype.close = function() {
		if (!this.isClosed()) {
			this._closing = true;
		}
		this._opening = false;
	};
	Fusion_Window.prototype.isOkTriggered = function() {
		return Input.isRepeated('ok');
	};
	Fusion_Window.prototype.isCancelTriggered = function() {
		return Input.isRepeated('cancel');
	};

	// This part handles all functions related to pressing the 'ok' button
	Fusion_Window.prototype.processOk = function() {
		if (this.isCurrentItemEnabled()) {
			this.playOkSound();
			
			// If there's already an actor selected, we should go to the status screen
			// of the resulting demon
			if ( actor1Selected ){
				SceneManager._scene._fusionHelpWindow.refresh();
				this.close();
				var actor = $gameParty.members()[this.index()];
				var res = this.calculateFusionResult(actor, actor1Selected);
				
				//temporarily add the actor to the current party list so the game doesn't crash
				$gameParty.addActor(res.id);

				// Display the status of the actor... runs into an error.
				this._fusionResultWindow.setActor( $gameParty.members()[ $gameParty.size() - 1 ]);
				SceneManager._scene._fusionHelpWindow.close();
				SceneManager._scene._myWindow.close();
				SceneManager._scene._fusionResultWindow.refresh();
				SceneManager._scene._fusionResultWindow.open();
				SceneManager._scene._fusionChoiceWindow.refresh();
				SceneManager._scene._fusionChoiceWindow.open();

				//remove the temporary member from the party
				$gameParty.removeActor(res.id);
				this.callOkHandler();
				actor1Selected = null;
			}
			// else, it's the assumption that there's nothing selected yet.
			else{
				SceneManager._scene._fusionHelpWindow.refresh();
				
				// Sets the selected actor
				actor1Selected = $gameParty.members()[this.index()];
				console.log('****----actor selected:' + actor1Selected);
				
				this._fusionHelpWindow.actorSelected = $gameParty.members()[this.index()];
				SceneManager._scene._myWindow.contents.clear();
				SceneManager._scene._myWindow.refresh();
				SceneManager._scene._fusionResultWindow.close();
				this.callOkHandler();
			}
		}
		else {
			this.playBuzzerSound();
			actor1Selected = null;
		};
	};

 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 // Fusion Help Window
 // Defines the help window class
 // Should display the selected demon on screen 2
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	Fusion_Window.prototype.createHelpWindow = function() {
	    this._fusionHelpWindow = new Fusion_Window_Help();
	    this.addWindow(this._fusionHelpWindow);
	};

	function Fusion_Window_Help() {
	    this.initialize.apply(this, arguments);
	}

	Fusion_Window_Help.prototype = Object.create(Window_Base.prototype);
	Fusion_Window_Help.prototype.constructor = Fusion_Window_Help;

	Fusion_Window_Help.prototype.initialize = function(numLines) {
	    var width = Graphics.boxWidth;
	    var height = this.contentsHeight()*2;
	    Window_Base.prototype.initialize.call(this, 0, 0, width, height);
	};

	Fusion_Window_Help.prototype.contentsHeight = function() {
	    return this.lineHeight();
	};

	Fusion_Window_Help.prototype.setText = function(text) {
	    if (this._text !== text) {
	        this._text = text;
	        this.refresh();
	    }
	};

	Fusion_Window_Help.prototype.clear = function() {
	    this.setText('');
	};

	Fusion_Window_Help.prototype.setItem = function(item) {
	    this.setText(item ? item.name : '');
	};

	Fusion_Window_Help.prototype.refresh = function() {
	    this.contents.clear();
	    var actorSelected;
	    this.setText('Select the 1st demon');
	    
	    if(actorSelected){
	    	this.setText('Select the second Demon \n    Currently Selected: ' + $dataClasses[actorSelected._classId].name + '   ' + actorSelected._name + '   ' + actorSelected.level);
	    	console.log ('From Help window, actor1Selected is : ' + actorSelected._name);
	    }
	    else{
			this.setText('Select the 1st demon');
	    };
	    this.drawTextEx(this._text, this.textPadding(), 0);
	};

	Fusion_Window_Help.prototype.standardFontSize = function() {
	    return 20;
	};
	Fusion_Window_Help.prototype.lineHeight = function() {
	    return 36;
	};
	Fusion_Window_Help.prototype.standardPadding = function() {
	    return 18;
	};
	Fusion_Window_Help.prototype.textPadding = function() {
	    return 3;
	};

 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 // Fusion Result Status Window
 // Defines the result window class
 // Should display the resulting demon's stats and skills
 // this._fusionResultWindow = new Result_Window_Status();
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	function Result_Window_Status() {
		this.initialize.apply(this, arguments);
	}

	Result_Window_Status.prototype = Object.create(Window_Status.prototype);
	Result_Window_Status.prototype.constructor = Result_Window_Status;

	Result_Window_Status.prototype.initialize = function() {
	    var width = Graphics.boxWidth;
	    var height = Graphics.boxHeight-60;
	    Window_Selectable.prototype.initialize.call(this, 0, 60, width, height);
	    this.refresh();
	    this.activate();
	    this.contents.fontSize = 20;
	};

	Result_Window_Status.prototype.refresh = function() {
	    this.contents.clear();
	    if (this._actor) {
	        //var lineHeight = this.lineHeight();
	        console.log(' Actor to be displayed: ' + this._actor._name);
	        var lineHeight = this.lineHeight()/2;
	        this.drawBlock2(lineHeight * 2);
	        this.drawBlock1(lineHeight * 0);
	        this.drawHorzLine(lineHeight * 1);
	        this.drawHorzLine(lineHeight * 6);
	        this.drawBlock3(lineHeight * 7);
	        this.drawHorzLine(lineHeight * 15);
	        this.drawBlock4(lineHeight * 16);
	    }
	};

	Result_Window_Status.prototype.setActor = function(actor) {
	    if (this._actor !== actor) {
	        this._actor = actor;
	        this.refresh();
	    }
	};

	// Contents
	Result_Window_Status.prototype.drawBlock1 = function(y) {
	    this.drawActorClass(this._actor, 6, y);
	    this.drawActorName(this._actor, 100, y);
	    this.drawText(this._actor.desc, 6, y*2);
	};

	Result_Window_Status.prototype.drawBlock2 = function(y) {
	    this.drawActorFace(this._actor, Graphics.boxWidth - 350, 0, 300, this.contentsHeight());
	    this.drawBasicInfo(6, y);
	    this.drawExpInfo(180, y);
	};

	Result_Window_Status.prototype.drawBlock3 = function(y) {
	    this.drawParameters(6, y);
	};

	Result_Window_Status.prototype.drawBlock4 = function(y) {
	    this.drawSkills(6,y);
	};

	Result_Window_Status.prototype.drawSkills = function(x, y) {
		var args = this._actor.skills();
		var lineHeight = (this.lineHeight()/7)*5;
	    var y2;
		this.changeTextColor(this.systemColor());
		this.drawText('Skills:', x, y);
		this.resetTextColor();
		var segmentWidth1 = (Graphics.boxWidth - 200 )/(args.length/4);
		console.log(args.length);
		console.log(args[0]);
		
		var rect = this.itemRect(y);
	    rect.width = segmentWidth1*4;
	    rect.height = lineHeight*5;
	    rect.x = x;
	    rect.y = lineHeight;
	    rect.lineHeight = lineHeight;
	    
	    // Maximum number of listed skills in a column.
	    var maxCols = 8;
	    
	    var len = args.length;
	    // Determine how many columns are needed by dividing the length by 5 then
	    // round the number up

	    var cols = Math.ceil(len/maxCols);

	    if ( args != null){
		//First case, if skills are less than or equal to 5, requiring one column
		    if (len <= maxCols){
				for (i = 0; i < len-1; i++){
					y2 = y + lineHeight * i;
					console.log(args[i]);
					this.drawText(args[i].name, rect.x, rect.y + y2, segmentWidth1);
				}
			}
		    else{
		    	for (i = 0; i < maxCols; i++){
		    		for( j = 0; j < cols; j++){
		    			y2 = y + lineHeight * i;
		    			//just making sure that it isn't empty for this iteration.
		    			if (args[ i+(j*maxCols) ]){
		    				this.drawText(args[ i+(j*maxCols) ].name, rect.x + (150*j), rect.y + y2, segmentWidth1);		
		    			}
		    		}
		    	}
		    }
	    }
	};

	Result_Window_Status.prototype.maxCols = function() {
	    return 2;
	};

	Result_Window_Status.prototype.drawHorzLine = function(y) {
	    var lineY = y + this.lineHeight() / 2 - 1;
	    this.contents.paintOpacity = 48;
	    this.contents.fillRect(0, lineY, this.contentsWidth(), 2, this.lineColor());
	    this.contents.paintOpacity = 255;
	};

	Result_Window_Status.prototype.drawBasicInfo = function(x, y) {
	    //var lineHeight = this.lineHeight()/1.5;
	    var lineHeight = this.lineHeight();
	    this.drawActorLevel(this._actor, x, y + lineHeight * 0);
	    this.drawActorHp(this._actor, x, y + lineHeight * 1);
	    this.drawActorMp(this._actor, x+180, y + lineHeight * 1);
	};

	Result_Window_Status.prototype.drawActorLevel = function(actor, x, y) {
	    this.changeTextColor(this.systemColor());
	    this.drawText(TextManager.levelA, x, y, 48);
	    this.resetTextColor();
	    this.drawText(actor.level, x + 50, y, 36, 'right');
	};

	Result_Window_Status.prototype.drawExpInfo = function(x, y) {
	    var lineHeight = this.lineHeight()/1.5;
	    var expTotal = TextManager.expTotal.format(TextManager.exp);
	    var expNext = TextManager.expNext.format(TextManager.level);
	    var value1 = this._actor.currentExp();
	    var value2 = this._actor.nextRequiredExp();
	    if (this._actor.isMaxLevel()) {
	        value1 = '-------';
	        value2 = '-------';
	    }
	    this.changeTextColor(this.systemColor());
	    //this.drawText(expTotal, x, y + lineHeight * 0, 270);
	    //this.drawText(expNext, x, y + lineHeight * 2, 270);
	    this.drawText('Next', x, y + lineHeight*0, 270);
	    this.resetTextColor();
	    //this.drawText(value1, x, y + lineHeight * 1, 270, 'right');
	    //this.drawText(value2, x, y + lineHeight * 3, 270, 'right');
	    this.drawText(value2, x+80, y + lineHeight*0, 100, 'right');
	};

	Result_Window_Status.prototype.drawParameters = function(x, y) {
	    var lineHeight = this.lineHeight()/1.4;
	    for (var i = 0; i < 6; i++) {
	        var paramId = i + 2;
	        var y2 = y + lineHeight * i;
	        this.changeTextColor(this.systemColor());
	        this.drawText(TextManager.param(paramId), x, y2, 160);
	        this.resetTextColor();
	        this.drawText(this._actor.param(paramId), x + 120, y2, 60, 'right');
	    }
	};

	Result_Window_Status.prototype.drawProfile = function(x, y) {
		this.drawTextEx(this._actor.profile(), x, y);
		//this.drawText(this._actor.profile(), x, y);
	};

	Result_Window_Status.prototype.drawTextEx = function(text, x, y) {
	    if (text) {
	        var textState = { index: 0, x: x, y: y, left: x };
	        textState.text = this.convertEscapeCharacters(text);
	        textState.height = this.calcTextHeight(textState, false);
	        textState.width = this.contentsWidth();
	        //this.resetFontSettings();
	        while (textState.index < textState.text.length) {
	            this.processCharacter(textState);
	        }
	        return textState.x - x;
	    }
	    else {
	        return 0;
	    }
	};

	Result_Window_Status.prototype.drawActorFace = function(actor, x, y, width, height) {
		//this.drawFace(actor.faceName(), actor.faceIndex(), x, y, Math.floor((this.width - (this.standardPadding() * 2)) / this.maxCols()), height);
	    var bustName = actor.name();
		//var bitmap = ImageManager.loadPicture(bustName);
	    var bitmap = ImageManager.loadPicture(bustName + '_Status');
	    //this.drawFace(actor.faceName(), actor.faceIndex(), x, y, width, height);
		var ox = 0;
		var oy = 0;
	    var dx = x - 1;
	    var dy = y ;
	    var sx = bitmap.width / 2 - width / 2 - ox;
	    var sy = oy;
	    var sh = height;
	    if (bitmap != null){
	        this.contents.unlimitedBlt(bitmap, sx, sy, width, sh, dx, dy);
	    };
	};

	Bitmap.prototype.unlimitedBlt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
	    dw = dw || sw;
	    dh = dh || sh;
	        this._context.globalCompositeOperation = 'source-over';
	        this._context.drawImage(source._canvas, sx, sy, sw, sh, dx, dy, dw, dh);
	        this._setDirty();
	};

	Result_Window_Status.prototype.drawActorCharacter = function(actor, x, y) {
	    this.drawCharacter(actor.characterName(), actor.characterIndex(), x, y);
	};

	Result_Window_Status.prototype.drawActorName = function(actor, x, y, width) {
	    width = width || 168;
	    this.changeTextColor(this.hpColor(actor));
	    this.drawText(actor.name(), x, y, width);
	};

	Result_Window_Status.prototype.drawActorClass = function(actor, x, y, width) {
	    width = width || 168;
	    this.resetTextColor();
	    this.drawText(actor.currentClass().name, x, y, width);
	};

	Result_Window_Status.prototype.drawActorNickname = function(actor, x, y, width) {
	    width = width || 270;
	    this.resetTextColor();
	    this.drawText(actor.nickname(), x, y, width);
	};

	Result_Window_Status.prototype.drawActorLevel = function(actor, x, y) {
	    this.changeTextColor(this.systemColor());
	    this.drawText(TextManager.levelA, x, y, 48);
	    this.resetTextColor();
	    this.drawText(actor.level, x + 84, y, 36, 'right');
	};

	Result_Window_Status.prototype.drawActorIcons = function(actor, x, y, width) {
	    width = width || 144;
	    var icons = actor.allIcons().slice(0, Math.floor(width / Result_Window_Status._iconWidth));
	    for (var i = 0; i < icons.length; i++) {
	        this.drawIcon(icons[i], x + Result_Window_Status._iconWidth * i, y + 2);
	    }
	};

	Result_Window_Status.prototype.drawCurrentAndMax = function(current, max, x, y,
	                                                   width, color1, color2) {
	    var labelWidth = this.textWidth('HP');
	    var valueWidth = this.textWidth('0000');
	    var slashWidth = this.textWidth('/');
	    var x1 = x + width - valueWidth;
	    var x2 = x1 - slashWidth;
	    var x3 = x2 - valueWidth;
	    if (x3 >= x + labelWidth) {
	        this.changeTextColor(color1);
	        this.drawText(current, x3, y, valueWidth, 'right');
	        this.changeTextColor(color2);
	        this.drawText('/', x2, y, slashWidth, 'right');
	        this.drawText(max, x1, y, valueWidth, 'right');
	    } else {
	        this.changeTextColor(color1);
	        this.drawText(current, x1, y, valueWidth, 'right');
	    }
	};

	Result_Window_Status.prototype.drawActorHp = function(actor, x, y, width) {
	    width = width || 186;
	    var color1 = this.hpGaugeColor1();
	    var color2 = this.hpGaugeColor2();
	    this.drawGauge(x, y, width, actor.hpRate(), color1, color2);
	    this.changeTextColor(this.systemColor());
	    this.drawText(TextManager.hpA, x, y, 44);
	    this.drawCurrentAndMax(actor.hp, actor.mhp, x, y, width,
	                           this.hpColor(actor), this.normalColor());
	};

	Result_Window_Status.prototype.drawActorMp = function(actor, x, y, width) {
	    width = width || 186;
	    var color1 = this.mpGaugeColor1();
	    var color2 = this.mpGaugeColor2();
	    this.drawGauge(x, y, width, actor.mpRate(), color1, color2);
	    this.changeTextColor(this.systemColor());
	    this.drawText(TextManager.mpA, x, y, 44);
	    this.drawCurrentAndMax(actor.mp, actor.mmp, x, y, width,
	                           this.mpColor(actor), this.normalColor());
	};

	Result_Window_Status.prototype.drawActorTp = function(actor, x, y, width) {
	    width = width || 96;
	    var color1 = this.tpGaugeColor1();
	    var color2 = this.tpGaugeColor2();
	    this.drawGauge(x, y, width, actor.tpRate(), color1, color2);
	    this.changeTextColor(this.systemColor());
	    this.drawText(TextManager.tpA, x, y, 44);
	    this.changeTextColor(this.tpColor(actor));
	    this.drawText(actor.tp, x + width - 64, y, 64, 'right');
	};

	Result_Window_Status.prototype.drawActorSimpleStatus = function(actor, x, y, width) {
	    var lineHeight = this.lineHeight();
	    var x2 = x + 180;
	    var width2 = Math.min(200, width - 180 - this.textPadding());
	    this.drawActorName(actor, x, y);
	    this.drawActorLevel(actor, x, y + lineHeight * 1);
	    this.drawActorIcons(actor, x, y + lineHeight * 2);
	    this.drawActorClass(actor, x2, y);
	    this.drawActorHp(actor, x2, y + lineHeight * 1, width2);
	    this.drawActorMp(actor, x2, y + lineHeight * 2, width2);
	};

 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 // Fusion Choice Window
 // Let's the user decide wether to proceed to fusion or not
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	function Fusion_Choice_Window() {
	    this.initialize.apply(this, arguments);
	};

	Fusion_Choice_Window.prototype = Object.create(Window_Command.prototype);
	Fusion_Choice_Window.prototype.constructor = Fusion_Choice_Window;

	Fusion_Choice_Window.prototype.initialize = function(x, y) {
	    Window_Command.prototype.initialize.call(this, x, y);
	    this.addCommand("Yes", "yes");
	    this.addCommand("No", "no");
	};

	Fusion_Choice_Window.prototype.numVisibleRows = function() {
	    return 1;
	};

	Fusion_Choice_Window.prototype.maxCols = function() {
	    return 2;
	};

	Fusion_Choice_Window.prototype.itemTextAlign = function() {
	    return 'center';
	};


 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 // Fusion Process
 // Defines processes and calculation related to fusion
 // This part calculates the result of the fusion based on the class
 // of the ingredients. Should not allow fusion above main character's
 // level. 
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	Fusion_Window.prototype.calculateFusionResult = function(item1, item2){
		var fusionResultClass = resultArray[item1._classId - 2][item2._classId - 2];
		var fusionResultArray = [];
		var fusionResultLevel = 0;
		var fusionResult = null;
		
		//create an array for all results
		for ( i = 1; i < $dataActors.length; i++){

			// Adds all actors with the same class to the array
			// For future: Needs to skip those with special tags, like
			// special fusion or evolution only
			// if has boss tag, needs to defeat boss first
			if ( $dataActors[i].classId == fusionResultClass ){
				fusionResultArray.push($dataActors[i]);
				console.log(' Added to the fusionResultArray: ' + $dataActors[i].classId + '  ' + $dataActors[i].name + '  ' + $dataActors[i].initialLevel);
			}
		}
		
		// If Element:
		if ( item2._actorId == item1._actorId){
			// Calculate which element to be the result of
			console.log('calculateFusionResult: Element: item11Selected.name is :' + item2._name);
			console.log('calculateFusionResult: Element: item1.name is :' + item1._name);
		}
		// If not element but valid:
		else if( resultArray[item2._classId - 2][ item1._classId - 2] != 0 ){
			
			var lvlOfDemon1 = $dataActors[item2._actorId].initialLevel;
			var lvlOfDemon2 = $dataActors[item1._actorId].initialLevel;
			fusionResultLevel = Math.floor( ( ( lvlOfDemon2 + lvlOfDemon1 ) / 2 ) + 1);
			
			//find a demon from the result array whose level is less than or equal to
			for ( j = 0; j < fusionResultArray.length; j++){
				if( fusionResultLevel >= fusionResultArray[j].initialLevel ){
					fusionResult = fusionResultArray[j];
				}
			}
		};
		return fusionResult;
	};





})();
Pages: 1