require( "common" )
require( "ID/WarL/WarLData" )
require( "ID/WarL/WarLEventRoutine" )
require( "ID/WarL/WarLInitFuntion" )
require( "ID/WarL/WarLDeInitFuntion" )
require( "ID/WarL/WarLEventMobRoutine" )


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --														-- --
-- --					    ¸ÞÀÎÇÔ¼ö						-- --
-- --														-- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

function Main( Field )
cExecCheck( "Main" )

	local EventMemory = InstanceField[Field]

	if EventMemory == nil then

		InstanceField[Field] = { }

		EventMemory					= InstanceField[Field]
		EventMemory["MapIndex"]		= Field
cAssertLog( "TestData: Main MapIndex2 = " .. EventMemory["MapIndex"] ) -- ######### COMMENTS ##########
		EventMemory["CurrentTime"]	= nil
		EventMemory["EventNumber"]	= 1
		EventMemory["EM_STATE"]		= EM_STATE["Start"]

		EventMemory[EventMemory["EventNumber"]]					= { }
		EventMemory[EventMemory["EventNumber"]]["EventData"]	= { }
		EventMemory[EventMemory["EventNumber"]]["EventState"]	= ES_STATE["State1"]

		EventMemory["ObjectState"] 				= { }
		EventMemory["ObjectState"]["L_Line"] 	= 1
		EventMemory["ObjectState"]["R_Line"] 	= 1

		EventMemory["CurrentTime"]			= nil

cAssertLog( "TestData: Main 2.7" ) -- ######### COMMENTS ##########
--		cSetFieldScript( EventMemory["MapIndex"], SCRIPT_MAIN )
		DOOR_N_GATE_CREATE( EventMemory )
--		cFieldScriptFunc( EventMemory["MapIndex"], "MapLogin", "PlayerMapLogin" )
cAssertLog( "TestData: Main 2.10" ) -- ######### COMMENTS ##########
	end

	MainRoutine( EventMemory )

end


function MainRoutine( EventMemory )

	if EventMemory == nil then

		return

	end
--cScriptMessage( EventMemory["MapIndex"], NOTICEINFO[2]["INDEX"] )
--cAssertLog( "TestData: cScriptMessage: " .. EventMemory["MapIndex"] .. "," .. NOTICEINFO[2]["FILENAME"] .. "," .. NOTICEINFO[2]["INDEX"] ) -- ######### COMMENTS ##########

	EventMemory["CurrentTime"] = cCurrentSecond()

	if EventMemory["EM_STATE"] == EM_STATE["Start"] then
cAssertLog( "TestData: MainRoutine 3" ) -- ######### COMMENTS ##########

--cScriptMessage( EventMemory["MapIndex"], "AdlF_Msg_02_001" )
--cAssertLog( "TestData: cScriptMessage: TestMessage05here" ) -- ######### COMMENTS ##########
--cScriptMessage( EventMemory["MapIndex"], NOTICEINFO[2]["INDEX"] )
cAssertLog( "TestData: TestData: MainRoutine 3.5 " .. EventMemory["MapIndex"] .. "," .. "AdlF_Msg_02_001" ) -- outputs to the zone assert log

		EventMemory["EM_STATE"]	= EM_STATE["Play"]
		EVENT_INIT_FUNC[EventMemory["EventNumber"]] ( EventMemory )

	elseif EventMemory["EM_STATE"] == EM_STATE["Play"] then

		local ReturnValue = EVENT_ROUTINE[EventMemory["EventNumber"]] ( EventMemory )

		if ReturnValue == EVENT_ROUTINE_END then
cAssertLog( "TestData: MainRoutine 4" ) -- ######### COMMENTS ##########

			EventMemory["EM_STATE"] = EM_STATE["End"]

		end

	elseif EventMemory["EM_STATE"] == EM_STATE["End"] then
cAssertLog( "TestData: MainRoutine 5" ) -- ######### COMMENTS ##########

		EVENT_DEINIT_FUNC[EventMemory["EventNumber"]] ( EventMemory )
		EventMemory["EventNumber"] = EventMemory["EventNumber"] + 1

	end

end

