"use strict";

var tdlg=0;
DATA_SDS_SCRIPTED_EVENTS["Raviene_intro"] = {
		//0 : {
		tdlg : {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();

					cacheVars.ravi = new GO_Raviene();
					cacheVars.ravi.sprite.x = (19<<4);
					cacheVars.ravi.sprite.y = (1<<4);
					cacheVars.ravi.direction = -1;
					//cacheVars.meli.sprite.map_room.addSprite(cacheVars.ravi.sprite);
					cacheVars.ravi.addToRoom(cacheVars.meli.sprite.map_room);
					cacheVars.objMgr.add(cacheVars.ravi);

					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.KILL;
					cacheVars.ravi.spell_target_name = "Hedgeboar";
				}

				cacheVars.bgmName = SDS.bgmName;
				if (SDS.bgm) SDS.bgm.stop();
				//SDS.bgm = new Chiptune("Writing a Character",SDS.bgmchip);
				//SDS.bgm.play(true);
				
				if (DATA_SDS_DIALOGUE["Raviene_c3_introduction_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c3_introduction_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		//1 : {
		(++tdlg) : {
			customPre : function(cacheVars){
				// asynchronous dialog
				if (DATA_SDS_DIALOGUE["Raviene_c3_introduction_0cast"]){
					cacheVars.dlgMgr.open("Raviene_c3_introduction_0cast",noop);
				}
			},
			controls : {
				"Raviene":{B:true}
			},
			customPost : noop
		},
		//91 : {
		(tdlg+=90) : {
			customPre : noop,
			controls : {
				"Raviene":{B:false}
			},
			customPost : noop
		},
		//122 : {
		(tdlg+=31) : {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.KILL;
					cacheVars.ravi.spell_target_name = "Meli";
				}
				if (DATA_SDS_DIALOGUE["Raviene_c3_introduction_1"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c3_introduction_1",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		//123 : {
		(++tdlg) : {
			customPre : noop,
			controls : {
				"Raviene":{B:true}
			},
			customPost : noop
		},
		//213 : {
		(tdlg+=90) : {
			customPre : noop,
			controls : {
				"Raviene":{B:false}
			},
			customPost : noop
		},
		//214 : {
		(++tdlg) : {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Raviene_c3_introduction_2"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c3_introduction_2",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		//215 : {
		(++tdlg) : {
			customPre : noop,
			controls : {
				"Raviene":{A:true, right: true, up: true}
			},
			customPost : noop
		},
		//234 : {
		(tdlg+=19) : {
			customPre : noop,
			controls : {
				"Raviene":{A:false}
			},
			customPost : noop
		},
		//235 : {
		(++tdlg) : {
			customPre : noop,
			controls : {
				"Raviene":{A:true}
			},
			customPost : noop
		},
		//295 : {
		(tdlg+=60) : {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					//cacheVars.ravi.sprite.map_room.removeSprite(cacheVars.ravi.sprite);
					cacheVars.ravi.clearFromRoom(cacheVars.ravi.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.ravi);
				}
			},
			controls : {},
			customPost : function(cacheVars){
				GLOBAL_DIARY.note(3,"MET_RAVIENE");

				SDS.bgmName = cacheVars.bgmName;
				SDS.bgm.stop();
				SDS.bgm = new Chiptune(SDS.bgmName,SDS.bgmchip);
				SDS.bgm.play(true);

				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}

			}
		},
	};