Cleanup / Armor support

This commit is contained in:
Anuken
2020-05-21 14:57:15 -04:00
parent b562c30381
commit 61d9fd3d72
31 changed files with 481 additions and 455 deletions

View File

@@ -78,7 +78,7 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
if(canDrown() && floor.isLiquid && floor.drownTime > 0){
drownTime += Time.delta() * 1f / floor.drownTime;
drownTime = Mathf.clamp(drownTime);
if(Mathf.chance(Time.delta() * 0.05f)){
if(Mathf.chanceDelta(0.05f)){
floor.drownUpdateEffect.at(x, y, 0f, floor.mapColor);
}

View File

@@ -2,6 +2,7 @@ package mindustry.entities.comp;
import arc.math.*;
import arc.util.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
@@ -49,6 +50,20 @@ abstract class HealthComp implements Entityc{
return health < maxHealth - 0.001f;
}
/** Damage and pierce armor. */
void damagePierce(float amount, boolean withEffect){
if(this instanceof Shieldc){
damage(amount / Math.max(1f - ((Shieldc)this).armor(), Vars.minArmorDamage), withEffect);
}else{
damage(amount, withEffect);
}
}
/** Damage and pierce armor. */
void damagePierce(float amount){
damagePierce(amount, true);
}
void damage(float amount){
health -= amount;
hitTime = 1f;
@@ -71,6 +86,10 @@ abstract class HealthComp implements Entityc{
damage(amount * Time.delta(), hitTime <= -20 + hitDuration);
}
void damageContinuousPierce(float amount){
damagePierce(amount * Time.delta(), hitTime <= -20 + hitDuration);
}
void clampHealth(){
health = Mathf.clamp(health, 0, maxHealth);
}

View File

@@ -5,19 +5,26 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.gen.*;
import static mindustry.Vars.minArmorDamage;
@Component
abstract class ShieldComp implements Healthc, Posc{
@Import float health, hitTime;
@Import float health, hitTime, x, y;
@Import boolean dead;
/** Absorbs health damage. */
float shield;
/** Absorbs percentage of damage, up to 90% */
float armor;
/** Shield opacity. */
transient float shieldAlpha = 0f;
@Replace
@Override
public void damage(float amount){
//apply armor
amount *= Math.max(1f - armor, minArmorDamage);
hitTime = 1f;
boolean hadShields = shield > 0.0001f;
@@ -37,7 +44,7 @@ abstract class ShieldComp implements Healthc, Posc{
}
if(hadShields && shield <= 0.0001f){
Fx.unitShieldBreak.at(x(), y(), 0, this);
Fx.unitShieldBreak.at(x, y, 0, this);
}
}
}