// Repair gun

// [SG] added FBF_NORANDOM to all repairs and adjusted damage accordingly.
// Repairgun disarms C4's slightly slower, Bomb-squad stays the same

actor RepairGun : AOWWeapon {
    Weapon.BobSpeed 1.75
    Weapon.BobRangeX 0.2
    Weapon.BobRangeY 0.4
    Weapon.BobStyle Alpha
	AttackSound "repairgun/fire"
	DropItem "EngineerPack"
	Weapon.KickBack 0
	Weapon.AmmoUse 0
	Weapon.AmmoGive 0
	Weapon.PreferredSkin "MarineBackpack"
	Weapon.UpSound "weapons/up/repair"
	States {
	Select:
		TNT1 A 0 A_JumpIfInventory ("RepairGunUpgrade", 1, "SelectEnhanced")
		REP1 A 1 offset (90,100)
		REP1 A 1 offset (80,89)
		REP1 A 1 offset (70,79)
		REP1 A 1 offset (60,70)
		REP1 A 1 offset (50,62)
		REP1 A 1 offset (40,55)
		REP1 A 1 offset (30,49)
		REP1 A 1 offset (20,44)
		REP1 A 1 offset (15,40)
		REP1 A 1 offset (10,37)
		REP1 A 1 offset (5,34)
		REP1 A 1 offset (0,0)
		TNT1 A 0 A_TakeInventory("SelectAnimation",1)
		goto ready
	Deselect:
	    TNT1 A 0 A_TakeInventory("ActionFragGrenade",1)	
        TNT1 A 0 A_TakeInventory("ActionFlashbang",1)
        TNT1 A 0 A_TakeInventory("ActionRemoteC4",1)	
        TNT1 A 0 A_TakeInventory("ActionMeleeAttack",1)
		TNT1 A 0 A_TakeInventory("ActionReload",1)	
		REP1 A 0 A_JumpIfInventory ("RepairGunUpgrade", 1, "DeselectEnhanced")
		REP1 A 1 offset (4,34)
		REP1 A 1 offset (8,40)
		REP1 A 1 offset (16,49)
		REP1 A 1 offset (24,62)
		REP1 A 1 offset (32,79)
		REP1 A 1 offset (40,100)
		TNT1 A 0 offset (1, 33)
		TNT1 A 0 A_Lower
		wait
	Ready:
	    TNT1 A 0 A_JumpIfInventory("SelectAnimation",1,"Select")
		TNT1 A 0 A_JumpIfInventory("RepairGunUpgrade", 1, "ReadyEnhanced")
		TNT1 A 0 A_JumpIfInventory("ActionFragGrenade",1,"UseFragGrenade")
		TNT1 A 0 A_JumpIfInventory("ActionFlashbang",1,"UseFlashbang")
		TNT1 A 0 A_JumpIfInventory("ActionRemoteC4",1,"UseRemoteC4")
		TNT1 A 0 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_TakeInventory("ActionReload",1)
		REP1 A 1 A_WeaponReady
		loop
	Fire:
		REP1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready")
		REP1 C 0 A_JumpIfInventory ("RepairGunUpgrade", 1, "FireEnhanced")
		REP1 C 2
		REP1 B 0 bright A_FireBullets (0.2, 0.2, 1, 2, "RepairDisarmPuff", FBF_NORANDOM, 800)
		REP1 B 0 bright ACS_ExecuteAlways (650, 0, 10, 0)
		REP1 B 2 bright ACS_ExecuteAlways (820, 0) // display target health
		REP1 C 2 A_Refire
		Goto Ready
	AltFire:
		REP1 A 0 A_JumpIfInventory("RepairGunUpgrade",1, "Altfire.Enhanced")
		REP1 A 1 A_JumpIfTargetInLOS ("Fire")
		goto ready
	Altfire.Enhanced:
		REP2 A 1 A_JumpIfTargetInLOS ("Fire")
		REP2 A 0
		goto Ready
	ReadyEnhanced:
		TNT1 A 0 A_JumpIfInventory("ActionFragGrenade",1,"UseFragGrenade")
		TNT1 A 0 A_JumpIfInventory("ActionFlashbang",1,"UseFlashbang")
		TNT1 A 0 A_JumpIfInventory("ActionRemoteC4",1,"UseRemoteC4")
		TNT1 A 0 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_TakeInventory("ActionReload",1)
		REP2 A 1 A_WeaponReady
		loop
	DeselectEnhanced:
		REP2 A 1 offset (4,34)
		REP2 A 1 offset (8,40)
		REP2 A 1 offset (16,49)
		REP2 A 1 offset (24,62)
		REP2 A 1 offset (32,79)
		REP2 A 1 offset (40,100)
		TNT1 A 0 offset (1, 33)
		TNT1 A 0 A_Lower
		wait
	SelectEnhanced:
		REP2 A 1 offset (90,100)
		REP2 A 1 offset (80,89)
		REP2 A 1 offset (70,79)
		REP2 A 1 offset (60,70)
		REP2 A 1 offset (50,62)
		REP2 A 1 offset (40,55)
		REP2 A 1 offset (30,49)
		REP2 A 1 offset (20,44)
		REP2 A 1 offset (15,40)
		REP2 A 1 offset (10,37)
		REP2 A 1 offset (5,34)
		REP2 A 1 offset (0,0)
		TNT1 A 0 A_TakeInventory("SelectAnimation",1)
		goto ready
	FireEnhanced:
		REP2 C 1
		REP2 B 0 bright A_FireBullets (0.2, 0.2, 1, 1, "EnhancedRepairDisarmPuff", FBF_NORANDOM, 800)
		REP2 B 0 bright ACS_ExecuteAlways (650, 0, 10, 0)
		REP2 B 1 bright ACS_ExecuteAlways (820, 0)
		REP2 A 2 A_Refire
		Goto Ready
	}
}

actor RepairGunUpgrade : Inventory {}

actor HealGun : RepairGun {
	DropItem "MedicPack"
	Weapon.PreferredSkin "MarineMedic"
	States {
	Spawn:
		TNT1 A 0
		stop
    Select:
		REP4 A 1 offset (90,100)
		REP4 A 1 offset (80,89)
		REP4 A 1 offset (70,79)
		REP4 A 1 offset (60,70)
		REP4 A 1 offset (50,62)
		REP4 A 1 offset (40,55)
		REP4 A 1 offset (30,49)
		REP4 A 1 offset (20,44)
		REP4 A 1 offset (15,40)
		REP4 A 1 offset (10,37)
		REP4 A 1 offset (5,34)
		REP4 A 1 offset (0,0)
		TNT1 A 0 A_TakeInventory("SelectAnimation",1)
		goto ready
	Deselect:
	    TNT1 A 0 A_TakeInventory("ActionFragGrenade",1)	
        TNT1 A 0 A_TakeInventory("ActionFlashbang",1)
        TNT1 A 0 A_TakeInventory("ActionRemoteC4",1)	
        TNT1 A 0 A_TakeInventory("ActionMeleeAttack",1)
		TNT1 A 0 A_TakeInventory("ActionReload",1)	
		REP4 A 1 offset (4,34)
		REP4 A 1 offset (8,40)
		REP4 A 1 offset (16,49)
		REP4 A 1 offset (24,62)
		REP4 A 1 offset (32,79)
		REP4 A 1 offset (40,100)
		TNT1 A 0 offset (1, 33)
		TNT1 A 0 A_Lower
		wait
	Ready:
	    TNT1 A 0 A_JumpIfInventory("SelectAnimation",1,"Select")
        TNT1 A 0 A_JumpIfInventory("ActionFragGrenade",1,"UseFragGrenade")
		TNT1 A 0 A_JumpIfInventory("ActionFlashbang",1,"UseFlashbang")
		TNT1 A 0 A_JumpIfInventory("ActionRemoteC4",1,"UseRemoteC4")
		TNT1 A 0 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_TakeInventory("ActionReload",1)
		REP4 A 1 A_WeaponReady
		loop
	Fire:
		TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready")
		REP4 A 0 A_JumpIfTargetInLOS ("AltFire")
		goto Ready
	AltFire:
		TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready")
		REP4 C 2
		REP4 B 0 bright A_FireBullets (0, 0, 1, 0, "MedicPuff", 0, 800) // visual ONLY
		REP4 B 0 bright ACS_ExecuteAlways (650, 0, 6, 1) // actually does the healing
		REP4 B 2 bright ACS_ExecuteAlways (820, 0) // display target health
		REP4 C 2 A_Refire
		goto Ready
	}
}

actor BombSquadGun : RepairGun {
	+THRUGHOST
	AttackSound "repairgun/fire"
	States {
    Select:
		REP3 A 1 offset (90,100)
		REP3 A 1 offset (80,89)
		REP3 A 1 offset (70,79)
		REP3 A 1 offset (60,70)
		REP3 A 1 offset (50,62)
		REP3 A 1 offset (40,55)
		REP3 A 1 offset (30,49)
		REP3 A 1 offset (20,44)
		REP3 A 1 offset (15,40)
		REP3 A 1 offset (10,37)
		REP3 A 1 offset (5,34)
		REP3 A 1 offset (0,0)
		TNT1 A 0 A_TakeInventory("SelectAnimation",1)
		goto ready
	Deselect:
	    TNT1 A 0 A_TakeInventory("ActionFragGrenade",1)	
        TNT1 A 0 A_TakeInventory("ActionFlashbang",1)
        TNT1 A 0 A_TakeInventory("ActionRemoteC4",1)	
        TNT1 A 0 A_TakeInventory("ActionMeleeAttack",1)
		TNT1 A 0 A_TakeInventory("ActionReload",1)	
		REP3 A 1 offset (4,34)
		REP3 A 1 offset (8,40)
		REP3 A 1 offset (16,49)
		REP3 A 1 offset (24,62)
		REP3 A 1 offset (32,79)
		REP3 A 1 offset (40,100)
		TNT1 A 0 offset (1, 33)
		TNT1 A 0 A_Lower
		wait
	Ready:
	    TNT1 A 0 A_JumpIfInventory("SelectAnimation",1,"Select")
		TNT1 A 0 A_JumpIfInventory("ActionFragGrenade",1,"UseFragGrenade")
		TNT1 A 0 A_JumpIfInventory("ActionFlashbang",1,"UseFlashbang")
		TNT1 A 0 A_JumpIfInventory("ActionRemoteC4",1,"UseRemoteC4")
		TNT1 A 0 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_TakeInventory("ActionReload",1)
		REP3 A 1 A_WeaponReady
		Loop
	Fire:
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "Ready")
		TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready")
		REP3 C 2
		REP3 B 2 bright A_FireBullets (0.0, 0.0, 1, 20, "DisarmPuff", FBF_NORANDOM, 500)
		REP3 C 2 A_Refire
		Goto Ready
	AltFire:
		stop
	}
}

actor RemoverGunHeat : Ammo
{
	Inventory.Maxamount 100
	Inventory.Amount 1
	+IGNORESKILL
}

actor RemoverGun : RepairGun {
	AttackSound "repairgun/fire"
	//Weapon.Ammotype "RemoverGunHeat"
	//+AMMO_OPTIONAL
	States {
    Select:
		REP5 A 1 offset (90,100)
		REP5 A 1 offset (80,89)
		REP5 A 1 offset (70,79)
		REP5 A 1 offset (60,70)
		REP5 A 1 offset (50,62)
		REP5 A 1 offset (40,55)
		REP5 A 1 offset (30,49)
		REP5 A 1 offset (20,44)
		REP5 A 1 offset (15,40)
		REP5 A 1 offset (10,37)
		REP5 A 1 offset (5,34)
		REP5 A 1 offset (0,0)
		TNT1 A 0 A_TakeInventory("SelectAnimation",1)
		goto ready
	Deselect:
	    TNT1 A 0 A_TakeInventory("ActionFragGrenade",1)	
        TNT1 A 0 A_TakeInventory("ActionFlashbang",1)
        TNT1 A 0 A_TakeInventory("ActionRemoteC4",1)	
        TNT1 A 0 A_TakeInventory("ActionMeleeAttack",1)
		TNT1 A 0 A_TakeInventory("ActionReload",1)	
		REP5 A 1 offset (4,34)
		REP5 A 1 offset (8,40)
		REP5 A 1 offset (16,49)
		REP5 A 1 offset (24,62)
		REP5 A 1 offset (32,79)
		REP5 A 1 offset (40,100)
		TNT1 A 0 offset (1, 33)
		TNT1 A 0 A_Lower
		wait
	Ready:
	    TNT1 A 0 A_JumpIfInventory("SelectAnimation",1,"Select")
		TNT1 A 0 A_JumpIfInventory("ActionFragGrenade",1,"UseFragGrenade")
		TNT1 A 0 A_JumpIfInventory("ActionFlashbang",1,"UseFlashbang")
		TNT1 A 0 A_JumpIfInventory("ActionRemoteC4",1,"UseRemoteC4")
		TNT1 A 0 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_TakeInventory("ActionReload",1)
		REP5 A 0 A_TakeInventory("RemoverGunHeat",2)
		REP5 AA 1 A_WeaponReady
		Loop
	Fire:
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "Ready")
		TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready")
		//TNT1 A 0 A_JumpIfInventory ("RemoverGunHeat", 100, "Cool")
		REP5 C 2
		//REP5 B 0 A_GiveInventory("RemoverGunHeat",1)
		REP5 B 2 bright A_FireBullets (0.0, 0.0, 1, 20, "DeconstructionPuff", FBF_NORANDOM, 256)
		REP5 C 2 A_Refire
		Goto Ready
	Cool:
		REP5 A 35 A_PlaySound("Plasma/FailFire")
		TNT1 A 0 A_PlaySound("Plasma/Vapour")
	CoolingLoop:
		REP5 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2 A_TakeInventory("RemoverGunHeat",2)
		Goto Ready
	AltFire:
		TNT1 A 0 A_JumpIfTargetInLOS ("Fire")
		Goto Ready
	}
}

actor DisarmPuff {
	+NOINTERACTION
	+PUFFONACTORS
	+BLOODLESSIMPACT
	+FORCEXYBILLBOARD
	+ALWAYSPUFF
	+THRUGHOST
	+PUFFGETSOWNER
	+NODAMAGETHRUST
	Renderstyle Add
	Alpha 0.5
	Scale 0.25
	DamageType "Disarm"
	States {
	Spawn:
		DPFF A 0
		DPFF A 0 A_Explode (9, 64)
		DPFF ABC 2 bright
	Melee:
		DPFF DE 2 bright
		DPFF F 1 A_FadeOut
		wait
	}
}

actor RepairDisarmPuff : DisarmPuff {
	Alpha 0.66
	States {
	Spawn:
		RPFF A 0
		RPFF A 0 A_Explode (9, 64)
		RPFF ABC 2 bright
	Melee:
		RPFF DE 2 bright
		RPFF F 1 A_FadeOut
		wait
	}
}

actor EnhancedRepairDisarmPuff : DisarmPuff {
	States {
	Spawn:
		UPFF A 0
		UPFF A 0 A_Explode (9, 64)
		UPFF ABC 2 bright
	Melee:
		UPFF DE 2 bright
		UPFF F 1 A_FadeOut
		wait
	}
}

actor MedicPuff : DisarmPuff {
	states {
	Spawn:
		HPFF ABC 2 bright
	Melee:
		HPFF DE 2 bright
		HPFF F 1 A_FadeOut
		wait
	}
}

actor DeconstructionPuff : DisarmPuff {
	DamageType "Deconstruction"
	States {
	Spawn:
		DCPF A 0
		DCPF A 0 A_Explode (64, 8) //[JD] Smaller radius = precise deconstructions
		DCPF ABC 2 bright
	Melee:
		DCPF DE 2 bright
		DCPF F 1 A_FadeOut
		wait
	}
}


actor DisarmTrail {
	+NOINTERACTION
	+CLIENTSIDEONLY
	Scale 0.05
	Alpha 0.5
	RenderStyle add
	states {
	Spawn:
		DPFF ABCDEF 2 bright
		stop
	}
}

actor HealTrail : DisarmTrail {
	States {
	Spawn:
		HPFF ABCDEF 2 bright
		stop
	}
}
actor UpgradedRepairTrail : DisarmTrail {
	States {
	Spawn:
		UPFF ABCDEF 2 bright
		stop
	}
}
actor RepairTrail : DisarmTrail {
	States {
	Spawn:
		PLCX ABCDEF 2 bright
		stop
	}
}