Fix units that can't be hit being hit by some things. (#7391)

* Hittable check in checkTarget

* Remove hittable() and checkTarget() overlap

* Make PointBulletType abide collision types

There should probably be a thing for jsonable `buildingFilter`s, in the case that you want something that doesn't target blocks.

* PointBulletTypes should not be reflectable

* oop

* Use targettable instead of hittable

* targetable check for Damage#linecast

* targetable check for defenderAI

* I shot, and then I hit something, but it was some invisible thing in the way, so I guess I missed
This commit is contained in:
MEEPofFaith
2022-08-19 19:05:11 -07:00
committed by GitHub
parent b9e633a10e
commit 6ca54d4f6a
5 changed files with 8 additions and 7 deletions

View File

@@ -28,7 +28,7 @@ public class DefenderAI extends AIController{
public Teamc findTarget(float x, float y, float range, boolean air, boolean ground){ public Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
//Sort by max health and closer target. //Sort by max health and closer target.
var result = Units.closest(unit.team, x, y, Math.max(range, 400f), u -> !u.dead() && u.type != unit.type, (u, tx, ty) -> -u.maxHealth + Mathf.dst2(u.x, u.y, tx, ty) / 6400f); var result = Units.closest(unit.team, x, y, Math.max(range, 400f), u -> !u.dead() && u.type != unit.type && u.targetable(unit.team), (u, tx, ty) -> -u.maxHealth + Mathf.dst2(u.x, u.y, tx, ty) / 6400f);
if(result != null) return result; if(result != null) return result;
//return core if found //return core if found

View File

@@ -374,7 +374,7 @@ public class Damage{
tmpUnit = null; tmpUnit = null;
Units.nearbyEnemies(hitter.team, rect, e -> { Units.nearbyEnemies(hitter.team, rect, e -> {
if((tmpUnit != null && e.dst2(x, y) > tmpUnit.dst2(x, y)) || !e.checkTarget(hitter.type.collidesAir, hitter.type.collidesGround)) return; if((tmpUnit != null && e.dst2(x, y) > tmpUnit.dst2(x, y)) || !e.checkTarget(hitter.type.collidesAir, hitter.type.collidesGround) || !e.targetable(hitter.team)) return;
e.hitbox(hitrect); e.hitbox(hitrect);
Rect other = hitrect; Rect other = hitrect;
@@ -468,7 +468,7 @@ public class Damage{
/** Damages all entities and blocks in a radius that are enemies of the team. */ /** Damages all entities and blocks in a radius that are enemies of the team. */
public static void damage(Team team, float x, float y, float radius, float damage, boolean complete, boolean air, boolean ground, boolean scaled, Bullet source){ public static void damage(Team team, float x, float y, float radius, float damage, boolean complete, boolean air, boolean ground, boolean scaled, Bullet source){
Cons<Unit> cons = entity -> { Cons<Unit> cons = entity -> {
if(entity.team == team || !entity.hittable() || !entity.within(x, y, radius + (scaled ? entity.hitSize / 2f : 0f)) || (entity.isFlying() && !air) || (entity.isGrounded() && !ground)){ if(entity.team == team || !entity.checkTarget(air, ground) || !entity.hittable() || !entity.within(x, y, radius + (scaled ? entity.hitSize / 2f : 0f))){
return; return;
} }

View File

@@ -101,7 +101,7 @@ public class EnergyFieldAbility extends Ability{
if(hitUnits){ if(hitUnits){
Units.nearby(null, rx, ry, range, other -> { Units.nearby(null, rx, ry, range, other -> {
if(other != unit && (other.isFlying() ? targetAir : targetGround)){ if(other != unit && other.checkTarget(targetAir, targetGround) && other.targetable(unit.team)){
all.add(other); all.add(other);
} }
}); });

View File

@@ -30,7 +30,7 @@ public class FlakBulletType extends BasicBulletType{
if(b.time >= flakDelay && b.fdata >= 0 && b.timer(2, flakInterval)){ if(b.time >= flakDelay && b.fdata >= 0 && b.timer(2, flakInterval)){
Units.nearbyEnemies(b.team, Tmp.r1.setSize(explodeRange * 2f).setCenter(b.x, b.y), unit -> { Units.nearbyEnemies(b.team, Tmp.r1.setSize(explodeRange * 2f).setCenter(b.x, b.y), unit -> {
//fdata < 0 means it's primed to explode //fdata < 0 means it's primed to explode
if(b.fdata < 0f || !unit.checkTarget(collidesAir, collidesGround) || !unit.type.targetable) return; if(b.fdata < 0f || !unit.checkTarget(collidesAir, collidesGround) || !unit.targetable(b.team)) return;
if(unit.within(b, explodeRange + unit.hitSize/2f)){ if(unit.within(b, explodeRange + unit.hitSize/2f)){
//mark as primed //mark as primed

View File

@@ -16,6 +16,7 @@ public class PointBulletType extends BulletType{
scaleLife = true; scaleLife = true;
lifetime = 100f; lifetime = 100f;
collides = false; collides = false;
reflectable = false;
keepVelocity = false; keepVelocity = false;
backMove = false; backMove = false;
} }
@@ -42,7 +43,7 @@ public class PointBulletType extends BulletType{
float range = 1f; float range = 1f;
Units.nearbyEnemies(b.team, px - range, py - range, range*2f, range*2f, e -> { Units.nearbyEnemies(b.team, px - range, py - range, range*2f, range*2f, e -> {
if(e.dead()) return; if(e.dead() || !e.checkTarget(collidesAir, collidesGround) || !e.hittable()) return;
e.hitbox(Tmp.r1); e.hitbox(Tmp.r1);
if(!Tmp.r1.contains(px, py)) return; if(!Tmp.r1.contains(px, py)) return;
@@ -56,7 +57,7 @@ public class PointBulletType extends BulletType{
if(result != null){ if(result != null){
b.collision(result, px, py); b.collision(result, px, py);
}else{ }else if(collidesTiles){
Building build = Vars.world.buildWorld(px, py); Building build = Vars.world.buildWorld(px, py);
if(build != null && build.team != b.team){ if(build != null && build.team != b.team){
build.collision(b); build.collision(b);