@name WirePlatformer
@inputs W A S D Space Shift R FL Alt Mouse1 Active
@outputs CamPos:vector CamAng:vector CamVel:vector Ply:entity
@persist Vel:vector CamPos:vector CamAng:vector Cam Sprint HP MHP
@persist Rest AttackSounds:array CurWep Color:vector
@persist Weap:array Damage:array Crit:array Length:array
if (first()) {
    AttackSounds=array()
    AttackSounds[1,string]="weapons/stunstick/stunstick_swing1.wav"
    AttackSounds[2,string]="weapons/stunstick/stunstick_swing2.wav"
    Weap=array()
    Weap[1,string]="Sword"
    Weap[2,string]="Mace"
    Weap[3,string]="Axe"
    Damage=array()
    Damage[1,number]=5
    Damage[2,number]=3
    Damage[3,number]=7
    Crit=array()
    Crit[1,number]=95
    Crit[2,number]=97
    Crit[3,number]=93
    Length=array()
    Length[1,number]=3000
    Length[2,number]=2000
    Length[3,number]=4000
    CurWep=1
    HP=25 #Maybe items to add onto HP?
    MHP=HP
    runOnChat(1)
    runOnTick(1)
    gSetGroup("WireRPG")
    gShare(1)
    signalSetGroup("WireRPG")
    runOnSignal("WireRPG",1,1)
    timer("Holos",75)
}
if (clk("Holos")) {
    Color=randvec(vec(0,0,0),vec(255,255,255))
    #
    holoCreate(1) #Body
    holoModel(1,"hqcylinder2")
    holoScaleUnits(1,vec(2,2,3))
    holoColor(1,Color)
    holoPos(1,entity():pos()-vec(0,0,98.5))
    holoAng(1,ang())
    #
    holoCreate(2) #Head
    holoModel(2,"hqicosphere2")
    holoScaleUnits(2,vec(2,2,2))
    holoColor(2,vec(185,145,115))
    holoPos(2,entity():pos()-vec(0,0,96.5))
    holoAng(2,ang())
    holoParent(2,1)
    #
    holoCreate(3) #Directional Arrow
    holoModel(3,"pyramid")
    holoScaleUnits(3,vec(1.5,1.5,2))
    holoColor(3,vec4(200,25,25,200))
    holoPos(3,entity():pos()-vec(-3.2,0,99.5))
    holoAng(3,ang(90,0,0))
    holoParent(3,1)
    #
    #Hair colors!
    HairColor=array()
    HairColor[1,vector]=vec(60,40,0)
    HairColor[2,vector]=vec(100,20,20)
    HairColor[3,vector]=vec(0,0,0)
    HairColor[4,vector]=vec(130,130,20)
    HairColor[5,vector]=vec(75,75,75)
    #
    holoCreate(4) #Hair!
    holoModel(4,"hqicosphere2")
    holoScaleUnits(4,vec(2,2,2))
    holoColor(4,HairColor[randint(1,5),vector])
    holoPos(4,entity():pos()-vec(0.1,0,96.4))
    holoAng(4,ang(340,0,0))
    holoParent(4,2)
    #
    #Eye Colors!
    EyeColor=array()
    EyeColor[1,vector]=vec(20,20,20)
    EyeColor[2,vector]=vec(0,100,0)
    EyeColor[3,vector]=vec(0,0,255)
    EyeColor[4,vector]=vec(50,50,200)
    EyeColor[5,vector]=vec(40,20,0)
    EyeColor[6,vector]=vec(0,0,0)
    EyeColor[7,vector]=vec(75,75,75)
    EyeColor[8,vector]=vec(100,80,50)
    EyeColor[9,vector]=vec(25,100,100)
    EyeColor[10,vector]=vec(120,120,120)
    Rand=randint(1,10)
    #
    holoCreate(5) #Eye1
    holoModel(5,"hqicosphere2")
    holoScaleUnits(5,vec(0.6,0.6,0.6))
    holoColor(5,EyeColor[Rand,vector])
    holoPos(5,entity():pos()-vec(-0.8,0.35,96.5))
    holoAng(5,ang())
    holoParent(5,2)
    #
    holoCreate(6) #Eye2
    holoModel(6,"hqicosphere2")
    holoScaleUnits(6,vec(0.6,0.6,0.6))
    holoColor(6,EyeColor[Rand,vector])
    holoPos(6,entity():pos()-vec(-0.8,-0.35,96.5))
    holoAng(6,ang())
    holoParent(6,2)
    timer("Holos2",150)
}
if (clk("Holos2")) {
    holoCreate(7) #Sleeve1
    holoModel(7,"hqcylinder2")
    holoScaleUnits(7,vec(1,1,1.4))
    holoColor(7,Color)
    holoPos(7,entity():pos()-vec(0,0.90,97.85))
    holoAng(7,ang(0,0,325))
    holoParent(7,1)
    #
    holoCreate(8) #Sleeve2
    holoModel(8,"hqcylinder2")
    holoScaleUnits(8,vec(1,1,1.4))
    holoColor(8,Color)
    holoPos(8,entity():pos()-vec(0,-0.90,97.85))
    holoAng(8,ang(0,0,35))
    holoParent(8,1)
    #
    holoCreate(9) #Hand1
    holoModel(9,"hqicosphere2")
    holoScaleUnits(9,vec(1,1,1))
    holoColor(9,vec(185,145,115))
    holoPos(9,entity():pos()-vec(0,1.25,98.5))
    holoAng(9,ang())
    holoParent(9,7)
    #
    holoCreate(10) #Hand2
    holoModel(10,"hqicosphere2")
    holoScaleUnits(10,vec(1,1,1))
    holoColor(10,vec(185,145,115))
    holoPos(10,entity():pos()-vec(0,-1.25,98.5))
    holoAng(10,ang())
    holoParent(10,8)
    #
    holoCreate(11) #HP Bar
    holoScaleUnits(11,vec(1,5,1))
    holoColor(11,hsv2rgb(vec((HP/MHP)*120,1,1)))
    holoAlpha(11,150)
    holoPos(11,entity():pos()-vec(0,0,94))
    holoAng(11,ang())
    holoParent(11,1)
    #
    holoCreate(12) #Sword
    holoModel(12,"pyramid")
    holoScaleUnits(12,vec(0.4,0.4,3))
    holoColor(12,vec(175,175,175))
    holoPos(12,entity():pos()-vec(-1.5,-1.25,98.5))
    holoAng(12,ang(90,0,0))
    holoParent(12,9)
    timer("Holos3",150)
}
if (clk("Holos3")) {
    holoCreate(13) #Mace(Head)
    holoModel(13,"hqcylinder2")
    holoScaleUnits(13,vec(1.4,1.4,1.4))
    holoColor(13,vec4(75,75,75,0))
    holoPos(13,entity():pos()-vec(-3,-1.25,98.5))
    holoAng(13,ang())
    holoParent(13,9)
    #
    holoCreate(14) #Mace(Shaft)
    holoModel(14,"hqcylinder2")
    holoScaleUnits(14,vec(0.5,0.5,3))
    holoColor(14,vec4(50,30,0,0))
    holoPos(14,entity():pos()-vec(-1.5,-1.25,98.5))
    holoAng(14,ang(90,0,0))
    holoParent(14,13)
    #
    holoCreate(15) #Axe(Head)
    holoModel(15,"prism")
    holoScaleUnits(15,vec(0.5,1.4,1.4))
    holoColor(15,vec4(75,75,75,0))
    holoPos(15,entity():pos()-vec(-3,-1.25,98.9))
    holoAng(15,ang(180,90,0))
    holoParent(15,9)
    #
    holoCreate(16) #Axe(Shaft)
    holoModel(16,"hqcylinder2")
    holoScaleUnits(16,vec(0.5,0.5,3))
    holoColor(16,vec4(50,30,0,0))
    holoPos(16,entity():pos()-vec(-1.5,-1.25,98.5))
    holoAng(16,ang(90,0,0))
    holoParent(16,15)
    for (I=1,30) {holoMaterial(I,"models/debug/debugwhite")}
}

#Do stuff!
if (R) {entity():isWeldedTo():ejectPod(),reset()}
#Declaration.
Ply=holoEntity(1)

#Movement
if (changed(Active)&Active) {
    entity():isWeldedTo():printDriver(4,"Current Weapon:"+Weap[CurWep,string])
}
if (Active) {
if (changed(Shift)&Shift&Sprint==0) {
    timer("SprintOff",7000)
    Sprint=1
}
if (clk("SprintOff")) {
    timer("Rest",4000)
    Sprint=-0.5
}
elseif (clk("Rest")) {Sprint=0}
H=rangerOffset(2,Ply:pos()+vec(0,0,0.2),Vel):hit()
if (H) {Vel=vec()}
InAir=rangerOffset(1,Ply:pos()-vec(0,0,1.5),vec(0,0,-1)):hit()
if (InAir) {
    Vel=vec()
    if (W) {
        H=rangerOffset(2,Ply:pos(),Ply:forward()):hit()
        if (!H) {
            Vel+=Ply:forward()/2*(Sprint+1)
        }
        else {
            H=rangerOffset(3,Ply:pos(),Ply:forward()+vec(0,0,0.4)):hit()
            if (!H) {
                Vel+=Ply:forward()/2*(Sprint+1)+vec(0,0,0.9)
            }
        }
    }
    if (S) {
        H=rangerOffset(2,Ply:pos(),-Ply:forward()):hit()
        if (!H) {
            Vel-=Ply:forward()/4*(Sprint+1)
        }
        else {
            H=rangerOffset(3,Ply:pos(),-Ply:forward()+vec(0,0,0.4)):hit()
            if (!H) {
                Vel-=Ply:forward()/4*(Sprint+1)
                Vel+=vec(0,0,0.9)
            }
        }
    }
    if (A) {
        H=rangerOffset(2,Ply:pos(),-Ply:right()):hit()
        if (!H) {
            Vel-=Ply:right()/3*(Sprint+1)
        }
        else {
            H=rangerOffset(3,Ply:pos(),-Ply:right()+vec(0,0,0.4)):hit()
            if (!H) {
                Vel-=Ply:forward()/3*(Sprint+1)
                Vel+=vec(0,0,0.9)
            }
        }
    }
    if (D) {
        H=rangerOffset(2,Ply:pos(),Ply:right()):hit()
        if (!H) {
            Vel+=Ply:right()/3*(Sprint+1)
        }
        else {
            H=rangerOffset(3,Ply:pos(),Ply:right()+vec(0,0,0.4)):hit()
            if (!H) {
                Vel+=Ply:forward()/3*(Sprint+1)+vec(0,0,0.9)
            }
        }
    }
    if (A&W|D&W) {
        Vel-=vec(Vel:x()/1.5,Vel:y()/1.5,Vel:z()/2)
    }
    if (A&S|D&S) {
        Vel-=vec(Vel:x()/1.5,Vel:y()/1.5,Vel:z()/2)
    }
    if (Space) {
        Vel+=vec(0,0,1)
    }
    IsInObject=rangerOffset(1,Ply:pos()-vec(0,0,1.5),vec(0,0,1)):hit()
    if (IsInObject) {Vel+=vec(0,0,0.2)}
}
else {Vel-=vec(0,0,0.0155279503)*2} #Thats the inches per second.
holoAng(1,ang(0,entity():isWeldedTo():driver():eye():toAngle():yaw(),0))
holoPos(1,Ply:pos()+Vel) #Actually, 1.55279503 inches/s^2, but I
                         #need to scale down, yknow?
#Cam
Eye=entity():isWeldedTo():driver():eye()
if (changed(FL)&FL) {Cam=!Cam}
if (!Cam) {
    Tr=rangerOffset(50,Ply:pos(),-entity():isWeldedTo():driver():eye())
    CamPos=Tr:position()+entity():isWeldedTo():driver():eye()*10+Tr:hitNormal()*3
    CamAng=Eye
}
else {
    Tr=rangerOffset(5,Ply:pos(),-entity():isWeldedTo():driver():eye())
    CamPos=holoEntity(2):pos()-entity():isWeldedTo():driver():eye()+vec(-4,2,1.5):rotate(Eye:toAngle())+Tr:hitNormal()*3
    CamAng=Eye
}
CamVel=$CamPos+$CamAng
#holoPos(11,Ply:pos()+vec(0,0,4):rotate(Eye:toAngle()))
#holoAng(11,Eye:toAngle())     #Disabled HP bar adjustment.

#Death and Damage
if (HP<=0) {entity():isWeldedTo():printDriver(4,"You died."),reset()}
if (signalClk("WireRPG","WireRPG")) {
    HP-=gGetNum(signalSender():id())
    print(4,"Ouch!")
    holoScaleUnits(12,vec(1,(HP/MHP)*5,1))
    holoColor(12,hsv2rgb(vec((HP/MHP)*120,1,1)))
}
if (changed(Mouse1)&Mouse1&Rest==0) {
    CritB=randint(0,100)
    if (CritB>=Crit[CurWep,number]) {Bonus=100-CritB}
    gSetNum(entity():id(),Damage[CurWep,number]+Bonus+randint(-1,1))
    findIncludeClass("gmod_wire_hologram")
    findExcludePlayerProps(owner())
    findInCone(Ply:pos(),Ply:forward(),5,90)
    if (find()) {
        signalSendToPlayer("WireRPG",find():owner())
    }
    Rest=1
    timer("Rested",Length[CurWep,number])
    Ply:soundPlay("Swing",2,AttackSounds[randint(1,AttackSounds:count()),string])
}
if (clk("Rested")) {Rest=0}

#Weapon Switching
if (changed(Alt)&Alt) {
    CurWep++
    if (CurWep>Weap:count()) {CurWep=1}
    entity():isWeldedTo():printDriver(4,"Current Weapon:"+Weap[CurWep,string])
    if (CurWep==1) {
        holoAlpha(12,255)
        holoAlpha(13,0)
        holoAlpha(14,0)
        holoAlpha(15,0)
        holoAlpha(16,0)
    }
    elseif (CurWep==2) {
        holoAlpha(12,0)
        holoAlpha(13,255)
        holoAlpha(14,255)
        holoAlpha(15,0)
        holoAlpha(16,0)
    }
    elseif (CurWep==3) {
        holoAlpha(12,0)
        holoAlpha(13,0)
        holoAlpha(14,0)
        holoAlpha(15,255)
        holoAlpha(16,255)
    }
}
}
