Actor ResBFG1 : Weapon {
	Weapon.SelectionOrder 900
	Weapon.SlotNumber 7
    Inventory.PickupSound "weapons/pickup"
    Inventory.PickupMessage "You got the ion cannon!"	
	Weapon.AmmoType1 "IonAmmo"
	Weapon.AmmoType2 "IonOverheat"
	Weapon.AmmoUse1 1
	Weapon.AmmoGive 36
	Decal "BaronScorch"
	AttackSound ""
	+INVENTORY.UNDROPPABLE
	Tag "Ion Cannon"
	Weapon.BobStyle InverseSmooth
	Weapon.BobSpeed 1.75
	Weapon.BobRangeY 0.5
	Weapon.BobRangeX 0.8
	States {
		Spawn:
			RW04 X -1
		Stop
		Ready:
			RW04 A 1 A_WeaponReady(WRF_NOSWITCH)
		ReadyLoop:
			TNT1 A 0 A_GiveInventory("DnD_OverheatCanReduce", 1)
			TNT1 A 0 ACS_NamedExecuteAlways("DnD Overheat Reduction", 0, DND_OVERHEAT_ION, 2 | (3 << 16))
			RW04 AAAAAAAAA 1 A_WeaponReady
		Loop
		Deselect:
			TNT1 A 0 A_StopSound(7)
			TNT1 A 0 A_TakeInventory("P_RedFire", 1)
			TNT1 A 0 A_TakeInventory("H_WeaponSlot7", 1)
			TNT1 A 0 A_TakeInventory("DnD_UsingEnergy", 1)
		DeselectLoop:
			RW04 A 1 A_Lower
			TNT1 A 0 A_Lower
		Loop
		Select:
			TNT1 A 0 A_GiveInventory("P_RedFire", 1)
			TNT1 A 0 A_GiveInventory("H_WeaponSlot7", 1)
			TNT1 A 0 A_GiveInventory("DnD_UsingEnergy", 1)
			TNT1 A 0 A_TakeInventory("DnD_WeaponID", 0x7FFFFFFF)
			TNT1 A 0 A_GiveInventory("DnD_WeaponID", DND_WEAPON_IONCANNON)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Weapon Damage Cache", 0, DND_DMGID_0, 125)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Weapon Damage Cache", 0, DND_DMGID_1, 64)
	    SelectLoop:
			RW04 A 1 A_Raise
			TNT1 A 0 A_Raise
		Loop
		Fire:
			TNT1 A 0 A_JumpIfInventory("DnD_QuestReward_GodSlayerBonus", 1, "FireCont")
			TNT1 A 0 A_JumpIfInventory("IonCooldown", 1, "NoAction")
			TNT1 A 0 A_JumpIfInventory("IonOverheat", 0, "NoAction")
		FireCont:
			RW04 A 1
			TNT1 A 0 A_TakeInventory("DnD_OverheatCanReduce", 1)
			RW04 B 9 A_PlayWeaponSound("IonCannon/Spin")
			RW04 C 8
			RW04 D 7
			RW04 A 6
			RW04 B 5
			RW04 C 4
			RW04 D 3
			TNT1 A 0 A_PlaySound("IonCannon/SpinLoop", 7, 1.0, 1)
		FireLoop:
			TNT1 A 0 A_JumpIfInventory("IonOverheat", 0, "WindDown4")
			TNT1 A 0 A_JumpIfInventory("IonAttackCount", 3, "Fire4")
			TNT1 A 0 A_JumpIfInventory("IonAttackCount", 2, "Fire3")
			TNT1 A 0 A_JumpIfInventory("IonAttackCount", 1, "Fire2")
			RW04 E 3 Bright A_GiveInventory("IonShooter", 1)
			RW04 F 2 Bright A_GiveInventory("IonShooter", 1)
			RW04 C 2
			TNT1 A 0 A_GiveInventory("IonAttackCount", 1)
			TNT1 A 0 A_Refire("FireLoop")
		Goto WindDown1
		Fire2:
			TNT1 A 0 A_JumpIfInventory("IonOverheat", 0, "WindDown1")
			RW04 H 3 Bright A_GiveInventory("IonShooter", 1)
			RW04 E 2 Bright A_GiveInventory("IonShooter", 1)
			RW04 B 2
			TNT1 A 0 A_GiveInventory("IonAttackCount", 1)
			TNT1 A 0 A_Refire("FireLoop")
		Goto WindDown2
		Fire3:
			TNT1 A 0 A_JumpIfInventory("IonOverheat", 0, "WindDown2")
			RW04 G 3 Bright A_GiveInventory("IonShooter", 1)
			RW04 H 2 Bright A_GiveInventory("IonShooter", 1)
			RW04 A 2
			TNT1 A 0 A_GiveInventory("IonAttackCount", 1)
			TNT1 A 0 A_Refire("FireLoop")
		Goto WindDown3
		Fire4:
			TNT1 A 0 A_JumpIfInventory("IonOverheat", 0, "WindDown3")
			RW04 F 3 Bright A_GiveInventory("IonShooter", 1)
			RW04 G 2 Bright A_GiveInventory("IonShooter", 1)
			RW04 D 2
			TNT1 A 0 A_TakeInventory("IonAttackCount", 0)
			TNT1 A 0 A_Refire("FireLoop")
		Goto WindDown4
		WindDown1:
			TNT1 A 0 A_GiveInventory("IonCooldownGiver", 1)
			TNT1 A 0 A_GiveInventory("DnD_OverheatCanReduce", 1)
			TNT1 A 0 A_StopSound(7)
			TNT1 A 0 A_PlayWeaponSound("IonCannon/Slowdown")
			RW04 D 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 A 4 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 B 5 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 6 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 7 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 A 8 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 B 9 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 10 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 11 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
		Goto Ready
		WindDown2:
			TNT1 A 0 A_GiveInventory("IonCooldownGiver", 1)
			TNT1 A 0 A_GiveInventory("DnD_OverheatCanReduce", 1)
			TNT1 A 0 A_StopSound(7)
			TNT1 A 0 A_PlayWeaponSound("IonCannon/Slowdown")
			RW04 C 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 4 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 A 5 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 B 6 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 7 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 8 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 A 9 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 B 10 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 11 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 12 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
		Goto Ready
		WindDown3:
			TNT1 A 0 A_GiveInventory("IonCooldownGiver", 1)
			TNT1 A 0 A_GiveInventory("DnD_OverheatCanReduce", 1)
			TNT1 A 0 A_StopSound(7)
			TNT1 A 0 A_PlayWeaponSound("IonCannon/Slowdown")
			RW04 B 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 4 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 5 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 A 6 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 B 7 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 8 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 9 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 A 10 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
		Goto Ready
		WindDown4:
			TNT1 A 0 A_GiveInventory("IonCooldownGiver", 1)
			TNT1 A 0 A_GiveInventory("DnD_OverheatCanReduce", 1)
			TNT1 A 0 A_StopSound(7)
			TNT1 A 0 A_PlayWeaponSound("IonCannon/Slowdown")
			RW04 A 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 B 4 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 5 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 6 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 A 7 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 B 8 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 C 9 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
			RW04 D 10 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
		Goto Ready
		NoAction:
			RW04 A 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
			TNT1 A 0 A_TakeInventory("IonOverheat", 2)
		Goto Ready
		Flash:
		  TNT1 A 4 A_Light1
		  TNT1 A 3 A_Light2
		  TNT1 A 0 A_Light0
		  stop
	}
}

Actor IonCooldown : PowerDamage {
	powerup.duration -3
	damagefactor "normal", 1.0
}

Actor IonCooldownGiver : DnD_Activator {
	States {
		Pickup:
			TNT1 A 0 A_JumpIfInventory("IonOverHeat", 0, "Give")
		Stop
		Give:
			TNT1 A 0 A_GiveInventory("IonCooldown", 1)
		Stop
	}
}

Actor IonAttackCount : Inventory {
	inventory.maxamount 3
}

Actor IonShooter : DnD_Activator {
	States {
		Pickup:
			TNT1 A 0 A_PlayWeaponSound("IonCannon/Fire")
			TNT1 A 0 A_GiveInventory("IonOverheat", 2)
			TNT1 A 0 A_SpawnItemEx("GunSmokeSmaller", 18 * cos(-pitch), 0, 36 * (1 + sin(-pitch)), 0, 0, 1)
			TNT1 A 0 A_JumpIfInventory("NetherCheck", 1, "Full")
			TNT1 A 0 A_FireBullets(7.2, 5.6, 1, ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_0, TALENT_ENERGY), "IonPuff", FBF_NORANDOM | FBF_USEAMMO)
		Stop
		Full:
			TNT1 A 0 A_FireBullets(7.2, 5.6, 1, ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_0, TALENT_ENERGY), "IonPuff_FullDMG", FBF_NORANDOM | FBF_USEAMMO)
		Stop
	}
}

Actor IonPuff : BulletPuff {
	DamageType "Energy"
	+PUFFONACTORS
	+PUFFGETSOWNER
	+MTHRUSPECIES
	+FOILINVUL
	+THRUGHOST
	VSpeed 0
	States {
		Spawn:
			TNT1 A 0 NoDelay A_SpawnItem("RedParticleSpawner")
			TNT1 A 0 A_JumpIfInTargetInventory("Ability_ExplosionMastery", 1, "LessDmg")
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_1, TALENT_ENERGY, DND_USETARGET), 160)
			IOPF A 3 bright A_PlaySound("IonCannon/Hit")
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_1, TALENT_ENERGY, DND_USETARGET), 160)
			IOPF BC 3 Bright
			IOPF DEF 2 Bright
		Stop
		LesSDmg:
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_1, TALENT_ENERGY, DND_USETARGET) / 2, 160, 0)
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_1, TALENT_ENERGY, DND_USETARGET) / 2, 160)
			IOPF A 3 bright A_PlaySound("IonCannon/Hit")
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_1, TALENT_ENERGY, DND_USETARGET) / 2, 160, 0)
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_1, TALENT_ENERGY, DND_USETARGET) / 2, 160)
			IOPF BC 3 Bright
			IOPF DEF 2 Bright
		Stop
	}
}

Actor IonPuff_FullDMG : IonPuff {
	DamageType "EnergyFull"
	+FORCERADIUSDMG
}

Actor ResBFG2 : Weapon {
	Weapon.SelectionOrder 900
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 0
	Weapon.AmmoGive2 0
	Weapon.AmmoType "ThunderAmmo"
	Weapon.AmmoType2 "ThunderRangeCounter"
	Inventory.PickupMessage "you got the thunder staff!"
	Weapon.SlotNumber 7
	Tag "Thunder Staff"
	States {
		Spawn:
			APOP A -1
		Stop
		Ready:
			APOF BB 1 Bright A_WeaponReady
			TNT1 A 0 A_PlaySound("ThunderStaff/Loop", 7, 1.0, 1)
			APOF CCDDEE 1 Bright A_WeaponReady
		Loop
		Deselect:
			TNT1 A 0 A_TakeInventory("P_GrayFire", 1)
			TNT1 A 0 A_TakeInventory("H_WeaponSlot7", 1)
		DeselectLoop:
			TNT1 A 0 A_StopSound(7)
			APOF A 1 A_Lower
			TNT1 A 0 A_Lower
		Loop
		Select:
			TNT1 A 0 A_GiveInventory("P_GrayFire", 1)
			TNT1 A 0 A_GiveInventory("H_WeaponSlot7", 1)
			TNT1 A 0 A_TakeInventory("DnD_WeaponID", 0x7FFFFFFF)
			TNT1 A 0 A_GiveInventory("DnD_WeaponID", DND_WEAPON_THUNDERSTAFF)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Weapon Damage Cache", 0, DND_DMGID_0, 50, 5 | (10 << 16))
			TNT1 A 0 ACS_NamedExecuteAlways("DND Weapon Damage Cache", 0, DND_DMGID_1, 100)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Weapon Damage Cache", 0, DND_DMGID_2, 250)
		SelectLoop:
			APOF A 1 A_Raise
			TNT1 A 0 A_Raise
		Loop
		Fire:
			TNT1 A 0 A_JumpIfInventory("ArtemisCheck", 1, "ContinueFire")
			TNT1 A 0 A_JumpIfInventory("ThunderAmmo", 15, "ContinueFire")
		Goto DoNothing
		ContinueFire:
			APOF A 1 A_GiveInventory("ThunderShooter1", 1)
			TNT1 A 0 A_PlayWeaponSound("ThunderStaff/Fire")
			TNT1 A 0 A_SetBlend("LightBlue", 0.25, 18)
			APOF A 1 Offset(0, 36)
			TNT1 A 0 A_Recoil(2.4)
			APOF B 1 Bright Offset(0, 41)
			APOF B 1 Bright Offset(0, 47)
			APOF C 1 Bright Offset(0, 54)
			APOF C 1 Bright Offset(0, 58)
			APOF D 1 Bright Offset(0, 61)
			APOF D 1 Bright Offset(0, 63)
			APOF E 1 Bright Offset(0, 64)
			APOF E 1 Bright Offset(0, 65)
			APOF BCD 2 Bright Offset(0, 66)
			APOF CC 1 Bright Offset(0, 65)
			APOF DD 1 Bright Offset(0, 59)
			APOF B 1 Bright Offset(0, 52)
			APOF B 1 Bright Offset(0, 44)
			APOF C 1 Bright Offset(0, 37)
			APOF C 1 Bright Offset(0, 35)
			APOF D 1 Bright Offset(0, 34)
			APOF D 1 Bright Offset(0, 33)
			APOF BC 2 Bright A_weaponReady(WRF_NOFIRE | WRF_NOSWITCH)
			TNT1 A 0 A_Refire
			APOF D 2 Bright A_weaponReady(WRF_NOFIRE | WRF_NOSWITCH)
			TNT1 A 0 A_Refire
			APOF E 2 Bright A_weaponReady(WRF_NOFIRE | WRF_NOSWITCH)
		Goto Ready
		DoNothing:
			TNT1 A 0 A_JumpIfInventory("ThunderHoldFrames", 2, "DoNothing_3")
			TNT1 A 0 A_JumpIfInventory("ThunderHoldFrames", 1, "DoNothing_2")
			TNT1 A 0 A_GiveInventory("ThunderHoldFrames", 1)
			APOF C 2 Bright A_weaponReady(WRF_NOFIRE | WRF_NOSWITCH)
		Goto Ready
		DoNothing_2:
			TNT1 A 0 A_GiveInventory("ThunderHoldFrames", 1)
			APOF D 2 Bright A_weaponReady(WRF_NOFIRE | WRF_NOSWITCH)
		Goto Ready
		DoNothing_3:
			TNT1 A 0 A_TakeInventory("ThunderHoldFrames", 2)
			APOF B 2 Bright A_weaponReady(WRF_NOFIRE | WRF_NOSWITCH)
		Goto Ready
		AltFire:
			TNT1 A 0 A_JumpIfInventory("ArtemisCheck", 1, "ContinueAltFire")
			TNT1 A 0 A_JumpIfInventory("ThunderAmmo", 25, "ContinueAltFire")
		Goto DoNothing
		ContinueAltFire:
			TNT1 A 0 A_TakeInventory("ThunderStopRing", 1)
			APOF A 1 ACS_NamedExecuteAlways("DND Thunder Ring", 0, 128)
		HoldAlt:
			TNT1 A 0 A_JumpIfInventory("ThunderRangeCounter", 0, "LetGoAlt")
			APOF A 2 A_GiveInventory("ThunderRangeCounter", 1)
			APOF A 1 A_Refire("HoldAlt")
		Goto LetGoAlt
		LetGoAlt:
			TNT1 A 0 A_PlayWeaponSound("ThunderStaff/Alt")
			TNT1 A 0 A_GiveInventory("ThunderStopRing", 1)
			TNT1 A 0 A_SetBlend("Gray", 0.33, 24)
			APOF A 1 Offset(0, 41)
			APOF A 1 Offset(0, 47)
			APOF A 1 Offset(0, 54)
			APOF A 1 Offset(0, 58)
			APOF A 1 Offset(0, 61)
			APOF A 1 Offset(0, 63)
			APOF A 1 Offset(0, 64)
			APOF A 1 Offset(0, 65)
			TNT1 A 0 A_TakeInventory("ThunderStopRing", 1)
			TNT1 A 0 A_GiveInventory("ThunderShooter2", 1)
			TNT1 A 0 A_Quake(6, 17, 0, 384)
			TNT1 A 0 A_JumpIFInventory("NetherCheck", 1, "Full")
			APOF A 1 Offset(0, 65)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Thunderstaff Lightning", 0)
		ContinueAltAnim:
			APOF A 16 A_TakeInventory("ThunderRangeCounter", 0)
			APOF AAA 1 Offset(0, 59)
			APOF AA 1 Offset(0, 52)
			APOF A 1 Offset(0, 44)
			APOF A 1 Offset(0, 37)
			APOF A 1 Offset(0, 35)
			APOF A 1 Offset(0, 34)
			APOF A 1 Offset(0, 33)
			APOF BCD 2 Bright Offset(0, 32) A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
			APOF BCDBCDBCD 2 Bright A_WeaponReady(WRF_NOSECONDARY | WRF_NOSWITCH)
		Goto Ready
		Full:
			APOF A 1
			TNT1 A 0 ACS_NamedExecuteAlways("DND Thunderstaff Lightning", 0, 1)
		Goto ContinueAltAnim
	}
}

Actor ThunderHoldFrames : Inventory {
	inventory.maxamount 2
}

Actor ThunderStopRing : DnD_Boolean { }

Actor ThunderRangeCounter : Ammo {
	inventory.amount 1
	inventory.maxamount 105
	ammo.backpackamount 0
	ammo.backpackmaxamount 105
	+IGNORESKILL
}

Actor ThunderShooter1 : DnD_Activator {
	States {
		Pickup:
			TNT1 A 0 A_JumpIfInventory("ArtemisCheck", 1, "NoTake")
			TNT1 A 0 A_TakeInventory("ThunderAmmo", 15)
		NoTake:
			TNT1 A 0 A_JumpIfInventory("NetherCheck", 1, "Full")
			TNT1 A 0 A_FireCustomMissile("BallLightning", 0, 0)
		Stop
		Full:
			TNT1 A 0 A_FireCustomMissile("BallLightning_FullDMG", 0, 0)
		Stop
	}
}

Actor ThunderShooter2 : DnD_Activator {
	States {
		Pickup:
			TNT1 A 0 A_JumpIfInventory("ArtemisCheck", 1, "NoTake")
			TNT1 A 0 A_TakeInventory("ThunderAmmo", 25)
		NoTake:
			TNT1 A 0 A_RadiusGive("ThunderStrike", ACS_NamedExecuteWithResult("DND Thunder Range"), RGF_MONSTERS, 1)
		Stop
	}
}

Actor ThunderstaffExp1 : BaseExplosionDamage {
	DamageType "Lightning"
	States {
		Spawn:
			TNT1 A 1 NoDelay A_JumpIFInTargetInventory("Ability_ExplosionMastery", 1, "LessDmg")
			TNT1 A 1 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET), 96, 1)
		Stop
		LessDmg:
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET) / 2, 96, 0)
			TNT1 A 1 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET) / 2, 96, 1)
		Stop
	}
}

Actor ThunderstaffExp2 : BaseExplosionDamage {
	DamageType "Lightning"
	States {
		Spawn:
			TNT1 A 1 NoDelay A_JumpIFInTargetInventory("Ability_ExplosionMastery", 1, "LessDmg")
			TNT1 A 1 A_Explode(5 * ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET), 256, 1)
		Stop
		LessDmg:
			TNT1 A 0 A_Explode(5 * ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET) / 2, 256, 0)
			TNT1 A 1 A_Explode(5 * ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET) / 2, 256, 1)
		Stop
	}
}

Actor ThunderstaffExp3 : BaseExplosionDamage {
	DamageType "Lightning"
	+NOCLIP
	+FOILINVUL
	States {
		Spawn:
			TNT1 A 4 NoDelay A_JumpIFInTargetInventory("Ability_ExplosionMastery", 1, "LessDmg")
			TNT1 A 1 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET), 256, 1)
		Stop
		LessDmg:
			TNT1 A 4
			TNT1 A 0 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET) / 2, 256, 0)
			TNT1 A 1 A_Explode(ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_2, TALENT_ELEMENTAL, DND_USETARGET) / 2, 256, 1)
		Stop
	}
}

Actor ThunderstaffExp1_FullDMG : ThunderstaffExp1 {
	DamageType "LightningFull"
	+FORCERADIUSDMG
}

Actor ThunderstaffExp2_FullDMG : ThunderstaffExp2 {
	DamageType "LightningFull"
	+FORCERADIUSDMG
}

Actor ThunderstaffExp3_FullDMG : ThunderstaffExp3 {
	DamageType "LightningFull"
	+FORCERADIUSDMG
}

Actor ThunderTarget : PowerProtection {
	damagefactor "normal", 1.0
	powerup.duration 3
}

Actor ThunderStrike : DnD_Info { }

Actor BallLightning {
	Radius 8
	Height 16
	Speed 10
	Damage (ACS_NamedExecuteWithResult("DND Weapon Damage Retrieve", DND_DMGID_0, TALENT_ELEMENTAL, DND_USETARGET))
	DamageType "Lightning"
	Renderstyle Add
	Scale 0.75
	Decal Scorch
	PROJECTILE
	ReactionTime 10
	+MTHRUSPECIES
	States {
		Spawn:
			TNT1 A 0 A_CountDown
			ZAP7 A 1 Bright A_PlaySoundEx("ThunderStaff/Loop", "SoundSlot7", 1, -1)
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160)
			ZAP7 A 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 B 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			ZAP7 BBB 0 Bright A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160)
			ZAP7 B 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 C 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 A 0 A_RadiusGive("ThunderTarget", 384.0, RGF_MONSTERS, 1)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Thunderstaff Bolts", 0, 0)
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 C 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160)
			ZAP7 D 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 D 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 E 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 E 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 Bright A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			TNT1 A 0 A_RadiusGive("ThunderTarget", 384.0, RGF_MONSTERS, 1)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Thunderstaff Bolts", 0, 0)
		Loop
		Death:
			TNT1 A 0 A_StopSoundEx("SoundSlot7")
			TNT1 A 0 A_PlayWeaponSound("ThunderStaff/Impact")
			TNT1 A 0 A_SpawnItem("ThunderStaffExp1")
			TNT1 AAAAA 0 A_SpawnItemEx("ZapPuff", Random(-16, 16), Random(-16, 16), Random(-16, 16), 0, 0, 0, 0, 160) 
		Fade:
			ZAP7 ABCDE 2 Bright A_FadeOut(0.1)
		Loop
		Submerged:
			TNT1 A 0 A_Stop
			TNT1 A 0 A_StopSoundEx("SoundSlot7")
			TNT1 A 0 A_PlayWeaponSound("ThunderStaff/Impact")
			TNT1 A 0 A_SpawnItem("ThunderstaffExp2")
			TNT1 AAAAA 0 A_SpawnItemEx("ZapPuff", Random(-16, 16), Random(-16, 16), Random(-16, 16), 0, 0, 0, 0, 160)
		Goto Fade
	}
}

Actor BallLightning_FullDMG : BallLightning {
	DamageType "LightningFull"
	States {
		Spawn:
			TNT1 A 0 A_CountDown
			ZAP7 A 1 Bright A_PlaySoundEx("ThunderStaff/Loop", "SoundSlot7", 1, -1)
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160)
			ZAP7 A 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 B 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			ZAP7 BBB 0 Bright A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160)
			ZAP7 A 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 C 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 A 0 A_RadiusGive("ThunderTarget", 384.0, RGF_MONSTERS, 1)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Thunderstaff Bolts", 0, 1)
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 C 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160)
			ZAP7 D 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 D 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 E 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			ZAP7 E 1 Bright A_JumpIf(WaterLevel > 2, "Submerged")
			TNT1 AAA 0 Bright A_SpawnItemEx("SmallZapPuff", 0, Random(-12, 12), Random(-12, 12), 0, 0, 0, 0, 160) 
			TNT1 A 0 A_RadiusGive("ThunderTarget", 384.0, RGF_MONSTERS, 1)
			TNT1 A 0 ACS_NamedExecuteAlways("DND Thunderstaff Bolts", 0, 1)
		Loop
		Death:
			TNT1 A 0 A_StopSoundEx("SoundSlot7")
			TNT1 A 0 A_PlayWeaponSound("ThunderStaff/Impact")
			TNT1 A 0 A_SpawnItem("ThunderStaffExp1_FullDMG")
			TNT1 AAAAA 0 A_SpawnItemEx("ZapPuff", Random(-16, 16), Random(-16, 16), Random(-16, 16), 0, 0, 0, 0, 160) 
			Fade:
			ZAP7 ABCDE 2 Bright A_FadeOut(0.1)
		Loop
		Submerged:
			TNT1 A 0 A_Stop
			TNT1 A 0 A_StopSoundEx("SoundSlot7")
			TNT1 A 0 A_PlayWeaponSound("ThunderStaff/Impact")
			TNT1 A 0 A_SpawnItem("ThunderstaffExp2_FullDMG")
			TNT1 AAAAA 0 A_SpawnItemEx("ZapPuff", Random(-16, 16), Random(-16, 16), Random(-16, 16), 0, 0, 0, 0, 160)
		Goto Fade
	}
}

actor ZapPuff {
	Radius 2
	Height 2
	Renderstyle Add
	DamageType "Lightning"
	+NOINTERACTION
	+CLIENTSIDEONLY
	+PUFFONACTORS
	+ALWAYSPUFF
	States {
		Spawn:
			TNT1 A 1
			TNT1 A 0 A_Jump(256, "Puff1", "Puff2", "Puff3", "Puff4")
		Puff1:
			ZAP1 C 1 Bright A_FadeOut(0.1)
		Loop
		Puff2:
			ZAP1 D 1 Bright A_FadeOut(0.1)
		Loop
		Puff3:
			ZAP1 E 1 Bright A_FadeOut(0.1)
		Loop
		Puff4:
			ZAP1 F 1 Bright A_FadeOut(0.1)
		Loop
	}
}

Actor ZapPuff_FullDMG : ZapPuff {
	DamageType "LightningFull"
}

actor SmallZapPuff : ZapPuff {
	Scale 0.5
	States {
		Spawn:
			TNT1 A 0 NoDelay Thing_ChangeTID(0, SPECIAL_FX_TID)
		Goto Super::Spawn
	}
}

Actor ThunderStaffLightningFX {
	Renderstyle Add
	Alpha 0.01
	xScale 1.25
	YScale 2.5
	Height 1
	Radius 1
	+NOINTERACTION
	+CLIENTSIDEONLY
	States {
		Spawn:
			TNT1 A 0 NoDelay A_PlaySound("ThunderStaff/Thunder")
			TNT1 AAAAAAAA 0 A_SpawnItemEx("RocketSmoke", 0, 0, 0, frandom(-2, 2), frandom(-2, 2), frandom(-2 ,2), 0, SXF_NOCHECKPOSITION)
			TNT1 A 1
			TNT1 A 0 A_Jump(256, "1", "2", "3", "4", "5")
		1:
			ZOT1 A 0
		Goto Vanish
		2:
			ZOT1 B 0
		Goto Vanish
		3:
			ZOT1 C 0
		Goto Vanish
		4:
			ZOT1 D 0
		Goto Vanish
		5:
			ZOT1 E 0
		Goto Vanish
		Vanish:
			"####" "###" 1 Bright A_FadeIn(0.33)
			"####" "#" 1 Bright
		VanishLoop:
			"####" "#" 1 Bright A_FadeOut(0.085)
		Loop
	}
}

Actor ThunderStaffRingAfterFX {
	Scale 0.35
	Renderstyle Add
	Alpha 1.0
	+NOINTERACTION
	+CLIENTSIDEONLY
	States {
		Spawn:
			TNT1 A 0 NoDelay Thing_ChangeTID(0, SPECIAL_FX_TID)
			TNT1 A 2
			ZAP7 AABBCCDDEE 1 A_FadeOut(0.1)
		Stop
	}
}

Actor ThunderStaffRingFX {
	Scale 0.35
	Renderstyle Add
	Alpha 1.0
	Projectile
	Speed 0
	Damage 0
	+THRUACTORS
	+CLIENTSIDEONLY
	+NOCLIP
	States {
		Spawn:
			TNT1 A 2
		SpawnLoop:
			ZAP7 AABBCCDDEE 2 Bright A_SpawnItemEx("ThunderStaffRingAfterFX")
		Loop
		Fade:
			ZAP7 AAABBBCCCDDDEEE 1 Bright A_FadeOut(0.075)
		Stop
	}
}