# SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 GoobBot <uristmchands@proton.me>
# SPDX-FileCopyrightText: 2025 OnsenCapy <101037138+OnsenCapy@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 chromiumboy <50505512+chromiumboy@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

- type: entity
  parent: BaseStructure
  id: BaseWeaponTurret
  name: turret
  abstract: true
  components:
  - type: Clickable
  - type: InteractionOutline
  - type: Actions
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb
          bounds: "-0.45,-0.45,0.45,0.45"
        density: 60
        mask:
        - MachineMask
        layer:
        - MachineLayer
  - type: Sprite
    sprite: Objects/Weapons/Guns/Turrets/turrets.rsi
    drawdepth: Mobs
    layers:
    - state: syndie_lethal
  - type: InteractionPopup
    interactDelay: 0.2
    successChance: 0.8
    interactSuccessString: petting-success-generic
    interactFailureString: petting-failure-generic
    interactSuccessSound:
      path: /Audio/Effects/double_beep.ogg
  - type: CombatMode
    toggleMouseRotator: false
  - type: Damageable
    damageContainer: Inorganic
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 600
      behaviors:
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
      - !type:PlaySoundBehavior
        sound:
          collection: MetalGlassBreak
    - trigger:
        !type:DamageTrigger
        damage: 300
       # TODO: Construction graph
      behaviors:
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
      - !type:PlaySoundBehavior
        sound:
          collection: MetalGlassBreak
      - !type:SpawnEntitiesBehavior
        spawn:
          SheetSteel1:
            min: 3
            max: 5
  - type: HTN
    rootTask:
      task: TurretCompound
    blackboard:
      RotateSpeed: !type:Single
        3.141
      SoundTargetInLOS: !type:SoundPathSpecifier
        path: /Audio/Effects/double_beep.ogg
  - type: MouseRotator
    angleTolerance: 5
    rotationSpeed: 180
    simple4DirMode: false
  - type: NoRotateOnInteract
  - type: NoRotateOnMove
  - type: Input
    context: "human"

- type: entity
  parent: BaseWeaponTurret
  id: BaseWeaponBallisticTurret
  description: A ballistic machine gun auto-turret.
  name: ballistic turret
  abstract: true
  components:
  - type: ContainerContainer
    containers:
      ballistic-ammo: !type:Container
  - type: Gun
    fireRate: 6
    selectedMode: FullAuto
    availableModes:
    - FullAuto
    soundGunshot:
      path: /Audio/Weapons/Guns/Gunshots/gun_sentry.ogg
  - type: BallisticAmmoProvider
    proto: CartridgeCaselessRifle
    capacity: 500

- type: entity
  parent: BaseWeaponTurret
  id: BaseWeaponEnergyTurret
  name: laser turret
  description: An auto-turret armed with a heavy laser. Its weapon will recharge while connected to an active power grid.
  abstract: true
  components:
  - type: Sprite
    sprite: Objects/Weapons/Guns/Turrets/sentry_turret.rsi
    drawdepth: FloorObjects
    granularLayersRendering: true
    layers:
    - state: support
      renderingStrategy: NoRotation
    - state: base
    - state: lethal
      shader: unshaded
  - type: Gun
    projectileSpeed: 15
    fireRate: 1.5
    soundGunshot:
      path: /Audio/Weapons/Guns/Gunshots/taser2.ogg
  - type: ProjectileBatteryAmmoProvider
    proto: BulletEnergyTurretLaser
    fireCost: 100
  - type: Battery
    maxCharge: 2000
    startingCharge: 0
  - type: ApcPowerReceiverBattery
    idleLoad: 5
    batteryRechargeRate: 200
    batteryRechargeEfficiency: 0.0 #temporarily no power draw because this was causing potentially seizure inducing light flickering
  - type: ApcPowerReceiver
    powerLoad: 5
  - type: ExtensionCableReceiver
  - type: HTN
    rootTask:
      task: EnergyTurretCompound
