<commit_before>{ EntityScript } = require('src/lib/LazerScript')
{ MineCannonInActive, MineCannonActive } = require('./mine_cannon')
{ TurretInActive, TurretActive } = require('./turret')
{ Swirler, Shooter, CrewShooters, Stalker, ScraperFlyer, DroneFlyer } = require('../stage1/army_drone')
{ HeliInactive, HeliFlyAway, HeliAttack } = require('./heli_attack')

class Cabin1Inactive extends EntityScript
  spawn: (options) ->
    Crafty.e('FirstShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  execute: ->
    @invincible yes

class Cabin1Active extends EntityScript
  spawn: (options) ->
    item = Crafty('FirstShipCabin').get(0)
    if item and item.health > 10
      item.reveal()
      return item
    Crafty.e('FirstShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  onKilled: ->
    @deathDecoy()

  execute: ->
    @bindSequence 'Destroyed', @onKilled
    @sequence(
      @invincible no
      @wait(20000)
    )

class Cabin2Inactive extends EntityScript
  spawn: (options) ->
    Crafty.e('SecondShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  execute: ->
    @invincible yes

class Cabin2Active extends EntityScript
  spawn: (options) ->
    item = Crafty('SecondShipCabin').get(0)
    if item and item.health > 10
      item.reveal()
      return item
    Crafty.e('SecondShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  onKilled: ->
    @deathDecoy()

  execute: ->
    @bindSequence 'Destroyed', @onKilled
    @sequence(
      @invincible no
      @wait(20000)
    )

class ShipBoss extends EntityScript

  spawn: (options) ->
    Crafty.e('BattleShip').attr(
      x: Crafty.viewport.width + 180
      y: 400
      defaultSpeed: options.speed ? 85
    )
    # .setSealevel(@level.visibleHeight - 10)

  getPath: (pattern) ->
    console.log('pattern', pattern)
    return [
      [.156, .5]
      [.5, .833]
      [.86, .52]

      [.5, .21]
      [.156, .5]
      [.5, .833]
      [.86, .52]

      [-20, .21]
    ]

  randomAmountSpawnedDrones: ->
    console.log(Math.round(Math.random() * 5))
    return Math.round(Math.random() * 5)

  placeEnemiesOnShip: ->
    @sequence(
      @placeSquad Cabin1Inactive,
        options:
          attach: 'Cabin1Place'
      @placeSquad Cabin2Inactive,
        options:
          attach: 'Cabin2Place'
      @placeSquad TurretInActive, # Turret
        amount: 2
        delay: 0
        options:
          attach: 'TurretPlace'
      @placeSquad MineCannonInActive, # MineCannon
        options:
          attach: 'MineCannonPlace'
      @placeSquad HeliInactive,
        amount: 2
        delay: 0
        options:
          attach: 'HeliPlace'
    )

  executeStageOne: ->
    @sequence(
      @moveTo(x: 0.8, easing: "easeInOutQuad")
      @placeSquad MineCannonActive,
        options:
          attach: 'MineCannonPlace'
    )

  releaseDronesFromHatchOne: (dronePattern) ->
    @sequence(
      @action 'open1'
      @wait(500)
      @parallel(
        @placeSquad DroneFlyer,
          amount: 5,
          delay: 500
          options:
            startAt: 'ShipHatch1'
            hatchReveal: 'ShipHatch1'
            dx: 25
            dy: 20
            debug: true,
            path: @getPath(dronePattern)
        @sequence(
          @wait(1200)
          @action 'close1'
        )
      )
    )

  releaseDronesFromHatchTwo: (dronePattern) ->
    @sequence(
      @action 'open2'
      @wait(500)
      @parallel(
        @placeSquad DroneFlyer,
          amount: 8,
          delay: 500
          options:
            startAt: 'ShipHatch1'
            hatchReveal: 'ShipHatch1'
            dx: 25
            dy: 20
            debug: true,
            path: @getPath(dronePattern)<commit_msg>Fix departure point from hatch 2<commit_after>{ EntityScript } = require('src/lib/LazerScript')
{ MineCannonInActive, MineCannonActive } = require('./mine_cannon')
{ TurretInActive, TurretActive } = require('./turret')
{ Swirler, Shooter, CrewShooters, Stalker, ScraperFlyer, DroneFlyer } = require('../stage1/army_drone')
{ HeliInactive, HeliFlyAway, HeliAttack } = require('./heli_attack')

class Cabin1Inactive extends EntityScript
  spawn: (options) ->
    Crafty.e('FirstShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  execute: ->
    @invincible yes

class Cabin1Active extends EntityScript
  spawn: (options) ->
    item = Crafty('FirstShipCabin').get(0)
    if item and item.health > 10
      item.reveal()
      return item
    Crafty.e('FirstShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  onKilled: ->
    @deathDecoy()

  execute: ->
    @bindSequence 'Destroyed', @onKilled
    @sequence(
      @invincible no
      @wait(20000)
    )

class Cabin2Inactive extends EntityScript
  spawn: (options) ->
    Crafty.e('SecondShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  execute: ->
    @invincible yes

class Cabin2Active extends EntityScript
  spawn: (options) ->
    item = Crafty('SecondShipCabin').get(0)
    if item and item.health > 10
      item.reveal()
      return item
    Crafty.e('SecondShipCabin, KeepAlive')
      .shipCabin()
      .sendToBackground(1.0, -8)

  onKilled: ->
    @deathDecoy()

  execute: ->
    @bindSequence 'Destroyed', @onKilled
    @sequence(
      @invincible no
      @wait(20000)
    )

class ShipBoss extends EntityScript

  spawn: (options) ->
    Crafty.e('BattleShip').attr(
      x: Crafty.viewport.width + 180
      y: 400
      defaultSpeed: options.speed ? 85
    )
    # .setSealevel(@level.visibleHeight - 10)

  getPath: (pattern) ->
    console.log('pattern', pattern)
    return [
      [.156, .5]
      [.5, .833]
      [.86, .52]

      [.5, .21]
      [.156, .5]
      [.5, .833]
      [.86, .52]

      [-20, .21]
    ]

  randomAmountSpawnedDrones: ->
    console.log(Math.round(Math.random() * 5))
    return Math.round(Math.random() * 5)

  placeEnemiesOnShip: ->
    @sequence(
      @placeSquad Cabin1Inactive,
        options:
          attach: 'Cabin1Place'
      @placeSquad Cabin2Inactive,
        options:
          attach: 'Cabin2Place'
      @placeSquad TurretInActive, # Turret
        amount: 2
        delay: 0
        options:
          attach: 'TurretPlace'
      @placeSquad MineCannonInActive, # MineCannon
        options:
          attach: 'MineCannonPlace'
      @placeSquad HeliInactive,
        amount: 2
        delay: 0
        options:
          attach: 'HeliPlace'
    )

  executeStageOne: ->
    @sequence(
      @moveTo(x: 0.8, easing: "easeInOutQuad")
      @placeSquad MineCannonActive,
        options:
          attach: 'MineCannonPlace'
    )

  releaseDronesFromHatchOne: (dronePattern) ->
    @sequence(
      @action 'open1'
      @wait(500)
      @parallel(
        @placeSquad DroneFlyer,
          amount: 5,
          delay: 500
          options:
            startAt: 'ShipHatch1'
            hatchReveal: 'ShipHatch1'
            dx: 25
            dy: 20
            debug: true,
            path: @getPath(dronePattern)
        @sequence(
          @wait(1200)
          @action 'close1'
        )
      )
    )

  releaseDronesFromHatchTwo: (dronePattern) ->
    @sequence(
      @action 'open2'
      @wait(500)
      @parallel(
        @placeSquad DroneFlyer,
          amount: 8,
          delay: 500
          options:
            startAt: 'ShipHatch2'
            hatchReveal: 'ShipHatch2'
            dx: 25
            dy: 20
            debug: true,
            path: @getPath(dronePattern)
{'fraction_non_alphanumeric': 0.12122809329292397, 'fraction_numerical': 0.03149295032283568, 'mean_word_length': 2.0929095354523226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4998952', 'n_tokens_mistral': 2782, 'n_tokens_neox': 2598, 'n_words': 520}