
// LOST SOUL
//
ACTOR RLLostSoul : RLLostSoulBase 16407
{
  Health 25
  
  MinMissileChance 300
  
  DamageFactor "Bullet", 0.5
  DamageFactor "Fire", 0.25
  DamageFactor "Ice", 1.25
  
  +BRIGHT
  -NOINFIGHTING
  
  AttackSound "skull/melee"
  
  DamageType "Melee"
  PainType "BluntMelee"
  DeathType "BluntMelee"
  
  Obituary "%o was struck by a Lost Soul."
  Tag "Lost Soul"
    //$category "MP Standard"
  
	// Guncaster compatibility
	DropItem "Dosh1"
	DropItem "Dosh1"
	DropItem "Dosh1", 128
	DropItem "Dosh1", 192
	DropItem "Dosh5", 64
	DropItem "Dosh5", 192
	DropItem "SkullfireBringer", 1 //lel.
  States
  {
  Spawn:
    LSOL AB Random(5,6) Bright A_Look
    Loop
	
  See:
    TNT1 A 0 A_CheckFlag ("FRIENDLY", 2) // Friendly monsters do not use commands
    TNT1 A 0 A_JumpIfInventory("PowerRLNightmareSoulCommand", 1, "CommandMissile")
    LSOL A 3 Bright A_Chase ("", "Missile")
    TNT1 A 0 A_CheckFlag ("FRIENDLY", 2) // Friendly monsters do not use commands
    TNT1 A 0 A_JumpIfInventory("PowerRLNightmareSoulCommand", 1, "CommandMissile")
    LSOL B 3 Bright A_Chase ("", "Missile")
    Loop
	
  MissileProper:
    LSOL C 10 Bright A_FaceTarget
    LSOL D 4 Bright A_SkullAttack
	Goto MissileLoop
  MissileLoop:
    LSOL CD 4 Bright
//    TNT1 A 0 A_JumpIf(Abs(VelX) <= 0.01 || Abs(VelY) <= 0.01 || Abs(VelZ) <= 0.01, "See") // original broken code, hue
	TNT1 A 0 A_JumpIf(CallACS("DRLA_GetMoving") == 0, "MissileFail")
    Goto MissileLoop
  MissileFail:
    TNT1 A 0 A_ChangeFlag ("SKULLFLY", 0)
    TNT1 A 0 A_Stop
    Goto See
	
  CommandMissile:
    TNT1 A 0 A_JumpIfInventory("PowerRLNightmareSoulCommand", 1, 1)
    Goto CommandMissile1
    LSOL C 1 Bright A_FaceTarget
    Goto CommandMissile
  CommandMissile1:
    TNT1 A 0 A_FaceTarget
    TNT1 A 0 A_Jump(128, 2)
    TNT1 A 0 A_PlaySound("skull/melee", CHAN_VOICE)
	TNT1 A 0 A_SkullAttack
    LSOL DDDD 1 Bright A_FaceTarget
    Goto MissileLoop
	
  PainMain:
    LSOL E 3 Bright
    LSOL E 3 Bright A_Pain
    Goto See

  //Fire
  // Lost Souls are immune to being ignited as they are already one with the fireforce
  Pain.Meteorfist:
	"####" "#" 0 A_FaceTarget
	"####" "#" 0 A_ChangeVelocity(frandom(-13.0,-17.0),0,frandom(9.0,11.0),CVF_RELATIVE)
	"####" "#" 0 A_Jump(256,"Pain")
	Goto Pain
  Pain.Fire:
	"####" "#" 0 A_Jump(256,"Pain")
	Goto Pain
	
  DeathMain:
    TNT1 A 0 A_GiveInventory ("RLLostSoulKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    TNT1 A 0 A_RadiusGive("RLAgonyElementalCounterAttack", 128, RGF_MONSTERS, 1)
    LSOL F 6 Bright
    LSOL G 6 Bright A_Scream
    LSOL H 6 Bright
    LSOL I 6 Bright A_NoBlocking
    LSOL J 6
    LSOL K 6
	TNT1 A 0
    "####" "#" 0 A_Jump(256, "DestroyedEnd")
    Goto DestroyedEnd
  DeathFrame:
    TNT1 A 0
    "####" "#" 0 A_Jump(256, "DestroyedEnd")
    Goto DestroyedEnd
	
  //Fire
  Death.Meteorfist:
	"####" "#" 0 A_FaceTarget
	"####" "#" 0 A_ChangeVelocity(frandom(-15.0,-20.0),0,frandom(10.0,15.0),CVF_RELATIVE)
	"####" "#" 0 A_Jump(256,"Death")
	Goto Death
  Death.Lightning:
  Death.LightningBlue:
  Death.Fire:
	"####" "#" 0 A_Jump(256,"Death")
	Goto Death
	
	//Ice
  GenericFreezeDeath:
	"####" "#" 0 A_GiveInventory ("RLLostSoulKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    "####" "#" 0 A_Jump(256, "GenericFreezeMana")
    Goto GenericFreezeMana
//==============================================================================
//					--	DOOMRL ARSENAL STUFF  --
//==============================================================================
  Pain.NeuralStun:
    D2F1 J 2 Bright
    Goto See
  Pain.RigelBlast:
    TNT1 A 0 A_PlaySound("weapons/dn2gunhit", CHAN_BODY)
    D2F1 J 2 Bright
    Goto See
	
  Death.RigelBlast:
    TNT1 A 0 A_GiveInventory ("RLLostSoulKillIncrementer", 1, AAPTR_PLAYER1) // Used for tallying total kills and bestiary info
    TNT1 A 0 A_RadiusGive("RLAgonyElementalCounterAttack", 128, RGF_MONSTERS, 1)
    TNT1 A 0 A_PlaySound("weapons/dn2gunexplosion", CHAN_BODY)
    TNT1 A 0 A_NoBlocking
    TNT1 A 0 A_SpawnItemEx ("RLDuke2MediumExplosion", 0,0,16, 0,0,0, 0, SXF_NOCHECKPOSITION)
    TNT1 A 35
    Stop
	
//==============================================================================
//					--	Special Monster Attacks  --
//==============================================================================
  ShadowAuraMissileAttack:
    LSOL CD 4 Bright A_SkullAttack
	TNT1 A 0 A_JumpIf(CallACS("DRLA_GetMoving") == 0, "See")
    Goto ShadowAuraMissileAttack
	
//==============================================================================
//					--	Final Doomer Compatibility Stuff  --
//==============================================================================
  DeathXSparkFrame:
    "####" "#" 0 A_JumpIfInTargetInventory("Mana",0,2)
    "####" "#" 0 A_DropItem("MinorManaPod",-1,54)
    LSOL E 0
    "####" "#" 0 A_Jump(256, "DeathXSpark")
	Goto DeathXSpark
	
//==============================================================================
//					--	Guncaster Compatibility Stuff  --
//==============================================================================
	MidasFrame1:
		LSOL E 0 A_SpawnItemEx("Midas_Statue_LostSoul", 0,0,0, 0,0,0, 0,SXF_TRANSFERPOINTERS|SXF_TRANSFERSPRITEFRAME)
		TNT1 A 0 A_JumpIf(1, "DestroyedEnd")
		Goto DestroyedEnd
	MidasFrame2:
		LSOL E 0 A_SpawnItemEx("Midas_Statue_LostSoul", 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:
		LSOL E 0 A_SpawnItemEx("Midas_Statue_LostSoul", 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:
		LSOL E 1 Bright A_ChangeFlag("SOLID",0)
		"####" "#" 1 Bright A_Playsound("Gumpop/Expand",5)
		"####" "###################################" 1 Bright A_SetScale(ScaleX+frandom(0.01,0.025))
		"####" "#" 1 Bright A_Playsound("Gumpop/Pop",5)
		"####" "#" 0 A_Jump(256,"XDeathMain")
		Goto XDeathMain
		
	//Thunderstruck
	Pain.Lightning:
		"####" "#" 0 A_Jump(164,1)
		Goto Pain
		LSOL E 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
		LSOL E 0 A_ChangeFlag("NOPAIN",1)
		"####" "#" 0 A_SetUserVar("User_LightningLock", User_LightningLock + 10)
		"####" "#" 0 A_Jump(256,"BlueLightningLock")
		Goto BlueLightningLock
		
		// Overwrite these for monsters that do not leave corpses behind
	//Dreadful
	Death.Tiberium:
		"####" "#" 0 A_Jump(256, "Death")
		Goto Death
	Death.BlueTiberium:
		"####" "#" 0 A_Jump(256, "Death")
		Goto Death
	//Fire and Lightning
	Death.Fire:
		"####" "#" 0 A_Jump(256,"Death")
		Goto Death
  }
}

ACTOR RLLostSoulPE : RLLostSoul
{
  States
  {
  Spawn:
    TNT1 A 0 A_JumpIfInventory ("RLLostSoulPEToken", 1, "Spawn2")
    TNT1 A 0 A_GiveInventory ("RLLostSoulPEToken", 1)
    LSOL CD 4 Bright
	TNT1 A 0 A_JumpIf(CallACS("DRLA_GetMoving") == 0, "Nope")
    Goto Spawn+2
  Nope:
    TNT1 A 0 A_ChangeFlag ("SKULLFLY", 0)
    TNT1 A 0 A_Stop
    Goto Spawn2
  Spawn2:
    LSOL AB Random(5,6) Bright A_Look
    Loop
	
  DestroyedEnd:  // Redefined here so that Pain Elemental spawned Lost Soul corpses do not linger
    "####" "#" 0
    Stop
  }
}

ACTOR RLLostSoulNPE : RLLostSoul
{
  States
  {
  DestroyedEnd:  // Redefined here so that Pain Elemental spawned Lost Soul corpses do not linger
    "####" "#" 0
    Stop
  }
}

ACTOR RLLostSoulAgony : RLLostSoulPE
{
  +NOINFIGHTING
  +THRUSPECIES
  Damage (random(1,3) * 3)
}

Actor RLLostSoulPEToken : Inventory
{
inventory.maxamount 1
}

ACTOR RLDRPGSummonedLostSoul : RLLostSoul
{
  -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
  }
}

ACTOR RLCCLostSoul : RLLostSoul
{
  +TOUCHY
  States
  {
  See:
    LSOL AB 6 Bright A_Chase
    Loop
  Missile:
    LSOL C 10 Bright A_FaceTarget
    LSOL D 4 Bright A_SkullAttack
    LSOL CD 4 Bright
    Goto Missile+2
  Melee:
    Stop
  Death:
    LSOL F 6 Bright
    LSOL G 6 Bright A_Scream
    LSOL H 6 Bright
    LSOL I 6 Bright A_NoBlocking
    LSOL J 6
    LSOL K 6
    Stop
  }
}
