Implemented saving of weapons after disconnect
This commit is contained in:
@@ -102,6 +102,12 @@ public class NetClient extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < data.weapons.length; i ++){
|
||||
Vars.control.addWeapon((Weapon) Upgrade.getByID(data.weapons[i]));
|
||||
}
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Vars.control.getWeapons().peek();
|
||||
Vars.ui.hudfrag.updateWeapons();
|
||||
|
||||
UCore.log("Recieved entities: " + Arrays.toString(data.players) + " player ID: " + data.playerid);
|
||||
gotEntities = true;
|
||||
});
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.*;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
@@ -33,6 +31,7 @@ import java.util.Arrays;
|
||||
public class NetServer extends Module{
|
||||
/**Maps connection IDs to players.*/
|
||||
IntMap<Player> connections = new IntMap<>();
|
||||
ObjectMap<String, ByteArray> weapons = new ObjectMap<>();
|
||||
float serverSyncTime = 4, itemSyncTime = 10, blockSyncTime = 120;
|
||||
boolean closing = false;
|
||||
|
||||
@@ -67,6 +66,7 @@ public class NetServer extends Module{
|
||||
|
||||
dp.playerid = player.id;
|
||||
dp.players = Vars.control.playerGroup.all().toArray(Player.class);
|
||||
dp.weapons = weapons.get(packet.name, new ByteArray()).toArray();
|
||||
|
||||
UCore.log("Sending entities: " + Arrays.toString(dp.players));
|
||||
|
||||
@@ -145,7 +145,13 @@ public class NetServer extends Module{
|
||||
});
|
||||
|
||||
Net.handleServer(UpgradePacket.class, packet -> {
|
||||
Player player = connections.get(Net.getLastConnection());
|
||||
|
||||
Weapon weapon = (Weapon)Upgrade.getByID(packet.id);
|
||||
|
||||
if(!weapons.containsKey(player.name)) weapons.put(player.name, new ByteArray());
|
||||
if(!weapons.get(player.name).contains(weapon.id)) weapons.get(player.name).add(weapon.id);
|
||||
|
||||
Vars.control.removeItems(UpgradeRecipes.get(weapon));
|
||||
});
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Packets {
|
||||
public static class EntityDataPacket{
|
||||
public Player[] players;
|
||||
public int playerid;
|
||||
public byte[] weapons;
|
||||
}
|
||||
|
||||
public static class SyncPacket{
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -35,7 +36,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
protected int explosionRadius = 19;
|
||||
protected int explosionDamage = 135;
|
||||
protected float flashThreshold = 0.46f; //heat threshold at which the lights start flashing
|
||||
|
||||
|
||||
public NuclearReactor(String name) {
|
||||
super(name);
|
||||
generateItem = Item.uranium;
|
||||
@@ -52,6 +53,9 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Input Item: " + generateItem);
|
||||
list.add("[powerinfo]Max Power Generation/second: " + Strings.toFixed(powerMultiplier*60f, 2));
|
||||
list.removeValue(list.select(s -> s.contains("Power/Liquid")).iterator().next(), true);
|
||||
list.removeValue(list.select(s -> s.contains("Max liquid/second:")).iterator().next(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user