This commit is contained in:
sharlotte
2021-09-19 14:06:20 +09:00
parent c8b7ae13c2
commit 210cd78fe5
13 changed files with 138 additions and 90 deletions

View File

@@ -1,9 +1,15 @@
package UnitInfo;
import arc.graphics.g2d.*;
import arc.math.Mathf;
import arc.scene.style.*;
import arc.util.Strings;
import mindustry.core.UI;
import mindustry.entities.bullet.BulletType;
import mindustry.entities.bullet.LightningBulletType;
import mindustry.type.UnitType;
import mindustry.type.weapons.PointDefenseWeapon;
import mindustry.type.weapons.RepairBeamWeapon;
import java.lang.reflect.*;
@@ -27,6 +33,29 @@ public class SUtils {
return String.valueOf(number);
}
public static float bulletRange(BulletType b) {
float a = 0;
float n = 1;
for (int i = 0; i < b.lifetime; i++) {
a += n;
n *= (1 - b.drag);
};
a += n;
a /= b.lifetime;
return b.speed * a * Mathf.pow(1 - b.drag, b.lifetime / 2) * b.lifetime +
Math.max(b.lightning > 0 || b instanceof LightningBulletType ? (b.lightningLength + b.lightningLengthRand) * 6 : 0,
b.fragBullet != null ? bulletRange(b.fragBullet) * b.fragLifeMax * b.fragVelocityMax : b.splashDamageRadius);
};
public static float unitRange(UnitType u) {
final float[] mrng = {0};
u.weapons.each(w -> w.bullet != null, w -> {
mrng[0] = Math.max(mrng[0], (w instanceof RepairBeamWeapon || w instanceof PointDefenseWeapon) ? 0 : bulletRange(w.bullet));
if(mrng[0] == 0) mrng[0] = w.bullet.range();
});
return mrng[0];
}
public static Object invoke(Object ut, String fieldName) throws IllegalAccessException, NoSuchFieldException {
Field field = ut.getClass().getDeclaredField(fieldName);
field.setAccessible(true);