actor ProtoChargeWep_ScriptBar : ScriptBar {}

actor ProtoChargeWep : BaseMM8BDMWep
{
    //$Category RNC-Weapons
    //$Title Proto Charge
    //$Sprite RNCWC0
    Weapon.AmmoUse 1
    Weapon.AmmoGive 28
    Weapon.SlotNumber 5
    Tag "$TAG_PROTOCHARGE"
    Obituary "$OB_PROTOCHARGE"
    Inventory.Pickupmessage "$PU_PROTOCHARGE"
    weapon.ammotype "ProtoChargeAmmo"
    inventory.icon "RNCWP3"
    States
    {
        SpawnLoop:
            RNCW C -1
            loop

        Ready:
            NCH1 R 0 ACS_NamedExecuteWithResult("core_weaponcolor",CLR_PROTOCHARGE)
            NCH1 R 1 A_WeaponReady
            goto Ready+1
            
        Deselect:
            NCH1 R 0 A_StopSoundEx("Weapon")
            NCH1 R 0
            goto DeselectSwap
        Select:
            NCH1 R 0
            goto SelectSwap

        Fire:
        Hold:
            NCH1 R 0 A_JumpIfNoAmmo("NoAmmo")
            NCH1 R 0 A_JumpIfInventory("WeaponCharge",9,"Hold1")
            NCH1 R 1 A_GiveInventory("WeaponCharge",1)
            NCH1 R 0 A_Refire
            goto Fire1
        Altfire:
            NCH1 R 0 A_JumpIfNoAmmo("NoAmmo")
        Fire1:
            NCH1 R 0 ACS_NamedExecuteWithResult("core_chargecolor",CLR_PROTOCHARGE,TCLR_NONE)
            NCH1 R 0 A_TakeInventory("WeaponCharge",999)
            NCH1 R 0 A_PlaySoundEx("weapon/mbuster","Weapon")
            NCH1 R 0 A_FireCustomMissile("ProtoCharge",0,1,8,0)
            NCH1 STRR 2
            NCH1 R 0 A_Refire
            goto Ready+1

        Hold1:
            NCH1 R 0 A_JumpIfInventory("WeaponCharge",10,"Charge1")
            NCH1 R 0 A_GunFlash("Sound.ProtoCharge")
            NCH1 R 1 A_GiveInventory("WeaponCharge",1)
        Charge1:
            NCH1 U 0 A_JumpIfInventory("WeaponCharge",80,"Charge2")
            NCH1 U 0 A_GiveInventory("WeaponCharge",1)
            NCH1 U 1 ACS_NamedExecuteWithResult("core_chargecolor",CLR_PROTOCHARGEC1,TCLR_CHARGE1)
            NCH1 U 0 A_Refire("Charge1.a")
            goto Fire1
        Charge1.a:
            NCH1 U 0 A_JumpIfInventory("WeaponCharge",80,"Charge2")
            NCH1 U 1 A_GiveInventory("WeaponCharge",1)
            NCH1 U 0 A_Refire("Charge1.b")
            goto Fire1
        Charge1.b:
            NCH1 R 0 A_JumpIfInventory("WeaponCharge",80,"Charge2")
            NCH1 R 0 ACS_NamedExecuteWithResult("core_chargecolor",CLR_PROTOCHARGE,TCLR_NONE)
            NCH1 R 1 A_GiveInventory("WeaponCharge",1)
            NCH1 R 0 A_Refire("Charge1.c")
            goto Fire1
        Charge1.c:
            NCH1 R 0 A_JumpIfInventory("WeaponCharge",80,"Charge2")
            NCH1 R 1 A_GiveInventory("WeaponCharge",1)
            NCH1 R 0 A_Refire("Charge1")
            goto Fire1
        Charge2:
            NCH1 V 1 ACS_NamedExecuteWithResult("core_chargecolor",CLR_PROTOCHARGEC2,TCLR_PROTOCHARGEC2)
            NCH1 V 0 A_Refire("Charge2.a")
            goto Fire2
        Charge2.a:
            NCH1 V 1
            NCH1 V 0 A_Refire("Charge2.b")
            goto Fire2
        Charge2.b:
            NCH1 R 1 ACS_NamedExecuteWithResult("core_chargecolor",CLR_PROTOCHARGE,TCLR_NONE)
            NCH1 R 0 A_JumpIfInventory("IsBot", 1, "BotFire")
            NCH1 R 0 A_Refire("Charge2.c")
            goto Fire2
        Charge2.c:
            NCH1 R 1
            NCH1 R 0 A_Refire("Charge2")
            goto Fire2
        BotFire:
            NCH1 R 0 A_Jump(16, "Fire2")
            NCH1 R 0 A_Refire("Charge2.c")
            goto Fire2
        Fire2:
            NCH1 R 0 ACS_NamedExecuteWithResult("core_chargecolor",CLR_PROTOCHARGE,TCLR_NONE)
            NCH1 R 0 A_TakeInventory("WeaponCharge",999)
            NCH1 R 0 A_JumpIfInventory("ProtoChargeAmmo",5,"Fire2r")
            NCH1 R 0 A_PlaySoundEx("weapon/mbuster","Weapon")
            NCH1 R 0 A_TakeInventory("ProtoChargeAmmo",5,TIF_NOTAKEINFINITE)
            NCH1 R 0 A_FireCustomMissile("ProtoCharge",0,0,8,0)
            NCH1 STRR 2
            NCH1 R 0 A_Refire
            goto Ready+1
        Fire2r:
            NCH1 R 0 A_PlaySoundEx("weapon/cfire","Weapon")
            NCH1 R 0 A_TakeInventory("ProtoChargeAmmo",5,TIF_NOTAKEINFINITE)
            NCH1 R 0 A_FireCustomMissile("ProtoCharged",0,0,8,0)
            NCH1 STRRRR 2
            NCH1 R 0 A_Refire
            goto Ready+1

        Sound.ProtoCharge:
            TNT1 A 0 A_JumpIfInventory("WeaponCharge",80,"Sound.ProtoCharge2")
            TNT1 A 4 A_PlaySoundEx("weapon/heat1", "Weapon", 0)
            TNT1 A 1 A_JumpIfInventory("WeaponCharge",1,"Sound.ProtoCharge")
            stop
        Sound.ProtoCharge2:
            TNT1 A 4 A_PlaySoundEx("weapon/heat3", "Weapon", 0)
            TNT1 A 1 A_JumpIfInventory("WeaponCharge",1,"Sound.ProtoCharge")
            stop

        NoAmmo:
            NCH1 R 1 ACS_NamedExecute("core_noammo",0)
            NCH1 R 0 A_Refire
            goto Ready+1
    }
}
actor ProtoChargeAmmo : Ammo {inventory.amount 1 inventory.maxamount 28 +INVENTORY.IGNORESKILL}

actor ProtoCharge : BasicProjectile
{
    +BRIGHT
    +DONTBLAST
    damagetype "ProtoCharge"
    Obituary "$OB_PROTOCHARGE"
    damage (CallACS("rnc_cbm_damage",10))
    Radius 4
    Height 4
    Speed 36
    States
    {
        Spawn:
            CBUS HG 3
            loop
        Death:
            TNT1 A 0
            TNT1 A 0 A_SpawnItemEx("OilPitIgnite",0,0,8)
            stop
    }
}

actor ProtoCharged : ProtoCharge
{
    damage (CallACS("rnc_cbm_damage",80))
    Speed 18
    radius 25
    height 25
    States
    {
        Spawn:
            TNT1 A 0
            CBUS A 0 A_SpawnItemEx("ProtoChargeGFX",-32,0,0,momx/2,momy/2,momz/2,0,SXF_ABSOLUTEMOMENTUM|SXF_TRANSFERTRANSLATION)
            CBUS AB 2
            goto Spawn
    }
}

actor ProtoChargeGFX : BasicGraphicEffect
{
    +BRIGHT
    States
    {
        SpawnFrame:
            CBUS DE 2
        Death:
            CBUS F 1 A_FadeOut(0.5)
            loop
}
}