Fixed compile errors, unitification
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -29,20 +28,11 @@ public class NetEvents {
|
||||
Net.send(new GameOverPacket(), SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){
|
||||
BulletPacket packet = new BulletPacket();
|
||||
packet.x = x;
|
||||
packet.y = y;
|
||||
packet.angle = angle;
|
||||
packet.damage = damage;
|
||||
packet.owner = owner.id;
|
||||
packet.type = type.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleEnemyDeath(BaseUnit enemy){
|
||||
EnemyDeathPacket packet = new EnemyDeathPacket();
|
||||
public static void handleUnitDeath(Unit enemy){
|
||||
EntityDeathPacket packet = new EntityDeathPacket();
|
||||
packet.id = enemy.id;
|
||||
packet.group = (byte)enemy.getGroup().getID();
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
@@ -60,7 +50,7 @@ public class NetEvents {
|
||||
}
|
||||
|
||||
public static void handlePlayerDeath(){
|
||||
PlayerDeathPacket packet = new PlayerDeathPacket();
|
||||
EntityDeathPacket packet = new EntityDeathPacket();
|
||||
packet.id = Vars.player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
@@ -100,13 +90,14 @@ public class NetEvents {
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleShoot(Weapon weapon, float x, float y, float angle){
|
||||
ShootPacket packet = new ShootPacket();
|
||||
packet.weaponid = weapon.id;
|
||||
public static void handleShoot(SyncEntity entity, float x, float y, float angle, short data){
|
||||
EntityShootPacket packet = new EntityShootPacket();
|
||||
packet.groupid = (byte)entity.getGroup().getID();
|
||||
packet.x = x;
|
||||
packet.y = y;
|
||||
packet.data = data;
|
||||
packet.rotation = angle;
|
||||
packet.playerid = Vars.player.id;
|
||||
packet.entityid = entity.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
|
||||
@@ -161,60 +161,31 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
//not a real packet.
|
||||
public static class EffectPacket{
|
||||
public int id;
|
||||
public static class EntityShootPacket implements Packet{
|
||||
public float x, y, rotation;
|
||||
public int color;
|
||||
}
|
||||
|
||||
public static class ShootPacket implements Packet{
|
||||
public byte weaponid;
|
||||
public float x, y, rotation;
|
||||
public int playerid;
|
||||
public short bulletid;
|
||||
public byte groupid;
|
||||
public short data;
|
||||
public int entityid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(weaponid);
|
||||
buffer.put(groupid);
|
||||
buffer.putInt(entityid);
|
||||
buffer.putFloat(x);
|
||||
buffer.putFloat(y);
|
||||
buffer.putFloat(rotation);
|
||||
buffer.putInt(playerid);
|
||||
buffer.putShort(bulletid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
weaponid = buffer.get();
|
||||
groupid = buffer.get();
|
||||
entityid = buffer.getInt();
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
rotation = buffer.getFloat();
|
||||
playerid = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BulletPacket implements Packet{
|
||||
public int type, owner;
|
||||
public float x, y, angle;
|
||||
public short damage;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putShort((short)type);
|
||||
buffer.putInt(owner);
|
||||
buffer.putFloat(x);
|
||||
buffer.putFloat(y);
|
||||
buffer.putFloat(angle);
|
||||
buffer.putShort(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
type = buffer.getShort();
|
||||
owner = buffer.getInt();
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
angle = buffer.getFloat();
|
||||
damage = buffer.getShort();
|
||||
bulletid = buffer.getShort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,16 +260,19 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public static class EnemyDeathPacket implements Packet{
|
||||
public static class EntityDeathPacket implements Packet{
|
||||
public byte group;
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(group);
|
||||
buffer.putInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
group = buffer.get();
|
||||
id = buffer.getInt();
|
||||
}
|
||||
}
|
||||
@@ -496,20 +470,6 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerDeathPacket implements Packet{
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
id = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomMapPacket extends Streamable{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,40 +8,38 @@ import io.anuke.mindustry.net.Streamable.StreamChunk;
|
||||
|
||||
public class Registrator {
|
||||
private static Class<?>[] classes = {
|
||||
StreamBegin.class,
|
||||
StreamChunk.class,
|
||||
WorldData.class,
|
||||
SyncPacket.class,
|
||||
PositionPacket.class,
|
||||
ShootPacket.class,
|
||||
PlacePacket.class,
|
||||
BreakPacket.class,
|
||||
StateSyncPacket.class,
|
||||
BlockSyncPacket.class,
|
||||
BulletPacket.class,
|
||||
EnemyDeathPacket.class,
|
||||
BlockUpdatePacket.class,
|
||||
BlockDestroyPacket.class,
|
||||
ConnectPacket.class,
|
||||
DisconnectPacket.class,
|
||||
ChatPacket.class,
|
||||
KickPacket.class,
|
||||
UpgradePacket.class,
|
||||
WeaponSwitchPacket.class,
|
||||
BlockTapPacket.class,
|
||||
BlockConfigPacket.class,
|
||||
EntityRequestPacket.class,
|
||||
ConnectConfirmPacket.class,
|
||||
GameOverPacket.class,
|
||||
FriendlyFireChangePacket.class,
|
||||
PlayerDeathPacket.class,
|
||||
CustomMapPacket.class,
|
||||
MapAckPacket.class,
|
||||
EntitySpawnPacket.class,
|
||||
NetErrorPacket.class,
|
||||
PlayerAdminPacket.class,
|
||||
AdministerRequestPacket.class,
|
||||
TracePacket.class,
|
||||
StreamBegin.class,
|
||||
StreamChunk.class,
|
||||
WorldData.class,
|
||||
SyncPacket.class,
|
||||
PositionPacket.class,
|
||||
EntityShootPacket.class,
|
||||
PlacePacket.class,
|
||||
BreakPacket.class,
|
||||
StateSyncPacket.class,
|
||||
BlockSyncPacket.class,
|
||||
EntityDeathPacket.class,
|
||||
BlockUpdatePacket.class,
|
||||
BlockDestroyPacket.class,
|
||||
ConnectPacket.class,
|
||||
DisconnectPacket.class,
|
||||
ChatPacket.class,
|
||||
KickPacket.class,
|
||||
UpgradePacket.class,
|
||||
WeaponSwitchPacket.class,
|
||||
BlockTapPacket.class,
|
||||
BlockConfigPacket.class,
|
||||
EntityRequestPacket.class,
|
||||
ConnectConfirmPacket.class,
|
||||
GameOverPacket.class,
|
||||
FriendlyFireChangePacket.class,
|
||||
CustomMapPacket.class,
|
||||
MapAckPacket.class,
|
||||
EntitySpawnPacket.class,
|
||||
NetErrorPacket.class,
|
||||
PlayerAdminPacket.class,
|
||||
AdministerRequestPacket.class,
|
||||
TracePacket.class,
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user