// LCA 1.6.0
ACTOR "Legendary AK-47" : Weapon 16602
{
//$Category Weapons/LCA
//$Sprite A47IA0
//$Title "Legendary AK-47"
	Weapon.PreferredSkin "LegendaryAK47-Marine"
	Weapon.AmmoType "LAK47Magazine"
	Weapon.AmmoType2 "LegendaryBulletMag"
	Weapon.SelectionOrder 380
	Weapon.KickBack 120
	Weapon.AmmoGive 31
	Weapon.AmmoGive2 20
	Weapon.AmmoUse 1
	Scale 0.95
	Inventory.PickupSound "items/legAK47Reload3"
	Obituary "%o was perforated by %k's Legendary AK-47."
    Inventory.PickupMessage "Legendary AK-47"
	Decal LegBulletChip
	+WEAPON.AMMO_OPTIONAL
    +WEAPON.NOALERT
	+INVENTORY.UNDROPPABLE
	States 
	{
    Deselect:
		TNT1 A 0 A_PlayWeaponSound("weapons/weapondown")
		A47G A 1 A_Lower
		Goto Deselect+1
	Select:
		TNT1 A 0 A_Raise
		Wait
	Ready:
		TNT1 A 0 A_PlayWeaponSound("weapons/legAK47Select")
		A47S ABCDEF 1
		TNT1 A 0 A_JumpIfInventory("HandGrenadeAction",1,"GrenadeCheck")
		TNT1 A 0 A_JumpIfInventory("MineAction",1,"MineCheck")
		A47G A 1 A_WeaponReady
		Goto Ready+7
	Fire:
	    TNT1 A 0 A_JumpIfNoAmmo("Empty")	
	    TNT1 A 0 A_PlaySound("weapons/legAK47Fire")
	    TNT1 A 0 A_AlertMonsters	
		TNT1 A 0 A_GunFlash
		TNT1 A 0 Radius_Quake(1,2,0,1,0)
	    TNT1 A 0 A_SpawnItemEx("LegRifleCasing",30,3,25,Random(2,4),Random(3,6),Random(3,6),0)
		TNT1 A 0 A_Light1
		TNT1 A 0 A_ZoomFactor(0.99)
		// A47F A 1 Bright A_FireBullets(4.0,2.4,1,Random(30,50),"LegendaryASGBulletPuff")
		A47F A 1 Bright A_FireCustomMissile("48-62Bullet", frandom(-4.0, 4.0), true, 0, 8, false, frandom(-2.4, 2.4))
		A47F B 1 Bright
		TNT1 A 0 A_Light0
		TNT1 A 0 A_Recoil(0.1)
		A47F CD 1
		TNT1 A 0 A_ZoomFactor(1.0)
	    TNT1 A 0 A_JumpIfInventory("LAK47Magazine",1,1)
		Goto Ready+7
	    TNT1 A 0 A_PlaySound("weapons/legAK47Fire")
	    TNT1 A 0 A_AlertMonsters	
		TNT1 A 0 A_GunFlash
		TNT1 A 0 Radius_Quake(1,2,0,1,0)
	    TNT1 A 0 A_SpawnItemEx("LegRifleCasing",30,3,25,Random(2,4),Random(3,6),Random(3,6),0)
		TNT1 A 0 A_Light2
		// A47F A 1 Bright A_FireBullets(4.0,2.4,1,Random(30,50),"LegendaryASGBulletPuff")
		A47F A 1 Bright A_FireCustomMissile("48-62Bullet", frandom(-4.0, 4.0), true, 0, 8, false, frandom(-2.4, 2.4))
		A47F B 1 Bright
		TNT1 A 0 A_Light0
		TNT1 A 0 A_Recoil(0.1)
		A47F CD 1
		TNT1 A 0 A_ReFire
		Goto Ready+7
	Flash:
		TNT1 A 0
		Goto LightDone
    Empty:
        A47G A 10 A_PlayWeaponSound("weapons/click")
    AltFire:
  	    TNT1 A 0 A_JumpIfInventory("LAK47Magazine",31,2)
        TNT1 A 0 A_JumpIfInventory("LegendaryBulletMag",1,2)
		TNT1 A 0
		Goto Ready+7
		TNT1 A 0 A_JumpIfInventory("LAK47Magazine",1,"MaxReload")
	    A47R A 1 A_PlayWeaponSound("weapons/legAK47Reload1")
 	    A47R BCD 1
	    A47R E 1 A_FireCustomMissile("LegAK47EmptyMagSpawner", 0, 0, 0, 1)
	    A47R F 1
		A47R G 8
		A47R HIJK 1
	    A47R L 8 A_PlayWeaponSound("weapons/legAK47Reload2")
		A47R MN 2 
		A47R OP 1
		A47R T 1 A_PlayWeaponSound("weapons/legAK47Reload3")
		A47R U 3
		A47R V 4 
		A47R W 3
		A47R XY 2
		TNT1 A 0 A_JumpIfInventory("LegendaryBulletMag",1,"Reload")
    Reload:
	    TNT1 A 0 A_TakeInventory("LegendaryBulletMag",1)
	    TNT1 A 0 A_GiveInventory("LAK47Magazine",1)
	    TNT1 A 0 A_JumpIfInventory("LAK47Magazine",30,2)
	    TNT1 A 0 A_JumpIfInventory("LegendaryBulletMag",1,"Reload")
		TNT1 A 0
		Goto Ready+7
	MaxReload:
	    A47R A 1 A_PlayWeaponSound("weapons/arreload")
 	    A47R BCD 1
	    A47R E 1 A_FireCustomMissile("LegAK47EmptyMagSpawner", 0, 0, 0, 1)
	    A47R F 1
		A47R G 8
		A47R HIJK 1
	    TNT1 A 0 A_JumpIfInventory("LegendaryBulletMag",1,"Reload2")
    Reload2:
	    TNT1 A 0 A_TakeInventory("LegendaryBulletMag",1)
	    TNT1 A 0 A_GiveInventory("LAK47Magazine",1)
	    TNT1 A 0 A_JumpIfInventory("LAK47Magazine",31,"Full")
	    TNT1 A 0 A_JumpIfInventory("LegendaryBulletMag",1,"Reload2")
    Full:
	    A47R L 8 A_PlayWeaponSound("weapons/legAK47Reload2")
		A47R MN 2 
		A47R OPQRS 1
	    A47G A 2
	    Goto Ready+7
    GrenadeCheck:
	    TNT1 A 0 A_JumpIfInventory("HandGrenadeAmmo",1,"GrenadeToss")
		TNT1 A 0 A_TakeInventory("HandGrenadeAction",1)
	    Goto Ready+7
    GrenadeToss:
  	    TNT1 A 0 A_PlayWeaponSound("weapons/weapondown") 
	    A47S FEDCBA 1
	    TNT1 A 4
		HGRN ABC 1
		HGRN D 2
		HGRN EFG 1
		HGRN HI 2
		TNT1 A 15 A_PlayWeaponSound("weapons/hgrenadepin")
		TNT1 A 0 A_PlayWeaponSound("weapons/hgrenadethrow")
		TNT1 A 0 A_TakeInventory("HandGrenadeAmmo",1)
		HGNE A 1 A_FireCustomMissile("ThrownGrenade",0,0,0,0)
		HGRN J 1
		HGRN KLM 2
		HGRN NO 1
		TNT1 A 6
		TNT1 A 0 A_JumpIfInventory("HandGrenadeAmmo",1,2)
		TNT1 A 0 A_TakeInventory("Hand Grenade",1)
		TNT1 A 0 A_TakeInventory("HandGrenadeAction",1)
		TNT1 A 0
		Goto Ready+1
    MineCheck:
		TNT1 A 0 A_JumpIfInventory("MineAmmo",1,"MineToss")
		TNT1 A 0 A_TakeInventory("MineAction",1)
		Goto Ready+7
    MineToss:
  	    TNT1 A 0 A_PlayWeaponSound("weapons/weapondown") 
	    CGNR FEDCBA 1
		TNT1 A 8
		TNT1 A 0 A_PlayWeaponSound("weapons/hgrenadethrow")
		MINE ABCDEF 1		
		TNT1 A 0 A_TakeInventory("MineAmmo",1)	  
		MINE G 1 A_FireCustomMissile("ThrownMine",0,0,0,0)
		MINE HI 1
		MINE JK 2
		TNT1 A 0 A_JumpIfInventory("MineAmmo",1,2)
		TNT1 A 0 A_TakeInventory("Land Mine",1)
		TNT1 A 0 A_TakeInventory("MineAction",1)
		TNT1 A 0
		TNT1 A 5
		Goto Ready+1
	Spawn:
		A47I A -1
		Stop		
	}
}

ACTOR LAK47Magazine : Ammo 
{
	Inventory.Amount 0
	Inventory.MaxAmount 31
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 31
	Inventory.Icon "A47IA0"
	+IGNORESKILL
}

ACTOR LegendaryBulletMag : Ammo 16803
{
//$Category Ammunition/LCA
//$Sprite LBLPA0
//$Title "Legendary Bullet Magazine"
	Scale 0.3
	Inventory.PickupMessage "Legendary Bullets"
	Inventory.PickupSound "items/clipbox"
	Inventory.Amount 10
	Inventory.MaxAmount 150
	Ammo.BackpackAmount 30
	Ammo.BackpackMaxAmount 300
	Inventory.Icon "LBLPA0"
	+NOTIMEFREEZE
	States 
	{
	Spawn:
		LBLP A -1
		Stop
    }
}

ACTOR "48-62Bullet" : FastProjectile {
    Scale 0.1
    Height 1
    Radius 1
    Damage (random(98,100)*random(1,3))
    Speed 400
    Projectile
    Renderstyle ADD
    Species "Player"
    +FORCEXYBILLBOARD
    +DONTSPLASH
    +BloodSplatter
    +THRUSPECIES
    +NOTIMEFREEZE
    Decal LegBulletChip
    DamageType "Legendary"
    States {
    Spawn:
        TRAC A 1 BRIGHT
        Loop
    Death:
        PUFF A 0 A_SpawnItemEx("LegendaryASGBulletPuff")
        PUFF ABCD 4
        Stop
    XDeath:
        TNT1 A 0
        Stop
    }
}

ACTOR LegRifleCasing : BulletCasing 
{
	Scale 0.18
	Seesound "weapons/casing1"
	+NOTIMEFREEZE
	States 
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(304) == 1, "Toaster")
		CAS9 GHABCDEF 2
		Loop
    Death:
		TNT1 A 0
		TNT1 A 0 A_Jump(128,3)
		CAS9 A 100
		CAS9 A 5 A_FadeOut(0.10)
		Goto Death+3
		CAS9 E 100
		CAS9 E 5 A_FadeOut(0.10)
		Goto Death+5
	}
}
ACTOR LegAK47EmptyMagSpawner : CasingSpawner 
{
	+NOTIMEFREEZE
	States 
	{
	Spawn:
		TNT1 A 0
		TNT1 A 1 A_SpawnItemEx("LegAK47EmptyMag", 2, 0, -12, 1, 0, 0, Random(-100, -110), 128)
		Stop
    }
}

ACTOR LegAK47EmptyMag : BulletCasing 
{
	Scale 0.40
    SeeSound "MP40/EmptyMagazine"
	+NOTIMEFREEZE
    States 
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(304) == 1, "Toaster")
		LA4C ABCD 3  
		Loop
    Death:
		TNT1 A 0
		TNT1 A 0 A_Jump(128,3)
		LA4C B 100
		LA4C B 5 A_FadeOut(0.10)
		Goto Death+3
		LA4C D 100
		LA4C D 5 A_FadeOut(0.10)
		Goto Death+5
	}
}