Scriptname _SAG_Activ_NewStatsScripts extends ReferenceAlias  

GlobalVariable Property _SAG_Activ_BJ_ExAequo Auto
GlobalVariable Property _SAG_Activ_BJ_Fails Auto
GlobalVariable Property _SAG_Activ_BJ_GoldLost Auto
GlobalVariable Property _SAG_Activ_BJ_GoldWon Auto
GlobalVariable Property _SAG_Activ_BJ_Victories Auto

GlobalVariable Property ProphetDiceWonGames Auto
GlobalVariable Property ProphetDiceLostGames Auto
GlobalVariable Property ProphetDiceLostGold Auto
GlobalVariable Property _SAG_ProphDiceWonGold Auto

Event OnInit()
	RegisterForMenu("Journal Menu")
EndEvent
Event OnPlayerLoadGame()
	OnInit()
EndEvent

Event OnMenuOpen(string a_menuName)

; DICE JACK - won games
	string[]DJWGargs = new string[4]
	DJWGargs[0] = "Tavern Games - Dice Jack: won games" ; Stat name
	DJWGargs[1] =  _SAG_Activ_BJ_Victories.Value as INT
	DJWGargs[2] = "0" ; stat category index as string 0 = "General"
	DJWGargs[3] = ""
	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", DJWGargs)

; DICE JACK - lost games
	string[]DJLGargs = new string[4]
	DJLGargs[0] = "Tavern Games - Dice Jack: lost games" ; Stat name
	DJLGargs[1] =  _SAG_Activ_BJ_Fails.Value as INT
	DJLGargs[2] = "0" ; stat category index as string 0 = "General"
	DJLGargs[3] = ""
	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", DJLGargs)

; DICE JACK - Ex Aequo
	string[]DJEAargs = new string[4]
	DJEAargs[0] = "Tavern Games - Dice Jack: ex aequo" ; Stat name
	DJEAargs[1] =  _SAG_Activ_BJ_ExAequo.Value as INT
	DJEAargs[2] = "0" ; stat category index as string 0 = "General"
	DJEAargs[3] = ""
	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", DJEAargs)

; DICE JACK - Gold Lost
	string[]DJGLargs = new string[4]
	DJGLargs[0] = "Tavern Games - Dice Jack: lost gold" ; Stat name
	DJGLargs[1] =  _SAG_Activ_BJ_GoldLost.Value as INT
	DJGLargs[2] = "0" ; stat category index as string 0 = "General"
	DJGLargs[3] = ""
	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", DJGLargs)

; DICE JACK - Gold Won
	string[]DJGWargs = new string[4]
	DJGWargs[0] = "Tavern Games - Dice Jack: won gold" ; Stat name
	DJGWargs[1] =  _SAG_Activ_BJ_GoldWon.Value as INT
	DJGWargs[2] = "0" ; stat category index as string 0 = "General"
	DJGWargs[3] = ""
	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", DJGWargs)

; DICE JACK - victory ratio
	string[] DJVRargs = new string[4]
	DJVRargs[0] = "Tavern Games - Dice Jack: victory ratio" ; Stat name
	;Fixed divide by zero error here.
	if( _SAG_Activ_BJ_Victories.Value + _SAG_Activ_BJ_Fails.Value + _SAG_Activ_BJ_ExAequo.Value == 0 )
		DJVRargs[1] = "0%"
	else
		DJVRargs[1] =  (_SAG_Activ_BJ_Victories.Value/(_SAG_Activ_BJ_Victories.Value+_SAG_Activ_BJ_Fails.Value+_SAG_Activ_BJ_ExAequo.Value)*100) as int +"%"
	endif
	DJVRargs[2] = "0" ; stat category index as string 0 = "General"
	DJVRargs[3] = ""
	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", DJVRargs)

EndEvent