001package com.fs.starfarer.api.impl.campaign.skills; 002 003import java.awt.Color; 004 005import org.lwjgl.util.vector.Vector2f; 006 007import com.fs.starfarer.api.characters.AfterShipCreationSkillEffect; 008import com.fs.starfarer.api.characters.DescriptionSkillEffect; 009import com.fs.starfarer.api.characters.ShipSkillEffect; 010import com.fs.starfarer.api.combat.CombatEntityAPI; 011import com.fs.starfarer.api.combat.DamageAPI; 012import com.fs.starfarer.api.combat.MutableShipStatsAPI; 013import com.fs.starfarer.api.combat.ShipAPI; 014import com.fs.starfarer.api.combat.ShipAPI.HullSize; 015import com.fs.starfarer.api.combat.ShipHullSpecAPI.ShipTypeHints; 016import com.fs.starfarer.api.combat.listeners.AdvanceableListener; 017import com.fs.starfarer.api.combat.listeners.DamageTakenModifier; 018import com.fs.starfarer.api.util.Misc; 019 020public class PolarizedArmor { 021 022 //public static float ARMOR_FRACTION_BONUS = 0.05f; 023 public static float EFFECTIVE_ARMOR_BONUS = 50; 024 public static float EMP_BONUS_PERCENT = 50f; 025 026 public static float VENT_RATE_BONUS = 25f; 027 028 public static float NON_SHIELD_FLUX_LEVEL = 50f; 029 030 public static class Level0 implements DescriptionSkillEffect { 031 public String getString() { 032 return "\n\n*Ships without a shield or a phase cloak are treated as always having " + (int) NON_SHIELD_FLUX_LEVEL + "% hard flux."; 033 } 034 public Color[] getHighlightColors() { 035 Color h = Misc.getHighlightColor(); 036 h = Misc.getDarkHighlightColor(); 037 return new Color[] {h}; 038 } 039 public String[] getHighlights() { 040 return new String [] {"" + (int) NON_SHIELD_FLUX_LEVEL + "%"}; 041 } 042 public Color getTextColor() { 043 return null; 044 } 045 } 046 047 public static class PolarizedArmorEffectMod implements DamageTakenModifier, AdvanceableListener { 048 protected ShipAPI ship; 049 protected String id; 050 public PolarizedArmorEffectMod(ShipAPI ship, String id) { 051 this.ship = ship; 052 this.id = id; 053 } 054 055 public void advance(float amount) { 056 MutableShipStatsAPI stats = ship.getMutableStats(); 057 058 float fluxLevel = ship.getHardFluxLevel(); 059 060 if (ship.getShield() == null && !ship.getHullSpec().isPhase() && 061 (ship.getPhaseCloak() == null || !ship.getHullSpec().getHints().contains(ShipTypeHints.PHASE))) { 062 fluxLevel = NON_SHIELD_FLUX_LEVEL * 0.01f; 063 } 064 065 //float armorBonus = ship.getArmorGrid().getArmorRating() * ARMOR_FRACTION_BONUS * fluxLevel; 066 float armorBonus = EFFECTIVE_ARMOR_BONUS * fluxLevel; 067 float empBonus = EMP_BONUS_PERCENT * fluxLevel; 068 //armorBonus = 1090000; 069 //wefwef we fe stats.getMaxArmorDamageReduction().modifyFlat(id, 0.1f); 070 //stats.getEffectiveArmorBonus().modifyFlat(id, armorBonus); 071 stats.getEffectiveArmorBonus().modifyPercent(id, armorBonus); 072 stats.getEmpDamageTakenMult().modifyMult(id, 1f - empBonus * 0.01f); 073 074 //Color c = new Color(255, 200, 100, 100); 075 Color c = ship.getSpriteAPI().getAverageColor(); 076 c = Misc.setAlpha(c, 127); 077 float b = 0f; 078 if (fluxLevel > 0.75f) { 079 b = 1f * (fluxLevel - 0.75f) / 0.25f; 080 } 081 if (b > 0) { 082 ship.setJitter(this, c, 1f * fluxLevel * b, 1, 0f); 083 } 084 } 085 086 public String modifyDamageTaken(Object param, 087 CombatEntityAPI target, DamageAPI damage, 088 Vector2f point, boolean shieldHit) { 089 return null; 090 } 091 092 } 093 094 public static class Level1 implements ShipSkillEffect { 095 096 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) { 097 stats.getMaxArmorDamageReduction().modifyFlat(id, 0.05f); 098 } 099 100 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) { 101 stats.getMaxArmorDamageReduction().unmodify(id); 102 } 103 104 public String getEffectDescription(float level) { 105 return "Maximum damage reduction by armor increased from 85% to 90%"; 106 } 107 108 public String getEffectPerLevelDescription() { 109 return null; 110 } 111 112 public ScopeDescription getScopeDescription() { 113 return ScopeDescription.PILOTED_SHIP; 114 } 115 } 116 117 118 public static class Level2 implements AfterShipCreationSkillEffect { 119 public void applyEffectsAfterShipCreation(ShipAPI ship, String id) { 120 ship.addListener(new PolarizedArmorEffectMod(ship, id)); 121 } 122 public void unapplyEffectsAfterShipCreation(ShipAPI ship, String id) { 123 MutableShipStatsAPI stats = ship.getMutableStats(); 124 ship.removeListenerOfClass(PolarizedArmorEffectMod.class); 125 stats.getEffectiveArmorBonus().unmodify(id); 126 stats.getEmpDamageTakenMult().unmodify(id); 127 } 128 129 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {} 130 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {} 131 132 public String getEffectDescription(float level) { 133 //return "Up to +" + (int)Math.round(ARMOR_FRACTION_BONUS * 100f) + "% of base armor for damage reduction calculation only, based on current hard flux level"; 134 135 return "Up to +" + (int)(EFFECTIVE_ARMOR_BONUS) + "% armor for damage reduction calculation only, based on current hard flux level*"; 136 } 137 public String getEffectPerLevelDescription() { 138 return null; 139 } 140 public ScopeDescription getScopeDescription() { 141 return ScopeDescription.PILOTED_SHIP; 142 } 143 } 144 145 public static class Level3 implements ShipSkillEffect { 146 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {} 147 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {} 148 149 public String getEffectDescription(float level) { 150 return "EMP damage taken reduced by up to " + (int)Math.round(EMP_BONUS_PERCENT) + "%, based on current hard flux level*"; 151 } 152 public String getEffectPerLevelDescription() { 153 return null; 154 } 155 public ScopeDescription getScopeDescription() { 156 return ScopeDescription.PILOTED_SHIP; 157 } 158 } 159 160 public static class Level4 implements ShipSkillEffect { 161 162 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) { 163 stats.getVentRateMult().modifyPercent(id, VENT_RATE_BONUS); 164 } 165 166 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) { 167 stats.getVentRateMult().unmodify(id); 168 } 169 170 public String getEffectDescription(float level) { 171 return "+" + (int)(VENT_RATE_BONUS) + "% flux dissipation rate while venting"; 172 //return "+" + (int)(VENT_RATE_BONUS) + "% flux vent rate"; 173 } 174 175 public String getEffectPerLevelDescription() { 176 return null; 177 } 178 179 public ScopeDescription getScopeDescription() { 180 return ScopeDescription.PILOTED_SHIP; 181 } 182 } 183 184} 185 186 187 188 189 190 191 192 193 194 195