Fixed interpolation, made death and damage serverside

This commit is contained in:
Anuken 2018-06-09 11:58:15 -04:00
parent bc7b584001
commit be2fa1dfad
6 changed files with 45 additions and 32 deletions

View File

@ -15,13 +15,13 @@ public class Annotations {
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface Remote {
/**Specifies the locations where this method can be invoked.*/
/**Specifies the locations from which this method can be invoked.*/
Loc targets() default Loc.server;
/**Specifies which methods are generated. Only affects client methods.*/
/**Specifies which methods are generated. Only affects server-to-client methods.*/
Variant variants() default Variant.all;
/**The local locations where this method is called.*/
Loc called() default Loc.none;
/**Whether to forward this packet to all other clients.*/
/**Whether to forward this packet to all other clients upon recieval. Server only.*/
boolean forward() default false;
/**Whether the packet for this method is sent with UDP instead of TCP.
* UDP is faster, but is prone to packet loss and duplication.*/

View File

@ -118,7 +118,6 @@ public class NetServer extends Module{
player.mech = packet.mobile ? Mechs.standardShip : Mechs.standard;
player.dead = true;
player.setNet(player.x, player.y);
player.setNet(player.x, player.y);
player.color.set(packet.color);
connections.put(id, player);
@ -198,7 +197,7 @@ public class NetServer extends Module{
NetConnection connection = Net.getConnection(player.clientid);
if(connection == null){
Log.err("Player {0} failed to connect.", player.name);
//player disconnected
connections.remove(player.clientid);
player.remove();
return;

View File

@ -7,6 +7,8 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pools;
import com.badlogic.gdx.utils.Queue;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.Mechs;
import io.anuke.mindustry.content.Weapons;
@ -16,8 +18,10 @@ import io.anuke.mindustry.entities.traits.CarriableTrait;
import io.anuke.mindustry.entities.traits.CarryTrait;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.CallEntity;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Trail;
import io.anuke.mindustry.net.In;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
@ -152,13 +156,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
@Override
public void damage(float amount){
hitTime = hitDuration;
if(!debug) {
health -= amount;
if(health <= 0 && !dead && isLocal){ //remote players don't die normally
onDeath();
dead = true;
}
CallEntity.onPlayerDamage(this, amount);
if(health <= 0 && !dead && isLocal){
CallEntity.onPlayerDeath(this);
}
}
@ -167,19 +168,25 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
return super.collides(other) || other instanceof ItemDrop;
}
@Override
public void onDeath(){
dead = true;
respawning = false;
placeQueue.clear();
@Remote(in = In.entities, targets = Loc.server, called = Loc.server)
public static void onPlayerDamage(Player player, float amount){
player.hitTime = hitDuration;
player.health -= amount;
}
dropCarry();
@Remote(in = In.entities, targets = Loc.server, called = Loc.server)
public static void onPlayerDeath(Player player){
player.dead = true;
player.respawning = false;
player.placeQueue.clear();
float explosiveness = 2f + (inventory.hasItem() ? inventory.getItem().item.explosiveness * inventory.getItem().amount : 0f);
float flammability = (inventory.hasItem() ? inventory.getItem().item.flammability * inventory.getItem().amount : 0f);
Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, getSize()/2f, Palette.darkFlame);
Effects.sound("die", this);
super.onDeath();
player.dropCarry();
float explosiveness = 2f + (player.inventory.hasItem() ? player.inventory.getItem().item.explosiveness * player.inventory.getItem().amount : 0f);
float flammability = (player.inventory.hasItem() ? player.inventory.getItem().item.flammability * player.inventory.getItem().amount : 0f);
Damage.dynamicExplosion(player.x, player.y, flammability, explosiveness, 0f, player.getSize()/2f, Palette.darkFlame);
Effects.sound("die", player);
player.onDeath();
}
@Override
@ -194,7 +201,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
@Override
public void removed() {
Log.info("\n\nPLAYER REMOVED\n\n");
dropCarry();
}
@ -218,8 +224,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
boolean snap = snapCamera && isLocal;
String mname = mech.name;
float px = x, py =y;
if(snap){
@ -370,11 +374,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
public void update(){
hitTime = Math.max(0f, hitTime - Timers.delta());
if(!isLocal){
//interpolate();
return;
}
if(isDead()){
CoreEntity entity = (CoreEntity)getClosestCore();
@ -384,6 +383,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
return;
}
if(!isLocal){
interpolate();
return;
}
if(mech.flying){
updateFlying();
}else{
@ -624,12 +628,15 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
@Override
public void read(DataInput buffer, long time) throws IOException {
float lastx = x, lasty = y, lastrot = rotation;
super.readSave(buffer);
name = buffer.readUTF();
color.set(buffer.readInt());
dead = buffer.readBoolean();
weapon = Upgrade.getByID(buffer.readByte());
mech = Upgrade.getByID(buffer.readByte());
interpolator.read(lastx, lasty, x, y, time, rotation);
rotation = lastrot;
}
//endregion

View File

@ -63,6 +63,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
x = interpolator.pos.x;
y = interpolator.pos.y;
if(interpolator.values.length > 0){
rotation = interpolator.values[0];
}

View File

@ -119,6 +119,6 @@ public class Weapon extends Upgrade {
Effects.effect(type.smokeEffect, x + weapon.tr.x, y + weapon.tr.y, rotation, player);
//reset timer for remote players
player.timer.getTime(left ? Player.timerShootLeft : Player.timerShootRight);
player.timer.reset(left ? Player.timerShootLeft : Player.timerShootRight, weapon.reload);
}
}

View File

@ -8,6 +8,7 @@ import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.net.In;
import io.anuke.mindustry.net.Net;
@ -73,6 +74,11 @@ public class Build {
//just in case
if(tile == null) return;
//remote players only (?)
if(player.getPlaceQueue().size == 0){
player.getPlaceQueue().addFirst(new BuildRequest(x, y, rotation, recipe));
}
Block sub = Block.getByName("build" + result.size);
tile.setBlock(sub, rotation);