Unit status cleanup
This commit is contained in:
@@ -85,6 +85,7 @@ public class StatusEffects implements ContentList{
|
||||
damageMultiplier = 1.4f;
|
||||
damage = -0.01f;
|
||||
effect = Fx.overdriven;
|
||||
permanent = true;
|
||||
}};
|
||||
|
||||
shielded = new StatusEffect("shielded"){{
|
||||
@@ -92,9 +93,7 @@ public class StatusEffects implements ContentList{
|
||||
}};
|
||||
|
||||
boss = new StatusEffect("boss"){{
|
||||
armorMultiplier = 3f;
|
||||
damageMultiplier = 3f;
|
||||
speedMultiplier = 1.1f;
|
||||
permanent = true;
|
||||
}};
|
||||
|
||||
shocked = new StatusEffect("shocked");
|
||||
|
||||
@@ -18,7 +18,7 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
|
||||
@Import Vec2 vel;
|
||||
|
||||
float elevation;
|
||||
float drownTime;
|
||||
transient float drownTime;
|
||||
transient float splashTimer;
|
||||
|
||||
boolean isGrounded(){
|
||||
|
||||
@@ -29,6 +29,12 @@ abstract class StatusComp implements Posc, Flyingc{
|
||||
return amount * Mathf.clamp(1f - armorMultiplier / 100f);
|
||||
}
|
||||
|
||||
/** Apply a status effect for 1 tick (for permanent effects) **/
|
||||
void apply(StatusEffect effect){
|
||||
apply(effect, 1);
|
||||
}
|
||||
|
||||
/** Adds a status effect to this unit. */
|
||||
void apply(StatusEffect effect, float duration){
|
||||
if(effect == StatusEffects.none || effect == null || isImmune(effect)) return; //don't apply empty or immune effects
|
||||
|
||||
@@ -61,6 +67,17 @@ abstract class StatusComp implements Posc, Flyingc{
|
||||
statuses.add(entry);
|
||||
}
|
||||
|
||||
/** Removes a status effect. */
|
||||
void unapply(StatusEffect effect){
|
||||
statuses.remove(e -> {
|
||||
if(e.effect == effect){
|
||||
Pools.free(e);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
boolean isBoss(){
|
||||
return hasEffect(StatusEffects.boss);
|
||||
}
|
||||
@@ -87,7 +104,7 @@ abstract class StatusComp implements Posc, Flyingc{
|
||||
@Override
|
||||
public void update(){
|
||||
Floor floor = floorOn();
|
||||
if(isGrounded() && floor.status != null){
|
||||
if(isGrounded()){
|
||||
//apply effect
|
||||
apply(floor.status, floor.statusDuration);
|
||||
}
|
||||
@@ -105,7 +122,7 @@ abstract class StatusComp implements Posc, Flyingc{
|
||||
entry.time = Math.max(entry.time - Time.delta(), 0);
|
||||
applied.set(entry.effect.id);
|
||||
|
||||
if(entry.time <= 0){
|
||||
if(entry.time <= 0 && !entry.effect.permanent){
|
||||
Pools.free(entry);
|
||||
index --;
|
||||
statuses.remove(index);
|
||||
@@ -119,6 +136,12 @@ abstract class StatusComp implements Posc, Flyingc{
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
for(StatusEntry e : statuses){
|
||||
e.effect.draw((Unitc)this);
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasEffect(StatusEffect effect){
|
||||
return applied.get(effect.id);
|
||||
}
|
||||
|
||||
@@ -18,14 +18,12 @@ import mindustry.world.blocks.environment.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@Component
|
||||
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, Drawc, Boundedc, Syncc{
|
||||
@Import float x, y, rotation, elevation;
|
||||
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc{
|
||||
@Import float x, y, rotation, elevation, maxHealth;
|
||||
|
||||
private UnitController controller;
|
||||
private UnitType type;
|
||||
|
||||
int level;
|
||||
|
||||
public void moveAt(Vec2 vector){
|
||||
moveAt(vector, type.accel);
|
||||
}
|
||||
@@ -92,7 +90,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
||||
@Override
|
||||
public void type(UnitType type){
|
||||
this.type = type;
|
||||
maxHealth(type.health);
|
||||
this.maxHealth = type.health;
|
||||
heal();
|
||||
drag(type.drag);
|
||||
hitSize(type.hitsize);
|
||||
|
||||
@@ -19,6 +19,8 @@ public class StatusEffect extends MappableContent{
|
||||
public float speedMultiplier = 1f;
|
||||
/** Damage per frame. */
|
||||
public float damage;
|
||||
/** If true, the effect never disappears. */
|
||||
public boolean permanent;
|
||||
/** Tint color of effect. */
|
||||
public Color color = Color.white.cpy();
|
||||
/** Effect that happens randomly on top of the affected unit. */
|
||||
@@ -71,6 +73,10 @@ public class StatusEffect extends MappableContent{
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Unitc unit){
|
||||
|
||||
}
|
||||
|
||||
public boolean reactsWith(StatusEffect effect){
|
||||
return transitions.containsKey(effect);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user