it begins
This commit is contained in:
@@ -1,32 +1,22 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
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;
|
||||
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.SolidEntity;
|
||||
import io.anuke.ucore.entities.impl.TimedEntity;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.entities.trait.PosTrait;
|
||||
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;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Pooling;
|
||||
import io.anuke.ucore.util.SeedRandom;
|
||||
|
||||
@@ -34,26 +24,13 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
|
||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
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;
|
||||
|
||||
public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, TimeTrait{
|
||||
private static int lastSeed = 0;
|
||||
private static float angle;
|
||||
private static SeedRandom random = new SeedRandom();
|
||||
|
||||
private Array<Vector2> lines = new Array<>();
|
||||
private Array<PosTrait> 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(){
|
||||
@@ -66,92 +43,19 @@ public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncT
|
||||
|
||||
/**Do not invoke!*/
|
||||
@Remote(called = Loc.server)
|
||||
public static Lightning createLighting(int seed, Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
public static void createLighting(int seed, Team team, Color color, float damage, float x, float y, 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;
|
||||
|
||||
angle = targetAngle;
|
||||
entities.clear();
|
||||
|
||||
Units.getNearbyEnemies(team, rect, entities::add);
|
||||
|
||||
for(int i = 0; i < length; i++){
|
||||
l.lines.add(new Vector2(x, y));
|
||||
|
||||
float x2 = x + Angles.trnsx(angle, step);
|
||||
float y2 = y + Angles.trnsy(angle, step);
|
||||
|
||||
angle += Mathf.range(15f);
|
||||
rect.setSize(attractRange).setCenter(x, y);
|
||||
|
||||
Units.getNearbyEnemies(team, rect, entity -> {
|
||||
float dst = entity.distanceTo(x2, y2);
|
||||
if(dst < attractRange){
|
||||
angle = Mathf.slerp(angle, Angles.angle(x2, y2, entity.x, entity.y), (attractRange - dst) / attractRange / 4f);
|
||||
}
|
||||
});
|
||||
|
||||
if(l.random.chance(0.1f)){
|
||||
createLighting(l.random.nextInt(), team, effect, color, damage, x2, y2, angle + l.random.range(30f), length / 3)
|
||||
.parent = l;
|
||||
}
|
||||
|
||||
x = x2;
|
||||
y = y2;
|
||||
}
|
||||
|
||||
l.lines.add(new Vector2(x, y));
|
||||
l.add();
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void getHitbox(Rectangle rectangle){}
|
||||
|
||||
@Override
|
||||
public void getHitboxTile(Rectangle rectangle){}
|
||||
|
||||
@Override
|
||||
public void absorb(){
|
||||
activeFrame = 99;
|
||||
if(parent != null){
|
||||
parent.absorb();
|
||||
for (int i = 0; i < length; i++) {
|
||||
Effect
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
random.setSeed(seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,45 +74,10 @@ public class Lightning extends SolidEntity 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) ? wetDamageMultiplier : 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(){
|
||||
time = 0f;
|
||||
color = Palette.lancerLaser;
|
||||
lines.clear();
|
||||
parent = null;
|
||||
activeFrame = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,11 +86,6 @@ public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncT
|
||||
Pooling.free(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage(){
|
||||
return damage/10f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
float lx = x, ly = y;
|
||||
|
||||
Reference in New Issue
Block a user