Loads of bugfixes, gameplay tweaks

This commit is contained in:
Anuken
2018-06-22 19:14:50 -04:00
parent 57d5628750
commit 74878b5cb1
38 changed files with 748 additions and 568 deletions
@@ -6,7 +6,9 @@ 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.fx.UnitFx;
import io.anuke.mindustry.entities.Player;
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;
@@ -31,7 +33,7 @@ import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, VelocityTrait, TimeTrait, Poolable {
public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawTrait, VelocityTrait, TimeTrait, Poolable {
public static int typeID = -1;
private static final float sinkLifetime = 80f;
@@ -62,6 +64,10 @@ public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, Veloc
@Remote(called = Loc.server, in = In.entities)
public static void onPickup(int itemid){
ItemDrop drop = itemGroup.getByID(itemid);
if(drop != null){
Effects.effect(UnitFx.pickup, drop);
}
itemGroup.removeByID(itemid);
}
@@ -104,9 +110,14 @@ public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, Veloc
@Override
public void collision(SolidTrait other, float x, float y) {
Player player = (Player)other;
if(player.inventory.canAcceptItem(item, amount)){
player.inventory.addItem(item, amount);
CallEntity.onPickup(getID());
if(player.inventory.canAcceptItem(item, 1)){
int used = Math.min(amount, player.inventory.capacity() - player.inventory.getItem().amount);
player.inventory.addItem(item, used);
amount -= used;
if(amount <= 0) {
CallEntity.onPickup(getID());
}
}
}
@@ -182,6 +193,22 @@ public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, Veloc
return itemGroup;
}
@Override
public void writeSave(DataOutput data) throws IOException {
data.writeFloat(x);
data.writeFloat(y);
data.writeByte(item.id);
data.writeShort(amount);
}
@Override
public void readSave(DataInput data) throws IOException {
x = data.readFloat();
y = data.readFloat();
item = Item.getByID(data.readByte());
amount = data.readShort();
}
@Override
public void write(DataOutput data) throws IOException{
data.writeFloat(x);
@@ -13,11 +13,13 @@ public class UnitDrops {
dropTable = new Item[]{Items.tungsten, Items.lead, Items.carbide};
}
for(Item item : dropTable){
if(Mathf.chance(0.2)){
int amount = Mathf.random(1, 30);
CallEntity.createItemDrop(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f),
unit.getVelocity().x + Mathf.range(0.5f), unit.getVelocity().y + Mathf.range(0.5f));
for (int i = 0; i < 3; i++) {
for(Item item : dropTable){
if(Mathf.chance(0.2)){
int amount = Mathf.random(1, 5);
CallEntity.createItemDrop(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f),
unit.getVelocity().x + Mathf.range(3f), unit.getVelocity().y + Mathf.range(3f));
}
}
}
}
@@ -184,11 +184,19 @@ public class Drone extends FlyingUnit implements BuilderTrait {
public final UnitState
build = new UnitState(){
public void entered() {
target = null;
}
public void update() {
BuildEntity entity = (BuildEntity)target;
TileEntity core = getClosestCore();
if(entity == null){
setState(repair);
return;
}
if(core == null) return;
if(entity.progress() < 1f && entity.tile.block() instanceof BuildBlock){ //building is valid
@@ -243,6 +251,9 @@ public class Drone extends FlyingUnit implements BuilderTrait {
}
},
mine = new UnitState() {
public void entered() {
target = null;
}
public void update() {
if(targetItem == null) {
@@ -253,7 +264,11 @@ public class Drone extends FlyingUnit implements BuilderTrait {
if(inventory.isFull()){
setState(drop);
}else{
//only mines tungsten for now
if(targetItem != null && !inventory.canAcceptItem(targetItem)){
setState(drop);
return;
}
retarget(() -> {
if(getMineTile() == null){
findItem();
@@ -279,6 +294,9 @@ public class Drone extends FlyingUnit implements BuilderTrait {
}
},
drop = new UnitState() {
public void entered() {
target = null;
}
public void update() {
if(inventory.isEmpty()){