# SPDX-FileCopyrightText: 2024 Plykiya <58439124+Plykiya@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 BramvanZijp <56019239+BramvanZijp@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 Killerqu00 <47712032+Killerqu00@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 SX-7 <92227810+SX-7@users.noreply.github.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# ScatteringGrenade is intended for grenades that spawn entities, especially those with timers
- type: entity
  abstract: true
  parent: BaseItem
  id: ScatteringGrenadeBase
  components:
  - type: Appearance
  - type: ContainerContainer
    containers:
      cluster-payload: !type:Container
  - type: Damageable
    damageContainer: Inorganic
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 10
      behaviors:
      - !type:TriggerBehavior
  - type: ScatteringGrenade
  - type: OnUseTimerTrigger
    delay: 3
  - 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
  parent: [ScatteringGrenadeBase, BaseSecurityContraband]
  id: ClusterBang
  name: clusterbang
  description: Can be used only with flashbangs. Explodes several times.
  components:
  - type: ScatteringGrenade
    whitelist:
      tags:
      - GrenadeFlashBang
    distance: 6
    velocity: 6
  - type: ClusterGrenadeVisuals
    state: base
  - type: Sprite
    sprite: Objects/Weapons/Grenades/clusterbang.rsi
    state: base-0

- type: entity
  parent: ClusterBang
  id: ClusterBangFull
  name: ClusterBang
  description: Launches three flashbangs after the timer runs out.
  suffix: Full
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/clusterbang.rsi
    layers:
    - state: icon
      map: ["enum.TriggerVisualLayers.Base"]
  - type: ScatteringGrenade
    whitelist:
      tags:
      - GrenadeFlashBang
    fillPrototype: GrenadeFlashBang
    distance: 6
    velocity: 6
  - type: TimerTriggerVisuals
    primingSound:
      path: /Audio/Effects/countdown.ogg
  - type: GenericVisualizer
    visuals:
      enum.Trigger.TriggerVisuals.VisualState:
        enum.ConstructionVisuals.Layer:
          Primed: { state: primed }
          Unprimed: { state: icon }
  - type: EmitSoundOnTrigger
    sound:
      path: "/Audio/Machines/door_lock_off.ogg"

- type: entity
  parent: [ScatteringGrenadeBase, BaseSyndicateContraband]
  id: ClusterGrenade
  name: clustergrenade
  description: Why use one grenade when you can use three at once!
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/clusterbomb.rsi
    layers:
    - state: icon
      map: ["enum.TriggerVisualLayers.Base"]
  - type: ScatteringGrenade
    fillPrototype: ExGrenade
    distance: 4
  - type: OnUseTimerTrigger
    beepSound:
      path: "/Audio/Effects/beep1.ogg"
      params:
        volume: 5
    initialBeepDelay: 0
    beepInterval: 0.5
  - type: EmitSoundOnTrigger
    sound:
      path: "/Audio/Machines/door_lock_off.ogg"
  - type: StaticPrice
    price: 2500

- type: entity
  parent: [ScatteringGrenadeBase, BaseSyndicateContraband]
  id: ClusterBananaPeel
  name: cluster banana peel
  description: Splits into 6 explosive banana peels after throwing, guaranteed fun!
  components:
  - type: Sprite
    sprite: Objects/Specific/Hydroponics/banana.rsi
    state: produce
  - type: ScatteringGrenade
    fillPrototype: TrashBananaPeelExplosive
    capacity: 6
    delayBeforeTriggerContents: 20
  - type: LandAtCursor
  - type: DamageOnLand
    damage:
      types:
        Blunt: 10
  - type: EmitSoundOnTrigger
    sound:
      path: "/Audio/Items/bikehorn.ogg"

- type: entity
  parent: [SoapSyndie, ScatteringGrenadeBase, BaseSyndicateContraband]
  id: SlipocalypseClusterSoap
  name: slipocalypse clustersoap
  description: Spreads small pieces of syndicate soap over an area upon landing on the floor.
  components:
  - type: Sprite
    sprite: Objects/Specific/Janitorial/soap.rsi
    layers:
    - state: syndie-4
  - type: ScatteringGrenade
    fillPrototype: SoapletSyndie
    capacity: 30
    delayBeforeTriggerContents: 60
    randomDistance: true
    randomThrowDistanceMax: 3
  - type: LandAtCursor
  - type: DamageOnLand
    damage:
      types:
        Blunt: 10
  - type: EmitSoundOnTrigger
    sound:
      path: "/Audio/Effects/flash_bang.ogg"
  - type: StaticPrice
    price: 1000

- type: entity
  parent: ScatteringGrenadeBase
  id: GrenadeFoamDart
  name: foam dart grenade
  description: Releases a bothersome spray of foam darts that cause severe welching.
  components:
  - type: Sprite
    sprite: Objects/Weapons/Grenades/foamdart.rsi
    layers:
    - state: icon
      map: ["Base"]
    - state: primed
      map: ["enum.TriggerVisualLayers.Base"]
  - type: ScatteringGrenade
    fillPrototype: BulletFoam
    capacity: 30
    velocity: 30
  - type: OnUseTimerTrigger
    beepSound:
      path: "/Audio/Effects/beep1.ogg"
      params:
        volume: 5
    initialBeepDelay: 0
    beepInterval: 2
  - type: EmitSoundOnTrigger
    sound:
      path: "/Audio/Weapons/Guns/Gunshots/batrifle.ogg"