Massive amount of bug/crash fixes, wave saving
This commit is contained in:
@@ -705,6 +705,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
buffer.writeBoolean(dead);
|
||||
buffer.writeByte(mech.id);
|
||||
buffer.writeBoolean(isBoosting);
|
||||
buffer.writeInt(mining == null ? -1 : mining.packedPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -717,6 +718,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
dead = buffer.readBoolean();
|
||||
mech = Upgrade.getByID(buffer.readByte());
|
||||
boolean dashing = buffer.readBoolean();
|
||||
int mine = buffer.readInt();
|
||||
interpolator.read(lastx, lasty, x, y, time, rotation);
|
||||
rotation = lastrot;
|
||||
|
||||
@@ -724,6 +726,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
x = lastx;
|
||||
y = lasty;
|
||||
}else{
|
||||
mining = world.tile(mine);
|
||||
isBoosting = dashing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
|
||||
create(item, x, y, to, () -> {});
|
||||
}
|
||||
|
||||
@Remote(in = In.entities, called = Loc.server, unreliable = true)
|
||||
public static void transferItemToUnit(Item item, float x, float y, Unit to){
|
||||
create(item, x, y, to, () -> to.inventory.addItem(item, 1));
|
||||
}
|
||||
|
||||
@Remote(in = In.entities, called = Loc.server)
|
||||
public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){
|
||||
for (int i = 0; i < Mathf.clamp(amount/3, 1, 8); i++) {
|
||||
|
||||
@@ -8,9 +8,9 @@ import io.anuke.mindustry.content.fx.BlockFx;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.effect.ItemTransfer;
|
||||
import io.anuke.mindustry.game.EventType.BlockBuildEvent;
|
||||
import io.anuke.mindustry.gen.CallBlocks;
|
||||
import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
@@ -27,10 +27,7 @@ import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.graphics.Shapes;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
import io.anuke.ucore.util.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -189,10 +186,10 @@ public interface BuilderTrait {
|
||||
|
||||
if(unit.inventory.canAcceptItem(item) &&
|
||||
Mathf.chance(Timers.delta() * (0.06 - item.hardness * 0.01) * getMinePower())){
|
||||
ItemTransfer.create(item,
|
||||
CallEntity.transferItemToUnit(item,
|
||||
tile.worldx() + Mathf.range(tilesize/2f),
|
||||
tile.worldy() + Mathf.range(tilesize/2f),
|
||||
unit, () -> unit.inventory.addItem(item, 1));
|
||||
unit);
|
||||
}
|
||||
|
||||
if(Mathf.chance(0.06 * Timers.delta())){
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class BaseUnit extends Unit{
|
||||
|
||||
protected boolean isWave;
|
||||
protected Squad squad;
|
||||
protected UnitFactoryEntity spawner;
|
||||
protected int spawner = -1;
|
||||
|
||||
public BaseUnit(UnitType type, Team team){
|
||||
this.type = type;
|
||||
@@ -61,7 +61,7 @@ public abstract class BaseUnit extends Unit{
|
||||
}
|
||||
|
||||
public void setSpawner(UnitFactoryEntity spawner) {
|
||||
this.spawner = spawner;
|
||||
this.spawner = spawner.tile.packedPosition();
|
||||
}
|
||||
|
||||
public UnitType getType() {
|
||||
@@ -267,10 +267,14 @@ public abstract class BaseUnit extends Unit{
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
if(spawner != null){
|
||||
spawner.hasSpawned = false;
|
||||
spawner = null;
|
||||
Tile tile = world.tile(spawner);
|
||||
|
||||
if(tile != null && tile.entity instanceof UnitFactoryEntity){
|
||||
UnitFactoryEntity factory = (UnitFactoryEntity)tile.entity;
|
||||
factory.hasSpawned = false;
|
||||
}
|
||||
|
||||
spawner = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -302,6 +306,7 @@ public abstract class BaseUnit extends Unit{
|
||||
super.writeSave(stream);
|
||||
stream.writeByte(type.id);
|
||||
stream.writeBoolean(isWave);
|
||||
stream.writeInt(spawner);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,6 +314,7 @@ public abstract class BaseUnit extends Unit{
|
||||
super.readSave(stream);
|
||||
byte type = stream.readByte();
|
||||
this.isWave = stream.readBoolean();
|
||||
this.spawner = stream.readInt();
|
||||
|
||||
this.type = UnitType.getByID(type);
|
||||
add();
|
||||
|
||||
@@ -34,6 +34,10 @@ import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.ThreadQueue;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
@@ -117,7 +121,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
|
||||
@Override
|
||||
public void setMineTile(Tile tile) {
|
||||
this.mineTile = tile;
|
||||
mineTile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,6 +212,21 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput data) throws IOException {
|
||||
super.write(data);
|
||||
data.writeInt(mineTile == null ? -1 : mineTile.packedPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput data, long time) throws IOException {
|
||||
super.read(data, time);
|
||||
int mined = data.readInt();
|
||||
if(mined != -1){
|
||||
mineTile = world.tile(mined);
|
||||
}
|
||||
}
|
||||
|
||||
public final UnitState
|
||||
|
||||
build = new UnitState(){
|
||||
@@ -317,7 +336,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
if(target instanceof Tile) {
|
||||
moveTo(type.range/1.5f);
|
||||
|
||||
if (distanceTo(target) < type.range) {
|
||||
if (distanceTo(target) < type.range && mineTile != target) {
|
||||
setMineTile((Tile)target);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user