actor Plugman_W : BaseMM8BDMWep_CBM
{
tag "$TAGC_9D"
dropitem "PlugBallWep"
Weapon.AmmoUse 2
Weapon.AmmoGive 14
Obituary "$OB_PLUGITIN"
Inventory.Pickupmessage "It's just like out of one of my japanese animes! :B"
weapon.ammotype "YouWaShockAmmo"
States
{
Spawn:
C_09 D 1
loop

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

Ready:
PLGH A 0 ACS_NamedExecuteWithResult("core_weaponcolor",DYE_PLUGMAN)
goto Ready1
Ready1:
PLGH A 0 A_JumpIfInventory("YouWaShockAmmo",2,"Ready2")
PLGH A 7 A_WeaponReady(WRF_NOPRIMARY)
PLGH A 0 A_GiveInventory("YouWaShockAmmo",1)
loop
Ready2:
PLGH A 7 A_WeaponReady
PLGH A 0 A_GiveInventory("YouWaShockAmmo",1)
loop

Fire:
PLGH A 0 A_JumpIfInventory("PlugmanLatch",2,"AllyPlug")
PLGH A 0 A_JumpIfInventory("PlugmanLatch",1,"EnemyPlug")
PLGH A 0 A_JumpIfNoAmmo("NoAmmo")
PLGH A 0 A_JumpIfInventory("PlayerPropertyRage",1,"FireR")
PLGH BCDEB 1
goto FireEnd
FireR:
PLGH BED 1
goto FireEnd
FireEnd:
PLGH A 0 A_FireCustomMissile("PlugBallStartClass",0,1,8,0)
PLGH A 0 A_PlaySoundEx("weapon/Plugball","Weapon")
PLGH A 0 A_JumpIfInventory("PlayerPropertyRage",1,"FireEndR")
PLGH A 1 offset(3,35)
PLGH A 1 offset(8,40)
PLGH A 1 offset(13,45)
PLGH A 2 offset(18,50)
PLGH A 1 offset(13,45)
PLGH A 1 offset(8,40)
PLGH A 1 offset(3,35)
Goto Ready1
FireEndR:
PLGH A 1 offset(4,36)
PLGH A 1 offset(10,42)
PLGH A 1 offset(18,50)
PLGH A 1 offset(10,42)
PLGH A 1 offset(4,36)
Goto Ready1

NoAmmo:
PLGH A 0
Goto Ready1

Altfire:
PLGH A 0 A_JumpIfInventory("PlugmanLatch",1,"UnPlug")
PLGH A 0 A_PlaySoundEx("weapon/magnetmissile","Weapon")
PLGH F 0 A_SpawnItemEx("PlugManPlugShot",0,8,28,cos(-pitch)*38,0,sin(-pitch)*38,0,1)
PLGH F 0 A_JumpIfInventory("PlayerPropertyRage",1,"AltfireR")
PLGH F 1 offset(3,35)
PLGH F 1 offset(8,40)
PLGH F 1 offset(13,45)
PLGH F 1 offset(18,50)
PLGH F 1 offset(13,45)
PLGH F 1 offset(8,40)
PLGH F 1 offset(3,35)
Goto AltfireCheck
AltfireR:
PLGH F 1 offset(4,36)
PLGH F 1 offset(10,42)
PLGH F 1 offset(18,50)
PLGH F 1 offset(10,42)
PLGH F 1 offset(4,36)
Goto AltfireCheck
AltfireCheck:
PLGH F 0 A_WeaponReady(14)
PLGH F 0 A_JumpIfInventory("PlayerPropertyRage",1,"AltfireCheckR")
PLGH FFFFFFFFFFFFF 1 A_JumpIfInventory("PlugmanLatch",1,"Plugged")
PLGH A 6 A_PlaySoundEx("weapon/adapterreturn","Body")
Goto Ready1
AltfireCheckR:
PLGH FFFFFFFFFFF 1 A_JumpIfInventory("PlugmanLatch",1,"Plugged")
PLGH A 4 A_PlaySoundEx("weapon/adapterreturn","Body")
Goto Ready1

Plugged:
PLGH F 8 A_WeaponReady(12)
PluggedReady0:
PLGH F 0 A_JumpIfInventory("PlugmanLatch",2,"PluggedReady2")
PLGH FFF 1 A_JumpIfInventory("PlugmanLatch",1,"PluggedReady1")
Goto UnPlug
PluggedReady1:
PLGH F 12 A_WeaponReady
PLGH F 0 A_GiveInventory("YouWaShockAmmo",1)
PLGH FFF 1 A_JumpIfInventory("PlugmanLatch",1,"PluggedReady1")
Goto UnPlug
PluggedReady2:
PLGH F 0 A_JumpIfInventory("YouWaShockAmmo",2,"PluggedReady1")
PLGH F 12 A_WeaponReady(WRF_NOPRIMARY)
PLGH F 0 A_GiveInventory("YouWaShockAmmo",1)
PLGH FFF 1 A_JumpIfInventory("PlugmanLatch",1,"PluggedReady2")
Goto UnPlug

EnemyPlug:
PLGH F 0 A_PlaySoundEx("weapon/PlugShock","Body")
PLGH F 0 A_GiveInventory("PlugManEnemyInventory",1,AAPTR_TRACER)
PLGH F 0 A_GiveInventory("PluggedEnemySlow",1)
PLGH F 0 A_GiveInventory("PlugmanIsShocking",1)
PLGH F 2 A_GiveInventory("YouWaShockAmmo",4)
PLGH O 2 ACS_NamedExecuteWithResult("cbm_PlugHealthDrain",10*(CallACS("core_checkrune",RUNE_SPREAD,2)*2+1))
PLGH F 0 A_PlaySoundEx("weapon/PlugShock","Body")
PLGH F 0 A_GiveInventory("PlugManEnemyInventory",1,AAPTR_TRACER)
PLGH F 0 A_GiveInventory("PluggedEnemySlow",1)
PLGH F 0 A_GiveInventory("PlugmanIsShocking",1)
PLGH F 2 A_GiveInventory("YouWaShockAmmo",4)
PLGH O 2 ACS_NamedExecuteWithResult("cbm_PlugHealthDrain",10*(CallACS("core_checkrune",RUNE_SPREAD,2)*2+1))
PLGH FF 1 A_JumpIfInventory("PlugmanLatch",1,"PluggedReady1")
Goto UnPlug

AllyPlugAmmoCheck:
PLGH F 0 A_JumpIfInventory("YouWaShockAmmo",1,"AllyPlug")
PLGH F 1
PLGH F 12 A_WeaponReady(WRF_NOPRIMARY)
Goto PluggedReady0
AllyPlug:
PLGH F 1 A_JumpIfInventory("PlugmanLatch",1,"AllyPlugFire")
Goto Unplug
AllyPlugFire:
PLGH F 0 A_PlaySoundEx("weapon/PlugShock", "Body")
PLGH F 0 A_GiveInventory("PlugManAllyInventory", 1, AAPTR_TRACER)
PLGH F 0 A_GiveInventory("PlugmanIsShocking",1)
PLGH F 2 A_TakeInventory("YouWaShockAmmo",1,1)
PLGH O 2
PLGH F 0 A_PlaySoundEx("weapon/PlugShock", "Body")
PLGH F 0 A_GiveInventory("PlugManAllyInventory", 1, AAPTR_TRACER)
PLGH F 2 A_GiveInventory("PlugmanIsShocking",1)
PLGH O 2
PLGH F 0 A_PlaySoundEx("weapon/PlugShock", "Body")
PLGH F 0 A_GiveInventory("PlugManAllyInventory", 1, AAPTR_TRACER)
PLGH F 2 A_GiveInventory("PlugmanIsShocking",1)
PLGH O 2
PLGH F 0 A_Refire("AllyPlugAmmoCheck")
PLGH F 4 A_WeaponReady(WRF_NOPRIMARY)
Goto PluggedReady0

UnPlug:
PLGH A 0 A_TakeInventory("PlugmanLatch")
PLGH A 4 A_PlaySoundEx("weapon/adapterreturn","Body")
PLGH A 4 A_WeaponReady(WRF_NOSECONDARY)
Goto Ready1
}
}

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

actor PlugmanLatch : Inventory
{
inventory.amount 1
inventory.maxamount 2
}

actor PlugM_DontZapHP_F : Inventory{}

actor PlugmanIsShocking : Powerup
{
powerup.duration 5
}

actor PlugmanRageFlag : Powerup
{
powerup.duration 8
//damagefactor "normal", 1.07
}

actor PluggedEnemySlow : PowerSpeed
{
+POWERSPEED.NOTRAIL
powerup.duration 8
speed 0.75
}

actor PlugManEnemyInventory : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_SpawnItemEx("Plugman_PlugEnemy_H",0,0,0,0,0,0,0,32)
TNT1 A 0 //A_GiveInventory("PluggedEnemySlow",1)
stop
}
}

actor PlugManAllyInventory : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_SpawnItemEx("Plugman_PlugAlly_H",0,0,0,0,0,0,0,32)
TNT1 A 0 A_JumpIfInventory("PlugmanRageFlag",1,3)
TNT1 A 0 ACS_NamedExecuteWithResult("core_runeplayer",0,1,RUNE_RAGE)
TNT1 A 0 A_SpawnItemEx("Plugman_PowerRage_ST_Watcher")
TNT1 A 0 A_GiveInventory("PlugmanRageFlag",1)
stop
}
}

actor PlugManAllyRageEnd_P : CustomInventory
{
states
{
Pickup:
TNT1 A 0 ACS_NamedExecuteWithResult("core_runeplayer",0,0,RUNE_RAGE)
stop
}
}

actor Plugman_PowerRage_ST_Watcher : BasicHelper
{
+SERVERSIDEONLY
States
{
Spawn:
TNT1 A 1
TNT1 A 0 A_JumpIfInTargetInventory("PlugmanRageFlag",1,"Spawn")
goto SpawnEnd
SpawnEnd:
TNT1 A 0 A_TakeFromTarget("PlugmanRageFlag",9)
TNT1 A 0 A_GiveToTarget("PlugManAllyRageEnd_P",1)
stop
}
}

actor Plugman_PlugEnemy_H : BasicHelper
{
States
{
Spawn:
TNT1 A 0
TNT1 A 5 A_PlaySoundEx("weapon/PlugShock","Weapon")
stop
}
}

actor Plugman_PlugAlly_H : BasicHelper
{
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_SpawnItemEx("PlugPowerFX",0,0,0,0,0,0,0,32)
TNT1 A 5 A_PlaySoundEx("weapon/PlugShock","Weapon")
stop
}
}

actor PlugPowerFX : BasicGraphicEffect
{
+FORCEXYBILLBOARD
+BRIGHT
States
{
SpawnFrame:
PLGH L 0
PLGH LLMM 1 A_Warp(2,0,0,0,0,WARPF_COPYINTERPOLATION)
stop
}
}

actor PlugManPlugShot : ProjSpawnFuncActor
{
//Translation "192:192=228:228","198:198=95:95"
var int user_PTID;
PROJECTILE
damagetype "PlugM_Prong"
Obituary "$OB_PLUGITIN"
+SKYEXPLODE
+EXPLODEONWATER
+HITTRACER
+THRUGHOST
+DONTREFLECT
+DONTBLAST
+FORCEALLYCOLLISION
Damage (100)
Height 26
Radius 26
speed 38
scale 2.5
states
{
Spawn:
PLGH G 0
//PLGH G 0 A_SetUserVar("user_PTID",CallACS("core_gettarget"))

PLGH G 0 ACS_NamedExecuteWithResult("core_drawhookshot",CallACS("core_gettarget"),18,12,0)
//PLGH G 0 ACS_NamedExecuteAlways("cbm_drawhookshot", 0, user_PTID, 18)
PLGH GGGGGGGGGGGGGGGG 1
//PLGH GGGGGGGGGGGGGGGG 1 ACS_NamedExecuteAlways("cbm_DrawPlugCable",0,0,user_PTID,0)
stop
Death:
TNT1 A 0 A_SpawnItemEX("ElectrifyEffect")
TNT1 A 0 A_JumpIfInventory("MM8BDMPlayer",1,"DeathCheck",8)
stop
DeathCheck:
TNT1 A 0 A_JumpIf(CallACS("core_targetexists",1)!=0,"DeathLatch")
stop
DeathLatch:
TNT1 A 0 ACS_NamedExecuteWithResult("cbm_PlugLatch")
//TNT1 A 35 ACS_NamedExecuteAlways("cbm_PlugLatch",0)
stop
}
}

Actor PlugManPlugShotFX : BasicGraphicEffect//Normal FX
{
Translation "198:198=89:89"
+NOTIMEFREEZE
States
{
SpawnFrame:
PLGH H 0
PLGH H 1
stop
}
}
Actor PlugManPlugCableFX : PlugManPlugShotFX//Fx that changes if Plug uses mainfire
{
Translation "192:192=228:228","198:198=95:95"
+NOTIMEFREEZE
States
{
SpawnFrame:
PLGH H 0
PLGH H 1 A_JumpIf(angle>0, "Woah")
stop
Woah:
PLGH H 0 A_Jump(100,2,3)
PLGH H 1
stop
PLGH I 1 bright
stop
PLGH J 1 bright
stop
}
}

actor PlugmanFinshingPlugHit
{
PROJECTILE
damagetype "PlugM_Plugged"
Obituary "$OB_PLUGITIN"
+DONTREFLECT
+DONTBLAST
damage (100)
speed 1
States
{
Spawn:
TNT1 A 1
stop
}
}

actor PluggedEnemyFinalHit : BasicImplosion
{
damagetype "PlugM_Plugged"
Obituary "$OB_PLUGITIN"
States
{
Spawn:
TNT1 A 0
TNT1 A 3 A_Explode(10,15,0,0,15)
stop
}
}


actor PlugBallStartClass : ProjSpawnFuncActor
{
PROJECTILE
damagetype "PlugM_Ball"
Obituary "$OB_PLUGBALL"
-NOGRAVITY
+SKYEXPLODE
+EXPLODEONWATER
+FORCEXYBILLBOARD
+BRIGHT
Gravity 1.0
reactiontime 20
Damage (90)
Radius 17
Height 32
speed 35
Scale 2.5
States
{
Spawn:
TNT1 A 0
Loopy:
PLGH WXYZ 1
loop
XDeath:
Crash:
TNT1 A 0 A_SpawnItemEX("ElectrifyEffect")
stop
Death:
TNT1 A 0 A_SpawnItemEX("ElectrifyEffect")
TNT1 A 0 A_SpawnItemEx("PlugBallClass",0,0,0,24)
stop
}
}

actor PlugBallClassFall_P : CustomInventory
{
States
{
Pickup:
TNT1 A 0 A_ChangeFlag("NOGRAVITY",1)//A_SetGravity(0.0)
TNT1 A 0 A_ChangeVelocity(0,0,-24,3)
TNT1 A 0 ThrustThing(angle*256/360,0,1,0)
stop
}
}
actor PlugBallClassForward_P : CustomInventory
{
States
{
Pickup:
TNT1 A 0 A_ChangeFlag("NOGRAVITY",0)
TNT1 A 0 A_ChangeVelocity(24,0,-24,3)
stop
}
}

actor PlugBallClass : ProjSpawnFuncActor
{
var int user_x;
var int user_y;
PROJECTILE
damagetype "PlugM_Ball"
Obituary "$OB_PLUGBALL"
-NOGRAVITY
+DONTSPLASH//
+BOUNCEONWALLS
+DONTREFLECT
+FORCEXYBILLBOARD
+STEPMISSILE
+NOEXPLODEFLOOR
+BRIGHT
maxstepheight 15
bouncecount 30
bouncefactor 1.0
wallbouncefactor 1.0
gravity 4.0
reactiontime 47
Damage (90)//180
Radius 16
Height 32
Speed 24
Scale 2.5
States
{
Spawn:
TNT1 A 0
PLGH W 0 A_SetUserVar(user_x,x)
PLGH W 0 A_SetUserVar(user_y,y)
PLGH W 0 A_GiveInventory("ReSyncPickup",1)
SpawnL:
PLGH W 0
PLGH W 1 A_JumpIf(z-floorz>0,"Fall1")
PLGH X 1 A_JumpIf(z-floorz>0,"Fall2")
PLGH Y 1 A_JumpIf(z-floorz>0,"Fall3")
PLGH Z 1 A_JumpIf(z-floorz>0,"Fall4")
PLGH W 0 A_CountDown

PLGH W 0 A_JumpIf((user_x-x < 2 && user_x-x > -2) && (user_y-y < 2 && user_y-y > -2), "Death2")
PLGH W 0 A_SetUserVar(user_x, x)
PLGH W 0 A_SetUserVar(user_y, y)
loop

Fall1:
PLGH W 0 A_GiveInventory("PlugBallClassFall_P")
goto SpawnF+1
Fall2:
PLGH X 0 A_GiveInventory("PlugBallClassFall_P")
goto SpawnF+2
Fall3:
PLGH Y 0 A_GiveInventory("PlugBallClassFall_P")
goto SpawnF+3
Fall4:
PLGH Z 0 A_GiveInventory("PlugBallClassFall_P")
goto SpawnF+4
SpawnF:
PLGH W 0
PLGH W 1 A_JumpIf(z-floorz==0,"Forward1")
PLGH X 1 A_JumpIf(z-floorz==0,"Forward2")
PLGH Y 1 A_JumpIf(z-floorz==0,"Forward3")
PLGH Z 1 A_JumpIf(z-floorz==0,"Forward4")
PLGH W 0 A_CountDown
loop
Forward1:
PLGH W 1 A_GiveInventory("PlugBallClassForward_P")
goto SpawnL+2
Forward2:
PLGH X 1 A_GiveInventory("PlugBallClassForward_P")
goto SpawnL+3
Forward3:
PLGH Y 1 A_GiveInventory("PlugBallClassForward_P")
goto SpawnL+4
Forward4:
PLGH Z 1 A_GiveInventory("PlugBallClassForward_P")
goto SpawnL+5
Death2:
TNT1 A 1 A_CountDownArg(0)
wait
Death:
TNT1 A 1 A_SpawnItemEX("ElectrifyEffect")
stop
}
}


actor Plugman_W_NormalBar : NormalBar {Args 4,39}