actor JunkShieldWep : BaseMM8BDMWep 10087
{
    //$Category MM8BDM-Weapons
    //$Title Junk Shield
    //$Sprite WEA3N0
    Weapon.AmmoUse 6
    Weapon.AmmoGive 30
    Weapon.SlotNumber 7
    Inventory.Pickupmessage "$PU_JUNKSHIELD"
    Obituary "$OB_JUNKSHIELD"
    Tag "$TAG_JUNKSHIELD"
    weapon.ammotype "JunkShieldAmmo"
    inventory.icon "JSHISI"
    States
    {
    SpawnLoop:
        WEA3 N -1
        loop
    Ready:
        JARM A 0 ACS_ExecuteAlways(998,0,57)
        JARM A 1 A_WeaponReady
        Goto Ready+1
    Deselect:
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Lower
        JARM A 1 A_Lower
        Loop
    Select:
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Raise
        JARM A 1 A_Raise
        Loop
    Altfire:
        JARM A 0 A_JumpIfNoAmmo("NoAmmo")
        JARM BCDEF 2
        goto ChargeAttack
    Fire:
        JARM A 0 A_JumpIfNoAmmo("NoAmmo")
        JARM A 1
        goto ChargeStart
    ChargeStart:
        JARM A 0 A_JumpIfNoAmmo("NoAmmo")
        JARM BCDEF 2
        JARM A 0 A_Refire("ChargeBegin")
        goto ChargeAttack
    ChargeBegin:
        TNT1 A 0 A_SpawnItemEx("JunkSpawnFX", 0, 0, 0, 0, 0, 0,0)
        TNT1 A 0 A_GiveInventory("ShieldCheck", 1)
        TNT1 A 0 A_GiveInventory("WeaponCharge", 1)
        TNT1 A 0 A_GunFlash // Sound handler
        goto ChargeWait
    ChargeWaitCheck:
        TNT1 A 0 A_JumpIfInventory("JunkShieldCharge", 5, "ChargeWaitFull")
        TNT1 A 0 A_JumpIfInventory("JunkChargeWait", 1, "ChargeWait")
        goto ShieldCharge
    ChargeWait:
        TNT1 A 1
        TNT1 A 0 A_Refire("ChargeWaitCheck")
        goto ChargeAttack
    ShieldCharge:
        TNT1 A 0 A_SpawnItemEx("JunkSpawnFX", 0, 0, 0, 0, 0, 0, 0)
        TNT1 A 0 A_PlaySoundEx("weapon/coilbounce1", "body")
        TNT1 A 0 A_GiveInventory("JunkShieldCharge", 1)
        TNT1 A 0 A_GiveInventory("JunkChargeWait", 1)
        TNT1 A 0 A_JumpIfInventory("IsBot", 1, "BotFireMid")
        goto ChargeWait
    ChargeWaitFull:
        TNT1 A 1 A_RailWait
        TNT1 A 0 A_JumpIfInventory("IsBot", 1, "BotFireFull")
        TNT1 A 0 A_Refire("ChargeWaitFull")
        goto ChargeAttack
    ChargeAttack:
        JARM H 0 A_StopSoundEx("weapon")
        JARM HJK 2
        JARM A 0 A_TakeInventory("WeaponCharge",999)
        JARM A 0 A_TakeInventory("ShieldCheck",999)
        JARM A 0 A_PlaySoundEx("weapon/junkshield", "Weapon")
        JARM A 0 A_FireCustomMissile("JunkProjectile",0,1,0,-12)
        JARM A 0 A_FireCustomMissile("JunkProjectile",120,0,0,-12)
        JARM K 2 A_FireCustomMissile("JunkProjectile",-120,0,0,-12)
        JARM K 0 A_JumpIfInventory("JunkShieldCharge", 1, "ShieldBlastStart")
        goto ShieldEnd
    ShieldBlastStart:
        JARM K 0 A_JumpIfInventory("JunkShieldCharge", 5, "ShieldBlast5")
        JARM K 0 A_JumpIfInventory("JunkShieldCharge", 4, "ShieldBlast4")
        JARM K 0 A_JumpIfInventory("JunkShieldCharge", 3, "ShieldBlast3")
        JARM K 0 A_JumpIfInventory("JunkShieldCharge", 2, "ShieldBlast2")
        JARM K 0 A_JumpIfInventory("JunkShieldCharge", 1, "ShieldBlast1")
    ShieldBlast5:
        JARM K 0 A_TakeInventory("JunkShieldCharge",1)
        JARM A 0 A_FireCustomMissile("JunkProjectile",0,0,0,-12,0,2)
        JARM A 0 A_FireCustomMissile("JunkProjectile",120,0,0,-12,0,2)
        JARM K 2 A_FireCustomMissile("JunkProjectile",-120,0,0,-12,0,2)
    ShieldBlast4:
        JARM K 0 A_TakeInventory("JunkShieldCharge",1)
        JARM A 0 A_FireCustomMissile("JunkProjectile",1.25,0,0,-12,0,-1.5)
        JARM A 0 A_FireCustomMissile("JunkProjectile",120+1.25,0,0,-12,0,-1.5)
        JARM K 2 A_FireCustomMissile("JunkProjectile",-120+1.25,0,0,-12,0,-1.5)
    ShieldBlast3:
        JARM K 0 A_TakeInventory("JunkShieldCharge",1)
        JARM A 0 A_FireCustomMissile("JunkProjectile",-2,0,0,-12,0,1)
        JARM A 0 A_FireCustomMissile("JunkProjectile",120-2,0,0,-12,0,1)
        JARM K 2 A_FireCustomMissile("JunkProjectile",-120-2,0,0,-12,0,1)
    ShieldBlast2:
        JARM K 0 A_TakeInventory("JunkShieldCharge",1)
        JARM A 0 A_FireCustomMissile("JunkProjectile",2,0,0,-12,0,1)
        JARM A 0 A_FireCustomMissile("JunkProjectile",120+2,0,0,-12,0,1)
        JARM K 2 A_FireCustomMissile("JunkProjectile",-120+2,0,0,-12,0,1)
    ShieldBlast1:
        JARM K 0 A_TakeInventory("JunkShieldCharge",1)
        JARM A 0 A_FireCustomMissile("JunkProjectile",-1.25,0,0,-12,0,-1.5)
        JARM A 0 A_FireCustomMissile("JunkProjectile",120-1.25,0,0,-12,0,-1.5)
        JARM K 2 A_FireCustomMissile("JunkProjectile",-120-1.25,0,0,-12,0,-1.5)
        goto ShieldEnd
    ShieldEnd:
        JARM K 4
        JARM JI 2
        goto Ready+1
    NoAmmo:
        JARM A 1 ACS_Execute(979,0)
        goto Ready+1
    Flash:
        TNT1 A 0 A_PlaySoundEx("weapon/coilstart", "Weapon")
        TNT1 A 35
        TNT1 A 0 A_JumpIfInventory("WeaponCharge", 1, "Sound.BusterCharge")
        stop
    BotFireMid:
        TNT1 A 0 A_Jump(25, "ChargeAttack")
        goto ChargeWait
    BotFireFull:
        TNT1 A 0 A_Jump(75, "ChargeAttack")
        goto ChargeWaitFull+2
    }
}

actor JunkShieldAmmo : Ammo
{
    inventory.amount 1
    inventory.maxamount 30
    +INVENTORY.IGNORESKILL
}

actor JunkShieldCharge : Inventory
{
    inventory.amount 1
    inventory.maxamount 5
}

actor JunkChargeWait : Powerup
{
    powerup.duration 6
}


actor JunkSpawnFX
{
    PROJECTILE
    +NOINTERACTION
    +CLIENTSIDEONLY
    height 1
    radius 1
    scale 2.5
    states
    {
    Spawn:
        TNT1 A 0
        JSHF GGFFEEDDCCBBAA 1 A_Warp(AAPTR_TARGET, -12, 0, 0, 0, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION)
        JSHF A 0 A_SpawnItemEx("JunkShieldWarper", 0, 0, 0, 0, 0, 0, 0, SXF_TRANSFERPOINTERS)
        TNT1 A 5
        stop
    }
}

actor JunkShieldWarper : BaseShieldWarper
{
	States
	{
    Shield:
        JSHI HHIIJJKKLLMMNNOOAABBCCDDEEFFGG 1 A_Warp(AAPTR_TARGET, 0, 0, 0, 0, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION)
        loop
	}
}

actor JunkProjectile
{
    PROJECTILE
    +SHOOTABLE
    +THRUSPECIES
    +NOTAUTOAIMED
    Species "JunkShot"
    +DONTRIP
    -NOBLOCKMAP
    +NOBLOOD
    +NORADIUSDMG
    +CANTSEEK
    +NOTAUTOAIMED
	+RIPPER
	painchance 256
    damagetype "JunkShield"
    Obituary "$OB_JUNKSHIELD"
    Damage (4)
    Health 800
    Height 30
    Radius 16
    scale 2.5
    Speed 30
    States
    {
    Spawn:
        JSHI X 0
        JSHI X 4
        JSHI X 0 A_SpawnItemEx("JunkProjectile2", -momx*4, -momy*4, -momz*4, momx, momy, momz, angle, SXF_ABSOLUTEMOMENTUM)
        JSHI X 1
        wait
    Death:
        TNT1 A 0 //A_JumpIf(health <= 0, "Shattered")
    XDeath:
        TNT1 A 0 A_SpawnItemEx("ExplosionEffect1", 0, 0, 10)
        stop
	Pain:
    Shattered:
        TNT1 A 0 A_PlaySoundEx("item/protoreflect","Weapon")
        TNT1 A 0 A_SpawnItemEx("JunkEndEffect1")
        TNT1 A 2
        stop
    }
}

actor JunkEndEffect1 : BasicGraphicEffect
{
    renderstyle "add"
    +BRIGHT
    alpha 0.9
    States
    {
    Spawn:
		JSHI Z 0
        JSHI Z 0 A_SetScale(scaleX + 0.1, 2.5) 
        JSHI Z 1 A_FadeOut(0.05)
        loop
    }
}

actor JunkProjectile2 : JunkProjectile
{
    Health 400
    Damage (4)
    States
    {
    Spawn:
		JSHI Y 0
        JSHI Y 4
        loop
    Shattered:
         TNT1 A 0 A_PlaySoundEx("item/protoreflect","Weapon")
        TNT1 A 0 A_SpawnItemEx("JunkEndEffect2")
		TNT1 A 2
        stop
    }
}

actor JunkEndEffect2 : JunkEndEffect1
{
    States
    {
    Spawn:
        JSHI "[" 0 A_SetScale(scaleX + 0.1, 2.5) 
        JSHI "[" 1 A_FadeOut(0.05)
        loop
    }
}

actor JunkDebrisSpawner : CustomInventory
{
    inventory.amount 1
    inventory.maxamount 1
    +AUTOACTIVATE
    States
    {
    Spawn:
        TNT1 A 1
        loop
    Use:
        TNT1 AA 0 A_SpawnItemEx("JunkDebris",0,0,0,random(-10,10),random(-10,10),random(5,15),random(0,360))
        TNT1 AAAA 1 A_SpawnItemEx("JunkDebrisSmall",0,0,0,random(-10,10),random(-10,10),random(5,15),random(0,360))
        stop
    XDeath:
    Death:
        TNT1 A 1
        stop
    }
}

actor JunkDebris
{
    PROJECTILE
    -NOGRAVITY
    +CLIENTSIDEONLY
    +THRUACTORS
    Height 1
    Radius 1
    scale 2.5
    reactiontime 4
    States
    {
    Spawn:
        TNT1 A 0 
        TNT1 A 0 A_PlaySoundEx("weapon/junkend","Voice")
        JSHI V 2
        TNT1 A 2 A_CountDown
        Goto Spawn+2
    }
}

actor JunkDebrisSmall : JunkDebris
{
    reactiontime 3
    States
    {
    Spawn:
        JSHI W 2
        TNT1 A 2 A_CountDown
        loop
    }
}
