Implemented authoritative movement/shooting, fixed netbugs

This commit is contained in:
Anuken
2018-06-13 17:06:46 -04:00
parent 4ca9a26bdd
commit c077f6e1e8
17 changed files with 268 additions and 87 deletions

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.gen.CallEntity;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
@@ -130,6 +131,10 @@ public class DesktopInput extends InputHandler{
mode = none;
}
if(player.isShooting && !canShoot()){
CallEntity.setShooting(false);
}
if(isPlacing()){
cursorType = hand;
selectScale = Mathf.lerpDelta(selectScale, 1f, 0.2f);
@@ -188,7 +193,7 @@ public class DesktopInput extends InputHandler{
//only begin shooting if there's no cursor event
if(!tileTapped(cursor) && player.getPlaceQueue().size == 0 && !tryTapPlayer(worldx, worldy) && !droppingItem &&
!tryBeginMine(cursor) && player.getMineTile() == null){
shooting = true;
CallEntity.setShooting(true);
}
}
}else if(button == Buttons.RIGHT){ //right = begin breaking
@@ -206,7 +211,7 @@ public class DesktopInput extends InputHandler{
@Override
public boolean touchUp (int screenX, int screenY, int pointer, int button) {
if(button == Buttons.LEFT){
shooting = false;
CallEntity.setShooting(false);
}
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false;

View File

@@ -46,7 +46,6 @@ public abstract class InputHandler extends InputAdapter{
public Recipe recipe;
public int rotation;
public boolean droppingItem;
public boolean shooting;
public InputHandler(Player player){
this.player = player;
@@ -189,10 +188,6 @@ public abstract class InputHandler extends InputAdapter{
public boolean canShoot(){
return recipe == null && !ui.hasMouse() && !onConfigurable() && !isDroppingItem();
}
public boolean isShooting(){
return shooting;
}
public boolean onConfigurable(){
return false;
@@ -262,6 +257,11 @@ public abstract class InputHandler extends InputAdapter{
player.addBuildRequest(new BuildRequest(tile.x, tile.y));
}
@Remote(targets = Loc.client, called = Loc.both, in = In.entities)
public static void setShooting(Player player, boolean on){
player.isShooting = on;
}
@Remote(targets = Loc.both, called = Loc.server, in = In.entities)
public static void dropItem(Player player, float angle){
if(Net.server() && !player.inventory.hasItem()){