001package com.fs.starfarer.api.impl.campaign.ghosts; 002 003import com.fs.starfarer.api.campaign.SectorEntityToken; 004import com.fs.starfarer.api.util.Misc; 005 006public class GBITooClose extends BaseGhostBehaviorInterrupt { 007 008 protected float distThreshold; 009 protected SectorEntityToken to; 010 protected SharedTrigger trigger; 011 012 public GBITooClose(float delay, SectorEntityToken to, float distThreshold) { 013 this(delay, to, distThreshold, null); 014 } 015 public GBITooClose(float delay, SectorEntityToken to, float distThreshold, SharedTrigger trigger) { 016 super(delay); 017 this.distThreshold = distThreshold; 018 this.to = to; 019 this.trigger = trigger; 020 } 021 022 @Override 023 public boolean shouldInterruptBehavior(SensorGhost ghost, GhostBehavior behavior) { 024 if (hasDelayRemaining()) return false; 025 026 float dist = Misc.getDistance(to, ghost.getEntity()); 027 dist -= to.getRadius(); 028 dist -= ghost.getEntity().getRadius(); 029 030 boolean inRange = dist < distThreshold; 031 if (inRange && trigger != null) { 032 trigger.set(true); 033 } 034 return inRange || (trigger != null && trigger.isSet()); 035 } 036 037 038}