--================ Danh Sách Các qStep =================--

require "npc/vl_quest_npc_client"
require "questui/vl_quest_introwindow_ui"
require "questui/vl_quest_markers"
require "questui/vl_quest_popup_ui"
require "mainquest1/vl_quest1_questupdate"
require "buildingstructure/vl_buildingstructure_utils"
require "buildingstructure/vl_bunker_labroom_basement"

VLQS = VLQS or {}
VLQS.Q1Steps = VLQS.Q1Steps or {}

VLF.var.requestCol = {
	["q1s053"] = 3000,
	["q1s032"] = 2,
	["q1s031"] = 1500,
	["q1s028"] = 10,
	["q1s027"] = 3,
	["q1s026"] = 5,
	["q1s021"] = 15,
	["q1s018"] = 15,
	["q1s017"] = 30,
	["q1s016"] = 1400
	}
	

local qtype = getText("IGUI_VLQ_MainQuest")
local questMarker = getTexture("media/textures/questmarker_48.png")
local localVar = {}

assert(VLPL, "Stack trace: Missing dependency: VLPL - vl_quest1_queststep_list.lua")
assert(VLZB, "Stack trace: Missing dependency: VLZB - vl_quest1_queststep_list.lua")
assert(VLIT, "Stack trace: Missing dependency: VLIT - vl_quest1_queststep_list.lua")
assert(VLBS, "Stack trace: Missing dependency: VLBS - vl_quest1_queststep_list.lua")

local ActiveQuestIntro_Centre = VLF.ActiveQuestIntro_Centre
local ActiveQuestIntro_Free = VLF.ActiveQuestIntro_Free
local MarkerList_Add = VLF.MarkerList_Add
local SetNPCStateInQueueSpawnList = VLZB.SetNPCStateInQueueSpawnList
local DoSpawnItemQuestOnSquare = VLIT.DoSpawnItemQuestOnSquare
local IsPlayerInArea = VLPL.IsPlayerInArea
local GetItemQuestInINVPlayer = VLIT.GetItemQuestInINVPlayer
local AddCorpseInArea = VLZB.AddCorpseInArea
local GetPlayerGlobalModDataQ1 = VLGMD.GetPlayerGlobalModDataQ1
local QuestUpdatedPopIn = VLF.QuestUpdatedPopIn
local DoSpawnItemQuestInContainer = VLIT.DoSpawnItemQuestInContainer
local GetQuestGlobalModData = VLGMD.GetQuestGlobalModData
local GetNPCsByVarAndQStep = VLZB.GetNPCsByVarAndQStep
local GetZombieID = VLZB.GetZombieID
local SetNewZombieStats = VLZB.SetNewZombieStats
local AddObjectToSquare = VLF.AddObjectToSquare
local AddCorpseCustomize = VLZB.AddCorpseCustomize
local RemoveObjectOnSquare = VLF.RemoveObjectOnSquare
local GetSquare = VLF.GetSquare
local GetZombieOnlineIDorUID = VLZB.GetZombieOnlineIDorUID
local NPCTurnToZombie = VLF.NPCTurnToZombie
local AddItemToSquares = VLIT.AddItemToSquares
local GetObjectOnSquare = VLF.GetObjectOnSquare
local GetOrCreateSquare = VLF.GetOrCreateSquare
local GetZombieModDataQuest = VLZB.GetZombieModDataQuest
local DoQuestStepActive = VLF.DoQuestStepActive
local UpdateNPCToNextQStep = VLZB.UpdateNPCToNextQStep
local AddBunkerLabRoom = VLBS.AddBunkerLabRoom
local SpawnNPCOnClient = VLZB.SpawnNPCOnClient
local IsPlayerCanSeeNPC = VLPL.IsPlayerCanSeeNPC
local SetPlayerGMD_Q1 = VLGMD.SetPlayerGMD_Q1
local RemoveNPCQuest = VLZB.RemoveNPCQuest
local GetFoodInContainer = VLIT.GetFoodInContainer
local KillNPCQuest = VLZB.KillNPCQuest
local GetWaterSourcesInCont = VLIT.GetWaterSourcesInCont
local GetPlayerGlobalModData = VLGMD.GetPlayerGlobalModData
local SetPlayerGMD_Data = VLGMD.SetPlayerGMD_Data
local GetItemsInContainer = VLIT.GetItemsInContainer
local RemoveItemFromContainer = VLIT.RemoveItemFromContainer

--Kiểm tra thức ăn trên người
local function HasFoodInINV(player)
    if not player then return false end
    local items = player:getInventory():getItems()
    for i = 0, items:size() - 1 do
        local item = items:get(i)
        if item then
            if item:IsFood() then
                return true
            end
        end
    end
    return false
end

--Kiểm tra nước uống trên người
local function HasDrinkInINV(player)
    if not player then return false end
    local items = player:getInventory():getItems()
    for i = 0, items:size() - 1 do
        local item = items:get(i)
        if item then
            if item:isWaterSource() then
                return true
            end
        end
    end
    return false
end

--THÊM HOẶC CẬP NHẬT NHIỆM VỤ TRONG BẢNG QUEST - không cần xóa bảng đã thêm trước đó vì đã được ghi đè
local function QuestList_AddItem(text, itemData) --QuestList_AddItem("Q"..tostring(id), {id = id, qStep = qStep, isDone = isDone, qtype = qtype, isCollection = isCollection, currentCollection = currentCollection, requestCollection = requestCollection, name = getText("IGUI_VLQ_"..tostring(id).."_Name"), task = getText("IGUI_VLQ_"..tostring(id).."_Task_"..tostring(qStep)), desc = getText("IGUI_VLQ_"..tostring(id).."_Desc_"..tostring(qStep))})
    if not text or not itemData then return end
	local id,qStep  = itemData.id, itemData.qStep
	local isDone = itemData.isDone or false
	local isCollection, currentCollection, requestCollection = itemData.isCollection or false, itemData.currentCollection, itemData.requestCollection
	local collectQItemName = itemData.collectQItemName or nil
	local qtype = itemData.qtype or getText("IGUI_VLQ_MainQuest")
	if not id or not qStep then return end
	
    VLF.QuestListShowOnUI[text] = {id = id, qStep = qStep, isDone = isDone, qtype = qtype, isCollection = isCollection, currentCollection = currentCollection, requestCollection = requestCollection, collectQItemName = collectQItemName, name = itemData.name, task = itemData.task, desc = itemData.desc}
end

local function DoQuestList_AddItem(args) --DoQuestList_AddItem({id = 1, qStep = "q1s003", isDone = false, qtype = getText("IGUI_VLQ_MainQuest"), isCollection = false, currentCollection = nil, requestCollection = nil})
	local id, qStep = args.id, args.qStep
	if not id or not qStep then return end
	QuestList_AddItem("Q"..tostring(id), {id = id, qStep = qStep, isDone = args.isDone, qtype = args.qtype, isCollection = args.isCollection, currentCollection = args.currentCollection, requestCollection = args.requestCollection, collectQItemName = args.collectQItemName, name = getText("IGUI_VLQ_"..tostring(id).."_Name"), task = getText("IGUI_VLQ_"..tostring(id).."_Task_"..tostring(qStep)), desc = getText("IGUI_VLQ_"..tostring(id).."_Desc_"..tostring(qStep))})
end

local function DoAddCorpses(player, square, args) --DoAddCorpses(player, square, {qStep = qStep, x = -1, y = -1, z = 0, isSplatBlood = true, isBloodFloor = true, range = 1, number = 5})
	local sq = square or getCell():getGridSquare(args.x, args.y, args.z)
	local x, y, z = sq:getX(), sq:getY(), sq:getZ()
	local corpse
	if sq then --check square để chắc chắn vị trí spawn item đã được load. Dù có teleport đến vẫn spawn.Vì khi tp, code chạy trước khi square các tầng cao chưa load
		local qStep = args.qStep
		local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
		if not playerGMD_Quest_Q1[qStep].isAddedCorpses then
			local isSplatBlood, isBloodFloor, range, number = args.isSplatBlood or false, args.isBloodFloor or false, args.range or 1, args.number or 1
			for i = 1, number do
				corpse = AddCorpseInArea({x = x, y = y, z = z, isSplatBlood = isSplatBlood, isBloodFloor = isBloodFloor, range = range})
			end
			playerGMD_Quest_Q1[qStep].isAddedCorpses = true
			sendClientCommand(player, "MainQuest1", "UpdateQuestStep", {qStep_isAddedCorpses = qStep, isAddedCorpses = playerGMD_Quest_Q1[qStep].isAddedCorpses})
		end
	end
end

local function AddCorpseEventq1s009()
	AddCorpseCustomize({x = 13521, y = 4856, z = 0, outfitName = "Police", femaleChance = 0, number = 1})
	AddCorpseCustomize({x = 13515, y = 4854, z = 0, outfitName = "Police", femaleChance = 0, number = 1})	
	AddCorpseCustomize({x = 13514, y = 4860, z = 0, outfitName = "Police", femaleChance = 0, number = 2})
	AddCorpseCustomize({x = 13520, y = 4861, z = 0, outfitName = "Police", femaleChance = 0, number = 1})	
	AddCorpseCustomize({x = 13518, y = 4859, z = 0, outfitName = "Police", femaleChance = 0, number = 1})	
	AddCorpseCustomize({x = 13521, y = 4868, z = 0, outfitName = "Police", femaleChance = 0, number = 2})	
	AddCorpseCustomize({x = 13524, y = 4862, z = 0, outfitName = "Police", femaleChance = 0, number = 1})
	AddCorpseCustomize({x = 13520, y = 4863, z = 0, outfitName = "Police", femaleChance = 0, number = 2})
	
	AddCorpseCustomize({x = 13519, y = 4852, z = 0, outfitName = "PoliceRiot", femaleChance = 0, number = 1})
	AddCorpseCustomize({x = 13510, y = 4846, z = 0, outfitName = "PoliceRiot", femaleChance = 0, number = 1})
	AddCorpseCustomize({x = 13529, y = 4856, z = 0, outfitName = "PoliceRiot", femaleChance = 0, number = 1})
end
	
function VLF.WaitTimePassQ1()
	local player = getPlayer()
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, nil)
	local nowHour = getGameTime():getWorldAgeHours()
	local qStep, hourToWait
	
	if playerGMD_Quest_Q1.q1s058 and playerGMD_Quest_Q1.q1s058.active == true then--chờ 72h	
		qStep, hourToWait = "q1s058", 72
	elseif playerGMD_Quest_Q1.q1s056 and playerGMD_Quest_Q1.q1s056.active == true then--chờ 24h	
		qStep, hourToWait = "q1s056", 24
	elseif playerGMD_Quest_Q1.q1s054 and playerGMD_Quest_Q1.q1s054.active == true then--chờ 24h	
		qStep, hourToWait = "q1s054", 24
	elseif playerGMD_Quest_Q1.q1s053 and playerGMD_Quest_Q1.q1s053.active == true then--chờ 72h	
		qStep, hourToWait = "q1s053", 72
	elseif playerGMD_Quest_Q1.q1s051 and playerGMD_Quest_Q1.q1s051.active == true then--chờ 36h	
		qStep, hourToWait = "q1s051", 36
	elseif playerGMD_Quest_Q1.q1s049 and playerGMD_Quest_Q1.q1s049.active == true then--chờ 2h	
		qStep, hourToWait = "q1s049", 2
	elseif playerGMD_Quest_Q1.q1s046 and playerGMD_Quest_Q1.q1s046.active == true then--chờ 24h	
		qStep, hourToWait = "q1s046", 24
	elseif playerGMD_Quest_Q1.q1s037 and playerGMD_Quest_Q1.q1s037.active == true then--chờ 48h	
		qStep, hourToWait = "q1s037", 48
	elseif playerGMD_Quest_Q1.q1s033 and playerGMD_Quest_Q1.q1s033.active == true then--chờ 168h	
		qStep, hourToWait = "q1s033", 168
	elseif playerGMD_Quest_Q1.q1s029 and playerGMD_Quest_Q1.q1s029.active == true then--chờ 72h	
		qStep, hourToWait = "q1s029", 72
	elseif playerGMD_Quest_Q1.q1s024 and playerGMD_Quest_Q1.q1s024.active == true then--chờ 72h	
		qStep, hourToWait = "q1s024", 72
	elseif playerGMD_Quest_Q1.q1s022 and playerGMD_Quest_Q1.q1s022.active == true then--chờ 24h	
		qStep, hourToWait = "q1s022", 24
	elseif playerGMD_Quest_Q1.q1s019 and playerGMD_Quest_Q1.q1s019.active == true then--chờ 24h
		qStep, hourToWait = "q1s019", 24
	end
	if qStep and hourToWait then
		--print("Client-----------WaitTimePassQ1= "..tostring(nowHour).." - "..tostring(playerGMD_Quest_Q1[qStep].startHourWait))
		if not playerGMD_Quest_Q1[qStep].startHourWait then
			playerGMD_Quest_Q1[qStep].startHourWait = nowHour
			sendClientCommand(player, "MainQuest1", "UpdatePlayerGMD", {qStep = qStep, key = "waitHourPass", waitHourPassed = nil, startHourWait = nowHour})
		end
		if (nowHour - playerGMD_Quest_Q1[qStep].startHourWait) >= hourToWait then
			playerGMD_Quest_Q1[qStep].waitHourPassed = true
			playerGMD_Quest_Q1[qStep].startHourWait = nil
			sendClientCommand(player, "MainQuest1", "UpdatePlayerGMD", {qStep = qStep, key = "waitHourPass", waitHourPassed = true, startHourWait = nil})
			Events.EveryHours.Remove(VLF.WaitTimePassQ1)
			return
		end
	end
end
local WaitTimePassQ1 = VLF.WaitTimePassQ1
--Events.EveryHours.Remove(WaitTimePassQ1)
--Events.EveryHours.Add(WaitTimePassQ1)

--Khởi tạo ModData cho quest collect item --Không cần transmit
local function SetDataForCollectQuest(player, qStep, dataName, collected, request)
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	local collectedKey = "collected" .. dataName
	local requestKey   = "request" .. dataName
	if not playerGMD_Quest_Q1[qStep][collectedKey] then
		playerGMD_Quest_Q1[qStep][collectedKey] = collected
	end
	if not playerGMD_Quest_Q1[qStep][requestKey] then
		playerGMD_Quest_Q1[qStep][requestKey] = request
	end
	return playerGMD_Quest_Q1[qStep][collectedKey], playerGMD_Quest_Q1[qStep][requestKey]
end

--==================================================================--

VLQS.Q1Steps["q1s000"] = function(player)
	DoQuestStepActive(player, {isPopIn = false, qStep = "q1s000", active = "done", qStep_Next = "q1s001", active_Next = true})
end

--q1s001 - tìm nước uống
VLQS.Q1Steps["q1s001"] = function(player)
	local qStep, qStep_Next = "q1s001", "q1s002"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	if HasDrinkInINV(player) then
		DoQuestStepActive(player, {introWindow = false, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true})
		ActiveQuestIntro_Free(getText("IGUI_VLQ_1_Desc_q1s002"), (getCore():getScreenWidth() - 800) / 2, (getCore():getScreenHeight() - 200) / 6, 800, 200, false, "")
	end
end

--q1s002 - tìm thức ăn
VLQS.Q1Steps["q1s002"] = function(player)
	local qStep, qStep_Next = "q1s002", "q1s003"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	if HasFoodInINV(player) then
		DoQuestStepActive(player, {introWindow = true, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true})
	end
end

--q1s003 - NPC - Tìm em trai tại trường trung học Riverside - nói chuyện với phó Hiệu Trưởng
VLQS.Q1Steps["q1s003"] = function(player)
	local qStep, qStep_Next = "q1s003", "q1s004"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 6444, y = 5447, texture = questMarker})
end

--q1s004 - NPC - Đến trụ sở cảnh sát Riverside để hỏi về em trai - nói chuyện với cảnh sát viên
VLQS.Q1Steps["q1s004"] = function(player)
	local qStep, qStep_Next = "q1s004", "q1s005"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 6082, y = 5260, texture = questMarker})
end

--q1s005 - Đi đến nhà cảnh sát trưởng để hỏi rõ tình hình
VLQS.Q1Steps["q1s005"] = function(player)
	local qStep, qStep_Next = "q1s005", "q1s006"
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 6762, y = 5393, texture = questMarker})

	local itemFullType = "Base.GenericMail"
	--spawn nhật ký của cảnh sát trưởng
	if IsPlayerInArea(player, 6757, 5385, 6769, 5398, nil) then
		if not localVar["addItem5"] then
			local x, y, z = 6760, 5391, 1
			local square = GetSquare(x, y, z, true, false, false, false)
			if square then
				local item = DoSpawnItemQuestOnSquare({qStep = qStep, x = x, y = y, z = z, itemFullType = itemFullType, range = 1, isNote = true, noteStep = 1, qID = 1, iModData = "isKeyQuest1"})					 
				if item then localVar["addItem5"] = true end
			end
		end
		--Thêm xác chết bên ngoài cửa phòng
		if not playerGMD_Quest_Q1[qStep].isAddedCorpses then
			local x, y, z = 6764, 5391, 1
			local square = GetSquare(x, y, z, true, false, false, false)
			if square then
				DoAddCorpses(player, square, {qStep = qStep, x = x, y = y, z = z, isSplatBlood = true, isBloodFloor = true, range = 1, number = 5})
			end
		end
	else 
		if localVar["addItem5"] ~= false then localVar["addItem5"] = false end
	end
				
	--lấy được nhật ký
	local itemQuest = GetItemQuestInINVPlayer(player, itemFullType, qStep, "isKeyQuest1")
	if itemQuest then
		--lấy nhật ký thì npc thành zombie
		local zNPCList = GetNPCsByVarAndQStep("npcQuestIdle", qStep)
		if zNPCList and zNPCList[1] then
			NPCTurnToZombie(player, zNPCList[1], qStep, {isPopUp = false})
		end
		
		DoQuestStepActive(player, {introWindow = true, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false})
		--print("Client-----------PlayerModData.active= "..tostring(qStep).." - ", playerGMD_Quest_Q1[qStep].active)
	end
end
 
--q1s006 - Tìm em trai tại doanh trại quân đội Military Research Facility
VLQS.Q1Steps["q1s006"] = function(player)
	local qStep, qStep_Next = "q1s006", "q1s007"
	local playerGMD = GetPlayerGlobalModData(player)
	
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 5561, y = 12480, texture = questMarker})
 
	local itemFullType = "Base.GenericMail"
	if IsPlayerInArea(player, 5537, 12456, 5583, 12504, 0) then
		--Add các item quest 1 lần duy nhất --nếu player chết thì sẽ add lại --document
		if not localVar["addItem6_4"] then
			local x, y, z = 5579, 12486, 0
			local square = GetOrCreateSquare(x, y, z)
			if square then
				DoSpawnItemQuestInContainer({qStep = qStep, x = x, y = y, z = z, itemFullType = "Base.GenericMail", range = 0, isNote = true, noteStep = 1, qID = 1, addOnSquare = true})
				localVar["addItem6_4"] = true
			end			
		end

		if not localVar["addItem6_5"] then
			local x, y, z = 5554, 12486, 0
			local square = GetOrCreateSquare(x, y, z)
			if square then
				DoSpawnItemQuestInContainer({qStep = qStep, x = x, y = y, z = z, itemFullType = "Base.GenericMail", range = 0, isNote = true, noteStep = 2, qID = 1, addOnSquare = true})
				localVar["addItem6_5"] = true
			end
		end		
	end
	
	--Add các item quest chính --document
	if IsPlayerInArea(player, 5559, 12429, 5578, 12452, -17) then
		if not localVar["addItem6"] then --đảm bảo chỉ chạy 1 lần khi player ở trong khu vực này
			local x, y, z = 5566, 12430, -17
			local square = GetOrCreateSquare(x, y, z)
			if square then
				DoSpawnItemQuestInContainer({qStep = qStep, x = x, y = y, z = z, itemFullType = "Base.GenericMail", range = 0, isNote = true, noteStep = 3, qID = 1, addOnSquare = true})
				localVar["addItem6"] = true
			end
			
			--Gợi ý nhiệm vụ
			HaloTextHelper.addGoodText(player, getText("IGUI_VLQ_1_HaloText1_q1s006"))
		end
		
		if not localVar["addItem6_2"] then
			local x, y, z = 5564, 12432, -17
			local square = GetOrCreateSquare(x, y, z)
			if square then
				DoSpawnItemQuestInContainer({qStep = qStep, x = x, y = y, z = z, itemFullType = itemFullType, range = 0, isNote = true, noteStep = 4, qID = 1, addOnSquare = true, iModData = "isKeyQuest1"})
				localVar["addItem6_2"] = true
			end
		end
		
		if not localVar["addItem6_3"] then
			local x, y, z = 5564, 12434, -17
			local square = GetOrCreateSquare(x, y, z)
			if square then
				DoSpawnItemQuestInContainer({qStep = qStep, x = x, y = y, z = z, itemFullType = itemFullType, range = 0, isNote = true, noteStep = 5, qID = 1, addOnSquare = true, iModData = "isKeyQuest2"})
				localVar["addItem6_3"] = true
			end
		end
	else
		if localVar["addItem6"] ~= false then localVar["addItem6"] = false end
		if localVar["addItem6_2"] ~= false then localVar["addItem6_2"] = false end
		if localVar["addItem6_3"] ~= false then localVar["addItem6_3"] = false end
	end
	
	--Kiểm tra đã lấy được 2 item quest isKeyQuest chưa
	if not playerGMD.Data["hasQItem1_q1s006"] then
		local itemQuest = GetItemQuestInINVPlayer(player, itemFullType, qStep, "isKeyQuest1")
		if itemQuest then
			SetPlayerGMD_Data(player, "hasQItem1_q1s006", true)
		end
	end
	
	if not playerGMD.Data["hasQItem2_q1s006"] then
		local itemQuest = GetItemQuestInINVPlayer(player, itemFullType, qStep, "isKeyQuest2")

		if itemQuest then 
			SetPlayerGMD_Data(player, "hasQItem2_q1s006", true)
		end
	end
	
	if playerGMD.Data["hasQItem1_q1s006"] == true and playerGMD.Data["hasQItem2_q1s006"] == true then
		SetPlayerGMD_Data(player, "hasQItem1_q1s006", nil)
		SetPlayerGMD_Data(player, "hasQItem2_q1s006", nil)
		DoQuestStepActive(player, {introWindow = true, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true})
	end
end

--q1s007 - Tìm em trai tại Finnegan Research Group
VLQS.Q1Steps["q1s007"] = function(player)
	local qStep, qStep_Next = "q1s007", "q1s008"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 13591, y = 1703, texture = questMarker})
	
	--Gợi ý NPC trên mái
	if IsPlayerInArea(player, 13561, 1688, 13625, 1722, 0) then
		if not localVar["addEvent7"] then
			HaloTextHelper.addGoodText(player, getText("IGUI_VLQ_1_HaloText1_q1s007"))
			localVar["addEvent7"] = true
		end
	else
		if localVar["addEvent7"] then localVar["addEvent7"] = nil end
	end
end

--q1s008 - Tìm manh mối tại Louisville Metro Police Department
VLQS.Q1Steps["q1s008"] = function(player)
	local qStep, qStep_Next = "q1s008", "q1s009"
	local questMD = GetQuestGlobalModData(qStep)
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12539, y = 1633, texture = questMarker})	
	
	if IsPlayerInArea(player, 12510, 1600, 12570, 1656, 6) then
		--if not pDataQ.itemQuest[qStep].spawnedEventObj then
		local modDataKey, val = "AddedEventObjects", true
		--print("Client----questMD.Object 111 = ", questMD.Object[qStep])
		if not questMD.Object[qStep] then questMD.Object[qStep] = {} end
		
		if not questMD.Object[qStep][modDataKey] then
			local x, y, z = 12555, 1634, 6
			local square = GetSquare(x, y, z, true, false, false, false)
			--print("Client----questMD.Object 333 = ", square)
			
			if square then
				sendClientCommand(player, "NPCQuestCM", "RemoveZombiesInAreaExceptNPC", {x1 = 12553, y1 = 1628, x2 = 12561, y2 = 1635, z = 6})
				local object = AddObjectToSquare(nil, "location_business_office_generic_01_32", {isTransmit = true, needSqIsFree = true, needFloor = true, x = x, y = y, z = z, objType = "IsoObject", isNorth = true, isLocked = false})
				
				if object then questMD.Object[qStep][modDataKey] = val end
				sendClientCommand(player, "NPCQuestCM", "UpdateQuestModData", {qStep = qStep, modDataKey = modDataKey, val = val})
			end
		end
	end
end

--q1s009 - Tìm địa điểm bị tập kích
VLQS.Q1Steps["q1s009"] = function(player)
	local qStep, qStep_Next = "q1s009", "q1s010"
	local questMD = GetQuestGlobalModData(qStep)
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	
	if IsPlayerInArea(player, 13460, 4801, 13580, 4921, nil) then
		--Check 4 square để đảm bảo khu vực event đã được load hết
		local square1 = GetSquare(13511, 4849, 0, true, false, false, false)
		local square2 = GetSquare(13526, 4849, 0, true, false, false, false)
		local square3 = GetSquare(13511, 4871, 0, true, false, false, false)
		local square4 = GetSquare(13526, 4871, 0, true, false, false, false)
							
		if square1 and square2 and square3 and square4 then	
			local modDataKey, val = "AddedEventObjects", true
			if not questMD.Object[qStep] then questMD.Object[qStep] = {} end
			if not questMD.Object[qStep][modDataKey] then
				sendClientCommand(player, "MainQuest1", "AddVehicleEvents", {qStep = qStep}) --thêm vehicles event
				AddCorpseEventq1s009() --thêm xác event
				sendClientCommand(player, "NPCQuestCM", "UpdateQuestModData", {qStep = qStep, modDataKey = modDataKey, val = val})
				questMD.Object[qStep][modDataKey] = val
			end
			if IsPlayerInArea(player, 13511, 4849, 13526, 4871, nil) then
				DoQuestStepActive(player, {introWindow = false, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false})
			end
		end
	end
end

--q1s010 - Tìm manh mối tại địa điểm bị tập kích 
VLQS.Q1Steps["q1s010"] = function(player)
	local qStep, qStep_Next = "q1s010", "q1s011"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	
	--add note
	local itemFullType = "Base.Notepad"
	if IsPlayerInArea(player, 13460, 4801, 13580, 4921, nil) then
		if not localVar["addItem10"] then --đảm bảo chỉ chạy 1 lần khi player ở trong khu vực này, tránh spawn lại item khi bị nhặt lên
			local x, y, z = 13519, 4862, 0
			local square = GetOrCreateSquare(x, y, z)
			if square then
				DoSpawnItemQuestOnSquare({qStep = qStep, x = x, y = y, z = z, itemFullType = itemFullType, range = 1, isNote = true, noteStep = 1, qID = 1, iModData = "isKeyQuest1"})					 
				localVar["addItem10"] = true
			end
		end				
	else
		if localVar["addItem10"] ~= false then localVar["addItem10"] = false end
	end
	
	--lấy được note
	local itemQuest = GetItemQuestInINVPlayer(player, itemFullType, qStep, "isKeyQuest1")
	if itemQuest then
		DoQuestStepActive(player, {introWindow = false, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false})
	end
end

--q1s011 - Tìm manh mối về từ khóa MUL 
VLQS.Q1Steps["q1s011"] = function(player)
	local qStep, qStep_Next = "q1s011", "q1s012"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
end

--q1s012 --Phòng thí nghiệm bí ẩn
VLQS.Q1Steps["q1s012"] = function(player)
	local qStep, qStep_Next = "q1s012", "q1s013"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})	
end

--q1s013 --Tìm Dr. Bassler
VLQS.Q1Steps["q1s013"] = function(player)
	local qStep, qStep_Next = "q1s013", "q1s014"
	local questMD = GetQuestGlobalModData(qStep)
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})	
	
	if IsPlayerInArea(player, 10569, 9444, 10689, 9564, 0) then
		local modDataKey, val = "AddedEventObjects", true
		if not questMD.Object[qStep] then questMD.Object[qStep] = {} end
		
		if not questMD.Object[qStep][modDataKey] then
			local x, y, z = 10628, 9503, 0
			local square = GetOrCreateSquare(x, y, z)
			
			if square then
				local object = AddObjectToSquare(nil, "location_business_office_generic_01_32", {isTransmit = true, needSqIsFree = true, needFloor = true, x = x, y = y, z = z, objType = "IsoObject", isNorth = true, isLocked = false})
				if object then questMD.Object[qStep][modDataKey] = val end
				sendClientCommand(player, "NPCQuestCM", "UpdateQuestModData", {qStep = qStep, modDataKey = modDataKey, val = val})
			end
		end
	end
end

--q1s014 --Trở về phòng thí nghiệm Dr. Venter
VLQS.Q1Steps["q1s014"] = function(player)
	local qStep, qStep_Next = "q1s014", "q1s015"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

--q1s015 --Đồng ý hỗ trợ Dr. Venter
VLQS.Q1Steps["q1s015"] = function(player)
	local qStep, qStep_Next = "q1s015", "q1s016"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

--q1s016 --Hỗ trợ Dr. Venter tìm kiếm thức ăn -- 1 người/ngày/100 hunger --1400
VLQS.Q1Steps["q1s016"] = function(player)
	local qStep, qStep_Next = "q1s016", "q1s017"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "RHunger", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = getText("IGUI_VLQ_2_CollectQItemName_q1s016")})
end

--q1s017 --Hỗ trợ Dr. Venter tìm nước tinh khiết -- 1 người/ngày/2l --30
VLQS.Q1Steps["q1s017"] = function(player)
	local qStep, qStep_Next = "q1s017", "q1s018"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "RThirst", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = getText("IGUI_VLQ_2_CollectQItemName_q1s017")})
end

--q1s018 --Hỗ trợ Dr. Venter lấy mẫu máu xác sống
VLQS.Q1Steps["q1s018"] = function(player)
	local qStep, qStep_Next = "q1s018", "q1s019"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local qItem = instanceItem("Base.VLZBloodSyringe")
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "ZBlood", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = qItem and qItem:getName() or nil})
	if not localVar["addMenu18"] then
		Events.OnPreFillWorldObjectContextMenu.Remove(VLF.AddContextMenu_BloodSample)
		Events.OnPreFillWorldObjectContextMenu.Add(VLF.AddContextMenu_BloodSample)
		localVar["addMenu18"] = true
	end
end

--q1s019 --Chờ đợi Dr. Venter nghiên cứu mẫu máu --1 ngày
VLQS.Q1Steps["q1s019"] = function(player)
	local qStep, qStep_Next = "q1s019", "q1s020"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent19"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent19"] = true
	end
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true, qID = 2}) --cập nhật qStep --kiểm tra bắt buộc isNPC_Next
	end
end

--q1s020 --Trở lại phòng thí nghiệm của Dr. Venter
VLQS.Q1Steps["q1s020"] = function(player)
	local qStep, qStep_Next = "q1s020", "q1s021"	
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

--q1s021 --Hỗ trợ Dr. Venter lấy 15 mẫu vật từ xác sống
VLQS.Q1Steps["q1s021"] = function(player)
	local qStep, qStep_Next = "q1s021", "q1s022"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local qItem = instanceItem("Base.VLZSpecimenContainer")
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "ZSpecimen", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = qItem and qItem:getName() or nil})
	if not localVar["addMenu21"] then
		Events.OnPreFillWorldObjectContextMenu.Remove(VLF.AddContextMenu_ZombieSpecimen)
		Events.OnPreFillWorldObjectContextMenu.Add(VLF.AddContextMenu_ZombieSpecimen)
		localVar["addMenu21"] = true
	end		
end

--q1s022 --Chờ đợi Dr. Venter nghiên cứu mẫu vật --1 ngày
VLQS.Q1Steps["q1s022"] = function(player)
	local qStep, qStep_Next = "q1s022", "q1s023"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent22"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent22"] = true
	end
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true, qID = 2})
	end
end

--q1s023 --Uống rượu cùng người bạn vong niên
VLQS.Q1Steps["q1s023"] = function(player)
	local qStep, qStep_Next = "q1s023", "q1s024"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

--q1s024 --Chờ đợi Dr. Venter nghiên cứu mẫu vật --3 ngày
VLQS.Q1Steps["q1s024"] = function(player)
	local qStep, qStep_Next = "q1s024", "q1s025"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent24"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent24"] = true
	end
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true, qID = 2})
	end
end

--q1s025 --Trở lại phòng thí nghiệm của Dr. Venter
VLQS.Q1Steps["q1s025"] = function(player)
	local qStep, qStep_Next = "q1s025", "q1s026"	
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

--q1s026 --Hỗ trợ Dr. Venter bắt 5 con chuột sống
VLQS.Q1Steps["q1s026"] = function(player)
	local qStep, qStep_Next = "q1s026", "q1s027"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "Mouse", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = getText("IGUI_VLQ_2_CollectQItemName_q1s026")})
end

--q1s027 --Hỗ trợ Dr. Venter bắt 3 con ếch còn sống
VLQS.Q1Steps["q1s027"] = function(player)
	local qStep, qStep_Next = "q1s027", "q1s028"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local qItem = instanceItem("Base.Frog")
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "Frog", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = qItem and qItem:getName() or nil})
end

--q1s028 --Hỗ trợ Dr. Venter bắt 10 con đỉa còn sống- Leech
VLQS.Q1Steps["q1s028"] = function(player)
	local qStep, qStep_Next = "q1s028", "q1s029"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local qItem = instanceItem("Base.Leech")
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "Leech", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = qItem and qItem:getName() or nil})
end

--q1s029 --Chờ đợi Dr. Venter nghiên cứu mẫu vật --3 ngày
VLQS.Q1Steps["q1s029"] = function(player)
	local qStep, qStep_Next = "q1s029", "q1s030"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent29"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent29"] = true
	end
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true, qID = 2})
	end
end

--q1s030 --Trở lại phòng thí nghiệm của Dr. Venter
VLQS.Q1Steps["q1s030"] = function(player)
	local qStep, qStep_Next = "q1s030", "q1s031"	
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

--q1s031 --Hỗ trợ Dr. Venter tìm kiếm thức ăn -- 1 người/ngày/100 hunger --1500
VLQS.Q1Steps["q1s031"] = function(player)
	local qStep, qStep_Next = "q1s031", "q1s032"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "RHunger", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = getText("IGUI_VLQ_2_CollectQItemName_q1s016")})
end

--q1s032 --Hỗ trợ Dr. Venter lấy 2 mẫu vật từ người đang bị biến đổi
VLQS.Q1Steps["q1s032"] = function(player)
	local qStep, qStep_Next = "q1s032", "q1s033"
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	local qItem = instanceItem("Base.VLInfectedSpecimenContainer")
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "InfecSpecimen", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = qItem and qItem:getName() or nil})

	if not localVar["addEvent32"] then
		Events.EveryHours.Remove(VLF.Event_Survivalist_InHouse)
		Events.EveryHours.Add(VLF.Event_Survivalist_InHouse)
		Events.OnPreFillWorldObjectContextMenu.Remove(VLF.AddContextMenu_InfectedSpecimen)
		Events.OnPreFillWorldObjectContextMenu.Add(VLF.AddContextMenu_InfectedSpecimen)
		localVar["addEvent32"] = true
	end
end

--q1s033 --Chờ đợi Dr. Venter nghiên cứu mẫu vật --7 ngày
VLQS.Q1Steps["q1s033"] = function(player)
	local qStep, qStep_Next = "q1s033", "q1s034"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	--if not playerGMD_Quest_Q1[qStep].startHourWait then playerGMD_Quest_Q1[qStep].startHourWait = getGameTime():getWorldAgeHours() end
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent33"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent33"] = true
	end
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true, qID = 2})
	end
end

--q1s034 --Trở lại phòng thí nghiệm của Dr. Venter
VLQS.Q1Steps["q1s034"] = function(player)
	local qStep, qStep_Next = "q1s034", "q1s035"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

local function EveryTenMinutes_AddSoundNoise()
	local sq = getCell():getGridSquare(10637, 10405, 0)
	if sq then addSound(sq:getFloor(), sq:getX(), sq:getY(), sq:getZ(), 250, 1000) end
end
--Events.EveryTenMinutes.Remove(EveryTenMinutes_AddSoundNoise)
--Events.EveryTenMinutes.Add(EveryTenMinutes_AddSoundNoise)

--q1s035 --Hối thúc Dr. Venter tiêu hủy mẫu vật sống
VLQS.Q1Steps["q1s035"] = function(player)
	local qStep, qStep_Next = "q1s035", "q1s036"
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	
	--Khi q1s035_2 active thì đổi hiển thị trong bảng Quest
	if not playerGMD_Quest_Q1.q1s035_2 then playerGMD_Quest_Q1.q1s035_2 = {} end
	if playerGMD_Quest_Q1.q1s035_2.active == true then
		DoQuestList_AddItem({id = 2, qStep = "q1s035_2", isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
		--Tạo sound nil thu hút zombies
		if not localVar["addNoise35"] then	
			Events.EveryTenMinutes.Remove(EveryTenMinutes_AddSoundNoise)
			Events.EveryTenMinutes.Add(EveryTenMinutes_AddSoundNoise)
			localVar["addNoise35"] = true
		end
	else
		DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	end
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	
	--Không còn zombie xung quanh thì update NPC và qStep
	--local pDataQ = GetPlayerModDataQuest(nil)
	--if pDataQ.events.q1s035 == true then
	local playerGMD = GetPlayerGlobalModData(player)
	if playerGMD.Data["event_q1s035"] == true then
	
		local zNPCList = GetNPCsByVarAndQStep("npcQuestIdle", qStep)
		--print("Client-------zNPCList= ", zNPCList)
		if zNPCList and zNPCList[1] then
			--print("Client-------zNPCList[1]= ", zNPCList[1])
			UpdateNPCToNextQStep(zNPCList[1], qStep_Next) --cập nhật NPC thành NPC qStep tiếp theo
		end
		playerGMD_Quest_Q1.q1s035_2.active = nil
		DoQuestStepActive(player, {npcTalk = false, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = true, qID = 2}) --cập nhật qStep --kiểm tra bắt buộc isNPC_Next
	end
end

--q1s036 --Trở lại phòng thí nghiệm của Dr. Venter
VLQS.Q1Steps["q1s036"] = function(player)
	local qStep, qStep_Next = "q1s036", "q1s037"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
end

--q1s037 --Chờ đợi Dr. Venter nghiên cứu mẫu vật --2 ngày
VLQS.Q1Steps["q1s037"] = function(player)
	local qStep, qStep_Next = "q1s037", "q1s038"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	--if not playerGMD_Quest_Q1[qStep].startHourWait then playerGMD_Quest_Q1[qStep].startHourWait = getGameTime():getWorldAgeHours() end
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent37"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent37"] = true
	end
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		--Nếu không ở phòng thí nghiệm +-80 ô thì mới update quest. --Để xóa NPC
		if not IsPlayerInArea(player, 10630 - 80, 10394 - 80, 10651 + 80, 10415 + 80, nil) then
			DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 2}) --cập nhật qStep --kiểm tra bắt buộc isNPC_Next
			SetNPCStateInQueueSpawnList({qStep = "q1s014_2", active = nil}) --Deactive Dr. Bassler
		end
	end
end

--q1s038 --Trở lại phòng thí nghiệm của Dr. Venter
VLQS.Q1Steps["q1s038"] = function(player)
	local qStep, qStep_Next = "q1s038", "q1s039"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	if IsPlayerInArea(player, 10630, 10394, 10651, 10415, -1) then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 2}) --cập nhật qStep --kiểm tra bắt buộc isNPC_Next
	end
end

--q1s039 --Lời nhắn của Dr. Venter
VLQS.Q1Steps["q1s039"] = function(player)
	local qStep, qStep_Next = "q1s039", "q1s040"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 10637, y = 10407, texture = questMarker})
	
	--Add thư nhắn + Fitness Serum của Tiến Sĩ
	local itemFullType = "Base.GenericMail"
	if IsPlayerInArea(player, 10630, 10394, 10651, 10415, -1) then
		if not localVar["addItem38"] then
			local x, y, z = 10644, 10402, -1
			local square = GetOrCreateSquare(x, y, z)
			if square then
				--Thư nhắn
				local item = DoSpawnItemQuestOnSquare({qStep = qStep, x = x, y = y, z = z, itemFullType = itemFullType, range = 0, isNote = true, noteStep = 1, qID = 2, iModData = "isKeyQuest1", totalPage = 2})
				--Fitness Serum
				local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
				if not playerGMD_Quest_Q1[qStep].rewardsAdded then --chỉ add 1 lần duy nhất
					local item2 = AddItemToSquares(square, "Base.VLUpgradeFitnessSerum1", {qStep = qStep, range = 0})

					if item2 then 
						--playerGMD_Quest_Q1[qStep].rewardsAdded = true 
						SetPlayerGMD_Q1(player, qStep, "rewardsAdded", true)
					end
				end
				if item then localVar["addItem38"] = true end						
			end
		end
	else if localVar["addItem38"] ~= false then localVar["addItem38"] = false end
	end
	--Lấy được thư nhắn của tiến sĩ
	local itemQuest = GetItemQuestInINVPlayer(player, itemFullType, qStep, "isKeyQuest1")
	if itemQuest then
		DoQuestStepActive(player, {introWindow = false, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 2})
		--Không update máy phát điện và không update tình trạng ở phòng thí nghiệm nữa
		--local pDataQ = GetPlayerModDataQuest(nil)
		--pDataQ.events.generatorAtLab = "stop"
		
		local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
		playerGMD_Quest_Q1[qStep]["deactiveLabRoom"] = true
		sendClientCommand(player, "MainQuest1", "UpdatePlayerGMD", {qStep = qStep, key = "deactiveLabRoom", val = true})
	end
end




--q1s040 --Tìm Dr. Venter tại địa điểm được đánh dấu
VLQS.Q1Steps["q1s040"] = function(player)
	local qStep, qStep_Next = "q1s040", "q1s041"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})	
	--12529, 11270, 0 --bunker
	local questMD = GetQuestGlobalModData(qStep)
	local x, y, z = 12529, 11270, 0 --tọa độ x, y, z khởi tạo bunker room
	if IsPlayerInArea(player, x - 60, y - 60, x + 60, y + 60, nil) then
		--local addedBunker = false
		
		local modDataKey, val = "AddedBuilding", true
		
		if not questMD.Object[qStep] then questMD.Object[qStep] = {} end
		if not questMD.Object[qStep][modDataKey] then
			--kiểm tra đã load 2 đầu bunker --đảm bảo add bunker đầy đủ
			local cell = getCell()
			local sq1 = cell:getGridSquare(x - 8, y - 8, 0)
			local sq2 = cell:getGridSquare(x + 10, y + 10, 0)
			if sq1 and sq2 then
			--Add Bunker + Basement B1
				--Xóa zombie xung quanh khu vực bunker
				--sendClientCommand(player, "NPCQuestCM", "RemoveZombiesInAreaExceptNPC", {x1 = x - 18, y1 = y - 18, x2 = x + 23, y2 = y + 25, z = 0})

				questMD.Object[qStep][modDataKey] = val
				sendClientCommand(player, "NPCQuestCM", "UpdateQuestModData", {qStep = qStep, modDataKey = modDataKey, val = val})
				
				--Add BunkerLabRoom
				AddBunkerLabRoom({isTransmit = true, x = x, y = y, x2 = x + 5, y2 = y + 7, z = 0})
				
				--Add NPCs vào danh sách chờ spawn
				SetNPCStateInQueueSpawnList({qStep = "q1s041_1", active = true}) --Dr. Venter
				SetNPCStateInQueueSpawnList({qStep = "q1s041_2", active = true}) --NPC em trai
				SetNPCStateInQueueSpawnList({qStep = "q1s041_3", active = true}) --Dr. Bassler
				SetNPCStateInQueueSpawnList({qStep = "q1s041_4", active = true}) --Thêm NPC Bảo vệ 1
				SetNPCStateInQueueSpawnList({qStep = "q1s041_5", active = true}) --Thêm NPC Bảo vệ 2
				SetNPCStateInQueueSpawnList({qStep = "q1s041_6", active = true}) --Thêm NPC Bảo vệ 3
				
				--Add NPCs spawn trực tiếp --Không cần chờ loadgridsquare
				SpawnNPCOnClient("q1s041_1", 0)
				SpawnNPCOnClient("q1s041_2", 0)
				SpawnNPCOnClient("q1s041_3", 0)
				SpawnNPCOnClient("q1s041_4", 0)
				SpawnNPCOnClient("q1s041_5", 0)
				SpawnNPCOnClient("q1s041_6", 0)
				
				--addedBunker = true
				SetPlayerGMD_Q1(player, qStep, "addedBunker", true)
				
				--[[
				local npcData = VLF.npcData
				local _qStep = "q1s041_1"
				if npcData[_qStep] then
					sendClientCommand(getPlayer(), "NPCQuestCM", "RequestSpawnNPC", {qStep = _qStep, x = npcData[_qStep].startX, y = npcData[_qStep].startY, z = npcData[_qStep].startZ, removeZRange = 0, femaleChance = npcData[_qStep].femaleChance})
				end				
				local _qStep = "q1s041_2"
				if npcData[_qStep] then
					sendClientCommand(getPlayer(), "NPCQuestCM", "RequestSpawnNPC", {qStep = _qStep, x = npcData[_qStep].startX, y = npcData[_qStep].startY, z = npcData[_qStep].startZ, removeZRange = 0, femaleChance = npcData[_qStep].femaleChance})
				end
				local _qStep = "q1s041_3"
				if npcData[_qStep] then
					sendClientCommand(getPlayer(), "NPCQuestCM", "RequestSpawnNPC", {qStep = _qStep, x = npcData[_qStep].startX, y = npcData[_qStep].startY, z = npcData[_qStep].startZ, removeZRange = 0, femaleChance = npcData[_qStep].femaleChance})
				end
				local _qStep = "q1s041_4"
				if npcData[_qStep] then
					sendClientCommand(getPlayer(), "NPCQuestCM", "RequestSpawnNPC", {qStep = _qStep, x = npcData[_qStep].startX, y = npcData[_qStep].startY, z = npcData[_qStep].startZ, removeZRange = 0, femaleChance = npcData[_qStep].femaleChance})
				end
				local _qStep = "q1s041_5"
				if npcData[_qStep] then
					sendClientCommand(getPlayer(), "NPCQuestCM", "RequestSpawnNPC", {qStep = _qStep, x = npcData[_qStep].startX, y = npcData[_qStep].startY, z = npcData[_qStep].startZ, removeZRange = 0, femaleChance = npcData[_qStep].femaleChance})
				end
				local _qStep = "q1s041_6"
				if npcData[_qStep] then
					sendClientCommand(getPlayer(), "NPCQuestCM", "RequestSpawnNPC", {qStep = _qStep, x = npcData[_qStep].startX, y = npcData[_qStep].startY, z = npcData[_qStep].startZ, removeZRange = 0, femaleChance = npcData[_qStep].femaleChance})
				end
				]]
			end
		end
		 
		--khi vào gần khu vực bunker
		local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
		if playerGMD_Quest_Q1[qStep].addedBunker == true then
			if IsPlayerInArea(player, x - 8, y - 8, x + 13, y + 15, nil) then
				DoQuestStepActive(player, {introWindow = true, isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 2})
			end
		end
	end
end

--q1s041 --Tìm Dr. Venter tại hầm trú ẩn --tìm được Em Trai
VLQS.Q1Steps["q1s041"] = function(player)
	local qStep, qStep_Next = "q1s041", "q1s042"
	DoQuestList_AddItem({id = 2, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s042 --Nói chuyện với em trai của bạn
VLQS.Q1Steps["q1s042"] = function(player)
	local qStep, qStep_Next = "q1s042", "q1s043"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s043 --Nói chuyện với Dr. Venter về tình huống hiện tại
VLQS.Q1Steps["q1s043"] = function(player)
	local qStep, qStep_Next = "q1s043", "q1s044"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s044 --Quyết định của em trai
VLQS.Q1Steps["q1s044"] = function(player)
	local qStep, qStep_Next = "q1s044", "q1s045"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end
 
--q1s045 --Nói cho Dr. Venter về quyết định của em trai
VLQS.Q1Steps["q1s045"] = function(player)
	local qStep, qStep_Next = "q1s045", "q1s046"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s046 --Chờ Dr. Venter chuẩn bị cho thử nghiệm - chờ 1 ngày
VLQS.Q1Steps["q1s046"] = function(player)
	local qStep, qStep_Next = "q1s046", "q1s047"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	
	if not localVar["addEvent46"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent46"] = true
	end
	
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		--Xóa NPC em trai trong phòng
		local zNPCList = GetNPCsByVarAndQStep("npcQuestIdle", "q1s041_3")
		if zNPCList and zNPCList[1] then
			RemoveNPCQuest(zNPCList[1])
		end
		SetNPCStateInQueueSpawnList({qStep = "q1s041_3", active = nil})
		
		--Add NPC em trai nằm tại giường bệnh
		SetNPCStateInQueueSpawnList({qStep = "q1s046_3", active = true})
		SpawnNPCOnClient("q1s046_3", 0)
		
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 1})
	end
end

--q1s047 --Nói chuyện với Dr. Venter tại phòng thí nghiệm
VLQS.Q1Steps["q1s047"] = function(player)
	local qStep, qStep_Next = "q1s047", "q1s048"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s048 --Tiến hành thử nghiệm Super Human Serum
VLQS.Q1Steps["q1s048"] = function(player)
	local qStep, qStep_Next = "q1s048", "q1s049"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s049 --Chờ đợi thử nghiệm của Dr. Venter - chờ 2 tiếng
VLQS.Q1Steps["q1s049"] = function(player)
	local qStep, qStep_Next = "q1s049", "q1s050"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
	
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent49"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent49"] = true
	end
	
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		if IsPlayerInArea(player, 12520, 11262, 12534, 11277, -1) then 	--khu vực BunkerLab
			--local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
			if IsPlayerCanSeeNPC(player, nil, "npcQuestSleepOnBed", "q1s046_3") then
				ActiveQuestIntro_Centre(getText("IGUI_VLQ_1_Desc_q1s050"), 800, 500, false, "")
				DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 1})
			end
		end	
	end
end

--q1s050 --Hỏi Dr. Venter về phản ứng của cơ thể em trai
VLQS.Q1Steps["q1s050"] = function(player)
	local qStep, qStep_Next = "q1s050", "q1s051"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s051 --Chờ đợi thử nghiệm của Dr.Venter - chờ 1,5 ngày
VLQS.Q1Steps["q1s051"] = function(player)
	local qStep, qStep_Next = "q1s051", "q1s052"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
	
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent51"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent51"] = true
	end
	
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 1})
	end
end

--q1s052 --Nói chuyện với Dr.Venter tại phòng thí nghiệm
VLQS.Q1Steps["q1s052"] = function(player)
	local qStep, qStep_Next = "q1s052", "q1s053"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s053 --Tìm nguyên liệu điều chế thuốc giảm đau đặc biệt --3000
--Base.BlackSage + Base.Pills | BlackSage giảm 7 pain - Painkillers giảm 100 (100%) trong 50 phút | 1 BlackSage = 7 | 1 pill = 14 (vỉ 10 = 140)
--3 ngày sau nếu chưa hoàn thành quest này thì skip tới q1s055, đánh dấu modData để ảnh hưởng sau này
VLQS.Q1Steps["q1s053"] = function(player)
	local qStep, qStep_Next = "q1s053", "q1s054"
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
 
	local collectedStart, request = SetDataForCollectQuest(player, qStep, "RPain", 0, VLF.var.requestCol[qStep])
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = true, currentCollection = collectedStart, requestCollection = request, collectQItemName = getText("IGUI_VLQ_1_CollectQItemName_q1s053")})
	
	--Thời gian tìm nguyên liệu 3 ngày. Hết 3 ngày thì skip tới q1s055, và đánh dấu modData
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent53"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent53"] = true
	end
	
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		--đánh dấu không hoàn thành quest tìm giảm đau
		SetPlayerGMD_Q1(player, qStep, "isNotEnoughReducePain", true)
		ActiveQuestIntro_Free(getText("IGUI_VLQ_1_Notification2_q1s053"), (getCore():getScreenWidth() - 800) / 2, (getCore():getScreenHeight() - 200) / 16, 800, 250, false, "")
		--Skip qStep
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = "done", isNPC_Next = false, qID = 1})
		DoQuestStepActive(player, {isPopIn = false, qStep = qStep, active = "done", qStep_Next = "q1s055", active_Next = true, isNPC_Next = false, qID = 1})
	end

end

--q1s054 --Chờ đợi thử nghiệm của Dr.Venter - chờ 1 ngày
VLQS.Q1Steps["q1s054"] = function(player)
	local qStep, qStep_Next = "q1s054", "q1s055"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})

	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent54"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent54"] = true
	end
	
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 1})
	end
	
end

--q1s055 --Nói chuyện với Dr.Venter tại phòng thí nghiệm
VLQS.Q1Steps["q1s055"] = function(player)
	local qStep, qStep_Next = "q1s055", "q1s056"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s056 --Chờ đợi thử nghiệm của Dr.Venter - chờ 1 ngày
VLQS.Q1Steps["q1s056"] = function(player)
	local qStep, qStep_Next = "q1s056", "q1s057"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
	
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent56"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent56"] = true
	end
	
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 1})
	end
end

--q1s057 --Kết quả thử nghiệm
VLQS.Q1Steps["q1s057"] = function(player)
	local qStep, qStep_Next = "q1s057", "q1s058"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--q1s058 --Chờ đợi Dr. Venter tìm ra nguyên nhân - 3 ngày
VLQS.Q1Steps["q1s058"] = function(player)
	local qStep, qStep_Next = "q1s058", "q1s059"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
	
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if not localVar["addEvent58"] then
		if not playerGMD_Quest_Q1[qStep].waitHourPassed then
			Events.EveryHours.Remove(WaitTimePassQ1)
			Events.EveryHours.Add(WaitTimePassQ1)
		end
		localVar["addEvent58"] = true
	end
	
	if playerGMD_Quest_Q1[qStep].waitHourPassed == true then
		DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = qStep_Next, active_Next = true, isNPC_Next = false, qID = 1})
	end
end

--q1s059 --Nói chuyện với Dr.Venter tại phòng thí nghiệm
VLQS.Q1Steps["q1s059"] = function(player)
	local qStep, qStep_Next = "q1s059", "q1s060"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
end

--Cập nhật dữ liệu cho NPC Health Info --các chỉ số không vượt quá 100.
local function UpdateNPCHealthInfo(player, qStep)
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	if playerGMD_Quest_Q1[qStep].npcLastUpdateTime then
		local now = getGameTime():getMinutesStamp()
		local minutesPassed = now - playerGMD_Quest_Q1[qStep].npcLastUpdateTime
		if minutesPassed > 0 then
			--hunger --hunger 100 = max --3 ngày = 100 --4320/100 = 43.2 phút tăng 1 hunger		--400 = chết
			local hunger = playerGMD_Quest_Q1[qStep].npcHunger + (minutesPassed / 43.2)
			if hunger > 401 then hunger = 401 end
			if hunger ~= playerGMD_Quest_Q1[qStep].npcHunger then
				SetPlayerGMD_Q1(player, qStep, "npcHunger", hunger)
			end
			
			--thirst --thirst 100 = max --1,5 ngày = 100 --2160/100 = 21.6 phút tăng 1 thirst		--200 = chết
			local thirst = playerGMD_Quest_Q1[qStep].npcThirst + (minutesPassed / 21.6)
			if thirst > 201 then thirst = 201 end
			if thirst ~= playerGMD_Quest_Q1[qStep].npcThirst then
				SetPlayerGMD_Q1(player, qStep, "npcThirst", thirst)
			end
			
			--[[
			--dirty --dirty 100 = max --5 ngày = 100 --7200/100 = 72 phút tăng 1 dirty
			local dirty = playerGMD_Quest_Q1[qStep].npcDirty + (minutesPassed / 72)
			if dirty > 101 then dirty = 101 end
			if dirty ~= playerGMD_Quest_Q1[qStep].npcDirty then
				SetPlayerGMD_Q1(player, qStep, "npcDirty", dirty)
			end
			]]
			
			--poisoned --poisoned 100 = max --ăn 1 món có độc tăng 1 level độc --432 phút tăng 1 độc/ 1 level
			--lvl 1: 30 ngày = 100. 	--lvl 5: 6 ngày = 100
			local poisonedLevel = playerGMD_Quest_Q1[qStep].npcPoisonedLvl
			if poisonedLevel > 0 then
				local poisoned = playerGMD_Quest_Q1[qStep].npcPoisoned + ((poisonedLevel * minutesPassed) / 432)
				if poisoned > 101 then poisoned = 101 end
				if poisoned ~= playerGMD_Quest_Q1[qStep].npcPoisoned then
					SetPlayerGMD_Q1(player, qStep, "npcPoisoned", poisoned)
				end
				
			end
			
			--cập nhật thời gian update
			SetPlayerGMD_Q1(player, qStep, "npcLastUpdateTime", now)
			
			--Đúng thời gian, Dr. Bassler sẽ cho em trai ăn mỗi ngày 1 lần. set cố định hunger = 10, thirst = 10. Tỉ lệ bình thường 95% sẽ cho ăn
			--Nếu đã nhờ Dr. Bassler thì sẽ không quên cho ăn 	--tỉ lệ 100%
			if getGameTime():getHour() == 12 and (getGameTime():getMinutes() >= 0 and getGameTime():getMinutes() < 10) then
				local rate = ZombRand(100)
				local rateCare = 95 	--tỉ lệ Dr. Bassler chăm sóc em trai hàng ngày
				
				if playerGMD_Quest_Q1[qStep].careBrotherRequest == true then
					rateCare = 100
				end
				
				if rate < rateCare then
					SetPlayerGMD_Q1(player, qStep, "npcHunger", 10)
					SetPlayerGMD_Q1(player, qStep, "npcThirst", 10)
				end
			end
			
			--Kiểm tra đã hết thời gian nhờ Dr. Bassler chăm sóc em trai thì reset	--3 ngày --72 tiếng
			if playerGMD_Quest_Q1[qStep].careBrotherRequest == true then
				local nowHour = getGameTime():getWorldAgeHours()
				if (nowHour - playerGMD_Quest_Q1[qStep].careBrotherRequestStartHour) >= 72 then
					SetPlayerGMD_Q1(player, qStep, "careBrotherRequest", nil)
					SetPlayerGMD_Q1(player, qStep, "careBrotherRequestStartHour", nil)
				end
			end
			
		end
	end
end

local function EveryTenMinutes_UpdateNPCHealthInfo()
    UpdateNPCHealthInfo(getPlayer(), "q1s060")
end
--Events.EveryTenMinutes.Remove(EveryTenMinutes_UpdateNPCHealthInfo)
--Events.EveryTenMinutes.Add(EveryTenMinutes_UpdateNPCHealthInfo)

--Sử dụng trong function ActivateVisibleButtons  --file: vl_quest_talktonpc_interaction_ui.lua
--Chọn các button để hiển thị phụ thuộc vào các ModData của quest
VLINTER.SetButtons["q1s060"] = function(player, qStep, buttonList)
    local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
    if playerGMD_Quest_Q1[qStep].npcPoisoned >= 20 or playerGMD_Quest_Q1[qStep].getRemovePoisonQuest == true then
        if playerGMD_Quest_Q1[qStep].getRemovePoisonQuest == true then
            buttonList["interactionButton1"] = true
        else
			buttonList["interactionButton3"] = true 
        end
    end
    if not playerGMD_Quest_Q1[qStep].careBrotherRequest then
        buttonList["interactionButton2"] = true
    end
end

local function GetAllItemsByType(player, itemType)
	local itemList = {}
    -- Inventory chính
    local inv = player:getInventory()
	if inv then
		GetItemsInContainer(inv, itemList, itemType)
	end
    return itemList
end

local function GiveItemsQuestQ1s060(player, qStep, zNPC)
    local flag = 0
    local antibioticsList = GetAllItemsByType(player, "Base.Antibiotics")
    local wildGarlicList = GetAllItemsByType(player, "Base.WildGarlic2")
    local lemonGrassList = GetAllItemsByType(player, "Base.LemonGrass")

    if #antibioticsList >= 10 then
        flag = flag + 1
    end
    if #wildGarlicList >= 30 then
        flag = flag + 1
    end
    if #lemonGrassList >= 30 then
        flag = flag + 1
    end
    
    --Nếu đủ items quest
    if flag == 3 then
        UIManager.FadeIn(2)
        
        --Xóa nhiệm vụ
        SetPlayerGMD_Q1(player, qStep, "getRemovePoisonQuest", nil)
    
        --Xóa items quest
        local container = player:getInventory()
        RemoveItemFromContainer(container, nil, "Base.Antibiotics", 10)
        RemoveItemFromContainer(container, nil, "Base.WildGarlic2", 30)
        RemoveItemFromContainer(container, nil, "Base.LemonGrass", 30)
        
        --Xóa nhiễm độc
        local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
        SetPlayerGMD_Q1(player, qStep, "npcPoisoned", 0.0)
        SetPlayerGMD_Q1(player, qStep, "npcPoisonedLvl", 0)
        
        --Hiện khung chat tiếp --đặt dưới cùng để không bị hiển thị các nút khác khi data chưa cập nhật
        VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_1_NPCTalk_q1s060_2_2"), 800, 500, zNPC)

    else
        HaloTextHelper.addBadText(player, getText("IGUI_VLQ_Notification_NotEnoughItemsQuest"))
    end
end

VLINTER.InteractionButton1["q1s060"] = function(player, qStep, zNPC)
    --Kiểm tra túi đồ player có đủ item quest thì hoàn thành
    GiveItemsQuestQ1s060(player, qStep, zNPC)
end

VLINTER.InteractionButton2["q1s060"] = function(player, qStep, zNPC)
    --Nhờ Dr. Bassler để ý chăm sóc em trai trong 3 ngày
    SetPlayerGMD_Q1(player, qStep, "careBrotherRequest", true)
    SetPlayerGMD_Q1(player, qStep, "careBrotherRequestStartHour", getGameTime():getWorldAgeHours())
    --hiện bảng talk NPC
    VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_1_NPCTalk_q1s060_2_3"), 800, 500, zNPC)
end

VLINTER.InteractionButton3["q1s060"] = function(player, qStep, zNPC)
    --Hỏi về tình trạng nhiễm độc của em trai và nhận quest tìm nguyên liệu để chế thuốc giải
    SetPlayerGMD_Q1(player, qStep, "getRemovePoisonQuest", true) --Xong nhiệm vụ thì xóa data này
    --hiện bảng talk NPC
    VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_1_NPCTalk_q1s060_2_1"), 800, 500, zNPC)
end

--q1s060 --Chăm sóc em trai
VLQS.Q1Steps["q1s060"] = function(player)
	local qStep, qStep_Next = "q1s060", "q1s061"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = false, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
	MarkerList_Add({qStep = qStep, x = 12531, y = 11273, texture = questMarker})
	
	local playerGMD_Quest_Q1 = GetPlayerGlobalModDataQ1(player, qStep)
	--Khởi tạo dữ liệu Health Info cho em trai
	if not localVar["addEvent60"] then
		if not playerGMD_Quest_Q1[qStep].npcLastUpdateTime then
			--SetPlayerGMD_Q1(player, qStep, "needTakeCare", true)
			SetPlayerGMD_Q1(player, qStep, "npcLastUpdateTime", getGameTime():getMinutesStamp())
			SetPlayerGMD_Q1(player, qStep, "npcHunger", 20.0)
			SetPlayerGMD_Q1(player, qStep, "npcThirst", 20.0)
			--SetPlayerGMD_Q1(player, qStep, "npcDirty", 5.0)
			SetPlayerGMD_Q1(player, qStep, "npcPoisoned", 0.0)	--tăng theo thời gian nếu đang bị nhiễm độc. max = 100 = die
			SetPlayerGMD_Q1(player, qStep, "npcPoisonedLvl", 0) --khi cho NPC ăn, nếu đồ ăn có độc thì tăng 1 level nhiễm độc. max = 5
		end
		
		--Chạy event để cập nhật NPC Health Info
		Events.EveryTenMinutes.Remove(EveryTenMinutes_UpdateNPCHealthInfo)
		Events.EveryTenMinutes.Add(EveryTenMinutes_UpdateNPCHealthInfo)
		
		localVar["addEvent60"] = true
	end
	
	-- Kết thúc 1 --Em trai chết vì nhiễm độc, đói, khát
	if playerGMD_Quest_Q1[qStep].npcPoisoned >= 100 or playerGMD_Quest_Q1[qStep].npcHunger >= 400 or playerGMD_Quest_Q1[qStep].npcThirst >= 200 then
		if IsPlayerCanSeeNPC(player, nil, "npcQuestSleepOnBed", qStep) then
			--Hủy Event
			Events.EveryTenMinutes.Remove(EveryTenMinutes_UpdateNPCHealthInfo)
			
			--Kill NPC em trai
			local questMD = GetQuestGlobalModData(qStep)
			local zID = questMD.NPC[qStep]["zID"]
			if zID then
				KillNPCQuest(qStep, zID)
			end
			--Active qStep kết thúc 1 --q1s990
			DoQuestStepActive(player, {isPopIn = true, qStep = qStep, active = "done", qStep_Next = "q1s990", active_Next = true, isNPC_Next = false, qID = 1})
			
			print("Client---NPC Dead---qStep - npcHunger - npcThirst - npcPoisoned - npcPoisonedLvl", qStep, playerGMD_Quest_Q1[qStep].npcHunger, playerGMD_Quest_Q1[qStep].npcThirst, playerGMD_Quest_Q1[qStep].npcPoisoned, playerGMD_Quest_Q1[qStep].npcPoisonedLvl)			
		end
	end
end


--============= NHỮNG KẾT THÚC CỦA QUEST =============--

--q1s990 --Kết thúc 1 --Em trai chết
VLQS.Q1Steps["q1s990"] = function(player)
	local qStep = "q1s990"
	DoQuestList_AddItem({id = 1, qStep = qStep, isDone = true, qtype = qtype, isCollection = false, currentCollection = nil, requestCollection = nil})
end
	
	
	
	
	
	
	
	
	
	