actor Knightman_W : BaseMM8BDMWep_CBM
{
tag "$TAGC_6D"
dropitem "KnightCrushWep"
Weapon.AmmoUse 0
Weapon.AmmoGive 28
Obituary "$OB_KNIGHTCRUSH"
weapon.ammotype "TisButAScratchAmmo"
States
{
Spawn:
C_06 D 1
loop

Deselect:
KNIA A 0 A_GiveInventory("StopShield",1)
goto DeselectSwap
Select:
KNIA A 0
goto SelectSwap

Ready:
KNIA A 1 ACS_NamedExecuteWithResult("core_weaponcolor",DYE_KNIGHTMAN)
Ready0:
KNIA A 0 A_TakeInventory("StopShield",9)
KNIA A 0 A_GunFlash("Flash",1)
Goto Ready1
Ready1:
KNIA A 0 A_JumpIfInventory("TisButAScratchAmmo",28,"Ready2")
KNIA A 3 A_WeaponReady(8)
KNIA A 0 A_GiveInventory("TisButAScratchAmmo",1)
loop
Ready2:
KNIA A 3 A_WeaponReady
KNIA A 0 A_GiveInventory("TisButAScratchAmmo",1)
loop

Fire:
KNIA B 0 A_PlaySoundEx("weapon/KnightShot","Weapon")
KNIA B 0 A_GiveInventory("StopShield",1)
KNIA B 3 A_GiveInventory("VivifyFlag1",1)
KNIA C 0 A_TakeInventory("KnightDouble",1)
KNIA C 3 A_FireCustomMissile("KnightM_Crusher",0,0,-8,0)
KNIA D 6
Goto Check

Check:
KNIA D 0 A_JumpIfInventory("KnightDouble",1,"Return")
KNIA D 1 A_GiveInventory("KnightFlag",1)
KNIA D 0 A_JumpIfInventory("KnightFlag",35,"Return")
loop

Return:
KNIA D 2 A_TakeInventory("VivifyFlag1")
KNIA C 2
KNIA B 4 A_TakeInventory("KnightFlag")
Goto Ready0

AltFire:
KNIA A 0 A_JumpIfInventory("TisButAScratchAmmo",28,"ShieldCharge")
goto Ready1
//KNIA H 4 //A_ChangeVelocity(Cos(pitch)*79,-14,-sin(pitch)*48,1)//A_SetAngle(45)
ShieldCharge:
KNIA G 0 A_GiveInventory("VivifyDelay7",1)
KNIA G 0 A_Refire(1)
KNIA G 0 A_TakeInventory("TisButAScratchAmmo",7)
KNIA G 0 A_TakeInventory("TisButAScratchAmmo",21,1)
KNIA G 2 ACS_NamedExecuteWithResult("core_stopplayer",0,1)
KNIA G 0 A_PlaySoundEx("weapon/chargekick","Weapon")
KNIA G 0 A_GiveInventory("StopShield",1)
KNIA G 0 ACS_NamedExecuteWithResult("core_invulnerableplayer",0,1)
KNIA H 1 A_ChangeVelocity(Cos(pitch)*6,0,-sin(pitch)*3,1)//A_Recoil(-6)
KNIA H 0 A_FireCustomMissile("KnightRush")
KNIA H 0 A_Blast(BF_NOIMPACTDAMAGE,255,192,20.0,"KnightmanBlastFX")
KNIA H 1 A_ChangeVelocity(Cos(pitch)*6,0,-sin(pitch)*3,1)
KNIA H 0 A_FireCustomMissile("KnightRush")
KNIA H 0 A_Blast(BF_NOIMPACTDAMAGE,255,192,20.0,"KnightmanBlastFX")
KNIA H 1 A_ChangeVelocity(Cos(pitch)*6,0,-sin(pitch)*3,1)
KNIA H 0 A_FireCustomMissile("KnightRush")
KNIA H 0 A_Blast(BF_NOIMPACTDAMAGE,255,192,20.0,"KnightmanBlastFX")
KNIA H 1 A_ChangeVelocity(Cos(pitch)*6,0,-sin(pitch)*3,1)
KNIA H 0 A_FireCustomMissile("KnightRush")
KNIA H 0 A_Blast(BF_NOIMPACTDAMAGE,255,192,20.0,"KnightmanBlastFX")
KNIA G 1 ACS_NamedExecuteWithResult("core_stopplayer",0,0)
KNIA G 0 ACS_NamedExecuteWithResult("core_invulnerableplayer",0,0)
KNIA G 0 A_TakeInventory("StopShield",9)
KNIA G 3 A_GunFlash("Flash",1)
Goto Ready1

Flash:
TNT1 A 1 A_GiveInventory("KnightShieldHitbox_P",1)
stop
}
}

actor TisButAScratchAmmo : Ammo
{
inventory.amount 1
inventory.maxamount 28
+INVENTORY.IGNORESKILL
}

actor KnightM_CrusherCheck_P : CustomInventory
{
States
{
Pickup:
//TNT1 A 0 A_SpawnItemEx("KnightM_CrusherPrang",0,0,-12,0,0,0,0,32)
//TNT1 A 0 A_SpawnItemEx("KnightM_CrusherPrang",sqrt(momx*momx+momy*momy)*0.5,0,momz*0.5-12,0,0,0,0,32+8)
TNT1 A 0 A_SpawnItemEx("KnightM_CrusherPrang",0,0,0,momx,momy,momz,0,32+8)
stop
}
}


actor KnightmanBlastFX : BasicGraphicEffect
{
States
{
Spawn:
TNT1 A 0
TNT1 A 1
stop
}
}

actor KnightM_Crusher : ProjSpawnFuncActor
{
var int user_TranslateBlackColors;
PROJECTILE
damagetype "KnightM_Mace"
Obituary "$OB_KNIGHTCRUSH"
+RIPPER
+NOTARGETSWITCH
+SKYEXPLODE
//+DONTSPLASH
+THRUGHOST
+FORCEXYBILLBOARD
+BOUNCEONFLOORS
+BOUNCEONWALLS
+BOUNCEONCEILINGS
+ALLOWBOUNCEONACTORS
+CANBOUNCEWATER
BounceFactor 1.0
WallBounceFactor 1.0
damage (0)
Radius 8
Height 8
speed 40
scale 2.5
States
{
Spawn:
KNIA I 0
KNIA II 1 A_GiveInventory("KnightM_CrusherCheck_P")
KNIA I 0 A_ChangeFlag("THRUGHOST",0)
KNIA IIIIIIII 1 A_GiveInventory("KnightM_CrusherCheck_P")
KNIA I 0 A_TakeFromTarget("KnightFlag",999)
KNIA IIIIIIII 1 A_GiveInventory("KnightM_CrusherCheck_P")
KNIA I 0 A_SpawnItemEx("KnightM_CrusherReturn",0,0,0,0,0,0,0,1)
stop
Death:
KNIA I 0 A_GiveToTarget("KnightDouble",1)
KNIA I 0 A_TakeFromTarget("KnightFlag",999)
stop
}
}

actor KnightReturnerSound : BasicHelper
{
States
{
Spawn:
TNT1 A 0
TNT1 A 1 A_PlaySoundEx("weapon/KnightReturn","Weapon")
stop
}
}

actor KnightM_CrusherReturn : KnightM_Crusher
{
+NOINTERACTION
+SEEKERMISSILE
ReactionTime 87//about 10 seconds
States
{
Spawn:
KNIA I 0
KNIA I 0 A_RearrangePointers(0,0,2)
KNIA I 0 A_FaceTarget
goto Spawn2
Spawn2:
KNIA I 0 A_TakeFromTarget("KnightFlag",99)
KNIA I 0 A_JumpIfCloser(46,"Death")
KNIA I 0 A_SpawnItemEx("KnightReturnerSound")
KNIA II 0 A_SeekerMissile(90,90,SMF_PRECISE)
KNIA I 1 A_GiveInventory("KnightM_CrusherCheck_P")
KNIA I 0 A_JumpIfCloser(46,"Death")
KNIA I 1 A_GiveInventory("KnightM_CrusherCheck_P")
KNIA I 0 A_JumpIfCloser(46,"Death")
KNIA I 1 A_GiveInventory("KnightM_CrusherCheck_P")
KNIA I 0 A_JumpIfCloser(46,"Death")
KNIA I 1 A_GiveInventory("KnightM_CrusherCheck_P")
KNIA I 0 A_JumpIfCloser(46,"Death")

KNIA I 0 A_CountDown
KNIA I 0 A_JumpIf(!CallACS("cbm_PointerExists",AAPTR_TARGET),"Death")
loop
}
}

actor KnightM_CrusherPrang
{
PROJECTILE
damagetype "KnightM_Mace"
Obituary "$OB_KNIGHTCRUSH"
+RIPPER
+THRUGHOST
+DONTBLAST
+DONTSPLASH
Renderstyle None
damage (80+CallACS("core_checkrune",RUNE_RAGE,2)*40)//110
radius 12
height 12//24
Scale 1.0
States
{
Spawn:
TNT1 A 2
stop
/*
Death:
TNT1 A 0 A_Explode(80,24,0,0,24)
stop
*/
}
}

actor KnightShieldHitbox_P : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_SpawnItemEx("KnightShieldHitbox1",28,-7,8,0,0,0,0,1)
TNT1 A 0 A_SpawnItemEx("KnightShieldHitbox2",28,1,8,0,0,0,0,1)
TNT1 A 0 A_SpawnItemEx("KnightShieldHitbox3",28,9,8,0,0,0,0,1)
TNT1 A 0 A_SpawnItemEx("KnightShieldHitbox4",28,17,8,0,0,0,0,1)
TNT1 A 0 A_SpawnItemEx("KnightShieldHitbox5",28,25,8,0,0,0,0,1)
TNT1 A 0 A_SpawnItemEx("KnightShieldHitbox6",20,25,8,0,0,0,0,1)
TNT1 A 0 A_SpawnItemEx("KnightShieldHitbox7",12,25,8,0,0,0,0,1)
stop
}
}

actor KnightShieldHitbox1 : BasicShieldHitbox
{
Meleerange 28
Accuracy -7
Mass 8
states
{
Pain:
TNT1 A 0 
TNT1 A 0 A_SpawnItemEx("KnightShieldDeathFX")
TNT1 A 0 A_PlaySound("item/protoreflect")
goto Spawn
}
}
actor KnightShieldHitbox2 : KnightShieldHitbox1
{
Accuracy 1
}
actor KnightShieldHitbox3 : KnightShieldHitbox1
{
Accuracy 9
}
actor KnightShieldHitbox4 : KnightShieldHitbox1
{
Accuracy 17
}
actor KnightShieldHitbox5 : KnightShieldHitbox1
{
Accuracy 25
}
actor KnightShieldHitbox6 : KnightShieldHitbox5
{
Meleerange 20
}
actor KnightShieldHitbox7 : KnightShieldHitbox5
{
Meleerange 12
}

actor KnightShieldDeathFX : BasicGraphicEffect
{
+BRIGHT
alpha 0.9
renderstyle add
states
{
SpawnFrame:
KNIA L 0 A_SetScale(scaleX + 0.1, 2.5) 
KNIA L 1 A_FadeOut(0.05)
loop
}
}

actor PainKnightM_PushHit : Basic_PainFling_H{Args 8,0,2}
actor DeathKnightM_PushHit : Basic_DeathFling_H{Args 30,44,0}

actor KnightRush : BasicImplosion
{
Damagetype "KnightM_Push"
Obituary "$OB_KNIGHTRUSH"
States
{
Spawn:
TNT1 A 0
TNT1 A 1 A_Explode(50,120,0,0,16)
stop
}
}

actor Knightman_W_NormalBar : NormalBar {Args 87,198}