Global drone repair / Fixed item bridge
This commit is contained in:
@@ -143,10 +143,14 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public void damage(float damage){
|
||||
if(dead) return;
|
||||
|
||||
float preHealth = health;
|
||||
|
||||
Call.onTileDamage(tile, health - tile.block().handleDamage(tile, damage));
|
||||
|
||||
if(health <= 0){
|
||||
Call.onTileDestroyed(tile);
|
||||
}else if(preHealth >= maxHealth() - 0.00001f && health < maxHealth()){ //when just damaged
|
||||
world.indexer.notifyTileDamaged(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@ import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.util.Threads;
|
||||
import io.anuke.ucore.util.EnumSet;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Threads;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -125,6 +126,12 @@ public class Units{
|
||||
return value[0];
|
||||
}
|
||||
|
||||
/**Returns the neareset damaged tile.*/
|
||||
public static TileEntity findDamagedTile(Team team, float x, float y){
|
||||
Tile tile = Geometry.findClosest(x, y, world.indexer.getDamaged(team));
|
||||
return tile == null ? null : tile.entity;
|
||||
}
|
||||
|
||||
/**Returns the neareset ally tile in a range.*/
|
||||
public static TileEntity findAllyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
|
||||
return world.indexer.findTile(team, x, y, range, pred);
|
||||
|
||||
@@ -104,22 +104,17 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(target != null && (((TileEntity) target).health >= ((TileEntity) target).tile.block().health
|
||||
|| target.distanceTo(Drone.this) > discoverRange)){
|
||||
target = null;
|
||||
}
|
||||
|
||||
if(target == null){
|
||||
retarget(() -> {
|
||||
target = Units.findAllyTile(team, x, y, discoverRange,
|
||||
tile -> tile.entity != null && tile.entity.health + 0.0001f < tile.block().health);
|
||||
retarget(() -> {
|
||||
target = Units.findDamagedTile(team, x, y);
|
||||
|
||||
if(target == null){
|
||||
setState(mine);
|
||||
}
|
||||
});
|
||||
}else if(target.distanceTo(Drone.this) > type.range){
|
||||
circle(type.range);
|
||||
if(target == null){
|
||||
setState(mine);
|
||||
}
|
||||
});
|
||||
|
||||
if(target.distanceTo(Drone.this) > type.range){
|
||||
circle(type.range*0.9f);
|
||||
}else{
|
||||
TileEntity entity = (TileEntity) target;
|
||||
entity.healBy(type.healSpeed * entity.tile.block().health / 100f * Timers.delta());
|
||||
@@ -318,7 +313,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
target = null;
|
||||
}
|
||||
|
||||
if(Net.client() && state.is(repair) && target instanceof TileEntity){
|
||||
if(Net.client() && state.is(repair) && target instanceof TileEntity && target.distanceTo(this) < type.range){
|
||||
TileEntity entity = (TileEntity) target;
|
||||
entity.health += type.healSpeed * Timers.delta();
|
||||
entity.health = Mathf.clamp(entity.health, 0, entity.tile.block().health);
|
||||
@@ -329,7 +324,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
|
||||
@Override
|
||||
protected void updateRotation(){
|
||||
if(target != null && (state.is(repair) || state.is(mine))){
|
||||
if(target != null && ((state.is(repair) && target.distanceTo(this) < type.range) || state.is(mine))){
|
||||
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.3f);
|
||||
}else{
|
||||
rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.3f);
|
||||
@@ -355,7 +350,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
|
||||
TargetTrait entity = target;
|
||||
|
||||
if(entity instanceof TileEntity && state.is(repair)){
|
||||
if(entity instanceof TileEntity && state.is(repair) && target.distanceTo(this) < type.range){
|
||||
float len = 5f;
|
||||
Draw.color(Color.BLACK, Color.WHITE, 0.95f + Mathf.absin(Timers.time(), 0.8f, 0.05f));
|
||||
Shapes.laser("beam", "beam-end",
|
||||
|
||||
Reference in New Issue
Block a user