Starsector API
Loading...
Searching...
No Matches
ShockRepeaterOnFireEffect.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.util.Iterator;
4
5import java.awt.Color;
6
7import org.lwjgl.util.vector.Vector2f;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.combat.CollisionClass;
11import com.fs.starfarer.api.combat.CombatEngineAPI;
12import com.fs.starfarer.api.combat.CombatEntityAPI;
13import com.fs.starfarer.api.combat.DamageType;
14import com.fs.starfarer.api.combat.DamagingProjectileAPI;
15import com.fs.starfarer.api.combat.EmpArcEntityAPI;
16import com.fs.starfarer.api.combat.MissileAPI;
17import com.fs.starfarer.api.combat.OnFireEffectPlugin;
18import com.fs.starfarer.api.combat.ShipAPI;
19import com.fs.starfarer.api.combat.WeaponAPI;
20import com.fs.starfarer.api.combat.WeaponAPI.AIHints;
21import com.fs.starfarer.api.impl.campaign.ids.Stats;
22import com.fs.starfarer.api.util.Misc;
23
27
28 public static float ARC = 30f;
29
30 public void onFire(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine) {
31 //ARC = 30f;
32 float emp = projectile.getEmpAmount();
33 float dam = projectile.getDamageAmount();
34
35 CombatEntityAPI target = findTarget(projectile, weapon, engine);
36 float thickness = 20f;
37 float coreWidthMult = 0.67f;
38 Color color = weapon.getSpec().getGlowColor();
39 if (target != null) {
40 EmpArcEntityAPI arc = engine.spawnEmpArc(projectile.getSource(), projectile.getLocation(), weapon.getShip(),
41 target,
43 dam,
44 emp, // emp
45 100000f, // max range
46 "shock_repeater_emp_impact",
47 thickness, // thickness
48 color,
49 new Color(255,255,255,255)
50 );
51 arc.setCoreWidthOverride(thickness * coreWidthMult);
53 } else {
54 Vector2f from = new Vector2f(projectile.getLocation());
55 Vector2f to = pickNoTargetDest(projectile, weapon, engine);
56 EmpArcEntityAPI arc = engine.spawnEmpArcVisual(from, weapon.getShip(), to, weapon.getShip(), thickness, color, Color.white);
57 arc.setCoreWidthOverride(thickness * coreWidthMult);
59 //Global.getSoundPlayer().playSound("shock_repeater_emp_impact", 1f, 1f, to, new Vector2f());
60 }
61 }
62
63 public Vector2f pickNoTargetDest(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine) {
64 float spread = 50f;
65 float range = weapon.getRange() - spread;
66 Vector2f from = projectile.getLocation();
67 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(weapon.getCurrAngle());
68 dir.scale(range);
69 Vector2f.add(from, dir, dir);
70 dir = Misc.getPointWithinRadius(dir, spread);
71 return dir;
72 }
73
75 float range = weapon.getRange();
76 Vector2f from = projectile.getLocation();
77
78 Iterator<Object> iter = Global.getCombatEngine().getAllObjectGrid().getCheckIterator(from,
79 range * 2f, range * 2f);
80 int owner = weapon.getShip().getOwner();
81 CombatEntityAPI best = null;
82 float minScore = Float.MAX_VALUE;
83
84 ShipAPI ship = weapon.getShip();
85 boolean ignoreFlares = ship != null && ship.getMutableStats().getDynamic().getValue(Stats.PD_IGNORES_FLARES, 0) >= 1;
86 ignoreFlares |= weapon.hasAIHint(AIHints.IGNORES_FLARES);
87
88 while (iter.hasNext()) {
89 Object o = iter.next();
90 if (!(o instanceof MissileAPI) &&
92 !(o instanceof ShipAPI)) continue;
94 if (other.getOwner() == owner) continue;
95
96 if (other instanceof ShipAPI) {
97 ShipAPI otherShip = (ShipAPI) other;
98 if (otherShip.isHulk()) continue;
99 //if (!otherShip.isAlive()) continue;
100 if (otherShip.isPhased()) continue;
101 if (!otherShip.isTargetable()) continue;
102 }
103
104 if (other.getCollisionClass() == CollisionClass.NONE) continue;
105
106 if (ignoreFlares && other instanceof MissileAPI) {
107 MissileAPI missile = (MissileAPI) other;
108 if (missile.isFlare()) continue;
109 }
110
111 float radius = Misc.getTargetingRadius(from, other, false);
112 float dist = Misc.getDistance(from, other.getLocation()) - radius;
113 if (dist > range) continue;
114
115 if (!Misc.isInArc(weapon.getCurrAngle(), ARC, from, other.getLocation())) continue;
116
117 //float angleTo = Misc.getAngleInDegrees(from, other.getLocation());
118 //float score = Misc.getAngleDiff(weapon.getCurrAngle(), angleTo);
119 float score = dist;
120
121 if (score < minScore) {
122 minScore = score;
123 best = other;
124 }
125 }
126 return best;
127 }
128
129}
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
CombatEntityAPI findTarget(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine)
void onFire(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine)
Vector2f pickNoTargetDest(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine)
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
Definition Misc.java:1196
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
static float getTargetingRadius(Vector2f from, CombatEntityAPI target, boolean considerShield)
Definition Misc.java:1349
static Vector2f getPointWithinRadius(Vector2f from, float r)
Definition Misc.java:711
static boolean isInArc(float direction, float arc, Vector2f from, Vector2f to)
Definition Misc.java:1722
Iterator< Object > getCheckIterator(Vector2f loc, float checkWidth, float checkHeight)
EmpArcEntityAPI spawnEmpArcVisual(Vector2f from, CombatEntityAPI fromAnchor, Vector2f to, CombatEntityAPI toAnchor, float thickness, Color fringe, Color core)
EmpArcEntityAPI spawnEmpArc(ShipAPI damageSource, Vector2f point, CombatEntityAPI pointAnchor, CombatEntityAPI empTargetEntity, DamageType damageType, float damAmount, float empDamAmount, float maxRange, String impactSoundId, float thickness, Color fringe, Color core)
void setCoreWidthOverride(float coreWidthOverride)
MutableShipStatsAPI getMutableStats()