ACTOR WeaponEnhancerModule : Inventory { Inventory.Amount 1 Inventory.MaxAmount 45 Inventory.InterhubAmount 45 }
ACTOR ExoticWeaponEnhancerModule : WeaponEnhancerModule {}
Actor SuperChargedWeaponEnhancerModule : WeaponEnhancerModule {}
ACTOR SuperChargedWEMToken : Inventory {inventory.maxamount 1}

Actor WeaponWorldSpawnCheck : Inventory {inventory.maxamount 1}
Actor WEMAction : Inventory {inventory.maxamount 1}

ACTOR WEMBlueToken : Inventory { Inventory.Amount 1 Inventory.MaxAmount 1 Inventory.InterhubAmount 1 }
ACTOR WEMGreenToken : Inventory { Inventory.Amount 1 Inventory.MaxAmount 1 Inventory.InterhubAmount 1 }
ACTOR WEMRedToken : Inventory { Inventory.Amount 1 Inventory.MaxAmount 1 Inventory.InterhubAmount 1 }

Actor WeaponEnhancerModuleGiver : CustomInventory //Very much inspired by CDI's weapon upgrader
{
Inventory.Amount 1
Inventory.MaxAmount 1
Inventory.Icon "WPUPA0"
Inventory.PickupMessage "\c[X5]Weapon Enhancer Module\c-"
Inventory.PickupSound "wem/pickup"
Tag "WEM - Collect enough to upgrade an upgradable weapon"
Scale 0.8
+NOTIMEFREEZE
+FLOATBOB
+DONTGIB
+COUNTITEM
States
{
  Spawn:
	TNT1 A 0 NoDelay A_JumpIf(ACS_NamedExecuteWithResult("NexusNoFloat") == 0,2)
	TNT1 A 0 A_ChangeFlag(FLOATBOB,0)
	WPUP A 1 Bright A_SpawnItemEx("GreenPowerLine",random(10,-10),random(10,-10),Frandom(0,5),0,0,2,0,0,128)
	WPUP A 1 Bright A_SpawnItemEx("BluePowerLine",random(10,-10),random(10,-10),Frandom(0,5),0,0,2,0,0,128)
    Goto Spawn+2
  Pickup:
	TNT1 A 0 ACS_NamedExecuteAlways("WEMFirstUpgrade",0,1)
	TNT1 A 1 A_GiveInventory("WeaponEnhancerModule",1)
	Stop
}
}

Actor ExoticWeaponEnhancerModuleGiver : WeaponEnhancerModuleGiver
{
Inventory.PickupMessage "\c[X9]Exotic Weapon Enhancer Module\c-"
Inventory.Icon "WPUPB0"
States
{
  Spawn:
	TNT1 A 0 NoDelay A_JumpIf(ACS_NamedExecuteWithResult("NexusNoFloat") == 0,2)
	TNT1 A 0 A_ChangeFlag(FLOATBOB,0)
	WPUP B 1 Bright A_SpawnItemEx("GreenPowerLine",random(10,-10),random(10,-10),Frandom(0,5),0,0,2,0,0,128)
	WPUP B 1 Bright A_SpawnItemEx("LightGreenSpark",random(-12,12),random(-12,12),random(16,25),frandom(-0.4,0.4),frandom(-0.4,0.4),frandom(0,2),0,0,164)
    Goto Spawn+2
  Pickup:
	TNT1 A 0 ACS_NamedExecuteAlways("WEMFirstUpgrade",0,2)
	TNT1 A 1 A_GiveInventory("ExoticWeaponEnhancerModule",1)
	Stop
	}
}

Actor SuperChargedWeaponEnhancerModuleGiver : WeaponEnhancerModuleGiver
{
Inventory.PickupMessage "\c[m6]Super Charged Weapon Enhancer Module\c-"
Inventory.Icon "WPUPC0"
+ISMONSTER
States
{
  Spawn:
    TNT1 A 0 NoDelay A_SpawnItemEx("SuperChargedWEMCircle",0,0,0,0,0,0,0,SXF_SETMASTER|SXF_NOCHECKPOSITION)
	TNT1 A 0 A_JumpIf(ACS_NamedExecuteWithResult("NexusNoFloat") == 0,2)
	TNT1 A 0 A_ChangeFlag(FLOATBOB,0)
  Looping:
	WPUP C 1 Bright A_SpawnItemEx("RedPowerLine",random(10,-10),random(10,-10),Frandom(0,5),0,0,2,0,0,128)
    Loop
  Pickup:
    TNT1 A 0 A_GiveInventory("SuperChargedWEMToken",1)
	TNT1 A 0 ACS_NamedExecuteAlways("WEMFirstUpgrade",0,3)
    TNT1 A 1 A_GiveInventory("SuperChargedWeaponEnhancerModule",1)
	Stop
	}
}

Actor SuperChargedWEMCircle : PatriarchOrbitCube1
{
Renderstyle Add
Scale 0.1
States
  {	
  Spawn:
	CLBA B 1 Bright A_JumpIfInventory("SuperChargedWEMToken",1,"Fade",AAPTR_MASTER)
	TNT1 A 0 A_Warp(AAPTR_MASTER,24,0,25,10,WARPF_NOCHECKPOSITION|WARPF_INTERPOLATE|WARPF_USECALLERANGLE,"Spawn") //,30,0,105,10,
  Fade:
    TNT1 AAA 1 A_TakeInventory("SuperChargedWEMToken",1,0,AAPTR_MASTER)
	Stop
  }
}