Fixed interpolation, made death and damage serverside
This commit is contained in:
@@ -15,13 +15,13 @@ public class Annotations {
|
|||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.CLASS)
|
@Retention(RetentionPolicy.CLASS)
|
||||||
public @interface Remote {
|
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;
|
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;
|
Variant variants() default Variant.all;
|
||||||
/**The local locations where this method is called.*/
|
/**The local locations where this method is called.*/
|
||||||
Loc called() default Loc.none;
|
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;
|
boolean forward() default false;
|
||||||
/**Whether the packet for this method is sent with UDP instead of TCP.
|
/**Whether the packet for this method is sent with UDP instead of TCP.
|
||||||
* UDP is faster, but is prone to packet loss and duplication.*/
|
* UDP is faster, but is prone to packet loss and duplication.*/
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ public class NetServer extends Module{
|
|||||||
player.mech = packet.mobile ? Mechs.standardShip : Mechs.standard;
|
player.mech = packet.mobile ? Mechs.standardShip : Mechs.standard;
|
||||||
player.dead = true;
|
player.dead = true;
|
||||||
player.setNet(player.x, player.y);
|
player.setNet(player.x, player.y);
|
||||||
player.setNet(player.x, player.y);
|
|
||||||
player.color.set(packet.color);
|
player.color.set(packet.color);
|
||||||
connections.put(id, player);
|
connections.put(id, player);
|
||||||
|
|
||||||
@@ -198,7 +197,7 @@ public class NetServer extends Module{
|
|||||||
NetConnection connection = Net.getConnection(player.clientid);
|
NetConnection connection = Net.getConnection(player.clientid);
|
||||||
|
|
||||||
if(connection == null){
|
if(connection == null){
|
||||||
Log.err("Player {0} failed to connect.", player.name);
|
//player disconnected
|
||||||
connections.remove(player.clientid);
|
connections.remove(player.clientid);
|
||||||
player.remove();
|
player.remove();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.Pools;
|
import com.badlogic.gdx.utils.Pools;
|
||||||
import com.badlogic.gdx.utils.Queue;
|
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.Vars;
|
||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
import io.anuke.mindustry.content.Weapons;
|
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.CarryTrait;
|
||||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
|
import io.anuke.mindustry.gen.CallEntity;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.mindustry.graphics.Trail;
|
import io.anuke.mindustry.graphics.Trail;
|
||||||
|
import io.anuke.mindustry.net.In;
|
||||||
import io.anuke.mindustry.type.*;
|
import io.anuke.mindustry.type.*;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.Floor;
|
import io.anuke.mindustry.world.blocks.Floor;
|
||||||
@@ -152,13 +156,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage(float amount){
|
public void damage(float amount){
|
||||||
hitTime = hitDuration;
|
CallEntity.onPlayerDamage(this, amount);
|
||||||
if(!debug) {
|
|
||||||
health -= amount;
|
if(health <= 0 && !dead && isLocal){
|
||||||
if(health <= 0 && !dead && isLocal){ //remote players don't die normally
|
CallEntity.onPlayerDeath(this);
|
||||||
onDeath();
|
|
||||||
dead = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,19 +168,25 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
return super.collides(other) || other instanceof ItemDrop;
|
return super.collides(other) || other instanceof ItemDrop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Remote(in = In.entities, targets = Loc.server, called = Loc.server)
|
||||||
public void onDeath(){
|
public static void onPlayerDamage(Player player, float amount){
|
||||||
dead = true;
|
player.hitTime = hitDuration;
|
||||||
respawning = false;
|
player.health -= amount;
|
||||||
placeQueue.clear();
|
}
|
||||||
|
|
||||||
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);
|
player.dropCarry();
|
||||||
float flammability = (inventory.hasItem() ? inventory.getItem().item.flammability * inventory.getItem().amount : 0f);
|
|
||||||
Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, getSize()/2f, Palette.darkFlame);
|
float explosiveness = 2f + (player.inventory.hasItem() ? player.inventory.getItem().item.explosiveness * player.inventory.getItem().amount : 0f);
|
||||||
Effects.sound("die", this);
|
float flammability = (player.inventory.hasItem() ? player.inventory.getItem().item.flammability * player.inventory.getItem().amount : 0f);
|
||||||
super.onDeath();
|
Damage.dynamicExplosion(player.x, player.y, flammability, explosiveness, 0f, player.getSize()/2f, Palette.darkFlame);
|
||||||
|
Effects.sound("die", player);
|
||||||
|
player.onDeath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -194,7 +201,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removed() {
|
public void removed() {
|
||||||
Log.info("\n\nPLAYER REMOVED\n\n");
|
|
||||||
dropCarry();
|
dropCarry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,8 +224,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
|
|
||||||
boolean snap = snapCamera && isLocal;
|
boolean snap = snapCamera && isLocal;
|
||||||
|
|
||||||
String mname = mech.name;
|
|
||||||
|
|
||||||
float px = x, py =y;
|
float px = x, py =y;
|
||||||
|
|
||||||
if(snap){
|
if(snap){
|
||||||
@@ -370,11 +374,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
public void update(){
|
public void update(){
|
||||||
hitTime = Math.max(0f, hitTime - Timers.delta());
|
hitTime = Math.max(0f, hitTime - Timers.delta());
|
||||||
|
|
||||||
if(!isLocal){
|
|
||||||
//interpolate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isDead()){
|
if(isDead()){
|
||||||
CoreEntity entity = (CoreEntity)getClosestCore();
|
CoreEntity entity = (CoreEntity)getClosestCore();
|
||||||
|
|
||||||
@@ -384,6 +383,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isLocal){
|
||||||
|
interpolate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(mech.flying){
|
if(mech.flying){
|
||||||
updateFlying();
|
updateFlying();
|
||||||
}else{
|
}else{
|
||||||
@@ -624,12 +628,15 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput buffer, long time) throws IOException {
|
public void read(DataInput buffer, long time) throws IOException {
|
||||||
|
float lastx = x, lasty = y, lastrot = rotation;
|
||||||
super.readSave(buffer);
|
super.readSave(buffer);
|
||||||
name = buffer.readUTF();
|
name = buffer.readUTF();
|
||||||
color.set(buffer.readInt());
|
color.set(buffer.readInt());
|
||||||
dead = buffer.readBoolean();
|
dead = buffer.readBoolean();
|
||||||
weapon = Upgrade.getByID(buffer.readByte());
|
weapon = Upgrade.getByID(buffer.readByte());
|
||||||
mech = Upgrade.getByID(buffer.readByte());
|
mech = Upgrade.getByID(buffer.readByte());
|
||||||
|
interpolator.read(lastx, lasty, x, y, time, rotation);
|
||||||
|
rotation = lastrot;
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
|
|
||||||
x = interpolator.pos.x;
|
x = interpolator.pos.x;
|
||||||
y = interpolator.pos.y;
|
y = interpolator.pos.y;
|
||||||
|
|
||||||
if(interpolator.values.length > 0){
|
if(interpolator.values.length > 0){
|
||||||
rotation = interpolator.values[0];
|
rotation = interpolator.values[0];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,6 @@ public class Weapon extends Upgrade {
|
|||||||
Effects.effect(type.smokeEffect, x + weapon.tr.x, y + weapon.tr.y, rotation, player);
|
Effects.effect(type.smokeEffect, x + weapon.tr.x, y + weapon.tr.y, rotation, player);
|
||||||
|
|
||||||
//reset timer for remote players
|
//reset timer for remote players
|
||||||
player.timer.getTime(left ? Player.timerShootLeft : Player.timerShootRight);
|
player.timer.reset(left ? Player.timerShootLeft : Player.timerShootRight, weapon.reload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import io.anuke.mindustry.content.blocks.Blocks;
|
|||||||
import io.anuke.mindustry.content.fx.Fx;
|
import io.anuke.mindustry.content.fx.Fx;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
|
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.net.In;
|
import io.anuke.mindustry.net.In;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
@@ -73,6 +74,11 @@ public class Build {
|
|||||||
//just in case
|
//just in case
|
||||||
if(tile == null) return;
|
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);
|
Block sub = Block.getByName("build" + result.size);
|
||||||
|
|
||||||
tile.setBlock(sub, rotation);
|
tile.setBlock(sub, rotation);
|
||||||
|
|||||||
Reference in New Issue
Block a user