- type: entity
  abstract: true
  parent: BaseItem
  id: GrenadeBase
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/grenade.rsi
    layers:
    - state: icon
      map: ["enum.TriggerVisualLayers.Base"]
  - type: Item
    size: Small
  - type: Clothing
    quickEquip: false
    slots:
    - Belt
  - type: TriggerOnUse
  - type: TimerTrigger
    delay: 3
  - type: Damageable
    damageContainer: Inorganic
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 10
      behaviors:
      - !type:TriggerBehavior
        keyOut: timer # explode immediately
      - !type:DoActsBehavior
        acts: ["Destruction"]
  - type: Appearance
  - type: AnimationPlayer
  - type: GenericVisualizer
    visuals:
      enum.Trigger.TriggerVisuals.VisualState:
        enum.ConstructionVisuals.Layer:
          Primed: { state: primed }
          Unprimed: { state: icon }
  - type: Tag
    tags:
    - HandGrenade
  - type: Fixtures
    fixtures:
      fix1:
        shape: !type:PhysShapeCircle
          radius: 0.2
        density: 20 # derived from base_item
        mask:
        - ItemMask
        restitution: 0.3
        friction: 0.2

- type: entity
  name: explosive grenade
  description: Grenade that creates a small but devastating explosion.
  parent: [GrenadeBase, BaseSyndicateContraband]
  id: ExGrenade
  components:
  - type: ExplodeOnTrigger
    keysIn:
    - timer
  - type: Explosive
    explosionType: Default
    maxIntensity: 10
    intensitySlope: 3
    totalIntensity: 120 # about a ~4 tile radius
    canCreateVacuum: false
  - type: TimerTrigger
    beepSound:
      path: "/Audio/Effects/beep1.ogg"
      params:
        volume: 5
    initialBeepDelay: 0
    beepInterval: 2 # 2 beeps total (at 0 and 2)

- type: entity
  name: flashbang
  description: Eeeeeeeeeeeeeeeeeeeeee.
  parent: [ GrenadeBase, BaseSecurityContraband ]
  id: GrenadeFlashBang
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/flashbang.rsi
  - type: FlashOnTrigger
    keysIn:
    - timer
    range: 7
  - type: EmitSoundOnTrigger
    keysIn:
    - timer
    sound:
      path: "/Audio/Effects/flash_bang.ogg"
    positional: true
  - type: DeleteOnTrigger
    keysIn:
    - timer
  - type: SpawnOnTrigger
    keysIn:
    - timer
    proto: GrenadeFlashEffect
    predicted: true
  - type: Appearance
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/countdown.ogg
  - type: GuideHelp
    guides:
    - Security
    - Antagonists
  - type: Tag
    tags:
    - HandGrenade
    - GrenadeFlashBang

- type: entity
  id: GrenadeFlashEffect
  categories: [ HideSpawnMenu ]
  components:
    - type: PointLight
      enabled: true
      radius: 5
      energy: 8
      netsync: false
    - type: LightFade
      duration: 0.5
    - type: TimedDespawn
      lifetime: 0.5

#The explosive values for these are pretty god damn mediocre, but SS14's explosion system is hard to understand - this is a good enough approximation of how it was in SS13.
#Ideally, there should be a weak radius around the bomb outside of its gibbing / spacing range capable of dealing fair damage to players / structures.
- type: entity
  name: syndicate minibomb
  description: A syndicate-manufactured explosive used to stow destruction and cause chaos.
  parent: [GrenadeBase, BaseSyndicateContraband]
  id: SyndieMiniBomb
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/syndgrenade.rsi
  - type: ExplosionResistance
    damageCoefficient: 0.1
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 10
      behaviors:
      - !type:TimerStartBehavior
    - trigger:
        !type:DamageTrigger
        damage: 45
      behaviors:
      - !type:TriggerBehavior
        keyOut: timer # immediately explode
      - !type:DoActsBehavior
        acts: ["Destruction"]
  - type: TimerTrigger
    delay: 5
  - type: ExplodeOnTrigger
    keysIn:
    - timer
  - type: Explosive
    explosionType: Minibomb
    totalIntensity: 200
    intensitySlope: 30 #Will destroy the tile under it reliably, space 1-2 more to rods. Only does any significant damage in a 5-tile cross.
    maxIntensity: 60
  - type: Appearance
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/minibombcountdown.ogg
      params:
        volume: 12
  - type: StaticPrice
    price: 2000

- type: entity
  name: self destruct
  description: Go out on your own terms!
  parent: GrenadeBase
  id: SelfDestructSeq
  categories: [ HideSpawnMenu ]
  components:
  - type: ExplodeOnTrigger
    keysIn:
    - timer
  - type: Explosive
    explosionType: Minibomb
    totalIntensity: 400
    intensitySlope: 30
    maxIntensity: 125
    deleteAfterExplosion: false
    repeatable: true
    canCreateVacuum: true
  - type: TimerTrigger
    delay: 4.5
    beepSound:
      path: /Audio/Effects/Grenades/SelfDestruct/SDS_Charge2.ogg
      params:
        volume: 30
    initialBeepDelay: 0
    beepInterval: 16


- type: entity
  parent: [ GrenadeBase, BaseSyndicateContraband ]
  id: SingularityGrenade
  name: singularity grenade
  description: Grenade that simulates the power of a singularity, pulling things in a heap.
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/singularitygrenade.rsi
  - type: TimerTrigger
    delay: 3
    beepInterval: 0.46
    beepSound:
      path: /Audio/Effects/Grenades/Supermatter/smbeep.ogg
      params:
        volume: -5
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/Grenades/Supermatter/smbeep.ogg
      params:
        volume: -5
  - type: EmitSoundOnTrigger
    keysIn:
    - timer
    sound:
      path: /Audio/Effects/Grenades/Supermatter/supermatter_start.ogg
      params:
        volume: 5
  - type: AnchorOnTrigger
    keysIn:
    - timer
    removeOnTrigger: true
  - type: TwoStageTrigger
    keysIn:
    - timer
    triggerDelay: 10.45
    components:
      - type: AmbientSound
        enabled: true
        volume: -5
        range: 14
        sound:
          path: /Audio/Effects/Grenades/Supermatter/supermatter_loop.ogg
      - type: GravityWell
        maxRange: 7
        baseRadialAcceleration: 5
        baseTangentialAcceleration: .5
        gravPulsePeriod: 0.03
      - type: SingularityDistortion
        intensity: 150
        falloffPower: 1.5
      - type: PointLight
        enabled: true
        color: "#ffaa44"
        energy: 8
        radius: 6
        softness: 1
        offset: "0, 0"
      - type: EmitSoundOnTrigger
        sound:
          path: /Audio/Effects/Grenades/Supermatter/supermatter_end.ogg
          params:
            volume: 5
        positional: true
        keysIn:
        - stageTwo
      - type: DeleteOnTrigger
        keysIn:
        - stageTwo
  - type: StaticPrice
    price: 1000

- type: entity
  name: whitehole grenade
  description: Grenade that repulses everything around for some time.
  parent: SingularityGrenade
  id: WhiteholeGrenade
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/whiteholegrenade.rsi
  - type: TimerTrigger
    delay: 3
    beepInterval: 0.69
  - type: EmitSoundOnTrigger
    keysIn:
    - timer
    sound:
      path: /Audio/Effects/Grenades/Supermatter/whitehole_start.ogg
      params:
        volume: 5
  - type: AnchorOnTrigger
    keysIn:
    - timer
    removeOnTrigger: true
  - type: TwoStageTrigger
    triggerDelay: 11.14
    components:
      - type: AmbientSound
        enabled: true
        volume: -5
        range: 14
        sound:
          path: /Audio/Effects/Grenades/Supermatter/whitehole_loop.ogg
      - type: GravityWell
        maxRange: 7
        baseRadialAcceleration: -10
        baseTangentialAcceleration: -1
        gravPulsePeriod: 0.03
      - type: SingularityDistortion
        intensity: -200
        falloffPower: 1.5
      - type: PointLight
        enabled: true
        color: "#ffffff"
        energy: 8
        radius: 6
        softness: 1
        offset: "0, 0"
      - type: EmitSoundOnTrigger
        keysIn:
        - stageTwo
        sound:
          path: /Audio/Effects/Grenades/Supermatter/supermatter_end.ogg
          params:
            volume: 15
        positional: true
      - type: DeleteOnTrigger
        keysIn:
        - stageTwo
  - type: StaticPrice
    price: 1000

- type: entity
  name: the nuclear option
  description: Please don't throw it, think of the children.
  parent: GrenadeBase
  id: NuclearGrenade
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/nukenade.rsi
  - type: TimerTrigger
    delay: 5
  - type: ExplodeOnTrigger
    keysIn:
    - timer
  - type: Explosive
    explosionType: Default
    totalIntensity: 20000 # ~15 tile radius.
    intensitySlope: 5
    maxIntensity: 50
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:TriggerBehavior
        keyOut: timer # immediately explode
      - !type:DoActsBehavior
        acts: ["Destruction"]
  - type: Appearance
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/countdown.ogg

- type: entity
  name: modular grenade
  description: A grenade casing. Requires a trigger and a payload.
  parent: BaseItem
  id: ModularGrenade
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/modular.rsi
    layers:
    - state: empty
      map: [ "enum.ConstructionVisuals.Layer" ]
  - type: Item
    size: Small
  - type: Tag
    tags:
    - HandGrenade
  - type: PayloadCase
  - type: Construction
    graph: ModularGrenadeGraph
    node: emptyCase
  - type: Damageable
    damageContainer: Inorganic
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:TriggerBehavior
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
  - type: Appearance
  - type: GenericVisualizer
    visuals:
      enum.ConstructionVisuals.Key:
        enum.ConstructionVisuals.Layer:
          emptyCase: { state: empty }
          wiredCase: { state: wired }
          caseWithTrigger: { state: no-payload }
          caseWithPayload: { state: no-trigger }
          grenade: { state: complete }
      enum.Trigger.TriggerVisuals.VisualState:
        enum.ConstructionVisuals.Layer:
          Primed: { state: primed }
          # Unprimed: <Use state determined by enum.ConstructionVisuals.Layer>
  - type: StaticPrice
    price: 75

- type: entity
  name: EMP grenade
  description: A grenade designed to wreak havoc on electronic systems.
  parent: [GrenadeBase, BaseSyndicateContraband]
  id: EmpGrenade
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/empgrenade.rsi
  - type: EmpOnTrigger
    keysIn:
    - timer
    range: 5.5
    energyConsumption: 50000
  - type: DeleteOnTrigger
    keysIn:
    - timer
  - type: Appearance
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/countdown.ogg
  - type: StaticPrice
    price: 666 # 2000 for 3, I love fractions

- type: entity
  name: holy hand grenade
  description: O Lord, bless this thy hand grenade, that with it thou mayst blow thine enemies to tiny bits, in thy mercy.
  parent: [GrenadeBase, BaseSyndicateContraband]
  id: HolyHandGrenade
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/holyhandgrenade.rsi
  - type: ExplodeOnTrigger
    keysIn:
    - timer
  - type: Explosive
    explosionType: Default # same as macrobomb
    totalIntensity: 3500
    intensitySlope: 15
    maxIntensity: 70
    canCreateVacuum: true
  - type: TimerTrigger
    delay: 3 # by canon
  - type: PointLight
    radius: 7
    energy: 3
    netsync: false
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/hallelujah.ogg
  - type: StaticPrice
    price: 10000

- type: entity
  parent: [ GrenadeBase, BaseSecurityContraband ]
  id: SmokeGrenade
  name: smoke grenade
  description: A tactical grenade that releases a large, long-lasting cloud of smoke when used.
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/smoke.rsi
  - type: SmokeOnTrigger
    keysIn:
    - timer
    duration: 30
    spreadAmount: 50
  - type: EmitSoundOnTrigger
    keysIn:
    - timer
    sound: /Audio/Items/smoke_grenade_smoke.ogg
    positional: true
  - type: DeleteOnTrigger
    keysIn:
    - timer
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Items/smoke_grenade_prime.ogg

- type: entity
  parent: [ BaseCivilianContraband, SmokeGrenade ]
  id: CleanerGrenade
  name: cleanade
  description: Special grenade for janitors, releasing large cloud of space cleaner foam.
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/janitor.rsi
  - type: SmokeOnTrigger
    keysIn:
    - timer
    duration: 15
    spreadAmount: 50
    smokePrototype: Foam
    solution:
      reagents:
      - ReagentId: SpaceCleaner
        Quantity: 30

- type: entity
  parent: SmokeGrenade
  id: TearGasGrenade
  name: tear gas grenade
  description: A riot control tear gas grenade. Causes irritation, pain and makes you cry your eyes out.
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/tear_gas.rsi
  - type: SmokeOnTrigger
    keysIn:
    - timer
    duration: 10
    spreadAmount: 30
    smokePrototype: TearGasSmokeWhite
    solution:
      reagents:
      - ReagentId: TearGas
        Quantity: 20

- type: entity
  parent: [ BaseEngineeringContraband, SmokeGrenade ]
  id: MetalFoamGrenade
  name: metal foam grenade
  description: An emergency tool used for patching hull breaches with special quick-set metal foam. Almost as good as real floors!
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/metalfoam.rsi
  - type: TimerTrigger
    delay: 5
  - type: SmokeOnTrigger
    keysIn:
    - timer
    duration: 10
    spreadAmount: 20
    smokePrototype: AluminiumMetalFoam
  - type: StaticPrice
    price: 350

- type: entity
  parent: [ BaseEngineeringContraband, GrenadeBase ] # Prevent inheriting DeleteOnTrigger from SmokeGrenade
  id: AirGrenade
  name: air grenade
  description: A special solid state chemical grenade used for quickly releasing standard air into a spaced area. Fills up to 30 tiles!
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/airboom.rsi
  - type: EmitSoundOnTrigger
    keysIn:
    - timer
    sound: /Audio/Items/smoke_grenade_smoke.ogg
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Items/smoke_grenade_prime.ogg
  - type: TimerTrigger
    delay: 3
  - type: ReleaseGasOnTrigger
    keysIn:
    - timer
    removeFraction: 0.25
    air:
      volume: 1000
      moles: # Target is 3117.84 mols total for filling 30 tiles (goal is 101.325 kPa @ 20C)
        Oxygen: 654.7464 # oxygen
        Nitrogen: 2463.0936 # nitrogen
      temperature: 293.15
  - type: StaticPrice
    price: 350
  - type: GenericVisualizer
    visuals:
      enum.ReleaseGasOnTriggerVisuals.Key:
        enabled:
          True: { state: active }
          False: { state: spent }

# Non-explosive "dummy" grenades to use as a distraction.

- type: entity
  name: trick grenade
  description: All the grenade without any of the boom.
  parent: GrenadeBase
  id: GrenadeDummy
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/grenade.rsi
  - type: DeleteOnTrigger
    keysIn:
    - timer
  - type: SpawnOnTrigger
    keysIn:
    - timer
    proto: GrenadeFlashEffect
    predicted: true
  - type: EmitSoundOnTrigger
    keysIn:
    - timer
    sound:
      path: /Audio/Effects/Emotes/parp1.ogg
    positional: true
  - type: Appearance
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/countdown.ogg

- type: entity
  name: syndicate trickybomb
  description: A syndicate-manufactured explosive used to make an excellent distraction.
  parent: [GrenadeDummy, BaseSyndicateContraband]
  id: SyndieTrickyBomb
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/syndgrenade.rsi
  - type: TimerTrigger
    delay: 5
  - type: EmitSoundOnTrigger
    keysIn:
    - timer
    sound:
      path: /Audio/Effects/Emotes/parp1.ogg
    positional: true
  - type: Appearance
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/minibombcountdown.ogg
      params:
        volume: 12
  - type: StaticPrice
    price: 1000
