Fixed item drop duplicates, invincible players

This commit is contained in:
Anuken
2018-07-04 15:22:59 -04:00
parent 071d0fbbf7
commit cc92edfa58
8 changed files with 19 additions and 18 deletions

View File

@@ -12,8 +12,8 @@ import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.bullet.BulletType; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.bullet.LiquidBulletType; import io.anuke.mindustry.entities.bullet.LiquidBulletType;
import io.anuke.mindustry.entities.effect.Fire; import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.ItemDrop;
import io.anuke.mindustry.entities.effect.Lightning; import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.gen.CallEntity;
import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList; import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
@@ -258,7 +258,7 @@ public class TurretBullets extends BulletList implements ContentList {
if(amountDropped > 0){ if(amountDropped > 0){
float angle = b.angle() + Mathf.range(100f); float angle = b.angle() + Mathf.range(100f);
float vs = Mathf.random(0f, 4f); float vs = Mathf.random(0f, 4f);
CallEntity.createItemDrop(Item.getByID(i), amountDropped, b.x, b.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs)); ItemDrop.create(Item.getByID(i), amountDropped, b.x, b.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs));
} }
} }
} }

View File

@@ -353,7 +353,9 @@ public class NetClient extends Module {
if(entity == null){ if(entity == null){
entity = (SyncTrait) TypeTrait.getTypeByID(typeID).get(); //create entity from supplier entity = (SyncTrait) TypeTrait.getTypeByID(typeID).get(); //create entity from supplier
entity.resetID(id); entity.resetID(id);
add = true; if(!netClient.isEntityUsed(entity.getID())){
add = true;
}
} }
//read the entity //read the entity
@@ -364,7 +366,7 @@ public class NetClient extends Module {
throw new RuntimeException("Error reading entity of type '"+ group.getType() + "': Read length mismatch [write=" + readLength + ", read=" + (netClient.byteStream.position() - position - 1)+ "]"); throw new RuntimeException("Error reading entity of type '"+ group.getType() + "': Read length mismatch [write=" + readLength + ", read=" + (netClient.byteStream.position() - position - 1)+ "]");
} }
if(add && !netClient.isEntityUsed(entity.getID())){ if(add){
entity.add(); entity.add();
netClient.addRemovedEntity(entity.getID()); netClient.addRemovedEntity(entity.getID());
} }

View File

@@ -199,7 +199,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public void damage(float amount){ public void damage(float amount){
CallEntity.onPlayerDamage(this, calculateDamage(amount)); CallEntity.onPlayerDamage(this, calculateDamage(amount));
if(health <= 0 && !dead && isLocal){ if(health <= 0 && !dead){
CallEntity.onPlayerDeath(this); CallEntity.onPlayerDeath(this);
} }
} }

View File

@@ -57,8 +57,7 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
return drop; return drop;
} }
@Remote(called = Loc.server, in = In.entities) public static void create(Item item, int amount, float x, float y, float velocityX, float velocityY){
public static void createItemDrop(Item item, int amount, float x, float y, float velocityX, float velocityY){
create(item, amount, x, y, 0).getVelocity().set(velocityX, velocityY); create(item, amount, x, y, 0).getVelocity().set(velocityX, velocityY);
} }

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.entities.units;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.Items; import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.gen.CallEntity; import io.anuke.mindustry.entities.effect.ItemDrop;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
@@ -23,7 +23,7 @@ public class UnitDrops {
for(Item item : dropTable){ for(Item item : dropTable){
if(Mathf.chance(0.2)){ if(Mathf.chance(0.2)){
int amount = Mathf.random(1, 5); int amount = Mathf.random(1, 5);
CallEntity.createItemDrop(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f), ItemDrop.create(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f),
unit.getVelocity().x + Mathf.range(3f), unit.getVelocity().y + Mathf.range(3f)); unit.getVelocity().x + Mathf.range(3f), unit.getVelocity().y + Mathf.range(3f));
} }
} }

View File

@@ -220,7 +220,7 @@ public abstract class InputHandler extends InputAdapter{
if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.block().hasItems){ if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.block().hasItems){
CallBlocks.transferInventory(player, tile); CallBlocks.transferInventory(player, tile);
}else{ }else{
CallEntity.dropItem(player, player.angleTo(x, y)); CallEntity.dropItem(player.angleTo(x, y));
} }
} }
@@ -267,7 +267,7 @@ public abstract class InputHandler extends InputAdapter{
player.addBuildRequest(new BuildRequest(tile.x, tile.y)); player.addBuildRequest(new BuildRequest(tile.x, tile.y));
} }
@Remote(targets = Loc.both, called = Loc.server, in = In.entities) @Remote(targets = Loc.client, called = Loc.server, in = In.entities)
public static void dropItem(Player player, float angle){ public static void dropItem(Player player, float angle){
if(Net.server() && !player.inventory.hasItem()){ if(Net.server() && !player.inventory.hasItem()){
throw new ValidateException(player, "Player cannot drop an item."); throw new ValidateException(player, "Player cannot drop an item.");

View File

@@ -2,14 +2,14 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import io.anuke.mindustry.content.bullets.TurretBullets;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.effect.ItemDrop;
import io.anuke.mindustry.entities.units.BaseUnit; import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.entities.units.UnitType; import io.anuke.mindustry.entities.units.UnitType;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup; import io.anuke.ucore.entities.EntityGroup;
@@ -59,13 +59,13 @@ public class DebugFragment extends Fragment {
row(); row();
new button("noclip", "toggle", () -> noclip = !noclip); new button("noclip", "toggle", () -> noclip = !noclip);
row(); row();
new button("fire", () -> { new button("items", () -> {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
Bullet.create(TurretBullets.fireball, player, player.x, player.y, Mathf.random(360f)); ItemDrop.create(Item.all().random(), 5, player.x, player.y, Mathf.random(360f));
} }
}); });
row(); row();
new button("team", "toggle", () -> player.toggleTeam()); new button("team", "toggle", player::toggleTeam);
row(); row();
new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug); new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
row(); row();

View File

@@ -10,8 +10,8 @@ import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.effect.ItemDrop;
import io.anuke.mindustry.gen.CallBlocks; import io.anuke.mindustry.gen.CallBlocks;
import io.anuke.mindustry.gen.CallEntity;
import io.anuke.mindustry.graphics.Layer; import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.net.In; import io.anuke.mindustry.net.In;
@@ -241,7 +241,7 @@ public class MassDriver extends Block {
if(amountDropped > 0){ if(amountDropped > 0){
float angle = Mathf.range(180f); float angle = Mathf.range(180f);
float vs = Mathf.random(0f, 4f); float vs = Mathf.random(0f, 4f);
CallEntity.createItemDrop(Item.getByID(i), amountDropped, bullet.x, bullet.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs)); ItemDrop.create(Item.getByID(i), amountDropped, bullet.x, bullet.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs));
} }
} }