001package com.fs.starfarer.api.impl.campaign.ghosts; 002 003import com.fs.starfarer.api.Global; 004import com.fs.starfarer.api.campaign.SectorEntityToken; 005 006public class GBIPlaySound extends BaseGhostBehaviorInterrupt { 007 008 protected String soundId; 009 protected float volume; 010 protected float pitch; 011 protected boolean played = false; 012 013 public GBIPlaySound(float delay, String soundId, float pitch, float volume) { 014 super(delay); 015 this.soundId = soundId; 016 this.pitch = pitch; 017 this.volume = volume; 018 } 019 020 @Override 021 public boolean shouldInterruptBehavior(SensorGhost ghost, GhostBehavior behavior) { 022 if (hasDelayRemaining()) return false; 023 024 if (!played) { 025 SectorEntityToken entity = ghost.getEntity(); 026 if (soundId != null && entity.isInCurrentLocation() && entity.isVisibleToPlayerFleet()) { 027 Global.getSoundPlayer().playSound(soundId, pitch, volume, entity.getLocation(), entity.getVelocity()); 028 } 029 played = true; 030 } 031 032 return false; 033 } 034 035 036}