/* We have Mithril Ring in Inventory */
IF %BGT_VAR%
PartyHasItem("X#XZMIRI")
Global("X#XzarMithrilRing","GLOBAL",0)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("X#XzarMithrilRing","GLOBAL",1)
END

IF
Global("X#XzarMithrilRing","GLOBAL",1)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

/* Intro of Cutscene for Dryad */
IF %BGT_VAR%
AreaCheck("%DryadFalls%")
Global("X#XzarDryad","GLOBAL",4)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
ClearAllActions()
SetGlobal("X#XZDR1","GLOBAL",1)
StartCutSceneMode()
StartCutScene("X#XZDR1")
END

IF %BGT_VAR%
AreaCheck("%DryadFalls%")
Global("X#XzarDryad","GLOBAL",6)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("X#XzarDryad","GLOBAL",7)
SetGlobalTimer("X#XzarDruidAttack","GLOBAL",22000)
END

/* Forest Spirits's Summon */
IF %BGT_VAR%
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
AreaCheck("%DryadFalls%")
Global("X#SummonForest","GLOBAL",1)
Dead("cdryad")
THEN
RESPONSE #100
SetGlobal("X#SummonForest","GLOBAL",2)
END

IF %BGT_VAR%
Global("X#SummonForest","GLOBAL",2)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

IF %BGT_VAR%
AreaCheck("%DryadFalls%")
Global("X#SummonForest","GLOBAL",3)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("X#SummonForest","GLOBAL",4)
CreateCreature("X#XZFSP1",[-1.-1],0)
CreateCreature("X#XZFSP2",[-1.-1],0)
CreateCreature("X#XZFSP3",[-1.-1],0)
MoveGlobalObject("XZFSPIRIT1","cdryad")
ActionOverride("XZFSPIRIT1",Dialogue(Player1))
END

IF %BGT_VAR%
AreaCheck("%DryadFalls%")
Global("X#SummonForest","GLOBAL",5)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("X#SummonForest","GLOBAL",6)
END

IF %BGT_VAR%
Global("X#SummonForest","GLOBAL",6)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

/* Druid's Summon */
IF %BGT_VAR%
Global("X#XzarDryad","GLOBAL",7)
InParty(Myself)
GlobalTimerExpired("X#XzarDruidAttack","GLOBAL")
Global("X#XzarDruidsExist","GLOBAL",0)
AreaType(FOREST)
!Exists("storm")
!Exists("blackberry")
!Exists("zosya")
THEN
RESPONSE #100
SetGlobal("X#XzarDruidsExist","GLOBAL",1)
CreateCreatureObjectOffScreen("X#BLACK",Myself,0,0,0)
CreateCreatureObjectOffScreen("X#STORM",Myself,0,0,0)
CreateCreatureObjectOffScreen("X#ZOSYA",Myself,0,0,0)
END

/* Xzar nags about the ring */
/* nag one */
IF %BGT_VAR%
See([ENEMY])
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
Global("X#XzarNags","GLOBAL",1)
GlobalTimerExpired("X#XzarRingNag","GLOBAL")
PartyHasItem("X#XZDRIA")
THEN
RESPONSE #100
SetGlobal("X#XzarNags","GLOBAL",2)
StartDialogueNoSet(Player1)
END

/* nag two */
IF %BGT_VAR%
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
Global("X#XzarNags","GLOBAL",3)
RealGlobalTimerExpired("X#XzarRingNag2","GLOBAL")
PartyHasItem("X#XZDRIA")
THEN
RESPONSE #100
SetGlobal("X#XzarNags","GLOBAL",4)
END

IF %BGT_VAR%
Global("X#XzarNags","GLOBAL",4)
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END


/* Xzar Charms Montaron */
IF %BGT_VAR%
!AreaCheck("%EBaldursGate_SorcerousSundries_L1%")
PartyHasItem("X#XZRING")
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
InParty("montaron")
!StateCheck("montaron",STATE_DEAD)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
OR(2)
Global("X#XzarCharmMontaron","GLOBAL",0)
Global("X#XzarCharmMontaron","GLOBAL",4)
THEN
RESPONSE #100
GiveItem("X#XZRING","xzar")
DisplayStringHead(Myself,@0)
IncrementGlobal("X#XzarCharmMontaron","GLOBAL",1)
END

IF %BGT_VAR%
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
InParty("montaron")
!StateCheck("montaron",STATE_DEAD)
OR(2)
Global("X#XzarCharmMontaron","GLOBAL",1)
Global("X#XzarCharmMontaron","GLOBAL",5)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

/* triggered dialog state has no reference to Montaron's dialog file, so no need to check him */
IF %BGT_VAR%
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
Global("X#XzarCharmMontaron","GLOBAL",6)
THEN
RESPONSE #100
SetGlobal("X#XzarCharmMontaron","GLOBAL",7)
END

/* dialog state has no reference to Montaron's dialog file, so no need to check him */
IF
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
Global("X#XzarCharmMontaron","GLOBAL",7)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

/* Intro of Cutscene */
IF %BGT_VAR%
Global("X#XzarCharmMontaron","GLOBAL",2)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
InParty("montaron")
!StateCheck("montaron",STATE_DEAD)
THEN
RESPONSE #100
ClearAllActions()
SetGlobal("X#XzarCharmMontaron","GLOBAL",3)
StartCutSceneMode()
StartCutScene("X#XZDR2")
END

/* Setting Up Xzar's Nags after making the ring */
IF %BGT_VAR%
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
PartyHasItem("X#XZRING")
GlobalLT("X#XzarNags","GLOBAL",5)
THEN
RESPONSE #100
SetGlobalTimer("X#XzarNagsTime","GLOBAL",3600)
SetGlobal("X#XzarNags","GLOBAL",5)
END

IF %BGT_VAR%
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
GlobalTimerExpired("X#XzarNagsTime","GLOBAL")
PartyHasItem("X#XZRING")
OR(2)
Global("X#XzarNags","GLOBAL",5)
Global("X#XzarNags","GLOBAL",7)
!HasItemEquiped("X#XZRING","xzar")
THEN
RESPONSE #100
IncrementGlobal("X#XzarNags","GLOBAL",1)
END

IF %BGT_VAR%
OR(2)
Global("X#XzarNags","GLOBAL",6)
Global("X#XzarNags","GLOBAL",8)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

/* Cutscene with Guards */
IF %BGT_VAR%
PartyHasItem("X#XZRING")
AreaType(CITY)
AreaType(OUTDOOR)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
Global("X#XzarNags","GLOBAL",9)
!HasItemEquiped("X#XZRING","xzar")
GlobalTimerExpired("X#XzarGuards","GLOBAL")
THEN
RESPONSE #100
SetGlobal("X#XzarNags","GLOBAL",10)
ClearAllActions()
StartCutSceneMode()
StartCutScene("X#XZDR3")
END

/* Timer for Xzar Abandoning the ring */
IF %BGT_VAR%
GlobalTimerExpired("X#XzarNagsTime","GLOBAL")
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
PartyHasItem("X#XZRING")
HasItemEquiped("X#XZRING","xzar")
GlobalLT("X#XzarNags","GLOBAL",14)
THEN
RESPONSE #100
SetGlobal("X#XzarNags","GLOBAL",14)
SetGlobalTimer("X#XzarRingFinale","GLOBAL",SEVEN_DAYS)
END

IF %BGT_VAR%
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
PartyHasItem("X#XZRING")
HasItemEquiped("X#XZRING","xzar")
Global("X#XzarNags","GLOBAL",14)
GlobalTimerExpired("X#XzarRingFinale","GLOBAL")
Died([ANYTHING])
THEN
RESPONSE #100
SetGlobal("X#XzarNags","GLOBAL",15)
END

IF %BGT_VAR%
Global("X#XzarNags","GLOBAL",15)
InParty("xzar")
!StateCheck("xzar",CD_STATE_NOTVALID)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

