<?xml version="1.0" encoding="utf-8"?>
<dungeons>
<dungeon intname="include">
	<script><![CDATA[
// Testfunction ist jetzt in allen Dungeons verfuegbar!
function Testfunction() {
	debugLog( "Dungeon include Testfunction" );
}
function unlockTeleportPoint() {

	var val = getSpecialState( "activeteleports" );
	var aktivepunkte = new Array();
	if (val != "") aktivepunkte = val.split(",");
	if (aktivepunkte.indexOf(getCurrentTrigger()) == -1) {
		aktivepunkte.push(getCurrentTrigger());
    	setSpecialState( "activeteleports", aktivepunkte.join(",") );
		debugLog("Teleport Point unlocked!");
		}
}

var rcheck = -1; //global rollCheck variable
var resid2 = -1; // greed und curiosity check

function curiosity(which, mod, residset){
	for(var j = getPartyCount()-1; j >= 0 ; j--){
		if (canAct(j)) { char = j; break; }
	}
	if (mod == null) mod = 0;
	if (getCharAttribute("NG", char) +mod <1) return;
	rcheck = rollCheck( {"which":"NG", "type":"attrib", "mod":mod, "who":char} );
	if (rcheck.ok) {
		if (residset != null) { resid2 = residset; } else { resid2 = 0; }
		repname = getName(rcheck.id);
		showDialogue( which, {"caption":"curiosity_hl","text":(repname)?getLangString("curiosity",[repname]):"curiosity"} ); 
	}
}

function greed(which, mod, residset){
	for(var j = getPartyCount()-1; j >= 0 ; j--){
		if (canAct(j)) { char = j; break; }
	}
	if (mod == null) mod = 0;
	if (getCharAttribute("GG", char) +mod <1) return;
	rcheck = rollCheck( {"which":"GG", "type":"attrib", "mod":mod, "who":char} );
	if (rcheck.ok) {
		if (residset != null) { resid2 = residset; } else { resid2 = 0; }
		repname = getName(rcheck.id);
		showDialogue( which, {"caption":"greed_hl","text":(repname)?getLangString("greed",[repname]):"greed"} ); 		
	}
}

function claustrophobia(which) {
	var part = 21;
	var location = getLocation();
//debugLog(location.x+" "+location.y+" "+location.z);
	var vorzeichen = [0,0,0];
	var position_trigger = [0,0,0];
	for (var i=0; i < 3; i++) {
		if (which.slice(part, part+1) == "m") vorzeichen[i] = -1; else vorzeichen[i] = 1;
		position_trigger[i] = vorzeichen[i]*Number(which.slice(part+1,part+5))/10;
		part += 6;
	}
//debugLog(position_trigger);
	var hr = ["n", "e", "s", "w", "a", "b"];
	var correct_direction = [0,0,0,0,0,0];
	for (var i=0; i < 6; i++) {
		if ( which.slice(part, part+1) == hr[i]) { 
			if (i == 0 || i == 2) { diff = location.z - position_trigger[1]; }
			if (i == 1 || i == 3) { diff = location.x - position_trigger[0]; }
			if ( position_trigger[2] != 9999 && (i == 4 || i == 5)) { var diff = location.y - position_trigger[2]; }
			if (i == 0 || i == 1 || i == 4) correct_direction[i] = diff; else correct_direction[i] = -diff; 
		}
		part++;
	}
	var max = 0, maxDirection = -1;
	for (var i=0; i < correct_direction.length; i++) {
		if (Math.abs(correct_direction[i]) > max) maxDirection = i;
	}
	part +=1;
	var RAbefore = Number(which.slice(part, part+2) );
	var RAafter = Number(which.slice(part+4, part+6) );
//debugLog(correct_direction+" + "+RAbefore+" + "+RAafter);	
	var oldRA = Number( getSpecialState("map.dungeon_RAthreshold"));
	var	newRA = -1;
	if (correct_direction[maxDirection] > 0) newRA = RAafter; else newRA = RAbefore;
	if ( oldRA != newRA ) {
		debugLog("New location, different claustrophobia level! Old threshold:"+oldRA+", new threshold: "+newRA)
		setSpecialState("map.dungeon_RAthreshold", newRA);
		startDialogueAt("raumangst","start");
	} 
}

]]></script>
</dungeon>
<dungeon intname="dngbloodpinnacles">
	<scene>dngbloodpinnacles</scene>
	<floor id="0">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="1" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="1" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 0 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="cantleave" x="-27.5" y="0" width="12" height="4" multi="true" />
			<!-- Fight-Trigger directly starts a fight if an accordingly named fight is defined FOR THIS LEVEL -->
			<trigger name="dfinal_18" x="18" y="14.5" width="4" height="2" />
			<!-- multi=false (or not defined) triggers EXACTLY ONCE, can be used for descriptions and the like -->
			<trigger name="entrance" x="-20.5" y="8.5" width="8" height="4" />
		</triggers>
	</floor>
	<script><![CDATA[
// Called when the Dungeon is initialized, with "initial=true" for first time entry
// and "initial=false" for loaded or returned or other time entry
function InitDungeon( initial ) {
	if( initial ){
		setSpecialState("tookGold",0);
	}
}
// Called when a trigger is entered, which is of the format "<floorid>_<triggername>", even if there is only floor 0
function OnTrigger( which ) {
	switch( which ) {
		// "none" is the callback name for OnDialogResult
		case "0_dfinal_18": showDialogue( "none", {text:which.substr(2)} ); break;
		// unlike the "autobattletrigger" handling, startBattle automatically looks into the globally defined battles as well
		case "0_toughbattle9": startBattle( "dfinal_"+which.substr(2) ); break;
		case "0_endbattle": if( getQuestState("schick_hyggelik") < 3 ) startBattle( "dfinal_endbattle" ); break;
		case "0_cantleave": checkCantLeave(); break;
	
		// unhandled triggers should return false
		default: return false;
	}
	return true;
}
// custom defined function, can be removed
function checkCantLeave() {
	if( getSpecialState( "tookGold" ) == 1 ) {
		moveToTrigger( "0_entrance", 0 );
		showDialogue( "none", {"text":"dfinal_6"} );
	}
}

function OnTriggerLeft( which ) {}
function OnPassTime( which ) {}
function OnDialogResult( which, resid ) {
	switch( which ) {
		case "0_2": if( resid == 0 ) { showDialogue( "none", {"text":getLangString( "dfinal_36", [getName( rollRandom(0,getPartyCount()))] )} ); } break;
		case "dfinal_50": showDialogue( "dfinal_51", {"text":"dfinal_51"} ); break;
		case "dfinal_51": showItemset( "dfinal_51" ); break;
		case "dfinal_53": 
		case "dfinal_54": 
			if( resid == 0 ) {
				if( getSpecialState( "tookGold" ) != "1" )
					autoSave();
				changeWealth( (which=="dfinal_53")?800:500000 );
				setSpecialState( "tookGold", "1" );
			} else {
				var res = rollCheck( {"which":"GG","who":"best","type":"attrib"} );
				showDialogue( "none", {"text":getLangString("dfinal_55",[res.name,getLangString("text_3rdperson_"+(getGender( res.id )),[])])});
			}
			break;
	}
}

// whenever a door is clicked, "which" as always <floorid>_<doorid>. Should return true if the doorclick was handled
function doorClicked( which ) { return false; }
// whenever a chest is clicked, "which" as always <floorid>_<chestid>. Should return true if the chestclick was handled
function chestClicked( which ) { return false; }
// whenever a chest is opened, "which" as always <floorid>_<chestid>. Should return true if the opening was handled
function chestOpened( which ) {
	switch( which ) {
		case "0_1": showDialogue( "none", {'text':'dfinal_34'} ); return true;
		case "0_2": showDialogue( "0_2", {'text':'dfinal_35','btcap1':'text_yes','btcap2':'text_no'} ); return true;
		case "0_4": showDialogue( "none", {'text':'dfinal_37'} ); return true;
	}
	return false;
}
]]></script>
	<!-- Contents of Itemsets here are stored and handled via Savegame whenever they are modified after first entry -->
	<itemsets>
		<!-- Custom set, e.g. "something lying on the floor" -->
		<itemset id="dfinal_51">
			<item id="pickaxe" />
		</itemset>
		<!-- Chest-Set automatically assiged to Chest ID 3 on Floor 0 -->
		<itemset id="chest_0_3">
			<item id="potion_healing" count="5" />
			<item id="potion_stronghealing" count="2" />
			<item id="potion_magic" count="5" />
			<item id="potion_magicstrong" count="2" />
		</itemset>
	</itemsets>
	<exit>
		<!-- 
can either be fixed coordinates like this:
[code]
	<coords>
	  <x>-19</x>
	  <y>21.8</y>
	  <z>35.5</z>
	</coords>
	<dungeon>prem</dungeon>
	<rotation>270</rotation>
[/code]
	or a script like below, executed when "leaving the dungeon". 
	Script can be "continueJourney();" if before entry of the dungeon "saveJourney()" was called -->
		<script>
		setJourneyState( {"route":"hyg1-hyg2","pos":0.64,"pause":true,"dir":false} );
	</script>
		<dungeon>script</dungeon>
	</exit>
</dungeon>
<dungeon intname="dngempty">
	<floor id="0">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="1" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="1" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 0 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="cantleave" x="-27.5" y="0" width="12" height="4" multi="true" />
			<!-- Fight-Trigger directly starts a fight if an accordingly named fight is defined FOR THIS LEVEL -->
			<trigger name="dfinal_18" x="18" y="14.5" width="4" height="2" />
			<!-- multi=false (or not defined) triggers EXACTLY ONCE, can be used for descriptions and the like -->
			<trigger name="entrance" x="-20.5" y="8.5" width="8" height="4" />
		</triggers>
	</floor>
	<script><![CDATA[
// Called when the Dungeon is initialized, with "initial=true" for first time entry
// and "initial=false" for loaded or returned or other time entry
function InitDungeon( initial ) {
	if( initial ){
		setSpecialState("tookGold",0);
	}
}
// Called when a trigger is entered, which is of the format "<floorid>_<triggername>", even if there is only floor 0
function OnTrigger( which ) {
	switch( which ) {
		// "none" is the callback name for OnDialogResult
		case "0_dfinal_18": showDialogue( "none", {text:which.substr(2)} ); break;
		// unlike the "autobattletrigger" handling, startBattle automatically looks into the globally defined battles as well
		case "0_toughbattle9": startBattle( "dfinal_"+which.substr(2) ); break;
		case "0_endbattle": if( getQuestState("schick_hyggelik") < 3 ) startBattle( "dfinal_endbattle" ); break;
		case "0_cantleave": checkCantLeave(); break;
	
		// unhandled triggers should return false
		default: return false;
	}
	return true;
}
// custom defined function, can be removed
function checkCantLeave() {
	if( getSpecialState( "tookGold" ) == 1 ) {
		moveToTrigger( "0_entrance", 0 );
		showDialogue( "none", {"text":"dfinal_6"} );
	}
}

function OnTriggerLeft( which ) {}
function OnPassTime( which ) {}
function OnDialogResult( which, resid ) {
	switch( which ) {
		case "0_2": if( resid == 0 ) { showDialogue( "none", {"text":getLangString( "dfinal_36", [getName( rollRandom(0,getPartyCount()))] )} ); } break;
		case "dfinal_50": showDialogue( "dfinal_51", {"text":"dfinal_51"} ); break;
		case "dfinal_51": showItemset( "dfinal_51" ); break;
		case "dfinal_53": 
		case "dfinal_54": 
			if( resid == 0 ) {
				if( getSpecialState( "tookGold" ) != "1" )
					autoSave();
				changeWealth( (which=="dfinal_53")?800:500000 );
				setSpecialState( "tookGold", "1" );
			} else {
				var res = rollCheck( {"which":"GG","who":"best","type":"attrib"} );
				showDialogue( "none", {"text":getLangString("dfinal_55",[res.name,getLangString("text_3rdperson_"+(getGender( res.id )),[])])});
			}
			break;
	}
}

// whenever a door is clicked, "which" as always <floorid>_<doorid>. Should return true if the doorclick was handled
function doorClicked( which ) { return false; }
// whenever a chest is clicked, "which" as always <floorid>_<chestid>. Should return true if the chestclick was handled
function chestClicked( which ) { return false; }
// whenever a chest is opened, "which" as always <floorid>_<chestid>. Should return true if the opening was handled
function chestOpened( which ) {
	switch( which ) {
		case "0_1": showDialogue( "none", {'text':'dfinal_34'} ); return true;
		case "0_2": showDialogue( "0_2", {'text':'dfinal_35','btcap1':'text_yes','btcap2':'text_no'} ); return true;
		case "0_4": showDialogue( "none", {'text':'dfinal_37'} ); return true;
	}
	return false;
}
]]></script>
	<!-- Contents of Itemsets here are stored and handled via Savegame whenever they are modified after first entry -->
	<itemsets>
		<!-- Custom set, e.g. "something lying on the floor" -->
		<itemset id="dfinal_51">
			<item id="pickaxe" />
		</itemset>
		<!-- Chest-Set automatically assiged to Chest ID 3 on Floor 0 -->
		<itemset id="chest_0_3">
			<item id="potion_healing" count="5" />
			<item id="potion_stronghealing" count="2" />
			<item id="potion_magic" count="5" />
			<item id="potion_magicstrong" count="2" />
		</itemset>
	</itemsets>
	<exit>
		<!-- 
can either be fixed coordinates like this:
[code]
	<coords>
	  <x>-19</x>
	  <y>21.8</y>
	  <z>35.5</z>
	</coords>
	<dungeon>prem</dungeon>
	<rotation>270</rotation>
[/code]
	or a script like below, executed when "leaving the dungeon". 
	Script can be "continueJourney();" if before entry of the dungeon "saveJourney()" was called -->
		<script>
		setJourneyState( {"route":"hyg1-hyg2","pos":0.64,"pause":true,"dir":false} );
	</script>
		<dungeon>script</dungeon>
	</exit>
</dungeon>
<dungeon intname="dngfkbinge">
	<scene>dngfkbinge</scene>
	<floor id="0">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="1" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="2" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="3" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="0" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="1" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="2" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="3" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="4" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="5" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="6" type="chest" state="locked" lockpickmod="6" foramenmod="3" />

		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 0 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="Skeleton" x="110" y="1" z="-30" width="3" height="4" multi="true" />
			<trigger name="Binge1Tools1" x="124" y="0" z="-18" width="3" height="4" multi="true" />
			<trigger name="Binge1Tools2" x="115" y="-4" z="-55" width="3" height="4" multi="true" />
			<trigger name="Binge1Chimney" x="89" y="1" z="-4" width="4" height="4" multi="true" />
			<trigger name="BingeAltar" x="121" y="-2" z="-46" width="6" height="4" multi="true" />
			<trigger name="BingeAnvil" x="128" y="-2" z="-84" width="4" height="4" multi="true" />
			<trigger name="MainPortalIn" x="114" y="0" z="-7.5" width="4" height="4" multi="true" />
			<trigger name="MainPortalOut" x="114" y="0" z="-11.5" width="4" height="4" multi="true" />
			<trigger name="Binge_relief" x="115" y="-2" z="-85" width="3" height="4" multi="true" />
			<trigger name="FootTrap" x="80" y="6" z="-70" width="5" height="4" multi="true" />
			<trigger name="coal_basin1" x="117.9" y="0" z="-0.7" width="2" height="2" multi="true" />
			<trigger name="coal_basin2" x="117.9" y="0" z="3.2" width="2" height="2" multi="true" />
			<trigger name="coal_basin3" x="112" y="0" z="3.2" width="2" height="2" multi="true" />
			<trigger name="coal_basin4" x="112" y="0" z="-0.7" width="2" height="2" multi="true" />
			<trigger name="coal_basin5" x="78" y="1" z="-8" width="2" height="2" multi="true" />
			<trigger name="coal_basin6" x="78" y="1" z="-26" width="2" height="2" multi="true" />
			<trigger name="coal_basin7" x="78.4" y="-3" z="-49.2" width="2" height="2" multi="true" />
			<trigger name="coal_basin8" x="75" y="-3" z="-41.7" width="2" height="2" multi="true" />
			<trigger name="coal_basin9" x="71" y="-3" z="-49.2" width="2" height="2" multi="true" />
			<trigger name="coal_basin10" x="67.6" y="6" z="-74.6" width="2" height="2" multi="true" />
			<trigger name="coal_basin11" x="67.6" y="6" z="-63.8" width="2" height="2" multi="true" />
			<trigger name="coal_basin12" x="100" y="6" z="-74.6" width="2" height="2" multi="true" />
			<trigger name="coal_basin13" x="110.7" y="-4" z="-45" width="2" height="2" multi="true" />
			<trigger name="coal_basin14" x="106.8" y="-4" z="-84" width="2" height="2" multi="true" />
			<trigger name="coal_basin15" x="135.4" y="-4" z="-84" width="2" height="2" multi="true" />
			<trigger name="coal_basin16" x="131.3" y="-4" z="-45" width="2" height="2" multi="true" />
			<trigger name="coal_basin17" x="100" y="6" z="-63.8" width="2" height="2" multi="true" />
			<trigger name="coal2_basin" x="140" y="-3" z="-8" width="2" height="2" multi="true" />
			<trigger name="Ingerimm_statue" x="141" y="-3" z="-23" width="3" height="3" multi="true" />
			<trigger name="Binge2GnomeTeleport2" x="135" y="-3" z="-16" width="4" height="4" multi="true" />
			<trigger name="Binge2GnomeTeleport3" x="100" y="1" z="-16" width="4" height="4" multi="true" />
			<trigger name="Quarters" x="80" y="1" z="-16" width="8" height="8" multi="true" />
			<trigger name="Entrance" x="116" y="0" z="-21" width="12" height="12" multi="true" />
			<trigger name="Shrine" x="140" y="-2" z="-16" width="8" height="8" multi="true" />
			<trigger name="GreatHall" x="123" y="-3" z="-65" width="8" height="8" multi="true" />
			<trigger name="DiningRoom" x="78" y="6" z="-70" width="8" height="8" multi="true" />

		</triggers>
	</floor>
	<floor id="1">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="3" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="4" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="7" state="open" />
			<tile cdoorid="6" state="locked" />
			<tile cdoorid="8" state="locked" />
			<tile cdoorid="2020" state="open"/>
			<tile cdoorid="2021" state="open"/>
			<tile cdoorid="2022" state="open"/>
			<tile cdoorid="2023" state="open"/>
			<tile cdoorid="2024" state="open"/>
			<tile cdoorid="2025" state="open"/>
			<tile cdoorid="2026" state="locked"/>
			<tile cdoorid="2027" state="locked"/>
			<tile cdoorid="2028" state="locked"/>
			<tile cdoorid="2029" state="open"/>
			<tile cdoorid="2030" state="open"/>
			<tile cdoorid="2031" state="open"/>
			<tile cdoorid="2034" state="locked"/>

			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="7" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="8" type="chest" state="locked" lockpickmod="8" foramenmod="6" />
			<tile chestid="9" type="chest" state="locked" lockpickmod="8" foramenmod="6" />
			<tile chestid="10" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="11" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="12" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 1 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="Binge2Chimney" x="-43" y="-3" z="125" width="3" height="3" multi="true" />
			<trigger name="Binge2Hole1" x="-47" y="-3" z="115.5" width="2" height="2" multi="true" />
			<trigger name="Binge2Hole2" x="-32" y="-3" z="99" width="2" height="2" multi="true" />
			<trigger name="Binge2Plate" x="-44" y="0" z="78" width="1" height="1" multi="true" />
			<trigger name="Binge2Lever" x="-35" y="0" z="76" width="2" height="2" multi="true" />
			<trigger name="Binge2Trap1" x="-29" y="-10" z="36" width="1" height="6" multi="true" />
			<trigger name="Binge2Trap2" x="-16" y="-10" z="36" width="1" height="6" multi="true" />
			<trigger name="Binge2Trap3" x="-1" y="-10" z="36" width="1" height="6" multi="true" />
			<trigger name="Binge2ClosingDoor" x="37" y="-14" z="73" width="5" height="5" multi="false" />
			<trigger name="Binge2RoomTrap" x="35" y="-13" z="77.5" width="13" height="16" multi="true" />
			<trigger name="Binge2GnomePlate" x="17" y="-14" z="123" width="2" height="2" multi="false" />
			<trigger name="Binge2GnomeWardrobe" x="15" y="-14" z="124" width="2" height="2" multi="false" />
			<trigger name="Binge2GnomeTeleport" x="37" y="-14" z="63" width="4" height="4" multi="true" />
			<trigger name="Binge2Crank" x="35" y="-14" z="78" width="4" height="4" multi="true" />
			<trigger name="Binge2CrankTeleport" x="27" y="-14" z="82" width="4" height="4" multi="true" />
			<trigger name="Binge2LeverTrap" x="-4" y="-2" z="105" width="1.5" height="1.5" multi="true" />
			<trigger name="Binge2RampEnd" x="8" y="-10" z="108" width="4" height="4" multi="true" />
			<trigger name="Binge2Ramp" x="5" y="-7" z="102" width="6" height="4" multi="true" />
			<trigger name="Binge2GnomeTeleport0" x="-4" y="-1" z="125" width="4" height="4" multi="true" />
			<trigger name="Binge2GnomeTeleport1" x="25" y="-3" z="59" width="4" height="4" multi="true" />
			<trigger name="Entrance" x="-56" y="-2" z="57" width="8" height="8" multi="true" />
			<trigger name="Waterfall" x="23" y="-9" z="42" width="8" height="8" multi="true" />
			<trigger name="StorageRoom" x="-50" y="-2" z="101" width="8" height="8" multi="true" />
			<trigger name="CommonRoom" x="-32" y="-2" z="110" width="8" height="8" multi="true" />
			<trigger name="Binge2Water" x="27" y="-16" z="58" width="55" height="35" multi="true" />
			<trigger name="Binge2Water2" x="26" y="-20" z="96" width="55" height="35" multi="true" />
			<trigger name="Binge2WaterBack" x="28" y="-9" z="43" width="3" height="3" multi="true" />

		</triggers>
	</floor>
	<floor id="2">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="9" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="10" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="11" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="12" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="13" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="14" state="locked" />
			<tile cdoorid="15" state="locked" />

			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="16" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="17" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="18" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="19" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="20" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 2 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="Binge3Chimney" x="-54" y="7.5" z="-103" width="3" height="3" multi="true" />
			<trigger name="Binge2GnomeTeleport4" x="24" y="13" z="-149" width="4" height="4" multi="true" />
			<trigger name="Binge2GnomeTeleport5" x="-20" y="10" z="-127" width="4" height="4" multi="true" />
			<trigger name="Binge3Latrine" x="-23" y="7" z="-138" width="4" height="4" multi="false" />
			<trigger name="Binge3Buffer" x="24" y="13" z="-155" width="4" height="4" multi="false" />
			<trigger name="Binge3Mound" x="20" y="23" z="-186" width="4" height="4" multi="true" />
			<trigger name="Binge3Tools" x="33" y="18" z="-192" width="4" height="4" multi="true" />
			<trigger name="Binge3Lorry" x="14.7" y="13" z="-154.6" width="3.5" height="1.5" multi="true" />
			<trigger name="Binge3Lorry1" x="12" y="11.5" z="-154.6" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Lorry2" x="8" y="11.5" z="-154.6" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Lorry3" x="3" y="11.5" z="-154.6" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Lorry4" x="-3" y="11.5" z="-154.6" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Lorry5" x="-11" y="11.5" z="-154.6" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Lorry6" x="-19" y="11.5" z="-154.55" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Lorry7" x="-28" y="11.5" z="-153.65" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Lorry8" x="-38" y="11.5" z="-152.2" width="0.5" height="0.5" multi="true" />
			<trigger name="Binge3Buffer2" x="-42" y="14" z="-152" width="4" height="4" multi="true" />
			<trigger name="Binge3Skid" x="-22.7" y="20" z="-162.4" width="2" height="2" multi="true" />
			<trigger name="Binge3Skid1" x="-13" y="13" z="-158" width="4" height="4" multi="true" />
			<trigger name="Binge3Forge" x="30" y="18" z="-194" width="3" height="3" multi="true" />
			<trigger name="Binge3JumpA" x="10" y="18" z="-174" width="2" height="4" multi="true" />
			<trigger name="Binge3JumpB" x="2" y="18" z="-174" width="2" height="4" multi="true" />
			<trigger name="Binge3Skeleton" x="30" y="10" z="-120" width="12" height="20" multi="true" />
			<trigger name="Binge3PartCrashed01" x="-21" y="2" z="-126" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed02" x="-12" y="1" z="-127" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed03" x="-43" y="7" z="-117" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed04" x="-49" y="7" z="-134" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed05" x="-55" y="7" z="-131" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed06" x="-33" y="7" z="-104" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed07" x="-3" y="10" z="-105" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed08" x="-1" y="10" z="-113" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed09" x="-3" y="10" z="-125" width="4" height="4" multi="true" />
			<trigger name="Binge3PartCrashed10" x="8" y="10" z="-119" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed01" x="-17" y="1" z="-126" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed02" x="-54" y="7" z="-120" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed03" x="-49" y="7" z="-116" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed04" x="-46" y="7" z="-120" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed05" x="-46" y="7" z="-122" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed06" x="-46" y="7" z="-128" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed07" x="-46" y="7" z="-134" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed08" x="-28" y="8" z="-104" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed09" x="-19" y="9" z="-104" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed10" x="-13" y="10" z="-104" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed11" x="-2" y="10" z="-108" width="4" height="4" multi="true" />
			<trigger name="Binge3FullCrashed12" x="0" y="10" z="-118" width="4" height="4" multi="true" />
			<trigger name="Binge3TotaCrashed01" x="-55" y="7" z="-127" width="4" height="4" multi="true" />
			<trigger name="Binge3TotaCrashed02" x="-54" y="7" z="-123" width="4" height="4" multi="true" />
			<trigger name="Binge3Crashing" x="-8" y="10" z="-126" width="4" height="4" multi="true" />
			<trigger name="Binge3Altar" x="-20" y="20" z="-175" width="3" height="3" multi="true" />
			<trigger name="Binge3Tomb01" x="-28.4" y="20" z="-171.8" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb02" x="-28.4" y="20" z="-177.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb03" x="-28.4" y="20" z="-179.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb04" x="-28.4" y="20" z="-181.3" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb05" x="-25.6" y="20" z="-171.8" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb06" x="-25.3" y="20" z="-177.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb07" x="-25.3" y="20" z="-179.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb08" x="-25.3" y="20" z="-181.3" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb09" x="-22.5" y="20" z="-171.8" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb10" x="-22" y="20" z="-177.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb11" x="-22" y="20" z="-179.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb12" x="-22" y="20" z="-181.3" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb13" x="-19" y="20" z="-177.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb14" x="-19" y="20" z="-179.5" width="1" height="1" multi="true" />
			<trigger name="Binge3Tomb15" x="-19" y="20" z="-181.3" width="1" height="1" multi="true" />
			<trigger name="Binge3JumpLever" x="-1" y="18" z="-168" width="4" height="4" multi="true" />
			<trigger name="Binge3Bar" x="31" y="18" z="-172" width="4" height="4" multi="true" />
			<trigger name="Binge3SkidTeleport" x="-15" y="18" z="-166" width="4" height="4" multi="true" />
			<trigger name="Binge3Graveyard" x="-32" y="20" z="-175" width="4" height="4" multi="true" />
			<trigger name="Binge3DiningRoom" x="-3" y="20" z="-189" width="4" height="4" multi="true" />
			<trigger name="Binge3MainHallTop" x="-20" y="13" z="-156" width="4" height="4" multi="true" />
			<trigger name="Binge3Entrance" x="6" y="7" z="-159" width="8" height="8" multi="true" />
			<trigger name="Binge3Key" x="-54" y="7" z="-134" width="3" height="3" multi="true" />
		</triggers>
	</floor>
	<floor id="3">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="28" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="21" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 3 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="Binge4Chimney" x="-116" y="11" z="125" width="4" height="4" multi="true" />
			<trigger name="Binge4Undead" x="-100" y="11" z="114" width="4" height="4" multi="true" />
			<trigger name="Binge4Hole1" x="-95" y="11" z="123" width="2" height="2" multi="true" />
			<trigger name="Binge4Hole2" x="-130" y="6" z="52" width="2" height="2" multi="true" />
			<trigger name="Binge4Wheel" x="-94" y="11" z="111" width="1" height="2" multi="true" />
			<trigger name="Binge4FireHole" x="-120" y="9" z="116" width="2" height="6" multi="true" />
			<trigger name="Binge4FireHoleExit" x="-108" y="11" z="104" width="4" height="4" multi="true" />
			<trigger name="Binge4Gargoyles" x="-109" y="70" width="21" height="19" multi="true" />
			<trigger name="Binge4Water" x="-109" y="6" z="71" width="4" height="4" multi="true" />
			<trigger name="Binge4FireSponge" x="-98" y="11" z="107" width="3" height="1" multi="true" />
			<trigger name="Binge4EfferdSponge" x="-94" y="11" z="107" width="3" height="1" multi="true" />
			<trigger name="Binge4BothSponges" x="-96" y="11" z="107" width="1" height="1" multi="false" />
			<trigger name="Binge4Smokeroom" x="-92" y="11" z="114" width="21" height="21" multi="true" />
			<trigger name="Binge4WheelRoom" x="-97" y="11" z="112" width="6" height="6" multi="true" />
			<trigger name="Binge4FountainRoom" x="-109" y="6" z="51" width="17" height="17" multi="true" />
			<trigger name="Binge4Entrance" x="-123" y="6" z="36" width="4" height="4" multi="true" />
		</triggers>
	</floor>
	<floor id="4">
		<triggers>
			<!-- Floor 4 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="Binge5Water1" x="-111.5" y="4" z="-80" width="4" height="4" multi="true" />
			<trigger name="Binge5Water2" x="-112" y="4" z="0" width="4" height="4" multi="true" />
			<trigger name="Binge5Water1Back" x="-116" y="4.5" z="-80" width="4" height="4" multi="true" />
			<trigger name="Binge5Water2Back" x="-116" y="4.5" z="0" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving1" x="-111" y="2" z="-4" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving2" x="-111" y="2" z="-14" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving3" x="-111" y="2" z="-19" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving4" x="-111" y="2" z="-29" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving5" x="-111" y="2" z="-39" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving6" x="-111" y="2" z="-45" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving7" x="-111" y="2" z="-51" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving8" x="-111" y="2" z="-60" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving9" x="-111" y="2" z="-68" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving10" x="-111" y="2" z="-74" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving11" x="-101" y="2" z="-4" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving12" x="-101" y="2" z="-14" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving13" x="-101" y="2" z="-19" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving14" x="-101" y="2" z="-29" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving15" x="-101" y="2" z="-39" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving16" x="-101" y="2" z="-45" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving17" x="-101" y="2" z="-51" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving18" x="-101" y="2" z="-60" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving19" x="-101" y="2" z="-68" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving20" x="-101" y="2" z="-78" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving21" x="-91" y="2" z="-4" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving22" x="-91" y="2" z="-14" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving23" x="-91" y="2" z="-19" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving24" x="-91" y="2" z="-29" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving25" x="-91" y="2" z="-39" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving26" x="-91" y="2" z="-45" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving27" x="-91" y="2" z="-51" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving28" x="-91" y="2" z="-60" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving29" x="-91" y="2" z="-68" width="4" height="4" multi="true" />
			<trigger name="Binge5Diving30" x="-91" y="2" z="-78" width="4" height="4" multi="true" />
			<trigger name="Binge5Entrance" x="-118" y="5" z="-86" width="8" height="8" multi="true" />
			<trigger name="Binge5Plate" x="-102.5" y="-1" z="-18" width="8" height="8" multi="true" />
		</triggers>
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="4011" state="locked"  />
			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="22" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="23" type="chest" state="locked" lockpickmod="6" foramenmod="3" />

		</tiles>
	</floor>
	<floor id="5">
		<triggers>
			<!-- Floor 5 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="Binge6Chimney" x="-56" y="5" z="5" width="4" height="4" multi="true" />
			<trigger name="Binge6Exit" x="-62" y="0" z="-4" width="4" height="4" multi="true" />
			<trigger name="Binge6Wall" x="-11" y="10" z="5" width="4" height="4" multi="false" />	
			<trigger name="Binge6Lootbox" x="-17" y="10" z="-11" width="2" height="2" multi="true" />
			<trigger name="Binge6Hole" x="30" y="0.5" z="-42" width="2" height="2" multi="true" />
			<trigger name="Binge6Golem" x="-29" y="0" z="-56.5" width="24" height="24" multi="true" />
﻿			<trigger name="Binge6FirePlate1" x="15" y="-0.2" z="-42" width="3" height="16" multi="true" />	
			<trigger name="Binge6FirePlate2" x="12" y="-0.2" z="-42" width="3" height="16" multi="true" />	
			<trigger name="Binge6FirePlate3" x="9" y="-0.2" z="-42" width="3" height="16" multi="true" />	
			<trigger name="Binge6FirePlate4" x="6" y="-0.2" z="-42" width="3" height="16" multi="true" />	
			<trigger name="Binge6FirePlate5" x="3" y="-0.2" z="-42" width="3" height="16" multi="true" />	
			<trigger name="Binge6FirePlate6" x="0" y="-0.2" z="-42" width="3" height="16" multi="true" />	
			<trigger name="Binge6Back1FirePlate" x="18" y="0" z="-42" width="4" height="4" multi="true" />	
			<trigger name="Binge6Back2FirePlate" x="-4" y="0" z="-42" width="4" height="4" multi="true" />
			<trigger name="Binge6Entrance" x="22" y="10" z="4" width="4" height="4" multi="true" />
			<trigger name="Binge6GolemRoom" x="-12" y="1" z="-42" width="4" height="4" multi="true" />
			<trigger name="Binge6CommonRoom" x="-4" y="10" z="-6" width="4" height="4" multi="true" />
			<trigger name="Binge6WaterRoom" x="1" y="1" z="-26" width="4" height="4" multi="true" />
			<trigger name="Binge6FireHall" x="22" y="0" z="-42" width="4" height="4" multi="true" />
			<trigger name="Binge6Lever" x="6" y="10" z="-8" width="2" height="2" multi="true" />
			<trigger name="Binge6Water" x="-4" y="0" z="-23" width="12" height="4" multi="true" />
			<trigger name="Binge6Secretdoor" x="-6" y="0" z="-42" width="4" height="4" multi="true" />
		</triggers>
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="30" state="locked" lockpickmod="4" foramenmod="7" runindifficulty="4" />	
			<tile cdoorid="31" state="locked" lockpickmod="4" foramenmod="7" runindifficulty="4" />	
			<tile cdoorid="25" state="locked" />	
			<tile cdoorid="26" state="locked" />	
			<tile cdoorid="27" state="locked" />	
			<tile cdoorid="28" state="locked" />	
			<tile cdoorid="29" state="locked" />	
			<tile cdoorid="42" state="locked" />		
			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="24" type="chest" state="locked" lockpickmod="9" foramenmod="9" />
			<tile chestid="25" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="26" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
			<tile chestid="27" type="chest" state="closed" />
			<tile chestid="28" type="chest" state="closed" />
			<tile chestid="29" type="chest" state="closed" />
			<tile chestid="30" type="chest" state="closed" />
		</tiles>
	</floor>
	<script><![CDATA[
// Called when the Dungeon is initialized, with "initial=true" for first time entry
// and "initial=false" for loaded or returned or other time entry
function InitDungeon( initial ) {
	if( initial ){
	}
	setSpecialState("map.dungeon_RAthreshold",3);
	startDialogueAt("raumangst","start");
	setSpecialState("map.raumangstaktiv",1);
	}

// Called when a trigger is entered, which is of the format "<floorid>_<triggername>", even if there is only floor 0
function OnTrigger( which ) {
	var TriggerFloor = which.substr( 0, 1 );
	switch( TriggerFloor ) {
		case "0": return Floor0(which);
		case "1": return Floor1(which);
		case "2": return Floor2(which);
		case "3": return Floor3(which);
		case "4": return Floor4(which);
		case "5": return Floor5(which);
	}
}

function Floor0(which){
	if (which.substr( 2, 10 ) == "coal_basin") {startDialogue( "coal_basin"); return true;}
	switch( which ) {
		case "0_Skeleton": startDialogue( "Binge_Skeleton"); break;
		case "0_Ingerimm_statue": startDialogue( "Ingerimm_statue"); break;
		case "0_coal2_basin": startDialogue( "coal_basin2"); break;
		case "0_Binge_relief": startDialogue( "Binge_relief"); break;
		case "0_MainPortalIn": setSpecialState( "MainPortalIn",1);setSpecialState( "MainPortalOut",0) ; break;
		case "0_MainPortalOut": setSpecialState( "MainPortalIn",0);setSpecialState( "MainPortalOut",1) ; break;
		case "0_FootTrap": startDialogue( "BingeFootTrap"); break;
		case "0_Binge1Tools1":	var spstate = getGeneralState("Binge1Tools1");	if( spstate.val != 1 ) setGeneralState("Binge1Tools1",{"doublelist":["torch",3,"lockpick",1,"tinderbox",1,"pickaxe",1],"val":1}); spstate = getGeneralState("Binge1Tools1"); if(typeof(spstate.items)!="object") break; showDialogue("Binge1Tools1",{"caption":"Binge3Tools_hl","text":"binge2_85","btcap1":"text_yes","btcap2":"text_no"});break;
		case "0_Binge1Tools2": var spstate = getGeneralState("Binge1Tools2");	if( spstate.val != 1 ) setGeneralState("Binge1Tools2",{"doublelist":["st_chain",1,"rope",1,"crowbar",1,"shovel",2, "hammer",1],"val":1}); spstate = getGeneralState("Binge1Tools2"); if(typeof(spstate.items)!="object") break;showDialogue("Binge1Tools2",{"caption":"Binge3Tools_hl","text":"binge2_86","btcap1":"text_yes","btcap2":"text_no"});break;
		case "0_Binge1Chimney": startDialogue( "Binge1Chimney"); break;
		case "0_BingeAltar": startDialogue( "BingeAltar"); break;
		case "0_BingeAnvil": startDialogue( "BingeAnvil"); break;
		case "0_Quarters": unlockTeleportPoint(); break;
		case "0_Entrance": unlockTeleportPoint(); break;
		case "0_Shrine": unlockTeleportPoint(); break;
		case "0_GreatHall": unlockTeleportPoint(); break;
		case "0_DiningRoom": unlockTeleportPoint(); break;

		// unhandled triggers should return false
		default: return false;
	}
	return true;
}
function Floor1(which){
	switch( which ) {
		case "1_Binge2Chimney": startDialogue( "Binge2Chimney"); break;
		case "1_Binge2Hole1": setSpecialState("BingeHoleLevel", 2);startDialogue( "Binge2Hole1"); break;
		case "1_Binge2Hole2": setSpecialState("BingeHoleLevel", 2);startDialogue( "Binge2Hole2"); break;
		case "1_Binge2Plate": startDialogue( "Binge2Plate"); break;
		case "1_Binge2Lever": startDialogue( "Binge2Lever"); break;
		case "1_Binge2Trap1": startDialogue( "Binge2Trap1"); break;
		case "1_Binge2Trap2": startDialogue( "Binge2Trap2"); break;
		case "1_Binge2Trap3": startDialogue( "Binge2Trap3"); break;
		case "1_Binge2GnomeTeleport": if(getSpecialState("Binge2GnomeAutosave") != 1) {setSpecialState("Binge2GnomeAutosave",1); autoSave();} break;
		case "1_Binge2ClosingDoor": startDialogue( "Binge2ClosingDoor"); break;
		case "1_Binge2GnomePlate": startDialogue( "Binge2GnomePlate"); break;
		case "1_Binge2GnomeWardrobe": startDialogue( "Binge2GnomeWardrobe"); break;
		case "1_Binge2Crank": startDialogue( "Binge2Crank"); break;
		case "1_Binge2LeverTrap": startDialogue( "Binge2LeverTrap"); break;
		case "1_Binge2Ramp": startDialogue( "Binge2Ramp"); break;
		case "1_Entrance": unlockTeleportPoint(); break;
		case "1_Waterfall": unlockTeleportPoint(); break;
		case "1_StorageRoom": unlockTeleportPoint(); break;
		case "1_CommonRoom": unlockTeleportPoint(); break;
		case "1_Binge2Water": showDialogue( "none", {"caption":"BingeWater_hl","text":"binge3_62"} ); moveToTrigger("1_Binge2WaterBack"); break;
		case "1_Binge2Water2": showDialogue( "none", {"caption":"BingeWater_hl","text":"binge3_62"} ); moveToTrigger("1_Binge2CrankTeleport"); break;

		// unhandled triggers should return false
		default: return false;
	}
	return true;
}
function Floor2(which){
	if (which.substr( 2, 17 ) == "Binge3PartCrashed") {askPartCrashed( which.substr( 19, 2 ), false ); return true;}
	if (which.substr( 2, 17 ) == "Binge3FullCrashed") {askFullCrashed( which.substr( 19, 2 ), false ); return true;}
	if (which.substr( 2, 17 ) == "Binge3TotaCrashed") {askTotaCrashed( which.substr( 19, 2 ), false ); return true;}
	if (which.substr( 2, 10 ) == "Binge3Tomb") {askTomb( which.substr( 12, 2 ) ); return true;}
	switch( which ) {
		case "2_Binge3Chimney": startDialogue( "Binge3Chimney"); break;
		case "2_Binge3Latrine": startDialogue( "Binge3Latrine"); break;
		case "2_Binge3Buffer": showDialogue( "none", {"text":"binge4_5"} ); break;
		case "2_Binge3Mound": startDialogue( "Binge3Mound"); break;
		case "2_Binge3Tools": startDialogue( "Binge3Tools"); break;
		case "2_Binge3Buffer2": if (getSpecialState("binge2_Binge3Lorry_go") =="") startDialogue( "Binge3Buffer2"); break;
		case "2_Binge3Lorry": if (getSpecialState("binge2_Binge3Lorry_go") =="") startDialogue( "Binge3Lorry"); break;			
		case "2_Binge3Skid": if (canAct(0)) startDialogue( "Binge3Skid"); break;	
		case "2_Binge3Forge": startDialogue( "Binge3Forge"); break;
		case "2_Binge3JumpA": setSpecialState("Binge3Jump","A");startDialogue( "Binge3Jump"); break;
		case "2_Binge3JumpB": setSpecialState("Binge3Jump","B");startDialogue( "Binge3Jump"); break;	
		case "2_Binge3Skeleton": if (getSpecialState("Binge3Skeleton") ==0) startBattle("Binge3Skeleton"); break;	
		case "2_Binge3Crashing": if (getSpecialState("Binge3Crashed") != 1) {var hintchar = getBest({"which":"sinnensch","type":"skill"}); hintchar = hintchar.charid;showDialogue("Binge3Crashing",{"caption":"Binge3Crashing_hl","text":getLangString("binge4_68",[getName(hintchar)])});}break;
		case "2_Binge3Altar": showDialogue("Binge3Altar",{"caption":"BingeAltar_hl","text":"binge4_55","btcap1":"text_yes","btcap2":"text_no"}); break;
		case "2_Binge3JumpLever": if (getSpecialState("Binge3JumpLever")!=1) {showDialogue("Binge3JumpLever",{"caption":"BingeLever_hl","text":"blut3_83","btcap1":"text_yes","btcap2":"text_no"});} break;
		case "2_Binge3Bar": unlockTeleportPoint(); break;
		case "2_Binge3SkidTeleport": unlockTeleportPoint(); break;
		case "2_Binge3Graveyard": unlockTeleportPoint(); break;
		case "2_Binge3DiningRoom": unlockTeleportPoint(); break;
		case "2_Binge3MainHallTop": unlockTeleportPoint(); break;
		case "2_Binge3Entrance": unlockTeleportPoint(); break;
		case "2_Binge3Key": startDialogue("Binge3Key");break;

		// unhandled triggers should return false
		default: return false;
	}
		return true;
	}
	
	function Floor3(which){
	switch( which ) {
		case "3_Binge4Chimney": startDialogue( "Binge4Chimney"); break;
		case "3_Binge4Undead": if (getSpecialState("Binge4Undead") ==0) {showDialogue( "Binge4Undead1", {"text":"binge5_12"} );} else startDialogue("Binge4Undead"); break;
		case "3_Binge4Hole1": setSpecialState("BingeHoleLevel", 4);startDialogue( "Binge2Hole1"); break;
		case "3_Binge4Hole2": setSpecialState("BingeHoleLevel", 4);startDialogue( "Binge2Hole2"); break;
		case "3_Binge4Wheel": if (getSpecialState("Binge4WheelTurned") !=1) {showDialogue("Binge4Wheel",{"caption":"Binge4Wheel_hl","text":getLangString("binge5_13",[getName(0),getLangString("text_pp203_"+getGender(0),[])]),"btcap1":"text_yes","btcap2":"text_no"});break;} else {showDialogue("Binge4WheelB",{"caption":"Binge4Wheel_hl","text":getLangString("binge5_15",[getName(0),getLangString("text_pp_"+getGender(0),[])])}); break;}
		case "3_Binge4FireHole": startDialogue( "Binge4FireHole"); break;
		case "3_Binge4Water": startDialogue( "BingeWater"); break;
		case "3_Binge4FireSponge": startDialogue( "Binge4FireSponge"); break;
		case "3_Binge4EfferdSponge": startDialogue( "Binge4EfferdSponge"); break;
		case "3_Binge4BothSponges": showDialogue( "Binge4BothSponges", {"caption":"Binge4Sponge_hl","text":"binge5_24"} ); break;
		case "3_Binge4Gargoyles": if(getSpecialState("Binge4Gargoyles") != 1) {showDialogue( "none", {"text":"binge5_27"} ) ;startBattle("Binge4Gargoyles");} break;
		case "3_Binge4Smokeroom": if(getSpecialState("Binge4Smoke")==1) {showDialogue( "none", {"text":"binge_33"} ) ;addEffect({"who":-1,"which":"choking"});}break;
		case "3_Binge4FountainRoom": unlockTeleportPoint(); break;
		case "3_Binge4WheelRoom": unlockTeleportPoint(); break;
		case "3_Binge4Entrance": unlockTeleportPoint(); break;

		// unhandled triggers should return false
		default: return false;
	}
		return true;
	}

	function Floor4(which){
	if (which.substr( 2, 12 ) == "Binge5Diving") {if(getSpecialState("Binge4WheelTurned") !=1) startDialogue( "Binge5Diving"); return true;}
	switch( which ) {
		case "4_Binge5Water1": if(getSpecialState("Binge4WheelTurned") !=1) startDialogue( "Binge5Water"); break;
		case "4_Binge5Water2": if(getSpecialState("Binge4WheelTurned") !=1) startDialogue( "Binge5Water"); break;
		case "4_Binge5Entrance": unlockTeleportPoint(); break;
		case "4_Binge5Plate": if ((getDoorState("4_4011") != 2) && (getSpecialState("Binge4WheelTurned") ==1)) startDialogue("Binge5Door");  return true;

		// unhandled triggers should return false
		default: return false;
	}
		return true;
	}

		function Floor5(which){
if (which.substr(2,15)=="Binge6FirePlate") { if((getSpecialState("Binge6GolemAttacked") ==1)||(setSpecialState("Binge6StoneStolen")==1)){showDialogue( "Binge6FirePlateKill", {"caption": "Binge6FirePlate_hl","text":"binge7_10"} );} else startDialogue("Binge6FirePlate");return true;}
	switch( which ) {
		case "5_Binge6Chimney": startDialogue( "Binge6Chimney"); break;
		case "5_Binge6Golem": startDialogue( "Golem"); break;
		case "5_Binge6Exit": if (getSpecialState("map.binge_door_collapsed")==1) showDialogue( "none", {"caption":"Binge6Exit_hl","text":"binge7_29"} ); else showDialogue( "Binge6Exit", {"caption":"Binge6Exit_hl","text":"binge2_15","btcap1":"text_yes","btcap2":"text_no"} ); break;
		case "5_Binge6Wall": showDialogue( "Binge6Wall", {"caption":"Binge6Wall_hl","text":"binge7_14"} ); break;
		case "5_Binge6Lootbox": if(getSpecialState("Binge6LootboxDone") !=1){startDialogue( "Binge6Lootbox");} break;
		case "5_Binge6Hole": startDialogue( "Binge6Hole"); break;
		case "5_Binge6Entrance": unlockTeleportPoint(); break;
		case "5_Binge6GolemRoom": unlockTeleportPoint(); break;
		case "5_Binge6CommonRoom": unlockTeleportPoint(); break;
		case "5_Binge6WaterRoom": unlockTeleportPoint(); break;
		case "5_Binge6FireHall": unlockTeleportPoint(); break;
		case "5_Binge6Secretdoor": if (getDoorState("5_26")==0) startDialogue( "Binge6Secretdoor"); break;
		case "5_stair1": if ((getSpecialState("Binge6LeatherTaken")==1)||(getSpecialState("Binge6TreasureTaken")==1)||(getSpecialState("Binge6GolemAttacked") ==1)){ showDialogue( "Binge6Wall", {"caption":"Binge6Wall_hl","text":"binge7_14a"} );} else return false; break;
		case "5_Binge6Lever": startDialogue( "Binge6Lever"); break;
		case "5_Binge6Water":if (getSpecialState("Binge6WaterBarsDone")==1) {startDialogueAt("Binge6Water","7")} else {startDialogue("Binge6Water")} break;

		// unhandled triggers should return false
		default: return false;
	}
		return true;
	}


function OnTriggerLeft( which ) {
switch(which){
	case "3_Binge4Smokeroom": removeEffect({"who":-1,"which":"choking"});break;
	case "1_Binge2RoomTrap": removeEffect({"who":-1,"which":"BingeClosedRoom1"});removeEffect({"who":-1,"which":"BingeClosedRoom2"});removeEffect({"who":-1,"which":"BingeClosedRoom3"});removeEffect({"who":-1,"which":"BingeClosedRoom4"});break;
}
}
function OnPassTime( which ) {}
function OnDialogResult( which, resid ) {
	switch( which ) {
		case "Binge1Exit": if (resid ==0) {if ((getTotalPartyCount()==getPartyCount())){jumpToLocation({"where":"finsterkoppen","x":412,"y":2,"z":38,"rot":90});	startDialogueAt("raumangst","end");} else showDialogue( "none", {"caption":"Binge6Exit_hl","text":"text_multigrouplocationchange"} )} break;
		case "Binge1Tools1": if (resid == 0) {showItemContainer({"linked":true,"justtake":true,"itemset":"Binge1Tools1"});} break;
		case "Binge1Tools2": if (resid == 0) {showItemContainer({"linked":true,"justtake":true,"itemset":"Binge1Tools2"});} break;	
		case "Binge3Crashing": var res = rollCheck({"which":"gefahrensinn","who":0,"type":"skill", "mod":0}); setSpecialState("Binge3Crashed",1); if (res.ok) {showDialogue("Binge3Crashing2", {"caption":"Binge3Crashing_hl", "text": getLangString("binge4_71",[getName(0)])});} else { dealDamage({"who":0,"amount":"3W6","type":"ignorers"}); showDialogue("Binge3Crashing3", {"caption":"Binge3Crashing_hl", "text": getLangString("binge4_69",[getName(0)])});} break;
		case "Binge3Crashing3": showDialogue("Binge3Crashing4", {"caption":"Binge3Crashing_hl", "text": getLangString("binge4_70",[getName(0),getLangString("text_3rdperson_"+getGender(0),[])])}); break;
		case "Binge3Altar": if (resid ==0) {var res = rollCheck({"which":"altespr","who":"best","type":"skill", "mod":-3}); if (res.ok) {passTime( "", 0.5 );showDialogue("Binge3Altar2", {"caption":"BingeAltar_hl", "text": getLangString("binge4_57",[getName(0),getLangString("text_3rdperson_"+getGender(0),[])])});} else {passTime( "", 0.5 );showDialogue("Binge3Altar2", {"caption":"BingeAltar_hl", "text": getLangString("binge4_56",[])});}} break;
		case "Binge3JumpLever": if (resid ==0) {setSpecialState("Binge3JumpLever",1); setDoorState("2_15",2);setDungeonObjectState("bridgelever",2);}break;
		case "Binge4Undead1": startBattle("Binge4Undead"); break;
		case "Binge4Wheel": if (resid == 0) {setSpecialState("Binge4WheelTurned",1);setDoorState("4_4099",2);showDialogue("Binge4WheelB",{"caption":"Binge4Wheel_hl","text":getLangString("binge5_14",[getName(0)])}); break;}
		case "Binge6Exit": if (resid ==0) {if ((getTotalPartyCount()==getPartyCount())){if (findInventoryItem("st_sstone") > 0){ setSpecialState("map.binge_door_collapsed",1);showDialogue( "none", {"caption":"Binge6Exit_hl","text":"binge7_28"} );} setJourneyState({"route":"Route063","pos":0.99,"dir":false});	startDialogueAt("raumangst","end");} else showDialogue( "none", {"caption":"Binge6Exit_hl","text":"text_multigrouplocationchange"} )} break;
		case "Binge6Wall": showDialogue( "none", {"caption":"Binge6Wall_hl","text":"binge7_15" }); break;
		case "Binge6FirePlateKill": dealDamage({"who":-1, "amount":999, "type":"ignorers", "reason":"Ingerimms Wrath"}); break;
}
	if( which.substr(0,11) == "PartCrashed" ) {
		if( resid == 0 ) askPartCrashed( which.substr(11,2), true );
	}
	if( which.substr(0,11) == "FullCrashed" ) {
		if( resid == 0 ) askFullCrashed( which.substr(11,2), true );
	}
	if( which.substr(0,11) == "TotaCrashed" ) {
		if( resid == 0 ) askTotaCrashed( which.substr(11,2), true );
	}
	if( which.substr(0,19) == "UnshovelFullCrashed" ) {
	showDialogue("2"+which, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_62",[])});	
	}
	if( which.substr(0,14) == "TotaCrashedTry" ) {
		var mod = -1*getCharAttribute("BE",0);
		var res = rollCheck({"which":"GE","who":0,"type":"attrib", "mod":mod});
	if (res.ok) { showDialogue("TotaCrashedA"+which, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_66",[getName(0)])});
	}
	else {dealDamage({"who":0,"amount":"1W6","type":"ignorers"});
	showDialogue("TotaCrashedT"+which, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_67",[getName(0)])});
	}
	}
	if((( which.substr(0,11) == "Binge3TombA" )||( which.substr(0,11) == "Binge3TombC" ))&&(resid==0)) {if(getSpecialState("BingeTombSave") != 1) {autoSave();setSpecialState("BingeTombSave",1)};setSpecialState("BingeTombAxeCallback",which.substr(11,2));setGeneralState("Binge3TombAxe",{"doublelist":["hatchet",1]}); showItemContainer({"linked":true,"justtake":true,"itemset":"Binge3TombAxe","callback":"Binge3TombAxeCallback"})}
	if((( which.substr(0,11) == "Binge3TombA" )&&(resid==1))||(( which.substr(0,11) == "Binge3TombB" )&&(resid==0))) {if(getSpecialState("BingeTombSave") != 1) {autoSave();setSpecialState("BingeTombSave",1)};if(getSpecialState("BingeTombSearchedCounter") !=1 ){setSpecialState("BingeTombSearchedCounter",1); setSpecialState("Binge3TombSearched"+which.substr(11,2),1);modifyGodGrace("Ingerimm", -10);showDialogue("Binge3TombD"+which.substr(11,2),{"caption":"Binge3Tomb_hl","text":"binge4_54"})}else showDialogue("Binge3TombE"+which.substr(11,2),{"caption":"Binge3Tomb_hl","text":"binge4_54b" })}
	if( which.substr(0,11) == "Binge3TombD" ) {startBattle("Binge3Tomb")}
	if( which.substr(0,11) == "Binge3TombE" ) {gameover()}
	if( which.substr(0,11) == "Binge3TombF" ) {for (var i=0; i<getPartyCount();i++) {
	var res = getEquipped("weapon",i);
	if (res.BF >0) {modifyInventoryItem({"who":i, "slot":"weapon", "setbf":res.BF+1});}
	for(var j = 1; j <= 35; j++){
  	var ivpos = "inventory"+((j<10)?("0"+j):j);
  	var res = getEquipped(ivpos, i);
	if (res.BF >0) {modifyInventoryItem({"who":i, "slot":ivpos, "setbf":res.BF+1});}
}
}}
}

// whenever a door is clicked, "which" as always <floorid>_<doorid>. Should return true if the doorclick was handled
function doorClicked( which ) { 
	switch( which ) {
		case "0_5": if (getCurrentTrigger()=="0_MainPortalIn") startDialogue("BingeMainPortalIn"); else startDialogue("BingeMainPortalOut");  return true;
		case "0_2": showDialogue( "Binge1Exit", {"caption":"Binge6Exit_hl","text":"binge2_15","btcap1":"text_yes","btcap2":"text_no"} ); return true;
		case "1_1": setSpecialState("Binge2FakeDoor",(Number(getSpecialState("Binge2FakeDoor"))+1)); if((round(Number(getSpecialState("Binge2FakeDoor"))/2)*2)==getSpecialState("Binge2FakeDoor")){startDialogue("Binge2FakeDoor"); return true} else return false;
		case "3_14": {
		if( getDoorState("3_14") != 2 ) {
			var cnt = findInventoryItem( "st_bigcopperkey" );
			if( cnt >= 1 ) {
				showDialogue("Binge4Key", { "text": "Binge4Key"});
				setDoorState("3_14",2);
				awardXP("xp_kupferschluessel",-1,10);
				removeInventoryItem( "st_bigcopperkey",1 );
				return true;
			} 
		}
		
	}

		case "5_30": {
		if( getDoorState("5_30") != 2 ) {
			var cnt = findInventoryItem( "st_doublebeardedkey" );
			if( cnt >= 1 ) {
				setDoorState("5_30",2);
				awardXP("xp_doppelbartschluessel",-1,10);
				removeInventoryItem( "st_doublebeardedkey",1 );
				showDialogue("Binge6Key", { "text": getLangString("binge7_16",[getName(0)])});
				return true;
			} 
		}
		
	}
	}
	return false; }
// whenever a chest is clicked, "which" as always <floorid>_<chestid>. Should return true if the chestclick was handled
function chestClicked( which ) { 
switch( which ) {
		case "0_4": startDialogue( "BingeChest01" ); return true;
	}
	return false; }


// whenever a chest is opened, "which" as always <floorid>_<chestid>. Should return true if the opening was handled
function chestOpened( which ) {
	switch( which ) {
		case "1_11": startDialogue( "Binge2GnomeChest" ); return true;
		case "5_28": startDialogue( "Binge6sstoneChest" ); return true;
		case "5_27": startDialogue("Binge6LeatherChest"); return true;
		case "5_30": startDialogue( "Binge6TreasureChest" ); return true;
	}
	return false;
}

function askPartCrashed( which, doit ) {
	if ((which == "01")||(which == "07")||(which == "08")||(which == "09")||(which == "10")) return;
	switch(which){
	case "02": var curDoor="2_27";break;
	case "03": var curDoor="2_21";break;
	case "04": var curDoor="2_20";break;
	case "05": var curDoor="2_19";break;
	case "06": var curDoor="2_23";break;
}
	setSpecialState("Binge3curDoor",curDoor);
	if( getDoorState( curDoor ) == 2 ) return;
	if( !doit )
	showDialogue("PartCrashed"+which,{"caption":"Binge3Crashed_hl","text":"binge4_58","btcap1":"text_yes","btcap2":"text_no"})
	else {
		var cnt = findInventoryItem( "shovel" );
		if( cnt < 1 ) {
			showDialogue("PartCrashed"+which, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_59",[])});
				return;
			}
		unShovel( "PartCrashed"+which, 2 );
	}
}

function askFullCrashed( which, doit ) {
	if ((which == "01")||(which == "02")||(which == "04")||(which == "07")||(which == "09")||(which == "10")) return;
	switch(which){
	case "03": var curDoor="2_16";break;
	case "05": var curDoor="2_24";break;
	case "06": var curDoor="2_17";break;
	case "08": var curDoor="2_22";break;
	case "11": var curDoor="2_25";break;
	case "12": var curDoor="2_26";break;
}
	setSpecialState("Binge3curDoor",curDoor);
	if( getDoorState( curDoor ) == 2 ) return;
	if( !doit )
	showDialogue("FullCrashed"+which,{"caption":"Binge3Crashed_hl","text":"binge4_63","btcap1":"text_yes","btcap2":"text_no"})
	else {
		var cnt = findInventoryItem( "shovel" );
		if( cnt < 1 ) {
			showDialogue("FullCrashed"+which, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_59",[])});
				return;
			}
		unShovel( "FullCrashed"+which, 4 );
	}
}

function askTotaCrashed( which, doit ) {
	
	if( !doit )
	showDialogue("TotaCrashed"+which,{"caption":"Binge3Crashed_hl","text":"binge4_64","btcap1":"text_yes","btcap2":"text_no"})
	else {
		var cnt = findInventoryItem( "shovel" );
		if( cnt < 1 ) {
			showDialogue("FullCrashed"+which, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_59",[])});
				return;
			}
			showDialogue("TotaCrashedTry"+which, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_65",[])});
				return;
			}
	}


function unShovel( result, basedur ) {
	var shovelcnt = findInventoryItem( "shovel" );
	if (shovelcnt >2) shovelcnt = 2;
	var digger = 0;
	var j = -1;
	var h = -1;
	for (var i=0; i < getPartyCount();i++) {
	if (canAct(i)) {
	var cnt = findInventoryItemAt( i , "shovel" );
	if( cnt > 0 ){
	digger++;
	if (j ==-1) j = i;
	else {if (h ==-1) h = i;}
	}}}
	var curDoor = getSpecialState("Binge3curDoor");
	setDoorState( curDoor, 2 );
	awardXP( "xp_bingegeroell",-1, 2 );

 if (digger == 1){
	passTime( result, basedur );
	showDialogue("Unshovel"+result, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_60",[getName(j)])});
}
 if (digger > 1){
	basedur = basedur/2;
	passTime( result, basedur );
	showDialogue("Unshovel"+result, {"caption":"Binge3Crashed_hl", "text": getLangString("binge4_61",[getName(j),getName(h)])});
}
}

function askTomb( which) {
if ((getSpecialState("Binge3TombAxeTaken"+which) == 0) && (getSpecialState("Binge3TombSearched"+which) == 0)) {
showDialogue("Binge3TombA"+which,{"caption":"Binge3Tomb_hl","text":"binge4_50","btcap1":"binge4_51","btcap2":"binge4_52","btcap3":"binge2_33a"})
}
if ((getSpecialState("Binge3TombAxeTaken"+which) == 1) && (getSpecialState("Binge3TombSearched"+which) == 0)) {
showDialogue("Binge3TombB"+which,{"caption":"Binge3Tomb_hl","text":"binge4_50b","btcap1":"binge4_52","btcap2":"binge2_33a"})
}

if ((getSpecialState("Binge3TombAxeTaken"+which) == 0) && (getSpecialState("Binge3TombSearched"+which) == 1)) {
showDialogue("Binge3TombC"+which,{"caption":"Binge3Tomb_hl","text":"binge4_50c","btcap1":"binge4_51","btcap2":"binge2_33a"})
}
}
function Binge3TombAxeCallback() {if(typeof(getGeneralState("Binge3TombAxe").items)!="object") {setSpecialState("Binge3TombAxeCounter",Number(getSpecialState("Binge3TombAxeCounter"))+1);setSpecialState("Binge3TombAxeTaken"+getSpecialState("BingeTombAxeCallback"),1);modifyGodGrace("Ingerimm", -10); if(getSpecialState("Binge3TombAxeCounter")>2) showDialogue("Binge3TombE"+getSpecialState("BingeTombAxeCallback"),{"caption":"Binge3Tomb_hl","text":"binge4_53b"}); else {if(getSpecialState("Binge3TombAxeCounter")>1) showDialogue("Binge3TombF"+getSpecialState("BingeTombAxeCallback"),{"caption":"Binge3Tomb_hl","text":"binge4_53a"}); else {showDialogue("Binge3TombG"+getSpecialState("BingeTombAxeCallback"),{"caption":"Binge3Tomb_hl","text":"binge4_53"})}}}}
]]></script>
	<!-- Contents of Itemsets here are stored and handled via Savegame whenever they are modified after first entry -->
	<itemsets>
		<!-- Custom set, e.g. "something lying on the floor" -->
		<itemset id="Binge1Chimney">
			<item id="st_doublebeardedkey" />
			<item id="potion_healing" />
		</itemset>
		<!-- Chest-Set automatically assiged to Chest ID 3 on Floor 0 -->
		<itemset id="chest_0_2">
			<item id="alchemyset" count="1" />
			<item id="crystalball" count="1" />
			<item id="fancyrobe" count="1" />
			<item id="obsidiandagger" count="1" />
			<item id="coucrismengbilar" count="1" />
			<item id="bronzeflask" count="2" />
			<item id="st_doc_missingvocals" count="1" />
		</itemset>
		<itemset id="chest_0_3">
			<item id="battlestaff" count="1" />
			<item id="wolfknife" count="1" />
			<item id="beltofstrength_unided" count="1" />
			<item id="oil" count="2" />
			<item id="lanternempty" count="1" />
			<item id="st_doc_backwards" count="1" />
		</itemset>
		<itemset id="chest_0_1">
			<item id="potion_stronghealing" count="1" />
			<item id="potion_strength" count="1" />
			<item id="potion_dexterity" count="1" />
			<item id="hylailanfire" count="2" />
			<item id="rec_vomicum" count="1" />
			<item id="rec_hylailanfire" count="1" />
		</itemset>
		<itemset id="chest_1_8">
			<item id="throwingaxe2" count="1" />
			<item id="hatchet" count="1" />
			<item id="skullbelt_unided" count="1" />
		</itemset>
		<itemset id="chest_1_9">
			<item id="boots" count="3" />
			<item id="shield" count="3" />
			<item id="ironshield" count="3" />
		</itemset>
		<itemset id="chest_1_10">
			<item id="supplypack" count="10" />
			<item id="waterskin" count="10" />
			<item id="cutlery" count="10" />
			<item id="dishes" count="10" />
			<item id="drinkinghorn" count="1" />
		</itemset>
		<itemset id="chest_1_7">
			<item id="st_cartgrease" count="1" />
			<item id="st_crank" count="1" />
		</itemset>
		<itemset id="chest_2_18">
			<item id="whetstone" count="1" />
			<item id="knife" count="2" />
			<item id="dagger" count="1" />
			<item id="heavydagger" count="1" />
			<item id="sickle" count="1" />
		</itemset>
		<itemset id="chest_2_19">
			<item id="redcoins" count="1" />
			<item id="coucrisdagger" count="1" />
		</itemset>
		<itemset id="chest_2_17">
			<item id="piton" count="10" />
			<item id="ropeladder" count="1" />
			<item id="grapplinghook" count="1" />
			<item id="rope" count="1" />
		</itemset>
		<itemset id="chest_2_20">
		</itemset>
		<itemset id="chest_4_23">
		</itemset>
		<itemset id="chest_5_25">
			<item id="clothtrousers" count="5" />
			<item id="clothshirt" count="5" />
			<item id="robe1" count="5" />
			<item id="wintercoat" count="5" />
			<item id="tunic" count="5" />
		</itemset>
		<itemset id="chest_5_26">
			<item id="bunchofkeys" count="1" />
			<item id="crossbowheavy" count="2" />
			<item id="quarrel" count="40" />
			<item id="battleaxe" count="1" />
		</itemset>
		<itemset id="chest_5_24">
			<item id="sword" count="1" />
			<item id="heavydagger" count="1" />
			<item id="club" count="1" />
			<item id="throwingstar" count="1" />
			<item id="beltofstrength_unided" count="1" />
			<item id="st_doc_parchments" count="1" />
		</itemset>
	</itemsets>
	<exit>
		<!-- 
can either be fixed coordinates like this:
[code]
	<coords>
	  <x>-19</x>
	  <y>21.8</y>
	  <z>35.5</z>
	</coords>
	<dungeon>prem</dungeon>
	<rotation>270</rotation>
[/code]
	or a script like below, executed when "leaving the dungeon". 
	Script can be "continueJourney();" if before entry of the dungeon "saveJourney()" was called -->
	<script>
		startDialogueAt("raumangst","end");
	</script>
		<dungeon>script</dungeon>
	</exit>
</dungeon>
<dungeon intname="dngtjolmarnameless">
	<scene>dngnameless1</scene>
	<floor id="0">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="1" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
			<tile chestid="1" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 0 -->
			<!-- Multi=true is triggered EVERY time it is entered -->
			<trigger name="Pillar1" x="30" y="40" width="3" height="4" multi="true" />
			<trigger name="Pillar2" x="11" y="40" width="3" height="4" multi="true" />
			<trigger name="Pillar3" x="14" y="25" width="3" height="4" multi="true" />
			<trigger name="Pillar4" x="14" y="68" width="3" height="4" multi="true" />
			<trigger name="losestone" x="1" y="53" width="4" height="4" multi="true" />
			<trigger name="arkandor" x="2" y="26" width="3" height="4" multi="true" />
			<trigger name="knight" x="16" y="53" width="3" height="4" />
			<trigger name="plate" x="30" y="53" width="3" height="4" multi="true" />
			<!-- Fight-Trigger directly starts a fight if an accordingly named fight is defined FOR THIS LEVEL -->
			<trigger name="dfinal_18" x="18" y="14.5" width="4" height="2" />
			<!-- multi=false (or not defined) triggers EXACTLY ONCE, can be used for descriptions and the like -->
			<trigger name="entrance" x="-20.5" y="8.5" width="8" height="4" />
		</triggers>
	</floor>
	<script><![CDATA[
// Called when the Dungeon is initialized, with "initial=true" for first time entry
// and "initial=false" for loaded or returned or other time entry
function InitDungeon( initial ) {
	if( initial ){
		setSpecialState("tookGold",0);
	}
}
// Called when a trigger is entered, which is of the format "<floorid>_<triggername>", even if there is only floor 0
function OnTrigger( which ) {
	switch( which ) {
		// "none" is the callback name for OnDialogResult
		case "0_Pillar1": startDialogueAt("tdn_l3_pillars",2); break;
		case "0_Pillar2": startDialogueAt("tdn_l3_pillars",3); break;
		case "0_Pillar3": startDialogueAt("tdn_l3_pillars",4); break;
		case "0_Pillar4": startDialogueAt("tdn_l3_pillars",5); break;
		case "0_losestone": startDialogue("tdn_l3_losestone"); break;
		case "0_arkandor": startDialogue("tdn_arkandor"); break;
		case "0_knight": startBattle("tdn_l3_knight"); break;
		case "0_plate": startDialogue("tdn_l3_plate"); break;
		// unlike the "autobattletrigger" handling, startBattle automatically looks into the globally defined battles as well
		case "0_toughbattle9": startBattle( "dfinal_"+which.substr(2) ); break;
		case "0_endbattle": if( getQuestState("schick_hyggelik") < 3 ) startBattle( "dfinal_endbattle" ); break;
		case "0_cantleave": checkCantLeave(); break;
	
		// unhandled triggers should return false
		default: return false;
	}
	return true;
}
// custom defined function, can be removed
function checkCantLeave() {
	if( getSpecialState( "tookGold" ) == 1 ) {
		moveToTrigger( "0_entrance", 0 );
		showDialogue( "none", {"text":"dfinal_6"} );
	}
}

function OnTriggerLeft( which ) {}
function OnPassTime( which ) {}
function OnDialogResult( which, resid ) {
	switch( which ) {
		case "0_2": if( resid == 0 ) { showDialogue( "none", {"text":getLangString( "dfinal_36", [getName( rollRandom(0,getPartyCount()))] )} ); } break;
		case "dfinal_50": showDialogue( "dfinal_51", {"text":"dfinal_51"} ); break;
		case "dfinal_51": showItemset( "dfinal_51" ); break;
		case "dfinal_53": 
		case "dfinal_54": 
			if( resid == 0 ) {
				if( getSpecialState( "tookGold" ) != "1" )
					autoSave();
				changeWealth( (which=="dfinal_53")?800:500000 );
				setSpecialState( "tookGold", "1" );
			} else {
				var res = rollCheck( {"which":"GG","who":"best","type":"attrib"} );
				showDialogue( "none", {"text":getLangString("dfinal_55",[res.name,getLangString("text_3rdperson_"+(getGender( res.id )),[])])});
			}
			break;
	}
}

// whenever a door is clicked, "which" as always <floorid>_<doorid>. Should return true if the doorclick was handled
function doorClicked( which ) { 
	switch( which ) {
		case "0_1": startDialogueAt("tdn_l3_pillars",10); return true;
		case "0_2": startDialogue("tdn_l3_combinationlock"); return true;


return false; }}
// whenever a chest is clicked, "which" as always <floorid>_<chestid>. Should return true if the chestclick was handled
function chestClicked( which ) { return false; }
// whenever a chest is opened, "which" as always <floorid>_<chestid>. Should return true if the opening was handled
function chestOpened( which ) {
	switch( which ) {
		case "0_1": showDialogue( "none", {'text':'dfinal_34'} ); return true;
		case "0_2": showDialogue( "0_2", {'text':'dfinal_35','btcap1':'text_yes','btcap2':'text_no'} ); return true;
		case "0_4": showDialogue( "none", {'text':'dfinal_37'} ); return true;
	}
	return false;
}
]]></script>
	<!-- Contents of Itemsets here are stored and handled via Savegame whenever they are modified after first entry -->
	<itemsets>
		<!-- Custom set, e.g. "something lying on the floor" -->
		<itemset id="dfinal_51">
			<item id="pickaxe" />
		</itemset>
		<!-- Chest-Set automatically assiged to Chest ID 3 on Floor 0 -->
		<itemset id="chest_0_3">
			<item id="potion_healing" count="5" />
			<item id="potion_stronghealing" count="2" />
			<item id="potion_magic" count="5" />
			<item id="potion_magicstrong" count="2" />
		</itemset>
	</itemsets>
	<exit>
		<!-- 
can either be fixed coordinates like this:
[code]
	<coords>
	  <x>-19</x>
	  <y>21.8</y>
	  <z>35.5</z>
	</coords>
	<dungeon>prem</dungeon>
	<rotation>270</rotation>
[/code]
	or a script like below, executed when "leaving the dungeon". 
	Script can be "continueJourney();" if before entry of the dungeon "saveJourney()" was called -->
		<script>
		setJourneyState( {"route":"hyg1-hyg2","pos":0.64,"pause":true,"dir":false} );
	</script>
		<dungeon>script</dungeon>
	</exit>
</dungeon>
<dungeon intname="dngphextemple">
	<floor id="0">
		<!--Tiles are Read-Only and just as reference for IDs of Doors and Chests-->
		<tiles>
			<!-- Doors corresponding to Gameobjects in the dungeon -->
			<tile cdoorid="57" state="locked" lockpickmod="0" foramenmod="0" runindifficulty="8" />
			<tile cdoorid="74" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
			<tile cdoorid="62" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
			<tile cdoorid="61" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
			<tile cdoorid="60" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
			<tile cdoorid="55" state="locked" lockpickmod="8" foramenmod="8" runindifficulty="8" />
			<tile cdoorid="51" state="locked" lockpickmod="4" foramenmod="2" runindifficulty="8" />
			<tile cdoorid="56" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
			<tile cdoorid="53" state="locked" lockpickmod="6" foramenmod="6" runindifficulty="8" />
			<tile cdoorid="532" state="locked" lockpickmod="4" foramenmod="6" runindifficulty="8" />
			<tile cdoorid="63" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
			<tile cdoorid="52" state="locked" lockpickmod="10" foramenmod="10" runindifficulty="8" />
			<tile cdoorid="54" state="locked" lockpickmod="12" foramenmod="12" runindifficulty="8" />
Fallgrube			<tile cdoorid="73" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
Kampf D1			<tile cdoorid="66" state="locked" lockpickmod="5" foramenmod="5" runindifficulty="8" />
Baldower			<tile cdoorid="65" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
Kugeltür			<tile cdoorid="715" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
passphrase			<tile cdoorid="75" state="locked" lockpickmod="4" foramenmod="4" runindifficulty="8" />
nach norden			<tile cdoorid="70" state="locked" lockpickmod="8" foramenmod="8" runindifficulty="8" />
trittplatten			<tile cdoorid="71" state="locked" lockpickmod="5" foramenmod="5" runindifficulty="8" />
Klingelkasten			<tile cdoorid="64" state="locked" lockpickmod="7" foramenmod="7" runindifficulty="8" />
vor Labyrinth			<tile cdoorid="69" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
nichts, bei Tugendrätsel			<tile cdoorid="67" state="locked" lockpickmod="9" foramenmod="9" runindifficulty="8" />
nach Park			<tile cdoorid="68" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
Ausgang	Passphrase		<tile cdoorid="712" state="locked" lockpickmod="2" foramenmod="2" runindifficulty="8" />
Ausgang			<tile cdoorid="212" state="locked" lockpickmod="-2" foramenmod="-2" runindifficulty="8" />

			<tile cdoorid="99" state="closed" type="secretdoor" />
			<tile cdoorid="93" state="closed" type="secretdoor" />
			<tile cdoorid="94" state="closed" type="secretdoor" />

			<!-- Chests corresponding to Treasurechest Gameobjects in the Dungeon, Content of the Chest in "chest_<floor>_<chestid>" -->
4 Sternenschweif			<tile chestid="1" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
leer 6 rezept			<tile chestid="3" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
waage bei 12			<tile chestid="4" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
B Folterwerkzeug			<tile chestid="6" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
8 rezept Kobold-Stirn			<tile chestid="7" type="chest" state="locked" lockpickmod="6" foramenmod="3" trap="physical" diecnt="2" dietype="4" mod="4"  />
D1 ungeziefer Kobold-Ring			<tile chestid="8" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
20 Phexhelm			<tile chestid="5" type="chest" state="locked" lockpickmod="6" foramenmod="3" />
bei Opferstock Kobold-Gold			<tile chestid="10" type="chest" state="locked" lockpickmod="6" foramenmod="6" trap="physical" diecnt="2" dietype="4" mod="4"  />
nichts, bei Tugendrätsel			<tile chestid="9" type="chest" state="locked" lockpickmod="10" foramenmod="10" trap="physical" diecnt="2" dietype="4" mod="4" />
		</tiles>
		<!--Any Changes from here affect the game directly-->
		<triggers>
			<!-- Floor 0 -->
			<!-- Fight-Trigger directly starts a fight if an accordingly named fight is defined FOR THIS LEVEL
			<trigger name="dfinal_18" x="18" y="14.5" width="4" height="2" /> -->
			<!-- multi=false (or not defined) triggers EXACTLY ONCE, can be used for descriptions and the like -->
			<trigger name="B_verminfight" x="-131.5" y="39" width="1" height="2" />
			<trigger name="D1_verminfight" x="-100" y="118" width="4" height="4" />
			<trigger name="D1_zinken" x="-100" y="117" width="8" height="10" />
			<trigger name="D2_verminfight" x="-96" y="151" width="4" height="6" />
			<trigger name="D2_zinken" x="-97" y="150" width="10" height="12" />
			<!-- Multi=true is triggered EVERY time it is entered -->
<!--		<trigger name="I_virtuequiz" x="-37.75" y="167" width="3" height="0.5" multi="true" />
-->		<trigger name="I_virtuequiz" x="-36.50" y="168.2" width="3" height="0.5" multi="true" />
			<trigger name="I1_virtuestatue" x="-128.175" y="136.55" width="1.2" height="1.2" multi="true" />
			<trigger name="I2_virtuestatue" x="-121.325" y="136.55" width="1.2" height="1.2" multi="true" />
			<trigger name="I3_virtuestatue" x="-129.5" y="173.35" width="1.2" height="1.2" multi="true" />
			<trigger name="I4_virtuestatue" x="-16.7" y="119.7" width="1.2" height="1.2" multi="true" />
			<trigger name="I5_virtuestatue" x="-38.4" y="75.37" width="1.2" height="1.2" multi="true" />
			<trigger name="I6_virtuestatue" x="-63" y="182.2" width="1.2" height="1.2" multi="true" />
			<trigger name="J0_coalkey" x="-20.3" y="176.7" width="1.0" height="1.0" multi="true" />
			<trigger name="J1_coalbowl" x="-26.4" y="176.7" width="1.0" height="1.0" multi="true" />
			<trigger name="J4_coalbowl" x="-26.48" y="171.6" width="1.0" height="1.0" multi="true" />
			<trigger name="J5_coalbowl" x="-120.8" y="151.8" width="1.0" height="1.0" multi="true" />
			<trigger name="J6_coalbowl" x="-130.2" y="151.8" width="1.0" height="1.0" multi="true" />
			<trigger name="J7_coalbowl" x="-130.2" y="147" width="1.0" height="1.0" multi="true" />
<!--			<trigger name="J3_coaldoor" x="-19" y="169.5" width="1" height="1" multi="true" /> -->
			<trigger name="K1_treadplateK" x="-125.8" y="176.1" width="1" height="1" multi="true" />
			<trigger name="K2_treadplateK" x="-50.95" y="170.4" width="1" height="1" multi="true" />
			<trigger name="K_zinken" x="-94" y="174.5" width="6" height="4.0" multi="true" />
			<trigger name="K_pitfallK_instinct" x="-94" y="174.5" width="4" height="4.5" multi="true" />
			<trigger name="K_pitfallK" x="-94" y="174.5" width="2" height="5.0" multi="true" />
			<trigger name="L_leverL" x="2.9" y="102.9" width="1.5" height="1.5" multi="true" />
			<trigger name="M1_pushM" x="-107.0" y="55.5" width="2" height="2" multi="true" />
			<trigger name="M2_pushM" x="-121.2" y="64.9" width="2" height="2" multi="true" />
			<trigger name="M3_pushM" x="-119.0" y="67.2" width="2" height="2" multi="true" />
			<trigger name="M1_push_leave" x="-107.0" y="53.1" width="2" height="2" />
			<trigger name="M2_push_leave" x="-123.6" y="64.9" width="2" height="2" />
			<trigger name="M3_push_leave" x="-119.0" y="69.6" width="2" height="2" />
			<trigger name="Z01_treadplateZ138" x="0.5" y="94.4" width="2" height="2" multi="true" />
			<trigger name="Z02_treadplateZ132" x="-4.3" y="94.4" width="2" height="2" multi="true" />
			<trigger name="Z03_treadplateZ110" x="-28.3" y="94.4" width="2" height="2" multi="true" />
			<trigger name="Z04_treadplateZ140" x="-13.9" y="89.6" width="2" height="2" multi="true" />
			<trigger name="Z05_treadplateZ141" x="-37.9" y="89.6" width="2" height="2" multi="true" />
			<trigger name="Z06_treadplateZ130" x="-18.7" y="84.8" width="2" height="2" multi="true" />
			<trigger name="Z07_treadplateZ104" x="-4.3" y="80.0" width="2" height="2" multi="true" />
			<trigger name="Z08_treadplateZ112" x="-28.3" y="80.0" width="2" height="2" multi="true" />
			<trigger name="Z09_treadplateZ129" x="-33.1" y="80.0" width="2" height="2" multi="true" />
			<trigger name="Z10_treadplateZ137" x="-4.3" y="75.2" width="2" height="2" multi="true" />
			<trigger name="Z11_treadplateZ120" x="-37.9" y="70.4" width="2" height="2" multi="true" />
			<trigger name="Z12_treadplateZ106" x="0.5" y="65.6" width="2" height="2" multi="true" />
			<trigger name="Z13_treadplateZ114" x="-9.1" y="65.6" width="2" height="2" multi="true" />
			<trigger name="Z14_treadplateZ103" x="-13.9" y="65.6" width="2" height="2" multi="true" />
			<trigger name="Z15_treadplateZ123" x="-33.1" y="65.6" width="2" height="2" multi="true" />
			<trigger name="Z16_treadplateZ116" x="-37.9" y="65.6" width="2" height="2" multi="true" />
			<trigger name="Z17_treadplateZ126" x="-23.5" y="60.8" width="2" height="2" multi="true" />
				
<!--Eingang			<trigger name="1_entry" x="-63.6" y="36.8" width="2" height="2" />
-->			<trigger name="0_zinken" x="-68.2" y="38.5" width="2" height="2"  multi="true" />
			<trigger name="2_supplypacks" x="-85.8" y="49.9" width="1" height="1" multi="true" />
			<trigger name="2_zinken" x="-85.8" y="49.9" width="1.5" height="1.5" multi="true" />
			<trigger name="3a_secretdoor_0_99" x="-103" y="50.5" width="1" height="1" multi="true" />
<!--			<trigger name="3b_secretdoor_0_93" x="-120" y="65" width="1" height="1" multi="true" /> -->
			<trigger name="3c_secretdoor_0_97" x="-82.6" y="84.3" width="1" height="1" multi="true" />
			<trigger name="3d_secretdoor_0_94" x="-62" y="179.5" width="1" height="1" multi="true" />
			<trigger name="3e_secretdoor_0_95" x="-28" y="104.8" width="1" height="1" multi="true" />
			<trigger name="3e_zinken" x="-28" y="106.8" width="2" height="1" multi="true" />
			<trigger name="3f_secretdoor_0_96" x="-20" y="106" width="1" height="1" multi="true" />
			<trigger name="3f_zinken" x="-20" y="103" width="2" height="1" multi="true" />
			<trigger name="3g_secretdoor_0_720" x="-9.75" y="111.7" width="1" height="0.4" multi="true" />
			<trigger name="3g_secretdoor_0_721" x="-9.75" y="110.9" width="1" height="0.4" multi="true" />
			<trigger name="3h_secretdoor_0_101" x="-36.2" y="150.4" width="1" height="1" multi="true" />
			<trigger name="3i_secretdoor_0_100" x="-105.4" y="89.6" width="1" height="1" multi="true" />
			<trigger name="3k_secretdoor_0_204" x="-108.5" y="126.0" width="1" height="1" multi="true" />
			<trigger name="3l_secretdoor_0_98" x="-122.9" y="169.9" width="1" height="1" multi="true" />
			<trigger name="3m_secretdoor_0_205" x="-54.7" y="160.5" width="1" height="1" multi="true" />
			<trigger name="4a_treadplate4" x="-129.8" y="69.5" width="1" height="1" multi="true" />
			<trigger name="4b_treadplate4" x="-128.55" y="74.75" width="1" height="1" multi="true" />
			<trigger name="6_moneycrapper" x="-93" y="90" width="0.7" height="0.7" multi="true" />
			<trigger name="8_magicpotion" x="-80.2" y="68.5" width="1.5" height="1.5" multi="true" />
			<trigger name="9_pitfall9" x="-128.6" y="81.7" width="1.5" height="1.5" />
			<trigger name="11a_baldower" x="-129.7" y="81.6" width="1" height="2" />
			<trigger name="11_baldower" x="-65.15" y="123" width="1" height="1" multi="true" />
			<trigger name="11b_baldower_gold" x="-65.15" y="113.8" width="1" height="1" multi="true" />
			<trigger name="12_balance" x="-124.72" y="141.8" width="1.5" height="1.5" multi="true" />
			<trigger name="14_sign" x="-125.5" y="147" width="0.5" height="1" multi="true" />
			<trigger name="14a_treadplate14" x="-115.75" y="168.6" width="1" height="1" multi="true" />
			<trigger name="14b_treadplate14" x="-118.15" y="168.6" width="1" height="1" multi="true" />
			<trigger name="14c_treadplate14" x="-120.55" y="168.6" width="1" height="1" multi="true" />
			<trigger name="14d_treadplate14" x="-122.95" y="168.6" width="1" height="1" multi="true" />
			<trigger name="14e_treadplate14" x="-125.35" y="168.6" width="1" height="1" multi="true" />
			<trigger name="14f_treadplate14" x="-127.75" y="168.6" width="1" height="1" multi="true" />
			<trigger name="14g_treadplate14" x="-130.15" y="168.6" width="1" height="1" multi="true" />
			<trigger name="14h_treadplate14" x="-122.95" y="166.2" width="1" height="1" multi="true" />
			<trigger name="14i_treadplate14" x="-125.35" y="166.2" width="1" height="1" multi="true" />
			<trigger name="14j_treadplate14" x="-127.75" y="166.2" width="1" height="1" multi="true" />
			<trigger name="14k_treadplate14" x="-130.15" y="166.2" width="1" height="1" multi="true" />
			<trigger name="14x_treadplate14" x="-118.15" y="163.8" width="1" height="1" multi="true" />
			<trigger name="14y_treadplate14" x="-120.55" y="163.8" width="1" height="1" multi="true" />
			<trigger name="14l_treadplate14" x="-122.95" y="163.8" width="1" height="1" multi="true" />
			<trigger name="14m_treadplate14" x="-125.35" y="163.8" width="1" height="1" multi="true" />
			<trigger name="14n_treadplate14" x="-127.75" y="163.8" width="1" height="1" multi="true" />
			<trigger name="14o_treadplate14" x="-130.15" y="163.8" width="1" height="1" multi="true" />
			<trigger name="14z_treadplate14" x="-118.15" y="161.4" width="1" height="1" multi="true" />
			<trigger name="140_treadplate14" x="-120.55" y="161.4" width="1" height="1" multi="true" />
			<trigger name="14p_treadplate14" x="-122.95" y="161.4" width="1" height="1" multi="true" />
			<trigger name="14q_treadplate14" x="-125.35" y="161.4" width="1" height="1" multi="true" />
			<trigger name="14r_treadplate14" x="-127.75" y="161.4" width="1" height="1" multi="true" />
			<trigger name="14s_treadplate14" x="-130.15" y="161.4" width="1" height="1" multi="true" />

			<trigger name="141_treadplate14" x="-118.15" y="159" width="1" height="1" multi="true" />
			<trigger name="142_treadplate14" x="-120.55" y="159" width="1" height="1" multi="true" />
			<trigger name="14t_treadplate14" x="-122.95" y="159" width="1" height="1" multi="true" />
			<trigger name="14u_treadplate14" x="-125.35" y="159" width="1" height="1" multi="true" />
			<trigger name="14v_treadplate14" x="-127.75" y="159" width="1" height="1" multi="true" />
			<trigger name="14w_treadplate14" x="-130.15" y="159" width="1" height="1" multi="true" />

		<trigger name="15_insertion" x="-60.9" y="129.4" width="0.5" height="0.5" multi="true" />
			<trigger name="16_offertorybox" x="-7.85" y="137" width="1" height="5" multi="true" />
			<trigger name="16_zinken" x="-7.85" y="137" width="2" height="6" multi="true" />
			<trigger name="17_checkoffer" x="-28.9" y="130.5" width="2" height="4.5" multi="true" />
			<trigger name="17_zinken" x="-28.9" y="130.5" width="3" height="4.5" multi="true" />
			<trigger name="20_supplyroom" x="-30.8" y="104.4" width="1" height="3" multi="false" />
<!--			<trigger name="20_artefacts" x="72" y="-44" width="1" height="1" multi="true" />
-->			<trigger name="22_reunion" x="-23.85" y="185.1" width="2" height="2" />
			<trigger name="22b_compensation" x="-27.4" y="181.85" width="1.5" height="2.5" multi="true" />
			<trigger name="23_exit" x="-15.4" y="192" width="2" height="2" multi="true" />
			<trigger name="23_exit_no" x="-17.4" y="192" width="1" height="1" multi="true" />
			<trigger name="24a_electric_leave" x="-48.6" y="124.0" width="1" height="1" multi="true" />
			<trigger name="24a_electric_boat" x="-48.6" y="122.0" width="2" height="2" multi="true" />
			<trigger name="24a_electriceels" x="-48.1" y="119.5" width="3" height="3" multi="true" />
			<trigger name="24b_electric_leave" x="-34.3" y="116.8" width="1" height="1" multi="true" />
			<trigger name="24b_electric_boat" x="-36.3" y="116.8" width="2" height="2" multi="true" />
			<trigger name="24b_electriceels" x="-38.9" y="116.8" width="3" height="3" multi="true" />
			<trigger name="25_zinken" x="-88.5" y="130.5" width="12" height="12" multi="true" />
			<trigger name="25_puzzle" x="-88.5" y="130.5" width="10" height="10" multi="true" />
			<trigger name="25_trap" x="-88.5" y="130.5" width="8" height="8" multi="true" />
			<trigger name="26_passphrase" x="-47.7" y="139" width="1" height="1" multi="true" />
			<trigger name="27_zinken" x="-23.85" y="178.9" width="1" height="1" multi="true" />
			<trigger name="28a_waterjar" x="-16.8" y="108.25" width="1.5" height="1.5" multi="true" />
			<trigger name="28b_waterjar" x="-16.8" y="103.75" width="1.5" height="1.5" multi="true" />
			<trigger name="28c_waterjar" x="-6.3" y="108.25" width="1.5" height="1.5" multi="true" />
			<trigger name="28d_waterjar" x="-6.3" y="103.75" width="1.5" height="1.5" multi="true" />
			<trigger name="28e_watertub" x="-11.38" y="106.05" width="3.4" height="2.3" multi="true" />

			<trigger name="31_diegame" x="-83.8" y="41.6" width="2" height="2" multi="true" />
<!--
			<trigger name="33_galery01" x="-70.1" y="92.8" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery02" x="-69.1" y="92.8" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery03" x="-68.1" y="92.8" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery04" x="-67.1" y="92.8" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery05" x="-66.1" y="92.8" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery06" x="-65.1" y="92.8" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery07" x="-70.1" y="88.9" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery08" x="-69.1" y="88.9" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery09" x="-68.1" y="88.9" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery10" x="-67.1" y="88.9" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery11" x="-66.1" y="88.9" width="0.5" height="0.5" multi="true" />
			<trigger name="33_galery12" x="-65.1" y="88.9" width="0.5" height="0.5" multi="true" />
-->
			<trigger name="34_lib01" x="-59.8" y="92.3" width="0.4" height="3" multi="true" />
			<trigger name="34_lib02" x="-58.7" y="92.3" width="0.4" height="3" multi="true" />
			<trigger name="34_lib03" x="-57.5" y="92.8" width="0.4" height="2" multi="true" />
			<trigger name="34_lib04" x="-57.5" y="90.5" width="0.4" height="2" multi="true" />
			<trigger name="34_lib05" x="-58.1" y="89.05" width="1" height="0.6" multi="true" />
			<trigger name="34_lib06" x="-60.6" y="89.05" width="1" height="0.6" multi="true" />
			<trigger name="34_lib07" x="-61.3" y="88.2" width="0.6" height="2" multi="true" />
			<trigger name="34_lib08" x="-63.5" y="87.45" width="0.4" height="3" multi="true" />
			<trigger name="34_lib09" x="-57.5" y="87.45" width="0.4" height="3" multi="true" />
			<trigger name="34_lib10" x="-58.7" y="85.85" width="2" height="0.6" multi="true" />
			<trigger name="34_lib11" x="-62.4" y="85.85" width="2" height="0.6" multi="true" />
			<trigger name="34_lib12" x="-59.6" y="84.15" width="0.6" height="3" multi="true" />
			<trigger name="34_lib13" x="-61.3" y="85.2" width="0.6" height="1" multi="true" />
			<trigger name="34_lib14" x="-61.3" y="82.8" width="0.6" height="1" multi="true" />
			<trigger name="34_lib15" x="-63.5" y="84.1" width="0.4" height="2" multi="true" />
			<trigger name="34_lib16" x="-62.5" y="82.4" width="2" height="0.6" multi="true" />
			<trigger name="34_lib17" x="-63.4" y="80.45" width="0.4" height="3" multi="true" />
			<trigger name="34_lib18" x="-58.3" y="80.9" width="2" height="0.4" multi="true" />
			<trigger name="34_lib19" x="-59.7" y="79.8" width="0.4" height="2" multi="true" />
			<trigger name="34_lib20" x="-58.3" y="78.65" width="2" height="0.4" multi="true" />
			<trigger name="34_lib21" x="-64.55" y="78.4" width="2" height="0.4" multi="true" />
			<trigger name="34_lib22" x="-65.8" y="77.0" width="0.4" height="3.5" multi="true" />
			<trigger name="34_lib23" x="-65.8" y="73.0" width="0.4" height="1" multi="true" />
			<trigger name="34_lib24" x="-65.8" y="70.6" width="0.4" height="1" multi="true" />
			<trigger name="34_lib25" x="-64.8" y="71.8" width="2" height="0.6" multi="true" />
			<trigger name="34_lib26" x="-60.9" y="71.8" width="2" height="0.6" multi="true" />
			<trigger name="34_lib27" x="-58.7" y="71.8" width="2" height="0.6" multi="true" />
			<trigger name="34_lib28" x="-57.5" y="76.8" width="0.4" height="3" multi="true" />
			<trigger name="34_lib29" x="-57.5" y="73.4" width="0.4" height="3" multi="true" />
			<trigger name="34_lib30" x="-58.9" y="76.75" width="0.4" height="0.3" multi="true" />
			<trigger name="34_lib31" x="-58.9" y="73.8" width="0.4" height="1.0" multi="true" />
			<trigger name="34_lib32" x="-57.7" y="69.25" width="0.4" height="3" multi="true" />
			<trigger name="34_lib33" x="-59.6" y="67.15" width="2" height="0.4" multi="true" />
			<trigger name="34_lib34" x="-62.3" y="67.35" width="2" height="0.4" multi="true" />
			<trigger name="34_lib35" x="-64.65" y="67.35" width="2" height="0.4" multi="true" />
			<trigger name="34_lib36" x="-60.8" y="92.9" width="0.4" height="1.5" multi="true" />
			<trigger name="34_lib37" x="-60.8" y="90.5" width="0.4" height="1.7" multi="true" />


<!-- alle Trigger um 0,6 näher zum Rand -->
			<trigger name="35_parcour01" x="-19.3" z="154.0" y="8.2" width="1.0" height="0.2" multi="true" />
			<trigger name="35_parcour01s" x="-19.35" z="153.5" y="8.2" width="0.1" height="0.1" multi="true" />
			<trigger name="35_parcour01u" x="-19.4" z="158.4" y="2" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour02a" x="-19.4" z="159.1" y="14" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour02b" x="-18.7" z="160.2" y="8.2" width="0.3" height="0.3" multi="true" />
			<trigger name="35_parcour03" x="-16.7" z="161.6" y="8.2" width="0.3" height="0.3" multi="true" />
			<trigger name="35_parcour03u" x="-16.7" z="161.6" y="2" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour03s" x="-19.4" z="159.6" y="14" width="0.1" height="0.1" multi="true" />
			<trigger name="35_parcour04a" x="-14.4" z="163.0" y="8.2" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour04b" x="-13.8" z="164.4" y="8.2" width="1.0" height="0.5" multi="true" />
			<trigger name="35_parcour04bu" x="-13.8" z="163.8" y="8.2" width="1.0" height="0.5" multi="true" />
			<trigger name="35_parcour04bs" x="-13.8" z="163.8" y="8.2" width="0.1" height="0.1" multi="true" />
			<trigger name="35_parcour05" x="-13.8" z="165.6" y="12.2" width="0.5" height="0.5" multi="true" />
<!--			<trigger name="35_parcour06" x="-12.0" z="165.5" y="12.5" width="0.5" height="0.5" multi="true" />
		<trigger name="35_parcour07" x="-12.0" z="164.25" y="9" width="0.5" height="0.5" multi="true" /> -->
			<trigger name="35_parcour06" x="-12.0" z="162.2" y="12.2" width="0.5" height="0.2" multi="true" />
			<trigger name="35_parcour06u" x="-12.0" z="157.0" y="2" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour06s" x="-12.0" z="162.8" y="12.2" width="0.1" height="0.1" multi="true" />
			<trigger name="35_parcour07" x="-12.0" z="156.0" y="12.2" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour09" x="-17.4" z="156.9" y="12.2" width="0.3" height="0.3" multi="true" />
			<trigger name="35_parcour09u" x="-17.4" z="156.9" y="2" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour09s" x="-14.7" z="157.6" y="12.2" width="0.2" height="0.5" multi="true" />
			<trigger name="35_parcour10a" x="-20.9" z="155.8" y="12.2" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour10b" x="-22.5" z="155.8" y="12.2" width="0.2" height="0.5" multi="true" />
			<trigger name="35_parcour10bu" x="-23.7" z="155.6" y="2.0" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour10bs" x="-21.9" z="155.8" y="12.2" width="0.1" height="0.1" multi="true" />
			<trigger name="35_parcour11" x="-24.6" z="155.6" y="14.5" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour11b" x="-25.6" z="155.6" y="14.5" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour12" x="-24.6" z="161.4" y="14.5" width="1.0" height="0.2" multi="true" />
			<trigger name="35_parcour12u" x="-22.7" z="165.6" y="2.0" width="0.5" height="0.5" multi="true" />
			<trigger name="35_parcour12s" x="-24.6" z="160.9" y="14.5" width="0.1" height="0.1" multi="true" />
			<trigger name="35_parrope13" x="-22.5" z="166.1" y="14.5" width="0.5" height="0.5" multi="true" />

			<trigger name="35_rope1" x="-23.6" z="165.1" y="2.0" width="0.5" height="0.5" multi="true" />
			<trigger name="35_zinken" x="-23.6" z="165.1" y="2.0" width="1.5" height="1.5" multi="true" />
			<trigger name="35_rope2" x="-24.1" z="165.6" y="14.5" width="0.5" height="0.5" multi="true" />

			<trigger name="35_Height1" x="-17.5" z="158.0" y="14" width="16.5" height="20" multi="true" />
			<trigger name="35_Height2" x="-17.5" z="158.0" y="11" width="16.5" height="20" multi="true" />
			<trigger name="35_Height3" x="-17.5" z="158.0" y="2" width="19" height="22" multi="true" />

<!--			<trigger name="98a_Claustrophobia_03_04" x="-114" y="61" width="25" height="22" multi="true" />
-->
			<trigger name="98a_claustrophobia_m1098_p0985_p9999_nxxxxx_05_04" x="-109.8" y="98.5"  width="4" height="3" multi="true" />
			<trigger name="98b_claustrophobia_m1051_p0944_p9999_nexxxx_05_04" x="-105.1" y="94.4"  width="2.5" height="2.5" multi="true" />
			<trigger name="98c_claustrophobia_m1230_p1710_p9999_nxxxxx_04_03" x="-123.0" y="171.0"  width="2" height="2" multi="true" />
			<trigger name="98d_claustrophobia_m0605_p1797_p9999_xexxxx_03_04" x="-60.5" y="179.7"  width="2" height="2" multi="true" />
			<trigger name="98e_claustrophobia_m0290_p1500_p9999_xexxxx_04_06" x="-29" y="150"  width="3" height="3" multi="true" />

			
Eingang			<trigger name="99a_teleport" x="-68.5" y="49.5" width="9" height="9" />
Kreuzung Sternenschweif			<trigger name="99b_teleport" x="-116.5" y="88.9" width="3.5" height="3.5" />
Opferstock/Labyrinth			<trigger name="99c_teleport" x="1" y="125.5" width="4" height="4" />
Trittplattenraum			<trigger name="99d_teleport" x="-125.5" y="152" width="7" height="7" />
Ende Unterfährung			<trigger name="99e_teleport" x="-63" y="179.7" width="2" height="2" />
Kohlebecken			<trigger name="99f_teleport" x="-23.5" y="169.5" width="9" height="7" />

		</triggers>
	</floor>
	<script><![CDATA[
var p1 = "phextemp_";
var onlever = 0;
var waygone = [];
var lookuptable = { "g":131, "f":127, "e":128, "d":136, "c":134, "b":105, "a":115,
					"k":139, "j":148, "i":147, "h":146,
					"o":150, "n":142, "m":149, "l":151,   "y":111, "x":124, 
					"s":144, "r":133, "q":109, "p":113,   "0":122, "z":121,
					"w":145, "v":102, "u":108, "t":135,   "2":143, "1":117 };
		
var plate = Number(getSpecialState("phex0_Z_treadplateZ_plate"));
var lastPlate = Number(getSpecialState("phex0_Z_treadplateZ_lastplate"));
var opendoorset2 = 0;
var doorset1 = [	1188, 1113, 1111, 1124, 
					1169, 1165, 1166, 1174, 1172, 1171, 
					1189, 1112, 1125, 
					1168, 1182, 1183, 1176, 1175,
					1187, 1202, 1119, 1108, 1121, 1123, 
					1145, 1152, 1153, 1149, 1179, 1178,
					1199, 
					1144, 1148, 1147, 1160, 1159, 1161, 1163,
					1194, 1201, 1120, 1101, 1136, 1139, 1130, 
					1214, 1157, 1156, 1154,
					1193, 1116, 
					1208, 1207, 1211, 1210, 1222, 
					1191, 1204, 1104, 
					1206, 1221, 1217, 1218, 1224, 1226,
					1192, 1196, 1103, 1134, 1141, 1128 ];
var doorset2 = [	1190, 1107, 1105, 1126, 
					1167, 1173, 1170,
					1186, 1115, 1109, 1106, 1122, 
					1181, 1180, 1184, 1177, 
					1114, 1132, 
					1151, 1150, 1164, 
					1195, 1203, 1118, 1100, 1137, 1138, 1131, 
					1146, 1162, 
					1143, 
					1212, 1213, 1185, 1158, 1155, 
					1205, 1200, 1102, 1135, 1140, 1129, 
					1216, 1215, 1209, 1223,
					1198, 1117, 1133, 1142, 1127, 
					1220, 1219, 1225, 
					1197, 1110];

var curjar = 0;
var idjar1 = "waterjar1", idjar2 = "waterjar2", idjar3 = "waterjar3", idjar4 = "waterjar4";			
var contents = [0,0,0,0];
var maxesHard = [6,7,8,9];
var itm;
var falltime1 = 0, falltime2 = 0, falltime3 = 0;
var namenarray = [];
var textkey = "", zinken = [];
var trigger;
var chest;

// Called when the Dungeon is initialized, with "initial=true" for first time entry
// and "initial=false" for loaded or returned or other time entry
function InitDungeon( initial ) {
	if( initial ){
		setSpecialState("map.dungeon_RAthreshold",3);

		setDoorState(93, 2);	//Geheimtür push
		setDoorState(74, 2);	//tür Galerie/Geldscheiäer
		setDoorState(72, 2);	//tür Boot/Phextruhe
		setDoorState(69, 2);	//tür Labyrinth
		setDoorState(68, 4);	//tür vor Ausgang
		setDoorState(712, 4);	//tür vor Ausgang mit Passphrase
		setDoorState(703,2);	// leere Tugend-Säule
		setDoorState(706,2);	// leere Tugend-Säule

		for(var j = 0; j < doorset1.length; j++){
			setDoorState(doorset1[j], 2);
		}
		setSpecialState("phex0_16_offertorybox_moneyspent", 0);

		setGeneralState("phex0_I1_generalstate",{"doublelist":[],"val":1});
		setGeneralState("phex0_I2_generalstate",{"doublelist":[],"val":1});
		setGeneralState("phex0_I3_generalstate",{"doublelist":[],"val":1});
		setGeneralState("phex0_I4_generalstate",{"doublelist":[],"val":1});
		setGeneralState("phex0_Is1_generalstate",{"doublelist":["statuetteM",1],"val":1});
		setGeneralState("phex0_Is2_generalstate",{"doublelist":["statuetteE",1],"val":1});
		setGeneralState("phex0_Is3_generalstate",{"doublelist":["statuetteG",1],"val":1});
		setGeneralState("phex0_Is4_generalstate",{"doublelist":["statuetteK",1],"val":1});
		setGeneralState("phex0_Is5_generalstate",{"doublelist":[],"val":1});
		setGeneralState("phex0_Is6_generalstate",{"doublelist":[],"val":1});
		setGeneralState("phex0_2_generalstate",{"doublelist":["supplypack",10],"val":1});
		setGeneralState("phex0_6_generalstate",{"doublelist":["recunread_moneycrapper",1],"val":1});
		setGeneralState("phex0_8_generalstate",{"doublelist":["recunread_magicpotion",1],"val":1});
		setGeneralState("phex0_20_generalstate",{"doublelist":["phexshield",1, "phexhelmet", 1],"val":1});
		setGeneralState("phex0_26_generalstate",{"doublelist":["passphrase",1],"val":1});
		setGeneralState("phex0_28a_generalstate",{"doublelist":["waterjar1",1],"val":1});
		setGeneralState("phex0_28b_generalstate",{"doublelist":["waterjar2",1],"val":1});
		setGeneralState("phex0_28c_generalstate",{"doublelist":["waterjar3",1],"val":1});
		setGeneralState("phex0_28d_generalstate",{"doublelist":["waterjar4",1],"val":1});
		setGeneralState("phex0_35_generalstate",{"doublelist":[],"val":1});
		setGeneralState("phex0_35safty_generalstate",{"doublelist":[],"val":1});

		if (getSpecialState("phex0_1_entrance_gotXP") == ""){
			setSpecialState("phex0_1_entrance_gotXP",1);
			awardXP("xp_phexbetreten", -1, 10);
		}
		if (getSpecialState("tiefhusen.hensger_angry") == "1") startDialogueAt("tiefh_verschleppung",5);
		else startDialogueAt("tiefh_hensger",53);
	}
	setSpecialState("map.raumangstaktiv",1);
	startDialogueAt("raumangst","start");

}

function yesnodlg( name, textid ) {
	var param = {"caption":p1+textid+"_hl","text":p1+textid,"btcap1":"text_yes","btcap2":"text_no"};
	showDialogue( name, param );
}
function yesnodlg2( name, hlid, textid ) {
	var param = {"caption":p1+hlid+"_hl","text":p1+textid,"btcap1":"text_yes","btcap2":"text_no"};
	showDialogue( name, param );
}
function yesnodlg2name( name, hlid, textid, repname ) {
	var param = {"caption":p1+hlid+"_hl","text":(repname)?getLangString(p1+textid,[repname]):p1+textid,"btcap1":"text_yes","btcap2":"text_no"};
	showDialogue( name, param );
}

function sdlg( name, textid, bt1, bt2, bt3, bt4, bt5 ) {
	var param = {"caption":p1+textid+"_hl","text":p1+textid};
	if( bt1 != null ) param["btcap1"] = p1+bt1;
	if( bt2 != null ) param["btcap2"] = p1+bt2;
	if( bt3 != null ) param["btcap3"] = p1+bt3;
	if( bt4 != null ) param["btcap4"] = p1+bt4;
	if( bt5 != null ) param["btcap5"] = p1+bt5;
	showDialogue( name, param );
}
// Folgedialog; hlid gibt dabei die Überschrift von sdlg an
function sdlg2( name, hlid, textid, bt1, bt2, bt3, bt4 ) {
	var param = {"caption":p1+hlid+"_hl","text":p1+textid};
	if( bt1 != null ) param["btcap1"] = p1+bt1;
	if( bt2 != null ) param["btcap2"] = p1+bt2;
	if( bt3 != null ) param["btcap3"] = p1+bt3;
	if( bt4 != null ) param["btcap4"] = p1+bt4;
	showDialogue( name, param );
}
// Folgedialog mit Namen ersetzen ohne Buttonbeschriftung
function sdlgname( name, hlid, textid, repname ) {
	var param = {"caption":p1+hlid+"_hl","text":(repname)?getLangString(p1+textid,[repname]):p1+textid};
	showDialogue( name, param );
}
// Folgedialog mit Namen UND Personalpronomen ersetzen ohne Buttonbeschriftung
function sdlgname2( name, hlid, textid, repname, pp ) {
	var param = {"caption":p1+hlid+"_hl","text":(repname)?getLangString(p1+textid,[repname, pp]):p1+textid};
	showDialogue( name, param );
}
// Folgedialog mit Namen UND Personalpronomen ersetzen ohne Buttonbeschriftung
function sdlgname3( name, hlid, textid, repname, pp, etc ) {
	var param = {"caption":p1+hlid+"_hl","text":(repname)?getLangString(p1+textid,[repname, pp, etc]):p1+textid};
	showDialogue( name, param );
}

// Called when a trigger is entered, which is of the format "<floorid>_<triggername>", even if there is only floor 0
function OnTrigger( which ) {
	resid2 = -1;
	trigger = which;
	
//	debugLog("current Trigger: "+which);

	if ( which.lastIndexOf( "_zinken" ) >= 0 )		 	{ phex0_zinken(which); return true; }
	if ( which.lastIndexOf( "_verminfight" ) >= 0 ) 	{ sdlg(which, 71); return true; }
	if ( which.lastIndexOf( "_coalbowl" ) >= 0 )	 	{ sdlg("", 44); return true; }
	if ( which.lastIndexOf( "_treadplateK" ) >= 0 ) 	{ phex0_K_treadplateK(which, getPartyCount() ); return true; }
	if ( which.lastIndexOf( "_treadplateZ" ) >= 0) 		{ phex0_Z_treadplateZ(which); return true; }

	if ( which.lastIndexOf( "_secretdoor_" ) >= 0 ) 	{ phex_secretdoor(which); return true; }
	if ( which.lastIndexOf( "_treadplate4" ) >= 0 ) 	{ phex0_4_treadplate4(which, getPartyCount() ); return true; }
	if ( which.lastIndexOf( "_treadplate14" ) >= 0) 	{ phex0_14_treadplate14(which); return true; }
	if ( which.lastIndexOf( "_electriceels" ) >= 0 ) 	{ phex0_24_electriceels(which); return true;	}
	if ( which.lastIndexOf( "_waterjar" ) >= 0 ) 		{ phex0_28_waterjar(which); return true; }
	if ( which.lastIndexOf( "34_lib" ) >= 0 ) 			{ phex0_34_lib(which); return true; }
	if ( which.lastIndexOf( "35_parcour" ) >= 0 ) 		{ phex0_35_parcour(which); return true; }
//	if ( which.lastIndexOf( "35_height" ) >= 0 ) 		{ phex0_35_height(which); return true; }
	if ( which.lastIndexOf( "_teleport" ) >= 0 ) 		{ unlockTeleportPoint(); return true; }

	switch( which ) {
		case "0_I_virtuequiz": 		if (getDoorState(207) != 2) phex0_I_virtuequiz(0); break;
		case "0_I1_virtuestatue": 	startDialogueAt("phextemp0_I_virtuestatue", "1a"); break;
		case "0_I2_virtuestatue": 	startDialogueAt("phextemp0_I_virtuestatue", "1b"); break;
		case "0_I3_virtuestatue": 	startDialogueAt("phextemp0_I_virtuestatue", "1c"); break;
		case "0_I4_virtuestatue": 	startDialogueAt("phextemp0_I_virtuestatue", "1d"); break;
		case "0_I5_virtuestatue": 	startDialogueAt("phextemp0_I_virtuestatue", "1e"); break;
		case "0_I6_virtuestatue": 	startDialogueAt("phextemp0_I_virtuestatue", "1f"); break;
		case "0_J0_coalkey": 		if (getSpecialState("phex0_J0_coalkey_visited") == "2") { phex0_J0_coalkey("phex0_J0_coalkey1"); } else { sdlg("phex0_J0_coalkey1", 44); } break;
		case "0_K_pitfallK": 		phex0_K_pitfallK(0); break;
		case "0_K_pitfallK_instinct": phex0_K_pitfallK_instinct(0); break;
		case "0_L_leverL": 			phex0_L_leverL(0); break;
		case "0_M1_pushM": 			startDialogueAt("phextemp0_M_push", "1a"); break;
		case "0_M2_pushM": 			startDialogueAt("phextemp0_M_push", "1b"); break;
		case "0_M3_pushM": 			startDialogueAt("phextemp0_M_push", "1c"); break;
		case "0_1_entry": 			
		case "0_23_exit": 			phex0_0_leaveTemple(which); break;
		case "0_2_supplypacks": 	phex0_2_supplypacks(0); break;
		case "0_6_moneycrapper":	if (checkstorage("phex0_6") > 0 ) phex0_6_moneycrapper(0); break;
		case "0_8_magicpotion": 	if (checkstorage("phex0_8") > 0 ) phex0_8_magicpotion(0); break;
		case "0_9_pitfall9": 		phex0_9_pitfall9(0); break;
		case "0_11a_baldower": 		var char = getBest({"which":"gefahrensinn","type":"skill"}); sdlgname2("", 130, 130, char.shortname, getLangString("text_3rdperson_"+getGender(char.charid),[])); break;
		case "0_11_baldower": 		if (getDoorState(204) == 0) phex0_11_baldower(0); break;
		case "0_11b_baldower_gold": phex0_11b_baldower_gold(0); break;
		case "0_12_balance": 		startDialogueAt("coins", 1); break;
		case "0_14_sign": 			sdlg("phex0_14_sign1", 110); break;
		case "0_16_offertorybox": 	phex0_16_offertorybox(0); break;
		case "0_17_checkoffer": 	phex0_17_checkoffer(0); break;
		case "0_20_supplyroom": 	sdlg("", 150); break;
		case "0_22_reunion": 		startDialogue("phex0_22_reunion1"); break;
		case "0_22b_compensation": 	if (getSpecialState("phex0_22_reunion_done") == "1") startDialogueAt("phextemp0_22_sandbox", 1); break;
		case "0_24a_electric_boat": startDialogueAt("phextemp0_24_boat", "1a"); break;
		case "0_24b_electric_boat": startDialogueAt("phextemp0_24_boat", "1b"); break;
		case "0_25_puzzle":			startDialogueAt("phextemp0_25_trap", 1); break;
		case "0_25_trap":			phex0_25_trap(); break;
		case "0_26_passphrase": 	if (checkstorage("phex0_26") > 0 ) phex0_26_passphrase(0); break;
		case "0_28e_watertub": 		phex0_28e_watertub(0); break;
		
		case "0_31_diegame": 		startDialogueAt("phextemp0_31", 0); break;
		case "0_34_lib_139b": 		sdlg("0_34_lib_history", 138, "139b"); break;
//		case "0_35_Height1": 		debugLog("Trigger1"); break;
//		case "0_35_Height2": 		debugLog("Trigger2"); break;
		case "0_35_Height3": 		phex0_falldamage(); break;
		case "0_35_rope1":			phex0_35_rope1(0); break;
		case "0_35_rope2":			phex0_35_rope2(0); break;
		case "0_35_parrope13":		phex0_35_parrope13(0); break;
	
		// unhandled triggers should return false
		default: return false;
	}
	return true;
}

function OnTriggerLeft( which ) {
	resid2 = -1;

	if ( which.lastIndexOf( "_treadplateK" ) >= 0 ) 	{ phex0_K_treadplateK(which, -getPartyCount() ); return true; }
	if ( which.lastIndexOf( "_treadplate4" ) >= 0 ) 	{ phex0_4_treadplate4(which, -getPartyCount() ); return true; }
	if ( which.lastIndexOf( "_treadplate14" ) >= 0 ) 	{ phex0_14_treadplate14_lift(which); return true; }
	if ( which.lastIndexOf( "_claustrophobia_" ) >= 0 ) { claustrophobia(which); return true; }
	switch( which ) {
		case "0_17_checkoffer": 		phex0_17_checkoffer("OnLeave"); break;	
		case "0_35_Height1": 			falltime1 = getTime(); break;
		case "0_35_Height2": 			falltime2 = getTime(); break;
		default: return false;
	}
	return true;
}

function OnDialogResult( which, resid ) {
	if ( which.lastIndexOf( "_zinken" ) >= 0 ) 			{ phex0_zinken(which); return; }

	if ( which.lastIndexOf( "_verminfight" ) >= 0 ) 	{ startBattle("phex"+which); return; }
	if ( which.lastIndexOf( "_SDtryAgain" ) >= 0 ) 		{ if (resid == 0) { phex_secretdoor_open(which); } return; }
	if ( which.lastIndexOf( "_secretdoor_" ) >= 0 ) 	{ phex_secretdoor_open(which); return; }
	if ( which == "phextemp0_I_virtuestatue1") {	
		if (resid2 == 0) {
			zeilespalte = rollRandom(0,1);
			choice = rollRandom(1,5);
			startDialogueAt("phextemp0_I_virtuestatue", 14 ); 
		}
	}
	if ( which.lastIndexOf( "phex0_J0_coalkey" ) >= 0 ) 		{ phex0_J0_coalkey(which, resid); return true; }
	if ( which.lastIndexOf( "phex0_6_moneycrapper" ) >= 0 ) 	{ phex0_6_moneycrapper(which, resid); return true; }
	if ( which.lastIndexOf( "phex0_8_magicpotion" ) >= 0 ) 		{ phex0_8_magicpotion(which, resid); return true; }
	if ( which.lastIndexOf( "11_baldower" ) >= 0 ) 				{ phex0_11_baldower(which); return true; }
	if ( which.lastIndexOf( "11b_baldower_gold" ) >= 0 ) 		{ phex0_11b_baldower_gold(which, resid); return true; }
	if ( which.lastIndexOf( "phex0_15_doorwithoutlock" ) >= 0 ) { phex0_15_doorwithoutlock(which); return true; }
	if ( which.lastIndexOf( "phex0_16_offertorybox" ) >= 0 )	{ phex0_16_offertorybox(which, resid); return true; }
	if ( which.lastIndexOf( "phex0_26_passphrase" ) >= 0 ) 		{ phex0_26_passphrase(which, resid); return true; }
	if ( which.lastIndexOf( "_waterjar" ) >= 0 && resid == 0 )	{ phex0_28_waterjar(which, resid); return true; }
	if ( which.lastIndexOf( "_history" ) >= 0 ) 				{ phex0_34_lib_incTalent(which); return true; }
	if ( which.lastIndexOf( "_godscults" ) >= 0 ) 				{ phex0_34_lib_incTalent(which); return true; }
	if ( which.lastIndexOf( "35_parcour" ) >= 0 ) 				{ if (resid != 1) phex0_35_parcour(which, resid); return true; }
	if ( which.lastIndexOf( "phex0_35_rope1" ) >= 0 ) 			{ if (resid != 1) phex0_35_rope1(which); return true; }

	switch( which ) {
		case "0_1_entry": 						
		case "0_23_exit": 						phex0_0_leaveTemple(which, resid); break;
		case "phex0_I_virtuequiz1": 			if( resid != 4 ) { phex0_I_virtuequiz(which, resid); } break;
		case "phex0_K_pitfallK1": 				sdlg2("", 79, "79b"); break;
		case "phex0_L_leverL1": 				phex0_L_leverL(which, resid); break;
		case "phex0_2_supplypacks1": 			if( resid == 0 ) phex0_2_supplypacks(which); break;
		case "phex0_14_sign1":					sdlgname("", 110, "110b", getName(getLeaderID()) ); break;
		case "phex0_24a_electriceels":			moveToTrigger("0_24a_electric_leave", 180); break;
		case "phex0_24b_electriceels":			moveToTrigger("0_24b_electric_leave", 270); break;
		case "phex0_27_doorwithnumbers1":		if( resid == 0 ) { phex0_27_doorwithnumbers(which); } break;
		case "phex0_28e_watertub1":		 		if( resid == 0 ) { phex0_28e_watertub(which); } break;
		case "phex0_35_rope2A":		 			if( resid == 0 ) { phex0_35_rope2(which); } break;
		case "phex0_35_parrope13A":		 		if( resid == 0 ) { phex0_35_parrope13(which); } break;
		case "phex0_35_saftyrope1":		 		if( resid == 0 ) { phex0_35_saftyrope(which); } break;
		default: return false;
	}
	return true;
}
function OnPassTime( which ) {}

// custom defined function, can be removed

function phex0_0_leaveTemple(which, resid) {
//debugLog(resid);
	if (resid == null) yesnodlg(which, 129);
	if (resid == 0) {
		startDialogueAt("raumangst","ende");
		if (which == "0_1_entry") {
			setSpecialState("map.phex0_0_leaveTemple_openedEntrance", 1);
			jumpToLocation({"where":"tiefhusen","x":13.2,"y":0,"z":-49,"rot":0}); 
		}
		if (which == "0_23_exit") jumpToLocation({"where":"tiefhusen","x":13.25,"y":0,"z":-47.4,"rot":0}); 
		startDialogueAt("phex0_leave_fakes","1");
	}
	if (resid == 1 && which == "0_23_exit") { moveToTrigger("0_23_exit_no", 270); }
}

function takeoffstorage(which, limit, limitweight, filter, justtake, dontLeaveQuest, autoclose, dontLeavePersonal, callback) {
	passTime("", 1/60);
	//Öffnen des Item-Containers
	if( limit == null ) limit = 35;
	if( limitweight == null ) limitweight = 10000;
	if( filter == null || filter == "" ) filter = ""
//	["General", "Weapon", "Armor", "Equippable", "Herb", "Potion", "Poison", "Document", "Tool", "Ammo", "Ingredient", "Jewelry"];
	if( justtake == null ) justtake = false;
	if( dontLeaveQuest == null ) dontLeaveQuest = true;
	if( autoclose == null ) autoclose = true;
	if( dontLeavePersonal == null ) dontLeavePersonal = true;
	if( callback == null ) callback = "";
	showItemContainer({	"caption":getLangString(which+"_hl",[]),"desc":" ", "limit":limit, "limitweight":limitweight, "filter":filter, 
						"itemset":which+"_generalstate","linked":true,"who":0, "dontLeavePersonal":dontLeavePersonal, "justtake":justtake,
						"dontLeaveQuest":dontLeaveQuest, "autoclose":autoclose, "callback":callback});
	return "tobecontinued";
}
function checkstorage(which) {	
	//Ermittlung der Anzahl der Items im Container
	var gs = getGeneralState(which+"_generalstate");
	if (typeof(gs.items) == "object") {	notempty = 1;	} else { notempty = 0; }
	return notempty;
}


function phex_secretdoor(which) {
	var door = which.slice(16,21);
//	debugLog("door: "+door);
	if (door == "0_721") return;
	if (door == "0_721" && getDoorState("0_720") == 2) return;
	var mod = 0;
	var known = Number(getSpecialState("phex_secretdoor_"+which+"_known"));
//	var mod2 = Math.round( Math.max(0, 1+known-getTime())*2*getCharAttribute("KL", getLeaderID()) );
	switch (door) {
		case "0_99":	mod = -6; textID = 28; break;
//		case "0_93":	mod = -6; textID = 28; break;
		case "0_97":	mod = -6; textID = 51; break;
		case "0_94":	mod = -6; textID = 51; break;
		case "0_95":	mod = -6; textID = 52; break;
		case "0_96":	mod = -6; textID = 52; break;
		case "0_720":	mod = 0; textID = 52; break;
		case "0_721":	mod = 0; textID = 52; door = "0_720"; break;
		case "0_101":	mod = 0; textID = 52; break;
		case "0_100":	mod = -6; textID = 51; break;
		case "0_207":	mod = -6; textID = 52; break;
		case "0_204":	mod = -6; textID = 28; break;
		case "0_98":	mod = -6; textID = 52; break;
		case "0_205":	mod = -6; textID = 52; break;
	}
	if (getDoorState(door) != 2) {
		var best = getBest({"which":"KL","type":"attrib"});
		if (known > getTime() -getCharAttribute("KL",best.charid)/2 *24) {
			sdlgname(which, 28, "28d", getName(best.charid) );
		} else { rcheck = rollCheck({"who":getLeaderID(),"which":"sinnensch", "type":"skill", "mod":mod}); }
		if (rcheck.ok) {
			setSpecialState("phex_secretdoor_"+which+"_known",getTime());
			lookAtTrigger( which );
			sdlgname(which, 28, textID, getName(rcheck.id) );
		}
	}
}
function phex_secretdoor_open(which) {
	var door = which.slice(16,21);
	switch (door) {
		case "0_99":	mod = -3; break;
//		case "0_93":	mod = -3; break;
		case "0_97":	mod = -3; break;
		case "0_94":	mod = -3; break;
		case "0_95":	mod = -3; break;
		case "0_96":	mod = -3; break;
		case "0_720":	mod = -3; break;
		case "0_721":	mod = -3; break;
		case "0_101":	mod = -3; break;
		case "0_100":	mod = -3; break;
		case "0_207":	mod = -3; break;
		case "0_204":	mod = -3; break;
		case "0_98":	mod = -3; break;
		case "0_205":	mod = -3; break;
	}

/*	var known = Number(getSpecialState("phex_secretdoor_"+which+"_known"));
	i_max = 1;
	if (known > getTime() -getCharAttribute("KL",best.charid)/2 *24) var i_max = 7;
*/
	for (var i=0; i <= 6; i++) {
		if (i == 0) var who = getLeaderID();
		if (i == 1) who = "best";
		rcheck = rollCheck({"who":who,"which":"FF", "type":"attrib", "mod":mod});	
		var dauer = i*5;
		passTime("", 5/60);
		if (rcheck.ok) {
			if (door == "0_721" || door == "0_100" || door == "0_207" || door == "0_204" || door == "0_98" || door == "0_205") { 
	//			sdlgname("", 109, 111, getName(rcheck.id)); 
				sdlgname("", 109, 40, getName(rcheck.id)); 
				return;
			}
			setDoorState(door, 2);
			awardXP("xp_phexsecretdoor", rcheck.id, 2);
			if (i == 0) { 
				sdlgname("", 28, "28c", getName(rcheck.id) ); 
			} else {
				sdlgname2("", 28, "28a", getName(rcheck.id), dauer );
			}
			break;
		} else {
			yesnodlg2name(which+"_SDtryAgain", 28, "28b", getName(rcheck.id) );
		}
	}
}

function phex0_zinken(which) {
	return;
	passTime("", 1/60);
	textkey = "phex"+which;
//	if (textkey == "phex0_25_zinken") autoSave();
	var seen = getSpecialState("map.zinken_seen").split(",");
	if (seen.length > 0) {
		for (var i=0; i < seen.length;i++) {
			if (textkey == seen[i]) { return; }
		}
	}
	var best = getBest({"which":"gassenwissen","type":"skill"});
	rcheck = rollCheck({"which":"sinnensch","who":best.charid,"type":"skill", "mod":best.value });
	if (!rcheck.ok) return;
	
	switch (textkey) {
		case "phex0_0_zinken":		zinken = ["032", "001", "045", "064"]; break;
		case "phex0_1_zinken":		zinken = ["074"]; break;
		case "phex0_2_zinken":		zinken = ["073"]; break;
		case "phex0_3_zinken":		zinken = ["022"]; break;
		case "phex0_4_zinken":		zinken = ["024"]; break;
		case "phex0_5_zinken":		zinken = ["052", "074"]; break;
		case "phex0_7_zinken":		zinken = ["063", "014"]; break;
		case "phex0_9_zinken":		zinken = ["024", "062"]; break;
		case "phex0_10_zinken":		zinken = ["015", "063"]; break;
		case "phex0_16_zinken":		zinken = ["084"]; break;
		case "phex0_17_zinken":		zinken = ["053"]; break;
		case "phex0_25_zinken":		zinken = ["067", "061"]; break;
		case "phex0_27_zinken":		zinken = ["055"]; break;
		case "phex0_28L_zinken":	zinken = ["023"]; break;
		case "phex0_28R_zinken":	zinken = ["073", "023"]; break;
		case "phex0_B_zinken":		zinken = ["068", "013"]; break;
		case "phex0_D1_zinken":		zinken = ["017", "011", "068"]; break;
		case "phex0_D2_zinken":		zinken = ["069", "021"]; break;
		case "phex0_J0_zinken":		zinken = ["016"]; break;
		case "phex0_K_zinken":		zinken = ["067"]; break;
	}
	startDialogueAt("dlg_zinken", 1);
}

/*
function phex0_poisonedchest(which, resid) {
	if (resid == null) sdlg(which, 161, "161a", "161b", "161c");
	chest = which;
	if (resid == 0) chooseSingleCharacter( getLangString("phextemp_162",[]), "phex0_poisonedchest_chooseLockpick");
	if (resid == 1) chooseSingleCharacter( getLangString("phextemp_163",[]), "phex0_poisonedchest_chooseForamen");
}
function phex0_poisonedchest_chooseLockpick(who) {
	if (who == -1) return;
	passTime(5/60);
//	"foramen"
	rcheck = rollCheck( {"which":"FF", "type":"attrib", "mod":0, "who":who} );
	rcheck = rollCheck2({"which":"schloesser", "type":"skill", "mod":mod, "who": who});
	if (rcheck.ok) {
		awardXP("xp_blutbolzen", rcheck.id, 5);
		setSpecialState("blut"+which.slice(0,15)+"_disarmed", 1);
		sdlgname("", 79, 82, getName(rcheck.id));
	} else { if ( which == "2_9_quarreltrapshoot" || getSpecialState("blut2_15_quarreltra_disarmed") != "2")
		dealDamage({"amount":"2W6+5","who":rcheck.id,"type":"physical", "reason":"quarreltrap"});
		sdlgname2("", 79, 81, getName(rcheck.id), getLangString("text_3rdperson_"+getGender(rcheck.id),[]) );
	}
}
*/

function phex0_falldamage() {
	var namenarray = [];
	falltime3 = getTime(); 
	var damageMax = 0;
	if (falltime3 - falltime1 < 0.0006 && falltime3 != falltime1 ) { damageMax = 4; }
	else { if (falltime3 - falltime2 < 0.0004 && falltime3 != falltime2 ) damageMax = 2; }
//	debugLog(falltime3 - falltime1);
	falltime1 = 0; 
	falltime2 = 0;
	if (damageMax > 0) {
		for (var j = getPartyCount()-1; j >= 0; j--){
			damage = damageMax; 
			if (canAct(j)) {
				rcheck2 = rollCheck({"type":"skill","which":"koerperb","who":j, "mod":0});
				if (rcheck2.ok) damage = damage - rcheck2.resrem-1;
			}
			if (damage > 0) {
				namenarray[namenarray.length] = getName(j);
				dealDamage({"amount":damage+"W4+"+damage,"who":j,"type":"ignorers", "reason":"fall"}); 
			}
		}
	}
	if (namenarray.length > 0) phex0_falldamageMessage(namenarray);
}


function phex0_I_virtuequiz(which, resid){
	if (which == 0) { 
		passTime("", 1/60);
		var gs = getGeneralState("phex0_I1_generalstate");
		var count = 0;
		if (typeof(gs.items) == "object") {
			for (var i=0; i < gs.items.length; i++) {
				if (gs.items[i].id == "statuetteE") count++;
				if (gs.items[i].id == "statuetteG") count++;
				if (gs.items[i].id == "statuetteK") count++;
				if (gs.items[i].id == "statuetteM") count++;
			}
		}
		if (count == 4) {
			setSpecialState("phextemp0_31_strangerGone", 1);
			setDoorState(207, 2);
			setDoorState(714,2)
			awardXP("xp_phexvirtuequiz", -1, 20);
			sdlg2("", 102, "102b"); 
			return;
		}
		sdlg("phex0_I_virtuequiz1", 102, 103, 104, 105, 106, 107); 
	}
	if (which == "phex0_I_virtuequiz1") {
//		chooseItem( {"showequipped":false,"needchar":true, "action": p1+'103', "callback": "phex0_I_virtuequiz_chooseItem" } );
		takeoffstorage("phex0_I"+(resid+1), 4, 500, "General", false, false, false);
	}
}

function phex0_J0_coalkey(which, resid) {
	var visited = getSpecialState("phex0_J0_coalkey_visited");
	if (visited == "") setSpecialState("phex0_J0_coalkey_visited", 1);
	if (which == "phex0_J0_coalkey1" && visited == "1") {
		rcheck = rollCheck({"who":getLeaderID(),"which":"sinnensch", "type":"skill", "mod":-4});	
		if (rcheck.ok) {
			setSpecialState("phex0_J0_coalkey_visited", 2);
			sdlg2("", 44, "44b");
			return;
		}
	}
	if (which == "phex0_J0_coalkey1" && visited == "2") {
		chooseSingleCharacter( p1+"44c", "selectCharCoal" );
	}
	if (which == "phex0_J0_coalkey2") {
		showItemset("phex0_J0_coalkey_itemset");
	}
}
function selectCharCoal( choice ) {
	if (choice == -1) return;
	passTime("", 2/60);
	sdlgname("phex0_J0_coalkey2", 44, "44d", getName(choice));
}

function phex0_K_pitfallK_instinct() {
	if ( getDoorState(202) == 0 && getDoorState(203) == 0 && getSpecialState("phex0_K_pitfallK_triggered") != "1" ) {
		autoSave();
		rcheck = rollCheck({"who":getLeaderID(),"which":"gefahrensinn", "type":"skill", "mod":-4});		
		if (rcheck.ok) sdlgname("", 131, 131, getName(rcheck.id));
	}
}
function phex0_K_pitfallK( which ) {
	if ( getDoorState(202) == 0 && getDoorState(203) == 0 && getSpecialState("phex0_K_pitfallK_triggered") != "1" ) {
		setSpecialState("phex0_K_pitfallK_triggered", 1);
		setDoorState(7060,2);
		for(var j = 0; j < getPartyCount(); j++){
			dealDamage({"amount":"5W4+5","who":j,"type":"physical", "reason":"bolt trap"}); 
		}
		passTime("", 3/60);
		sdlg("phex0_K_pitfallK1", 79);
	}
}
function phex0_K_treadplateK( which, delta ) {
	if (which == "0_K1_treadplateK") {
		var onplateK1 = Number(getSpecialState("phex0_K_treadplateK_onplateK1") );
		onplateK1 = Math.max(0, onplateK1 + delta);
		setSpecialState("phex0_K_treadplateK_onplateK1", onplateK1);
//		debugLog(onplateK1);
		if (onplateK1 > 0) { setDoorState(202,2); } else { setDoorState(202,0); }
	}
	if (which == "0_K2_treadplateK") {
		var onplateK2 = Number(getSpecialState("phex0_K_treadplateK_onplateK2") );
		onplateK2 = Math.max(0, onplateK2 + delta);
		setSpecialState("phex0_K_treadplateK_onplateK2", onplateK2);
//		debugLog(onplateK2);
		if (onplateK2 > 0) { setDoorState(203,2); } else { setDoorState(203,0); }
	}
}

function phex0_L_leverL(which, resid) {
	if (which == 0) yesnodlg("phex0_L_leverL1", 113);
	if (which == "phex0_L_leverL1") {
		if (resid == 0 || resid2 == 0) { 
			lookAtTrigger( "0_L_leverL" );
			if (lastPlate != 0) { 
				setDoorState(plate, 0); 
				setDoorState(lastPlate, 0); 
				plate = 0;
				lastPlate = 0;
				setSpecialState("phex0_Z_treadplateZ_plate", plate);
				setSpecialState("phex0_Z_treadplateZ_lastplate", lastPlate);
				setDungeonObjectState("lever1", 2);
				setDungeonObjectState("lever1", 1);
			}
			sdlg2("", 113, 114);
		}
		if (resid == 1) { curiosity(which); }
	}
}

function phex0_Z_treadplateZ(which) {
	var plate = which.slice(17,20);
//	debugLog(plate);
	if (plate == lastPlate) return;

	if (getSpecialState("phex0_Z_treadplateZ_oddyseeBeganAt") == "" ) setSpecialState("phex0_Z_treadplateZ_oddyseeBeganAt", getTime() );
	if (opendoorset2 < 2) { opendoorset2 = 2; } else { opendoorset2 = 0; }
	if (lastPlate != 0) setDoorState(lastPlate, 0);
	setDoorState(plate, 2);
	setSpecialState("phex0_Z_treadplateZ_plate", plate);
	lastPlate = plate;
	setSpecialState("phex0_Z_treadplateZ_lastplate", lastPlate);
// Ausgangstür
	setDoorState(69, 2+opendoorset2);
	if (getDoorState(69) == 2 && which == "0_Z01_treadplateZ138" && getSpecialState("phex0_Z_treadplateZ_gotXP") == "" ) {
		setSpecialState("phex0_Z_treadplateZ_gotXP", 1);
		if (getTime() - getSpecialState("phex0_Z_treadplateZ_oddyseeBeganAt") <= 3/24) {
			awardXP("xp_phexlabyrinth_clever", -2, 30);
			sdlg2("", 149, "149b");
		} else { 
			awardXP("xp_phexlabyrinth", -2, 25);
			sdlg2("", 149, "149a");
		}
	}
	for(var j = 0; j < doorset1.length; j++){
		forceDoorState(doorset1[j], 2-opendoorset2);
	}
	for(var j = 0; j < doorset2.length; j++){
		forceDoorState(doorset2[j], opendoorset2);
	}
}


function phex0_2_supplypacks(which) {
	var gs = getGeneralState("phex0_2_generalstate");
	var nothingtakenyet = 0;
	if (typeof(gs.items) == "object") {
//		debugLog(gs.items[0].count);
		if (gs.items[0].count >= 10) nothingtakenyet = 1;
	}

	if (nothingtakenyet == 1) {
		if (which == 0) {
			yesnodlg("phex0_2_supplypacks1", "0a");
		} else {
			takeoffstorage("phex0_2", 1);
		}
	} else {
		sdlg2("", "0a", 1);
	}
}

function phex0_4_treadplate4( which, delta ) {
	if (which == "0_4a_treadplate4") {
		if (getDoorState(125) == 2) {
			var onplate4a = Number(getSpecialState("phex0_4_treadplate4_onplate4a") );
			onplate4a = Math.max(0, onplate4a + delta);
			setSpecialState("phex0_4_treadplate4_onplate4a", onplate4a);
	//		debugLog(onplate4a);
			if (onplate4a > 0) { setDoorState(107,2); } else { setDoorState(107,0); }
		}
	}
	if (which == "0_4b_treadplate4") {
		if (getDoorState(107) == 0) {
			var onplate4b = Number(getSpecialState("phex0_4_treadplate4_onplate4b") );
			onplate4b = Math.max(0, onplate4b + delta);
			setSpecialState("phex0_4_treadplate4_onplate4b", onplate4b);
	//		debugLog(onplate4b);
			if (onplate4b > 0) { setDoorState(125,2); } else { setDoorState(125,0); }
		}
	}
}

function phex0_6_moneycrapper(which, resid) {
	lookAtTrigger( "0_6_moneycrapper" );
	if (which == 0) yesnodlg("phex0_6_moneycrapper1", 2); 
	if (which == "phex0_6_moneycrapper1") {
		if (resid == 0) { sdlgname("phex0_6_moneycrapper2", 2, 42, getName(getLeaderID()) ); }
		if (resid == 1) { curiosity(which); }
	}
	if (which == "phex0_6_moneycrapper2") {
		sdlg2("phex0_6_moneycrapper3", 2, 43);
	}
	if (which == "phex0_6_moneycrapper3") {
//Fallgitter schließen
		setDoorState(74, 4);
		setDoorState(709, 2);
		setDoorState(710, 2);
		setDoorState(7072, 2);
		setDoorState(7081, 2);
//		setDoorState(74, 99);
		takeoffstorage("phex0_6", 1, 10, "Document", true);
//		showItemset("phex0_6_moneycrapper_itemset");
//"tür" öffnen
		setDoorState(100, 2);
	}
}

function phex0_8_magicpotion(which, resid) {
	lookAtTrigger( "0_8_magicpotion" );
	if (which == 0) yesnodlg("phex0_8_magicpotion1", 47); 
	if (which == "phex0_8_magicpotion1") {
		var angsthase = getWorst({"which":"MU", "type":"attribute"});
		if (resid == 0) { sdlgname2("phex0_8_magicpotion2", 47, 48, getName(angsthase.charid) , getName(getLeaderID()) ); }
		if (resid == 1) { curiosity(which); }
	}
	if (which == "phex0_8_magicpotion2") {
		sdlgname("phex0_8_magicpotion3", 47, 49, getName(getLeaderID()) );
	}
	if (which == "phex0_8_magicpotion3") {
//Fallgitter öffnen
		setDoorState(74, 2);
		setDoorState(709, 0);
		setDoorState(710, 0);
		setDoorState(7072, 0);
		setDoorState(7081, 0);
		awardXP("xp_phexfallgitter", -1, 5);
		takeoffstorage("phex0_8", 1, 10, "Document", true);	
	}
}

function phex0_9_pitfall9() {
	rcheck = rollCheck({"who":getLeaderID(),"which":"sinnensch", "type":"skill", "mod":-4});		
	if (!rcheck.ok) rcheck = rollCheck({"who":getLeaderID(),"which":"gefahrensinn", "type":"skill", "mod":-4});		
	
	if (rcheck.ok) {
		awardXP("xp_phexfallgrube", rcheck.id, 5);
		sdlgname2("", 3, 3, getName(rcheck.id), getLangString("text_3rdperson_"+getGender(rcheck.id),[]) );
	} else {
		var damage = rollRandom(1,4)+rollRandom(1,4)+rollRandom(1,4)+4;
		if (getCharAttribute("cLE", rcheck.id) > 5+damage ) {
			sdlgname3("", 3, 4, getName(rcheck.id), getLangString("text_pp_"+getGender(rcheck.id),[]), getLangString("text_pp3_"+getGender(rcheck.id),[]) );
		} else {
			sdlgname("", 3, "4b", getName(rcheck.id) );
		}
		dealDamage({"amount":damage,"who":rcheck.id,"type":"ignorers", "reason":"trap"}); 
		passTime("", 2/60);
	}
}

function phex0_11_baldower(which) {
	var answers = Number(getSpecialState("phex0_11_baldower_answers"));
	var moneyspent = Number(getSpecialState("phex0_11_baldower_moneyspent"));

	if (which == 0) {
		if (answers > moneyspent) {
			sdlg2("", 80, 83); return;
		}
		string = "phex0_11_baldower2";

		var langknown = getSpecialState("phex0_11_baldower_langknown");
		if (langknown == "") {
			rcheck = rollCheck({"which":"sprachen", "type":"skill", "mod":-3, "who": "best"}); 
			setSpecialState("phex0_11_baldower_langknown", rcheck.ok);
		} else {
			rcheck.ok = langknown;
		}
		if (rcheck.ok) string = "phex0_11_baldower1"
		sdlg(string, 80);
	}
	if (which == "phex0_11_baldower1") {
		sdlgname("phex0_11_baldower2", 80, 81, getName(rcheck.id));	
	}
	if (which == "phex0_11_baldower2") {	
		if (answers > 0) {
			sdlgname("phex0_11_baldower3", 80, 85, getName(getLeaderID()) ); return;
		}
		which = "phex0_11_baldower3";
	}
	if (which == "phex0_11_baldower3") {
		getNumber({"message":p1+"82", "min":0,"max":100,"callback":"phex0_11_baldower_answer"}); 
	}
}
function phex0_11_baldower_answer(chosen, amount) {
	if (chosen == true) {
		setSpecialState("phex0_11_baldower_answers", Number(getSpecialState("phex0_11_baldower_answers"))+1 );
		setSpecialState("phex0_11_baldower_moneyspent", 0);
		if (amount == 8) {
			setDoorState(204, 2);
			awardXP("xp_phexfrage", -1, 10);
			sdlg2("", 80, 54);
		} else {
			sdlg2("", 80, 55);
		}
	}
}	
function phex0_11b_baldower_gold(which, resid) {
	if (which == 0) yesnodlg2("phex0_11b_baldower_gold1", 80, 86);
	
	if (which == "phex0_11b_baldower_gold1") {
		if (resid == 0) {
			var max = Math.floor(getWealth()/100);
			getNumber({"message":p1+"89", "min":0,"max":max,"callback":"phex0_11b_baldower_gold_input"}); 
		}
		if (resid == 1 && getWealth() >= 100) curiosity("phex0_11b_baldower_gold1_curiosity");
	}
	if (which == "phex0_11b_baldower_gold1_curiosity" && resid2 == 0) {
		changeWealth(-100);
		setSpecialState("phex0_11_baldower_moneyspent", Number(getSpecialState("phex0_11_baldower_moneyspent"))+1 );
		sdlg2("", 80, 87);
	}
}
function phex0_11b_baldower_gold_input(chosen, amount) {
	if (chosen == true && amount > 0) {
		setSpecialState("phex0_11_baldower_moneyspent", Number(getSpecialState("phex0_11_baldower_moneyspent"))+amount)
		changeWealth(-100*amount);
		if (amount == 1) { sdlg2("", 80, 87); } else { sdlg2("", 80, 88); }
	}
}	

function phex0_14_treadplate14_lift(which) {
	which = which.slice(4,5);
	sd = lookuptable[ which ];
	setDoorState(sd, 0);
}
function phex0_14_treadplate14(which) {
	which = which.slice(4,5);
	sd = lookuptable[ which ];
	setDoorState(sd, 2);
//debugLog(sd);
	if (getDoorState(98) == 2) return;
	temp = getSpecialState("phex0_14_treadplate14_waygone");
	waygone = temp.split(',');
	switch (waygone.length) {
		case 0: if (which == "a") { waygone[waygone.length] = which } else { waygone = []; waygone[0] = which } ; break;
		case 1: if (which == "b") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 2: if (which == "c") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 3: if (which == "d") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 4: if (which == "e") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 5: if (which == "i") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 6: if (which == "e") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 7: if (which == "i") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 8: if (which == "j") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 9: if (which == "k") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 10: if (which == "o") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 11: if (which == "s") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 12: if (which == "r") { waygone[waygone.length] = which } else { waygone = [] } ; break;
		case 13: if (which == "s") { waygone[waygone.length] = which } else { waygone = [] } ; break;		
	}
//	debugLog(waygone);
	setSpecialState("phex0_14_treadplate14_waygone", waygone);
	if (waygone.length == 14) {
		awardXP("xp_phexplates", -1, 10);
		lookAtTrigger( "0_3l_secretdoor_0_98" );
		setDoorState(98, 2);
		sdlg("", 109);
	}
}

function phex0_15_doorwithoutlock(which) {
	if (which == 0) sdlgname("phex0_15_doorwithoutlock1", 90, 90, getName(getLeaderID()) );
	if (which == "phex0_15_doorwithoutlock1") {
		if ( findInventoryItem("st_lightball" > 0) ) {
			removeInventoryItem("st_lightball", 1);
			setDoorState(15, 2);
			sdlgname("", 90, 91, getName(getLeaderID()) );
		}
		if ( findInventoryItem("st_heavyball" > 0) ) {
			removeInventoryItem("st_heavyball", 1);
			sdlgname("", 90, 92, getName(getLeaderID()));
		}
	}
}

function phex0_16_offertorybox(which, resid) {
	if (which == 0) { 
//		setSpecialState("phex0_16_offertorybox_wealth", getWealth() );
		sdlg("phex0_16_offertorybox1", 34, 35, 84, 36); 
	}
	if (which == "phex0_16_offertorybox1") {
		if (resid == 0) {
			greed("phex0_16_offertorybox1", 0, 2);
			if (resid2 > -1) return;
			var max = Math.floor(getWealth()/100);
			getNumber({"message":p1+"45", "min":0,"max":max,"callback":"phex0_16_offertorybox_goldinput"}); 
		}
		if (resid == 1) { greed("phex0_16_offertorybox1", 0, 2); }
		if (resid == 2 || resid2 == 2) {
			modifyGodGrace("Phex", -50);
			sdlgname("phex0_16_offertorybox2", 34, 37, getName(rcheck.id) );
		}
	}
	if (which == "phex0_16_offertorybox2") {
		sdlg2("phex0_16_offertorybox3", 34, 38);
	}
	if (which == "phex0_16_offertorybox3") {
		teleportToTrigger("0_Z01_treadplateZ138", 0);
	}
}
function phex0_16_offertorybox_goldinput(chosen, amount) {
	if (chosen == true && amount > 0) {
		var moneyspent = Number(getSpecialState("phex0_16_offertorybox_moneyspent")) +amount*100;
		setSpecialState("phex0_16_offertorybox_moneyspent", moneyspent);
		changeWealth(-100*amount);
		modifyGodGrace("Phex", amount);
		if (getDoorState(205) != 2 && moneyspent >= 0.1 * (getWealth()+moneyspent) ) { 
			awardXP("xp_phexopfer", -1, 10);
			setDoorState(205, 2);
			sdlgname("", 34, 39, getName(getLeaderID()) ); 
		} else { sdlg2("", 34, 46); }
	}
}

function phex0_17_checkoffer(which) {
	if (which == 0) {
		loc1 = getLocation();
		setSpecialState("phex0_17_checkoffer_x", loc1.x);
//		debugLog(loc1.x+" "+loc1.y+" "+loc1.z);
		autoSave();
	}
	if (which == "OnLeave") {
		loc2 = getLocation();
		loc1 = Number(getSpecialState("phex0_17_checkoffer_x"));
		if (loc1 == 0) loc1 = -9999;
//		debugLog(loc2.x+" "+loc2.y+" "+loc2.z);
		trigg = Number(getSpecialState("phex0_16_offertorybox_moneyspent"));
		if ( trigg == 0 && loc2.x < loc1 ) {
			teleportToTrigger("0_Z01_treadplateZ138", 0);
		}
	}
}

function phex0_20_artefacts_check(which) {
	var gs = getGeneralState("phex0_20_generalstate");
	var weight = 0;
	if (typeof(gs.items) == "object") {
		for (var i=0; i < gs.items.length; i++) {
			weight += Number(gs.items[i].count) * Number(gs.items[i].weight);
		}
	}
	if (weight < 210 && getDoorState(72) == 2) {
		setDoorState(72, 4);
		var best = getBest({"which":"gefahrensinn","type":"skill"});
		lookAtTrigger( "0_24b_electric_leave" );
		sdlgname("", 61, 61, best.shortname );
	}
	if (weight >= 210 && getDoorState(72) == 4) {
		setDoorState(72, 2);
		if (findInventoryItem("phexshield" > 0) && findInventoryItem("phexhelmet" > 0) && getSpecialState("phex0_20_artefacts_gotXP") == "" ) {
			setSpecialState("phex0_20_artefacts_gotXP", 1);
			awardXP("xp_phexhelmschild", -1, 10);
			sdlgname("", 61, "61a" );
		}
	}
}

function phex0_24_electriceels(which) {
	id = getLeaderID();
	rcheck = rollCheck({"who":id,"which":"gefahrensinn", "type":"skill", "mod":-4});	
	if (rcheck.ok) {
		sdlgname2("phex"+which, 112, "112b", getName(id), getLangString("text_3rdperson_"+getGender(id),[]) ); 
		return;
	}
	passTime("", 2/60);
	dealDamage({"amount":"1W4+4","who":id,"type":"ignorers", "reason":"trap"}); 
	sdlgname3("phex"+which, 112, 112, getName(id), getLangString("text_3rdperson_"+getGender(id),[]), getLangString("text_pp2_"+getGender(id),[]) ); 
}

function phex0_25_trap() {
	var damage = Number(getSpecialState("phex0_25_trap_active"))+"W4";
	if (damage == "0W6") { sdlg("", 93); }
	else {
		dealDamage({"amount":damage,"who":-1,"type":"physical", "reason":"trap"}); 
		sdlg2("", 93, 94);
	}
}

function phex0_26_passphrase(which, resid) {
	if (which == 0) yesnodlg2("phex0_26_passphrase1", 47, "47a"); 
	if (which == "phex0_26_passphrase1") {
		var angsthase = getWorst({"which":"MU", "type":"attribute"});
		if (resid == 0) { sdlgname2("phex0_26_passphrase2", 47, "48a", getName(angsthase.charid) , getName(getLeaderID()) ); }
		if (resid == 1) { curiosity(which); }
	}
	if (which == "phex0_26_passphrase2") {
		takeoffstorage("phex0_26", 1, 10, "Document", true);	
	}	
}

function phex0_27_doorwithnumbers(which, resid) {
	if (which == 0) { 
		yesnodlg("phex0_27_doorwithnumbers1", 95, 95); 
	}
	if (which == "phex0_27_doorwithnumbers1") {
		getNumber({"message":p1+"96a", "min":1,"max":9,"callback":"phex0_27_doorwithnumbers_input"}); 
	}
}
function phex0_27_doorwithnumbers_input(chosen, amount) {
	if (chosen == true && amount > 0) {
		var No = getSpecialState("phex0_27_doorwithnumbers_chosen") +String(amount);
		setSpecialState("phex0_27_doorwithnumbers_chosen", No );
		No = Number(No);
		if (No < 10) {  getNumber({"message":p1+"96b", "min":1,"max":9,"callback":"phex0_27_doorwithnumbers_input"}); }
		if (No >= 10 && No < 100) { getNumber({"message":p1+"96c", "min":1,"max":9,"callback":"phex0_27_doorwithnumbers_input"}); }
		if (No > 100) {
			if (No == 912) {
				setDoorState(712, 2);
				awardXP("xp_phexdoorwithnumbers", -1, 10);
				sdlg2("", 95, "97a");
			} else {
				setSpecialState("phex0_27_doorwithnumbers_chosen", "" );
				sdlg2("", 95, "97b");			
			}
		}
	}
}

function phex0_28_waterjar(which, resid) {
	if (resid == null) { 
		if ( phex0_28_waterjar_check() == "full") yesnodlg2(which+"1", 98, "98a"); 
		if ( phex0_28_waterjar_check() == "empty") yesnodlg2(which+"1", 98, "98b"); 
	} else { 
		takeoffstorage("phex"+which.slice(0,5), 1, 250, "General", false, false, false, false, "phex0_28_waterjar_check"); 		
	}
}
function phex0_28_waterjar_check() {
	passTime("", 1/60);
	which = trigger;
	var gs = getGeneralState("phex"+which.slice(0,5)+"_generalstate");
	var weight = 0;
	var string = "full";
	if (typeof(gs.items) == "object") {
		for (var i=0; i < gs.items.length; i++) {
			weight += Number(gs.items[i].count) * Number(gs.items[i].weight);
		}
	} else {string = "empty";}
	switch (which.slice(0,5)) {
		case "0_28a":	sockel = 7134; break;
		case "0_28b":	sockel = 7132; break;
		case "0_28c":	sockel = 7133; break;
		case "0_28d":	sockel = 7131; break;
	}
	if (weight < 30) {
		setDoorState(sockel, 2);
	} else {
		setDoorState(sockel, 0);	
	}
	return string;
}

function phex0_28e_watertub(which) {
	if (which == 0) { yesnodlg("phex0_28e_watertub1", 99); }
	if (which == "phex0_28e_watertub1") {
		chooseItem( {"showequipped":false,"needchar":true, "action": p1+'100', "callback": "phex0_28e_watertub_chooseItem" } );
	}
}
function phex0_28e_watertub_chooseItem(itm, itmname, who) {
	if (itm == -1) return;
	if (itm == "waterskin" || itm == "drinkinghorn") { 
		passTime("", 5/60);
		fillUsesType( "water" ); 
		sdlg2("", 99, "101b");
		return; 
	}
// wenn tonkrug, dann voll machen
	if (itm == idjar1 || itm == idjar2 || itm == idjar3 || itm == idjar4) { 
		passTime("", 1/60);
		var temp = getSpecialState("map.phextemp0_28_waterjar_contents");
		if (temp != "") { contents = temp.split(',').map(Number); }
		switch (itm) {
			case idjar1:	curjar = 0; break;
			case idjar2:	curjar = 1; break;
			case idjar3:	curjar = 2; break;
			case idjar4:	curjar = 3; break;
		}
		contents[curjar] = maxesHard[curjar];
		setSpecialState("map.phextemp0_28_waterjar_contents", contents);
		sdlg2("", 99, "101c");
		return;
	}

	sdlg2("", 99, 101);
}

function phex0_34_lib(which) {
//	debugLog(which);
	var start = 139, end = 150;
	var tex = rollRandom(start,end);
	var who = rollRandom(0, getPartyCount()-1);
	if (!canAct(who)) {
		for (var i=who; i<who+getPartyCount();i++) {if (i=getPartyCount()) i=0; if (canAct(i)) {who = i; break} }
	}
	passTime("", 15/60);
	rcheck = rollCheck({"who":who,"which":"lesen", "type":"skill", "mod":0});
	if (tex > 148 || !rcheck.ok) { sdlg2("", 138, 138); return; }

	var alreadyread = new Array();
	var temp = getSpecialState( "phex0_34_lib_alreadyread" );
	if (temp != "") alreadyread = temp.split(",").map(Number);
	if (alreadyread.indexOf(tex) != -1) {
		for (var i=start; i<=end;i++) {
			if (alreadyread.indexOf(i) == -1) { tex = i; break;}
		}
	}	
	alreadyread.push(tex);
	setSpecialState( "phex0_34_lib_alreadyread", alreadyread.join(",") );
//debugLog(getSpecialState( "phex0_34_lib_alreadyread" ));
	
	var who2 = rollRandom(0, getPartyCount()-1);
	if (!canAct(who2) || who == who2) {
		for (var i=who2; i<who2+getPartyCount();i++) {if (i=getPartyCount()) i=0; if (canAct(i)) {who2 = i; break} }
	}
	switch (tex) {
		case 139:	sdlgname2("0_34_lib_139b", 138, tex, getName(who), getLangString("text_pp203_"+(getGender( who )),[]) ); break;
		case 140:	sdlgname("0_34_lib_godscults", 138, tex, getName(who) ); break;
		case 141:	sdlgname2("0_34_lib_godscults", 138, tex, getName(who), getName(who2) ); break;
		case 142:	sdlgname2("0_34_lib_history", 138, tex, getName(who), getLangString("text_pp201_"+(getGender( who )),[]) ); break;
		case 143:	sdlg2("0_34_lib_history", 138, tex); break;
		case 144:	sdlgname("0_34_lib_history", 138, tex, getName(who) ); break;
		case 145:	sdlgname2("0_34_lib_history", 138, tex, getName(who), getLangString("text_3rdperson_"+(getGender( who )),[]) ); break;
		case 146:	sdlg2("0_34_lib_godscults", 138, tex); break;
		case 147:	sdlgname("0_34_lib_godscults", 138, tex, getName(who) ); break;
		case 148:	sdlgname("0_34_lib_godscults", 138, tex, getName(who) ); break;
	}
}
function phex0_34_lib_incTalent(which) {
	if ( which.lastIndexOf( "_history" ) >= 0 ) 	var talent = "geschichte";
	if ( which.lastIndexOf( "_godscults" ) >= 0 ) 	var talent = "goetterkulte";
	var wert = Number( getSpecialState("phex0_34_lib_incTalent_"+talent) );
	wert++;
	setSpecialState("phex0_34_lib_incTalent_"+talent, wert);
	if (wert == 3) {
		for (var i = 0; i < getPartyCount(); i++){
			var taw = getCharSkill(talent,i);
			if( taw < 18 && canAct(i) ) {
				r = rollRandom(1,6) + rollRandom(1,6);
				result = "fail";
				if (taw >= 10 ) r = r + rollRandom(1,6);
				if (r > taw) {
					modifyCharSkill(talent, i, 1);
					result = "success";
				}
				debugLog(getName(i)+": Trying to increase skill '"+talent+"' (" + taw + "), roll: " + r + "; result: "+result);
			}
		}
	}
}

function phex0_35_parcour(which, resid) {
	var talent = "0"
	switch (which) {
		case "0_35_parcour01":	 talent = "GE"; var type = "attribute", mod = 5, HA = 1, damage = 2, rot = 0, moveto = "0_35_parcour02a"; break;
		case "0_35_parcour03":	 talent = "akrobatik"; var type = "skill", mod = 6, HA = 1, damage = 2, rot = 50, moveto = "0_35_parcour04a"; break;
		case "0_35_parcour04b":	 talent = "klettern"; var type = "skill", mod = 6, HA = 1, damage = 1, rot = 30, moveto = "0_35_parcour05"; break;
		case "0_35_parcour06":	 autoSave(); talent = "GE"; var type = "attribute", mod = 6, HA = 2, damage = 3, rot = 180, moveto = "0_35_parcour07"; break;
		case "0_35_parcour09":	 talent = "akrobatik"; var type = "skill", mod = 8, HA = 2, damage = 3, rot = 250, moveto = "0_35_parcour10a"; break;
		case "0_35_parcour10b":	 talent = "klettern"; var type = "skill", mod = 8, HA = 2, damage = 5, rot = 330, moveto = "0_35_parcour11"; break;
		case "0_35_parcour12":	 talent = "GE"; var type = "attribute", mod = 12, HA = 3, damage = 6, rot = 30, moveto = "35_parrope13"; break;
	}
	if (talent != 0) lookAtTrigger(moveto);
	if (resid == null) {
		switch (which) {
			case "0_35_parcour01":	 yesnodlg2name( which, 117, 117, getName(getLeaderID()) ); break;
			case "0_35_parcour03":	 sdlg2( which, 117, 120 ); break;
			case "0_35_parcour04b":	 yesnodlg2name( which, 117, 121, getName(getLeaderID()) ); break;
			case "0_35_parcour06":	 yesnodlg2name( which, 117, 122, getName(getLeaderID()) ); break;
			case "0_35_parcour09":	 sdlg2( which, 117, 120 ); break;
			case "0_35_parcour10b":	 yesnodlg2name( which, 117, 123, getName(getLeaderID()) ); break;
			case "0_35_parcour11b":	 phex0_35_saftyrope(0); return; break;
			case "0_35_parcour12":	 yesnodlg2name( which, 117, 124, getName(getLeaderID()) ); break;
		} 
	} else {
		namenarray = [];
		active = 0;

		for (var j = getPartyCount()-1; j >= 0; j--){
			if (canAct(j)) {
				active++;
				rcheck = rollCheck({"who":j,"which":talent,"type":type,"mod":mod-Math.round(HA*getCharAttribute("HA", j)) });
				if (!rcheck.ok) {
					phex0_35_falldamage(damage, j, which, rot);
				}
				if (rcheck.ok || (j == 0 && namenarray.length < active) ) {
					moveToTrigger(moveto, rot);
					if (moveto == "35_parrope13") {
						var uid = getCharUniqueId(j);
						if ( canAct(j) && getSpecialState("phex0_35_parcour_gotXP_"+uid, 1) == "") {
							setSpecialState("phex0_35_parcour_gotXP_"+uid, 1);
							awardXP("xp_phexparcour", j, 25);
						}
					}
				}
			} else { 
				moveToTrigger(which+"s", rot); 
				if (getPartyCount() > 1) splitLeaveCharacter(j);
			}
		}	
		phex0_falldamageMessage(namenarray);
	}
}
function phex0_35_falldamage(damage, who, which, rot) {
	namenarray[namenarray.length] = getName(who);
	if (canAct(who)) {
		rcheck2 = rollCheck({"type":"skill","which":"koerperb","who":who, "mod":0});
		if (rcheck2.ok) damage = Math.max(0, damage - rcheck2.resrem-1);
	}
	var ropelength = 0;
	if (which == "0_35_parcour12") { 
//Überprüft ob ein Seil an der Säule hinterlegt wurde
		var gs = getGeneralState("phex0_35safty_generalstate");
		if (typeof(gs.items) == "object") {
			for (var i=0; i < gs.items.length; i++) {
				if (gs.items[i].id == "rope") ropelength += 10;
				if (gs.items[i].id == "staff" && gs.items[i].level >= 3) ropelength += 10;
			}
		}
		if (ropelength >= 10) {
			moveToTrigger("0_35_parcour11", 0);
			damage = Math.max(0, damage-3);
		}	
	}
	dealDamage({"amount":damage+"W4+"+damage,"who":who,"type":"ignorers", "reason":"fall"}); 

	if (ropelength >= 10) {
		if (getSpecialState("phex0_35_saftyrope_who") == "") { setSpecialState("phex0_35_saftyrope_who", 0); }
		if (!canAct(who)) setSpecialState("phex0_35_saftyrope_who", getName(who));
//debugLog("canAct "+getName(who)+": "+canAct(who));			
	}
	if( trigger != which+"u" && ropelength < 10) moveToTrigger(which+"u", rot);
	if (getPartyCount() > 1) splitLeaveCharacter(rcheck.id);
}
function phex0_falldamageMessage(namenarray) {	
// Meldung für alle Trigger	
	if (namenarray.length >= 1) { 
		var verb = getLangString("dlg_has",[]);
		var names = namenarray[0];
		if (namenarray.length > 1) {
			var verb = getLangString("dlg_have",[]);
			for (var i = 1; i < namenarray.length; i++) {
				if (i == namenarray.length-1) { names = names+getLangString("dlg_and",[]); } else { names = names+", "; }
				names = names + namenarray[i];
			}
		}
//Falls an der Säule ein Seil angeknotet wurde:
		var who = getSpecialState("phex0_35_saftyrope_who");
		if ( who == "") {
			showMessage( getLangString("phextemp_118", [verb, names]) );
		} else {
			string = getLangString("phextemp_134",[]);
			if ( who != "0") string = getLangString("phextemp_135",[who]);
			showMessage( getLangString("phextemp_133", [names, string]) );		
//debugLog("who died "+getSpecialState("phex0_35_saftyrope_who"));			
			setSpecialState("phex0_35_saftyrope_who", "");	
		}
		
	} else { showMessage( getLangString("phextemp_119", []) ); }		
}

function phex0_35_rope2(which) {
	if (which == 0) { yesnodlg("phex0_35_rope2A", 125); }
	if (which == "phex0_35_rope2A") {
		takeoffstorage("phex0_35", 4, 250, "", false, true, false, false, "phex0_35_rope2_checklength");
	}
}

function phex0_35_rope2_checklength() {
// Prüfen, ob an der Mauer mind. 20 m Seil hinterlegt wurden, um hinauf klettern zu können
	var gs = getGeneralState("phex0_35_generalstate");
	if (typeof(gs.items) == "object") {
		var ropelength = 0;
		for (var i=0; i < gs.items.length; i++) {
			if (gs.items[i].id == "rope") ropelength += 10;
			if (gs.items[i].id == "staff" && gs.items[i].level >= 3) ropelength += 10;
			if (gs.items[i].id == "ropeladder") ropelength += 5;
//			if (gs.items[i].id == "grapplinghook") ropelength += 5;
		}
	}
	if (ropelength >= 20) { 
		if (getDoorState(9090) == 0) {
			passTime("", 3/60);
			setDoorState(9090, 2); 
		}
	} else {
		if (getDoorState(9090) == 2) {
			passTime("", 3/60);
			setDoorState(9090, 0); 
		}
	}
	return ropelength;
}

function phex0_35_rope1(which) {
// Prüfen, ob an der Mauer mind. 20 m Seil hinterlegt wurden, um hinauf klettern zu können
	if (which == 0) {
		var ropelength = phex0_35_rope2_checklength();
		if (ropelength >= 20) { yesnodlg("phex0_35_rope1A", 126); }
		else { yesnodlg("phex0_35_rope1B", 125); }
	}
	if (which == "phex0_35_rope1A") {
		moveToTrigger("35_parrope13", 180);
	}
	if (which == "phex0_35_rope1B") {
// Falls kein (langes) Seil nach unten hängt, gibts hier die Möglichkeit einen Wurfhaken nach oben zu werfen
		chooseItem( {"showequipped":true,"needchar":true, "action": p1+'100', "callback": "phex0_35_rope1_chooseItem" } );
	}
}

function phex0_35_rope1_chooseItem(itm, itmname, who) {
//Waurfhaken nach oben ins Mauerloch
	if (itm == -1) return;
	if (itm == "grapplinghook" && findRopeLength(-1) >= 20 ) { 
		moveToTrigger("35_parrope13", 180);
	} else {
		sdlg2("", 125, 127);
	}
}

function phex0_35_parrope13(which) {
// Prüfen, ob an der Mauer mind. 20 m Seil hinterlegt wurden, um hinunter klettern zu können
	if (which == 0) {
		var ropelength = phex0_35_rope2_checklength();
		if (ropelength >= 20) { yesnodlg2("phex0_35_parrope13A", 126, 128); }
	}
	if (which == "phex0_35_parrope13A") { moveToTrigger("35_parcour12u", 180); }
}

function phex0_35_saftyrope(which) {
	if (which == 0) {
		yesnodlg("phex0_35_saftyrope1", 132);
	}
	if (which == "phex0_35_saftyrope1") {
		takeoffstorage("phex0_35safty", 1, 100, "", false, true, false, false); 		
	}
}




// whenever a door is clicked, "which" is always <floorid>_<doorid>. Should return true if the doorclick was handled
function doorClicked( which ) { 
//bei Truhe bei Rezept 1
	if( which == "0_52" ) { 
		sdlg("", 115);
		return true; 
	}	
//Eingangstür;
	if( which == "0_58" ) {
		if( getSpecialState("map.phex0_0_leaveTemple_openedEntrance") != "1" ) {
			if (getSpecialState("phex0_1_entrance_checked") != "1") {
				setSpecialState("phex0_1_entrance_checked", 1);
				sdlg("", 59);
			} else {
				if (getPartyCount() > 1 && canAct(getLeaderID()+1) ) {
					rcheck = rollCheck( {"which":"KK", "type":"attrib", "mod":-5, "who":getLeaderID()} );
					rcheck2 = rollCheck( {"which":"KK", "type":"attrib", "mod":-5, "who":getLeaderID()+1} );
				} else { 
					rcheck = rollCheck( {"which":"KK", "type":"attrib", "mod":-10, "who":getLeaderID()} );
					rcheck2.ok = true; 
				}
				if (rcheck.ok && rcheck2.ok) { 
					setSpecialState("map.phex0_0_leaveTemple_openedEntrance", 1);
					yesnodlg("0_1_entry", 129);
//					setDoorState(58, 2);
//					sdlg2("", 59, "59a");
				} else { 
					dealDamage({"amount":"2W6","who":rcheck.id,"type":"ignorers", "reason":"door is stronger"}); 
					if (getPartyCount() > 1 && canAct(getLeaderID()+1) ) dealDamage({"amount":"2W6","who":getLeaderID()+1,"type":"ignorers", "reason":"door is stronger"}); 
					sdlg2("", 59, "59b"); 
				}
			}
		} 
		else {yesnodlg("0_1_entry", 129);}
		return true;
	}
//Folterzelle Parcour
	if( which == "0_67" ) { 
		sdlg("", 115);
		return true; 
	}	
//Blauer-Schlüssel-tür
	if( which == "0_68" && getDoorState("0_68") != 2 ) { 
		if (findInventoryItem("st_bluekey") > 0 ) {
			removeInventoryItem("st_bluekey", 1);
			setDoorState(68, 2);
			awardXP("xp_blauerschluessel", -1, 5);
			sdlg2("", 115, 116);
		} else {
			sdlg("", 115);
		}
		return true; 
	}	
//Kugel-tür
	if( which == "0_715" && getDoorState("0_715") != 2 ) { phex0_15_doorwithoutlock(0); return true; }
// Zahlenschloss
	if( which == "0_712" && getDoorState("0_712") != 2 ) { phex0_27_doorwithnumbers(0); return true; }

	return false; 
}
// whenever a chest is clicked, "which" is always <floorid>_<chestid>. Should return true if the chestclick was handled
function chestClicked( which ) { 
//Sternenschweif
	if (which == "0_1") {
		if (getDoorState(107) == 2 && getDoorState(125) == 2) {
			return false;
		} else {
			sdlg("0_1_zinken", 108);
			return true;
		}
	}
	
//XXX Truhe bei Rezept1
	if( which == "0_3" ) { 
		sdlg("0_3_zinken", 115); return true; 
	}	
//XXX Truhe bei Waage
	if( which == "0_4" ) { 
		sdlg("0_4_zinken", 115); return true; 
	}
	if( which == "0_5" ) { 
		phex0_zinken("0_5_zinken");
	}	
//vergiftete Truhe bei Rezept 2 (Kobold-Gold-Stirnreife)
	if (which == "0_7") {
//Diese Truhe ist schlecht versteckt mit einem Giftdorn gesichert. Ungeschickte Hände könnten die Falle aber auslösen. Wollt Ihr dennochh versuchen, das Schloss zu knacken?
		phex0_zinken("0_7_zinken");
	}
	if (which == "0_9") {
//Diese Truhe ist schlecht versteckt mit einem Giftdorn gesichert. Ungeschickte Hände könnten die Falle aber auslösen. Wollt Ihr dennochh versuchen, das Schloss zu knacken?
		phex0_zinken("0_9_zinken");
	}
	if (which == "0_10") {
//Diese Truhe ist schlecht versteckt mit einem Giftdorn gesichert. Ungeschickte Hände könnten die Falle aber auslösen. Wollt Ihr dennochh versuchen, das Schloss zu knacken?
		phex0_zinken("0_10_zinken");
	}
	return false; 
}
// whenever a chest is opened, "which" is always <floorid>_<chestid>. Should return true if the opening was handled
function chestOpened( which ) {
	switch( which ) {
		case "0_1": if (getSpecialState("phex0_4_treadplate4_gotXP") == "") {
			setSpecialState("phex0_4_treadplate4_gotXP", 1); awardXP("xp_phexsternenschweif", -1, 10); } break;
		case "0_5": takeoffstorage("phex0_20", null, null, null, false, false, false, false, "phex0_20_artefacts_check" ); return true; break;
		case "0_6": if(getSpecialState("phex0_6_chest_seen") == "") { setSpecialState("phex0_6_chest_seen",1); showMessage( getLangString( "phextemp_136", [] ) ); } break;
		case "0_10": if(getSpecialState("phex0_10_chest_seen") == "") { 
					setSpecialState("phex0_10_chest_seen",1);
					best = getBest({"which":"GG","type":"attrib"}); 
					showMessage( getLangString( "phextemp_137", [best.shortname, getLangString("text_3rdperson_"+getGender(best.charid), []) ] ) );} break;
	}
	return false;
}
]]></script>
	<!-- Contents of Itemsets here are stored and handled via Savegame whenever they are modified after first entry -->
	<itemsets>
		<!-- Custom set, e.g. "something lying on the floor" -->
		<itemset id="phex0_2_supplypacks_itemset">
			<item id="supplypack" count="10" />
		</itemset>
		<itemset id="phex0_J0_coalkey_itemset">
			<item id="st_bluekey" count="1" />
		</itemset>
		<!-- Chest-Set automatically assiged to Chest ID 1 on Floor 0 -->
		<itemset id="chest_0_1">
			<item id="money" count="40" />
			<item id="st_goldenthrowingaxe" count="1" />
		</itemset>
		<itemset id="chest_0_6">
			<item id="whip" count="1" />
			<item id="fishinghook" count="1" />
			<item id="mace_good" count="1" />
			<item id="ropeladder" count="1" />
			<item id="knife" count="1" />
			<item id="basilisk_tongue" count="1" />
			<item id="torch" count="1" />
			<item id="crowbar" count="1" />
			<item id="oil" count="2" />
			<item id="scythe" count="1" />
			<item id="ogreshortsword" count="1" />
			<item id="pois_miasthmaticum" count="1" />
			<item id="sickle" count="1" />
			<item id="grapplinghook" count="1" />
			<item id="ravenbeak" count="1" />
			<item id="whetstone" count="1" />
			<item id="tinderbox" count="1" />
			<item id="brassmirror" count="1" />
		</itemset>
<!-- Rezept 2 -->		
		<itemset id="chest_0_7">
			<item id="goldentiara_fake" count="10" />
		</itemset>
<!-- Ratten D1 -->		
		<itemset id="chest_0_8">
			<item id="goldenring_fake" count="10" />
		</itemset>
<!-- Statuette i4 -->		
		<itemset id="chest_0_10">
			<item id="gold_jewelry_fake" count="10" />
		</itemset>
	</itemsets>
	<exit>
		<!-- 
can either be fixed coordinates like this:
[code]
	<coords>
	  <x>-19</x>
	  <y>21.8</y>
	  <z>35.5</z>
	</coords>
	<dungeon>prem</dungeon>
	<rotation>270</rotation>
[/code]
	or a script like below, executed when "leaving the dungeon". 
	Script can be "continueJourney();" if before entry of the dungeon "saveJourney()" was called -->
	<script>
		startDialogueAt("raumangst","ende");
		startDialogueAt("phex0_leave_fakes","1");
	</script>
		<dungeon>script</dungeon>
	</exit>
</dungeon>
</dungeons>

