/*

==CRISSWORD==
A bit of an urothodox weapon, this dagger can rapidly fire
"zaps", bolts of condensed magic energy that can punch holes
through most targets with ease. The CrisSword can also be used
as a melee weapon, its blade bites deeper than the Hero sword's
wooden variant, thoguh its range leaves much to be desired.

The tools that come with the CrisSword offer additional
utility and crowd control, such as bait to lure and distract
enemies, leech fire magic to burn away the life essence of enemies
and convert it into healing magic that the user or their allies can
use! The blade can also project tiny duplicates of the wielder
to fight alongside them.

*/

actor CrisSword : weapon
{
	Weapon.SelectionOrder 200
	Inventory.RestrictedTo "PastLinked"
	weapon.bobstyle smooth
	weapon.bobrangex 0.1
	weapon.bobrangey 0.6
	weapon.bobspeed 2
	Weapon.AmmoUse 1
	Weapon.AmmoType "Clip"
	+WEAPON.AMMO_OPTIONAL
	+noautofire
	+NOAUTOAIM
	Tag "CrisSword"
	states
	{
	select:
		TNT1 A 0
		TNT1 A 0
	draw:
		TNT1 A 0
		HBID AAAAAAAA 0 a_raise
		TNT1 A 1 a_raise
		loop
	Ready:
		CXS1 A 1 a_weaponready
		Loop
	deselect:
		TNT1 A 0
		TNT1 A 0 a_jumpifhealthlower (1, "deadlower")
		TNT1 A 0 a_playsound ("PastLinked/WeaponSwitch",6)
	holster:
        TNT1 AAAAAAAAAAAAAAAAAAAA 0 A_lower
        TNT1 A 1 A_lower
		loop
	deadlower:
		TNT1 A 0
		TNT1 A 0
		TNT1 AAAAAAAAAAAAA 0 a_lower
		TNT1 A 1 a_lower
		wait
	Fire:
		CXS1 BCD 2
		CXS1 E 2
		TNT1 A 0 a_playsound ("Pastlinked/Crissword",0)
		TNT1 A 0 A_FireCustomMissile ("CrisSwordMelee",0,0)
		TNT1 A 0 a_gunflash ("Swordbeam",GFF_NOEXTCHANGE)
		CXS1 F 1
		CXS1 G 1 a_weaponready
		CXS1 H 1 a_weaponready
	Zap1Check:
		TNT1 A 0 
		TNT1 A 0 a_jumpifinventory ("clip",1, "Zap1")
		Goto AttackEnd
	Zap1:
		CXS1 I 1 bright
		TNT1 A 0 A_Quake(1, 2, 0, 20,"silence")
		TNT1 A 0 a_playsound ("PastLinked/Zap",CHAN_WEAPON)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		TNT1 A 0 A_FireCustomMissile ("CrisSwordZap")
		TNT1 A 0 offset (0,38)
		CXS1 J 1 bright
		TNT1 A 0 offset (0,32)
		CXS1 K 1 bright
		CXS1 H 2
		TNT1 A 0 a_refire ("Zap2Check")
		goto Attackend

	Zap2Check:
		TNT1 A 0 
		TNT1 A 0 a_jumpifinventory ("clip",1, "Zap2")
		Goto AttackEnd
	Zap2:
		CXS1 L 1 bright
		TNT1 A 0 A_Quake(1, 2, 0, 20,"silence")
		TNT1 A 0 a_playsound ("PastLinked/Zap",CHAN_WEAPON)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		TNT1 A 0 A_FireCustomMissile ("CrisSwordZap")
		TNT1 A 0 offset (0,38)
		CXS1 M 1 bright
		TNT1 A 0 offset (0,32)
		CXS1 N 1 bright
		CXS1 H 2
		TNT1 A 0 a_refire ("Zap1Check")
		goto Attackend
	AttackEnd:
		TNT1 A 0
		CXS2 ABCDEFG 1 a_weaponready
		goto ready
	
//Weak sword beam stuff (only triggers when ammoless and over 74 hp)
	Swordbeam:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("Clip",1,"NoBeam")
		TNT1 A 0 a_jumpifinventory ("SwordBeamTimer",1,"NoBeam")
		TNT1 A 1 a_jumpifhealthlower (75,"NoBeam")
		TNT1 A 0 a_giveinventory ("SwordBeamTimer",1)
		TNT1 A 0 A_FireCustomMissile ("WeakSwordBeam")
		stop
	NoBeam:
		TNT1 A 0
		TNT1 A 1 
		stop
		
//Altfire stuff		
	Altfire:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("BoomerangActive",1,"BoomerangCheck")
		TNT1 A 0 a_jumpifinventory ("CandleActive",1,"CandleCheck")
		TNT1 A 0 a_jumpifinventory ("BombBagActive",1,"BombCheck")
		CXS1 A 1 a_weaponready
		goto ready

//Bait (Boomerang)
	BoomerangCheck:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("BoomerangCooldown",1, "Ready")
		TNT1 A 0 a_jumpifinventory ("FireBoomerangToken",1, "FireBaitToss")
		TNT1 A 0 a_jumpifinventory ("MagicalBoomerangToken",1, "MagicalBaitToss")
		goto BaitToss
	BaitToss:
		CXS1 BCD 1
		B8TW ABB 2
		B8TW CDEF 2
		B8TW GH 2
		TNT1 A 0 a_playsound ("Pastlinked/Crissword",0)
		TNT1 A 0 a_giveinventory ("BoomerangCoolDown",260)
		TNT1 A 0 ACS_NamedExecuteAlways("BoomerangCharge", 0, 0, 0, 0)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		TNT1 A 0 A_FireCustomMissile ("Bait",0,0)
		B8TW II 1
		B8TW JKLMNOPQR 2
		goto ready
	MagicalBaitToss:
		CXS1 BCD 1
		B8TW ABB 2
		B8T2 CDEF 2
		B8T2 GH 2
		TNT1 A 0 a_playsound ("Pastlinked/Crissword",0)
		TNT1 A 0 a_giveinventory ("BoomerangCoolDown",260)
		TNT1 A 0 ACS_NamedExecuteAlways("BoomerangCharge", 0, 0, 0, 0)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		TNT1 A 0 A_FireCustomMissile ("MagicalBait",0,0)
		B8TW II 1
		B8TW JKLMNOPQR 2
		goto ready
	FireBaitToss:
		CXS1 BCD 1
		B8TW ABB 2
		B8T3 CDEF 2
		B8T3 GH 2
		TNT1 A 0 a_playsound ("Pastlinked/Crissword",0)
		TNT1 A 0 a_giveinventory ("BoomerangCoolDown",260)
		TNT1 A 0 ACS_NamedExecuteAlways("BoomerangCharge", 0, 0, 0, 0)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		TNT1 A 0 A_FireCustomMissile ("FireBait",0,0)
		B8TW II 1
		B8TW JKLMNOPQR 2
		goto ready



//Leech Fire Magic (Candle)
	CandleCheck:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("CandleCooldown",1, "Ready")
		LFPU ABC 1
		LFPU DD 1
		TNT1 A 0 a_playsound ("PastLinked/BombToss",0,0.80)
		TNT1 A 0 A_Quake(2, 3, 0, 20,"silence")
		LFPU E 1
		TNT1 A 0 a_jumpifinventory ("RedCandle",1, "RedLeechFire")
		LCF1 ABC 2
		TNT1 A 0 a_playsound ("PastLinked/CandleReady",0)
		TNT1 A 0 A_Quake(3, 2, 0, 20,"silence")
		LCF1 D 2 bright
		TNT1 A 0 a_playsound ("PastLinked/CrisswordMagic",0)
		TNT1 A 0 offset (0,42)
		LCF1 E 2 bright
		TNT1 A 0 offset (0,43)
		LCF1 F 2 bright
		TNT1 A 0 offset (0,36)
		LCF1 GHI 2 bright
		TNT1 A 0 offset (0,32)
		LCF1 JKLM 1 bright
		LCF1 NOP 2 bright
		LCF1 QR 1 bright
		LCF1 S 1 bright
		TNT1 A 0 A_Quake(2, 7, 0, 20,"silence")
		TNT1 A 0 a_giveinventory ("CandleCoolDown",450)
		TNT1 A 0 ACS_NamedExecuteAlways("CandleCharge", 0, 0, 0, 0)
		TNT1 A 0 a_playsound ("PastLinked/LeechFire",0)
		TNT1 A 0 a_firecustommissile ("BlueLeechFire",0,0,-12)
		TNT1 A 0 a_firecustommissile ("BlueLeechFire")
		TNT1 A 0 a_firecustommissile ("BlueLeechFire",0,0,12)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		LCF1 T 1 bright 
		TNT1 A 0 offset (0,46)
		LCF1 UV 1 bright
		TNT1 A 0 offset (0,40)
		LCF1 WXX 1 bright
		TNT1 A 0 offset (0,36)
		LCF1 YYZZ 1 bright
		TNT1 A 0 offset (0,32)
		LFPU F 2
		goto attackend
	RedLeechFire:
		LCF2 ABC 2
		TNT1 A 0 a_playsound ("PastLinked/CandleReady",0)
		TNT1 A 0 A_Quake(3, 2, 0, 20,"silence")
		LCF2 D 2 bright
		TNT1 A 0 a_playsound ("PastLinked/CrisswordMagic",0)
		TNT1 A 0 offset (0,42)
		LCF2 E 2 bright
		TNT1 A 0 offset (0,43)
		LCF2 F 2 bright
		TNT1 A 0 offset (0,36)
		LCF2 GHI 2 bright
		TNT1 A 0 offset (0,32)
		LCF2 JKLM 1 bright
		LCF2 NOP 2 bright
		LCF2 QR 1 bright
		LCF2 S 1 bright
		TNT1 A 0 A_Quake(2, 7, 0, 20,"silence")
		TNT1 A 0 a_giveinventory ("CandleCoolDown",450)
		TNT1 A 0 ACS_NamedExecuteAlways("CandleCharge", 0, 0, 0, 0)
		TNT1 A 0 a_playsound ("PastLinked/LeechFire",0)
		TNT1 A 0 a_firecustommissile ("RedLeechFire",0,0,-12)
		TNT1 A 0 a_firecustommissile ("RedLeechFire")
		TNT1 A 0 a_firecustommissile ("RedLeechFire",0,0,12)
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		LCF2 T 1 bright 
		TNT1 A 0 offset (0,46)
		LCF2 UV 1 bright
		TNT1 A 0 offset (0,40)
		LCF2 WXX 1 bright
		TNT1 A 0 offset (0,36)
		LCF2 YYZZ 1 bright
		TNT1 A 0 offset (0,32)
		LFPU F 2
		goto attackend


//Dupe magic (Bomb bag)	
	BombCheck:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("RocketAmmo",1, "DupeSpell")
		Goto Ready
	DupeSpell:
		LFPU ABC 1
		LFPU DD 1
		TNT1 A 0 a_playsound ("PastLinked/BombToss",0,0.80)
		TNT1 A 0 A_Quake(2, 3, 0, 20,"silence")
		LFPU E 3
		DPM1 ABC 2
		TNT1 A 0 a_playsound ("PastLinked/BombToss",0,0.40)
		TNT1 A 0 a_playsound ("PastLinked/RupeeGet",0)
		TNT1 A 0 A_Quake(3, 2, 0, 20,"silence")
		DPM1 D 2 bright
		TNT1 A 0 a_playsound ("PastLinked/CrisswordMagic",0)
		TNT1 A 0 offset (0,42)
		DPM1 E 2 bright
		TNT1 A 0 offset (0,43)
		DPM1 F 2 bright
		TNT1 A 0 offset (0,36)
		DPM1 GHI 2 bright
		TNT1 A 0 offset (0,32)
		DPM1 JKLM 2 bright
		DPM1 NOP 1 bright
		DPM1 QR 2 bright
		TNT1 A 0 a_playsound ("PastLinked/DupeMagic",0)
		DPM1 S 2 bright
		TNT1 A 0 A_Quake(2, 7, 0, 20,"silence")
		TNT1 A 0 a_takeinventory ("RocketAmmo",1)
		TNT1 A 0 a_firecustommissile ("DupeSpawner")
		TNT1 A 0 a_firebullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		DPM1 T 1 bright 
		TNT1 A 0 offset (0,46)
		DPM1 UV 1 bright
		TNT1 A 0 offset (0,40)
		DPM1 WXX 1 bright
		TNT1 A 0 offset (0,36)
		DPM1 YYZZ 1 bright
		TNT1 A 0 offset (0,32)
		LFPU F 2
		CXS2 ABCDEFG 1 a_weaponready
		TNT1 A 0 a_refire ("BombCheck")
		goto ready

	}
}


actor CrisSwordZap : fastprojectile
{
	Radius 8
	Height 5
	Speed 200
	Damage (13)
	Projectile
	species "Player"
	+thruspecies
	+bright
	+skyexplode
	renderstyle add
	alpha 0.98
	//SeeSound "PastLinked/SwordBeam"
	scale 0.35
	DamageType "CALinked"
	missiletype "ZapBoltTracer"
    missileheight 8
	Decal CANESDecal
	Obituary "%o was zapped by %k's sword"
	States
	{
	Spawn:
		CZ4P A 2
		TNT1 A 0 a_giveinventory ("ZapDistance",1)
		loop
	Death:
		PLZM H 0
		TNT1 A 0 a_setscale (0.10,0.10)
		CZ4P BCDE 2
		stop
	Xdeath:
		PLZM H 0
		TNT1 A 0 A_PlaySound("PastLinked/ZapHit", CHAN_AUTO,1,0,0.90)
		TNT1 A 0 a_jumpifinventory ("ZapDistance", 10, "HitLv4")
		TNT1 A 0 a_jumpifinventory ("ZapDistance", 6, "HitLv3")
		TNT1 A 0 a_jumpifinventory ("ZapDistance", 2, "HitLv2")
		TNT1 A 0 a_spawnitemex ("ZapBoltSpray",0,0,0,random(-9,9),random(-9,9),random(-5,5),0,SXF_NOCHECKPOSITION)
		CZ4P BCDE 2
		stop
	HitLv2:
		TNT1 A 0 
		TNT1 A 0 a_setscale (0.80,0.80)
		TNT1 AAA 0 a_spawnitemex ("ZapBoltSpray",0,0,0,random(-15,15),random(-15,15),random(-10,10),0,SXF_NOCHECKPOSITION)
		CZ4P BCDE 2
		stop
	HitLv3:
		TNT1 A 0 
		TNT1 A 0 a_fadeout (0.60)
		TNT1 A 0 a_setscale (1.25,1.25)
		TNT1 AAAA 0 a_spawnitemex ("ZapBoltSpray",0,0,0,random(-21,21),random(-21,21),random(-15,15),0,SXF_NOCHECKPOSITION)
		CZ4P BCDE 2
		stop
	HitLv4:
		TNT1 A 0 
		TNT1 A 0 a_fadeout (0.30)
		TNT1 A 0 a_setscale (2.50,2.50)
		TNT1 AAAAAA 0 a_spawnitemex ("ZapBoltSpray",0,0,0,random(-27,27),random(-27,27),random(-20,20),0,SXF_NOCHECKPOSITION)
		CZ4P BCDE 2
		stop
		
	}
}


actor ZapBoltTracer
{
	renderstyle add
	Alpha 0.96
	Scale 0.30
	+NOBLOCKMAP
	+NOGRAVITY
	+NOCLIP
	+DONTSPLASH
	+NOTELEPORT
	+clientsideonly
	+bright
	States
	{
	spawn:
		TNT1 A 0 
		TNT1 A 1 a_checkrange (30,"Flight")
		goto death
	Flight:
		CZ4P A 1
		TNT1 A 0 a_setscale (0.20)
		CZ4P A 1
		TNT1 A 0 a_setscale (0.15)
		CZ4P A 1
		TNT1 A 0 a_setscale (0.10)
		stop
	death:
		TNT1 A 1
		stop
	}
}


actor ZapBoltSpray
{
	renderstyle add
	Alpha 0.96
	projectile
	+thruactors
	speed 10
	+BRIGHT
	+CLIENTSIDEONLY
	scale 0.40
	states
	{
	spawn:	
		RTS2 AA 1 A_SpawnItemEx("ZapBoltSpray2",frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(-1,1),frandom(-1,1),frandom(0,1))
		RTS2 AA 1 A_SpawnItemEx("ZapBoltSpray2",frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(-1,1),frandom(-1,1),frandom(0,1))
		RTS2 AA 1 A_SpawnItemEx("ZapBoltSpray2",frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(-1,1),frandom(-1,1),frandom(0,1))
		RTS2 AA 1 A_SpawnItemEx("ZapBoltSpray2",frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(-1,1),frandom(-1,1),frandom(0,1))
		RTS2 AA 1 A_SpawnItemEx("ZapBoltSpray2",frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(-1,1),frandom(-1,1),frandom(0,1))
		
		TNT1 A 0 a_scalevelocity (0.50)
		RTS2 AA 1 A_SpawnItemEx("ZapBoltSpray2",frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(-1,1),frandom(-1,1),frandom(0,1))
		RTS2 AA 1 A_SpawnItemEx("ZapBoltSpray2",frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(-1,1),frandom(-1,1),frandom(0,1))
		Stop
	}
}

actor ZapBoltSpray2 : ZapBoltSpray
{
	renderstyle add
	Alpha 0.96
	projectile
	+thruactors
	speed 10
	+BRIGHT
	+CLIENTSIDEONLY
	scale 0.20
	states
	{
	spawn:	
		RTS2 AA 6
		goto fadingout
	Fadingout:
		RTS2 A 2
		TNT1 A 0 a_fadeout (0.80)
		loop
	}
}



actor WeakSwordBeam
{
	Radius 13
	Height 8
	Speed 20
	Damage (10)
	Projectile
	species "Player"
	DamageType "CALinked"
	+thruspecies
	+bright
	+skyexplode
	scale 0.25
	Obituary "%o was zapped by %k's sword"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 a_playsound ("PastLinked/WeakZap",6,0.50,0,1.20)
		CZ4P A 12
		TNT1 A 0 a_stop
		goto death
	Death:
		PLZM H 0
		CZ4P BCDE 2
		TNT1 A 1 a_takefromtarget ("SwordBeamTimer",99)
		stop
	Xdeath:
		PLZM H 0
		TNT1 A 0 A_PlaySound("PastLinked/CrisSwordHit", CHAN_AUTO)
		TNT1 A 0 a_takefromtarget ("SwordBeamTimer",99)
		CZ4P BCDE 2
		stop
	}
}



actor CrisSwordMelee : fastprojectile
{
	Projectile
	speed 90
	damage (25)
	obituary "%k proved it was dangerous to go alone to %o."
	+BLOODSPLATTER
	+thruspecies
	+dontblast
	+bright
	DamageType "CALinked"
	species "player"
	height 8
	radius 14
	mass 2000
	projectilekickback 1500
	states
	{
	Spawn:
		TNT1 A 1
		stop
	Death:
		TNT1 A 0
		TNT1 A 1
		TNT1 A 0 A_PlaySound("PastLinked/CrisSwordMiss", CHAN_AUTO)
		TNT1 A 0 A_SpawnDebris("WWStyleBulletSpark")
		TNT1 A 0 radius_quake (1,2,0,8,0)
		TNT1 A 5 
		stop
	Xdeath:
		TNT1 A 0
		TNT1 A 1
		TNT1 A 0 A_PlaySound("PastLinked/CrisSwordHit", 0,1,0,0.60)
		TNT1 A 0 radius_quake (1,4,0,8,0)
		STBE B 1
		STBE B 1 a_setscale (0.30,2)
		STBE B 1 a_setscale (0.80,1)
		STBE B 1 a_setscale (1.60,1.40)
		STBE B 2 a_setscale (0.80,1)
		stop
	}
}


actor ZapDistance : inventory
{inventory.maxamount 10}


