Scriptname _00E_NQ_G_05_Functions extends Quest  

Import _00E_QuestFunctions
;=====================================================================================
;              							FUNCTIONS                  					 
;=====================================================================================

Function SellPlant()
	
	_00E_NQ_G_05_PlantEnableMarkerQuellwachtREF.Enable()
	_00E_NQ_G_05_PlantEnableMarkerWuesteREF.Enable()
	_00E_NQ_G_05_HehlerREF.Enable()

EndFunction

Function DisablePlant()

	_00E_NQ_G_05_PlantEnableMarkerQuellwachtREF.Disable()
	_00E_NQ_G_05_PlantEnableMarkerWuesteREF.Disable()
	_00E_NQ_G_05_HehlerREF.Disable()
	
EndFunction

Function SellJuice()

	PlayerREF.RemoveItem(Gold001, 110)
	_00E_NQ_G_05_SurmakREF.RemoveItem(_00E_NQ_G_05_Daemmerblumensaft, 1, false, PlayerREF)
	
	if PlayerREF.GetItemCount(_00E_NQ_G_05_Daemmerblumensaft) < 1
		PlayerREF.AddItem(_00E_NQ_G_05_Daemmerblumensaft, 1)
	EndIf

EndFunction

Function SwitchChairs()

	_00E_NQ_G_MaelSittingChairREF.Enable()

EndFunction

Function UpdatePlantCounter(int iType, int iAmount)
	
	While bUpdatePlantCounterLocked
		Utility.WaitMenuMode(0.1)
	EndWhile
	bUpdatePlantCounterLocked = True
	
	PlantsCollection[iType].SetValue(PlantsCollection[iType].GetValue() + iAmount)
	Self.UpdateCurrentInstanceGlobal(PlantsCollection[iType])
		
	int iCurrentCount = PlantsCollection[iType].GetValueInt()

	if iType == 0
		if iCurrentCount >= 3
			If !(Self.IsObjectiveCompleted(10))
				Self.SetObjectiveCompleted(10)
			EndIf
		ElseIf iCurrentCount < 3
			Self.SetObjectiveCompleted(10,0)
			Self.SetObjectiveDisplayed(10, True, True)
		EndIf
	ElseIf iType == 1
		if iCurrentCount >= 3
			If !(Self.IsObjectiveCompleted(15))
				Self.SetObjectiveCompleted(15)
			EndIf
		ElseIf iCurrentCount < 3
			Self.SetObjectiveCompleted(15,0)
			Self.SetObjectiveDisplayed(15, True, True)
		EndIf
	ElseIf iType == 2
		if iCurrentCount >= 1
			If !(Self.IsObjectiveCompleted(20))
				Self.SetObjectiveCompleted(20)
			EndIf
		ElseIf iCurrentCount < 1
			Self.SetObjectiveCompleted(20,0)
			Self.SetObjectiveDisplayed(20, True, True)
		EndIf
	EndIf
	
	If Self.IsObjectiveCompleted(10) && Self.IsObjectiveCompleted(15) && Self.IsObjectiveCompleted(20)
		Self.SetStage(30)
		If !bDoneAutosave
			Game.RequestAutoSave()
			bDoneAutoSave = true
		EndIf
	EndIf
	
	bUpdatePlantCounterLocked = False
	
EndFunction

Function GiveMoney()

	PlayerREF.AddItem(Gold001, 150)
	
	If MQ09.IsCompleted()
		_00E_NQ_G_05_Enemylinker.Enable()
	EndIf

EndFunction

Function DespawnApothekarius()

	_00E_NQ_G_05_ApothekariusREF.Disable()
	_00E_NQ_G_05_MessengerREF.Disable()

EndFunction

Function TeleportDijaam()

	_00E_SC_DijaamOnelys.MoveTo(_00E_NQ_G_05_DijaamTeleportMarker)
	
EndFunction

Function DumpDijaam()

	If !CQ_D_01.IsCompleted()
		CQ_D_01.SetStage(20)
	EndIf

	_00E_SC_DijaamOnelys.MoveTo(_00E_NPCDumpMarker)
	
EndFunction

Function RemovePlayerFromSickle()
	
	PlayerREF.RemoveFromFaction(ArkHaendlergilde)
	PlayerREF.RemoveFromFaction(ArkKontorFaction)
	ArkHaendlergilde.SetPlayerExpelled()
	ArkKontorFaction.SetPlayerExpelled()

EndFunction

Function RemovePlants()

	PlayerREF.RemoveItem(_00E_NQ_G_05_Daemmerblumensaft, PlayerREF.GetItemCount(_00E_NQ_G_05_Daemmerblumensaft))
	PlayerREF.RemoveItem(_00E_NQ_G_05_Staubmadenstachel_Ingredient, PlayerREF.GetItemCount(_00E_NQ_G_05_Staubmadenstachel_Ingredient))
	PlayerREF.RemoveItem(_00E_NQ_G_05_NiederlandsNistel_Ingredient, PlayerREF.GetItemCount(_00E_NQ_G_05_NiederlandsNistel_Ingredient))
	DisablePlant()
	RewardMoney()
	SetObjectiveCompleted(30)

EndFunction

Function AddSilence()

	_00E_SilenceTransitionHighPriority.Add()

EndFunction

Function SetUpSC01()

	_00E_NQ_G_05_MessengerREF.Enable()
	_00E_NQ_G_05_MessengerREF.MoveTo(_00E_NQ_G_04_MessengerTeleportMarkerREF)
	DRSWoodSingleLight02OpenM.Play(_00E_NQ_G_04_MessengerTeleportMarkerREF)
	
EndFunction

Function SetUpSC02()

	_00E_NQ_G_05_CellarDoorREF.Lock(False)
	_00E_NQ_G_05_ApothekariusREF.Enable()
	_00E_NQ_G_05_Rodas_CorpseREF.Enable()
	_00E_NQ_G_05_Rodas_CorpseREF.MoveTo(NQG02_SC2_RhodasLieMarkerREF)
	_00E_NQ_G_05_ProtektorREF.Enable()
	MoveMaelSC02()

EndFunction

Function MoveMaelSC02()

	_00E_SC_Mael.MoveTo(_00E_NQ_G_04_MaelTeleportToCellarMarkerREF)
	
EndFunction

Function SetUpSC03()

	_00E_SC_DijaamOnelys.Enable()
	_00E_SC_DijaamOnelys.MoveTo(_00E_NQ_G_05_DijaamSitMarker)
	_00E_SC_Mael.MoveToMyEditorLocation()

EndFunction

Function StartSC01()

	NQ_G_05_SC01_MessengerArriveAtKontor.ForceStart()

EndFunction

Function StartSC02()

	_00E_SC_Mael.BlockActivation(true)
	NQ_G_05_SC02_CellarTalk.ForceStart()
	
EndFunction

Function StartSC03()

	NQ_G_05_SC03_DijaamTalk.ForceStart()

EndFunction

Function RewardMoney()

		PlayerREF.AddItem(Gold001, __Config_RewardMoney)

EndFunction

Function RemoveSilence()

	_00E_SilenceTransitionHighPriority.Remove()

EndFunction

Function FinishQuest()
	
	_00E_NQ_G_05_Rodas_CorpseREF.Disable()
	Levelsystem.GiveEP(__Config_RewardEXP)
	Levelsystem.RemoveSilence()
	Levelsystem.SetAllowIdleChatter(True)
	Self.CompleteQuest()
	NQ_G_06.SetStage(5)

EndFunction

Function OpenCellarDoor()

	NQ_G_05_CellarDoor.lock(false)

EndFunction

Function SetRodasUnconscious()

	_00E_NQ_G_05_Rodas_CorpseREF.SetUnconscious()
	_00E_NQ_G_05_Rodas_CorpseREF.EnableAI(False)

EndFunction

;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================
bool bDoneAutosave = false
Bool bUpdatePlantCounterLocked = False

Quest Property MQ09 Auto

;actors
Actor Property PlayerRef Auto
Actor Property _00E_NQ_G_05_MessengerREF Auto
Actor Property _00E_NQ_G_05_ApothekariusREF Auto
Actor Property _00E_NQ_G_05_Rodas_CorpseREF Auto
Actor Property _00E_NQ_G_05_ProtektorREF Auto
Actor Property _00E_SC_Mael Auto
Actor Property _00E_SC_DijaamOnelys Auto
Actor Property _00E_NQ_G_05_SurmakREF Auto
Actor Property _00E_NQ_G_05_HehlerREF Auto

;rewards
int Property __Config_RewardEXP Auto
int Property __Config_RewardMoney Auto
MiscObject Property Gold001 Auto

_00E_QuestFunctions Property Levelsystem Auto

;items
MiscObject Property _00E_NQ_G_05_Daemmerblumensaft Auto
MiscObject Property _00E_NQ_G_05_Staubmadenstachel_Ingredient Auto
MiscObject Property _00E_NQ_G_05_NiederlandsNistel_Ingredient Auto

;marker
Objectreference Property _00E_NQ_G_04_MessengerTeleportMarkerREF Auto
Objectreference Property _00E_NQ_G_05_CellarDoorREF Auto
Objectreference Property _00E_NQ_G_04_MaelTeleportToCellarMarkerREF Auto
Objectreference Property _00E_NQ_G_05_DijaamSitMarker Auto
Objectreference Property _00E_NQ_G_05_DijaamTeleportMarker Auto
Objectreference Property _00E_NPCDumpMarker Auto
Objectreference Property _00E_NQ_G_05_PlantEnableMarkerQuellwachtREF Auto
Objectreference Property _00E_NQ_G_05_PlantEnableMarkerWuesteREF Auto
ObjectReference Property _00E_NQ_G_05_Enemylinker Auto
ObjectReference Property NQG02_SC2_RhodasLieMarkerREF Auto
ObjectReference Property NQ_G_05_CellarDoor Auto

;GLOBALS
Globalvariable[] Property PlantsCollection Auto ;counter for plants collected

;scenes
Scene Property NQ_G_05_SC01_MessengerArriveAtKontor Auto
Scene Property NQ_G_05_SC02_CellarTalk Auto
Scene Property NQ_G_05_SC03_DijaamTalk Auto

;for guild rank
Faction Property ArkHaendlergilde Auto
Faction Property ArkKontorFaction Auto

;sound for dooropen when messenger is teleported
Sound Property DRSWoodSingleLight02OpenM Auto

MusicType Property _00E_SilenceTransitionHighPriority Auto

;Maels chairs
Objectreference Property _00E_NQ_G_MaelSittingChairREF Auto

;next quest start
Quest Property NQ_G_06 Auto
Quest Property CQ_D_01 Auto