UnitSpawnAbility 'type' field JSON compat / Fixed health bar out of bounds

This commit is contained in:
Anuken
2021-02-26 18:51:14 -05:00
parent d06eee99ba
commit ae6be1db3b
4 changed files with 12 additions and 10 deletions

View File

@@ -15,14 +15,14 @@ import mindustry.ui.*;
import static mindustry.Vars.*;
public class UnitSpawnAbility extends Ability{
public UnitType type;
public UnitType unit;
public float spawnTime = 60f, spawnX, spawnY;
public Effect spawnEffect = Fx.spawn;
protected float timer;
public UnitSpawnAbility(UnitType type, float spawnTime, float spawnX, float spawnY){
this.type = type;
public UnitSpawnAbility(UnitType unit, float spawnTime, float spawnX, float spawnY){
this.unit = unit;
this.spawnTime = spawnTime;
this.spawnX = spawnX;
this.spawnY = spawnY;
@@ -35,10 +35,10 @@ public class UnitSpawnAbility extends Ability{
public void update(Unit unit){
timer += Time.delta * state.rules.unitBuildSpeedMultiplier;
if(timer >= spawnTime && Units.canCreate(unit.team, type)){
if(timer >= spawnTime && Units.canCreate(unit.team, this.unit)){
float x = unit.x + Angles.trnsx(unit.rotation, spawnY, spawnX), y = unit.y + Angles.trnsy(unit.rotation, spawnY, spawnX);
spawnEffect.at(x, y);
Unit u = type.create(unit.team);
Unit u = this.unit.create(unit.team);
u.set(x, y);
u.rotation = unit.rotation;
if(!Vars.net.client()){
@@ -51,16 +51,16 @@ public class UnitSpawnAbility extends Ability{
@Override
public void draw(Unit unit){
if(Units.canCreate(unit.team, type)){
if(Units.canCreate(unit.team, this.unit)){
Draw.draw(Draw.z(), () -> {
float x = unit.x + Angles.trnsx(unit.rotation, spawnY, spawnX), y = unit.y + Angles.trnsy(unit.rotation, spawnY, spawnX);
Drawf.construct(x, y, type.icon(Cicon.full), unit.rotation - 90, timer / spawnTime, 1f, timer);
Drawf.construct(x, y, this.unit.icon(Cicon.full), unit.rotation - 90, timer / spawnTime, 1f, timer);
});
}
}
@Override
public String localized(){
return Core.bundle.format("ability.unitspawn", type.localizedName);
return Core.bundle.format("ability.unitspawn", unit.localizedName);
}
}