Added some simple chat commands.
This commit is contained in:
parent
fa736578a5
commit
289ce50552
|
@ -343,7 +343,7 @@ public class GuiRenderer {
|
|||
nvgFillColor(vgId, GuiUtils.rgba(0.7f, 0, 0, 1, colorA));
|
||||
nvgText(vgId, 5, y, msg.message());
|
||||
} else if (msg.author().equals("_PRIVATE")) {
|
||||
nvgFillColor(vgId, GuiUtils.rgba(0.3f, 0.3f, 0.3f, 1, colorA));
|
||||
nvgFillColor(vgId, GuiUtils.rgba(0.6f, 0.6f, 0.6f, 1, colorA));
|
||||
nvgText(vgId, 5, y, msg.message());
|
||||
} else {
|
||||
nvgFillColor(vgId, GuiUtils.rgba(1, 1, 1, 1, colorA));
|
||||
|
|
|
@ -91,6 +91,13 @@ public class ClientCommunicationHandler {
|
|||
server.getPlayerManager().getHandler(teamPlayer).sendTcpMessage(chat);
|
||||
}
|
||||
}
|
||||
} else if (chatWrittenMessage.message().equalsIgnoreCase("/kd")) {
|
||||
int k = player.getKillCount();
|
||||
int d = player.getDeathCount();
|
||||
float kd = d <= 0 ? 0 : (float) k / (float) d;
|
||||
sendTcpMessage(ChatMessage.privateMessage("Your kill/death ratio is %.2f.".formatted(kd)));
|
||||
} else if (chatWrittenMessage.message().equalsIgnoreCase("/kill")) {
|
||||
server.getPlayerManager().playerKilled(player, null);
|
||||
} else {
|
||||
server.getPlayerManager().broadcastTcpMessage(new ChatMessage(
|
||||
System.currentTimeMillis(),
|
||||
|
|
|
@ -169,11 +169,13 @@ public class PlayerManager {
|
|||
Vector3f deathPosition = new Vector3f(player.getPosition());
|
||||
player.setPosition(getBestSpawnPoint(player));
|
||||
player.setVelocity(new Vector3f(0));
|
||||
player.incrementDeathCount();
|
||||
resupply(player);
|
||||
broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis()));
|
||||
broadcastUdpMessage(new SoundMessage("death", 1, deathPosition));
|
||||
String deathMessage;
|
||||
if (killedBy != null) {
|
||||
killedBy.incrementKillCount();
|
||||
deathMessage = player.getUsername() + " was killed by " + killedBy.getUsername() + ".";
|
||||
} else {
|
||||
deathMessage = player.getUsername() + " died.";
|
||||
|
|
|
@ -184,6 +184,8 @@ public class ProjectileManager {
|
|||
float damage = gun.getBaseDamage();
|
||||
if (playerHitType == 1) damage *= 2;
|
||||
hitPlayer.setHealth(hitPlayer.getHealth() - damage);
|
||||
Vector3f impactAcceleration = new Vector3f(projectile.getVelocity()).normalize().mul(3);
|
||||
hitPlayer.getVelocity().add(impactAcceleration);
|
||||
int soundVariant = ThreadLocalRandom.current().nextInt(1, 4);
|
||||
server.getPlayerManager().broadcastUdpMessage(new SoundMessage("hurt_" + soundVariant, 1, hitPlayer.getPosition(), hitPlayer.getVelocity()));
|
||||
if (hitPlayer.getHealth() == 0) {
|
||||
|
|
|
@ -28,6 +28,9 @@ public class ServerPlayer extends Player {
|
|||
*/
|
||||
private float health;
|
||||
|
||||
private int deathCount;
|
||||
private int killCount;
|
||||
|
||||
public ServerPlayer(int id, String username) {
|
||||
super(id, username);
|
||||
this.inventory = new Inventory(new ArrayList<>(), 0);
|
||||
|
@ -57,6 +60,22 @@ public class ServerPlayer extends Player {
|
|||
this.health = health;
|
||||
}
|
||||
|
||||
public int getDeathCount() {
|
||||
return deathCount;
|
||||
}
|
||||
|
||||
public void incrementDeathCount() {
|
||||
deathCount++;
|
||||
}
|
||||
|
||||
public int getKillCount() {
|
||||
return killCount;
|
||||
}
|
||||
|
||||
public void incrementKillCount() {
|
||||
killCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to build an update message for this player, to be sent to
|
||||
* various clients.
|
||||
|
|
Loading…
Reference in New Issue