
// NIGHTMARE DEMON
//
ACTOR RLNightmareDemon : RLDemonBase 16522
{
  Health 300
  GibHealth -80
  
  SeeSound "nightmaredemon/sight"
  ActiveSound "nightmaredemon/active"
  PainSound "nightmaredemon/pain"
  DeathSound "nightmaredemon/death"
  
  Obituary "%o was distorted by a Nightmare Demon."
  Tag "Nightmare Demon"
    //$category "MP Nightmare"
  
	// Guncaster compatibility
	DropItem "Dosh1"
	DropItem "Dosh1"
	DropItem "Dosh1", 128
	DropItem "Dosh25"
  States
  {
  Spawn:
    NDEM AB random(9,10) A_Look
    Goto Spawn
	
  See:
    "####" "#" 0 A_JumpIfCloser (192, "ChaseA")
    NDEM AA 2 Fast A_Chase ("Melee", "")
    "####" "#" 0 A_Jump (192, "SeeB")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    Goto SeeB
  SeeB:
    "####" "#" 0 A_JumpIfCloser (192, "ChaseB")
    NDEM BB 2 Fast A_Chase ("Melee", "")
    "####" "#" 0 A_Jump (192, "SeeC")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    Goto SeeC
  SeeC:
    "####" "#" 0 A_JumpIfCloser (192, "ChaseC")
    NDEM CC 2 Fast A_Chase ("Melee", "")
    "####" "#" 0 A_Jump (192, "SeeD")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    Goto SeeD
  SeeD:
    "####" "#" 0 A_JumpIfCloser (192, "ChaseD")
    NDEM DD 2 Fast A_Chase ("Melee", "")
    "####" "#" 0 A_Jump (192, "See")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    Goto See
  ChaseA:
    NDEM AA 1 A_Chase ("Melee", "")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    TNT1 A 0 A_JumpIfCloser (192, "ChaseB")
    Goto SeeB
  ChaseB:
    NDEM BB 1 A_Chase ("Melee", "")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    TNT1 A 0 A_JumpIfCloser (192, "ChaseC")
    Goto SeeC
  ChaseC:
    NDEM CC 1 A_Chase ("Melee", "")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    TNT1 A 0 A_JumpIfCloser (192, "ChaseD")
    Goto SeeD
  ChaseD:
    NDEM DD 1 A_Chase ("Melee", "")
    "####" "#" 0 A_JumpIfInventory("DRPGShadowAuraToken", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfInventory("LDLegendaryMonsterTransformed", 1, "TeleportNormal")
    "####" "#" 0 A_JumpIfCloser (192, "ChaseA")
    Goto See
	
  TeleportMelee:
    NDEM E 0 A_SpawnItemEx ("RLNightmareDemonTeleportEffect", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERSPRITEFRAME)
	Goto Melee
  MeleeProper:
    TNT1 A 0 A_PlaySound("nightmaredemon/attack", CHAN_VOICE)
    NDEM EF 8 Fast A_FaceTarget
    NDEM G 8 Fast A_CustomMeleeAttack (5 * random(1, 10), "", "", "Melee")
    Goto See
	
  PainMain:
    TNT1 A 0 A_JumpIfInventory ("RLNightmareDemonTeleportToken", 3, 2)
    TNT1 A 0 A_JumpIfCloser (192, "TeleportPain")
    NDEM H 1
    TNT1 A 0 A_TakeInventory ("RLNightmareDemonTeleportToken", 3)
    NDEM H 2 Fast A_Pain
    Goto See
  TeleportPain:
    TNT1 A 0 A_GiveInventory ("RLNightmareDemonTeleportToken", 1)
    NDEM H 0 A_SpawnItemEx ("RLNightmareDemonTeleportEffect", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERSPRITEFRAME)
    TNT1 A 0 A_Pain
    TNT1 AAAAA 0 A_Chase ("TeleportMelee", "", CHF_NOPLAYACTIVE)
    NDEM A 0 A_SpawnItemEx ("RLNightmareDemonTeleportEffect", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERSPRITEFRAME)
    Goto See
	
  TeleportNormal:
    "####" "#" 0 A_SpawnItemEx ("RLNightmareDemonTeleportEffect", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERSPRITEFRAME)
    "####" "#####" 0 A_Chase ("TeleportMelee", "", CHF_NOPLAYACTIVE)
    "####" "#" 0 A_SpawnItemEx ("RLNightmareDemonTeleportEffect", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERSPRITEFRAME)
    Goto See
	
  DeathMain:
    TNT1 A 0 A_GiveInventory ("RLNightmareDemonKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    NDEM I 8
    NDEM J 8 A_Scream
    NDEM K 4
    NDEM L 4 A_NoBlocking
    TNT1 A 0 A_SpawnItem ("RLBodyThud", 0, 0, 0, 0)
    NDEM M 4
    NDEM N 0
    "####" "#" 0 A_Jump(256, "DeathEnd")
    Goto DeathEnd
  DeathFrame:
    NDEM N 0
    "####" "#" 0 A_Jump(256, "DeathEnd")
    Goto DeathEnd
	
  XDeathMain:
    TNT1 A 0 A_GiveInventory ("RLNightmareDemonKillIncrementer", 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)
    NDEM O 4
    NDEM P 4 A_XScream
    NDEM Q 4
    NDEM RS 4 A_NoBlocking
    TNT1 A 0 A_SpawnItem ("RLGibThud", 0, 0, 0, 0)
    NDEM TUV 4
    NDEM W 0
    "####" "#" 0 A_Jump(256, "XDeathEnd")
    Goto XDeathEnd
  SimpleXDeathMain:
    TNT1 A 0 A_GiveInventory ("RLNightmareDemonKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    NDEM O 4
    NDEM P 4 A_XScream
    NDEM Q 4
    NDEM RS 4 A_NoBlocking
    NDEM TUV 4
    NDEM W 0
    "####" "#" 0 A_Jump(256, "XDeathEnd")
    Goto XDeathEnd
	
	//Ice
  GenericFreezeDeath:
	"####" "#" 0 A_GiveInventory ("RLNightmareDemonKillIncrementer", 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)
    NDEM N 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_ChangeFlag ("NOPAIN", 0)
    NDEM NMLKJI 5
    Goto See
  NightmareRaise:
    TNT1 A 0 A_SpawnItemEx ("RLNightmareResurrectionFire", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION) 
    Goto RaiseContinue
  CyberneticRaise:
    TNT1 A 0 A_SpawnItemEx ("RLCyberneticResurrectionSparks", 0, 0, 20, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
    Goto RaiseContinue
	
  CrushDRLA:
    TNT1 A 0 A_SpawnItemEx("RLCrushedMedium",0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
    "####" "#" 0 A_Jump(256, "CrushEnd")
    Goto CrushEnd
//==============================================================================
//					--	DOOMRL ARSENAL STUFF  --
//==============================================================================
  Pain.RigelBlast:
    TNT1 A 0 A_PlaySound("weapons/dn2gunhit", CHAN_BODY)
    D2F2 C 2 Bright
    Goto See
  Pain.NeuralStun:
    D2F2 C 2 Bright
    Goto See
	
  Death.NeuralStun:
    TNT1 A 0
    Goto Death
  Death.RigelBlast:
    TNT1 A 0 A_GiveInventory ("RLDuke2Score", 800, AAPTR_TARGET)
    TNT1 A 0 A_GiveInventory ("RLNightmareDemonKillIncrementer", 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", 800, AAPTR_TARGET)
    TNT1 A 0 A_GiveInventory ("RLNightmareDemonKillIncrementer", 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  --
//==============================================================================
  ShadowAuraMeleeAttack:
    TNT1 A 0 A_PlaySound("nightmaredemon/attack", CHAN_VOICE)
    NDEM EF 3 A_FaceTarget
    NDEM G 3 A_CustomMeleeAttack (3 * random(1, 10), "", "", "Melee")
    Goto See
	
//==============================================================================
//					--	Final Doomer Compatibility Stuff  --
//==============================================================================
  DeathXSparkFrame:
    "####" "#" 0 A_JumpIfInTargetInventory("Mana",0,2)
    "####" "#" 0 A_DropItem("MinorManaPod",-1,54)
    NDEM H 0
    "####" "#" 0 A_Jump(256, "DeathXSpark")
	Goto DeathXSpark
	
//==============================================================================
//					--	Guncaster Compatibility Stuff  --
//==============================================================================
	MidasFrame1:
		NDEM H 0 A_SpawnItemEx("Midas_Statue_Demon", 0,0,0, 0,0,0, 0,SXF_TRANSFERPOINTERS|SXF_TRANSFERSPRITEFRAME)
		TNT1 A 0 A_JumpIf(1, "DestroyedEnd")
		Goto DestroyedEnd
	MidasFrame2:
		NDEM H 0 A_SpawnItemEx("Midas_Statue_Demon", 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:
		NDEM H 0 A_SpawnItemEx("Midas_Statue_Demon", 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:
		NDEM H 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
		NDEM H 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
		NDEM H 0 A_ChangeFlag("NOPAIN",1)
		"####" "#" 0 A_SetUserVar("User_LightningLock", User_LightningLock + 10)
		"####" "#" 0 A_Jump(256,"BlueLightningLock")
		Goto BlueLightningLock
  }
}

Actor RLNightmareDemonTeleportToken : Inventory
{
inventory.maxamount 3
}

ACTOR RLNightmareDemonTeleportEffect
{
  Radius 30
  Height 56
  +NOGRAVITY
  +FLOORCLIP
  +NOLIFTDROP
  +NOTONAUTOMAP
  Alpha 0.8
  RenderStyle Subtract
  States
  {
  Spawn:
    "####" "#" 0
    "####" "#" 0 A_SetScale (ScaleX+0.01)
    "####" "#" 1 A_FadeTo (0, 0.06, 1)
    Loop
  }
}

ACTOR RLNightmareDemonReborn : RLNightmareDemon
{
  +LOOKALLAROUND
  +NOPAIN
  States
  {
  Spawn:
    TNT1 A 0 NoDelay A_JumpIfInventory("RLResurrectionComplete", 1, "SpawnNormal")
    NDEM NMLKJI 5
    TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
    TNT1 A 0 A_GiveInventory("RLResurrectionComplete", 1)
  SpawnNormal:
    NDEM AB 10 A_Look
    Loop
  }
}

ACTOR RLDRPGSummonedNightmareDemon : RLNightmareDemon
{
  -COUNTKILL
  +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 RLCCNightmareDemon : RLNightmareDemon
{
  +TOUCHY
  States
  {
  Spawn:
    NDEM AB 10
    Loop
  See:
    NDEM AABBCCDD 2
    Loop
  Missile:
    Stop
  Melee:
    NDEM EF 8
    NDEM G 8
    Goto See
  Death:
    NDEM I 8
    NDEM J 8 A_Scream
    NDEM K 4
    NDEM L 4 A_NoBlocking
    NDEM M 4
    NDEM N -1
    Stop
  }
}
