Fixed bug with weapons not costing anything server-side

This commit is contained in:
Anuken
2018-01-05 19:42:38 -05:00
parent 1b9d42e2e4
commit 4cdddd9408
5 changed files with 23 additions and 2 deletions

View File

@@ -255,6 +255,7 @@ public class NetClient extends Module {
});
}
@Override
public void update(){
if(!Net.client() || !Net.active()) return;
@@ -265,6 +266,12 @@ public class NetClient extends Module {
}
}
public void handleUpgrade(Weapon weapon){
UpgradePacket packet = new UpgradePacket();
packet.id = weapon.ordinal();
Net.send(packet, SendMode.tcp);
}
public void handleSendMessage(String message){
ChatPacket packet = new ChatPacket();
packet.text = message;

View File

@@ -155,6 +155,11 @@ public class NetServer extends Module{
packet.name = player.name;
Net.send(packet, SendMode.tcp);
});
Net.handleServer(UpgradePacket.class, packet -> {
Weapon weapon = Weapon.values()[packet.id];
Vars.control.removeItems(weapon.requirements);
});
}
public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){

View File

@@ -114,4 +114,8 @@ public class Packets {
public enum KickReason{
kick, invalidPassword
}
public static class UpgradePacket{
public int id; //weapon ID only, currently
}
}

View File

@@ -34,6 +34,7 @@ public class Registrator {
DisconnectPacket.class,
ChatPacket.class,
KickPacket.class,
UpgradePacket.class,
Class.class,
byte[].class,

View File

@@ -2,8 +2,10 @@ package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.ucore.core.Draw;
@@ -52,9 +54,7 @@ public class UpgradeDialog extends FloatingDialog{
button.getLabelCell().left();
button.pack();
button.update(()->{
if(control.hasWeapon(weapon)){
button.setDisabled(true);
button.setColor(Color.GRAY);
@@ -128,6 +128,10 @@ public class UpgradeDialog extends FloatingDialog{
ui.weaponfrag.updateWeapons();
run.listen();
Effects.sound("purchase");
if(Net.active() && Net.client()){
Vars.netClient.handleUpgrade(weapon);
}
});
}