
/*

//***Che

Special superarchvile boss of secret map 46 (between 13 and 14).

Uses noxinant fireballs OR custom chaos fireballs if plyer is in a tank

*/

ACTOR YellowColumnOfLight1500Tall
{
	+FORCEYBILLBOARD
	+FLOORCLIP
	+NOBLOCKMAP
	Radius 1
	Height 128
	YScale 20.0
	RenderStyle Add
	Alpha 0.3
	States
	{
		Spawn:
			LTRU Z 1 BRIGHT
			LTRU Z -1 BRIGHT
			Loop
	}
}

ACTOR ToxicVileFlame: FBD_ArchvileFire2 
{
	Alpha 0.3
	// green
	Translation "176:191=115:123", "168:175=112:114", "38:47=115:119", "128:143=115:119", "144:151=115:121", "58:79=115:123", "13:15=117:120", "16:47=112:123", "208:223=112:118", "160:167=112:117", "232:235=115:118", "224:231=112:114"
	States
	{
		Spawn:
			TNT1 A 1 bright A_StartFire
			INFE A 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE B 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE C 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE D 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE E 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE F 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			
			INFE G 1 bright A_FireCrackle
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			
			INFE H 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE I 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE J 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE K 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE L 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			INFE M 1 bright A_Fire
			"----" A 0 A_SpawnItemEx("NoxinantProjectileTrail", Random(-24,24), Random(-24,24), Random(0,24), 0.1 * Random(-24,24), 0.1 * Random(-24,24), 0, 0, 128)
			
			INFE N 1 bright A_FireCrackle
			INFE N 1 BRIGHT A_Jump(256, "Finale")
			Wait // multiplayer shenanigans
			
		Finale:	
			INFE OPQRS 1 bright A_Fire
			INFE T 1 bright A_FireCrackle
			TNT1 A 2
			Stop
		
	}
}


ACTOR ToxicVileFlameAttack: ToxicVileFlame // inflicts damage
{
	States
	{
		Finale:	
			"----" A 0 A_CustomMissile("ToxicEffect", 0.0, 0.0, 0, CMF_AIMDIRECTION | CMF_SAVEPITCH | CMF_TRACKOWNER, 45)
			"----" A 0 A_CustomMissile("ToxicEffect", 0.0, 0.0, 90, CMF_AIMDIRECTION | CMF_SAVEPITCH | CMF_TRACKOWNER, 45)
			"----" A 0 A_CustomMissile("ToxicEffect", 0.0, 0.0, 180, CMF_AIMDIRECTION | CMF_SAVEPITCH | CMF_TRACKOWNER, 45)
			"----" A 0 A_CustomMissile("ToxicEffect", 0.0, 0.0, -90, CMF_AIMDIRECTION | CMF_SAVEPITCH | CMF_TRACKOWNER, 45)
			"----" AAAAA 0 A_CustomMissile("ToxicSpreader", 0.0, 0.0, Random(-180,180), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_SAVEPITCH, Random(5, 60))
			"----" A 0 A_PlaySound("vile/stop")
			INFE OPQRST 1 BRIGHT
			TNT1 A 30
			Stop	
	}
}

ACTOR Andarivile_UV: ArchDevil 17764
{
	//$category "EDAY map-dependent bosses"
	+BOSS
	Health 3000
	// highly contrast shiny green with dark blue shadows
	// doesn't cover the red range so attack frames are partly red with green highlights
	Translation "48:50=4:4", "51:56=[223,247,219]:[0,255,0]", "57:67=112:127", "68:79=240:247", "128:135=112:127", "208:213=[190,237,182]:[0,255,0]", "214:223=112:127", "136:143=240:247", "13:15=240:247", "9:12=240:247", "5:8=0:0", "13:15=240:247", "1:2=0:0", "236:239=240:247", "144:151=240:247"
	
	MaxStepHeight 48
	MaxDropoffHeight 70
	
	Tag "$ANDARIVILE"
	Obituary "$ANDARIVILE_O"
	
	//***Che I'm not proud of this blatant, outright cheating but he was all too cheesable otherwise.
	// Simply remove the player tank from the map? Why that would be too simple.
	// Настоящие джедаи простых путей не ищут.
	damagefactor "ExplosiveImpact", 0.5
	damagefactor "TankShell", 0.1 // player tank does 2000 damage, this reduces it to 200 + 150 splash one tic later = 350, *unless* the teleporting scripts whisks him away before splash hits.
	PainChance "TankShell", 255
	
	var int user_spawning;
	
	DamageFactor "Slime", 0.0 // immune to noxinants' attacks
	
	States {
		Spawn:
			DIAB B 1 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 5) //ACS_NamedExecuteAlways("SlaughtermapInit", 0, 1, 0, 0) 
			"----" A 0 A_GiveInventory("EnemyIsArchvile", 1)
			"----" A 0 A_GiveInventory("ImmuneToToxicEffect", 1)
			DIAB B 1
			Goto Stand			

		TryBlink:	
			"----" A 0 ACS_NamedExecuteWithResult("AndarivileTrySpawnNoxinant") // this is a map script!
			
			// first, try find a position in open space at a distance of 1000 
			"----" AAAAA 0 A_CustomMissile("SuperVileBlinkPositionFinder1000", 40, 0, random(40,320), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random(0, 45))
			// then, a position in open space at a distance of 600 (+ 2 tics delay)
			"----" AAAAA 0 A_CustomMissile("SuperVileBlinkPositionFinder600", 40, 0, random(40,320), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random(0, 45))
			// then, a long-range scan that succeeds even if it hits a wall (+ 3..4 tics delay)
			"----" AAAAA 0 A_CustomMissile("SuperVileBlinkPositionFinder4000", 40, 0, random(0,359), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random(0, 20))
			// we are getting desperate here. A small room? A tight corridor?
			// fire slow, floor hugging crawlers designed to get us up ledges or through low windows
			// (4..14 tics delay)
			"----" AAAAAAA 0 A_CustomMissile("SuperVileBlinkPositionFinderFallbackUpClose", 0, 0, random(40,320), CMF_AIMDIRECTION, 0)
			
		
		Missile:
			"----" A 0
			"----" A 0 A_TakeInventory("IAmRaiseable", 1) // not raiseable
			"----" A 0 A_SetUserVar("user_attacking", 1)
			
			// this one IS A MAP SCRIPT! (todo: clone to FBD core)
			"----" A 0 A_JumpIf(CallAcs("GetTargetIsPlayerTank"), "AndarivileAntiTankLogic")
			
			//***Che: attack bruisers and bosses by headshotting them
			"----" A 0 ACS_NamedExecuteWithResult("FBD_TryReAggroAtHead",1,1,TIDtoHate)
			
			"----" A 0 A_Jump(64, "FireGhostPain")
			Goto FireFlameSpam		
		
		AndarivileAntiTankLogic:
			
			"----" A 0 A_JumpIfInventory("BlinkCooldown", 20, 2)
			// this one is also a map script!
			"----" A 0 A_JumpIf(CallAcs("GetTargetIsAimingAtMe", 20), "CheatingBlinkIgnoreCooldown") 
			"----" A 0 
			Goto MissileAntiTank
			
		Pain.TankShell:
		CheatingBlinkIgnoreCooldown:
			DIAB Y 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 9, 0, 37)
			DIAB Y 0 A_TakeInventory("BlinkCooldown", 999)
			DIAB Y 0 A_Pain
			Goto BlinkAway
			
		FlameSpamContinue:	
		
			TNT1 A 0 A_JumpIf(CallAcs("GetTargetIsPlayerTank"), "FlameSpamContinueAntitank")
				//A_JumpIfInTargetInventory("IsInATank", 1, "FlameSpamContinueAntitank")
		
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 10, -3, 49)
			DIAB N 3 BRIGHT
			
				//***Che: do NOT adjust aim if target goes out of sight or is invisible
				TNT1 A 0 ACS_NamedExecuteWithResult("FBD_FaceTargetIfCanSeeIt")			
			
			DIAB O 3 BRIGHT A_CustomMissile("NoxinantFireball",41,0,angle + 0.3 * random(-2,2), CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, 0.1 * random(0,2))
			
			"----" A 0 A_TakeInventory("VileBarrageCount", 1)
			"----" A 0 A_JumpIfInventory("VileBarrageCount", 1, "FlameSpamContinue")
			
			"----" A 0 A_JumpIfInTargetInventory("PowerInvisibility", 1, "FlameSpamEnd")
			"----" A 0 A_JumpIfTargetInLOS("VileFlameAfterFlameSpam")
			"----" A 1 A_Jump(256, "FlameSpamEnd")
			Wait
			
		GenericVileFlame:
		VileFlameAfterFlameSpam:
			"----" A 0 A_SetUserVar("user_attacking", 1)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 10, -3, 49)
			DIAB N 3 BRIGHT A_FaceTarget
			DIAB O 3 BRIGHT A_VileStart
			// A_VileTarget includes A_FaceTarget
			DIAB NONONO 6 BRIGHT A_VileTarget("ToxicVileFlame")
			"----" A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 10, -3, 49)
			
			//"----"  A 0 A_JumpIf(CallAcs("FBD_GetTargetHasIronFeet"), "VileFlameAgainstRadsuit")
			"----"  A 0 A_JumpIfInTargetInventory("PowerIronFeet", 1, "VileFlameAgainstRadsuit")
			"----"  A 0 A_JumpIfInTargetInventory("ImmuneToToxicEffect", 1, "VileFlameAgainstRadsuit")
			
			// action native A_VileAttack(sound snd = "vile/stop", int initialdmg = 20, int blastdmg = 70, int blastradius = 70, float thrustfac = 1.0, name damagetype = "Fire", int flags = 0);
			
			//DIAB P 10 BRIGHT A_VileAttack("vile/stop", 20, 70, 70, 1.0, "Slime", VAF_DMGTYPEAPPLYTODIRECT) 
			//P.S. Instead of a customized vile attack, use a special damaging flame
			DIAB P 10 BRIGHT A_VileTarget("ToxicVileFlameAttack")
			Goto See

		VileFlameAgainstRadsuit:
			// does not negate completely but mitigates greatly
			DIAB P 10 BRIGHT A_VileAttack("vile/stop", 5, 10, 70, 1.0, "Slime", VAF_DMGTYPEAPPLYTODIRECT) 
			Goto See
	}
}


ACTOR Andarivile_HMP: Andarivile_UV 17765
{
	Health 2000
}

ACTOR Andarivile_ITYTD: Andarivile_UV 17767
{
	Health 1200
}

ACTOR Andarivile_COOP: Andarivile_UV 17766
{
	Health 4000
	Speed 19
	+MISSILEMORE
	Tag "$ANDARIVILE_H" // "Andarivile (Hell)"
	
	// EVERY attack is a blink!
	
	States
	{
		Missile:
			"----" A 0
			"----" A 0 A_TakeInventory("IAmRaiseable", 1) // not raiseable	

			TNT1 A 0 A_Jump(32, "FireGhostPain")
		
			"----" A 0 A_JumpIfInventory("BlinkCooldown", 1, 2)
			"----" A 1 A_Jump(256, "BlinkAway") 
			
			TNT1 A 0 A_JumpIf(CallAcs("GetTargetIsPlayerTank"), "MissileAntiTank")
			
			//***Che: attack bruisers and bosses by headshotting them
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_TryReAggroAtHead",1,1,TIDtoHate)
			
			TNT1 A 0 A_Jump(160, "FireGhostPain")
			Goto FireFlameSpam
			
			Wait
	
	}
}
