Lightning shield absorption

This commit is contained in:
Anuken
2018-09-15 16:37:28 -04:00
parent e284d9de8e
commit e4ea9d561e
13 changed files with 935 additions and 630 deletions

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.traits.AbsorbTrait;
import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TeamTrait;
import io.anuke.mindustry.game.Team;
@@ -26,7 +27,7 @@ import static io.anuke.mindustry.Vars.bulletGroup;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.world;
public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncTrait{
public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncTrait, AbsorbTrait{
private static Vector2 vector = new Vector2();
public Timer timer = new Timer(3);
private Team team;

View File

@@ -9,7 +9,9 @@ import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.AbsorbTrait;
import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TeamTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
@@ -17,9 +19,10 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.TimedEntity;
import io.anuke.ucore.entities.impl.SolidEntity;
import io.anuke.ucore.entities.trait.DrawTrait;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.entities.trait.TimeTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Angles;
@@ -34,17 +37,24 @@ import java.io.IOException;
import static io.anuke.mindustry.Vars.bulletGroup;
import static io.anuke.mindustry.Vars.world;
public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncTrait{
private static Array<SolidTrait> entities = new Array<>();
private static Rectangle rect = new Rectangle();
private static Rectangle hitrect = new Rectangle();
public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncTrait, AbsorbTrait, TeamTrait, TimeTrait{
private static final Array<SolidTrait> entities = new Array<>();
private static final Rectangle rect = new Rectangle();
private static final Rectangle hitrect = new Rectangle();
private static final float wetDamageMultiplier = 2;
private static final float step = 4f, range = 6f, attractRange = 20f;
private static int lastSeed = 0;
private static float angle;
private static float wetDamageMultiplier = 2;
private Array<Vector2> lines = new Array<>();
private Color color = Palette.lancerLaser;
private Lightning parent;
private SeedRandom random = new SeedRandom();
private float damage, time;
private int activeFrame;
private Effect effect;
private Team team;
/**For pooling use only. Do not call directly!*/
public Lightning(){
@@ -57,18 +67,17 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncT
/**Do not invoke!*/
@Remote(called = Loc.server)
public static void createLighting(int seed, Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
public static Lightning createLighting(int seed, Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
Lightning l = Pooling.obtain(Lightning.class, Lightning::new);
l.x = x;
l.y = y;
l.damage = damage;
l.effect = effect;
l.team = team;
l.random.setSeed(seed);
l.color = color;
float step = 4f;
float range = 6f;
float attractRange = 20f;
angle = targetAngle;
entities.clear();
@@ -77,10 +86,8 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncT
for(int i = 0; i < length; i++){
l.lines.add(new Vector2(x, y));
float fx = x, fy = y;
float x2 = x + Angles.trnsx(angle, step);
float y2 = y + Angles.trnsy(angle, step);
float fangle = angle;
angle += Mathf.range(15f);
rect.setSize(attractRange).setCenter(x, y);
@@ -90,32 +97,11 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncT
if(dst < attractRange){
angle = Mathf.slerp(angle, Angles.angle(x2, y2, entity.x, entity.y), (attractRange - dst) / attractRange / 4f);
}
entity.getHitbox(hitrect);
hitrect.x -= range / 2f;
hitrect.y -= range / 2f;
hitrect.width += range / 2f;
hitrect.height += range / 2f;
if(hitrect.contains(x2, y2) || hitrect.contains(fx, fy)){
float result = damage;
if(entity.hasEffect(StatusEffects.wet))
result = (result * wetDamageMultiplier);
entity.damage(result);
Effects.effect(effect, x2, y2, fangle);
}
});
if(l.random.chance(0.1f)){
createLighting(l.random.nextInt(), team, effect, color, damage, x2, y2, angle + l.random.range(30f), length / 3);
}
Tile tile = world.tileWorld(x, y);
if(tile != null && tile.entity != null && tile.getTeamID() != team.ordinal()){
Effects.effect(effect, x, y, fangle);
tile.entity.damage(damage/4f);
createLighting(l.random.nextInt(), team, effect, color, damage, x2, y2, angle + l.random.range(30f), length / 3)
.parent = l;
}
x = x2;
@@ -124,6 +110,41 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncT
l.lines.add(new Vector2(x, y));
l.add();
return l;
}
@Override
public void absorb(){
activeFrame = 99;
if(parent != null){
parent.absorb();
}
}
@Override
public boolean collides(SolidTrait other){
return false;
}
@Override
public void time(float time){
this.time = time;
}
@Override
public boolean canBeAbsorbed(){
return activeFrame < 3;
}
@Override
public float time(){
return time;
}
@Override
public float fin(){
return time/lifetime();
}
@Override
@@ -146,11 +167,45 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncT
return 10;
}
@Override
public Team getTeam(){
return team;
}
@Override
public void update(){
updateTime();
if(activeFrame == 2){
for(Vector2 vec : lines){
rect.setSize(range).setCenter(x, y);
Units.getNearbyEnemies(team, rect, unit -> {
unit.getHitbox(hitrect);
if(rect.overlaps(hitrect)){
unit.damage(damage * (unit.hasEffect(StatusEffects.wet) ? 2f : 1f));
Effects.effect(effect, vec.x, vec.y, 0f);
}
});
Tile tile = world.tileWorld(vec.x, vec.y);
if(tile != null && tile.entity != null && tile.getTeamID() != team.ordinal()){
Effects.effect(effect, vec.x, vec.y, 0f);
tile.entity.damage(damage/4f);
}
}
}
activeFrame ++;
}
@Override
public void reset(){
super.reset();
time = 0f;
color = Palette.lancerLaser;
lines.clear();
parent = null;
activeFrame = 0;
}
@Override
@@ -159,6 +214,11 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncT
Pooling.free(this);
}
@Override
public float getDamage(){
return damage/10f;
}
@Override
public void draw(){
float lx = x, ly = y;

View File

@@ -0,0 +1,12 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.ucore.entities.trait.DamageTrait;
import io.anuke.ucore.entities.trait.Entity;
public interface AbsorbTrait extends Entity, TeamTrait, DamageTrait{
void absorb();
default boolean canBeAbsorbed(){
return true;
}
}