Scriptname wizWoodPileHugeScript extends ObjectReference  

Actor Property PlayerREF Auto
MiscObject property myFuel auto
Keyword property MagicDamageFire auto
Activator property wizGiantCampFireMarker auto
Activator Property wizGiantCampFireMarkerMedium Auto
Static Property TreePineForestCutStump02 Auto
Container Property wizWoodPileHugeContainer Auto
Container Property wizWoodPileMediumContainer Auto


Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	;Delete this pile if the player takes all of the wood from it.
	;debug.notification(akdestcontainer)
	if akDestContainer != None 
	
		if akBaseItem == myFuel
			if self.GetItemCount(myFuel) == 0
				Game.DisablePlayerControls()			;Force player out of the wood inventory
				Game.EnablePlayerControls()
				self.Disable()
				self.Delete()
			endif
		endif

	endIf
endEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	if akSourceContainer == playerREF
		if self.isdisabled()
			Debug.Notification("You have cleared this wood pile!")
			PlayerREF.additem(akBaseItem, self.getItemCount(akBaseItem), true)
			self.removeitem(akBaseItem, self.getItemCount(akBaseItem))
		else
			if akBaseItem != myFuel
				Debug.Notification("Sorry firewood only!")
				PlayerREF.additem(akBaseItem, self.getItemCount(akBaseItem), true)
				self.removeitem(akBaseItem, self.getItemCount(akBaseItem))
			endIf
		endIf
	endIf
endEvent


Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack,  bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	;Torch bash
	if akSource == none && (akAggressor as Actor).GetEquippedItemType(0) == 11
		Burn_Pile()
	endIf
endEvent


Event OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect)
	if (akCaster == PlayerREF) 
		if akEffect.HasKeyword(MagicDamageFire)
			Burn_Pile()
		endIf
	endIf

endEvent

Function Burn_Pile()
		self.RemoveAllItems()
		self.disable()
		self.delete()

		;Check for a tree stump REALLY close
		ObjectReference ClosestStump = Game.FindClosestReferenceOfTypeFromRef(TreePineForestCutStump02 , self, 150.0)
		If ClosestStump != None
			ClosestStump.disableNoWait()
			ClosestStump.delete()
		EndIf
		
		ObjectReference GiantFire 
		if self.getbaseobject() == wizWoodPileHugeContainer
			GiantFire = self.PlaceAtMe(wizGiantCampFireMarker)  ; Giant Campfire Marker
		elseIf self.getBaseObject() == wizWoodPileMediumContainer
			GiantFire = self.PlaceAtMe(wizGiantCampFireMarkerMedium)  ; Giant Campfire Marker Medium
		endIf

		GiantFire.MoveTo(self, 0, 0, -100)
		GiantFire.SetAngle(0.0, 0.0, PlayerREF.GetAngleZ() + 180)

endFunction