Scriptname Tsc_ThrowingWeapons_QuestScript extends Quest  

GlobalVariable Property ModVersion  Auto
Perk Property PickupPerk  Auto  

FormList Property AmmoItemList  Auto
FormList Property ScrollList  Auto
SPELL Property CrafGrenadeSpell  Auto

Book Property FrostPotionRecipe  Auto
SPELL Property FrostPotionRecipeSpell  Auto


;FNIS variables
int ModID
int ModCRC
int magidle_base
int magatk_base

Event OnInit()
	ModVersion.SetValue(3.0)
	Game.GetPlayer().AddPerk(PickupPerk)

	version3Update()

	ModCRC = FNIS_aa.GetInstallationCRC()
	if (ModCRC == 0)
		Debug.Notification("FNIS hasn't been installed")
	else
		ModID = FNIS_aa.GetAAModID("tsc", "Spears", true)
		magidle_base = FNIS_aa.GetGroupBaseValue(ModID, FNIS_aa._magidle(), "Spears", true)
		magatk_base = FNIS_aa.GetGroupBaseValue(ModID, FNIS_aa._magatk(), "Spears", true)
		Debug.Notification("True Spear Combat FNIS successfully installed!")
	endIf

	Debug.Notification("True Spear Combat V0.7 Installed!")
EndEvent


Function version3Update()
	Game.GetPlayer().AddSpell(CrafGrenadeSpell)
	int num = Game.GetPlayer().GetItemCount(FrostPotionRecipe)
	if (num > 0)
		Game.GetPlayer().RemoveItem(FrostPotionRecipe, num, true)
		Game.GetPlayer().AddSpell(FrostPotionRecipeSpell, false)
	endIf

	int index = ScrollList.GetSize() - 1
	while (index > -1)
		num = Game.GetPlayer().GetItemCount(ScrollList.GetAt(index))
		if (num > 0)
			Game.GetPlayer().RemoveItem(ScrollList.GetAt(index), num, true)
			Game.GetPlayer().AddItem(AmmoItemList.GetAt(index), num, true)
		endIf
		index -= 1
	endWhile


endFunction

Function fnisUpdate()
	int current_crc = FNIS_aa.GetInstallationCRC()
	if (current_crc == 0)
		Debug.Trace("FNIS hasn't been installed properly")
	elseif (current_crc != ModCRC)
		ModID = FNIS_aa.GetAAModID("tsc", "Spears", true)
		magidle_base = FNIS_aa.GetGroupBaseValue(ModID, FNIS_aa._magidle(), "Spears", true)
		magatk_base = FNIS_aa.GetGroupBaseValue(ModID, FNIS_aa._magatk(), "Spears", true)
		ModCRC = current_crc
		Debug.Notification("True Spear Combat FNIS successfully updated!")
	endIf
endFunction

int Function getMagidle_base()
	return magidle_base
endFunction

int Function getMagatk_base()
	return magatk_base
endFunction

int Function getModCRC()
	return ModCRC
endFunction