actor MegaArm : BaseMM8BDMWep
{
    Weapon.AmmoUse 1
    Weapon.AmmoGive 3
    Weapon.SlotNumber 1
    Inventory.Pickupmessage "$PU_MEGAARM"
    Obituary "$OB_MEGAARM"
    Tag "$TAG_MEGAARM"
    weapon.ammotype "BusterAmmo"
    inventory.icon "NULLICON"
    Dropitem ""
    States
    {
    SpawnLoop:
        MARM A 1
        stop
    Ready:
        BUST B 0 A_JumpIfInventory("BusterGiven",1,"TakeBusters")
        Goto Ready2
    TakeBusters:
        BUST B 0 A_GiveInventory("TakeBuster", 1)
        Goto Ready2
    Ready2:
        BUST B 0 ACS_ExecuteAlways(998,0,0)
        BUST B 0 ACS_ExecuteAlways(998,0,0,1)
        BUST B 0 A_TakeInventory("WeaponCharge",999)
        BUST B 2 A_WeaponReady
        Goto Ready2+2
    Deselect:
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Lower
        BUST B 1 A_Lower
        Loop
    Select:
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Raise
        BUST B 1 A_Raise
        Loop
    Fire:
    Altfire:
        BUST B 0 A_JumpIfNoAmmo("Hold")
        BUST B 0 A_PlaySoundEx("weapon/mbuster","Weapon")
        BUST B 0 A_TakeInventory("WeaponCharge",999)
        BUST B 0 A_FireCustomMissile("MegaShot",0,0,8,0)
        BUST B 0 ACS_ExecuteAlways(998,0,0,1)
        BUST CD 3
		BUST B 1
        BUST B 0 A_Refire
        goto Ready2+2
    MiniFire:
        TNT1 A 0 A_TakeInventory("WeaponCharge",999)
        TNT1 A 0 A_StopSoundEx("SoundSlot5")
        TNT1 A 0 A_PlaySoundEx("weapon/megaarmmini","Weapon")
        TNT1 A 0 A_FireCustomMissile("MegaArmHand",0,0,8,0)
        TNT1 A 1
        TNT1 A 0 A_GiveInventory("MegaArmWait", 1)
        TNT1 A 0 ACS_ExecuteAlways(998,0,0,1)
        goto ChargeFireWait
	ChargeFireR:
        TNT1 A 0 A_TakeInventory("WeaponCharge",999)
        TNT1 A 0 A_StopSoundEx("SoundSlot5")
        TNT1 A 0 A_PlaySoundEx("weapon/megaarm","Weapon")
        TNT1 A 0 A_FireCustomMissile("MegaArmFistRAGE",0,0,8,0)
        TNT1 A 1
        TNT1 A 0 A_GiveInventory("MegaArmWait", 1)
        TNT1 A 0 ACS_ExecuteAlways(998,0,0,1)
		goto ChargeFireWait
    ChargeFire:
		TNT1 A 0 A_JumpIfInventory("PowerPartCAttack",1,"ChargeFireR")
		TNT1 A 0 A_JumpIfInventory("RageRuneFlag",1,"ChargeFireR")
        TNT1 A 0 A_TakeInventory("WeaponCharge",999)
        TNT1 A 0 A_StopSoundEx("SoundSlot5")
        TNT1 A 0 A_PlaySoundEx("weapon/megaarm","Weapon")
        TNT1 A 0 A_FireCustomMissile("MegaArmFist",0,0,8,0)
        TNT1 A 1
        TNT1 A 0 A_GiveInventory("MegaArmWait", 1)
        TNT1 A 0 ACS_ExecuteAlways(998,0,0,1)
    ChargeFireWait:
		TNT1 A 0 ACS_ExecuteAlways(998,0,0,1)
        TNT1 A 1 A_RailWait
        TNT1 A 0 A_JumpIfInventory("MegaArmWait", 1, "ChargeFireWait")
        TNT1 A 0 A_JumpIf(true, "ChargeFireEnd")
        loop
    ChargeFireEnd:
        BUST B 0 A_PlaySoundEx("weapon/megaarmreturn","Weapon")
        BUST B 6
        BUST B 0 A_Refire
        goto Ready2+2
    Hold:
        //BUST B 0 A_JumpIfInventory("WeaponCharge",34,"Charge2Start")
        BUST B 0 A_JumpIfInventory("WeaponCharge",14,"Charge")
        BUST B 1 A_GiveInventory("WeaponCharge",1)
        BUST B 0 A_Refire
        Goto Ready2+2
    Charge:
        //MARM H 0 A_JumpIfInventory("WeaponCharge",34,"Charge2Start")
        MARM H 0 A_PlaySoundEx("weapon/coilstart","Weapon")
        MARM H 0 A_JumpIfInventory("WeaponCharge",15,"Charge1")
        Goto Charge1
    BotFire:
        MARM H 0 A_Jump(128, "ChargeFire")
        MARM H 0 A_Refire
        Goto ChargeFire
    Charge1:
        MARM H 2 ACS_ExecuteAlways(991,0,221)
        MARM H 0 A_GiveInventory("WeaponCharge",1)
        MARM H 0 A_JumpIfInventory("WeaponCharge", 33, "Charge2Start")
        MARM H 0 A_Refire("Charge1.a")
        Goto MiniFire
    Charge1.a:
        BUST B 2 ACS_ExecuteAlways(991,0,0)
        MARM H 0 A_GiveInventory("WeaponCharge",1)
        MARM H 0 A_JumpIfInventory("WeaponCharge", 33, "Charge2Start")
        BUST B 0 A_Refire("Charge1.b")
        Goto MiniFire
    Charge1.b:
        MARM I 2 ACS_ExecuteAlways(991,0,222)
        MARM H 0 A_GiveInventory("WeaponCharge",1)
        MARM H 0 A_JumpIfInventory("WeaponCharge", 33, "Charge2Start")
        MARM I 0 A_Refire("Charge1.c")
        Goto MiniFire
    Charge1.c:
        MARM J 2 ACS_ExecuteAlways(991,0,223)
        MARM H 0 A_GiveInventory("WeaponCharge",1)
        MARM H 0 A_JumpIfInventory("WeaponCharge", 33, "Charge2Start")
        MARM J 0 A_Refire("Charge1.d")
        Goto MiniFire
    Charge1.d:
        MARM H 2 ACS_ExecuteAlways(991,0,221)
        MARM H 0 A_GiveInventory("WeaponCharge",1)
        MARM H 0 A_JumpIfInventory("WeaponCharge", 33, "Charge2Start")
        MARM H 0 A_Refire("Charge1")
        Goto MiniFire
    Charge2Start:
        MARM H 0 A_GunFlash("Sound.BusterCharge", GFF_NOEXTCHANGE)
        Goto Charge2
    Charge2:
        MARM K 1 ACS_ExecuteAlways(991,0,224)
        MARM K 0 A_Refire("Charge2.a")
        Goto ChargeFire
    Charge2.a:
        MARM L 1 ACS_ExecuteAlways(991,0,225)
        MARM L 0 A_Refire("Charge2.b")
        Goto ChargeFire
    Charge2.b:
        MARM M 1 ACS_ExecuteAlways(991,0,226)
        MARM M 0 A_Refire("Charge2.c")
        Goto ChargeFire
    Charge2.c:
        HSPR C 1 ACS_ExecuteAlways(991,0,0)
        HSPR C 0 A_JumpIfInventory("IsBot", 1, "BotFire")
        HSPR C 0 A_Refire("Charge2")
        Goto ChargeFire
    }
}

actor MegaArmFist
{
    PROJECTILE
    +HITTRACER
    +SKYEXPLODE
    +DONTREFLECT
    Damage (20)
    Speed 55
    height 18
    radius 18
    Scale 3.5
    reactiontime 5
    Obituary "$OB_MEGAARM"
    Damagetype "MegaArm"
    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 0 A_SpawnItemEx("ExplosionEffect1")
        MARM BC 2
        MARM B 0 A_Countdown
        goto Spawn+2
    GripCheck:
        MARM D 0 A_JumpIfInventory("CanBeMegaArmed", 1, "Grip", AAPTR_TRACER)
        MARM D 1 A_JumpIf(true, "GripFail")
        loop
    Grip:
        MARM D 0 A_SpawnItemEx("MegaArmGrip", 0, 0, 0, 0, 0, 0, 0, SXF_TRANSFERPOINTERS)
        stop
    XDeath:
        MARM D 0 A_CheckFlag("SHOOTABLE", "GripCheck", AAPTR_TRACER)
        MARM D 1 A_JumpIf(true, "Death")
        loop
    GripFail:
        MARM C 0
    Death:
        MARM C 0 A_CustomMissile("MegaArmReturn", 0, 0, 0, 0)
        stop
    }
}

actor MegaArmFistRAGE
{
    PROJECTILE
    +HITTRACER
    +SKYEXPLODE
    +DONTREFLECT
    Damage (20)
    Speed 110
    height 18
    radius 18
    Scale 3.5
    reactiontime 5
    Obituary "$OB_MEGAARM"
    Damagetype "MegaArm"
    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 0 A_SpawnItemEx("ExplosionEffect1")
        MARM BC 1
        MARM B 0 A_Countdown
        goto Spawn+2
    GripCheck:
        MARM D 0 A_JumpIfInventory("CanBeMegaArmed", 1, "Grip", AAPTR_TRACER)
        MARM D 1 A_JumpIf(true, "GripFail")
        loop
    Grip:
        MARM D 0 A_SpawnItemEx("MegaArmGripRAGE", 0, 0, 0, 0, 0, 0, 0, SXF_TRANSFERPOINTERS)
        stop
    XDeath:
        MARM D 0 A_CheckFlag("SHOOTABLE", "GripCheck", AAPTR_TRACER)
        MARM D 1 A_JumpIf(true, "Death")
        loop
    GripFail:
        MARM C 0
    Death:
        MARM C 0 A_CustomMissile("MegaArmReturnRAGE", 0, 0, 0, 0)
        stop
    }
}
actor MegaArmGripRAGE
{
    PROJECTILE
    +NOINTERACTION
    Damage (0)
    Speed 50
    height 18
    radius 18
    Scale 3.5
    reactiontime 5
    Obituary "$OB_MEGAARM"
    Damagetype "MegaArm"
    States
    {
    Spawn:
        MARM D 0
        MARM D 0 A_GiveInventory("CutterFlag", 10)
        MARM D 0 A_JumpIfInTargetInventory("LightTeamFlag", 1, "LightTracerCheck")
        MARM D 0 A_JumpIfInTargetInventory("WilyTeamFlag", 1, "WilyTracerCheck")
        MARM D 0 A_JumpIfInTargetInventory("CossackTeamFlag", 1, "CossackTracerCheck")
        MARM D 0 A_JumpIfInTargetInventory("KingTeamFlag", 1, "KingTracerCheck")
        goto Grip
    Grip:
        MARM DDD 1 A_Warp(AAPTR_TRACER, -12, frandom(-1, 1), 32, 180, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION)
        MARM D 0 A_JumpIfCloser(1800, "GripCheckLOS")
        MARM D 0 A_JumpIf(true, "Death")
        loop
    GripCheckLOS:
        MARM D 1 A_JumpIfTargetInLOS("GripCheckTime", 0)
        MARM D 0 A_JumpIf(true, "Death")
        loop
    GripCheckTime:
        MARM D 1 A_JumpIfInventory("CutterFlag", 1, "Tighter")
        MARM D 0 A_JumpIf(true, "Death")
        loop
    Tighter:
        MARM D 0 A_JumpIfInventory("IsDead", 1, "Death", AAPTR_TRACER)
        MARM D 0 A_JumpIfInTargetInventory("IsDead", 1, "Death")
        MARM D 0 A_GiveToTarget("MegaArmWait", 1)
        MARM D 0 A_SpawnItemEx("MegaArmDamage", 12)
        MARM D 0 A_TakeInventory("CutterFlag", 1)
        goto Grip
    Death:
        MARM C 0 A_SpawnItemEx("MegaArmReturnRAGE", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
        stop
    LightTracerCheck:
        MARM C 0 A_JumpIfInventory("LightTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    WilyTracerCheck:
        MARM C 0 A_JumpIfInventory("WilyTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    CossackTracerCheck:
        MARM C 0 A_JumpIfInventory("CossackTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    KingTracerCheck:
        MARM C 0 A_JumpIfInventory("KingTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    }
}


actor MegaArmGrip
{
    PROJECTILE
    +NOINTERACTION
    Damage (0)
    Speed 50
    height 18
    radius 18
    Scale 3.5
    reactiontime 5
    Obituary "$OB_MEGAARM"
    Damagetype "MegaArm"
    States
    {
    Spawn:
        MARM D 0
        MARM D 0 A_GiveInventory("CutterFlag", 10)
        MARM D 0 A_JumpIfInTargetInventory("LightTeamFlag", 1, "LightTracerCheck")
        MARM D 0 A_JumpIfInTargetInventory("WilyTeamFlag", 1, "WilyTracerCheck")
        MARM D 0 A_JumpIfInTargetInventory("CossackTeamFlag", 1, "CossackTracerCheck")
        MARM D 0 A_JumpIfInTargetInventory("KingTeamFlag", 1, "KingTracerCheck")
        goto Grip
    Grip:
        MARM DDDDDD 1 A_Warp(AAPTR_TRACER, -12, frandom(-1, 1), 32, 180, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION)
        MARM D 0 A_JumpIfCloser(1800, "GripCheckLOS")
        MARM D 0 A_JumpIf(true, "Death")
        loop
    GripCheckLOS:
        MARM D 1 A_JumpIfTargetInLOS("GripCheckTime", 0)
        MARM D 0 A_JumpIf(true, "Death")
        loop
    GripCheckTime:
        MARM D 1 A_JumpIfInventory("CutterFlag", 1, "Tighter")
        MARM D 0 A_JumpIf(true, "Death")
        loop
    Tighter:
        MARM D 0 A_JumpIfInventory("IsDead", 1, "Death", AAPTR_TRACER)
        MARM D 0 A_JumpIfInTargetInventory("IsDead", 1, "Death")
        MARM D 0 A_GiveToTarget("MegaArmWait", 1)
        MARM D 0 A_SpawnItemEx("MegaArmDamage", 12)
        MARM D 0 A_TakeInventory("CutterFlag", 1)
        goto Grip
    Death:
        MARM C 0 A_SpawnItemEx("MegaArmReturn", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
        stop
    LightTracerCheck:
        MARM C 0 A_JumpIfInventory("LightTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    WilyTracerCheck:
        MARM C 0 A_JumpIfInventory("WilyTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    CossackTracerCheck:
        MARM C 0 A_JumpIfInventory("CossackTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    KingTracerCheck:
        MARM C 0 A_JumpIfInventory("KingTeamFlag", 1, "Death", AAPTR_TRACER)
        goto Grip
    }
}

actor MegaArmDamage
{
    PROJECTILE
    Damage (6)
    Speed 0
    Height 5
    Radius 5
    Obituary "$OB_MEGAARM"
    Damagetype "MegaArm"
    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 1
        stop
    }
}

actor MegaArmWait : Powerup
{
    powerup.duration 70
}

actor MegaArmHand : MegaArmFist
{
    Damage (45)
	reactiontime 2
    Damagetype "MegaArmHand"
    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 0 A_SpawnItemEx("ExplosionEffect1")
        MARM BC 2
        MARM B 0 A_Countdown
        goto Spawn+2
    XDeath:
        MARM D 0
        goto Death
    }
}

actor MegaArmHandRAGE : MegaArmFistRAGE
{
    Damage (45)
	reactiontime 2
    Damagetype "MegaArmHand"
    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 0 A_SpawnItemEx("ExplosionEffect1")
        MARM BC 2
        MARM B 0 A_Countdown
        goto Spawn+2
    XDeath:
        MARM D 0
        goto Death
    }
}

actor MegaArmReturn
{
    PROJECTILE
    +NOINTERACTION
    +NOCLIP
    +SEEKERMISSILE
    reactiontime 70
    speed 50
    Damage (0)
    height 18
    radius 18
    Scale 3.5
    States 
    {
    Spawn:
        TNT1 A 0
        TNT1 A 0 A_RearrangePointers(AAPTR_DEFAULT, AAPTR_DEFAULT, AAPTR_TARGET)
    SpawnLoop:
        MARM ZZZZ 0 A_SeekerMissile(90, 90, SMF_PRECISE)
        MARM Z 1 A_GiveToTarget("MegaArmWait", 1)
        MARM Z 0 A_Countdown
        MARM Z 0 A_JumpIfCloser(64, "Death")
        loop
    Death:
        MARM Z 0 A_TakeFromTarget("MegaArmWait", 1)
        stop
    }
}


actor MegaArmReturnRAGE
{
    PROJECTILE
    +NOINTERACTION
    +NOCLIP
    +SEEKERMISSILE
    reactiontime 70
    speed 100
    Damage (0)
    height 18
    radius 18
    Scale 3.5
    States 
    {
    Spawn:
        TNT1 A 0
        TNT1 A 0 A_RearrangePointers(AAPTR_DEFAULT, AAPTR_DEFAULT, AAPTR_TARGET)
    SpawnLoop:
        MARM ZZZZ 0 A_SeekerMissile(90, 90, SMF_PRECISE)
        MARM Z 1 A_GiveToTarget("MegaArmWait", 1)
        MARM Z 0 A_Countdown
        MARM Z 0 A_JumpIfCloser(64, "Death")
        loop
    Death:
        MARM Z 0 A_TakeFromTarget("MegaArmWait", 1)
        stop
    }
}
