Massive amount of fixes and changes with multiplayer/annotations

This commit is contained in:
Anuken
2018-06-08 22:43:23 -04:00
parent 0620c635e5
commit 690571eec0
34 changed files with 557 additions and 290 deletions
@@ -30,7 +30,9 @@ import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.*;
import java.io.*;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
@@ -192,6 +194,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
@Override
public void removed() {
Log.info("\n\nPLAYER REMOVED\n\n");
dropCarry();
}
@@ -368,7 +371,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
hitTime = Math.max(0f, hitTime - Timers.delta());
if(!isLocal){
interpolate();
//interpolate();
return;
}
@@ -552,9 +555,9 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
dead = true;
respawning = false;
trail.clear();
health = maxHealth();
add();
heal();
}
public boolean isShooting(){
@@ -601,7 +604,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
private void readSaveSuper(DataInput stream) throws IOException {
super.readSave(stream);
byte uamount = stream.readByte();
for (int i = 0; i < uamount; i++) {
upgrades.add(Upgrade.getByID(stream.readByte()));
@@ -611,13 +613,23 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
}
@Override
public void write(DataOutput buffer) {
//todo
public void write(DataOutput buffer) throws IOException {
super.writeSave(buffer);
buffer.writeUTF(name);
buffer.writeInt(Color.rgba8888(color));
buffer.writeBoolean(dead);
buffer.writeByte(weapon.id);
buffer.writeByte(mech.id);
}
@Override
public void read(DataInput buffer, long time) {
//todo
public void read(DataInput buffer, long time) throws IOException {
super.readSave(buffer);
name = buffer.readUTF();
color.set(buffer.readInt());
dead = buffer.readBoolean();
weapon = Upgrade.getByID(buffer.readByte());
mech = Upgrade.getByID(buffer.readByte());
}
//endregion
@@ -63,7 +63,9 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
x = interpolator.pos.x;
y = interpolator.pos.y;
rotation = interpolator.values[0];
if(interpolator.values.length > 0){
rotation = interpolator.values[0];
}
}
@Override
@@ -100,6 +102,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
stream.writeByte(team.ordinal());
stream.writeFloat(x);
stream.writeFloat(y);
stream.writeFloat(rotation);
stream.writeShort((short)health);
stream.writeByte(status.current().id);
stream.writeFloat(status.getTime());
@@ -111,6 +114,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
byte team = stream.readByte();
float x = stream.readFloat();
float y = stream.readFloat();
float rotation = stream.readFloat();
int health = stream.readShort();
byte effect = stream.readByte();
float etime = stream.readFloat();
@@ -120,6 +124,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
this.health = health;
this.x = x;
this.y = y;
this.rotation = rotation;
this.status.set(StatusEffect.getByID(effect), etime);
}
@@ -51,9 +51,7 @@ public class BasicBulletType extends BulletType {
for (int i = 0; i < fragBullets; i++) {
float len = Mathf.random(1f, 7f);
float a = Mathf.random(360f);
Bullet bullet = Bullet.create(fragBullet, b,
x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a);
bullet.getVelocity().scl(Mathf.random(fragVelocityMin, fragVelocityMax));
Bullet.create(fragBullet, b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax));
}
}
}
@@ -3,10 +3,8 @@ package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Pools;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TeamTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.net.Interpolator;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.BulletEntity;
@@ -15,31 +13,31 @@ import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.entities.trait.VelocityTrait;
import io.anuke.ucore.util.Timer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.bulletGroup;
import static io.anuke.mindustry.Vars.world;
public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncTrait{
public class Bullet extends BulletEntity<BulletType> implements TeamTrait{
private static Vector2 vector = new Vector2();
private Interpolator interpolator = new Interpolator();
//private Interpolator interpolator = new Interpolator();
private Team team;
public Timer timer = new Timer(3);
public static Bullet create(BulletType type, TeamTrait owner, float x, float y, float angle){
return create(type, owner, owner.getTeam(), x, y, angle);
public static void create (BulletType type, TeamTrait owner, float x, float y, float angle){
create(type, owner, owner.getTeam(), x, y, angle);
}
public static Bullet create (BulletType type, Entity owner, Team team, float x, float y, float angle){
public static void create (BulletType type, Entity owner, Team team, float x, float y, float angle){
create(type, owner, team, x, y, angle, 1f);
}
public static void create (BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl){
Bullet bullet = Pools.obtain(Bullet.class);
bullet.type = type;
bullet.owner = owner;
bullet.velocity.set(0, type.speed).setAngle(angle);
bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl);
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).getVelocity() : Vector2.Zero);
bullet.hitbox.setSize(type.hitsize);
@@ -47,11 +45,14 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
bullet.type = type;
bullet.set(x, y);
bullet.add();
return bullet;
}
public static Bullet create(BulletType type, Bullet parent, float x, float y, float angle){
return create(type, parent.owner, parent.team, x, y, angle);
public static void create(BulletType type, Bullet parent, float x, float y, float angle){
create(type, parent.owner, parent.team, x, y, angle);
}
public static void create(BulletType type, Bullet parent, float x, float y, float angle, float velocityScl){
create(type, parent.owner, parent.team, x, y, angle, velocityScl);
}
/**Internal use only!*/
@@ -60,7 +61,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
public boolean collidesTiles(){
return true; //TODO make artillery and such not do this
}
/*
@Override
public boolean doSync(){
return type.syncable;
@@ -85,7 +86,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
y = data.readFloat();
team = Team.values()[data.readByte()];
type = BulletType.getByID(data.readByte());
}
}*/
@Override
public Team getTeam() {
@@ -1,19 +1,18 @@
package io.anuke.mindustry.entities.units;
import io.anuke.mindustry.content.fx.ExplosionFx;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.util.Angles;
@@ -21,7 +20,9 @@ import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timer;
import java.io.*;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
@@ -55,12 +56,6 @@ public abstract class BaseUnit extends Unit{
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
}
public void effectAt(Effect effect, float rotation, float dx, float dy){
Effects.effect(effect,
x + Angles.trnsx(rotation, dx, dy),
y + Angles.trnsy(rotation, dx, dy), Mathf.atan2(dx, dy) + rotation);
}
public boolean targetHasFlag(BlockFlag flag){
return target instanceof TileEntity &&
((TileEntity)target).tile.block().flags.contains(flag);
@@ -248,12 +243,13 @@ public abstract class BaseUnit extends Unit{
}
@Override
public void write(DataOutput data) {
//todo
public void write(DataOutput data) throws IOException{
writeSave(data);
}
@Override
public void read(DataInput data, long time) {
//todo
public void read(DataInput data, long time) throws IOException{
super.readSave(data);
this.type = UnitType.getByID(data.readByte());
}
}