/*
--GENKA-12 PISTOL--
idea supplied by Combine_Kegan
Sprites courtesy of Sgt. Shivers
Clip and casing sprites nicked from Trailblazer, sprites made by DoomNukem
Clip and casing code heavily modified from Pillowblaster's code from Trailblazer


The Genka-12 Semiautomatic Pistol is a Shivers emporium
Manufactured weapon, a stout weapon modelled after the 
UAC's own sidearm, boasting incredible accuracy at the
longest of ranges. The Genka pistol also features a super
rapid burst fire mode, allowing troops to completely 
empty their magazine into a target, doing this causes the 
rounds to fragment and split, effectively doubling the
number of rounds fired, however this is absurdly inaccurate 
and requires the pistol to vent for a brief moment.
This particular model comes witha belt-clipped nanomachic 
generator to supply the user with an infinite supply of reloads, 
this results in the magazines and bullet casings deteroriating 
rather fast though, so don't think you can make a living 
selling the brass casings, you cheap bastard.*/


ACTOR D3PS : Weapon
{
	Weapon.SelectionOrder 60
	Weapon.AmmoUse 1
	weapon.ammouse2 1
	Weapon.AmmoGive2 12
	Weapon.AmmoType "D3PSAmmo"
	Weapon.AmmoType2 "D3PSAmmo"
	Weapon.SlotNumber 2
	Inventory.PickupMessage "You got the Genka-12 semi-automatic pistol!"
	Obituary "%k tapped %o to death."
	+WEAPON.AMMO_OPTIONAL
	+WEAPON.ALT_AMMO_OPTIONAL
	Tag "Genka-12"
	States
	{
	Ready:
		D3PS A 1 A_WeaponReady
		TNT1 A 0 a_giveinventory ("reloadtimer", 1)
		TNT1 A 0 a_jumpifinventory ("reloadtimer", 50, "reloadcheck")
		Loop
	reloadcheck:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("D3PSAmmo",12,"ready")
		D3PS A 1 a_weaponready
		goto quickreload
	Deselect:
		TNT1 A 0
		TNT1 A 0 a_jumpifhealthlower (1, "deadlower")
		TNT1 A 0 a_playsound ("D3pistol/holster", 0)
	holster:
		TNT1 A 0
		D3PS A 1 a_lower
		TNT1 A 0 a_takeinventory ("secretaction", 99)
		TNT1 A 0 a_takeinventory ("reloadtimer", 99)
		TNT1 AAA 0 a_lower
		D3PS A 1 a_lower
		loop
	deadlower:
		TNT1 A 0
		TNT1 A 0
		TNT1 AAAAAAAAAAAAA 0 a_lower
		TNT1 A 1 a_lower
		wait	
	Select:
		TNT1 A 0
		TNT1 A 0 a_playsound ("D3Pistol/draw")
		D3UP AAAAAAAAAA 0 a_raise
		D3UP ABCDEFG 1 
		D3UP G 0 a_playsound ("D3Pistol/Equip")
		D3UP AAAA 0 a_raise
		D3UP HIJKLMN 2 a_weaponready
		goto ready
	Fire:
		D3PS A 0 A_JumpIfInventory("D3PSAmmo",1,"shoot")
		goto quickreload
	shoot:
		TNT1 A 0 a_takeinventory ("reloadtimer", 99)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff")
		D3PS B 0 A_firecustommissile ("genkabullet",0,0)
		D3PS B 0 A_PlaySound ("D3Pistol/Fire")
		D3PS B 1 Bright A_SetPitch(Pitch-0.2)
		D3PS C 0 A_SetPitch(Pitch+0.1)
		D3PS C 1 A_FireCustomMissile("Bulletcasingspawner",0,0,2,6)
		D3PS D 0 A_SetPitch(Pitch+0.1)
		D3PS D 1 
		D3PS E 2 
		Goto Ready
	AltFire:
		TNT1 A 0 a_takeinventory ("reloadtimer", 99)
		TNT1 A 0 A_JumpIfInventory("D3PSAmmo",1,"shootingtime")
		goto quickreload
	shootingtime:
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff")
		D3PS B 0 A_firecustommissile ("genkabulletspray",Frandom(2, -2), 0, 0, 0, 0, Frandom(2, -2))
		D3PS B 0 A_firecustommissile ("genkabulletspray",Frandom(5, -5), 0, -1, 1, 0, Frandom(5, -5))
		D3PS B 0 A_PlaySound ("D3Pistol/Fire")
		D3PS B 1 Bright A_SetPitch(Pitch-0.6)
		D3PS C 0 A_SetPitch(Pitch+0.3)
		D3PS C 0 A_FireCustomMissile("Bulletcasingspawner",0,0,2,6)
		D3PS D 0 A_SetPitch(Pitch+0.3)
		D3PS A 1
		TNT1 A 0 a_jumpifinventory ("D3PSAmmo", 1, "shootingtime")
		D3PS D 2 
		D3PS E 8
	reloadingtime:
		D3PS FGHI 2
		D3PS I 0 A_PlaySound ("D3Pistol/Reload")
		D3PS JKLMNO 2
		TNT1 A 0 A_SpawnItemEx("PistolClipDrop",0,0,20)
		TNT1 A 0 A_GiveInventory("D3PSAmmo", 12)
		D3PS PQRSTUV 2
		D3UP CDEFG 1
		D3UP G 0 a_playsound ("D3Pistol/Equip")
		D3UP HIJKLMN 2
		goto ready
	quickreload:
		D3PS FGHI 2
		D3PS I 0 A_PlaySound ("D3Pistol/Reload")
		D3PS JKLMNO 2
		TNT1 A 0 A_SpawnItemEx("PistolClipDrop",0,0,20)
		TNT1 A 0 A_GiveInventory("D3PSAmmo", 12)
		D3PS PQRSTUV 2
		goto ready
	Spawn:
		D3PS Z -1
		Stop
	}
}

actor genkabullet : fastprojectile
{
	+notimefreeze
	projectile
    +FORCEXYBILLBOARD	
	species "player"
	missiletype "bullettracer"
    missileheight 10
	+thruspecies
	height 4
	radius 4
	speed 300
	damage 2
    Scale 0.2
	Decal bulletchip
	alpha 0.55
	states
	{
	spawn:
		TNT1 A 1
		loop
	death:
		TNT1 A 0
		TNT1 A 1
		PUFF A 0
		PUFF A 3 Bright A_SpawnDebris("WWStyleBulletSpark")
		PUFF B 3 Bright A_SetTranslucent(.75,0)
		PUFF C 3 Bright A_SetTranslucent(.5,0)
		PUFF D 3 Bright A_SetTranslucent(.25,0)
		stop
	xdeath:
		TNT1 A 0
		TNT1 A 0 a_jumpifintargetinventory ("daibatana", 1, "givecharge")
		TNT1 A 1
		stop
	givecharge:
		TNT1 A 0
		TNT1 A 0
		TNT1 A 0 a_giveinventory ("batcharge", 2, AAPTR_TARGET)
		TNT1 A 5 
		stop
	}
}

actor genkabulletspray : genkabullet
{
	speed 80
	states
	{
	xdeath:
		TNT1 A 0
		TNT1 A 0 a_jumpifintargetinventory ("daibatana", 1, "givecharge")
		TNT1 A 1
		stop
	givecharge:
		TNT1 A 0
		TNT1 A 0 a_jump (50, "nothing")
		TNT1 A 0 a_giveinventory ("batcharge", 1, AAPTR_TARGET)
		stop
	nothing:
		TNT1 A 0
		TNT1 A 5 
		stop		
	}
}

ACTOR WWStyleBulletSpark
{
	Health 4
	radius 3
	height 6
	speed .1
	RenderStyle ADD
	Alpha		1
	Scale 0.5
	Mass		0
	+missile
	+doombounce
	+FLOORCLIP
	+DONTSPLASH
	+NOTELEPORT
	+clientsideonly
	States
	{
		PUFF A 1
		PUFF AAA 1  Bright A_SetTranslucent(.8,1)
		PUFF AAAA 1  Bright A_SetTranslucent(.6,1)
		PUFF AAAAAA 1  Bright A_SetTranslucent(.4,1)
		PUFF AAAAAAAA 1 Bright A_SetTranslucent(.2,1)
		Stop
	}
}

actor bullettracer
{
	RenderStyle add
	Alpha 0.95
	Scale 0.7
	+NOBLOCKMAP
	+NOGRAVITY
	+NOCLIP
	+DONTSPLASH
	+NOTELEPORT
	+clientsideonly
	States
	{
	spawn:
		PUFF A 2 
		stop
	death:
		TNT1 A 1
		stop
	}
}


ACTOR D3PSAmmo : Ammo
{
  Inventory.PickupMessage "You shouldn't see this!"
  Inventory.Amount 12
  Inventory.MaxAmount 12
  Ammo.BackpackAmount 12
  Ammo.BackpackMaxAmount 12
  Inventory.Icon "CLIPA0"
  States
  {
  Spawn:
    CLIP A -1
    Stop
  }
}

//CLIPS AND CASING EFFECTS
//Code shamelessly borrowed from Pillowblaster's Trailblazer
//Mod, with permission of course

ACTOR PistolClipDrop
{
	Radius 3
	Height 5
	Speed 0
	Scale 0.2
	PROJECTILE
	-NOGRAVITY
	+BOUNCEONACTORS
	Gravity 0.75
	BounceType Doom
	BounceCount 4
	BounceFactor 0.8
	+clientsideonly
	States
	{
	Spawn:
		CLP1 A 0
		CLP1 ABCDEFGH 1 A_JumpIf(floorz == z, "clipbounce")
		Loop
	clipbounce:
		TNT1 A 0 a_playsound ("Clip/pistol")
		CLP1 A 1 thrustthing (random(1,359),1,0,0)
		goto spawn
	Death:
		TNT1 A 0 a_jump (256, "dead1", "dead2")
		loop
	Dead1:
		TNT1 A 0 a_playsound ("Clip/pistol")
		CLP1 I 50
		CLP1 I 1 a_fadeout (0.01)
		wait
	Dead2:
		TNT1 A 0 a_playsound ("Clip/pistol")
		CLP1 J 50
		CLP1 J 1 a_fadeout (0.01)
		wait
   }
}



//MORE NICKED SHIT

ACTOR BulletCasingSpawner //Shamelessly stolen from probably one of Weasel's mods, yoink. (Then taken by me, double yoink)
{
	Speed 13
	PROJECTILE
	+NOCLIP
	States
	{
	Spawn:
		TNT1 AA 0 A_CustomMissile("BulletCasing",0,0,random(-100,-80),CMF_AIMDIRECTION,random(-15,15))
		Stop
	}
}

ACTOR BulletCasing
{
	Radius 2
	Height 4
	Speed 8
	Scale 0.1
	PROJECTILE
	-NOGRAVITY
	+BOUNCEONACTORS
	+DONTSPLASH
	Gravity 0.75
	BounceType Doom
	BounceCount 6
	BounceFactor 0.6  
	+clientsideonly
	States
	{
	Spawn:
		CAS1 ABCDEFGH 1 bright
		Goto rollingloop
	rollingloop:
		TNT1 A 0 a_playsound ("Casing/Bullet",0,1,0,1.6)
		CAS1 A 0 A_Jump(128,1,3,5,7)
		CAS1 ABCDEFGH 1 bright
		Loop
	Death:
		TNT1 A 0 a_jump (256, "dead1","dead2")
		loop
	dead1:
		TNT1 A 0 a_playsound ("Casing/Bullet",0,1,0,1.6)
		CAS1 I 60 bright
		CAS1 I 1 bright a_fadeout (0.01)
		wait
 	dead2:
		TNT1 A 0 a_playsound ("Casing/Bullet",0,1,0,1.6)
		CAS1 J 60 bright
		CAS1 J 1 bright a_fadeout (0.01)
		wait
  }
}

actor flickpuff : bulletpuff
{
	renderstyle "normal"
	+FORCEXYBILLBOARD	
	+LOOKALLAROUND
	+bloodlessimpact
	+PUFFONACTORS
	states
	{
	spawn:
		TNT1 A 0
		stop
	}
}

actor reloadtimer : inventory
{inventory.maxamount 70}