;======================================================
[Statedef -2];常時監視ステート(相手に行動を制御されても関係無く常に実行される)
;======================================================



[state ゲージ自動回復]
type = poweradd
triggerall = stateno != 1333
trigger1 = gametime%2 = 0 ;2フレームごとに回復
value = 3 ;回復する量

[State -2, ]
type = Helper
triggerall = !ishelper;本体
triggerall = alive
triggerall = !numhelper(1234);このヘルパーが存在していない時
trigger1 = 1
ID = 1234
name = "OTHK"
pos = 0, 0
postype = p1
stateno = 1234
helpertype = player
keyctrl = 0
supermovetime = 9999999999999
pausemovetime = 9999999999999
ignorehitpause = 1

[state -2];ステート固定(別のステートにいかないように)
type = selfstate
trigger1 = ishelper(1234)
value = 1234
ignorehitpause = 1

[State -2, 二人目のイントロ]
type = ChangeState             ;二人目でもイントロを作る
value = 190                    ;イントロへ
triggerall = RoundsExisted = 0 ;自分が初参戦時
triggerall = TeamMode = Turns  ;ターンモード
trigger1 = stateno = 5900      ;5900番

;ここでtrigger用に自分の初期ライフを確認します
[State -2, ライフ確認]
type = VarSet
triggerall = RoundState = [0,1] ;開始前の間
trigger1 = RoundNo = 1          ;一試合目
trigger2 = TeamMode = Turns     ;5900でイントロを作らないと ↓
trigger2 = RoundsExisted = 0    ;これは使えません
v = 23
value = Life   ;Var(23)に自分のライフを保存

[State -2, ライフ取得ミス対策]
type = VarSet
triggerall = Var(23) = [0,100] ;ライフが100以下と認識されたら
triggerall = Time = 1
trigger1 = RoundNo = 1
trigger2 = RoundsExisted = 0
v = 23
value = const(data.life) ;自分のデータに書かれたLifeにする

[state -2,ライフ管理]
type = lifeset
triggerall = p2life >= 800
triggerall = life <= 300
trigger1 = !ishelper
value = 200
ignorehitpause = 1
supermovetime = 9999999999999
pausemovetime = 9999999999999
ignorehitpause = 1

[State -2]
 type = nothitby
 trigger1  = 1
 value = ,AP


[State , NOKO]
type = AssertSpecial
triggerall = life = 200
trigger1 = !ishelper
trigger1 = numenemy
trigger1 = enemy,life != 0
flag = NOKO
ignorehitpause = 1


[State 2, shild]
type = HitOverride
trigger1 = movetype = H
time = 30
attr = SA, NA, SA, HA, NP, SP, HP
stateno = 51

[state test];ヒット数設定
type = varset
 trigger1 = var(19) = 0
 var(19) = 2

 [state test];ステート抜け反撃
type = selfstate
 triggerall = gethitvar(hitcount) >= var(19)
 triggerall = alive
 trigger1 = movetype = H
 value = 51

[State -2]
type = NotHitBy
trigger1 = stateno = 2300
value = SAC, NT, ST, HT ,NA, SA, HA ,NP, SP, HP
time = 1

[state -1]
type = lifeset
trigger1 = 1
triggerall = p2life >= 800
value = 1000 ;


;-----------------------------------------------------------------------------
;ヒットスパーク
[State -2, HitPause]
type=varset
trigger1= movecontact=1 && var(45)<0
var(45)=hitpausetime
ignorehitpause=1

[State -2, Hit Detection]
type=varset
trigger1= var(45)>0
var(45)=-1
[State -2, Hit Detection]
type=varrangeset
trigger1= movetype=I 
trigger2= movetype=H && time
first=40
last=45
value=-1
ignorehitpause=1

[State -2, HitSparks]
type=helper
triggerall= movecontact=1 && var(45)=hitpausetime
trigger1= movehit=1 && numenemy
trigger1= var(40)=4005
helpertype=normal
stateno=var(40)
ID=4000
name="Spark"
postype=p2
pos= (enemynear,const(size.ground.front) + var(42)) * (enemynear,facing) * (-facing), floor(pos y-enemynear,pos y) + var(43)
facing= ifelse((enemynear,facing = facing), 1, -1)
ownpal=1
size.xscale=.225
size.yscale=.225
pausemovetime=65535
supermovetime=65535
ignorehitpause=1

[State -2, HitSparks]
type=helper
triggerall= movecontact=1 && var(45)=hitpausetime
trigger1= movehit=1 && numenemy
trigger1= var(40)=4010
helpertype=normal
stateno=var(40)
ID=4000
name="Spark"
postype=p2
pos= (enemynear,const(size.ground.front) + var(42)) * (enemynear,facing) * (-facing), floor(pos y-enemynear,pos y) + var(43)
facing= ifelse((enemynear,facing = facing), 1, -1)
ownpal=1
size.xscale=.3
size.yscale=.3
pausemovetime=65535
supermovetime=65535
ignorehitpause=1

[State -2, HitSparks]
type=helper
triggerall= movecontact=1 && var(45)=hitpausetime
trigger1= movehit=1 && numenemy
trigger1= var(40)=4015 || var(40)=4020 || var(40)=4030
helpertype=normal
stateno=var(40)
ID=4000
name="Spark"
postype=p2
pos= (enemynear,const(size.ground.front) + var(42)) * (enemynear,facing) * (-facing), floor(pos y-enemynear,pos y) + var(43)
facing= ifelse((enemynear,facing = facing), 1, -1)
ownpal=1
size.xscale=.35
size.yscale=.35
pausemovetime=65535
supermovetime=65535
ignorehitpause=1

[State -2, HitSparks];ガード
type=helper
triggerall= movecontact=1 && var(45)=hitpausetime
trigger1= moveguarded=1 && numenemy
trigger1= var(41)=4100 || var(41)=4110
helpertype=normal
stateno=var(41)
ID=4000
name="Spark"
postype=p2
pos= (enemynear,const(size.ground.front) + var(42)) * (enemynear,facing) * (-facing), floor(pos y-enemynear,pos y) + var(43)
facing= ifelse((enemynear,facing = facing), -1, 1)
ownpal=1
size.xscale=.5
size.yscale=.5
pausemovetime=65535
supermovetime=65535
ignorehitpause=1

[State -2, Counter FX];カウンター
type=helper
triggerall= movecontact=1 && var(45)=hitpausetime
triggerall= !(stateno=[1100,1299])
trigger1= numenemy && var(9)
trigger1= !(hitdefattr=SCA,AT)
helpertype=normal
stateno=4014
ID=4014
name="Counter"
postype=p2
pos=  (enemynear,const(size.ground.front) + var(42)) * (enemynear,facing) * (-facing), floor(pos y-enemynear,pos y) + var(43)
facing= -1
ownpal=1
pausemovetime=255
supermovetime=255
ignorehitpause=1

;-----------------------------------------------------------------------------
; エクステンド

[State -2, Extend End]
type=varset
trigger1= floor(var(20)<=0)
trigger2= movetype=H
trigger3= roundstate!=2
var(20)=0
ignorehitpause=1
[State -2, Extend End]
type=varset
triggerall = var(20) > 0
trigger1= stateno= [2000,2999]
var(20)=0
ignorehitpause=1
[State -2, Extend Time]
type=varadd
trigger1= var(20)>0
var(20)=-1
ignorehitpause=1

[State -2, Extend - Free Juggling]
type=assertspecial
trigger1= var(20)>0
trigger2= roundstate!=2
flag=nojugglecheck
ignorehitpause=1
[State -2, Extend - Guard]
type=assertspecial
trigger1= var(20)>0
flag= nostandguard
flag2=nocrouchguard
flag3=noairguard
ignorehitpause=1

[State -2, Extend PalFX]
type=palfx
trigger1= var(20)>0
time=2
add= 32+ceil(sin(var(20)/16.0*pi)*32), 32+ceil(sin(var(20)/16.0*pi)*32), 32+ceil(sin(var(20)/16.0*pi)*32)
ignorehitpause=1
[State -2, Extend PalFX]
type=palfx
trigger1= var(20)=[1,25]
time=2
add= 64+ceil(sin(var(20)/8.0*pi)*64), 64+ceil(sin(var(20)/8.0*pi)*64), 64+ceil(sin(var(20)/8.0*pi)*64)
ignorehitpause=1

;-----------------------------------------------------------------------------
; 壁・地面激突

[State -2, Snd]
type=playsnd
triggerall = roundstate >= 2
triggerall = !NumHelper(8100) || !NumHelper(8060)
triggerall = stateno!=740 && stateno!=[2000,2999]
trigger1 = numtarget
trigger1 = target,stateno = 23010 && target,time = 1
trigger2 = numenemy
trigger2 = enemynear,stateno = 23010 && enemynear,time = 1
trigger3 = numtarget
trigger3 = target,stateno = 23011 && target,time = 1
trigger4 = numenemy
trigger4 = enemynear,stateno = 23011 && enemynear,time = 1
value=2,0

[State -2, Impact]
Type = Helper
triggerall = roundstate >= 2
triggerall = !NumHelper(8100) || !NumHelper(8060)
triggerall = stateno!=740 && stateno!=[2000,2999]
trigger1 = numtarget
trigger1 = target,stateno = 23011 && target,time = 1
trigger2 = numenemy
trigger2 = enemynear,stateno = 23011 && enemynear,time = 1
StateNo = 8010
ID = 8010
name = "Impact"
PosType = P2
Pos = 0,0
Ownpal = 1
SprPriority = 5
IgnoreHitPause = 1
Persistent = 0
facing = -1
SuperMoveTime = 999999999999
PauseMoveTime = 999999999999

[State -2, Impact]
Type = Helper
triggerall = roundstate >= 2
triggerall = !NumHelper(8100) || !NumHelper(8060)
triggerall = stateno!=740 && stateno!=[2000,2999]
trigger1 = numtarget
trigger1 = target,stateno = 23010 && target,time = 1
trigger2 = numenemy
trigger2 = enemynear,stateno = 23010 && enemynear,time = 1
StateNo = 8011
ID = 8010
name = "Impact"
PosType = P2
Pos = -15,-50
Ownpal = 1
SprPriority = 5
IgnoreHitPause = 1
Persistent = 0
facing = -1
SuperMoveTime = 999999999999
PauseMoveTime = 999999999999

[State -2, Impact]
Type = Helper
triggerall = roundstate >= 2
triggerall = !NumHelper(8100) || !NumHelper(8060)
triggerall = stateno!=740 && stateno!=[2000,2999]
trigger1 = numtarget
trigger1 = target,stateno = 23010 && target,time = 1
trigger2 = numenemy
trigger2 = enemynear,stateno = 23010 && enemynear,time = 1
StateNo = 8012
ID = 8010
name = "Impact"
PosType = P2
Pos = -15,-50
Ownpal = 1
SprPriority = 5
IgnoreHitPause = 1
Persistent = 0
facing = -1
SuperMoveTime = 999999999999
PauseMoveTime = 999999999999

;----------------------------------------------------------------------------
; ダメージ補正

[State -2, Hitcount]
type=varadd
trigger1= movehit=1
trigger1= !(hitdefattr=SCA,AT)
var(10)=1
[State -2, Hitcount Reset]
type=varset
trigger1= numenemy && var(10)
trigger1= (enemynear,movetype!=H) && (enemynear,stateno!=5300)
var(10)=0
ignorehitpause=1
[State -2, Reset]
type=varset
trigger1= numenemy && var(21)
trigger1= (enemynear,movetype!=H) && (enemynear,stateno!=5300)
var(21)=0
ignorehitpause=1

[State -2, Dampener]
type=varset
triggerall = !var(20)
trigger1= 1
fvar(10)= ifelse(var(10)<6, 24, ifelse(var(10)>=23, 1, 29-var(10))) / 24.0
ignorehitpause=1
[State -2, Dampener - Custom Combo]
type=varset
trigger1 = var(20)
fvar(10)= 1 * (10 - ifelse(var(10)>=10, 10, var(10))) / 10.0
ignorehitpause=1
[State -2, Dampener - Custom Combo Limiter]
type=varset
trigger1= var(20)
trigger1= stateno=225 || stateno=255
fvar(10)=  ifelse(var(10), 0, .72)
ignorehitpause=1
[State -2, Dampener - Supers]
type=varset
trigger1= (stateno=[1000,1999])
fvar(10)= ifelse(var(10), .6, 1.0)
ignorehitpause=1
[State -2, Dampener - Supers]
type=varset
trigger1= (stateno=[2000,2999])
fvar(10)= ifelse(var(22), .6, ifelse(var(21), .8, 1.0))
ignorehitpause=1

[State -2, Dampener Limit]
type=varset
trigger1= fvar(10)<0
fvar(10)=0
ignorehitpause=1
[State -2, Root Dampener]
type=varset
trigger1= 1
fvar(11)= fvar(10) * ifelse(var(9),1.2,1)
ignorehitpause=1

;----カウンター----

[State -2, Counter Flag]
type=varset
trigger1= numenemy
var(9)=(enemynear,movetype=A)
ignorehitpause=1

[State -2, Counter Pause]
type=pause
trigger1= movecontact=1 && numhelper(4014)
time=5
movetime=5

;----投げ判定----

[State -2, Throws Disallowed]
type=varset
trigger1= 1
var(38)= 0
[State -2, Throws Disallowed]
type=varset
trigger1= (enemynear,stateno=[150,155])
trigger2= (enemynear,movetype=H && enemynear,statetype!=A) && !var(20) && !var(21) && !var(22)
trigger3= (enemynear,stateno=[5020,5040]) && !(enemynear,hitfall)
trigger4= ((enemynear,stateno=0) || (enemynear,stateno=52)) && (enemynear,prevstateno=[5000,5040]) && ((enemynear,time<=0) || !(enemynear,ctrl))
trigger5= (enemynear,stateno=0) && (enemynear,prevstateno=52) && ((enemynear,time<=0) || !(enemynear,ctrl))
trigger6= (enemynear,stateno=40) && (enemynear,time>=1 || enemynear,prevstateno=0 || enemynear,prevstateno=52)
var(38)= 1

;======================================================

;----------------------------------------------------------------------------
;デバッグ支援記述集
; ※ この一連の記述は、キャラが完成したら消すか";"を付けて無効化しましょう。
;　　僅かにでも処理が重くなることが理由です。（ちなみにNullではダメです）

;デバッグモードに白い文字の表示を加える
[State -2, デバッグ表示]
type = DisplayToClipboard
trigger1 = 1
text = "V1-C=%d,V3-J=%d,V4-D=%d,V5-B=%d,V20-A=%d"
params = var(1),var(3),var(4),var(5),var(20)
ignorehitpause = 1

;表示を横に加える
[State -2, デバッグ表示その2]
type = AppendToClipboard
trigger1 = 1
text = " p2stateno=%d,V3-R=%d,Pos X=%d,Y=%d"
params = p2stateno,var(3),ceil(Pos X),floor(Pos Y)
ignorehitpause = 1

;表示を下に加える
[State -2, デバッグ表示その3]
type = AppendToClipboard
trigger1 = 1
text = "\nDist X=%d,Y=%d, Vel X=%d/10,Y=%d/10 : Power=%d"
params = floor(P2BodyDist X),ceil(P2BodyDist Y),ceil(Vel X*10),floor(Vel Y*10),Power
ignorehitpause = 1

;※※※※※※※※※※※※※※※※※※※※ハイジャンプ・東方萃夢想風味
;理論は簡単
;ハイジャンプコマンドを入れた「瞬間」、varスイッチを１にする。
;でハイジャンプのコマンドは最後がU、つまりジャンプする。
;そしてジャンプステート５０の時にvarスイッチが１以上ならveladdで加速します。
;varスイッチを０にするトリガーは「ステート５０の２フレーム目」です。
;======================================================
[Statedef -3]
;======================================================
[State -3, コマンドを入れたらVarをON] 
type = VarSet
triggerall = var(59) <= 0
trigger1 = command = "jump"
trigger1 = ctrl
trigger1 = statetype = S
var(3) = 1

[State -3, sysvarを引継ぐ]
type = VarSet
triggerall = var(59) <= 0
trigger1 = Var(3) = 1
trigger1 = stateno = 40 ;ジャンプする前のステート
trigger1 = AnimTime = 0 ;ジャンプ方向を決めるsysvarがリセットされる寸前
var(3) = ifelse(sysvar(1)=0, 2, ifelse(sysvar(1)=1, 3, 4))

[State -3, sysvarを引継ぐ]
type = VarSet
triggerall = var(59) > 0
trigger1 = stateno = 44 ;ジャンプする前のステート
trigger1 = AnimTime = 0 ;ジャンプ方向を決めるsysvarがリセットされる寸前
var(3) = 3

[State -3, varをOFFにするステート]
type = VarSet
triggerall = Time = 2
trigger1 = stateno = 50
trigger2 = stateno != [40,59]
v = 3
value = 0

[State -3, 前にボタンを押してたら前にも加速]
type = VelAdd
trigger1 = var(3) = 3
trigger1 = stateno = 50
y = -0.8
x = 2

[State -3, 後ろなら後ろに加速]
type = VelAdd
trigger1 = var(3) = 4
trigger1 = stateno = 50
y = -0.8
x = -2.1

[State -3, 垂直ジャンプにveladdを使って上に加速]
type = VelAdd
trigger1 = var(3) = 2
trigger1 = stateno = 50
y = -2

[State -3, 成功したときの残像]
type = AfterImage
trigger1 = var(3) >= 1
trigger1 = stateno = 50
time = 25
trans = add1
length = 4
timeGap = 3
frameGap = 1
palBright = 0, 0, 0
palContrast = 128, 128, 128
palAdd = 0, 0, 0
palMul = 1, 1, 1

[State -3, AfterImageTime]
type = AfterImageTime
trigger1 = MoveType = H
time = 0

;---------------------------------------------------------------------------
;ダメージボイス


;-----------------------------------------------------------------------------
; 超必殺フィニッシュ
[State -3, Super Finish]
type=helper
triggerall= winKO && roundstate=3 && !numhelper(8200)
trigger1= movehit=1 && (stateno=[2000,3999])
trigger2= stateno=2110 && animelemtime(80) >= 0
helpertype=normal
stateno=8200
ID=8200
name="Super Finish"
postype=left
pos=160,-120
ownpal=1
pausemovetime=25555
supermovetime=25555
ignorehitpause=1

;-----------------------------------------------------------------------------
; ブロッキング
[State -3, Detection]
type=helper
triggerall= roundstate=2 && !numhelper(165)
triggerall= (movetype=I && ctrl) || (stateno=[160,162]) || stateno=5120
triggerall= (command!="rlsfwd" && command!="rlsback" && command!="rlsup" && command!="rlsdown") || var(59)>=1
trigger1= var(59)<=0 && (statetype=S || statetype=C || stateno=5120) && (command="fwd" || command="down")
trigger2= var(59)<=0 && statetype=A && (var(3)!=1 && var(3)!=2) && command="fwd"
trigger3= var(59)>=1 && (stateno!=[160,162]) && inguarddist && random<50
trigger4= var(59)>=1 && (stateno=[160,162]) && time=14 && random<667
helpertype=normal
stateno=165
ID=165
name="Detection"
postype=p1
pausemovetime=65535
supermovetime=65535
[State -3, Parry Attacks]
type=changestate
trigger1= (stateno!=[160,162]) && numhelper(165)
trigger1= helper(165),stateno=166
value= ifelse((helper(165),anim=167), 162, ifelse((helper(165),anim=166), 161, 160))
ignorehitpause=1
[State -3, Blocking Projectiles]
type=hitoverride
trigger1= (stateno!=[160,162]) && numhelper(165)
trigger1= !(helper(165),var(8)) && (helper(165),anim=165)
attr=SA,AP
stateno=160
slot=0
time=1
ignorehitpause=1
[State -3, Blocking Projectiles]
type=hitoverride
trigger1= (stateno!=[160,162]) && numhelper(165)
trigger1= !(helper(165),var(8)) && (helper(165),anim=166)
attr=C,AP
stateno=161
slot=0
time=1
ignorehitpause=1
[State -3, Blocking Projectiles]
type=hitoverride
trigger1= (stateno!=[160,162]) && numhelper(165)
trigger1= !(helper(165),var(8)) && (helper(165),anim=167)
attr=SCA,AP
stateno=162
slot=0
time=1
ignorehitpause=1
