--================ Các Function Khi Nói Chuyện Với NPC Q3 =================--

require "questui/vl_quest_introwindow_ui"
require "questui/vl_quest_popup_ui"

VLF.TalkToNPC = VLF.TalkToNPC or {}

local ActiveQuestIntro_Centre = VLF.ActiveQuestIntro_Centre
local QuestUpdatedPopIn = VLF.QuestUpdatedPopIn
local GetItemsInContainer = VLIT.GetItemsInContainer
local RemoveItemFromContainer = VLIT.RemoveItemFromContainer
local GetPlayerGlobalModDataQ3 = VLGMD.GetPlayerGlobalModDataQ3
local GetAmountReduceHungerInContainer = VLIT.GetAmountReduceHungerInContainer
local RemoveFoodInContainer = VLIT.RemoveFoodInContainer
local SetPlayerGMD_Q3 = VLGMD.SetPlayerGMD_Q3
local UpdateQuestStepAndNext = VLF.UpdateQuestStepAndNext
local GetAmountRHungerInContByType = VLIT.GetAmountRHungerInContByType
local RemoveFoodInContByType = VLIT.RemoveFoodInContByType
local GetItemInContainerRecursive = VLIT.GetItemInContainerRecursive
local ResetData_EndQ3 = VLF.ResetData_EndQ3
local IsQuest3Completing = VLF.IsQuest3Completing
local UpdateNPC = VLZB.UpdateNPC
local AddReputationPoint = VLGMD.AddReputationPoint

local screenHeight = getCore():getScreenHeight()
local talkUIW, talkUIH = 800, 600
if screenHeight >= 700 then
	talkUIH = 700
end

--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
--qStep phải giống với qStep của NPC đang tương tác chứ không phải qStep đang active
VLINTER.SetButtons["q3s001"] = function(player, qStep, buttonList)
	buttonList["interactionButton1"] = true
end

--Sử dụng trong function VL_Quest_TalkToNPC_Interaction_UI:onInteractionBtn1()  --file: vl_quest_talktonpc_interaction_ui.lua
VLINTER.InteractionButton1["q3s001"] = function(player, qStep, zNPC)
    --Kiểm tra túi đồ player có đủ 200 hunger của đồ ăn không
    local container = player:getInventory()
    local rHungerInInv = GetAmountReduceHungerInContainer(container, true, true, false)
    if rHungerInInv >= 200 then
        --Xóa đồ ăn. Xóa >= 200 hunger thì ngừng
        RemoveFoodInContainer(container, 200)
        
        --Set ModData để update qStep
        SetPlayerGMD_Q3(player, qStep, "given200Hunger", true)
		
		--Hiển thị bảng talk cảm ơn
		ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_Desc_q3s003"), 800, 500, false, "")
    else
        HaloTextHelper.addBadText(player, getText("IGUI_VLQ_Notification_NotEnoughItemsQuest"))
    end
end

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

local function GiveItemsQuest_q3s004(player, qStep, zNPC)
    local flag = 0
	local container = player:getInventory()
    local antibioticsList = GetAllItemsByType(player, "Base.Antibiotics")
    local coldpackList = GetAllItemsByType(player, "Base.Coldpack")
    local paracetamolList = GetAllItemsByType(player, "Base.VLParacetamol")

    if #antibioticsList >= 6 then
        flag = flag + 1
    end
    if #coldpackList >= 1 then
        flag = flag + 1
    end
    if #paracetamolList >= 1 then
        flag = flag + 1
    end
    
    --Nếu đủ items quest
    if flag == 3 then        
        --Xóa items quest
        RemoveItemFromContainer(container, nil, "Base.Antibiotics", 6)
        RemoveItemFromContainer(container, nil, "Base.Coldpack", 1)
        RemoveItemFromContainer(container, nil, "Base.VLParacetamol", 1)
        
		return true
    else
        HaloTextHelper.addBadText(player, getText("IGUI_VLQ_Notification_NotEnoughItemsQuest"))
    end
	return false
end

local function GiveItemsQuest_q3s005(player, qStep, zNPC)
	local flag = 0
	local container = player:getInventory()
    local rHungerRice = GetAmountRHungerInContByType(container, "Base.Rice", false, true, false)
    local rHungerSugar = GetAmountRHungerInContByType(container, "Base.Sugar", true, true, true)
	rHungerSugar = rHungerSugar + GetAmountRHungerInContByType(container, "Base.SugarBrown", true, true, true)
    rHungerSugar = rHungerSugar + GetAmountRHungerInContByType(container, "Base.SugarCubes", true, true, true)
    rHungerSugar = rHungerSugar + GetAmountRHungerInContByType(container, "Base.SugarPacket", true, true, true)
    local rHungerSalt = GetAmountRHungerInContByType(container, "Base.Salt", true, true, true)
	local requestRice = 120
	local requestSugar = 30
	local requestSalt = 15
	
	if rHungerRice >= requestRice then
		flag = flag + 1
	end
	if rHungerSugar >= requestSugar then
		flag = flag + 1
	end
	if rHungerSalt >= requestSalt then
		flag = flag + 1
	end
	
	--Nếu đủ items quest
	if flag == 3 then
		--Xóa rice
		RemoveFoodInContByType(container, "Base.Rice", requestRice, true, true, true)
		
		--Xóa sugar
		local remain = requestSugar
		local removedSugar = 0

		if remain > 0 then
			local r = RemoveFoodInContByType(container, "Base.SugarPacket", remain, true, true, true)
			removedSugar = removedSugar + r
			remain = requestSugar - removedSugar
		end
		
		if remain > 0 then
			local r = RemoveFoodInContByType(container, "Base.SugarCubes", remain, true, true, true)
			removedSugar = removedSugar + r
			remain = requestSugar - removedSugar
		end

		if remain > 0 then
			local r = RemoveFoodInContByType(container, "Base.Sugar", remain, true, true, true)
			removedSugar = removedSugar + r
			remain = requestSugar - removedSugar
		end

		if remain > 0 then
			local r = RemoveFoodInContByType(container, "Base.SugarBrown", remain, true, true, true)
			removedSugar = removedSugar + r
		end
		
		--Xóa salt
		RemoveFoodInContByType(container, "Base.Salt", requestSalt, true, true, true)
		
		return true
	end
	
	HaloTextHelper.addBadText(player, getText("IGUI_VLQ_Notification_NotEnoughItemsQuest"))
end


--Bob
VLF.TalkToNPC["q3s001"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)

		if playerGMD_Quest_Q3["q3s002"] and playerGMD_Quest_Q3["q3s002"].active == true then
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s002"), talkUIW, talkUIH, zNPC)

		elseif playerGMD_Quest_Q3["q3s003"] and playerGMD_Quest_Q3["q3s003"].active == true then
			UpdateQuestStepAndNext(player, 3, true, false, true, "q3s003", "done", "q3s004", true)
			
		elseif playerGMD_Quest_Q3["q3s004"] and playerGMD_Quest_Q3["q3s004"].active == true then
			--6 Base.Antibiotics, 1 Base.Coldpack, 1 Base.VLParacetamol (painkiller icon, đổi màu)
			if GiveItemsQuest_q3s004(player, qStep, zNPC) == true then
				UpdateQuestStepAndNext(player, 3, true, false, true, "q3s004", "done", "q3s005", true)
			end
		elseif playerGMD_Quest_Q3["q3s005"] and playerGMD_Quest_Q3["q3s005"].active == true then
			--300 hunger: Base.Rice, Base.CannedMushroomSoup, Base.TinnedSoup
			--Đường (-30 hunger): Base.Sugar, Base.SugarBrown, Base.SugarCubes, Base.SugarPacket
			--Muối (-15 hunger): Base.Salt
			if GiveItemsQuest_q3s005(player, qStep, zNPC) == true then
				--tăng thêm 7 ngày thời gian sống cho Kate
				local newEndHour = playerGMD_Quest_Q3["q3s001"]["countHour_KateZombified"] + 168 	--FIXME: 168
				SetPlayerGMD_Q3(player, "q3s001", "countHour_KateZombified", newEndHour)
				
				UpdateNPC("npcQuestIdle", "q3s001", "q3s006")
			
				UpdateQuestStepAndNext(player, 3, true, false, true, "q3s005", "done", "q3s006", true)
				
				AddReputationPoint(player, 15)
			end
		end	
	end
end

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

--Sử dụng trong function ActivateVisibleButtons  --file: vl_quest_talktonpc_interaction_ui.lua
VLINTER.SetButtons["q3s006"] = function(player, qStep, buttonList)
	local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	if not playerGMD_Quest_Q3[qStep]["given500RHungerForBob"] then
		buttonList["interactionButton1"] = true
	end
end

--Sử dụng trong function VL_Quest_TalkToNPC_Interaction_UI:onInteractionBtn1()  --file: vl_quest_talktonpc_interaction_ui.lua
VLINTER.InteractionButton1["q3s006"] = function(player, qStep, zNPC)
    --Kiểm tra túi đồ player có đủ 500 hunger của đồ ăn không
    local container = player:getInventory()
    local rHungerInInv = GetAmountReduceHungerInContainer(container, true, true, false)
	local requestRHunger = 500
    if rHungerInInv >= requestRHunger then
        --Xóa đồ ăn. Xóa >= 500 hunger thì ngừng
        RemoveFoodInContainer(container, requestRHunger)
        QuestUpdatedPopIn()
		
        --Set ModData
        SetPlayerGMD_Q3(player, qStep, "given500RHungerForBob", true)
		
		--Hiển thị bảng talk cảm ơn của Bob
		ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s006_2"), 800, 500, false, "")
    else
        HaloTextHelper.addBadText(player, getText("IGUI_VLQ_Notification_NotEnoughItemsQuest"))
    end
end

--Bob
VLF.TalkToNPC["q3s006"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
		
		if playerGMD_Quest_Q3["q3s006"] and playerGMD_Quest_Q3["q3s006"].active == true then
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s006"), talkUIW, talkUIH, zNPC)
		
		elseif playerGMD_Quest_Q3["q3s007"] and playerGMD_Quest_Q3["q3s007"].active == true then
			UpdateNPC("npcQuestIdle", "q3s006", "q3s008")
			
			UpdateQuestStepAndNext(player, 3, true, false, true, "q3s007", "done", "q3s008", true)

		else
			ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s000"), 800, 500, false, "")
		end
	end
end

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

VLINTER.SetButtons["q3s008"] = function(player, qStep, buttonList)
	local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	if not playerGMD_Quest_Q3[qStep]["givenMedicine"] then
		buttonList["interactionButton1"] = true
	end
	if not playerGMD_Quest_Q3[qStep]["givenFood"] then
		buttonList["interactionButton2"] = true
	end
end

VLINTER.InteractionButton1["q3s008"] = function(player, qStep, zNPC)
    --Đưa thuốc cho Bob
	local isDone = GiveItemsQuest_q3s004(player, qStep, zNPC)

    if isDone == true then
        --Set ModData
        SetPlayerGMD_Q3(player, qStep, "givenMedicine", true)
		QuestUpdatedPopIn()
		
		--Hiển thị bảng talk tiếp theo
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
		if playerGMD_Quest_Q3[qStep]["givenMedicine"] and playerGMD_Quest_Q3[qStep]["givenFood"] then
			--tăng thêm 7 ngày thời gian sống cho Kate
			local newEndHour = playerGMD_Quest_Q3["q3s001"]["countHour_KateZombified"] + 168 	--FIXME: 168
			SetPlayerGMD_Q3(player, "q3s001", "countHour_KateZombified", newEndHour)
				
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s008"), talkUIW, talkUIH, zNPC)
			UpdateQuestStepAndNext(player, 3, false, false, true, qStep, "done", "q3s009", true)

			UpdateNPC("npcQuestIdle", "q3s008", "q3s009")
			
			SetPlayerGMD_Q3(player, qStep, "givenMedicine", nil)
			SetPlayerGMD_Q3(player, qStep, "givenFood", nil)
			AddReputationPoint(player, 20)
		else
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s008_2"), talkUIW, talkUIH, zNPC)
		end
    end
end

VLINTER.InteractionButton2["q3s008"] = function(player, qStep, zNPC)
    --Đưa đồ ăn của Kate cho Bob
	local isDone = GiveItemsQuest_q3s005(player, qStep, zNPC)

    if isDone == true then
        --Set ModData
        SetPlayerGMD_Q3(player, qStep, "givenFood", true)
		QuestUpdatedPopIn()
		
		--Hiển thị bảng talk tiếp theo
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
		if playerGMD_Quest_Q3[qStep]["givenMedicine"] and playerGMD_Quest_Q3[qStep]["givenFood"] then
			--tăng thêm 7 ngày thời gian sống cho Kate
			local newEndHour = playerGMD_Quest_Q3["q3s001"]["countHour_KateZombified"] + 168 	--FIXME: 168
			SetPlayerGMD_Q3(player, "q3s001", "countHour_KateZombified", newEndHour)
				
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s008"), talkUIW, talkUIH, zNPC)
			UpdateQuestStepAndNext(player, 3, false, false, true, qStep, "done", "q3s009", true)

			UpdateNPC("npcQuestIdle", "q3s008", "q3s009")
			
			SetPlayerGMD_Q3(player, qStep, "givenMedicine", nil)
			SetPlayerGMD_Q3(player, qStep, "givenFood", nil)
			AddReputationPoint(player, 20)
		else
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s008_2"), talkUIW, talkUIH, zNPC)
		end
    end
end

--Bob
VLF.TalkToNPC["q3s008"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)

		if playerGMD_Quest_Q3["q3s008"] and playerGMD_Quest_Q3["q3s008"].active == true then
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s008_2"), talkUIW, talkUIH, zNPC)
		end
	end
end

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

--Bob
VLF.TalkToNPC["q3s009"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)

		if playerGMD_Quest_Q3["q3s009"] and playerGMD_Quest_Q3["q3s009"].active == true then
			ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s000"), 800, 500, false, "")

		elseif playerGMD_Quest_Q3["q3s010"] and playerGMD_Quest_Q3["q3s010"].active == true then
			UpdateNPC("npcQuestIdle", "q3s009", "q3s011")
			UpdateQuestStepAndNext(player, 3, true, false, true, "q3s010", "done", "q3s011", true)

		end
	end
end

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

VLINTER.SetButtons["q3s011"] = function(player, qStep, buttonList)
	local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	if not playerGMD_Quest_Q3[qStep]["givenMedicine"] then
		buttonList["interactionButton1"] = true
	end
	if not playerGMD_Quest_Q3[qStep]["givenFood"] then
		buttonList["interactionButton2"] = true
	end
end

VLINTER.InteractionButton1["q3s011"] = function(player, qStep, zNPC)
    --Đưa thuốc cho Bob
	local isDone = GiveItemsQuest_q3s004(player, qStep, zNPC)

    if isDone == true then
        --Set ModData
        SetPlayerGMD_Q3(player, qStep, "givenMedicine", true)
		QuestUpdatedPopIn()
		
		--Hiển thị bảng talk tiếp theo
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
		if playerGMD_Quest_Q3[qStep]["givenMedicine"] and playerGMD_Quest_Q3[qStep]["givenFood"] then
			--tăng thêm 7 ngày thời gian sống cho Kate
			local newEndHour = playerGMD_Quest_Q3["q3s001"]["countHour_KateZombified"] + 168 	--FIXME: 168
			SetPlayerGMD_Q3(player, "q3s001", "countHour_KateZombified", newEndHour)
				
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s011"), talkUIW, talkUIH, zNPC)
			UpdateQuestStepAndNext(player, 3, false, false, true, qStep, "done", "q3s012", true)

			SetPlayerGMD_Q3(player, qStep, "givenMedicine", nil)
			SetPlayerGMD_Q3(player, qStep, "givenFood", nil)
			AddReputationPoint(player, 25)
		else
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s011_2"), talkUIW, talkUIH, zNPC)
		end
    end
end

VLINTER.InteractionButton2["q3s011"] = function(player, qStep, zNPC)
    --Đưa đồ ăn của Kate cho Bob
	local isDone = GiveItemsQuest_q3s005(player, qStep, zNPC)

    if isDone == true then
        --Set ModData
        SetPlayerGMD_Q3(player, qStep, "givenFood", true)
		QuestUpdatedPopIn()
		
		--Hiển thị bảng talk tiếp theo
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
		if playerGMD_Quest_Q3[qStep]["givenMedicine"] and playerGMD_Quest_Q3[qStep]["givenFood"] then
			--tăng thêm 7 ngày thời gian sống cho Kate
			local newEndHour = playerGMD_Quest_Q3["q3s001"]["countHour_KateZombified"] + 168 	--FIXME: 168
			SetPlayerGMD_Q3(player, "q3s001", "countHour_KateZombified", newEndHour)
				
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s011"), talkUIW, talkUIH, zNPC)
			UpdateQuestStepAndNext(player, 3, false, false, true, qStep, "done", "q3s012", true)

			SetPlayerGMD_Q3(player, qStep, "givenMedicine", nil)
			SetPlayerGMD_Q3(player, qStep, "givenFood", nil)
			AddReputationPoint(player, 25)
		else
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s011_2"), talkUIW, talkUIH, zNPC)
		end
    end
end

--Bob
VLF.TalkToNPC["q3s011"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)

		if playerGMD_Quest_Q3["q3s011"] and playerGMD_Quest_Q3["q3s011"].active == true then
			VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s011_2"), talkUIW, talkUIH, zNPC)
		else
			ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s000"), 800, 500, false, "")
		end
	end
end

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

VLINTER.SetButtons["q3s013"] = function(player, qStep, buttonList)
	local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	if not playerGMD_Quest_Q3[qStep]["offerHelpFindMedicine"] then
		buttonList["interactionButton1"] = true
	end

	if not playerGMD_Quest_Q3[qStep]["giveKateMercy1"] then
		buttonList["interactionButton2"] = true
	elseif playerGMD_Quest_Q3[qStep]["giveKateMercy1"] == true then
		buttonList["interactionButton4"] = true
	end
	
	--Nếu trong túi đồ có antiserum thì mới hiển thị nút
	local antiserum = GetItemInContainerRecursive(player:getInventory(), nil, "Base.VLAntiserum")
	if antiserum then
		buttonList["interactionButton3"] = true
	end
	
	buttonList["interactionButton5"] = true
end

--Đề xuất tiếp tục tìm thuốc cho Kate
VLINTER.InteractionButton1["q3s013"] = function(player, qStep, zNPC)
	SetPlayerGMD_Q3(player, qStep, "offerHelpFindMedicine", true)
	VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_InteractionBtn1Talk_q3s013"), talkUIW, talkUIH, zNPC)
end

--Khuyên Bob chấm dứt đau khổ cho Kate
VLINTER.InteractionButton2["q3s013"] = function(player, qStep, zNPC)
	SetPlayerGMD_Q3(player, qStep, "giveKateMercy1", true)
	VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_InteractionBtn2Talk_q3s013"), talkUIW, talkUIH, zNPC)
end

--Đề xuất cho Kate thử antiserum
VLINTER.InteractionButton3["q3s013"] = function(player, qStep, zNPC)
	--check có antiserum
	local container = player:getInventory()
	local antiserum = GetItemInContainerRecursive(container, nil, "Base.VLAntiserum")
	if antiserum then
		ActiveQuestIntro_Centre(getText("IGUI_VLQ_InteractionBtn3Talk_q3s013"), 800, 500, false, "")
		--update qStep
		UpdateQuestStepAndNext(player, 3, false, false, true, qStep, "done", "q3s015", true)
	end
			
end

--Xác định chấm dứt đau khổ cho Kate
VLINTER.InteractionButton4["q3s013"] = function(player, qStep, zNPC)
	SetPlayerGMD_Q3(player, qStep, "giveKateMercy2", true)
	ActiveQuestIntro_Centre(getText("IGUI_VLQ_InteractionBtn4Talk_q3s013"), 800, 500, false, "")

	UpdateQuestStepAndNext(player, 3, false, false, true, qStep, "done", "q3s014", true)
end

--Chọn tiếp tục chờ đợi
VLINTER.InteractionButton5["q3s013"] = function(player, qStep, zNPC)
	ActiveQuestIntro_Centre(getText("IGUI_VLQ_InteractionBtn5Talk_q3s013"), 800, 500, false, "")
	UpdateQuestStepAndNext(player, 3, false, false, true, qStep, "done", "q3s020", true)
end

--Bob
VLF.TalkToNPC["q3s013"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)

		if playerGMD_Quest_Q3["q3s013"] and playerGMD_Quest_Q3["q3s013"].active == true then
			if playerGMD_Quest_Q3[qStep]["giveKateMercy1"] == true then
				VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_InteractionBtn2Talk_q3s013"), talkUIW, talkUIH, zNPC)
			else
				VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s013"), talkUIW, talkUIH, zNPC)
			end
		elseif playerGMD_Quest_Q3["q3s016"] and playerGMD_Quest_Q3["q3s016"].active == true then	
			ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s016"), 800, 500, false, "")
		else
			ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s000"), 800, 500, false, "")
		end
	end
end

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

--Kate
VLF.TalkToNPC["q3s001_2"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)

		if playerGMD_Quest_Q3["q3s002"] and playerGMD_Quest_Q3["q3s002"].active == "done" then
			if not playerGMD_Quest_Q3["q3s002"]["isKateTalked1"] then
				ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s003_2_1"), 800, 500, false, "")
				SetPlayerGMD_Q3(player, "q3s002", "isKateTalked1", true)
				return
			end
		end

		if playerGMD_Quest_Q3["q3s006"] and playerGMD_Quest_Q3["q3s006"]["given500RHungerForBob"] == true then
			if not playerGMD_Quest_Q3["q3s006"]["isKateTalked2"] then
				ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s006_2_1"), 800, 500, false, "")
				SetPlayerGMD_Q3(player, "q3s006", "isKateTalked2", true)
				return
			end
		end
	end
end

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

VLINTER.SetButtons["q3s012"] = function(player, qStep, buttonList)
	local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	if not playerGMD_Quest_Q3[qStep]["sayKateIsDangerousToBob1"] then
		buttonList["interactionButton1"] = true
		
	elseif playerGMD_Quest_Q3[qStep]["sayKateIsDangerousToBob1"] == true and not playerGMD_Quest_Q3[qStep]["sayKateIsDangerousToBob2"] then
		buttonList["interactionButton2"] = true
	end
end

--Nói với Kate cô ấy đang là sự nguy hiểm cho Bob
VLINTER.InteractionButton1["q3s012"] = function(player, qStep, zNPC)
	SetPlayerGMD_Q3(player, "q3s012", "sayKateIsDangerousToBob1", true)
	VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_InteractionBtn1Talk_q3s012"), talkUIW, talkUIH, zNPC)
end

--Khẳng định lại điều này	--Kết cục 2 	--Chờ 12 tiếng OnPlayerUpdate_EventQ3(player) sẽ cập nhật kết thúc quest 
VLINTER.InteractionButton2["q3s012"] = function(player, qStep, zNPC)
	SetPlayerGMD_Q3(player, qStep, "startTime_KateSuicide", getGameTime():getWorldAgeHours())
	SetPlayerGMD_Q3(player, qStep, "sayKateIsDangerousToBob2", true)	
	QuestUpdatedPopIn()
	ActiveQuestIntro_Centre(getText("IGUI_VLQ_InteractionBtn2Talk_q3s012"), 800, 500, false, "")
end

--Kate
VLF.TalkToNPC["q3s012"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	
		if playerGMD_Quest_Q3["q3s012"] and playerGMD_Quest_Q3["q3s012"].active == true then
			if playerGMD_Quest_Q3[qStep]["sayKateIsDangerousToBob1"] == true and not playerGMD_Quest_Q3[qStep]["sayKateIsDangerousToBob2"] then
				VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_InteractionBtn1Talk_q3s012"), talkUIW, talkUIH, zNPC)
			else
				VLF.QuestUI.NPCInteractionWindow(player, qStep, getText("IGUI_VLQ_3_NPCTalk_q3s012_2_1"), talkUIW, talkUIH, zNPC)
			end
		end
	end
end

--Kate
VLF.TalkToNPC["q3s016"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	
		if (playerGMD_Quest_Q3["q3s017"] and playerGMD_Quest_Q3["q3s017"].active == true) or (playerGMD_Quest_Q3["q3s018"] and playerGMD_Quest_Q3["q3s018"].active == true) then
			ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s017_2_1"), 800, 500, false, "")
		end
	end
end

--Bob
VLF.TalkToNPC["q3s017"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	
		if playerGMD_Quest_Q3["q3s017"] and playerGMD_Quest_Q3["q3s017"].active == true then
			UpdateQuestStepAndNext(player, 3, true, false, true, qStep, "done", "q3s018", true)
		
		elseif playerGMD_Quest_Q3["q3s018"] and playerGMD_Quest_Q3["q3s018"].active == true then
			if not playerGMD_Quest_Q3["q3s018"]["isBobTalked"] then
				ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s018"), 800, 500, false, "")
				SetPlayerGMD_Q3(player, "q3s018", "isBobTalked", true)
			else
				ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s000"), 800, 500, false, "")
			end
		
		elseif playerGMD_Quest_Q3["q3s019"] and playerGMD_Quest_Q3["q3s019"].active == true then
			--clear data
			--ResetData_EndQ3(player)
			
			if not IsQuest3Completing() then
				SetPlayerGMD_Q3(player, "q3s100", "quest3End3", true)
				
				--update qStep kết thúc 3
				UpdateQuestStepAndNext(player, 3, true, false, true, "q3s019", "done", "q3s100", true)

				UpdateNPC("npcQuestIdle", "q3s017", "q3s103")
				
				AddReputationPoint(player, 150)
			end
		end
	end
end

--Kate
VLF.TalkToNPC["q3s019"] = function(player, square, zNPC, qStep)
	if qStep then
		local playerGMD_Quest_Q3 = GetPlayerGlobalModDataQ3(player, qStep)
	
		if playerGMD_Quest_Q3["q3s019"] and playerGMD_Quest_Q3["q3s019"].active == true then
			ActiveQuestIntro_Centre(getText("IGUI_VLQ_3_NPCTalk_q3s019_2_1"), 800, 500, false, "")
		end
	end
end

--Bob
VLF.TalkToNPC["q3s103"] = function(player, square, zNPC, qStep)
	if qStep then
	
	end
end




