"use strict";

DATA_SDS_SCRIPTED_EVENTS["Meli_earthquake_1"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli ){
					// we'll be controlling Meli here, so...
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli .controls = new Controls();

					cacheVars.meli.direction=-1;
					cacheVars.meli.overrideFrame=59;
				}

				cacheVars.bgmName = SDS.bgmName;
				SDS.switchBgm("Earthquake",false);

				cacheVars.countdown=15;
				cacheVars.delta=-1;

				DATA_EARTHQUAKE_FN(cacheVars);
			},
			controls : {},
			customPost : noop
		},
		2 : {
			customPre : noop,
			controls : {},
			customPost : DATA_EARTHQUAKE_FN
		},
		4 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				DATA_EARTHQUAKE_FN(cacheVars);
				cacheVars.countdown--;
				if (cacheVars.countdown>0){
					cacheVars.frameCounter=2;
				}
			}
		},
		6 : {
			customPre : noop,
			controls : {},
			customPost : DATA_EARTHQUAKE_FN
		},
		21 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.overrideFrame=null;
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}

				SDS.switchBgm(cacheVars.bgmName,true);
			}
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Charis_kick_demo"] = {
		0 : {
			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.charis = cacheVars.objMgr.getNamedObject("Charis");
				if (cacheVars.charis){
					cacheVars.painting = cacheVars.charis.painting;
					cacheVars.charis.painting = false;
					cacheVars.charis.idle_timer=0;
					cacheVars.charis.anim_state = cacheVars.charis.ANIM_STATES.bob;
					cacheVars.charis.frame_timer=0;
				}
				if (cacheVars.charis && cacheVars.meli){
					cacheVars.charis.direction = (cacheVars.charis.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}
				
				if (DATA_SDS_DIALOGUE["Charis_c1_advice_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Charis_c1_advice_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							GLOBAL_SCRATCHPAD.note("Dlg_Charis_Line",1);
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		1 : {
			customPre : noop,
			controls : {
				"Charis":{right:true, up:true}
			},
			customPost : noop
		},
		5 : {
			customPre : noop,
			controls : {
				"Charis":{right:false, left:true, up:true}
			},
			customPost : noop
		},
		9 : {
			customPre : noop,
			controls : {
				"Charis":{left:false, up:false, A:true}
			},
			customPost : noop
		},
		10 : {
			customPre : noop,
			controls : {
				"Charis":{A: false}
			},
			customPost : noop
		},
		19 : {
			customPre : noop,
			controls : {
				"Charis":{left:true, down:true}
			},
			customPost : noop
		},
		23 : {
			customPre : noop,
			controls : {
				"Charis":{left:false, right: true, down:true}
			},
			customPost : noop
		},
		27 : {
			customPre : noop,
			controls : {
				"Charis":{right:false, down:false}
			},
			customPost : function(cacheVars){
				if (cacheVars.charis && cacheVars.meli){
					cacheVars.charis.direction = (cacheVars.charis.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}

				cacheVars.wait=true;
				cacheVars.dlgMgr.open("Charis_c1_advice_1",function(index,retval){
					if (retval!=null){
						GLOBAL_SCRATCHPAD.note("Charis_c1_advice_1",1);
						cacheVars.wait=false; // yay js scoping
					}
				});
			}
		},
		28 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.overrideFrame=null;
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}

				if (cacheVars.charis && cacheVars.painting){
					cacheVars.charis.painting = cacheVars.painting;
				}
			}
		},
	};

DATA_SDS_SCRIPTED_EVENTS["Meli_shrine1_pray"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// we'll be controlling Meli here, so...
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();

					cacheVars.meli.overrideFrame = 27;
					cacheVars.meli.overrideFrame += cacheVars.meli.direction>0 ? 0 : 32;
				}
			},
			controls : {},
			customPost : noop
		},
		
		60 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.overrideFrame=null;
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				if (!GLOBAL_SCRATCHPAD.check("PRAYED") && !GLOBAL_DIARY.hasTear("S1_ALTAR")){
					//var altar = cacheVars.objMgr.getNamedObject("Altar");
					cacheVars.altar = cacheVars.objMgr.getNamedObject("Altar");
					if (cacheVars.altar){
						//var tear = new GO_Tear("S1_ALTAR");
						cacheVars.tear = new GO_Tear("S1_ALTAR");
						cacheVars.tear.spawnOnSprite(cacheVars.altar.sprite,cacheVars.objMgr);
						cacheVars.tear.sprite.y-=32;
						//var poof = new GO_Poof();
						cacheVars.poof = new GO_Poof();
						cacheVars.poof.spawnOnSprite(cacheVars.altar.sprite,cacheVars.objMgr);
						cacheVars.poof.sprite.y-=32;
					}
				}
				GLOBAL_SCRATCHPAD.note("PRAYED",true)
			}
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Rinda_shrinequake_setup"] = {
		0 : {
			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.rinda = cacheVars.objMgr.getNamedObject("Rinda");
				if (cacheVars.rinda && cacheVars.meli){
					cacheVars.rinda.direction = (cacheVars.rinda.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}
				cacheVars.shrinequake=false;
				if (DATA_SDS_DIALOGUE["Rinda_c1_advice_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_advice_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.previousRetval = retval;
							if (retval==1){
								GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",1);
								cacheVars.shrinequake = true;
							}
							else{
								GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",0);
								cacheVars.frameCounter=64; // skip straight to events at frame 64 (cleanup)
							}
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		1 : {
			customPre : function(cacheVars){
				
				if (cacheVars.previousRetval==1){ // chose to proceed.  Pop the next dialogue
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_advice_1",function(index,retval){
						if (retval!=null){
							GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",2);
							cacheVars.wait=false; // yay js scoping
						}
					});

				}
			},
			controls : {},
			customPost : noop
		},
		2 : {
			customPre : noop,
			controls : {
				"Rinda":{right:true, down:true}
			},
			customPost : noop
		},
		32 : {
			customPre : noop,
			controls : {
				"Rinda":{right:false, down:false, A:true}
			},
			customPost : function(cacheVars){
				cacheVars.wait=true;
				cacheVars.dlgMgr.open("Rinda_c1_advice_2",function(index,retval){
					if (retval!=null){
						GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",3);
						cacheVars.wait=false; // yay js scoping
					}
				});
			}
		},
		33 : {
			customPre : noop,
			controls : {
				"Rinda":{left:true, up:true, A:false}
			},
			customPost : noop
		},
		63 : {
			customPre : noop,
			controls : {
				"Rinda":{left:false, up:false}
			},
			customPost : function(cacheVars){
				//var meli = cacheVars.objMgr.getNamedObject("Meli");
				//var rinda = cacheVars.objMgr.getNamedObject("Rinda");
				if (cacheVars.rinda && cacheVars.meli){
					cacheVars.rinda.direction = (cacheVars.rinda.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}

				cacheVars.wait=true;
				cacheVars.dlgMgr.open("Rinda_c1_advice_3",function(index,retval){
					if (retval!=null){
						GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",4);
						cacheVars.wait=false; // yay js scoping
					}
				});
			}
		},
		64 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				//var meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.shrinequake && cacheVars.meli){
					// add the trigger region to run the shrinequake
					cacheVars.triggerEvent = function(sourceGO){
						if (GLOBAL_DIARY.check(1,"SHRINEQUAKE")) return "";

						GLOBAL_DIARY.note(1,"SHRINEQUAKE");
						GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",0);
						return "Meli_shrinequake_1";
					}

					//var trig = new GO_Trigger(2<<4,3<<4,triggerEvent);
					cacheVars.trig = new GO_Trigger(2<<4,3<<4,cacheVars.triggerEvent);
					cacheVars.trig.sprite.x = (4<<4);
					cacheVars.trig.sprite.y = (11<<4);
					cacheVars.meli.sprite.map_room.addSprite(cacheVars.trig.sprite);
					cacheVars.objMgr.add(cacheVars.trig);
				}
				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.overrideFrame=null;
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			}
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Meli_shrinequake_1"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.rinda = cacheVars.objMgr.getNamedObject("Rinda");
				cacheVars.delta = -1;
				// we'll be controlling Meli here, so...
				if (cacheVars.meli){
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.rinda){
					
				}

				cacheVars.bgmName = SDS.bgmName;
				SDS.switchBgm("Earthquake",false);

				cacheVars.countdown=19;

				DATA_SHRINEQUAKE_FN(cacheVars);
			},
			controls : {},
			customPost : noop
		},
		2 : {
			customPre : noop,
			controls : {},
			customPost : DATA_SHRINEQUAKE_FN
		},
		4 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				DATA_SHRINEQUAKE_FN(cacheVars);
				cacheVars.countdown--;
				if (cacheVars.countdown>0){
					cacheVars.frameCounter=2;
				}
			}
		},
		6 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				DATA_SHRINEQUAKE_FN(cacheVars);

				//var block = cacheVars.objMgr.getNamedObject("KeyBlock");
				cacheVars.block = cacheVars.objMgr.getNamedObject("KeyBlock");
				if (cacheVars.block){
					//var rock = new GO_Boulder(GO_Boulder.TYPES.SHRINEBLOCK);
					cacheVars.rock = new GO_Boulder(GO_Boulder.TYPES.SHRINEBLOCK);
					cacheVars.rock.sprite.x = cacheVars.block.sprite.x
					cacheVars.rock.sprite.y = cacheVars.block.sprite.y;
					//cacheVars.rock.name = "KeyBlock";

					//presto-change-o
					cacheVars.block.sprite.map_room.addSprite(cacheVars.rock.sprite);
					cacheVars.objMgr.add(cacheVars.rock);
					cacheVars.block.sprite.map_room.removeSprite(cacheVars.block.sprite);
					cacheVars.block.manager.remove(cacheVars.block); // this ~should~ be === cacheVars.objMgr, but just in case
				}
			}
		},
		21 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				SDS.switchBgm("Take (it outside) On Them!",true);		
			}
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Meli_shrinequake_2"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.rinda = cacheVars.objMgr.getNamedObject("Rinda");
				cacheVars.delta = -1;
				// we'll be controlling Meli here, so...
				if (cacheVars.meli){
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.rinda){
					
				}

				cacheVars.bgmName = SDS.bgmName;
				SDS.switchBgm("Earthquake",false);

				cacheVars.countdown=43;

				DATA_SHRINEQUAKE_FN(cacheVars);
			},
			controls : {},
			customPost : noop
		},
		2 : {
			customPre : noop,
			controls : {},
			customPost : DATA_SHRINEQUAKE_FN
		},
		4 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				DATA_SHRINEQUAKE_FN(cacheVars);
				cacheVars.countdown--;
				if (cacheVars.countdown>0){
					cacheVars.frameCounter=2;
				}
			}
		},
		6 : {
			customPre : noop,
			controls : {},
			customPost : DATA_SHRINEQUAKE_FN
		},
		21 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}

				SDS.switchBgm(cacheVars.bgmName,true);
			}
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Rinda_rescue"] = {
		0 : {
			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.rinda = cacheVars.objMgr.getNamedObject("Rinda");
				cacheVars.delta = -1;
				if (cacheVars.rinda){
					
				}

				DATA_SHRINEQUAKE_FN(cacheVars);
			},
			controls : {},
			customPost : noop
		},
		2 : {
			customPre : noop,
			controls : {},
			customPost : DATA_SHRINEQUAKE_FN
		},
		4 : {
			customPre : noop,
			controls : {},
			customPost : DATA_SHRINEQUAKE_FN
		},
		6 : {
			customPre : noop,
			controls : {},
			customPost : DATA_SHRINEQUAKE_FN
		},
		10 : {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					//var fred = new GO_FredNed();
					cacheVars.fred = new GO_FredNed();
					cacheVars.fred.name="Fred";
					cacheVars.fred.sprite.x = (1<<4);
					cacheVars.fred.sprite.y = (12<<4);
					cacheVars.meli.sprite.map_room.addSprite(cacheVars.fred.sprite);
					cacheVars.objMgr.add(cacheVars.fred);
					cacheVars.fred.direction=1;

					cacheVars.meli.direction=-1;
				}
				if (cacheVars.rinda){
					cacheVars.rinda.direction=-1;
				}
				

				if (DATA_SDS_DIALOGUE["Rinda_c1_trapped_16"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_trapped_16",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.previousRetval = retval;
							
							GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",17);
								
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		11 : {
			customPre : noop,
			controls : {
				"Fred":{right:true}
			},
			customPost : noop
		},
		101 : {
			customPre : noop,
			controls : {
				"Fred":{right:false}
			},
			customPost : function(cacheVars){
				cacheVars.wait=true;
				cacheVars.dlgMgr.open("Fred_c1_trapped_0",function(index,retval){
					if (retval!=null){
						cacheVars.wait=false; // yay js scoping
					}
				});
			}
		},
		102 : {
			customPre : noop,
			controls : {
				"Fred":{left:true}
			},
			customPost : noop
		},
		192 : {
			customPre : noop,
			controls : {
				"Fred":{left:false}
			},
			customPost : function(cacheVars){
				//var fred = cacheVars.objMgr.getNamedObject("Fred");
				if (cacheVars.fred){
					cacheVars.fred.sprite.map_room.removeSprite(cacheVars.fred.sprite);
					cacheVars.objMgr.remove(cacheVars.fred);
				}

				if (DATA_SDS_DIALOGUE["Rinda_c1_trapped_17"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_trapped_17",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.previousRetval = retval;
							
							GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",18);
						}
					});
				}
			}
		},
		193 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}

				GLOBAL_DIARY.note(1,"RESCUE");
				GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",0);
				GLOBAL_SCRATCHPAD.unpersist("Dlg_Rinda_Line");
			}
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Rinda_shrinequake2_setup"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				
				cacheVars.rinda = cacheVars.objMgr.getNamedObject("Rinda");
				if (cacheVars.rinda && cacheVars.meli){
					cacheVars.rinda.direction = (cacheVars.rinda.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}
				cacheVars.shrinequake=false;
				if (DATA_SDS_DIALOGUE["Rinda_c1_smoke_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_smoke_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",1);
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		1 : {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				cacheVars.triggerEvent = function(sourceGO){
					if (GLOBAL_DIARY.check(1,"SHRINEQUAKE2")) return "";

					GLOBAL_DIARY.note(1,"SHRINEQUAKE2");
					GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",0);
					GLOBAL_SCRATCHPAD.persist("Dlg_Rinda_Line");
					return "Meli_shrinequake_2";
				}

				cacheVars.trig = new GO_Trigger(2<<4,3<<4,cacheVars.triggerEvent);
				cacheVars.trig.sprite.x = (4<<4);
				cacheVars.trig.sprite.y = (11<<4);
				cacheVars.meli.sprite.map_room.addSprite(cacheVars.trig.sprite);
				cacheVars.objMgr.add(cacheVars.trig);
			}
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Rinda_catacombs_setup"] = {
		0 : {
			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.rinda = cacheVars.objMgr.getNamedObject("Rinda");
				if (cacheVars.rinda && cacheVars.meli){
					cacheVars.rinda.direction = (cacheVars.rinda.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}
				
				if (DATA_SDS_DIALOGUE["Rinda_c1_quake2_1"]){
					cacheVars.wait=true;

					cacheVars.bgmName = SDS.bgmName;
					SDS.switchBgm(null,true);

					cacheVars.dlgMgr.open("Rinda_c1_quake2_1",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",2);
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		1 : {
			customPre : function(cacheVars){
				if (cacheVars.rinda){
					cacheVars.rinda.direction = 1;
				}
			},
			controls : {
				"Rinda":{down:true}
			},
			customPost : noop
		},
		31 : {
			customPre : noop,
			controls : {
				"Rinda":{down:false, A:true}
			},
			customPost : function(cacheVars){
				SDS.switchBgm(cacheVars.bgmName,true);
			}
		},
		61 : {
			customPre : noop,
			controls : {
				"Altar":{left:true}
			},
			customPost : noop
		},
		71 : {
			customPre : noop,
			controls : {
				"Altar":{left:false}
			},
			customPost : noop
		},
		91 : {
			customPre : noop,
			controls : {
				"Altar":{left:true}
			},
			customPost : noop
		},
		111 : {
			customPre : noop,
			controls : {
				"Altar":{left:false}
			},
			customPost : noop
		},
		121 : {
			customPre : noop,
			controls : {
				"Altar":{left:true}
			},
			customPost : noop
		},
		171 : {
			customPre : noop,
			controls : {
				"Altar":{left:false}
			},
			customPost : noop
		},
		201 : {
			customPre : noop,
			controls : {
				"Rinda":{A:false}
			},
			customPost : function(cacheVars){
				if (cacheVars.rinda && cacheVars.meli){
					cacheVars.rinda.direction = (cacheVars.rinda.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}

				if (DATA_SDS_DIALOGUE["Rinda_c1_quake2_2"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_quake2_2",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",3);
						}
					});
				}
			}
		},
		202 : {
			customPre : noop,
			controls : {
				"Rinda":{A:false}
			},
			customPost : function(cacheVars){
				GLOBAL_DIARY.note(1,"CATACOMBS");
				GLOBAL_SCRATCHPAD.unpersist("Dlg_Rinda_Line");
				GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",0);

				if (cacheVars.meli && cacheVars.controls){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			}
		},
	};
	
DATA_SDS_SCRIPTED_EVENTS["Rinda_confiscate_trident"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.rinda = cacheVars.objMgr.getNamedObject("Rinda");
				if (cacheVars.rinda && cacheVars.meli){
					cacheVars.rinda.direction = (cacheVars.rinda.sprite.x>cacheVars.meli.sprite.x) ? -1 : 1;
				}
				
				if (DATA_SDS_DIALOGUE["Rinda_c1_trident"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_trident",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		},
		1 : {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Rinda_c1_takesTrident"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Rinda_c1_takesTrident",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		}
	};

DATA_SDS_SCRIPTED_EVENTS["Guy_bossfight_1"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.guy = cacheVars.objMgr.getNamedObject("BossGuy");

				if (DATA_SDS_DIALOGUE["Guy_c1_treasure_1"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Guy_c1_treasure_1",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							if (cacheVars.guy){
								cacheVars.guy.startFight();
							}

							SDS.switchBgm("Rumble",true);
						}
					});
				}
			},
			controls : {},
			customPost : noop
		}
	};
DATA_SDS_SCRIPTED_EVENTS["Guy_bossfight_2"] = {
		0 : {
			customPre : function(cacheVars){
				cacheVars.guy = cacheVars.objMgr.getNamedObject("BossGuy");

				if (DATA_SDS_DIALOGUE["Guy_c1_treasure_2"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Guy_c1_treasure_2",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							if (cacheVars.guy){
								cacheVars.guy.cleanupFight();
							}

							GLOBAL_DIARY.note(1,"BOSS");
						}
					});
				}
			},
			controls : {},
			customPost : noop
		}
	};
