actor Waveman_W : BaseMM8BDMWep_CBM
{
tag "$TAGC_5B"
dropitem "WavemanWepDroppedX"
Weapon.AmmoUse 4
Weapon.AmmoGive 28
Weapon.AmmoGive2 750
Obituary "$OB_WATERWAVE"
weapon.ammotype "GeorgeOfTheSeasAmmo"
weapon.ammotype2 "HookshotStamina"
+WEAPON.NOAUTOAIM
States
{
Spawn:
C_05 B 1
loop

Deselect:
WAVA A 0
goto DeselectSwap
Select:
WAVA A 0
goto SelectSwap

Ready:
WAVA A 0 ACS_NamedExecuteWithResult("core_weaponcolor",DYE_WAVEMAN)
WAVA A 0 A_GunFlash("Flash",1)
goto Ready2
Ready1:
WAVA A 0 A_JumpIfInventory("GeorgeOfTheSeasAmmo",4,"Ready2")
WAVA A 14 A_WeaponReady(WRF_NOPRIMARY)
goto Ready3
Ready2:
WAVA A 10 A_WeaponReady
goto Ready4
Ready3:
WAVA A 0 A_JumpIfInventory("IsBot",1,"Ready4")
WAVA A 0 A_JumpIfInventory("GeorgeOfTheSeasAmmo",4,"Ready4")
WAVA A 4 A_WeaponReady(WRF_NOPRIMARY)
WAVA A 0 A_GiveInventory("GeorgeOfTheSeasAmmo",1)
goto Ready3+1
Ready4:
WAVA A 4 A_WeaponReady
WAVA A 0 A_GiveInventory("GeorgeOfTheSeasAmmo",1)
loop

Fire:
WAVA E 0 A_JumpIfInventory("IsBot",1,"BotFire")
WAVA E 0 A_JumpIfNoAmmo("NoAmmo")
WAVA E 0 A_GiveInventory("VivifyDelay6",1)
WAVA E 0 A_Refire(1)
WAVA E 0 A_PlaySoundEx("weapon/waterwave","Weapon")
WAVA E 0 A_TakeInventory("GeorgeOfTheSeasAmmo",4,1)
WAVA FFFGGG 2 A_FireCustomMissile("PinpointWaterWaveSpawner",0,0,-8,0)
WAVA E 8
WAVA E 0 A_Refire
Goto Ready1
NoAmmo:
WAVA E 0
Goto Ready1

Altfire:
WAVA B 0 A_PlaySoundEx("weapon/mbuster","Weapon")
WAVA B 0 A_GiveInventory("GeorgeOfTheSeasAmmo",1)
WAVA B 0 A_FireCustomMissile("WaveHarpoon",0,0,8,0)
WAVA CD 3
WAVA B 3
WAVA B 7 A_GiveInventory("GeorgeOfTheSeasAmmo",1)
WAVA B 0 A_Refire
Goto Ready3

BotFire:
WAVA A 0 A_JumpIfInventory("GeorgeOfTheSeasAmmo",28,"BotFire2")
WAVA A 0 A_Jump(128,"AltFire")
WAVA A 0 A_JumpIfInventory("GeorgeOfTheSeasAmmo",4,"BotFire2")
WAVA A 0 A_Jump(32,"BotFire3")
goto Altfire
BotFire2:
WAVA A 0
goto Fire+1
BotFire3:
WAVA A 0 A_GiveInventory("GeorgeOfTheSeasAmmo",12)
goto Altfire

/*
AltFireHook:
//WAVA B 0 A_JumpIfInventory("IsBot",1,"BotFire")
WAVA B 0 A_TakeInventory("HookshotTired",9)
WAVA B 0 A_JumpIfInventory("HookshotStamina",200,1)
goto Altfire
WAVA B 0 A_PlaySoundEx("weapon/mbuster","Weapon")
WAVA B 0 A_GiveInventory("WavemanAltDelay",1)
WAVA B 0 A_GiveInventory("HookshotFiredFlag",1)
WAVA B 0 A_GunFlash("Flash",1)
WAVA B 0 A_GiveInventory("GeorgeOfTheSeasAmmo",1)
WAVA B 0 A_SpawnItemEx("WaveHarpoonHook",-2,8,32,cos(-pitch)*1,0,sin(-pitch)*1,0,1)
Goto AltFire3
AltFire3:
WAVA B 0 A_JumpIfInventory("HookshotTired",1,"AltFireEnd")
WAVA B 1 //A_PlaySoundEx("weapon/WireAdp","weapon")
WAVA B 0 A_ReFire("AltFire3")
goto AltFireEnd
AltFireEnd:
WAVA B 0 A_TakeInventory("HookshotFiredFlag",9)
WAVA B 0 A_GiveInventory("HookshotTired",1)
WAVA BC 3
WAVA A 0 A_ClearReFire
WAVA A 1 A_GunFlash("Flash",1)
Goto AltFireWait
AltFireWait:
WAVA A 1 A_RailWait
WAVA A 0 A_JumpIfInventory("WavemanAltDelay",1,"AltFireWait")
goto Ready1
*/

Flash:
TNT1 A 0
TNT1 A 1
TNT1 A 0 A_JumpIfInventory("WaveHookNeedLand",1,"FlashCheck")
TNT1 A 0 A_GiveInventory("HookshotStaminaFlash_P",1)
loop
FlashCheck:
TNT1 A 0 A_JumpIf(z-floorz==0,"FlashChecked")
TNT1 A 0 A_JumpIf(momz==0,"FlashCheckZ")
TNT1 A 0
TNT1 A 1
loop
FlashCheckZ:
TNT1 A 1
TNT1 A 0 A_JumpIf(z-floorz==0,"FlashChecked")
TNT1 A 0 A_JumpIf(momz==0,"FlashChecked")
TNT1 A 0
TNT1 A 0
goto FlashCheck
FlashChecked:
TNT1 A 0 A_TakeInventory("WaveHookNeedLand",1)
goto Flash
}
}

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

actor HookshotStamina : Ammo
{
inventory.amount 1
inventory.maxamount 750
+INVENTORY.IGNORESKILL
}


actor WaveHookWasFired : OnceC {}

actor WaveHookIsAlive : Powerup
{
Powerup.Duration 6
}

actor WaveHookNeedLand : OnceC {}

actor WaveHookKillFlag : OnceC {}

actor HookshotStaminaFlash_P : CustomInventory
{
States
{
Pickup:
TNT1 A 0 A_JumpIfInventory("WaveHookNeedLand",1,"No")
TNT1 A 0 A_JumpIfInventory("WaveHookWasFired",1,"No")
TNT1 A 0 A_JumpIfInventory("WaveHookIsAlive",1,"No")
TNT1 A 0 A_JumpIfInventory("HookshotStamina",750,"No")
TNT1 A 0 A_GiveInventory("HookshotStamina",1+CallACS("core_checkrune",RUNE_RAGE))
goto GiveAmmo
No:
TNT1 A 0
stop
}
}

actor WavemanHookshotItem : BasicClassItem
{
inventory.icon "HARPK"
inventory.pickupmessage "This hook is original content, do not steal."
tag "OC Wire Adaptor"
states
{
Spawn:
HARP K 1
loop

UseCBM:
TNT1 A 0 A_JumpIfInventory("WaveHookWasFired",1,"KillHook")
TNT1 A 0 A_JumpIfInventory("HookshotStamina",200,"Success")
fail

Success:
TNT1 A 0 A_JumpIfInventory("WaveHookIsAlive",1,"No")
TNT1 A 0 A_GiveInventory("WaveHookIsAlive",1)
TNT1 A 0 A_TakeInventory("HookshotStamina",25)
TNT1 A 0 A_GiveInventory("WaveHookWasFired",1)

TNT1 A 0 A_PlaySoundEx("weapon/WireAdp","Item")

TNT1 A 0 A_SpawnItemEx("WaveHarpoonHook_Helper")
TNT1 A 0 A_SpawnItemEx("WaveHarpoonHook",-2,8,32,cos(-pitch)*1,0,sin(-pitch)*1,0,1)
fail
KillHook:
TNT1 A 0 A_TakeInventory("WaveHookWasFired",9)
TNT1 A 0 A_GiveInventory("WaveHookKillFlag",1)
fail
}
}

actor WavemanHookshotStart_P : CustomInventory
{
States
{
Pickup:
TNT1 A 0 //A_Stop
stop
}
}

actor WaveM_TakeHookshotAmmo_P : CustomInventory
{
States
{
Pickup:
TNT1 A 0 A_TakeInventory("HookshotStamina",1)
TNT1 A 0 A_TakeInventory("HookshotStamina",1,1)
stop
}
}

actor WaveHarpoonHook_Helper : BasicHelper
{
States
{
Spawn:
TNT1 A 0
TNT1 A 1 A_JumpIf(CallACS("core_targetexists")==0,"Death")
TNT1 A 0 A_JumpIfInTargetInventory("WaveHookWasFired",1,"Check")
stop
Check:
TNT1 A 0 A_JumpIfInTargetInventory("WaveHookIsAlive",1,"Spawn")
TNT1 A 0 A_TakeFromTarget("WaveHookWasFired",1)
stop
}
}

actor WaveHarpoonHook : ProjSpawnFuncActor
{
var int user_PTID;
PROJECTILE
damagetype "WaveM_Hook"
Obituary "$OB_WAVEHOOKSHOT"
+DONTBLAST
+DONTREFLECT
//+PAINLESS
//+SKYEXPLODE
//+EXPLODEONWATER
+THRUGHOST
+NOTIMEFREEZE
+HITTRACER
+FORCEALLYCOLLISION
ReactionTime 1
Damage (40*(CallACS("core_checkrune",RUNE_SPREAD,2)*2+1))
Radius 8
Height 8
Speed 1
scale 2.5
states
{
Spawn:
HARP H 0
HARP H 0 A_SetUserVar("user_PTID",CallACS("core_gettarget"))
HARP H 0 A_GiveInventory("WeaponCharge",1)
HARP H 0 A_ScaleVelocity(55)//Speed of projectile.
HARP H 0 ACS_NamedExecuteWithResult("cbm_drawhookshot", user_PTID, 18)
HARP H 0 A_TakeFromTarget("WaveHookKillFlag",1)
goto Spawn2

Spawn2:
HARP H 0 A_GiveToTarget("WaveHookIsAlive",1)
HARP H 0 A_JumpIfInTargetInventory("WaveHookKillFlag",1,"SpawnX")
HARP H 1 A_JumpIf(CallACS("core_targetexists")==0,"SuperDeath")
HARP I 0 A_JumpIfInTargetInventory("WaveHookKillFlag",1,"SpawnX")
HARP I 1 A_JumpIf(CallACS("core_targetexists")==0,"SuperDeath")
loop

SpawnX:
"####" "#" 0 A_PlaySoundEx("S3_K/MetalSpark","Weapon")
"####" "#" 0 A_GiveInventory("WaveHookKillFlag",1)
"####" "#" 0 A_ChangeFlag("HITTRACER",0)
"####" "#" 0 A_ChangeFlag("NOGRAVITY",0)
"####" "#" 0 A_GiveInventory("ResyncPickup",1)
"####" "#" 1
wait

Death:
HARP I 0
HARP I 0 A_JumpIfInventory("WaveHookKillFlag",1,"SuperDeath")
HARP I 0 A_JumpIfInTargetInventory("PlayerPropertyGrounded",1,"SuperDeath")
HARP I 0 A_JumpIfInventory("WeaponCharge",1,1)
goto SuperDeathPoof
HARP I 0 A_JumpIfInTargetInventory("WaveHookWasFired",1,1)
goto SuperDeathPoof
HARP I 0 A_JumpIfInTargetInventory("WaveHookKillFlag",1,"SuperDeathPoof")
HARP I 0 A_PlaySoundEx("weapon/crashland","Weapon")
HARP I 0 A_GiveToTarget("WavemanHookshotStart_P",1)
HARP I 0 A_JumpIfInventory("NoHookshot",1,"Death1",AAPTR_TRACER)
HARP I 0 A_JumpIf(CallACS("cbm_istracerplayer")==1,"Death2")
HARP I 0 A_CheckFlag("SHOOTABLE","Death2",AAPTR_TRACER)
goto Death1
Death1:
HARP I 0 ACS_NamedExecuteWithResult("cbm_WaveHookshot",user_PTID,3,0)
HARP I 3
goto DeathLoop1
Death2:
HARP I 0 ACS_NamedExecuteWithResult("cbm_WaveHookshot",user_PTID,3,1)
HARP I 3//Needs at least 3 tics of delay.
goto DeathLoop2

DeathLoop1://Sit
HARP I 0 A_GiveToTarget("WaveHookIsAlive",1)
HARP I 0 A_JumpIfInTargetInventory("WaveHookKillFlag",1,"SuperDeathPoof")
HARP I 1 A_JumpIf(CallACS("core_targetexists")==0,"SuperDeath")
loop
DeathLoop2://Stick to object, but stop when it doesn't exist
HARP I 0 A_Warp(AAPTR_TRACER,-4,0,28)
HARP I 0 A_GiveToTarget("WaveHookIsAlive",1)
HARP I 0 A_JumpIfInTargetInventory("WaveHookKillFlag",1,"SuperDeathPoof")
HARP I 0 A_JumpIf(CallACS("core_targetexists")==0,"SuperDeath")
HARP I 1 A_JumpIf(CallACS("core_targetexists",1)==0,"DeathLoop1")
loop

SuperDeathPoof:
HARP I 0 A_ChangeFlag("NOINTERACTION",1)
UMFX OABCD 1 A_Stop
stop
SuperDeath:
HARP I 0
stop
}
}

Actor WaveHarpoonHookFX : BasicGraphicEffect
{
+NOTIMEFREEZE
States
{
Spawn:
HARP F 0
HARP F 1
stop
}
}

actor WaveHarpoon : ProjSpawnFuncActor
{
var int user_TranslateWhiteColors;
PROJECTILE 
Damagetype "WaveM_Shot"
Obituary "$OB_WAVEHARPOON" 
+FORCEXYBILLBOARD
damage (150)
Radius 10
Height 8
speed 40
scale 3.0
States
{
Spawn:
HARP A 1
loop
}
}

actor PinpointWaterWaveSpawner : FastProjectile
{
Height 16
Radius 6
speed 1000
//+RIPPER
//+THRUGHOST
+DONTBLAST
+SKYEXPLODE
+EXPLODEONWATER
+THRUACTORS
damage (0)
reactiontime 5
States
{
Spawn:
TNT1 A 0
TNT1 A 1 A_CountDown
loop
Death:
TNT1 A 0 A_CheckFloor("Forward")
TNT1 A 0 A_SpawnItemEx("WaterWaveSpawnerB",0,0,0,0,0,0,180,1)
stop
Forward:
TNT1 A 0 A_SpawnItemEx("WaterWaveSpawnerB2",0,0,0,0,0,0,0,1)
stop
}
}

actor WaterWaveSpawnerB : ProjSpawnFuncActor
{
PROJECTILE
+DONTBLAST
//+RIPPER
//+THRUGHOST
+THRUACTORS
+FLOORHUGGER
reactiontime 30
damage (0)
Height 40
Radius 6
scale 2.5
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_PlaySoundEx("weapon/WaveSummon","Weapon")
Spawn2:
TNT1 AA 1 A_CountDown
HARP BBBBCCBBBB 1 A_CountDown
loop
Death:
TNT1 A 0 //A_JumpIfCloser(64,"Launch")
Wave:
TNT1 A 0 A_SpawnItemEx("WaterWaveB",0,0,0,23)
TNT1 A 1 //A_PlaySoundEx("weapon/WaveSummonGo","Weapon")
stop
Launch:
TNT1 A 0 A_JumpIf(z!=floorz,"Wave")
TNT1 A 0 A_GiveToTarget("WaterWaveLaunch",1)
goto Wave
}
}

actor WaterWaveSpawnerB2 : WaterWaveSpawnerB
{
ReactionTime 1
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_PlaySoundEx("weapon/WaveSummon","Weapon")
TNT1 A 0 A_JumpIfCloser(100,"Spawn8")
TNT1 A 0 //A_LOG("Too far 100")
TNT1 A 0 A_JumpIfCloser(250,"Spawn7")
TNT1 A 0 //A_LOG("Too far 250")
TNT1 A 0 A_JumpIfCloser(400,"Spawn6")
TNT1 A 0 //A_LOG("Too far 400")
TNT1 A 0 A_JumpIfCloser(550,"Spawn5")
TNT1 A 0 //A_LOG("Too far 550")
TNT1 A 0 A_JumpIfCloser(700,"Spawn4")
TNT1 A 0 //A_LOG("Too far 700")
TNT1 A 0 A_JumpIfCloser(850,"Spawn3")
TNT1 A 0 //A_LOG("Too far 850")
Spawn2:
HARP ZZBBB 1
Spawn3:
HARP BCCBB 1
Spawn4:
HARP BBZZB 1
Spawn5:
HARP BBBCC 1
Spawn6:
HARP BBBBZ 1
Spawn7:
HARP ZBBBB 1
SpawnW:
HARP B 1 A_CountDown
wait
Spawn8:
HARP B 1
HARP B 1 A_CountDown
wait
}
}

actor WaterWaveLaunch : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_JumpIf(z-floorz==0||momz>=0,"Ground")
goto Air
Air:
TNT1 A 0 ThrustThingZ(0,10,0,1)
stop
Ground:
TNT1 A 0 ThrustThingZ(0,60,0,0)
stop
}
}

actor WaterWaveB : ProjSpawnFuncActor
{
PROJECTILE
damagetype "WaveM_Water"
Obituary "$OB_WATERWAVE"
-NOGRAVITY
+DONTSPLASH
+BOUNCEONCEILINGS
+NOEXPLODEFLOOR
+STEPMISSILE
maxstepheight 16
Bouncecount 1
gravity 51.0
ReactionTime 31
Damage (80)
Radius 6
Height 40
speed 23
Scale 2.5
States
{
Spawn:
TNT1 A 1
HARP B 3 A_GiveInventory("ResyncPickup",1)
SpawnL:
HARP CDEDCB 4
HARP B 0 A_CountDown
Goto Spawn+2
Death:
Crash:
XDeath:
TNT1 A 1 A_SpawnItemEx("SoakifyEffect")
stop
}
}


actor WavemanWepDroppedX : BasicHelper
{
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_SpawnItemEx("WaterWaveWep",0,0,0,momx,momy,momz,0,8)
TNT1 A 0 A_Jump(32,2)
TNT1 A 1
stop
TNT1 A 1 A_SpawnItemEx("WireAdaptor",0,0,0,-momx,-momy,momz,0,8)
stop
}
}


actor Waveman_W_NormalBar : NormalBar {Args 4,198}
actor Waveman_W_ScriptBar : ScriptBar {}