actor BreakDashWep : BaseMM8BDMWep 10109
{
    //$Category MM8BDM-Weapons
    //$Title Break Dash
    //$Sprite BDASA0
    Weapon.AmmoUse 7
    Weapon.AmmoGive 28
    Weapon.SlotNumber 4
    Inventory.Pickupmessage "$PU_BREAKDASH"
    Obituary "$OB_BREAKDASH"
    Tag "$TAG_BREAKDASH"
    weapon.ammotype "BreakDashAmmo"
    inventory.icon "BDASWI"
    States
    {
    SpawnLoop:
        BDAS A -1
        loop
    Ready:
        BDAS H 0 ACS_ExecuteAlways(998,0,213)
        BDAS H 1 A_WeaponReady
        goto Ready+1
    Deselect:
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Lower
        BDAS H 1
        Loop
    Select:
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Raise
        BDAS H 1 
        Loop
    Fire:
        BDAS H 0 A_JumpIfNoAmmo("Fire1")
        BDAS H 1
        goto Hold
    AltFire:
        BDAS H 0
        goto Fire1
    Hold:
        BDAS H 0 A_JumpIfInventory("WeaponCharge",4,"Hold2")
        BDAS H 0 A_JumpIfInventory("WeaponCharge",3,"HoldStart")
        BDAS H 2 A_GiveInventory("WeaponCharge",1)
        BDAS H 0 A_Refire
        goto Fire1
    HoldStart:
        BDAS H 0 A_PlaySoundEx("weapon/coilstart", "Weapon")
        goto Hold2
    Hold2:
        BDAS H 0 A_JumpIfInventory("WeaponCharge",23,"Hold3")
        BDAS H 0 A_JumpIfInventory("WeaponCharge",22,"HoldStart2")
        BDAS I 1 ACS_ExecuteAlways(998,0,214,1)
        BDAS G 0 A_Refire("Hold2.a")
        goto Fire1
    Hold2.a:
        BDAS H 1 ACS_ExecuteAlways(998,0,213,1)
        BDAS H 0 A_GiveInventory("WeaponCharge",1)
        BDAS G 0 A_Refire("Hold2")
        goto Fire1
    HoldStart2:
        BDAS H 0 A_GunFlash("Sound.BusterCharge", GFF_NOEXTCHANGE)
        BDAS H 0 A_GiveInventory("WeaponCharge",1)
        goto Hold3
    Hold3:
        BDAS J 1 ACS_ExecuteAlways(998,0,215,1)
        BDAS H 0 A_Refire("Hold3.a")
        goto Fire2
    Hold3.a:
        BDAS K 1 ACS_ExecuteAlways(998,0,216,1)
        BDAS H 0 A_Refire("Hold3.b")
        goto Fire2
    Hold3.b:
        BDAS H 1 ACS_ExecuteAlways(998,0,213,1)
        BDAS H 0 A_JumpIfInventory("IsBot", 1, "BotFire")
        BDAS H 0 A_Refire("Hold3")
        goto Fire2
    BotFire:
        BDAS H 0 A_Jump(64, "Fire2")
        BDAS H 0 A_Refire("Hold3")
        goto Fire2
    Fire1:
        BDAS H 0 ACS_ExecuteAlways(998,0,213,1)
        BDAS H 0 A_StopSoundEx ("SoundSlot5") 
        BDAS H 0 A_TakeInventory("WeaponCharge",500)
        BDAS H 0 A_ClearRefire
        BDAS H 0 A_PlaySoundEx("weapon/mbuster", "Weapon")
        BDAS H 0 A_FireCustomMissile("MegaShot", 0, 0, 8, 0)
        BDAS LM 3
        BDAS H 1
        goto Ready+1
    Fire2:
        BDAS G 0 A_TakeInventory("WeaponCharge",500)
        BDAS G 0 A_ClearRefire
        BDAS G 0 A_JumpIfNoAmmo("Fire1")
    DashBegin:
        BDAS B 0 ACS_NamedExecuteAlways("core_flyplayer",0,0,2)
        BDAS H 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,1)
        BDAS H 0 A_TakeInventory("BreakDashAmmo",7,TIF_NOTAKEINFINITE)
        BDAS N 1
        BDAS H 0 ACS_ExecuteAlways(998,0,213,1)
        BDAS OZG 1
        BDAS H 0 A_GiveInventory("BreakDashCharge", 3)
    DashLoop:
        BDAS F 0 A_PlaySoundEx("weapon/breakdash", "Weapon")
        BDAS F 0 A_GiveInventory("BreakDashSpeed", 1)
        BDAS F 0 A_SpawnItemEx("BreakDashFX", cos(pitch)*16+sin(-pitch)*12, 8, sin(-pitch)*16+32, momx, momy, momz, 0, SXF_ABSOLUTEMOMENTUM)
        BDAS F 0 A_SpawnItemEx("BreakDashSparkFX", 0, 0, 0, 0, 0, -2)
        BDAS F 1 A_FireCustomMissile("BreakDashCheck", 0, 0, 0, 0)
        BDAS G 0 A_JumpIfInventory("BreakDashRecoil", 1, "Recoil")
        BDAS F 0 A_SpawnItemEx("BreakDashFX", cos(pitch)*16+sin(-pitch)*12, 8, sin(-pitch)*16+32, momx, momy, momz, 0, SXF_ABSOLUTEMOMENTUM)
        BDAS F 0 A_SpawnItemEx("BreakDashSparkFX", 0, 0, 0, 0, 0, -2)
        BDAS F 1 A_FireCustomMissile("BreakDashCheck", 0, 0, 0, 0)
        BDAS G 0 A_JumpIfInventory("BreakDashRecoil", 1, "Recoil")
        BDAS F 0 A_SpawnItemEx("BreakDashFX", cos(pitch)*16+sin(-pitch)*12, 8, sin(-pitch)*16+32, momx, momy, momz, 0, SXF_ABSOLUTEMOMENTUM)
        BDAS F 0 A_SpawnItemEx("BreakDashSparkFX", 0, 0, 0, 0, 0, -2)
        BDAS F 1 A_FireCustomMissile("BreakDashCheck", 0, 0, 0, 0)
        BDAS G 0 A_JumpIfInventory("BreakDashRecoil", 1, "Recoil")
        BDAS F 0 A_SpawnItemEx("BreakDashFX", cos(pitch)*16+sin(-pitch)*12, 8, sin(-pitch)*16+32, momx, momy, momz, 0, SXF_ABSOLUTEMOMENTUM)
        BDAS F 0 A_SpawnItemEx("BreakDashSparkFX", 0, 0, 0, 0, 0, -2)
        BDAS F 1 A_FireCustomMissile("BreakDashCheck", 0, 0, 0, 0)
        BDAS G 0 A_JumpIfInventory("BreakDashRecoil", 1, "Recoil")
        BDAS G 0 A_TakeInventory("BreakDashCharge", 1)
        BDAS G 0 A_JumpIfInventory("BreakDashCharge", 1, "DashLoop")
        BDAS B 0 ACS_NamedExecuteAlways("core_flyplayer",0,0,0)
        BDAS B 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,0)
        BDAS B 0 A_ZoomFactor(1.0)
        BDAS GZON 2
        BDAS H 2
        goto Ready+1
    Recoil:
        BDAS Z 1
        BDAS G 0 A_PlaySoundEx("weapon/breakdashimpact", "weapon")
        BDAS G 0 A_ChangeVelocity(-20*cos(pitch), 0, -8*sin(-pitch)+10, CVF_RELATIVE|CVF_REPLACE)
        BDAS G 0 A_TakeInventory("BreakDashCharge", 100)
        BDAS B 0 ACS_NamedExecuteAlways("core_flyplayer",0,0,0)
        BDAS B 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,0)
        BDAS B 0 A_ZoomFactor(1.0)
        BDAS ZZZON 2
        BDAS H 2
        goto Ready+1
    NoAmmo:
        BDAS H 1 ACS_Execute(979,0)
        BDAS H 0 A_Refire
        goto Ready+1
    }
}

actor BreakDashCharge : WeaponCharge
{
    inventory.amount 1
    inventory.maxamount 35
}

actor BreakDashRecoil : Powerup
{
    powerup.duration 10
}

actor BreakDashAmmo : Ammo
{
    inventory.amount 1
    inventory.maxamount 28
    +INVENTORY.IGNORESKILL
}

actor BreakDashSpeed : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0 A_CheckFloor("Floor")
        TNT1 A 0 A_ChangeVelocity(60*cos(pitch), 0, 30*sin(-pitch), CVF_RELATIVE|CVF_REPLACE)
        stop
    Floor:
        TNT1 A 0 A_ChangeVelocity(60*cos(pitch), 0, (30*sin(-pitch) > 0) * 30*sin(-pitch), CVF_RELATIVE|CVF_REPLACE)
        stop
    }
}

actor BreakDashCheck : FastProjectile
{
    PROJECTILE
    Obituary "$OB_BREAKDASH"
    Damagetype "BreakDash"
    height 28
    radius 28
    speed 32
    Damage (53)
    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 1
        stop
    Death:
        TNT1 A 0 A_SpawnItemEx("BreakDashQuake")
        TNT1 A 0 A_GiveToTarget("BreakDashRecoil", 1)
        stop
    }
}

actor BreakDashQuake
{
    +NOINTERACTION
	+NOCLIP
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 Radius_Quake(2, 4, 0, 2, 0)
		TNT1 A 1
		stop
	}
}

actor BreakDashProtect : PowerProtection
{
    powerup.duration 10
    damagefactor "BreakDash", 0.0
}

actor BreakDashFX
{
    +NOINTERACTION
    +NOGRAVITY
    +CLIENTSIDEONLY
    +FORCEXYBILLBOARD
    -SOLID
	TRANSLATION "4:4=56:56"
    scale 2.5
    height 0
    radius 0
    States
    {
    Spawn:
        BDAS B 0
        BDAS B 1
        stop
    }
}

actor BreakDashSparkFX
{
    PROJECTILE
    +CLIENTSIDEONLY
    +RIPPER
    damage (0)
    height 2
    radius 1
    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 1
        stop
    Death:
        TNT1 AAAAA 0 A_SpawnItemEx("BreakDashSpark", 0, 0, 0, -frandom(8, 16), 0, frandom(4, 16), frandom(-20, 20))
        stop
    }
}

actor BreakDashSpark : BreakDashFX
{
translation "0:255=65:65"
    States
    {
    Spawn:
        BDAS CDE 1
        stop
    }
}
