actor WhimsicalStar : BaseMM8BDMUseItem
{
Inventory.RespawnTics 525
inventory.amount 1
inventory.maxamount 1
inventory.pickupmessage "$PU_WHIMSICALSTAR"
inventory.icon "WSTRICON"
Tag "$TAG_WHIMSICALSTAR"
Inventory.PickupSound "item/1up"
scale 2.0
+COUNTITEM
+INVBAR
states
{
SpawnLoop:
WSTR Z -1
loop
Use:
WSTR Z 0 A_JumpIfInventory("WhimsicalStarCounter",1,3)
WSTR Z 0 A_PlaySoundEx("item/refill","Voice")
WSTR Z 0 A_GiveInventory("WhimsicalStarActivate",1)
stop
WSTR Z 0 A_PlaySoundEx("item/refill","Voice")
WSTR Z 0 A_GiveInventory("WhimsicalStarCounter",30)
stop
}
}

actor WhimsicalStar_Respawn : 8BDMItemRespawn
{
	translation "192:192=4:4", "198:198=102:102"
	mass 525
}
actor WhimsicalStar_RespawnShadow : 8BDMItemRespawnShadow
{
	mass 525
	States
	{
	Spawn:
		WSTR Z 0
		goto Super::Spawn
	}
}

actor WhimsicalStarActivate : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_SpawnItemEX("WhimsicalStarActivater")
stop
}
}

actor WhimsicalStarActivater : BasicWatcher
{
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_JumpIfInTargetInventory("WhimsicalStarCounter",1,"Reset")
TNT1 A 0 A_GiveToTarget("WhimsicalStarCounter",30)
TNT1 A 0 A_GiveToTarget("WhimsicalStarVisual",1)
NowWeLoop:
TNT1 A 35 
TNT1 A 0 A_TakeFromTarget("WhimsicalStarCounter",1)
TNT1 A 0 A_JumpIfInTargetInventory("WhimsicalStarCounter",1,"NowWeLoop")
stop
Reset:
TNT1 A 0 A_GiveToTarget("WhimsicalStarCounter", 30)
stop
}
}


actor WhimsicalStarVisual : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_FireCustomMissile("WhimsicalStarProjectile",0,0,8,0,0,random(-2,2))
TNT1 A 0 A_FireCustomMissile("WhimsicalStarProjectile2",120,0,8,0,0,random(-2,2))
TNT1 A 0 A_FireCustomMissile("WhimsicalStarProjectile3",240,0,8,0,0,random(-2,2))
stop
}
}

actor WhimsicalStarCounter : Inventory
{
inventory.amount 1
inventory.maxamount 30
States
{
Spawn:
TNT1 A 0
stop
}
}

actor WhimsicalStarProjectile : RollingCutter
{
+BRIGHT
radius 0
height 0
speed 15
scale 3.75
damagetype "WhimsicalStar"
damage 0
+DONTSPLASH
+NOCLIP
+NOINTERACTION
+FORCEXYBILLBOARD
reactiontime 1
States
{
Spawn:
WSTR A 0
WSTR A 0 A_FaceTarget
WSTR A 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR AA 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR B 0 A_FaceTarget
WSTR B 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR BB 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR C 0 A_FaceTarget
WSTR C 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR CC 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR C 0 A_FaceTarget
WSTR C 0 A_Countdown
TNT1 A 0 A_JumpIfCloser(340,"Spawn")
goto DeathContinue
Death:
TNT1 A 0 A_JumpIfInTargetInventory("WhimsicalStarCounter",1,"DeathContinue")
TNT1 A 0
stop
DeathContinue:
TNT1 A 0 A_CustomMissile("WhimsicalStarProjectile",0,0,0,0)
TNT1 A 0
stop
}
}


actor WhimsicalStarProjectile2 : WhimsicalStarProjectile
{
reactiontime 2
States
{
Spawn:
WSTR B 0
WSTR B 0 A_FaceTarget
WSTR B 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR BB 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR C 0 A_FaceTarget
WSTR C 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR CC 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR A 0 A_FaceTarget
WSTR A 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR AA 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR A 0 A_FaceTarget
WSTR A 0 A_Countdown
TNT1 A 0 A_JumpIfCloser(340,"Spawn")
goto DeathContinue
DeathContinue:
TNT1 A 0 A_CustomMissile("WhimsicalStarProjectile2",0,0,0,0)
TNT1 A 0
stop
}
}

actor WhimsicalStarProjectile3 : WhimsicalStarProjectile
{
reactiontime 3
States
{
Spawn:
WSTR C 0
WSTR C 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR CC 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR A 0 A_FaceTarget
WSTR A 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR AA 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR B 0 A_FaceTarget
WSTR B 0 A_GiveInventory("WhimsicalStarMovement_P",1)
WSTR BB 1 A_SpawnItemEx("WhimsicalStarDamager",0,0,0,2,0,0)
WSTR B 0 A_FaceTarget
WSTR B 0 A_Countdown
TNT1 A 0 A_JumpIfCloser(340,"Spawn")
goto DeathContinue
DeathContinue:
TNT1 A 0 A_CustomMissile("WhimsicalStarProjectile3",0,0,0,0)
TNT1 A 0
stop
}
}

actor WhimsicalStarMovement_P : CustomInventory
{
States
{
Pickup:
TNT1 A 0 A_JumpIfCloser(340,"Default")
TNT1 A 0 A_ChangeVelocity(cos(-pitch)*15,0,sin(-pitch)*15,CVF_RELATIVE|CVF_REPLACE)
stop
Default:
TNT1 A 0 A_ChangeVelocity(cos(-pitch)*3,random(-6,6),0,CVF_RELATIVE)
stop
}
}

actor WhimsicalStarDamager : BasicExplosion
{
damagetype "WhimsicalStar"
Obituary "$OB_WHIMSICALSTAR"
+DONTREFLECT
+RIPPER
+DONTBLAST
States
{
Spawn:
TNT1 AA 0 A_SpawnItemEx("OilPitIgnite",0,0,8)
TNT1 A 0 A_Explode(CallACS("vile_cbm_damage",3),48,0,0,16)
TNT1 A 2
stop
}
}