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));
|
nvgFillColor(vgId, GuiUtils.rgba(0.7f, 0, 0, 1, colorA));
|
||||||
nvgText(vgId, 5, y, msg.message());
|
nvgText(vgId, 5, y, msg.message());
|
||||||
} else if (msg.author().equals("_PRIVATE")) {
|
} 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());
|
nvgText(vgId, 5, y, msg.message());
|
||||||
} else {
|
} else {
|
||||||
nvgFillColor(vgId, GuiUtils.rgba(1, 1, 1, 1, colorA));
|
nvgFillColor(vgId, GuiUtils.rgba(1, 1, 1, 1, colorA));
|
||||||
|
|
|
@ -91,6 +91,13 @@ public class ClientCommunicationHandler {
|
||||||
server.getPlayerManager().getHandler(teamPlayer).sendTcpMessage(chat);
|
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 {
|
} else {
|
||||||
server.getPlayerManager().broadcastTcpMessage(new ChatMessage(
|
server.getPlayerManager().broadcastTcpMessage(new ChatMessage(
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
|
|
|
@ -169,11 +169,13 @@ public class PlayerManager {
|
||||||
Vector3f deathPosition = new Vector3f(player.getPosition());
|
Vector3f deathPosition = new Vector3f(player.getPosition());
|
||||||
player.setPosition(getBestSpawnPoint(player));
|
player.setPosition(getBestSpawnPoint(player));
|
||||||
player.setVelocity(new Vector3f(0));
|
player.setVelocity(new Vector3f(0));
|
||||||
|
player.incrementDeathCount();
|
||||||
resupply(player);
|
resupply(player);
|
||||||
broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis()));
|
broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis()));
|
||||||
broadcastUdpMessage(new SoundMessage("death", 1, deathPosition));
|
broadcastUdpMessage(new SoundMessage("death", 1, deathPosition));
|
||||||
String deathMessage;
|
String deathMessage;
|
||||||
if (killedBy != null) {
|
if (killedBy != null) {
|
||||||
|
killedBy.incrementKillCount();
|
||||||
deathMessage = player.getUsername() + " was killed by " + killedBy.getUsername() + ".";
|
deathMessage = player.getUsername() + " was killed by " + killedBy.getUsername() + ".";
|
||||||
} else {
|
} else {
|
||||||
deathMessage = player.getUsername() + " died.";
|
deathMessage = player.getUsername() + " died.";
|
||||||
|
|
|
@ -184,6 +184,8 @@ public class ProjectileManager {
|
||||||
float damage = gun.getBaseDamage();
|
float damage = gun.getBaseDamage();
|
||||||
if (playerHitType == 1) damage *= 2;
|
if (playerHitType == 1) damage *= 2;
|
||||||
hitPlayer.setHealth(hitPlayer.getHealth() - damage);
|
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);
|
int soundVariant = ThreadLocalRandom.current().nextInt(1, 4);
|
||||||
server.getPlayerManager().broadcastUdpMessage(new SoundMessage("hurt_" + soundVariant, 1, hitPlayer.getPosition(), hitPlayer.getVelocity()));
|
server.getPlayerManager().broadcastUdpMessage(new SoundMessage("hurt_" + soundVariant, 1, hitPlayer.getPosition(), hitPlayer.getVelocity()));
|
||||||
if (hitPlayer.getHealth() == 0) {
|
if (hitPlayer.getHealth() == 0) {
|
||||||
|
|
|
@ -28,6 +28,9 @@ public class ServerPlayer extends Player {
|
||||||
*/
|
*/
|
||||||
private float health;
|
private float health;
|
||||||
|
|
||||||
|
private int deathCount;
|
||||||
|
private int killCount;
|
||||||
|
|
||||||
public ServerPlayer(int id, String username) {
|
public ServerPlayer(int id, String username) {
|
||||||
super(id, username);
|
super(id, username);
|
||||||
this.inventory = new Inventory(new ArrayList<>(), 0);
|
this.inventory = new Inventory(new ArrayList<>(), 0);
|
||||||
|
@ -57,6 +60,22 @@ public class ServerPlayer extends Player {
|
||||||
this.health = health;
|
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
|
* Helper method to build an update message for this player, to be sent to
|
||||||
* various clients.
|
* various clients.
|
||||||
|
|
Loading…
Reference in New Issue