001package com.fs.starfarer.api.impl.combat; 002 003import java.awt.Color; 004import java.util.EnumSet; 005 006import org.lwjgl.opengl.GL11; 007import org.lwjgl.util.vector.Vector2f; 008 009import com.fs.starfarer.api.Global; 010import com.fs.starfarer.api.combat.CombatEngineLayers; 011import com.fs.starfarer.api.combat.CombatEntityAPI; 012import com.fs.starfarer.api.combat.DamageAPI; 013import com.fs.starfarer.api.combat.MutableShipStatsAPI; 014import com.fs.starfarer.api.combat.ShipAPI; 015import com.fs.starfarer.api.combat.ShipSystemAPI; 016import com.fs.starfarer.api.combat.ViewportAPI; 017import com.fs.starfarer.api.combat.listeners.DamageTakenModifier; 018 019public class TriadShieldStats extends BaseShipSystemScript implements DamageTakenModifier { 020 021 public static Color JITTER_COLOR = new Color(100,50,255,75); 022 public static Color JITTER_UNDER_COLOR = new Color(100,50,255,155); 023 024 public static class TriadShieldVisuals extends CombatEntityPluginWithParticles { 025 public ShipAPI ship; 026 public TriadShieldStats script; 027 028 public TriadShieldVisuals(ShipAPI ship, TriadShieldStats script) { 029 this.ship = ship; 030 this.script = script; 031 } 032 033 034 @Override 035 public EnumSet<CombatEngineLayers> getActiveLayers() { 036 //return EnumSet.of(CombatEngineLayers.ABOVE_SHIPS_AND_MISSILES_LAYER); 037 return EnumSet.of(CombatEngineLayers.ABOVE_PARTICLES_LOWER); 038 } 039 @Override 040 public boolean isExpired() { 041 return false; 042 } 043 @Override 044 public float getRenderRadius() { 045 return ship.getCollisionRadius() + 100f; 046 } 047 048 @Override 049 public void advance(float amount) { 050 super.advance(amount); 051 052 entity.getLocation().set(ship.getLocation()); 053 if (Global.getCombatEngine().isPaused()) return; 054 } 055 056 @Override 057 public void render(CombatEngineLayers layer, ViewportAPI viewport) { 058 super.render(layer, viewport); 059 060 float alphaMult = viewport.getAlphaMult(); 061 062 ShipSystemAPI system = ship.getPhaseCloak(); 063 if (system == null) system = ship.getSystem(); 064 alphaMult *= system.getEffectLevel(); 065 if (alphaMult <= 0f) return; 066 067 GL11.glPushMatrix(); 068 GL11.glTranslatef(ship.getLocation().x, ship.getLocation().y, 0); 069 GL11.glRotatef(ship.getFacing(), 0, 0, 1); 070 071 GL11.glPopMatrix(); 072 073 } 074 } 075 076 protected TriadShieldVisuals visuals = null; 077 078 public String modifyDamageTaken(Object param, CombatEntityAPI target, DamageAPI damage, Vector2f point, boolean shieldHit) { 079 return null; 080 } 081 082 public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) { 083 ShipAPI ship = null; 084 boolean player = false; 085 if (stats.getEntity() instanceof ShipAPI) { 086 ship = (ShipAPI) stats.getEntity(); 087 player = ship == Global.getCombatEngine().getPlayerShip(); 088 id = id + "_" + ship.getId(); 089 } else { 090 return; 091 } 092 093 if (visuals == null) { 094 visuals = new TriadShieldVisuals(ship, this); 095 Global.getCombatEngine().addLayeredRenderingPlugin(visuals); 096 ship.addListener(this); 097 } 098 099 if (Global.getCombatEngine().isPaused()) { 100 return; 101 } 102 103 if (state == State.COOLDOWN || state == State.IDLE) { 104 unapply(stats, id); 105 return; 106 } 107 108 ShipSystemAPI system = ship.getPhaseCloak(); 109 if (system == null) system = ship.getSystem(); 110 111 112 113 float jitterLevel = effectLevel; 114 if (state == State.OUT) { 115 jitterLevel *= jitterLevel; 116 } 117 float jitterRangeBonus = jitterLevel * 0f; 118 if (state == State.IN || state == State.ACTIVE) { 119 120 } else if (state == State.OUT) { 121 122 } 123 124 float minJitter = 4; 125 JITTER_COLOR = new Color(100,100,255,75); 126 JITTER_UNDER_COLOR = new Color(100,100,255,155); 127 128 //JITTER_COLOR = new Color(100,50,255,125); 129// JITTER_UNDER_COLOR = new Color(100,100,255,100); 130// JITTER_UNDER_COLOR = new Color(50,50,125,100); 131// JITTER_COLOR = new Color(100,255,50,125); 132// JITTER_UNDER_COLOR = new Color(255,100,100,100); 133 if (jitterLevel > 0) { 134 ship.setCircularJitter(true); 135 ship.setJitter(this, JITTER_COLOR, jitterLevel, 1, 0f, 7f + jitterRangeBonus); 136 ship.setJitterUnder(this, JITTER_UNDER_COLOR, jitterLevel, 11, minJitter, minJitter + jitterRangeBonus); 137 } 138 } 139 140 141 public void unapply(MutableShipStatsAPI stats, String id) { 142 ShipAPI ship = null; 143 boolean player = false; 144 if (stats.getEntity() instanceof ShipAPI) { 145 ship = (ShipAPI) stats.getEntity(); 146 player = ship == Global.getCombatEngine().getPlayerShip(); 147 id = id + "_" + ship.getId(); 148 } else { 149 return; 150 } 151 152 153 } 154 155 public StatusData getStatusData(int index, State state, float effectLevel) { 156 return null; 157 } 158 159}