actor YoukaiBusterWep_NormalBar : NormalBar { args 250, 251 }
//actor YoukaiBusterWep_ScriptBar : ScriptBar {}

actor YoukaiBusterWep : BaseMM8BDMWep
{
	Weapon.AmmoUse 2
	Weapon.AmmoGive 28
	weapon.ammotype "YoukaiBusterAmmo"

	Weapon.SlotNumber 4

	Inventory.Pickupmessage "$PU_YOUKAIBUSTER"
	Obituary "$OB_YOUKAIBUSTER"
	Tag "$TAG_YOUKAIBUSTER"

	inventory.icon "YKAIBSTR"

	States
	{
		SpawnLoop:
			YKWP A 1
			loop

		Ready:
			YKBT B 0 ACS_NamedExecuteWithResult("core_weaponcolor", CLR_YOUKAIBUSTER)
			BUST B 0 A_JumpIfInventory("OncePower",1,"Ready2")
			YKBT B 0 A_GiveInventory("YoukaiBusterPower",1)
			YKBT B 0 A_GiveInventory("OncePower",1)
			goto Ready2
			
		Ready2:
			YKBT B 1 A_WeaponReady
			Goto Ready2

		Select:
			YKBT B 0
			goto SelectSwap
			
		Deselect:
			YKBT B 0
			goto DeselectSwap

		Fire:
			YKBT B 0 A_JumpIfNoAmmo("NoAmmo")
			YKBT B 0 A_JumpIfInventory("YoukaiBusterPower",75,"Power2")
			YKBT B 0 A_JumpIfInventory("YoukaiBusterPower",275,"Power3")
			YKBT B 0 A_JumpIfInventory("YoukaiBusterPower",1000,"Power4")
			YKBT B 0 A_PlaySoundEx("weapons/busters/megabusterfire","Weapon")
			YKBT E 0 A_TakeInventory("YoukaiBusterAmmo", 2, TIF_NOTAKEINFINITE)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",3,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",-3,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",0,0,8,0)
			YKBT CD 2
			YKBT B 12
			YKBT B 0 A_Refire
			goto Ready+2
			
		Power2:
			YKBT B 0 A_JumpIfNoAmmo("NoAmmo")
			YKBT B 0 A_JumpIfInventory("YoukaiBusterPower",275,"Power3")
			YKBT B 0 A_JumpIfInventory("YoukaiBusterPower",1000,"Power4")
			YKBT B 0 A_PlaySoundEx("weapons/busters/megabusterfire","Weapon")
			YKBT E 0 A_TakeInventory("YoukaiBusterAmmo", 2, TIF_NOTAKEINFINITE)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",3,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",-3,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBusterB",0,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiOrb",0,0,8,20)
			YKBT CD 2
			YKBT B 12
			YKBT B 0 A_Refire
			goto Ready+2
			
		Power3:
			YKBT B 0 A_JumpIfNoAmmo("NoAmmo")
			YKBT B 0 A_JumpIfInventory("YoukaiBusterPower",1000,"Power4")
			YKBT B 0 A_PlaySoundEx("weapons/busters/megabusterfire","Weapon")
			YKBT E 0 A_TakeInventory("YoukaiBusterAmmo", 2, TIF_NOTAKEINFINITE)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",2,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",-2,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBusterB",6,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBusterB",-6,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiOrbB",-10,0,-60,20)
			YKBT B 0 A_FireCustomMissile("YoukaiOrbB",10,0,60,20)
			YKBT CD 4
			YKBT B 13
			YKBT B 0 A_Refire
			goto Ready+2
		
		Power4:
			YKBT B 0 A_JumpIfNoAmmo("NoAmmo")
			YKBT B 0 A_PlaySoundEx("weapons/busters/megabusterfire","Weapon")
			YKBT E 0 A_TakeInventory("YoukaiBusterAmmo", 2, TIF_NOTAKEINFINITE)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",2,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBuster",-2,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBusterB",6,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiBusterB",-6,0,8,0)
			YKBT B 0 A_FireCustomMissile("YoukaiOrbB",-10,0,-60,20)
			YKBT B 0 A_FireCustomMissile("YoukaiOrbB",10,0,68,20)
			YKBT B 0 A_FireCustomMissile("YoukaiOrb",0,0,8,20)
			YKBT CD 5
			YKBT B 14
			YKBT B 0 A_Refire
			goto Ready+2
		
		NoAmmo:
			YKBT B 1 ACS_NamedExecuteAlways("core_noammo",0)
			goto Ready+2
	}
}

actor YoukaiBusterAmmo : Ammo
{
	inventory.amount 1
	inventory.maxamount 28
	Inventory.InterHubAmount 0
	+INVENTORY.IGNORESKILL
}

/* Scaling Code */

actor OncePower : Once {Inventory.InterHubAmount 0}

actor YoukaiPowerBar : Once
{
	inventory.amount 1
	inventory.maxamount 1000
	Inventory.InterHubAmount 0
	+INVENTORY.IGNORESKILL
}

actor YoukaiBusterPower : YoukaiPowerBar
{
	inventory.amount 1
	inventory.maxamount 1000
	Inventory.InterHubAmount 0
	+INVENTORY.IGNORESKILL
}

actor TouhouPower : CustomInventory
{
Height 0
Radius 0
+NOINTERACTION
-SOLID
+NOGRAVITY
+MISSILE
States
{
Spawn:
TNT1 A 0 nodelay A_GiveToTarget("TouhouPowerPickUP",1)
stop
}
}

actor TouhouPowerPickUP : CustomInventory
{
inventory.amount 1
inventory.maxamount 1
States
{
Pickup:
TNT1 A 0 A_GiveToTarget("YoukaiBusterPower",25)
stop
}
}

/* Projectiles */

actor YoukaiBuster : BasicBouncer
{
	+FORCEXYBILLBOARD
	+USEBOUNCESTATE
	+BRIGHT
	damagetype "YoukaiBuster"
	Obituary "$OB_YoukaiBuster"
	Speed 50
	Damage (CallACS("burst_cbm_damage",13))
	radius 10
	height 8
	bouncecount 1
	wallbouncefactor 0.95
	bouncefactor 0.95
	States
	{
		Spawn:
		YKBT A 1
		SpawnLoop:
		YKBT A 1 A_SpawnItemEx("YoukaiTrail",-5,0,0,0,0,0,0,SXF_WEPFXCOLOR)
		loop
		TNT1 A 0
		stop
		Death:
		TNT1 A 0 A_SpawnItemEx("YoukaiHit", 0, 0, 0, 0, 0, 0, 0, SXF_WEPFXCOLOR)
		stop
	}
}

actor YoukaiBusterB : BasicBouncer
{
	+FORCEXYBILLBOARD
	+USEBOUNCESTATE
	+BRIGHT
	damagetype "YoukaiBusterB"
	Obituary "$OB_YoukaiBuster"
	Speed 50
	Damage (CallACS("burst_cbm_damage",14))
	radius 10
	height 8
	bouncecount 2
	wallbouncefactor 0.95
	bouncefactor 0.95
	States
	{
		Spawn:
		YKBT A 1
		SpawnLoop:
		YKBT A 1 A_SpawnItemEx("YoukaiTrail",-5,0,0,0,0,0,0,SXF_WEPFXCOLOR)
		loop
		TNT1 A 0
		stop
		Death:
		TNT1 A 0 A_SpawnItemEx("YoukaiHit", 0, 0, 0, 0, 0, 0, 0, SXF_WEPFXCOLOR)
		stop
	}
}

actor YoukaiTrail : BasicGraphicEffect
{
	renderstyle add
	alpha 0.3
	Damage(0)
	+CLIENTSIDEONLY
	+Bright
	States
	{
		SpawnFrame:
		YKBS AAAABBBBCCCCDDDD 1
		stop 
	}
}

actor YoukaiBusterFX : BasicGraphicEffect
{
	renderstyle add
	alpha 0.5
	+BRIGHT
	States
	{
		Spawn:
		YKPN A 0
		YKPN ABCD 2
		stop
	}
}

actor YoukaiHit : BasicGraphicEffect
{
	renderstyle add
	alpha 0.5
	Damage(0)
	+CLIENTSIDEONLY
	+Bright
	States
	{
		SpawnFrame:
		YKBD AB 2
		stop 
	}
}

actor YoukaiOrb : BasicBouncer
{
	-NOGRAVITY
	+FORCEXYBILLBOARD
	+DONTREFLECT
	+BOUNCEONACTORS
	+BRIGHT
	damagetype "YoukaiOrb"
	Obituary "$OB_YoukaiBuster"
	Speed 30
	Damage (CallACS("burst_cbm_damage",6))
	radius 8
	height 8
	bouncecount 4
	wallbouncefactor 0.75
	bouncefactor 0.75
	States
	{
		Spawn:
		YKYG ABCD 0
		YKYG ABCD 3 ThrustThingZ(0, 1, 0, 1)
		/*YKYG ABCD 2 A_SpawnItemEx("YoukaiOrbTrail",-5,0,0,0,0,0,0,SXF_WEPFXCOLOR)*/
		YKYG ABCD 3
		loop
		Death:
		TNT1 A 0 A_SpawnItemEx("YinYangExplosion2", 0, 0, 0, 0, 0, 0, 0, SXF_WEPFXCOLOR)
		stop
	}
}

actor YoukaiOrbB : BasicBouncer
{
	-NOGRAVITY
	+FORCEXYBILLBOARD
	+DONTREFLECT
	+BOUNCEONACTORS
	+BRIGHT
	damagetype "YoukaiOrb"
	Obituary "$OB_YoukaiBuster"
	Speed 35
	Damage (CallACS("burst_cbm_damage",7))
	radius 10
	height 10
	bouncecount 5
	wallbouncefactor 0.85
	bouncefactor 0.85
	States
	{
		Spawn:
		YKBG ABCD 0
		YKBG ABCD 3 ThrustThingZ(0, 1, 0, 1)
		/*YKYG ABCD 2 A_SpawnItemEx("YoukaiOrbTrail",-5,0,0,0,0,0,0,SXF_WEPFXCOLOR)*/
		YKBG ABCD 3
		loop
		Death:
		TNT1 A 0 A_SpawnItemEx("YinYangExplosion2", 0, 0, 0, 0, 0, 0, 0, SXF_WEPFXCOLOR)
		stop
	}
}

/*actor YoukaiOrbTrail : BasicGraphicEffect
{
	renderstyle translucent
	alpha 0.3
	Damage(0)
	+CLIENTSIDEONLY
	+Bright
	States
	{
		SpawnFrame:
		YKYN AABBCCDD 1
		stop 
	}
}*/

/*actor YinYangExplosion1 : BasicExplosionEffect
{
	renderstyle translucent
	alpha 0.5
	+CLIENTSIDEONLY
	+Bright
    mass 2
    States
	{
		SpawnFrame:
		YKYN ABCD 2 A_SetTics(mass)
		stop
	}
}*/

actor YinYangExplosion2 : ExplosionEffect1
{
	Translation "192:129=250:250", "198:198=251:251"
	+BRIGHT
    +FORCEXYBILLBOARD
    mass 1
}