Starsector API
Loading...
Searching...
No Matches
GBDartAround.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.ghosts;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.campaign.SectorEntityToken;
6import com.fs.starfarer.api.util.IntervalUtil;
7import com.fs.starfarer.api.util.Misc;
8
9
10public class GBDartAround extends BaseGhostBehavior {
11
12 protected SectorEntityToken other;
13 protected int maxBurn;
14 protected float desiredRange;
15 protected float desiredRangeMin;
16 protected float desiredRangeMax;
17 protected IntervalUtil interval = new IntervalUtil(5f, 10f);
18 protected float angleOffset = 0f;
19 protected Vector2f dest = new Vector2f();
20
21 public GBDartAround(SectorEntityToken other, float duration, int maxBurn, float desiredRangeMin, float desiredRangeMax) {
22 super(duration);
23 this.other = other;
24 this.maxBurn = maxBurn;
25 this.desiredRangeMin = desiredRangeMin;
26 this.desiredRangeMax = desiredRangeMax;
27 interval.forceIntervalElapsed();
28 }
29
30 @Override
31 public void advance(float amount, SensorGhost ghost) {
32 if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) {
33 end();
34 return;
35 }
36 super.advance(amount, ghost);
37
38 float mult = 1f;
39 if (maxBurn >= 25f) mult = 3f;
40 else if (maxBurn >= 15f) mult = 2f;
41 else mult = 1.5f;
42 interval.advance(amount * mult);
43 if (interval.intervalElapsed()) {
44 angleOffset = (float) Math.random() * 360f;
45 desiredRange = desiredRangeMin + (desiredRangeMax - desiredRangeMin) * (float) Math.random();
46 dest = Misc.getUnitVectorAtDegreeAngle(
47 angleOffset + Misc.getAngleInDegrees(other.getLocation(), ghost.getEntity().getLocation()));
48 dest.scale(desiredRange + other.getRadius() + ghost.getEntity().getRadius());
49 Vector2f.add(dest, other.getLocation(), dest);
50 }
51
52 if (Misc.getDistance(dest, ghost.getEntity().getLocation()) < 10f) {
53 interval.forceIntervalElapsed();
54 }
55
56 ghost.moveTo(dest, new Vector2f(), maxBurn);
57 }
58
59
60
61}
62
63
64
65
66
67
68
69
70
71
72
73
74
void advance(float amount, SensorGhost ghost)
GBDartAround(SectorEntityToken other, float duration, int maxBurn, float desiredRangeMin, float desiredRangeMax)
void moveTo(Vector2f dest, float maxBurn)