;var(16)=juggle techo


;-------------------------
; Stand
[Statedef 0]
type = S
physics = S
sprpriority = 0

;normaL
[State 0, b]
type = ChangeAnim
triggerall = prevstateno != 3150
triggerall = life <= 250
trigger1 = Anim != 2 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0 ;Turn anim over
value = 2

;critical
[State 0, 1]
type = ChangeAnim
triggerall = prevstateno != 3150
triggerall = life > 250
trigger1 = Anim != 0 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0 ;Turn anim over
value = 0

[State 0, 1]
type = ChangeAnim
trigger1 = prevstateno = 3150 && anim != 3150
value = 3150

[State 0, 2]
type = VelSet
trigger1 = Time = 0
y = 0

[State 0, 3] ;Stop moving if low velocity or 4 ticks pass
type = VelSet
trigger1 = abs(vel x) < 2
trigger2 = Time = 4
x = 0

[State 191, Snd 2]
type = PlaySnd
triggerall = life <= 250
trigger1 = animelem = 7
value = 10,8
freqmul = 1.0+(random/5000.0)
volume = -100

;enloquecido
[State 180, 1]
type = changestate
trigger1 = anim != 3150
trigger1 = roundstate = 2
trigger1 = random = 1
value = 44
ctrl = 1

[State 0, VarSet]
type = VarSet
trigger1 = !time && prevstateno = 3150
v = 10
value = 0

;da control para winpose
[State 0, ctrl]
type = ctrlset
trigger1 = anim = 3150 && time = 100
value = 1

;crea muņeca si adelantan intro
[State 0, Helper]
type = Helper
trigger1 = !time && numhelper(3102) = 0
trigger1 = (prevstateno = 194)||(prevstateno = 3101)
helpertype = normal
name = "muņeca inerte"
ID = 3102
stateno = 3102
ownpal = 1
pos = 30,0


;-------------------------
; Stand enloquecido
[Statedef 44]
type = S
physics = S
sprpriority = 0

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 15,2
volume = 200
channel = 13
freqmul = 0.9+(random/5000.0)

[State 180, 1]
type = changeanim
trigger1 = time = 0
value = 3

[State 180, 1]
type = changestate
trigger1 = time = 40
value = 0
ctrl = 1

;---------------------------------------------------------------------------
; Jump Start
[Statedef 40]
type    = S
physics = S
anim = 40
ctrl = 0
sprpriority = 1

[State 40, 1]
type = VarSet
trigger1 = Time = 0
sysvar(1) = 0

[State 40, 2]
type = VarSet
trigger1 = command = "holdfwd"
sysvar(1) = 1

[State 40, 3]
type = VarSet
trigger1 = command = "holdback"
sysvar(1) = -1

[State 40, 4]
type = VelSet
trigger1 = AnimTime = 0
x = ifelse(var(15)=1,4.4,ifelse(sysvar(1)=0, const(velocity.jump.neu.x), ifelse(sysvar(1)=1, const(velocity.jump.fwd.x), const(velocity.jump.back.x))))
y = ifelse(var(15)=0,const(velocity.jump.y),-9)

[State 40, 5]
type = VelSet
trigger1 = AnimTime = 0
trigger1 = prevstateno = 100 ;RUN_FWD
trigger1 = sysvar(1) = 1
x = const(velocity.runjump.fwd.x)

[State 0, Explod]
type = Explod
trigger1 = AnimTime = 0
anim = f 63
pos = 0,10
facing = ifelse(random<500,1,-1)
scale = 0.3,0.3
sprpriority = 3
ownpal = 1

[State 0, Explod]
type = Explod
trigger1 = AnimTime = 0
anim = f 64
scale = 0.5,0.5
pos = 0,10
facing = ifelse(random<500,1,-1)
sprpriority = 0
ownpal = 1

[State 40, 6]
type = ChangeState
trigger1 = AnimTime = 0
value = 50
ctrl = 1

;---------------------------------------------------------------------------
; RUN_FWD
[Statedef 100]
type    = S
physics = S
anim = 100
sprpriority = 1

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 11,0
channel = 30
freqmul = 1.2+(random/5000.0)
volume = -50

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 11,0
channel = 31
freqmul = 0.7+(random/5000.0)
volume = -50

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 12,0
freqmul = 0.7+(random/5000.0)
volume = -100
channel = 29

[State 100, 1]
type = VelSet
trigger1 = 1
x = const(velocity.run.fwd.x)

[State 100, 2] ;Prevent run from canceling into walk
type = AssertSpecial
trigger1 = 1
flag = NoWalk

[State 100, 3] ;Prevent from turning
type = AssertSpecial
trigger1 = 1
flag = NoAutoTurn

[State 100, 4]
type = ChangeState
trigger1= var(24)=0 && command != "holdfwd"
trigger2= var(24)!=0 && p2bodydist x<60
trigger3= var(24)>=2 && enemynear, name = "ananzi" && enemynear, numhelper(1100)=1
trigger4 = var(24)>=2 && enemynear, name = "ananzi" && enemynear, stateno = 3100
value = 0

;---------------------------------------------------------------------------
; RUN_FWD AIR
[Statedef 101]
type    = A
physics = N
anim = 100
sprpriority = 1

[State 100, 1]
type = VelSet
trigger1 = 1
x = const(velocity.run.fwd.x)

[State 100, 1]
type = VelSet
trigger1 = 1
y = 0

[State 100, 2] ;Prevent run from canceling into walk
type = AssertSpecial
trigger1 = 1
flag = NoWalk

[State 100, 3] ;Prevent from turning
type = AssertSpecial
trigger1 = 1
flag = NoAutoTurn

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 11,0
channel = 30
freqmul = 1.2+(random/5000.0)
volume = -50

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 11,0
channel = 31
freqmul = 0.7+(random/5000.0)
volume = -50

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 12,0
freqmul = 0.7+(random/5000.0)
volume = -100
channel = 29

[State 100, 4]
type = ChangeState
trigger1 = !var(24) && command != "holdfwd"
trigger2= var(24) && p2bodydist x<80
trigger3 = time = 80
value = 102
ctrl = 1

;---------------------------------------------------------------------------
; RUN_FWD AIR STOP
[Statedef 102]
type    = A
physics = A
anim = 102
sprpriority = 1

[State 100, 4]
type = Changeanim
trigger1 = time = 0
value = 102

;---------------------------------------------------------------------------
; RUN_BACK
[Statedef 105]
type    = S
physics = S
ctrl = 0
anim = 105
sprpriority = 1

[State 0, Helper]
type = Helper
trigger1 = anim = 105 && animelem = 3
helpertype = normal
name = "fantasma run-back"
stateno = 106

[State 105, 2]
type = CtrlSet
trigger1 = animtime = 0
value = 1

[State 0, ChangeAnim]
type = ChangeAnim
trigger1 = anim = 105 && animelem=4 && backedgedist < 4
value = 107

[State 105, 2]
type = posadd
trigger1 = anim =105 && animelem = 4
trigger2 = anim = 107 && animelem = 1
x = ifelse(anim=105, -90, 320)

[State 0, ScreenBound]
type = ScreenBound
trigger1 = anim = 107
value = 0
movecamera = 1,0

[State 0, Turn]
type = Turn
trigger1 = anim = 107 && animelem = 1

[State 105, 3]
type = ChangeState
trigger1 = animtime = 0
value = 0

;---------------------------------------------------------------------------
;FANTASMA - RUN_BACK
[Statedef 106]
type    = S
physics = N
ctrl = 0
anim = 106
sprpriority = 3
velset = -3

[State 0, PlaySnd]
type = PlaySnd
trigger1 = !time
value = 15,4
volume = -50
freqmul = 1.0+(random/5000.0)

;desaparece en 50 ticks
[State 23, trans]
type = Trans
trigger1 = time > 0
trans = addalpha
alpha=ceil(256-5.12*(time)),ceil(0+5.12*(time))

[State 0, DestroySelf]
type = DestroySelf
trigger1 = time = 100

;--------------------------------------------
;muerto
[Statedef 5150, 0]
type = S
ctrl = 0
velset = 0,0
movetype = I
physics = S
sprpriority = 0

[State 5150, 8]
type = NotHitBy
trigger1 = 1
value = SCA
time = 1

[State 5150, 3] ;Hit up type anim
type = ChangeAnim
trigger1 = !time
trigger1 = (anim = [5111,5119]) || (anim = [5171,5179])
value = 5111

[State 610, 2]
type = changeanim
triggerall= Anim != 91231
triggerall= Anim != 5111 ;up type
trigger1 = !time
value = ifelse((anim != 3174),5150,3175)

[State 0, PlaySnd]
type = PlaySnd
triggerall= Anim != 91232
triggerall= Anim != 5111 ;up type
trigger1 = anim = 3175
value = 12,12
volume = -100
freqmul = 0.9+(random/5000.0)
persistent = 0

[State 0, PosSet]
type = PosSet
triggerall= Anim != 91231
trigger1 = !time
y = 0

;---------------------------------------------------------


;guard states fixed thanks to pots.
;===================<GUARD>================

;---START---
[Statedef 120]
type=U
physics=U
[State 120, anim]
type=changeanim
trigger1=!time
value=120+(statetype=C)+(statetype=A)*2
[State 120, sts]
type=statetypeset
trigger1=!time&&statetype=S
physics=S
[State 120, sts]
type=statetypeset
trigger1=!time&&statetype=C
physics=C
[State 120, sts]
type=statetypeset
trigger1=!time&&statetype=A
physics=A
[State 120, Hi to Lo]
type=statetypeset
trigger1=var(24)<=0&&statetype=S&&command="holddown"
trigger2=var(24)>=1&&statetype=S&&(enemynear,movetype=A)&&(enemynear,statetype=C)
statetype=C
physics=C
[State 120, Lo to Hi]
type=statetypeset
trigger1=var(24)<=0&&statetype=C&&command!="holddown"
trigger2=var(24)>=1&&statetype=C&&(enemynear,movetype=A)&&(enemynear,statetype!=C)
statetype=S
physics=S
[State 120, end]
type=changestate
trigger1=!animtime
value=130+(statetype=C)+(statetype=A)*2
[State 120, stop]
type=changestate
trigger1=(var(24)<=0&&command!="holdback")
trigger2=!inguarddist
value=140


;---STAND GUARD (guarding)---
[Statedef 130]
type=S
physics=S
[State 130, anim]
type=changeanim
trigger1=anim!=130
value=130
[State 130, Hi to Lo]
type=changestate
trigger1=var(24)<=0&&command="holddown"
trigger2=var(24)>=1&&(enemynear,movetype=A)&&(enemynear,statetype=C)
value=131
[State 130, Stop Guarding]
type=changestate
trigger1=(var(24)<=0&&command!="holdback")
trigger2=!inguarddist
value=140


;---CROUCH GUARD (guarding)---
[Statedef 131]
type=C
physics=C
[State 131, anim]
type=changeanim
trigger1=anim!=131
value=131
[State 131, Lo to Hi]
type=changestate
trigger1=var(24)<=0&&command!="holddown"
trigger2=var(24)>=1&&(enemynear,movetype=A)&&(enemynear,statetype!=C)
value=130
[State 131, Stop Guarding]
type=changestate
trigger1=(var(24)<=0&&command!="holdback")
trigger2=!inguarddist
value=140


;---AIR GUARD (guarding)---
[Statedef 132]
type=A
physics=N
[State 132, anim]
type=changeanim
trigger1=anim!=132
value=132
[State 132, grav]
type=veladd
trigger1=1
y=const(movement.yaccel)
[State 132, var]
type=varset
trigger1=1
sysvar(0)=(pos y>=0)&&(vel y>0)
[State 132, vel]
type=velset
trigger1=sysvar(0)
y=0
[State 132, pos]
type=posset
trigger1=sysvar(0)
y=0
[State 132, end]
type=changestate
trigger1=sysvar(0)&&inguarddist
trigger1=(var(24)<=0&&command="holdback")||var(24)>=1
value=130
[State 132, end]
type=changestate
trigger1=sysvar(0)
value=52
[State 132, stop guarding]
type=changestate
trigger1=(var(24)<=0&&command!="holdback")
trigger2=!inguarddist
value=140

;---GUARD (end)---
[Statedef 140]
type=U
physics=U
ctrl=1
[State 140, anim]
type=changeanim
trigger1=!time
value=140+(statetype=C)+(statetype=A)*2
[State 140, sts]
type=statetypeset
trigger1=!time&&statetype=S
physics=S
[State 140, sts]
type=statetypeset
trigger1=!time&&statetype=C
physics=C
[State 140, sts]
type=statetypeset
trigger1=!time&&statetype=A
physics=A
[State 140, Hi to Lo]
type=statetypeset
trigger1=var(24)<=0&&statetype=S&&command="holddown"
trigger2=var(24)>=1&&statetype=S&&(enemynear,movetype=A)&&(enemynear,statetype=C)
statetype=C
physics=C
[State 140, Lo to Hi]
type=statetypeset
trigger1=var(24)<=0&&statetype=C&&command!="holddown"
trigger2=var(24)>=1&&statetype=C&&(enemynear,movetype=A)&&(enemynear,statetype!=C)
statetype=S
physics=S
[State 140, 5]
type=changestate
trigger1=!animtime
value=(statetype=C)*11+(statetype=A)*51

;---SGUARDHIT (shaking)---
[Statedef 150]
type=S
movetype=H
physics=N
velset=0,0
[State 150, anim]
type=changeanim
trigger1=1
value=150
[State 150, end]
type=changestate
trigger1=hitshakeover
value=151+2*((var(24)<=0&&command="holddown")||(var(24)>=1&&(enemynear,movetype=A)&&(enemynear,statetype=C)))
[State 150, Hi to Lo]
type=statetypeset
trigger1=var(24)<=0&&statetype=S&&command="holddown"
trigger2=var(24)>=1&&statetype=S&&(enemynear,movetype=A)&&(enemynear,statetype=C)
statetype=C
physics=C
[State 150, Lo to Hi]
type=statetypeset
trigger1=var(24)<=0&&statetype=C&&command!="holddown"
trigger2=var(24)>=1&&statetype=C&&(enemynear,movetype=A)&&(enemynear,statetype!=C)
statetype=S
physics=S

;---SGUARDHIT2 (knocked back)---
[Statedef 151]
type=S
movetype=H
physics=S
anim=150
[State 151, vel]
type=hitvelset
trigger1=!time
x=1
[State 151, vel]
type=velset
trigger1=time=gethitvar(slidetime)
trigger2=hitover
x=0
[State 151, ctrl]
type=ctrlset
trigger1=time=gethitvar(ctrltime)
value=1
[State 151, Hi to Lo]
type=statetypeset
trigger1=var(24)<=0&&statetype=S&&command="holddown"
trigger2=var(24)>=1&&statetype=S&&(enemynear,movetype=A)&&(enemynear,statetype=C)
statetype=C
physics=C
[State 151, Lo to Hi]
type=statetypeset
trigger1=var(24)<=0&&statetype=C&&command!="holddown"
trigger2=var(24)>=1&&statetype=C&&(enemynear,movetype=A)&&(enemynear,statetype!=C)
statetype=S
physics=S
[State 151, end]
type=changestate
trigger1=hitover
value=130
ctrl=1

;---CGUARDHIT (shaking)---
[Statedef 152]
type=C
movetype=H
physics=N
velset=0,0
[State 152, anim]
type=changeanim
trigger1=1
value=151
[State 152, end]
type=changestate
trigger1=hitshakeover
value=151+2*((var(24)<=0&&command="holddown")||(var(24)>=1&&(enemynear,movetype=A)&&(enemynear,statetype=C)))
[State 152, Hi to Lo]
type=statetypeset
trigger1=var(24)<=0&&statetype=S&&command="holddown"
trigger2=var(24)>=1&&statetype=S&&(enemynear,movetype=A)&&(enemynear,statetype=C)
statetype=C
physics=C
[State 152, Lo to Hi]
type=statetypeset
trigger1=var(24)<=0&&statetype=C&&command!="holddown"
trigger2=var(24)>=1&&statetype=C&&(enemynear,movetype=A)&&(enemynear,statetype!=C)
statetype=S
physics=S

;---CGUARDHIT2 (knocked back)---
[Statedef 153]
type=C
movetype=H
physics=C
anim=151
[State 153, vel]
type=hitvelset
trigger1=!time
x=1
[State 153, vel]
type=velset
trigger1=time=gethitvar(slidetime)
trigger2=hitover
x=0
[State 153, ctrl]
type=ctrlset
trigger1=time=gethitvar(ctrltime)
value=1
[State 153, Hi to Lo]
type=statetypeset
trigger1=var(24)<=0&&statetype=S&&command="holddown"
trigger2=var(24)>=1&&statetype=S&&(enemynear,movetype=A)&&(enemynear,statetype=C)
statetype=C
physics=C
[State 153, Lo to Hi]
type=statetypeset
trigger1=var(24)<=0&&statetype=C&&command!="holddown"
trigger2=var(24)>=1&&statetype=C&&(enemynear,movetype=A)&&(enemynear,statetype!=C)
statetype=S
physics=S
[State 153, end]
type=changestate
trigger1=hitover
value=131
ctrl=1

;---AGUARDHIT (shaking)---
[Statedef 154]
type=A
movetype=H
physics=N
velset=0,0
[State 154, anim]
type=changeanim
trigger1=1
value=152
[State 154, end]
type=changestate
trigger1=hitshakeover
value=155

;---AGUARDHIT2 (knocked away)---
[Statedef 155]
type=A
movetype=H
physics=N
anim=152
[State 155, vel]
type=hitvelset
trigger1=!time
x=1
y=1
[State 155, vel]
type=veladd
trigger1=1
y=const(movement.yaccel)
[State 155, ctrl]
type=ctrlset
trigger1=time=gethitvar(ctrltime)
value=1
[State 155, var]
type=varset
trigger1=1
sysvar(0)=(pos y>=0)&&(vel y>0)
[State 155, vel]
type=velset
trigger1=sysvar(0)
y=0
[State 155, pos]
type=posset
trigger1=sysvar(0)
y=0
[State 155, end]
type=changestate
trigger1=sysvar(0)&&inguarddist
trigger1=(var(24)<=0&&command="holdback")||var(24)>=1
value=130
[State 155, end]
type=changestate
trigger1=sysvar(0)
value=52


