001package com.fs.starfarer.api.impl.campaign.ghosts; 002 003import java.awt.Color; 004import java.util.ArrayList; 005import java.util.List; 006 007import com.fs.starfarer.api.Global; 008import com.fs.starfarer.api.campaign.CampaignFleetAPI; 009import com.fs.starfarer.api.campaign.CustomCampaignEntityAPI; 010import com.fs.starfarer.api.campaign.SectorEntityToken; 011import com.fs.starfarer.api.impl.campaign.ids.Tags; 012import com.fs.starfarer.api.loading.CampaignPingSpec; 013import com.fs.starfarer.api.util.IntervalUtil; 014import com.fs.starfarer.api.util.Misc; 015 016 017public class GBIRemoraDrain extends BaseGhostBehaviorInterrupt { 018 019 //public static float REMORA_RANGE = 1000f; 020 021 protected SectorEntityToken target; 022 protected float drainRange; 023 protected IntervalUtil tracker = new IntervalUtil(5f, 10f); 024 025 public GBIRemoraDrain(SectorEntityToken target, float drainRange) { 026 super(0f); 027 this.target = target; 028 this.drainRange = drainRange; 029 } 030 031 032 @Override 033 public void advance(float amount, SensorGhost ghost, GhostBehavior behavior) { 034 super.advance(amount, ghost, behavior); 035 036 tracker.advance(amount); 037 if (tracker.intervalElapsed()) { 038 039 CustomCampaignEntityAPI entity = ghost.getEntity(); 040 041 CampaignPingSpec custom = new CampaignPingSpec(); 042 //custom.setUseFactionColor(true); 043 custom.setWidth(15); 044 custom.setRange(drainRange * 1.3f); 045// custom.setRange(drainRange * 1.3f); 046// custom.setMinRange(entity.getRadius()); 047// custom.setInvert(true); 048 custom.setDuration(0.5f); 049 custom.setAlphaMult(1f); 050 custom.setInFraction(0.1f); 051 custom.setNum(1); 052 custom.setColor(new Color(255, 100, 100, 255)); 053 Global.getSector().addPing(entity, custom); 054// Color color = custom.getColor(); 055// Misc.addHitGlow(entity.getContainingLocation(), entity.getLocation(), entity.getVelocity(), 056// entity.getRadius() * 3f + 100f, 0.5f, color); 057 058 if (ghost.getEntity().isInCurrentLocation()) { 059 Global.getSoundPlayer().playSound("ghost_remora_hit", 1f, 1f, 060 ghost.getEntity().getLocation(), ghost.getEntity().getVelocity()); 061 } 062 063 List<SectorEntityToken> list = new ArrayList<SectorEntityToken>(entity.getContainingLocation().getFleets()); 064 list.addAll(entity.getContainingLocation().getCustomEntities()); 065 //list.add(target); 066 for (SectorEntityToken other : list) { 067 if (other.hasTag(Tags.IMMUNE_TO_REMORA_PULSE)) continue; 068 float dist = Misc.getDistance(entity, other) - entity.getRadius() - other.getRadius(); 069 if (dist < drainRange) { 070 if (other.isPlayerFleet()) { 071 other.addFloatingText("Drive field drain!", Misc.getNegativeHighlightColor(), 1f, true); 072 } 073 float mult = 0.5f + 0.5f * (1f - dist / drainRange); 074 if (other instanceof CampaignFleetAPI) { 075 mult *= 2f; 076 } 077 other.addScript(new SpeedReduction(other, 0.5f * mult, 0.5f)); 078 } 079 } 080 } 081 } 082 083} 084 085 086 087 088 089 090 091 092 093 094 095 096