Scriptname wizWoodPileStatic extends ObjectReference  

Actor Property PlayerREF Auto
Actor Property ArngeirREF Auto
MiscObject property Firewood01 auto
FormList Property wizWoodPile Auto
FormList Property wizSafeContainerList Auto
GlobalVariable Property wizDynamicThingsEnabled Auto 
GlobalVariable Property wizOptionWoodPilesEnabled Auto 
GlobalVariable Property wizOptionDTResetTime Auto

Bool ItemAdded
Float Respawn

Event OnCellAttach()
	if ItemAdded != TRUE
		if utility.getCurrentGameTime() >= (Respawn + (wizOptionDTResetTime.getvalue() as float))
			Self.disable()
			Self.delete()
			Return
		endIf
	endIf

	if self.getNumItems() == 0
		self.Disable()
	endIf
endEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	if akSourceContainer == PlayerREF
		if akBaseItem != Firewood01 
			Debug.Notification("Sorry firewood only!")
			PlayerREF.additem(akBaseItem, aiItemCount, true)
			self.removeitem(akBaseItem, aiItemCount)
		else
			if ItemAdded == False
				ItemAdded= TRUE
				if !wizSafeContainerList.HasForm(self)
					wizSafeContainerList.AddForm(self)
;					debug.notification(wizSafeContainerList.GetSize())
				endIf
				debug.notification("Dynamic Things: This woodpile is safe for storage")
			endIf			
		endIf
	endIf
endEvent

Event OnCellDetach()
	Respawn = Utility.GetCurrentGameTime()
endEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	;Disable this pile if the player takes all of the wood from it.
	if akDestContainer != None 
;		if akBaseItem == Firewood01
			if self.getNumItems() == 0
				Game.DisablePlayerControls()			;Force player out of the wood inventory
				Game.EnablePlayerControls()
				ItemAdded=False
				self.Disable()
			endif
;		endif
	endIf
endEvent

Event OnActivate(ObjectReference akActionRef)
	if akActionRef == Game.GetPlayer()
		if ItemAdded == TRUE
			if !wizSafeContainerList.HasForm(self)
				wizSafeContainerList.AddForm(self)
;				debug.notification(wizSafeContainerList.GetSize())
			endIf
			debug.notification("Dynamic Things: This woodpile is safe for storage")
		endIf
	endIf
endEvent

event onReset()
	;Not used any more
endEvent