
// FORMER HUMAN CAPTAIN
//
ACTOR RLFormerCaptainPlasmaRifle : RLChaingunguyBase 16614
{
  Health 100
  
  DamageFactor "Bullet", 0.85
  
  Obituary "A Former Human Captain burnt %o into a pile of bloody ashes."
  Tag "Former Captain [Plasma Rifle]"
    //$category "MP Standard"
  
	DropItem "RLFormerCaptainPlasmaRifleDrop"
	// Guncaster compatibility
	DropItem "Dosh25", 192
	DropItem "Dosh35"
  States
  {
  Spawn:
    ZCPR AB Random(9,10) A_Look
    Loop
	
  See:
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "RetreatReload")
    ZCPR AABBCCDD 3 A_Chase ("", "Missile")
    Loop
  RetreatReload:
    TNT1 A 0 A_ChangeFlag ("FRIGHTENED", 1)
    ZCPR AA 3 A_Wander
    TNT1 A 0 A_JumpIfCloser (180, 2)
    TNT1 A 0 A_Jump (24, "Reload")
    ZCPR BB 3 A_Wander
    TNT1 A 0 A_JumpIfCloser (180, 2)
    TNT1 A 0 A_Jump (24, "Reload")
    ZCPR CC 3 A_Wander
    TNT1 A 0 A_JumpIfCloser (180, 2)
    TNT1 A 0 A_Jump (24, "Reload")
    ZCPR DD 3 A_Wander
    TNT1 A 0 A_JumpIfCloser (180, 2)
    TNT1 A 0 A_Jump (24, "Reload")
    TNT1 A 0
    Goto RetreatReload+1
	
  MissileProper:
    ZCPR EE 5 A_FaceTarget
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    TNT1 A 0 A_CheckFlag ("FRIENDLY", "SummonMissile") // Friendly monsters do not harm you
    ZCPR F 2 Bright A_CustomMissile ("RLFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 2 Bright A_CustomMissile ("RLFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 2 Bright A_CustomMissile ("RLFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 2 Bright A_CustomMissile ("RLFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    Goto MissileEnd
  SummonMissile:
    ZCPR F 2 Bright A_CustomMissile ("RLSummonFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 2 Bright A_CustomMissile ("RLSummonFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 2 Bright A_CustomMissile ("RLSummonFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 2 Bright A_CustomMissile ("RLSummonFormerCaptainPlasmaBall", 30, 13, frandom(-1,1), CMF_OFFSETPITCH, frandom(-1,1))
    ZCPR E 1 A_MonsterRefire(30, "MissileEnd")
    Goto MissileEnd
  MissileEnd:
    ZCPR E 9
    Goto See
	
  Reload:
    ZCPR EEEEEE 4 A_FaceTarget
    TNT1 A 0 A_PlaySound("rlmonsters/plasmarifleunload", 7)
    ZCPR E 4 A_FaceTarget
    ZCPR E 5 A_FaceTarget
    TNT1 A 0 A_ChangeFlag ("FRIGHTENED", 0)
    TNT1 A 0 A_PlaySound("rlmonsters/plasmarifleload", 7)
    TNT1 A 0 A_TakeInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40)
    ZCPR EEEEEE 4 A_FaceTarget
    Goto See
	
  PainMain:
    ZCPR G 3
    ZCPR G 3 A_Pain
    Goto See
	
  DeathMain:
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    ZCPR H 5
    ZCPR I 5 A_Scream
    ZCPR J 5 A_NoBlocking
    ZCPR K 5
    TNT1 A 0 A_SpawnItem ("RLBodyThud", 0, 0, 0, 0)
    ZCPR L 0
    "####" "#" 0 A_Jump(256, "DeathEnd")
    Goto DeathEnd
  DeathFrame:
    ZCPR L 0
    "####" "#" 0 A_Jump(256, "DeathEnd")
    Goto DeathEnd
	
  XDeathMain:
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    TNT1 A 0 A_SpawnItemEx ("RLGibber", 0,0,0, VelX,VelY,VelZ, 0, SXF_ABSOLUTEMOMENTUM | SXF_USEBLOODCOLOR | SXF_NOCHECKPOSITION)
    ZCPR M 5
    ZCPR N 5 A_XScream
    ZCPR O 5 A_NoBlocking
    TNT1 A 0 A_SpawnItem ("RLGibThud", 0, 0, 0, 0)
    ZCPR PQRS 5
    ZCPR T 0
    "####" "#" 0 A_Jump(256, "XDeathEnd")
    Goto XDeathEnd
  SimpleXDeathMain:
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    ZCPR M 5
    ZCPR N 5 A_XScream
    ZCPR O 5 A_NoBlocking
    ZCPR PQRS 5
    ZCPR T 0
    "####" "#" 0 A_Jump(256, "XDeathEnd")
    Goto XDeathEnd
	
	//Ice
  GenericFreezeDeath:
	"####" "#" 0 A_GiveInventory ("RLFormerCaptainKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    "####" "#" 0 A_Jump(256, "GenericFreezeMana")
    Goto GenericFreezeMana
		
  Raise:
	TNT1 A 0 ACS_NamedExecuteAlways("DRLA_Normalization") // Removes any palette abnormalities
	TNT1 A 0 A_SetScale(1) // resets altered enemies to default, make sure to match the scale factor in properties here!
    TNT1 A 0 A_ChangeFlag ("NOBLOCKMAP", 0)
    TNT1 A 0 A_ChangeFlag ("NOPAIN", 1)
    ZCPR L 2
    TNT1 A 0 A_JumpIfInventory ("RLNightmareResurrectionToken", 1, "NightmareRaise")
    TNT1 A 0 A_JumpIfInventory ("RLCyberneticResurrectionToken", 1, "CyberneticRaise")
    TNT1 A 0 A_SpawnItemEx ("RLResurrectionFire", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
  RaiseContinue:
    TNT1 A 0 A_JumpIfInventory ("RLCyberneticResurrectionToken", 1, 2)
    TNT1 A 0 A_ChangeFlag ("NOPAIN", 0)
    TNT1 A 0 A_ChangeFlag ("FRIGHTENED", 0)
    TNT1 A 0 A_TakeInventory ("RLFormerCaptainPlasmaRifleShotCounter", 40)
    ZCPR LKJIH 5
    Goto See
  NightmareRaise:
    TNT1 A 0 A_SpawnItemEx ("RLNightmareResurrectionFire", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION) 
    TNT1 A 0 A_ChangeFlag ("ALWAYSFAST", 1)
    Goto RaiseContinue
  CyberneticRaise:
    TNT1 A 0 A_SpawnItemEx ("RLCyberneticResurrectionSparks", 0, 0, 20, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
    TNT1 A 0 A_ChangeFlag ("NOPAIN", 1) 
    TNT1 A 0 A_ChangeFlag ("SEEINVISIBLE", 1)
    TNT1 A 0 A_ChangeFlag ("MISSILEMORE", 1)
    Goto RaiseContinue
	
  CrushDRLA:
    TNT1 A 0 A_SpawnItemEx("RLCrushedSmall",0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
    "####" "#" 0 A_Jump(256, "CrushEnd")
    Goto CrushEnd
//==============================================================================
//					--	DOOMRL ARSENAL STUFF  --
//==============================================================================
  ArsenalMissileCheck:
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "ShadowAuraMissileAttack") // DRPG Shadow Aura
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "LegendaryMissileAttack") // LegenDoom legendary monster
    "####" "#" 0 A_Jump(256, "MissileProper")
	Goto MissileProper
	
  Pain.RigelBlast:
    TNT1 A 0 A_PlaySound("weapons/dn2gunhit", CHAN_BODY)
    D2F1 G 2 Bright
    Goto See
  Pain.NeuralStun:
    D2F1 G 2 Bright
    Goto See
	
  Death.NeuralStun:
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    TNT1 A 0 A_NoBlocking
    TNT1 A 0 A_SpawnItemEx ("RLNeuralStunStars", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER)
    TNT1 A 0 A_Stop
    TNT1 A 0 ThrustThingZ (0, 20, 0, 0)
    CKD1 A -1
    Stop
  Death.RigelBlast:
    TNT1 A 0 A_GiveInventory ("RLDuke2Score", 500, AAPTR_TARGET)
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    TNT1 A 0 A_PlaySound("weapons/dn2gunexplosion", CHAN_BODY)
    TNT1 A 0 A_NoBlocking
    TNT1 A 0 A_SpawnItemEx ("RLDuke2BasicEnemyExplosions", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
    TNT1 A 35
    Stop
  XDeath.RigelBlast:
	TNT1 A 0 A_JumpIf(CallACS("DRLA_Gibs"), 1)
	Goto Death.RigelBlast
    TNT1 A 0 A_GiveInventory ("RLDuke2Score", 500, AAPTR_TARGET)
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    TNT1 A 0 A_PlaySound("weapons/dn2gungib", CHAN_BODY)
    TNT1 A 0 A_NoBlocking
    TNT1 A 0 A_SpawnItemEx ("RLDuke2BasicEnemyExplosions", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
    TNT1 A 0 A_SpawnItemEx ("RLDuke2RedGibber", 0,0,0, VelX,VelY,VelZ, 0, SXF_ABSOLUTEMOMENTUM | SXF_NOCHECKPOSITION)
    TNT1 A 35
    Stop
	
//==============================================================================
//					--	Special Monster Attacks  --
//==============================================================================
  ShadowAuraMissileAttack:
    ZCPR EEE 5 A_FaceTarget
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 80, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 1 Bright A_CustomMissile ("RLFormerCaptainBurstPlasmaBall", 30, 13, 0)
    ZCPR E 1 A_FaceTarget
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 80, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 1 Bright A_CustomMissile ("RLFormerCaptainBurstPlasmaBall", 30, 13, 0)
    ZCPR E 1 A_FaceTarget
    TNT1 A 0 A_JumpIfInventory ("RLFormerCaptainPlasmaRifleShotCounter", 80, "MissileEnd")
    TNT1 A 0 A_GiveInventory ("RLFormerCaptainPlasmaRifleShotCounter", 1)
    TNT1 A 0 A_FaceTarget
    ZCPR F 1 Bright A_CustomMissile ("RLFormerCaptainBurstPlasmaBall", 30, 13, 0)
    ZCPR E 1 A_FaceTarget
    Goto MissileEnd
	
//==============================================================================
//					--	Final Doomer Compatibility Stuff  --
//==============================================================================
  DeathXSparkFrame:
    "####" "#" 0 A_JumpIfInTargetInventory("Mana",0,2)
    "####" "#" 0 A_DropItem("MinorManaPod",-1,54)
    ZCPR G 0
    "####" "#" 0 A_Jump(256, "DeathXSpark")
	Goto DeathXSpark
	
//==============================================================================
//					--	Guncaster Compatibility Stuff  --
//==============================================================================
	MidasFrame1:
		ZCPR G 0 A_SpawnItemEx("Midas_Statue_ChaingunGuy", 0,0,0, 0,0,0, 0,SXF_TRANSFERPOINTERS|SXF_TRANSFERSPRITEFRAME)
		TNT1 A 0 A_JumpIf(1, "DestroyedEnd")
		Goto DestroyedEnd
	MidasFrame2:
		ZCPR G 0 A_SpawnItemEx("Midas_Statue_ChaingunGuy", 0,0,0, frandom(-10.0,-12.0),0,frandom(1.0,3.0), 0,SXF_TRANSFERPOINTERS|SXF_SETMASTER|SXF_TRANSFERSPRITEFRAME)
		TNT1 A 10 A_KillChildren
		TNT1 A 0 A_JumpIf(1, "DestroyedEnd")
		Goto DestroyedEnd
	MidasFrame3:
		ZCPR G 0 A_SpawnItemEx("Midas_Statue_ChaingunGuy", 0,0,0, frandom(-15.0,-20.0),0,frandom(10.0,15.0), 0,SXF_TRANSFERPOINTERS|SXF_SETMASTER|SXF_TRANSFERSPRITEFRAME)
		TNT1 A 10 A_KillChildren
		TNT1 A 0 A_JumpIf(1, "DestroyedEnd")
		Goto DestroyedEnd
		
	//Gumpop
	Death.Acid:
		ZCPR G 1 A_ChangeFlag("SOLID",0)
		"####" "#" 1 A_Playsound("Gumpop/Expand",5)
		"####" "###################################" 1 A_SetScale(ScaleX+frandom(0.01,0.025))
		"####" "#" 1 A_Playsound("Gumpop/Pop",5)
		"####" "#" 0 A_Jump(256,"XDeathMain")
		Goto XDeathMain
		
	//Thunderstruck
	Pain.Lightning:
		"####" "#" 0 A_Jump(164,1)
		Goto Pain
		ZCPR G 0 A_ChangeFlag("NOPAIN",1)
		"####" "#" 0 A_SetUserVar("User_LightningLock", User_LightningLock + 10)
		"####" "#" 0 A_Jump(256,"LightningLock")
		Goto LightningLock
		
	//Cauterizer
	Pain.LightningBlue:
		"####" "#" 0 A_Jump(48,1)
		Goto Pain
		ZCPR G 0 A_ChangeFlag("NOPAIN",1)
		"####" "#" 0 A_SetUserVar("User_LightningLock", User_LightningLock + 10)
		"####" "#" 0 A_Jump(256,"BlueLightningLock")
		Goto BlueLightningLock
  }
}

Actor RLFormerCaptainPlasmaRifleShotCounter : Inventory
{
inventory.maxamount 80
}

ACTOR RLFormerCaptainPlasmaBall : PlasmaBall
{
  +THRUGHOST
  +NOTIMEFREEZE
  +BLOODSPLATTER
  Alpha 0.85
  Decal "PlasmaScorch"
  Damagetype "Plasma"
  Damage (4 * random(1,5))
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 0 A_CheckFlag ("NOTIMEFREEZE", "DoorpegAntiTime", AAPTR_TARGET)
    TNT1 A 0 A_CheckFlag ("NOTIMEFREEZE", "DoorpegTimeRestore", AAPTR_DEFAULT)
    Goto SpawnAura
  DoorpegAntiTime: // If the firing monster has blue aura in DoomRPG, the projectile is not frozen in time.
    TNT1 A 0 A_CheckFlag ("NOTIMEFREEZE", "SpawnAura", AAPTR_DEFAULT)
    TNT1 A 0 A_ChangeFlag ("NOTIMEFREEZE", 1)
    Goto SpawnAura
  DoorpegTimeRestore: // If it suddenly loses the aura, the projectiles will freeze in time in midflight.
    TNT1 A 0 A_ChangeFlag ("NOTIMEFREEZE", 0)
    Goto SpawnAura
  SpawnAura:
    PLSS AB 6 Bright
    Goto Spawn
  Death:
    PLSE ABCDE 4 Bright
    Stop
  }
}

ACTOR RLSummonFormerCaptainPlasmaBall : RLFormerCaptainPlasmaBall
{
  +MTHRUSPECIES
  Damage 5
}

ACTOR RLFormerCaptainBurstPlasmaBall : RLFormerCaptainPlasmaBall
{
  Speed 35
  Damage (8 * random(1,4))
  Scale 1.2
  SeeSound "rlmonsters/burstplasma"
  Decal "PlasmaScorch"
  +NOTIMEFREEZE
  States
  {
  Spawn:
    BPLX AB 2 Bright
    Loop
  Death:
    BPLX CDEFGHI 3 Bright
    Stop
  }
}

ACTOR RLDRPGSummonedFormerCaptain : RLFormerCaptainPlasmaRifle
{
  -COUNTKILL
  +AVOIDMELEE
  +NOBLOCKMONST
  +NOTELESTOMP
  +NOFEAR
  +SEEINVISIBLE
  +DONTDRAIN
  +ALWAYSFAST
  +QUICKTORETALIATE
  +MISSILEMORE
  +THRUSPECIES
  Species "Player"
  States
  {
  Spawn:
	TNT1 A 0 NoDelay ACS_NamedExecuteAlways("MonsterInit", 0)
    TNT1 A 0 A_GiveInventory ("RLMonsterInitializerToken", 1)
    TNT1 A 0 A_GiveInventory ("DRPGDRLASummonedMonsterToken", 1)
	Goto Super::Spawn
	See:
	TNT1 A 0 ACS_NamedExecuteAlways("MonsterInit", 0)
    TNT1 A 0 A_GiveInventory ("RLMonsterInitializerToken", 1)
    TNT1 A 0 A_GiveInventory ("DRPGDRLASummonedMonsterToken", 1)
	Goto Super::See
  Raise:
    Stop
  }
}

ACTOR RLCCFormerCaptainPlasmaRifle : RLFormerCaptainPlasmaRifle
{
  +TOUCHY
  States
  {
  See:
    ZCPR AABBCCDD 3
    Loop
  Missile:
    ZCPR E 10
    ZCPR F 2 Bright
    ZCPR E 1
    ZCPR F 2 Bright
    ZCPR E 1
    ZCPR F 2 Bright
    ZCPR E 1
    ZCPR F 2 Bright
    ZCPR E 10
    Goto See
  Melee:
    Stop
  Death:
    ZCPR H 5
    ZCPR I 5 A_Scream
    ZCPR J 5 A_NoBlocking
    ZCPR K 5
    ZCPR L -1
    Stop
  }
}

//==============================================================================
//							MONSTER'S ITEM POOL

ACTOR RLFormerCaptainPlasmaRifleDrop : RLEnemyWeaponDrop
{
	States
	{
	WeaponDrop: // Drops for DRLA Arsenal + Monsterpack
		TNT1 A 0 A_DropItem("RLPlasmaRiflePickup")
		Stop
	WeaponDropNoArsenal: // Drops for Monsterpack
		TNT1 A 0 A_DropItem("PlasmaRifle")
		Stop
	WeaponDropVanilla: // Drops for Monsterpack if vanilla drops option is enabled
		TNT1 A 0 A_DropItem("Chaingun")
		Stop
	DonutstealDrop: // Drops for Demonsteele
		TNT1 A 0 A_DropItem("Cell")
		Stop
	}
}
