@name FailCake Sacrifice
@inputs Start Pod:wirelink Ent:entity
@outputs Hid Kill Ok Toggle T Holo Cos Sin Boss Ang:angle Melon:entity Die
@persist Onc P Alpha Rot Ply:array
@trigger all
runOnTick(1)

Active = Pod:number("Active")
E = entity()
propSpawnEffect(0)

if(first()){
Onc = 0
E:setMaterial("models/props_wasteland/rockcliff02c")
Ok = 0
Start = 0
Active = 0   
Alpha = 0
Hid = 2   
Kill = 0
Start = 0 
Boss = 0

holoCreate(21)
holoModel(21,"models/Gibs/HGIBS.mdl")
holoPos(21,E:toWorld(vec(-100,-40,0)))
holoScale(21,vec(4,4,4))
holoAng(21,ang(45,0,0))
holoAlpha(21,0)

for(I2=1,20){ 
holoCreate(I2)
holoModel(I2,"hqicosphere")
holoPos(I2,E:toWorld(vec(-200,-40,-40)))
holoScaleUnits(I2,vec(2,2,2))
holoColor(I2,vec(1,1,1))
holoMaterial(I2,"")
holoParent(I2,E)  
holoAlpha(I2,0)
holoEntity(I2):setTrails(20,20,20,"trails/smoke",vec(1,1,1),255)
}

}

if(Holo){
P+=1

Cos = cos(P*3)*10
Sin = sin(P*3)*10

for(I=0,15){ 
holoPos(I,E:toWorld(vec(-200,Cos*I - 40,Sin*I - 50)))
}
}

if(changed(Ent) & Boss == 0 & Die == 0){
Ply[1,entity] = Ent   
}

if(Start & ~Start & Boss == 0 & Kill == 0 & Die == 0){
Toggle=!Toggle    
}

   
if(Active & Toggle & Kill == 0 & Boss == 0 & Die == 0){
  
if(Onc == 0){
Onc = 1
E:soundPlay(2,0,"music/hl2_song10.mp3")  
E:soundPlay(1,0,"buttons/lever3.wav")  
}  

if(Hid <= 120){
Hid+=0.2   
}

if(Hid == 20){
E:soundPlay(4,0,"vo/Streetwar/sniper/male01/c17_09_help01.wav")     
}


if(Hid == 100){
E:soundPlay(4,0,"vo/Streetwar/sniper/male01/c17_09_help02.wav")     
}

if(Hid == 90){
E:soundPlay(4,0,"ambient/voices/m_scream1.wav")     
}

if(Hid >= 100){
E:soundPlay(3,0,"weapons/knife/knife_stab.wav")  
Kill = 1    
}
  
}else{

if(Hid > 0){
Hid-=0.1    
}
soundStop(1)
soundStop(2,5)
Onc = 0
}

if(Kill){ 
T+=0.1

if(T == 2){
E:soundPlay(2,0,"ambient/atmosphere/terrain_rumble1.wav") 
#earthquake(E,100,100,6,100000) 
Holo=1 
}


if(T == 10){
E:soundPlay(5,0,"ambient/thunder3.wav")  
}  

if(T == 20){
E:soundPlay(8,0,"music/prospero03.mp3")  
}  

if(T == 40){
E:soundPlay(9,0,"vo/Citadel/gman_exit01.wav")
soundPitch(9,70)
} 

if(T == 75){
E:soundPlay(9,0,"vo/eli_lab/al_laugh01.wav")
soundPitch(9,70)
} 

if(T == 75){
Kill = 0
Boss = 1
soundStop(8,3)
E:soundPlay(132,0,"music/hl2_song27_trainstation2.mp3")
} 
 
}


## The Boss


if(Boss){
   
if(Ply[1,entity]:health() <= 0){
Boss = 0
Die = 1    
}

if(Alpha == 70){
E:soundPlay(234,0,"vo/gman_misc/gman_03.wav") 
#holoEntity(21):ignite(100)   
soundPitch(234,70)
}
 
if(Alpha < 255){
Alpha+=0.5
Rot+=3
holoAng(21,ang(45,Rot,0))
}else{
Ang = (Ply[1,entity]:pos() - E:pos() + vec(0,-30,-50)):toAngle()

timer("FIRE",2000)

if(clk("FIRE")){
E:soundPlay(343,0,"ambient/machines/machine1_hit1.wav") 

Melon:propDelete()
Melon = propSpawn("models/Gibs/HGIBS.mdl",0)
Melon:setPos(((holoEntity(21):pos() + holoEntity(21):eye()*15)))
Melon:setMass(100)
Melon:applyForce((holoEntity(21):eye())*14^5)
Melon:setTrails(10,10,3,"trails/physbeam",vec(255,255,255),255)

}
holoAng(21,Ang)
}
holoAlpha(21,Alpha)
    
}

if(Die){
if(Alpha > 0){
Alpha-=0.5
Rot-=3    
holoAng(21,ang(45,Rot,0))
holoAlpha(21,Alpha)  
}else{
E:soundPlay(140,0,"vo/ravenholm/madlaugh02.wav")
reset()
}
 
}
