Synced fireballs and fire
This commit is contained in:
@@ -9,6 +9,7 @@ import io.anuke.mindustry.content.bullets.*;
|
||||
import io.anuke.mindustry.content.fx.*;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.entities.effect.Fire;
|
||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.entities.units.UnitType;
|
||||
@@ -133,5 +134,6 @@ public class ContentLoader {
|
||||
Vtol.typeID = SyncTrait.registerType(Vtol::new);
|
||||
Scout.typeID = SyncTrait.registerType(Scout::new);
|
||||
ItemDrop.typeID = SyncTrait.registerType(ItemDrop::new);
|
||||
Fire.typeID = SyncTrait.registerType(Fire::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.content.bullets.TurretBullets;
|
||||
import io.anuke.mindustry.content.fx.ExplosionFx;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.effect.Lightning;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -37,7 +37,7 @@ public class Damage {
|
||||
}
|
||||
|
||||
for(int i = 0; i < Mathf.clamp(flammability / 4, 0, 30); i ++){
|
||||
Timers.run(i/2, () -> Bullet.create(TurretBullets.fireball, null, Team.none, x, y, Mathf.random(360f)));
|
||||
Timers.run(i/2, () -> CallEntity.createBullet(TurretBullets.fireball, x, y, Mathf.random(360f)));
|
||||
}
|
||||
|
||||
int waves = Mathf.clamp((int)(explosiveness / 4), 0, 30);
|
||||
|
||||
@@ -2,9 +2,12 @@ package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.traits.TeamTrait;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.net.In;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.impl.BulletEntity;
|
||||
@@ -55,6 +58,11 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait{
|
||||
create(type, parent.owner, parent.team, x, y, angle, velocityScl);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, in = In.entities)
|
||||
public static void createBullet(BulletType type, float x, float y, float angle){
|
||||
create(type, null, Team.none, x, y, angle);
|
||||
}
|
||||
|
||||
/**Internal use only!*/
|
||||
public Bullet(){}
|
||||
|
||||
|
||||
@@ -4,11 +4,17 @@ import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.net.In;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -24,10 +30,12 @@ import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable {
|
||||
private static final IntMap<Fire> map = new IntMap<>();
|
||||
private static final float baseLifetime = 1000f;
|
||||
|
||||
public static int typeID = -1;
|
||||
|
||||
private int loadedPosition = -1;
|
||||
private Tile tile;
|
||||
private Block block;
|
||||
@@ -60,6 +68,11 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
/**Deserialization use only!*/
|
||||
public Fire(){}
|
||||
|
||||
@Override
|
||||
public int getTypeID() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float lifetime() {
|
||||
return lifetime;
|
||||
@@ -67,9 +80,22 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if(Mathf.chance(0.1 * Timers.delta())) {
|
||||
Effects.effect(EnvironmentFx.fire, tile.worldx() + Mathf.range(4f), tile.worldy() + Mathf.range(4f));
|
||||
}
|
||||
|
||||
if(Mathf.chance(0.05 * Timers.delta())){
|
||||
Effects.effect(EnvironmentFx.smoke, tile.worldx() + Mathf.range(4f), tile.worldy() + Mathf.range(4f));
|
||||
}
|
||||
|
||||
if(Net.client()){
|
||||
return;
|
||||
}
|
||||
|
||||
time = Mathf.clamp(time + Timers.delta(), 0, lifetime());
|
||||
|
||||
if(time >= lifetime()){
|
||||
CallEntity.onFireRemoved(getID());
|
||||
remove();
|
||||
}
|
||||
|
||||
@@ -98,8 +124,6 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
}
|
||||
|
||||
if(Mathf.chance(0.1 * Timers.delta())){
|
||||
Effects.effect(EnvironmentFx.fire, tile.worldx() + Mathf.range(4f), tile.worldy() + Mathf.range(4f));
|
||||
|
||||
Puddle p = Puddle.getPuddle(tile);
|
||||
if(p != null){
|
||||
puddleFlammability = p.getFlammability()/3f;
|
||||
@@ -112,10 +136,6 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
}
|
||||
Damage.damageUnits(null, tile.worldx(), tile.worldy(), tilesize, 3f, unit -> unit.applyEffect(StatusEffects.burning, 0.8f));
|
||||
}
|
||||
|
||||
if(Mathf.chance(0.05 * Timers.delta())){
|
||||
Effects.effect(EnvironmentFx.smoke, tile.worldx() + Mathf.range(4f), tile.worldy() + Mathf.range(4f));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,6 +153,18 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
add();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput data) throws IOException {
|
||||
data.writeFloat(x);
|
||||
data.writeFloat(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput data, long time) throws IOException {
|
||||
x = data.readFloat();
|
||||
y = data.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
loadedPosition = -1;
|
||||
@@ -160,4 +192,9 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
public EntityGroup targetGroup() {
|
||||
return fireGroup;
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, in = In.entities)
|
||||
public static void onFireRemoved(int fireid){
|
||||
fireGroup.removeByID(fireid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,20 +6,25 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
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.game.Team;
|
||||
import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.net.In;
|
||||
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.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.entities.impl.TimedEntity;
|
||||
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.SeedRandom;
|
||||
|
||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||
|
||||
@@ -27,19 +32,26 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait{
|
||||
private static Array<SolidTrait> entities = new Array<>();
|
||||
private static Rectangle rect = new Rectangle();
|
||||
private static Rectangle hitrect = new Rectangle();
|
||||
private static int lastSeed = 0;
|
||||
private static float angle;
|
||||
private static float wetDamageMultiplier = 2;
|
||||
|
||||
private Array<Vector2> lines = new Array<>();
|
||||
|
||||
public Color color = Palette.lancerLaser;
|
||||
private Color color = Palette.lancerLaser;
|
||||
private SeedRandom random = new SeedRandom();
|
||||
|
||||
/**Create a lighting branch at a location. Use Team.none to damage everyone.*/
|
||||
public static void create(Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
CallEntity.createLighting(lastSeed++, team, effect, color, damage, x, y, targetAngle, length);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, in = In.entities)
|
||||
public static void createLighting(int seed, Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
Lightning l = Pools.obtain(Lightning.class);
|
||||
|
||||
l.x = x;
|
||||
l.y = y;
|
||||
l.random.setSeed(seed);
|
||||
l.color = color;
|
||||
|
||||
float step = 3f;
|
||||
@@ -85,8 +97,8 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait{
|
||||
}
|
||||
});
|
||||
|
||||
if(Mathf.chance(0.1)){
|
||||
Lightning.create(team, effect, color, damage, x2, y2, angle + Mathf.range(100f), length/3);
|
||||
if(l.random.chance(0.1f)){
|
||||
createLighting(l.random.nextInt(), team, effect, color, damage, x2, y2, angle + l.random.range(100f), length/3);
|
||||
}
|
||||
|
||||
x = x2;
|
||||
@@ -111,6 +123,11 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait{
|
||||
lines.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
Pools.free(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
float lx = x, ly = y;
|
||||
|
||||
@@ -11,17 +11,16 @@ import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.content.bullets.TurretBullets;
|
||||
import io.anuke.mindustry.content.fx.BlockFx;
|
||||
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.impl.BaseEntity;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
@@ -112,7 +111,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
(liquid.flammability > 0.3f && dest.temperature > 0.7f)){ //flammable liquid + hot liquid
|
||||
Fire.create(tile);
|
||||
if(Mathf.chance(0.006 * amount)){
|
||||
Bullet.create(TurretBullets.fireball, tile.entity, Team.none, x, y, Mathf.random(360f));
|
||||
CallEntity.createBullet(TurretBullets.fireball, x, y, Mathf.random(360f));
|
||||
}
|
||||
}else if(dest.temperature > 0.7f && liquid.temperature < 0.55f){ //cold liquid poured onto hot puddle
|
||||
if(Mathf.chance(0.5f * amount)){
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package io.anuke.mindustry.io;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.annotations.Annotations.ReadClass;
|
||||
import io.anuke.annotations.Annotations.WriteClass;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.net.Packets.KickReason;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -90,6 +94,26 @@ public class TypeIO {
|
||||
return Team.values()[buffer.get()];
|
||||
}
|
||||
|
||||
@WriteClass(Effect.class)
|
||||
public static void writeEffect(ByteBuffer buffer, Effect effect){
|
||||
buffer.putShort((short)effect.id);
|
||||
}
|
||||
|
||||
@ReadClass(Effect.class)
|
||||
public static Effect readEffect(ByteBuffer buffer){
|
||||
return Effects.getEffect(buffer.getShort());
|
||||
}
|
||||
|
||||
@WriteClass(Color.class)
|
||||
public static void writeColor(ByteBuffer buffer, Color color){
|
||||
buffer.putInt(Color.rgba8888(color));
|
||||
}
|
||||
|
||||
@ReadClass(Color.class)
|
||||
public static Color readColor(ByteBuffer buffer){
|
||||
return new Color(buffer.getInt());
|
||||
}
|
||||
|
||||
@WriteClass(Weapon.class)
|
||||
public static void writeWeapon(ByteBuffer buffer, Weapon weapon){
|
||||
buffer.put(weapon.id);
|
||||
@@ -110,6 +134,16 @@ public class TypeIO {
|
||||
return AmmoType.getByID(buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(BulletType.class)
|
||||
public static void writeBulletType(ByteBuffer buffer, BulletType type){
|
||||
buffer.put((byte)type.id);
|
||||
}
|
||||
|
||||
@ReadClass(BulletType.class)
|
||||
public static BulletType readBulletType(ByteBuffer buffer){
|
||||
return BulletType.getByID(buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(Item.class)
|
||||
public static void writeItem(ByteBuffer buffer, Item item){
|
||||
buffer.put((byte)item.id);
|
||||
|
||||
Reference in New Issue
Block a user