<commit_before>local ObjectManager = require("managers.object.object_manager")
local QuestManager = require("managers.quest.quest_manager")

villageQuharekPhase2ConvoHandler = {  }

function villageQuharekPhase2ConvoHandler:getInitialScreen(pPlayer, pNpc, pConversationTemplate)
	local convoTemplate = LuaConversationTemplate(pConversationTemplate)

	if (VillageJediManagerTownship:getCurrentPhase() ~= 2) then
		return convoTemplate:getScreen("intro_communitycrafting_inactive")
	elseif (QuestManager.hasCompletedQuest(pPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_02) and VillageCommunityCrafting.isOnActiveCrafterList(pPlayer)) then
		return convoTemplate:getScreen("intro_questcompleted_activecrafter")
	elseif (QuestManager.hasCompletedQuest(pPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_02) and not VillageCommunityCrafting.isOnActiveCrafterList(pPlayer)) then
		return convoTemplate:getScreen("intro_questcompleted_notactivecrafter")
	else
		return convoTemplate:getScreen("intro_communitycrafting_active")
	end
end

function villageQuharekPhase2ConvoHandler:runScreenHandlers(conversationTemplate, conversingPlayer, conversingNPC, selectedOption, conversationScreen)
	local screen = LuaConversationScreen(conversationScreen)
	local screenID = screen:getScreenID()
	local conversationScreen = screen:cloneScreen()
	local clonedConversation = LuaConversationScreen(conversationScreen)

	if (screenID == "intro_questcompleted_activecrafter" or screenID == "intro_questcompleted_notactivecrafter" or screenID == "intro_communitycrafting_active") then
		if (VillageCommunityCrafting.getCurrentActiveCrafters() >= VillageCommunityCrafting.getMaxCraftersPerPhase()) then
			clonedConversation:addOption("@conversation/quharek_phase_2:s_955b2ddb", "max_crafters") -- I hear you're looking for crafters.
		else
			if (not CreatureObject(conversingPlayer):hasSkill("crafting_artisan_novice")) then
				clonedConversation:addOption("@conversation/quharek_phase_2:s_955b2ddb", "not_skilled") -- I hear you're looking for crafters.
			else
				clonedConversation:addOption("@conversation/quharek_phase_2:s_955b2ddb", "need_people_to_help") -- I hear you're looking for crafters.
			end
		end
		clonedConversation:addOption("@conversation/quharek_phase_2:s_baf57f52", "what_you_want_to_know") -- I'd like to get the status of the village defenses.
	elseif (screenID == "need_people_to_help") then
		clonedConversation:setDialogTextDI(VillageCommunityCrafting.getMinimumIngredients())
	elseif (screenID == "talk_to_qtqc") then
		VillageJediManagerCommon.setActiveQuestThisPhase(conversingPlayer)
		QuestManager.activateQuest(conversingPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_MAIN)
		QuestManager.activateQuest(conversingPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_01)
		VillageCommunityCrafting:addToActiveCrafterList(conversingPlayer)
		VillageCommunityCrafting:incrementCurrentActiveCrafters()
		VillageCommunityCrafting:addDefaultPlayerStatsToStatTables(conversingPlayer)

		ObjectManager.withCreaturePlayerObject(conversingPlayer, function(playerObject)
			playerObject:addWaypoint("dathomir", "@npc_name:qtqc", "", 5193, -4195, WAYPOINTYELLOW, true, true, 0)
		end)
	elseif (screenID == "see_attributes") then
		VillageCommunityCrafting:sendPlayerProjectAttributes(conversingPlayer, conversingNPC)
	elseif (string.match(screenID, "_slot_")) then
		local startPos, endPos = string.find(screenID, "_slot_")
		local tableType = string.sub(screenID, 1, startPos - 1)<commit_msg>[fixed] Quharek phase 2 convo bug<commit_after>local ObjectManager = require("managers.object.object_manager")
local QuestManager = require("managers.quest.quest_manager")

villageQuharekPhase2ConvoHandler = {  }

function villageQuharekPhase2ConvoHandler:getInitialScreen(pPlayer, pNpc, pConversationTemplate)
	local convoTemplate = LuaConversationTemplate(pConversationTemplate)

	if (VillageJediManagerTownship:getCurrentPhase() ~= 2) then
		return convoTemplate:getScreen("intro_communitycrafting_inactive")
	elseif (QuestManager.hasCompletedQuest(pPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_02) and VillageCommunityCrafting:isOnActiveCrafterList(pPlayer)) then
		return convoTemplate:getScreen("intro_questcompleted_activecrafter")
	elseif (QuestManager.hasCompletedQuest(pPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_02) and not VillageCommunityCrafting:isOnActiveCrafterList(pPlayer)) then
		return convoTemplate:getScreen("intro_questcompleted_notactivecrafter")
	else
		return convoTemplate:getScreen("intro_communitycrafting_active")
	end
end

function villageQuharekPhase2ConvoHandler:runScreenHandlers(conversationTemplate, conversingPlayer, conversingNPC, selectedOption, conversationScreen)
	local screen = LuaConversationScreen(conversationScreen)
	local screenID = screen:getScreenID()
	local conversationScreen = screen:cloneScreen()
	local clonedConversation = LuaConversationScreen(conversationScreen)

	if (screenID == "intro_questcompleted_activecrafter" or screenID == "intro_questcompleted_notactivecrafter" or screenID == "intro_communitycrafting_active") then
		if (VillageCommunityCrafting:getCurrentActiveCrafters() >= VillageCommunityCrafting:getMaxCraftersPerPhase()) then
			clonedConversation:addOption("@conversation/quharek_phase_2:s_955b2ddb", "max_crafters") -- I hear you're looking for crafters.
		else
			if (not CreatureObject(conversingPlayer):hasSkill("crafting_artisan_novice")) then
				clonedConversation:addOption("@conversation/quharek_phase_2:s_955b2ddb", "not_skilled") -- I hear you're looking for crafters.
			else
				clonedConversation:addOption("@conversation/quharek_phase_2:s_955b2ddb", "need_people_to_help") -- I hear you're looking for crafters.
			end
		end
		clonedConversation:addOption("@conversation/quharek_phase_2:s_baf57f52", "what_you_want_to_know") -- I'd like to get the status of the village defenses.
	elseif (screenID == "need_people_to_help") then
		clonedConversation:setDialogTextDI(VillageCommunityCrafting:getMinimumIngredients())
	elseif (screenID == "talk_to_qtqc") then
		VillageJediManagerCommon.setActiveQuestThisPhase(conversingPlayer)
		QuestManager.activateQuest(conversingPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_MAIN)
		QuestManager.activateQuest(conversingPlayer, QuestManager.quests.FS_PHASE_2_CRAFT_DEFENSES_01)
		VillageCommunityCrafting:addToActiveCrafterList(conversingPlayer)
		VillageCommunityCrafting:incrementCurrentActiveCrafters()
		VillageCommunityCrafting:addDefaultPlayerStatsToStatTables(conversingPlayer)

		ObjectManager.withCreaturePlayerObject(conversingPlayer, function(playerObject)
			playerObject:addWaypoint("dathomir", "@npc_name:qtqc", "", 5193, -4195, WAYPOINTYELLOW, true, true, 0)
		end)
	elseif (screenID == "see_attributes") then
		VillageCommunityCrafting:sendPlayerProjectAttributes(conversingPlayer, conversingNPC)
	elseif (string.match(screenID, "_slot_")) then
		local startPos, endPos = string.find(screenID, "_slot_")
		local tableType = string.sub(screenID, 1, startPos - 1)
{'fraction_non_alphanumeric': 0.08314415437003406, 'fraction_numerical': 0.012911464245175936, 'mean_word_length': 9.96267496111975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3440980', 'n_tokens_mistral': 2459, 'n_tokens_neox': 2208, 'n_words': 338}