
ACTOR RLNanoManufactureAmmoTristarBlaster : RLHeavyWeapon
{
  Obituary "%o was divided in three by %k's tristar blaster."
  Tag "Nanomachic Tristar Blaster"
  Weapon.SelectionOrder 20
  Weapon.SlotNumber 5
  Weapon.AmmoUse1 0
  Weapon.AmmoGive1 0
  Inventory.Icon "MTRIICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate",1, "ReadyAltFire")
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"ReadyAltFire")
    TNT1 A 0 A_GunFlash ("FlashGlow", GFF_NOEXTCHANGE)
    MTRI A 18 A_WeaponReady (WRF_NOSECONDARY | WRF_ALLOWZOOM)
    Loop
  ReadyAltFire:
    TNT1 A 0 A_GunFlash ("FlashGlow", GFF_NOEXTCHANGE)
    MTRI A 18 A_WeaponReady (WRF_ALLOWZOOM)
    Loop
	
  ScavengerDrop:
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"WeaponDropConfirm")
	TNT1 A 0 A_GiveInventory("RLScavengerDrop",1)
	TNT1 A 0 A_Print("Press again to drop current weapon,\nor press \crAlt Fire\c- to scrap it to retrieve a Mod Pack.")
	Goto AfterModDrop
  WeaponDropConfirm:
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 ACS_NamedExecuteWithResult("RLCerberusSetBonusCheck", 1) // Checks for all parts of the set bonus, gives or removes it accordingly - argument is tic delay before checking
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_TakeInventory("RLWeaponDrop",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 A_SpawnItemEx("RLNanoManufactureAmmoTristarBlasterPickup", 0, 0, 40, 8, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLNanoManufactureAmmoTristarBlasterSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLNanoManufactureAmmoTristarBlaster",1)
	Stop
  AfterModDrop:
    TNT1 A 0 A_GunFlash ("FlashGlow", GFF_NOEXTCHANGE)
    MTRI A 18 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
    MTRI A 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
	
  Deselect:
	TNT1 A 0
	TNT1 A 0 A_GiveInventory("RLDeselectionFunction",1)
	TNT1 A 0 A_TakeInventory("RLNanoManufactureAmmoTristarBlasterSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
    TNT1 A 0 A_GunFlash ("FlashGlow", GFF_NOEXTCHANGE)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    MTRI A 1 A_Lower
    Loop
  DeselectRenegade:
    TNT1 A 0 A_Lower
    loop
  SelectRenegade: 
    TNT1 A 0 A_Raise
    loop
  SelectSetWeapon:
	TNT1 A 0 A_GiveInventory("RLMasterAssemblyTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLInfiniteAmmoWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLNanoManufactureAmmoTristarBlasterSelected", 1)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 1)
    Goto SelectLoop
	TNT1 A 0 A_GiveInventory("PowerRLTechnicianMasterDamage", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    TNT1 A 0 A_GunFlash ("FlashGlow", GFF_NOEXTCHANGE)
    MTRI A 1 A_Raise
    Goto SelectLoop+2
	
  Fire:
	MTRI A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	MTRI A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	MTRI A 0 A_JumpIfInventory("RLRestrictionNoBoom",1,"NoBoomRestricted") // Cannot fire in levels that restrict it
	MTRI A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	MTRI A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
	TNT1 A 0 A_AlertMonsters
    TNT1 A 0 A_PlaySound("weapons/nanoheavyweaponflare", CHAN_BODY, 0.95, 0, 0.5)
	TNT1 A 0 A_FireCustomMissile ("RLTristarBlasterBall", 0, 0)
	TNT1 A 0 A_FireCustomMissile ("RLTristarBlasterBall", 15, 0)
	TNT1 A 0 A_FireCustomMissile ("RLTristarBlasterBall", -15, 0)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLBFG9000Recoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/nanotristarblaster", CHAN_WEAPON)
	TNT1 A 0 A_JumpIfInventory("RLCerberusSetBonusActive",1,"FireSetBonus")
    MTRI B 6 Bright A_GunFlash
    MTRI C 6 Bright
    MTRI DEF 6 Bright
    MTRI F 6 Bright A_Refire
    Goto Ready
  FireSetBonus:
    MTRI B 2 Bright A_GunFlash ("FlashSetBonus")
    MTRI C 2 Bright
    MTRI DEF 2 Bright
    MTRI F 2 Bright A_Refire
    Goto Ready
  Flash:
    TNT1 A 6 A_Light1
    TNT1 A 6 A_Light2
    TNT1 A 2 A_Light1
    TNT1 A 0 A_Light0
    Goto LightDone
  FlashSetBonus:
    TNT1 A 2 A_Light1
    TNT1 A 2 A_Light2
    TNT1 A 1 A_Light1
    TNT1 A 0 A_Light0
    Goto LightDone
  FlashGlow:
    MTRI GHIJKLMNOG 2 Bright A_Light0
    Goto LightDone
  FlashDrop:
    TNT1 A 0 A_Light0
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLNanoManufactureAmmoTristarBlasterPickup",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION, 0, tid)
    Stop
  Altfire:
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate",1, "ArmorModConversion")
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"ScavengerTime")
	Goto Ready
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
    TNT1 A 0 A_GiveInventory("RLNanomanufactureAmmoAssemblyLearntToken", 1) // Assembly is now listed in the HUD menus
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLNanoManufactureAmmoTristarBlasterSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 ACS_NamedExecuteWithResult("RLCerberusSetBonusCheck", 1) // Checks for all parts of the set bonus, gives or removes it accordingly - argument is tic delay before checking
  ScavengerContinue:
	TNT1 A 0 A_Jump(256,1,2,3,4)
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLNanoMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLNanoManufactureAmmoTristarBlaster",1)
	Stop
  }
}

//-------------------------------------------------------------------
//		MECHANICS

Actor RLNanoManufactureAmmoTristarBlasterSelected : RLPermanentInventory {}

//-------------------------------------------------------------------
//		PICKUPS

ACTOR RLNanoManufactureAmmoTristarBlasterPickup : RLMasterAssembledWeaponPickup
{
	//$Sprite MTRIX0
	Tag "Nanomachic Tristar Blaster [Pickup]"
	States
	{
	SpawnFrame:
		MTRI X 4
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
	SpawnLoop:
		"####" "#" 0 A_JumpIf(Abs(VelZ) <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 1
		Loop
	FloorHit:
		"####" "#" 0 A_PlaySound("weapons/gundropbigger")
		"####" "#" 0 A_ScaleVelocity (0.15)
		"####" "#" 0 A_ChangeFlag("SPECIAL", true)
		"####" "#" 0 A_ChangeFlag("THRUACTORS", false)
		"####" "#" 0 A_SetUserVar("user_floorhit", 1)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Stop
	Pickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("RLNanoManufactureAmmoTristarBlaster",1,"NotPickup") // If the player already has this weapon, they are not given the weapon
		"####" "#" 0 A_JumpIfInventory("RLWeaponLimit",0,"NotPickupLimit") // The absolute max limit check for weapons
		"####" "#" 0 ACS_NamedExecuteWithResult("RLCerberusSetBonusCheck", 1) // Checks for all parts of the set bonus, gives or removes it accordingly - argument is tic delay before checking
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLNanoManufactureAmmoTristarBlaster",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvNanomachic Tristar Blaster.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_Jump(256, "NotPickup")
		Goto NotPickup
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= Nanomachic Tristar Blaster =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/NanoTristarBlasterpickup")
		Stop
/*	SetBonusStart:
		"####" "#" 0 A_GiveInventory("RLCerberusSetBonusTristarBlaster",1)
		"####" "#" 0 A_JumpIfInventory("RLCerberusSetBonusBoots",1,"SetBonusCheck")
		"####" "#" 0 A_JumpIfInventory("RLCerberusSetBonusArmor",1,"SetBonusCheck")
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
	SetBonusCheck:
		"####" "#" 0 A_JumpIfInventory("RLCerberusSetBonusBoots",1,2)
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
		"####" "#" 0 A_JumpIfInventory("RLCerberusSetBonusArmor",1,2)
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
		"####" "#" 0 A_GiveInventory("RLCerberusSetBonusActive",1)
		"####" "#" 0 A_Print("\ccPicked up a \ctNanomachic Tristar Blaster.\n\c-= TRINITY GUARDIAN =\n\ccTristar Blaster fires three times faster", 8, "CONFONT")
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon*/
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonShells",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	SuperweaponStuff:
		"####" "#" 0 A_Jump(256, "NoSpecialStartsStuff")
		Goto NoSpecialStartsStuff
	}
}

ACTOR RLNanoManufactureAmmoTristarBlasterWorldSpawnPickup : RLNanoManufactureAmmoTristarBlasterPickup 17815
{
	States
	{
	NoSpecialStartsStuff:
		TNT1 A 0 A_JumpIf(CallACS("DRLA_opengl"), 3) // If enabled, rarity beam will be cyan, rather than blue
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorld", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorldDRPG", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_JumpIf(CallACS("DRPGCheckTiem"), "DRPGInit")
	SpawnFrame:
		MTRI X 4
		"####" "#" 0 A_GiveInventory("RLMasterItemSpawnMessageSender",1)
		"####" "#" 0 A_PlaySound("weapons/masterspawned", 7, 0.25, 0, 0)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
		
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/NanoTristarBlasterpickup")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Stop
	}
}
