@name Chaqua Disguise Missile
@inputs [C]:wirelink
@persist FA CA TA CFP BMS ZA Zm
@persist [BMV]:vector
@persist [BMA FAn]:angle
@persist [CB E O CC P]:entity
if(first())
{
    runOnTick(1)
    
    E = entity()
    O = owner()
    
    CC = C:entity()
    
    CB = holoCreate(1,O:pos())
    holoModel(1,"models/props_phx/torpedo.mdl")
    
    if(!CC:isValid())
    {
        cameraCreate(1)
    }
    
    rangerFilter(O)
    rangerPersist(1)
}

CCA = CC:isValid()

####

BMVe = clamp(O:vel():length(),0,32)
if(BMVe > 0)
{
    FAn = (O:vel()):toAngle():setPitch(0)
}

####

holoPos(1,O:pos()+vec(0,0,20)+(BMV*BMVe/32))
holoAng(1,CB:toWorld(CB:toLocal(FAn+(BMA*BMVe/32))/10))

CR = rangerOffset(32+(120*CFP),O:shootPos()+vec(0,0,30),-O:eye())
CV = vec(0,0,30)+O:shootPos()-O:eye()*CR:distance()-2
CAn = O:eyeAngles()
if(CCA)
{
    C["Position",vector] = CV
    C["Angle",angle] = CAn
}else
{
    cameraPos(1,CV)
    cameraAng(1,CAn)
}

rangerFilter(O)
Rd = rangerOffset(500000,O:shootPos()+vec(0,0,30),O:eye())
Zm = 90 - O:keyWalk()*70
ZA += (Zm-ZA)/5
if(CCA)
{
    C["FOV",number] = ZA
}else
{
    cameraZoom(1,ZA)
}

####

CA = O:keyDuck()

if(changed(O:keyZoom())&O:keyZoom()&CA)
{
    TA = !TA
}

FA = TA & CA & O:isAlive()

####

if(FA)
{
    CFP += 0.1
}else
{
    CFP -= 0.1
}
CFP = clamp(CFP,0,1)

####

if(FA)
{
    if(changed(O:weapon():type()))
    {
        O:weapon():setAlpha(0)
    }
    
    if(changed(O:keyAttack2()))
    {
        holoVisible(1,O,!O:keyAttack2())
        
        if(CCA)
        {
            C["Activated",number] = !O:keyAttack2()
        }else
        {
            cameraToggle(1,!O:keyAttack2())
        }
    }
    
    BMS -= BMVe*0.40625*O:isOnGround()
    BMV = vec(0,0,8 + cos(BMS)*2)
    BMA = ang(cos(BMS) - 4,cos(BMS/2)*2,sin(BMS/2)*3*O:isOnGround())
    
    local RD = rangerOffsetHull(CB:boxSize():length()*0.75,CB:toWorld(vec(-CB:boxSize():length()/4,0,0)),CB:forward(),vec(15))
    if(RD:hit() | (CFP == 1 & changed(P:isValid()) & !P:isValid()))
    {
        propSpawn("models/props_phx/torpedo.mdl",CB:pos(),1):propBreak()
    }
}

if(changed(FA))
{
    print(4,"Missile Disguise " + (FA ? "Activated" : "Deactivated"))
    
    if(CCA)
    {
        C["Activated",number] = FA
    }else
    {
        cameraToggle(1,FA)
    }
    
    if(FA)
    {
        P = propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",CB:pos(),1)
        P:setColor(0,0,0,0)
        P:propNotSolid(1)
        P:parentTo(CB)
    }else
    {
        P:propDelete()
    }
    
    O:setMaterial(FA ? "models/effects/vol_light001" : "phoenix_storms/chrome")
    O:weapon():setAlpha((!FA)*255)
    
    O:soundPlay("equip", FA ? 1.08 : 0.395,FA ? "player/taunt_launcher_hit.wav" : "player/taunt_wrench_shoulder.wav")
    
    holoVisible(1,O,FA)
}

if(changed(CFP))
{
    holoAlpha(1,CFP*255)
}
