scriptName _00E_Game_Playerhouse_BoardSC extends ObjectReference conditional

;=====================================================================================
;              							FUNCTIONS                 					 
;=====================================================================================

function EnableFurniture(Int iLevel)

	FadeToBlackIMOD.Apply(1.00000)
	utility.Wait(2 as Float)
	FadeToBlackHoldIMOD.ApplyCrossFade(1 as Float)
	if iLevel == 1
		_00E_Game_Playerhouse_ArkMarket_Level01Linker.Enable()
	elseIf iLevel == 2
		_00E_Game_Playerhouse_ArkMarket_Level02Linker.Enable()
	elseIf iLevel == 3
		_00E_Game_Playerhouse_ArkMarket_Level03Linker.Enable()
	endIf
	FadeToBlackBackIMOD.ApplyCrossFade(1 as Float)
	
endFunction

function DisableFurniture()

	FadeToBlackIMOD.Apply(1.00000)
	utility.Wait(2 as Float)
	FadeToBlackHoldIMOD.ApplyCrossFade(1 as Float)
	_00E_Game_Playerhouse_ArkMarket_Level01Linker.Disable(false)
	_00E_Game_Playerhouse_ArkMarket_Level02Linker.Disable(false)
	_00E_Game_Playerhouse_ArkMarket_Level03Linker.Disable(false)
	FadeToBlackBackIMOD.ApplyCrossFade(1 as Float)
	
endFunction


function OnActivate(ObjectReference akActionRef)
	
	;backwards compatibility for saves prior patch 1.2.3.0
	If (_00E_Game_Playerhouse_ArkMarket_Level01Linker.IsEnabled())
		_00E_FurniturePurchased.SetValue(1)
	EndIf
	;backwards compatibility for saves prior patch 1.2.3.0
	
	Int iButton = _00E_Game_PlayerHouse_ArkMarket_Board.Show(0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
	if iButton == 7
		return 
	elseIf iButton == 0
	
		If PlayerREF.GetParentCell() == CapitalCityPlayerhouse
			PlayerREF.RemoveItem(Gold001, 300)
		Else
			PlayerREF.RemoveItem(Gold001, 1250)
		EndIf
		
		_00E_FurniturePurchased.SetValue(1)
		self.EnableFurniture(1)
		
	elseIf iButton == 1
	
		If PlayerREF.GetParentCell() == CapitalCityPlayerhouse
			PlayerREF.RemoveItem(Gold001, 500)
		Else
			PlayerREF.RemoveItem(Gold001, 1500)
		EndIf

		_00E_FurniturePurchased.SetValue(2)
		self.EnableFurniture(2)
		
	elseIf iButton == 2
	
		If PlayerREF.GetParentCell() == CapitalCityPlayerhouse
			PlayerREF.RemoveItem(Gold001, 700)
		Else
			PlayerREF.RemoveItem(Gold001, 1750)
		EndIf

		_00E_FurniturePurchased.SetValue(3)
		self.EnableFurniture(3)
		
	elseif iButton == 4
	
		int iButton02 = _00E_Game_PlayerHouse_RemoveFurniture.Show()
		
		if iButton02 == 0
		
			ReturnAndRefund()
		
		Else

			Activate(PlayerREF)
			
		EndIf
	
	elseif iButton == 5
	
		Cell cCurrentCell = Self.GetParentCell()
		String sHouseName = NQ24.ChooseHouseName()
		cCurrentCell.SetName(sHouseName)
			
		If cCurrentCell == CapitalCityPlayerhouse
			Player.sHouseMarketQuarterName = sHouseName
		ElseIf cCurrentCell == CapitalCityPlayerHouseUpper
			Player.sHouseNobleQuarterName = sHouseName
		EndIf
	
	elseif iButton == 6

		_00E_PlayerhousingMaster.GetMaster().ShowExpansionBoardTutorial()
	
	endIf
	
endFunction

;=====================================================================================
;              							FUNCTIONS                 					 
;=====================================================================================

Function ReturnAndRefund()

	DisableFurniture()
	
	If PlayerREF.GetParentCell() == CapitalCityPlayerhouse

		If _00E_FurniturePurchased.GetValue() == 1
			PlayerREF.AddItem(Gold001, 150)
			_00E_FurniturePurchased.SetValue(0)
		ElseIf _00E_FurniturePurchased.GetValue() == 2
			PlayerREF.AddItem(Gold001, 250)
			_00E_FurniturePurchased.SetValue(0)
		ElseIf _00E_FurniturePurchased.GetValue() == 3
			PlayerREF.AddItem(Gold001, 350)
			_00E_FurniturePurchased.SetValue(0)
		EndIf
		
	ElseIf PlayerREF.GetParentCell() == CapitalCityPlayerhouseUpper
		
		If _00E_FurniturePurchased.GetValue() == 1
			PlayerREF.AddItem(Gold001, 625)
			_00E_FurniturePurchased.SetValue(0)
		ElseIf _00E_FurniturePurchased.GetValue() == 2
			PlayerREF.AddItem(Gold001, 750)
			_00E_FurniturePurchased.SetValue(0)
		ElseIf _00E_FurniturePurchased.GetValue() == 3
			PlayerREF.AddItem(Gold001, 875)
			_00E_FurniturePurchased.SetValue(0)		
		EndIf
	
	EndIf
	
EndFunction

;=====================================================================================
;              							PROPERTIES                 					 
;=====================================================================================

Actor Property PlayerREF Auto

Cell Property CapitalCityPlayerhouse Auto
Cell Property CapitalCityPlayerHouseUpper Auto

GlobalVariable Property _00E_FurniturePurchased Auto

bool Property bLevel01FurniturePurchased Auto Conditional Hidden
bool Property bLevel02FurniturePurchased Auto Conditional Hidden
bool Property bLevel03FurniturePurchased Auto Conditional Hidden

imagespacemodifier property FadeToBlackBackIMOD auto
ObjectReference property _00E_Game_Playerhouse_ArkMarket_Level01Linker auto
message property _00E_Game_PlayerHouse_ArkMarket_Board auto
imagespacemodifier property FadeToBlackIMOD auto
Bool property __Config_bHouseHasLevel02 auto conditional
{Check this if this house has level 02 furniture designed.}
ObjectReference property _00E_Game_Playerhouse_ArkMarket_Level02Linker auto
imagespacemodifier property FadeToBlackHoldIMOD auto
Bool property __Config_bHouseHasLevel01 auto conditional
{Check this if this house has level 01 furniture designed.}
ObjectReference property _00E_Game_Playerhouse_ArkMarket_Level03Linker auto
Bool property __Config_bHouseHasLevel03 auto conditional
{Check this if this house has level 03 furniture designed.}

MiscObject Property Gold001 Auto

Message Property _00E_Game_PlayerHouse_RemoveFurniture Auto

_00E_NQ24_Playerhousing_Functions Property NQ24 Auto
_00E_PlayerHousing_CellNameSC Property Player Auto