#include "scripts/bp_common.txt"
#include "scripts/map/common_level_script.txt"

//------------------------------------------------------------------------------------------------------------------------
// Start Game
//------------------------------------------------------------------------------------------------------------------------
$script 0
{
    int gotKey;
    
    GameVariables.GetInt("bGotMantisKey", gotKey);
    
    if(gotKey == 1)
    {
        // hopefully this is the only actor in this level that has this TID
        kActor @exitPortal = World.GetActorByTID(667);
        
        if(!(exitPortal is null))
        {
            // we need to know what area this actor is in
            int areaID = exitPortal.AreaID();
            
            if(areaID <= -1)
            {
                // oh dear...
                return;
            }
            
            if((World.GetAreaFlags(areaID) & AAF_TELEPORTAIR) == 0)
            {
                // oh dear...
                return;
            }
            
            // though args can be used for anything, they are typically used
            // in this fashion:
            //
            // 0: warp ID
            // 1: warp level ID or trigger sound ID
            // 2: checkpoint ID
            // 3: tag ID
            // 4: floor damage hit points
            // 5: floor damage rate
            
            // change to warp tag 10666 (in front of hub)
            World.ChangeAreaArg(areaID, 0, 10666);
            
            // change to level 5 (main hub)
            World.ChangeAreaArg(areaID, 1, 5);
        }
    }
	
	
	ActorFactory.Spawn("ShopPoint", -6311, 5061, 0, Math::Deg2Rad(90), 0); //Spawn Shop Portal
	ActorFactory.Spawn("ShopPoint", -683, 1153, -2253, Math::Deg2Rad(45), 0); //Spawn Shop Portal

	
	Game.CallDelayedMapScript(1, instigator, 0);
}
//------------------------------------------------------------------------------------------------------------------------
// Update Game
//------------------------------------------------------------------------------------------------------------------------
$script 1 {
	UpdateGeneralGame();
	//ActorInWorldTestUpdate();
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------