#include "scripts/common.txt"
#include "scripts/bp_common.txt"

class TurokShopPoint : ScriptObject {
    kActor @self;
	bool insidePlayer = true;
	//------------------------------------------------------------------------------------------------------------------------
    TurokShopPoint(kActor @actor) {
        @self = actor;
		self.Flags() |= AF_CANBETOUCHED;
    }
	//------------------------------------------------------------------------------------------------------------------------
    void OnTick(void) {
		self.PlaySound("sounds/shaders/generic_187.ksnd");
		if (insidePlayer) {
			if (!InRadius(self.Origin(), 160.0f)) {
				insidePlayer = false;
			}
		}
    }
	//------------------------------------------------------------------------------------------------------------------------
    void OnSpawn(void) {		
    }
	//------------------------------------------------------------------------------------------------------------------------
	void OnTouch(kActor @theActorThatTouchedMe) {
		if (!insidePlayer) {
			kVec3 pos = self.Origin();
			pos.z = Player.Actor().FloorHeight();
			int si = Player.Actor().GetSectorIndexAtLocation(pos);
			GameVariables.SetValue("BP.ShopWarpSector", "" + si);
			GameVariables.SetValue("BP.ShopWarpPos", pos.ToString());
			GameVariables.SetValue("BP.ShopWarpYaw", "" + Player.Actor().Yaw());
			GameVariables.SetValue("BP.ShopWarpMap", "" + Game.GetCurrentMapID());
			
			// Sys.Print("Sector: " + si + ", Pos: " + pos.ToString() + ", yaw: " + Player.Actor().Yaw() + ", mapID: " + Game.GetCurrentMapID());
			//warp to map
			PlayLoop.StartFreeWarp(theActorThatTouchedMe,
						   kVec3(-4752, -2514, 153), //pos
						   0, //yaw
						   22, //sectorindex
						   52); //mapid
		}
	}
	//------------------------------------------------------------------------------------------------------------------------
};
