many things
This commit is contained in:
@@ -2,7 +2,16 @@ package mindustry.entities.abilities;
|
||||
|
||||
import mindustry.gen.*;
|
||||
|
||||
public interface Ability{
|
||||
default void update(Unit unit){}
|
||||
default void draw(Unit unit){}
|
||||
public abstract class Ability implements Cloneable{
|
||||
public void update(Unit unit){}
|
||||
public void draw(Unit unit){}
|
||||
|
||||
public Ability copy(){
|
||||
try{
|
||||
return (Ability)clone();
|
||||
}catch(CloneNotSupportedException e){
|
||||
//I am disgusted
|
||||
throw new RuntimeException("java sucks", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
public class ForceFieldAbility implements Ability{
|
||||
public class ForceFieldAbility extends Ability{
|
||||
/** Shield radius. */
|
||||
public float radius = 60f;
|
||||
/** Shield regen speed in damage/tick. */
|
||||
@@ -21,18 +21,22 @@ public class ForceFieldAbility implements Ability{
|
||||
/** Cooldown after the shield is broken, in ticks. */
|
||||
public float cooldown = 60f * 5;
|
||||
|
||||
private float realRad;
|
||||
private Unit paramUnit;
|
||||
private final Cons<Shielderc> shieldConsumer = trait -> {
|
||||
/** State: radius scaling. */
|
||||
protected float radiusScale;
|
||||
|
||||
private static float realRad;
|
||||
private static Unit paramUnit;
|
||||
private static ForceFieldAbility paramField;
|
||||
private static final Cons<Shielderc> shieldConsumer = trait -> {
|
||||
if(trait.team() != paramUnit.team && Intersector.isInsideHexagon(paramUnit.x, paramUnit.y, realRad * 2f, trait.x(), trait.y()) && paramUnit.shield > 0){
|
||||
trait.absorb();
|
||||
Fx.absorb.at(trait);
|
||||
|
||||
//break shield
|
||||
if(paramUnit.shield <= trait.damage()){
|
||||
paramUnit.shield -= cooldown * regen;
|
||||
paramUnit.shield -= paramField.cooldown * paramField.regen;
|
||||
|
||||
Fx.shieldBreak.at(paramUnit.x, paramUnit.y, radius, paramUnit.team.color);
|
||||
Fx.shieldBreak.at(paramUnit.x, paramUnit.y, paramField.radius, paramUnit.team.color);
|
||||
}
|
||||
|
||||
paramUnit.shield -= trait.damage();
|
||||
@@ -56,13 +60,14 @@ public class ForceFieldAbility implements Ability{
|
||||
}
|
||||
|
||||
if(unit.shield > 0){
|
||||
unit.timer2 = Mathf.lerpDelta(unit.timer2, 1f, 0.06f);
|
||||
radiusScale = Mathf.lerpDelta(radiusScale, 1f, 0.06f);
|
||||
paramUnit = unit;
|
||||
paramField = this;
|
||||
checkRadius(unit);
|
||||
|
||||
Groups.bullet.intersect(unit.x - realRad, unit.y - realRad, realRad * 2f, realRad * 2f, shieldConsumer);
|
||||
}else{
|
||||
unit.timer2 = 0f;
|
||||
radiusScale = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +94,6 @@ public class ForceFieldAbility implements Ability{
|
||||
|
||||
private void checkRadius(Unit unit){
|
||||
//timer2 is used to store radius scale as an effect
|
||||
realRad = unit.timer2 * radius;
|
||||
realRad = radiusScale * radius;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class HealFieldAbility implements Ability{
|
||||
public class HealFieldAbility extends Ability{
|
||||
public float amount = 1, reload = 100, range = 60;
|
||||
public Effect healEffect = Fx.heal;
|
||||
public Effect activeEffect = Fx.healWave;
|
||||
|
||||
private boolean wasHealed = false;
|
||||
protected float timer;
|
||||
protected boolean wasHealed = false;
|
||||
|
||||
HealFieldAbility(){}
|
||||
|
||||
@@ -22,9 +23,9 @@ public class HealFieldAbility implements Ability{
|
||||
|
||||
@Override
|
||||
public void update(Unit unit){
|
||||
unit.timer1 += Time.delta;
|
||||
timer += Time.delta;
|
||||
|
||||
if(unit.timer1 >= reload){
|
||||
if(timer >= reload){
|
||||
wasHealed = false;
|
||||
|
||||
Units.nearby(unit.team, unit.x, unit.y, range, other -> {
|
||||
@@ -39,7 +40,7 @@ public class HealFieldAbility implements Ability{
|
||||
activeEffect.at(unit);
|
||||
}
|
||||
|
||||
unit.timer1 = 0f;
|
||||
timer = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class ShieldFieldAbility implements Ability{
|
||||
public class ShieldFieldAbility extends Ability{
|
||||
public float amount = 1, max = 100f, reload = 100, range = 60;
|
||||
public Effect applyEffect = Fx.shieldApply;
|
||||
public Effect activeEffect = Fx.shieldWave;
|
||||
|
||||
private boolean applied = false;
|
||||
protected float timer;
|
||||
protected boolean applied = false;
|
||||
|
||||
ShieldFieldAbility(){}
|
||||
|
||||
@@ -23,9 +24,9 @@ public class ShieldFieldAbility implements Ability{
|
||||
|
||||
@Override
|
||||
public void update(Unit unit){
|
||||
unit.timer1 += Time.delta;
|
||||
timer += Time.delta;
|
||||
|
||||
if(unit.timer1 >= reload){
|
||||
if(timer >= reload){
|
||||
applied = false;
|
||||
|
||||
Units.nearby(unit.team, unit.x, unit.y, range, other -> {
|
||||
@@ -41,7 +42,7 @@ public class ShieldFieldAbility implements Ability{
|
||||
activeEffect.at(unit);
|
||||
}
|
||||
|
||||
unit.timer1 = 0f;
|
||||
timer = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class StatusFieldAbility implements Ability{
|
||||
public class StatusFieldAbility extends Ability{
|
||||
public @NonNull StatusEffect effect;
|
||||
public float duration = 60, reload = 100, range = 20;
|
||||
public Effect applyEffect = Fx.heal;
|
||||
public Effect activeEffect = Fx.overdriveWave;
|
||||
|
||||
protected float timer;
|
||||
|
||||
StatusFieldAbility(){}
|
||||
|
||||
public StatusFieldAbility(@NonNull StatusEffect effect, float duration, float reload, float range){
|
||||
@@ -24,9 +26,9 @@ public class StatusFieldAbility implements Ability{
|
||||
|
||||
@Override
|
||||
public void update(Unit unit){
|
||||
unit.timer2 += Time.delta;
|
||||
timer += Time.delta;
|
||||
|
||||
if(unit.timer2 >= reload){
|
||||
if(timer >= reload){
|
||||
|
||||
Units.nearby(unit.team, unit.x, unit.y, range, other -> {
|
||||
other.apply(effect, duration);
|
||||
@@ -34,7 +36,7 @@ public class StatusFieldAbility implements Ability{
|
||||
|
||||
activeEffect.at(unit);
|
||||
|
||||
unit.timer2 = 0f;
|
||||
timer = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
60
core/src/mindustry/entities/abilities/UnitSpawnAbility.java
Normal file
60
core/src/mindustry/entities/abilities/UnitSpawnAbility.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package mindustry.entities.abilities;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
public class UnitSpawnAbility extends Ability{
|
||||
public @NonNull UnitType type;
|
||||
public float spawnTime = 60f, spawnX, spawnY;
|
||||
public Effect spawnEffect = Fx.spawn;
|
||||
|
||||
protected float timer;
|
||||
|
||||
public UnitSpawnAbility(@NonNull UnitType type, float spawnTime, float spawnX, float spawnY){
|
||||
this.type = type;
|
||||
this.spawnTime = spawnTime;
|
||||
this.spawnX = spawnX;
|
||||
this.spawnY = spawnY;
|
||||
}
|
||||
|
||||
public UnitSpawnAbility(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Unit unit){
|
||||
timer += Time.delta;
|
||||
|
||||
if(timer >= spawnTime && Units.canCreate(unit.team, type)){
|
||||
|
||||
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);
|
||||
u.set(x, y);
|
||||
u.rotation = unit.rotation;
|
||||
if(!Vars.net.client()){
|
||||
u.add();
|
||||
}
|
||||
|
||||
timer = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Unit unit){
|
||||
if(Units.canCreate(unit.team, type)){
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user