SHININGRIVER'S PROFILE

I do freelance photoshop and writing in my free time. I'm also a computer programmer.

//=============================================================================
//
// EdoTenseiFusion.js
// https://kinoar.github.io/rmmv-doc-web/index.html
//=============================================================================



/*:
 * @plugindesc Display a list of actors
 * @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];

var firstDemonClass = 8;
var secondDemonClass = 8;
var selectedDemon = 0;
var actor1Selected;

 //--------------------------------------------------------------------
 //
 // Select the 1st party member
 //
 // This must show all part members and determine whether they are fusable 
 // or not based on their classes.
 // THIS PART IS DONE AND OVER WITH PLEASE!!!!
 //--------------------------------------------------------------------


(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 'actorlist' plugin command
	Game_Interpreter.prototype.pluginCommand = function(command, args) {
		_Game_Interpreter_pluginCommand.call(this, command, args);
		if (command === 'fusion') {
			/*console.log(firstDemonClass);
			console.log(secondDemonClass);
			console.log(resultArray[firstDemonClass - 2][secondDemonClass - 2]);
			console.log('First Demon Class is ' + $dataClasses[firstDemonClass].name);
			console.log('Second Demon Class is ' + $dataClasses[secondDemonClass].name);
			console.log('Resulting Demon Class is ' + $dataClasses[resultArray[firstDemonClass - 2][secondDemonClass - 2]].name);
			*/
			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._fusion1HelpWindow.refresh();
				SceneManager._scene._fusion1HelpWindow.show();
				SceneManager._scene._fusion1HelpWindow.open();
			};
		}
	};

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

	// create the compendium window while starting the map
	Scene_Map.prototype.createAllWindows = function() {
		_Scene_Map_createallwindows.call(this);
		// This is the first fusion window
		this._myWindow = new Fusion1_Window(0, 0);
		this.addWindow(this._myWindow);
		this._myWindow.close();

		// This is the first fusion window's help window
		this._fusion1HelpWindow = new Fusion1_Window_Help();
		this.addWindow(this._fusion1HelpWindow);
		this._fusion1HelpWindow.close();

		// This is the second fusion window
		this._myWindow2 = new Fusion2_Window(0, 0);
		this.addWindow(this._myWindow2);
		this._myWindow2.close();

		//This is the second fusion window's help window
		this._fusion2HelpWindow = new Fusion2_Window_Help();
		this.addWindow(this._fusion2HelpWindow);
		this._fusion2HelpWindow.close();
		
	};


	// Define the first Fusion window class
	function Fusion1_Window() {
		this.initialize.apply(this, arguments);
	}

	//Fusion1_Window.prototype = Object.create(Window_Command.prototype);
	Fusion1_Window.prototype = Object.create(Window_Selectable.prototype);
	Fusion1_Window.prototype.constructor = Fusion1_Window;
	
	// set the width of the window
	Fusion1_Window.prototype.windowWidth = function() {
		return 816;
	};

	Fusion1_Window.prototype.standardFontSize = function() {
	    return 18;
	};
	// set the number of items in the list. Could use different values here,
	// such as $gameParty.members() or $gameParty.battleMembers()
	Fusion1_Window.prototype.maxItems = function() {
		return $gameParty.size();
	//return Game_Party.size();

	};

	// the number of visible rows in the window. Without this the height of the
	// window could be too tall for the screen with large numbers of actors
	Fusion1_Window.prototype.numVisibleRows = function() {
		return Math.min(10,this.maxItems());
	};

	// draw each line of the window. Its width is evenly divided into three
	Fusion1_Window.prototype.drawItem = function(index) {
		if (index == 0) {
			this.drawHeader();
		return;
		}
		this.setHelpWindow(this._fusion1HelpWindow);
		//var actor = $gameActors.actor(index);
		var actor = $gameParty.members()[index];
		console.log('actor: ' + actor.name);
		var rect = this.itemRectForText(index);
		//var segmentWidth = rect.width/3;
		var segmentWidth1 = rect.width/2;
		//partition of the selection part
		var segmentWidth2 = segmentWidth1/10;
		var segmentWidth3 = segmentWidth1/10;
		var actorClass = $gameParty.members()[index]._classId;
		if (actor) {
			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++){
				//check case if not equal or not zero, then possible for fusion. Otherwise, not possible
				console.log('=-=-=-=-');
				
				console.log('actor Class: ' + actorClass);
				console.log('i: ' + i);
				console.log('Game Party Member for this line: '+ $gameParty.members()[i+1]._name);

				//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
	Fusion1_Window.prototype.refresh = function() {
		this.move(0, Graphics.boxHeight - this.fittingHeight(this.numVisibleRows()),this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
		this.createContents();
		this.drawAllItems();
	};

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

	// draw the header text for each column
	Fusion1_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);
		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
	Fusion1_Window.prototype.cursorDown = function(wrap) {
		Window_Selectable.prototype.cursorDown.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorDown.call(this,wrap);
		}
	};

	Fusion1_Window.prototype.cursorUp = function(wrap) {
		Window_Selectable.prototype.cursorUp.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorUp.call(this,wrap);
		}
	};

	Fusion1_Window.prototype.isOkEnabled = function() {
		return true;
	};
	Fusion1_Window.prototype.isCancelEnabled = function() {
		return this.isHandled('cancel');
	};
	Fusion1_Window.prototype.callCancelHandler = function() {
		this.callHandler('cancel');
		Fusion1_Window.close();
		SceneManager._scene._fusion1HelpWindow.close();
	}

	Fusion1_Window.prototype.processCancel = function() {
		SoundManager.playCancel();
		this.updateInputData();
		this.deactivate();
		//
		// same here
		//
		this.close();
		console.log('Cancel triggered');
		this.callCancelHandler();
	};

	Fusion1_Window.prototype.close = function() {
		if (!this.isClosed()) {
			this._closing = true;
		}
		this._opening = false;
	};

	Fusion1_Window.prototype.isOkTriggered = function() {
		return Input.isRepeated('ok');
	};

	Fusion1_Window.prototype.isCancelTriggered = function() {
		return Input.isRepeated('cancel');
	};

	Fusion1_Window.prototype.processOk = function() {
		if (this.isCurrentItemEnabled()) {
			this.playOkSound();
			//this.updateInputData();
			//this.deactivate();
			//
			// I've added the next two lines to close the window and output
			// the index of the selected item to the console
			//
			//this.close();
			actor1Selected = $gameParty.members()[this.index()];
			console.log('OK triggered, index = ' + this.index());
			console.log('Selected party member is: ' + actor1Selected._name);
			console.log('party size: ' + $gameParty.size());
			
			//SceneManager._scene._fusion1HelpWindow.close();
			//SceneManager._scene._myWindow.close();
			// proceed to second fusion window

			SceneManager._scene._myWindow2.refresh();
			SceneManager._scene._myWindow2.show();
			SceneManager._scene._myWindow2.open();
			SceneManager._scene._myWindow2.activate();
			SceneManager._scene._myWindow2.select(1);
			SceneManager._scene._fusion2HelpWindow.refresh();
			SceneManager._scene._fusion2HelpWindow.show();
			SceneManager._scene._fusion2HelpWindow.open();

			this.callOkHandler();

		}
		else {
			this.playBuzzerSound();
		}
	};


	// This window serves as the 'help' window from the first screen,
	// as well as the help window on the second screen
	// For the first screen, it will just display the message:
	//    "Select the first demon"
	// For the second screen, it will display the message:
	//    "Select the second demon"
	//    
	// For the sacrificial fusion screen, it will display the message:
	//    "select demon to be sacrifice"
	//    
	//    


	Fusion1_Window.prototype.createHelpWindow = function() {
	    this._fusion1HelpWindow = new Fusion1_Window_Help();
	    this.addWindow(this._fusion1HelpWindow);
	};

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

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

	Fusion1_Window_Help.prototype.initialize = function(numLines) {
	    var width = Graphics.boxWidth;
	    //var height = this.fittingHeight(numLines || 4);
	    var height = this.contentsHeight() * 2;
	    Window_Base.prototype.initialize.call(this, 0, 0, width, height);
	    this.setText('Select the first demon');
	    //this.drawText('Second Demon: ', 0, this.lineHeight(), 'left');
	};

	Fusion1_Window_Help.prototype.contentsHeight = function() {
	    //return this.height - this.standardPadding() * 2;
	    return this.lineHeight();
	};

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

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

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

	Fusion1_Window_Help.prototype.refresh = function() {
	    this.contents.clear();
	    //this.move(0, Graphics.boxHeight - this.fittingHeight(this.numVisibleRows()),this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
	    //this.move(0, 0,this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
	    this.drawTextEx(this._text, this.textPadding(), 0);
	};

	Fusion1_Window_Help.prototype.standardFontSize = function() {
	    return 20;
	};

	Fusion1_Window_Help.prototype.lineHeight = function() {
	    return 36;
	};

	Fusion1_Window_Help.prototype.standardPadding = function() {
	    return 18;
	};

	Fusion1_Window_Help.prototype.textPadding = function() {
	    return 3;
	};


	//--------------------------------------------------------------------
	//
	// Select the 2nd Demon
	//
	// The selected demon from the first screen must be shown on this
	// screen, along with the result of the fusion
	//
	//--------------------------------------------------------------------


	// Define the second Fusion window class
	function Fusion2_Window() {
		this.initialize.apply(this, arguments);
	}

	//Fusion2_Window.prototype = Object.create(Window_Command.prototype);
	Fusion2_Window.prototype = Object.create(Window_Selectable.prototype);
	Fusion2_Window.prototype.constructor = Fusion2_Window;
	
	// set the width of the window
	Fusion2_Window.prototype.windowWidth = function() {
		return 816;
	};

	Fusion2_Window.prototype.standardFontSize = function() {
	    return 18;
	};
	// set the number of items in the list. Could use different values here,
	// such as $gameParty.members() or $gameParty.battleMembers()
	Fusion2_Window.prototype.maxItems = function() {
		return $gameParty.size();
	//return Game_Party.size();

	};

	// the number of visible rows in the window. Without this the height of the
	// window could be too tall for the screen with large numbers of actors
	Fusion2_Window.prototype.numVisibleRows = function() {
		return Math.min(10,this.maxItems());
	};

	// draw each line of the window. Its width is evenly divided into three
	Fusion2_Window.prototype.drawItem = function(index) {
		if (index == 0) {
			this.drawHeader();
		return;
		}
		this.setHelpWindow(this._Fusion2HelpWindow);
		var actor = $gameParty.members()[index];
		console.log('actor: ' + actor.name);
		var rect = this.itemRectForText(index);
		var segmentWidth1 = rect.width/2;
		var segmentWidth2 = segmentWidth1/10;
		//var segmentWidth3 = segmentWidth1/10;
		var segmentWidth3 = segmentWidth1;
		console.log( 'selected actor is: ' + actor1Selected._name);
		console.log( 'selected actor actorID is: ' + actor1Selected._actorId);
		if (actor) {
			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.
				console.log(' *--------* ');
				console.log(' Actor Class is: ' + actor._classId);
				console.log(' First Selected actor ID is: ' + actor1Selected._actorId );
				console.log(' current Actor actor ID is: ' + actor._actorId);
				if ( actor1Selected._actorId == actor._actorId){
					console.log('-------Same Actor!!!!!--------');
					this.changeTextColor(this.deathColor());
					this.drawText( '----------', rect.x + segmentWidth3, rect.y, segmentWidth3);
					this.resetTextColor();
				}
				//If element
				else if ( resultArray[actor1Selected._classId - 2][ actor._classId - 2] == 9 ){
					console.log('-------Same Class!!!!!--------');
					console.log(' *=========*');
					console.log(' actor1Selected classID is: ' + actor1Selected._classId);
					console.log(' actor classID is: ' + actor._classId);
					this.changeTextColor(this.hpGaugeColor1());
					this.drawText( 'Element', rect.x + segmentWidth3, rect.y, segmentWidth3);
					this.resetTextColor();
				}
				//If not same party member, process the results
				else{
					console.log('-------Possible Result!!!!!--------');
					console.log(' *=*=*=*=*=*=*');
					console.log(' actor1Selected classID is: ' + actor1Selected._classId);
					console.log(' actor classID is: ' + actor._classId);
					if( resultArray[actor1Selected._classId - 2][ actor._classId - 2] != 0 ){
						this.changeTextColor(this.crisisColor());
						//this.drawText( 'O', rect.x+segmentWidth1+(segmentWidth3*i), rect.y, segmentWidth3);
						//Show the fusion result
						this.drawText( 'RESULT!!!!!', rect.x + segmentWidth3, rect.y, segmentWidth3);
						this.resetTextColor();
					}
					
					else{
						console.log('-------Cannot Be!!!!!--------');
						this.changeTextColor(this.deathColor());
						this.drawText( 'X', rect.x + segmentWidth3, rect.y, segmentWidth3);	
						this.resetTextColor();
					}
				}
			
		}
	};

	// refresh the window, including moving it into position
	Fusion2_Window.prototype.refresh = function() {
		this.move(0, Graphics.boxHeight - this.fittingHeight(this.numVisibleRows()),this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
		this.createContents();
		this.drawAllItems();
	};

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

	// draw the header text for each column
	Fusion2_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.drawText('Result', rect.x + segmentWidth1 + segmentWidth3, rect.y, segmentWidth3*10);
		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
	Fusion2_Window.prototype.cursorDown = function(wrap) {
		Window_Selectable.prototype.cursorDown.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorDown.call(this,wrap);
		}
	};

	Fusion2_Window.prototype.cursorUp = function(wrap) {
		Window_Selectable.prototype.cursorUp.call(this,wrap);
		if (this.index() == 0) {
			Window_Selectable.prototype.cursorUp.call(this,wrap);
		}
	};

	Fusion2_Window.prototype.isOkEnabled = function() {
		return true;
	};
	Fusion2_Window.prototype.isCancelEnabled = function() {
		return this.isHandled('cancel');
	};
	Fusion2_Window.prototype.callCancelHandler = function() {
	    this.callHandler('cancel');
		Fusion2_Window.close();
	}

	Fusion2_Window.prototype.processCancel = function() {
		SoundManager.playCancel();
		this.updateInputData();
		this.deactivate();
		//
		// same here
		//
		this.close();
		console.log('Cancel triggered');
		this.callCancelHandler();
	};

	Fusion2_Window.prototype.close = function() {
		if (!this.isClosed()) {
			this._closing = true;
		}
		this._opening = false;
	};

	Fusion2_Window.prototype.isOkTriggered = function() {
		return Input.isRepeated('ok');
	};

	Fusion2_Window.prototype.isCancelTriggered = function() {
		return Input.isRepeated('cancel');
	};

	Fusion2_Window.prototype.processOk = function() {
		if (this.isCurrentItemEnabled()) {
			this.playOkSound();
			this.updateInputData();
			this.deactivate();
			//
			// I've added the next two lines to close the window and output
			// the index of the selected item to the console
			//
			this.close();
			console.log('OK triggered, index = '+this.index());
			console.log('party size: ' + $gameParty.size());
			this.callOkHandler();
			SceneManager._scene._fusion2HelpWindow.close();
			SceneManager._scene._myWindow2.close();
			
			this.callOkHandler();
		}
		else {
			this.playBuzzerSound();
		}
	};


	// This window serves as the 'help' window from the first screen,
	// as well as the help window on the second screen
	// For the first screen, it will just display the message:
	//    "Select the first demon"
	// For the second screen, it will display the message:
	//    "Select the second demon"
	//    
	// For the sacrificial fusion screen, it will display the message:
	//    "select demon to be sacrifice"
	//    
	//    


	Fusion2_Window.prototype.createHelpWindow = function() {
	    this._Fusion2HelpWindow = new Fusion2_Window_Help();
	    this.addWindow(this._Fusion2HelpWindow);
	};

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

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

	Fusion2_Window_Help.prototype.initialize = function(numLines) {
	    var width = Graphics.boxWidth;
	    //var height = this.fittingHeight(numLines || 4);
	    var height = this.contentsHeight() * 2;
	    Window_Base.prototype.initialize.call(this, 0, 0, width, height);
	    this.setText('Select the second Demon: ');
	    console.log (' From Help window, actor1Selected is : ' + actor1Selected);
	};

	Fusion2_Window_Help.prototype.contentsHeight = function() {
	    //return this.height - this.standardPadding() * 2;
	    return this.lineHeight();
	};

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

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

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

	Fusion2_Window_Help.prototype.refresh = function() {
	    this.contents.clear();
	    //this.move(0, Graphics.boxHeight - this.fittingHeight(this.numVisibleRows()),this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
	    //this.move(0, 0,this.windowWidth(),this.fittingHeight(this.numVisibleRows()));
	    //this.drawTextEx(this._text, this.textPadding(), 0);
	    console.log (' From Help window, actor1Selected is : ' + actor1Selected);
	    /*if ( actor1Selected != null ){ 
	    	this.setText('Select the second demon ' + actor1Selected._classId + ' ' + actor1Selected._name + ' ' + actor1Selected.level);
	    }
	    else{
	    	this.setText('Select the second Demon: ');
	    }*/
	    this.drawTextEx(this._text, this.textPadding(), 0);
	};


	Fusion2_Window_Help.prototype.standardFontSize = function() {
	    return 20;
	};

	Fusion2_Window_Help.prototype.lineHeight = function() {
	    return 36;
	};

	Fusion2_Window_Help.prototype.standardPadding = function() {
	    return 18;
	};

	Fusion2_Window_Help.prototype.textPadding = function() {
	    return 3;
	};


})();



	














 //--------------------------------------------------------------------
 //
 // Actual fusion function
 //
 // This part calculates the result of the fusion based on the class
 // of the ingredients. Should not allow fusion above main character's
 // level. 
 //
 //--------------------------------------------------------------------

/*****************************************
	Workflow:
	Check Class of 1st Demon		capture class as string
	Case string == 'Avatar'		
		fusionArray = Avatar array results	
	….		
	Case string == 'Yoma'		
		fusionArray = Yoma array results	
			
	Check Class of 2nd Demon		
		var index = corresponding index value based on selected array	
		Display result on results window	
	If press OK		
		// calculate fusion results based on hierarcy (see table below)	
		proceed to fusion	
		add team member( fusion result )	
		remove team member (ingredient 1 and 2)	
	//Skill Inheritance		
*/