Added friendly-fire config.
This commit is contained in:
parent
0bcbedd605
commit
4a2a715f32
|
@ -34,6 +34,11 @@ public class ProjectileManager {
|
||||||
this.removalQueue = new LinkedList<>();
|
this.removalQueue = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spawns any bullets necessary as a result of firing a gun.
|
||||||
|
* @param player The player that fired the gun.
|
||||||
|
* @param gun The gun that is firing the bullet(s).
|
||||||
|
*/
|
||||||
public void spawnBullets(ServerPlayer player, Gun gun) {
|
public void spawnBullets(ServerPlayer player, Gun gun) {
|
||||||
Random rand = ThreadLocalRandom.current();
|
Random rand = ThreadLocalRandom.current();
|
||||||
Vector3f pos = new Vector3f();
|
Vector3f pos = new Vector3f();
|
||||||
|
@ -94,6 +99,12 @@ public class ProjectileManager {
|
||||||
for (ServerPlayer player : server.getPlayerManager().getPlayers()) {
|
for (ServerPlayer player : server.getPlayerManager().getPlayers()) {
|
||||||
// Don't allow players to shoot themselves.
|
// Don't allow players to shoot themselves.
|
||||||
if (projectile.getPlayer() != null && projectile.getPlayer().equals(player)) continue;
|
if (projectile.getPlayer() != null && projectile.getPlayer().equals(player)) continue;
|
||||||
|
// Don't check for collisions with team players, if friendly fire is disabled.
|
||||||
|
if (
|
||||||
|
!server.getConfig().actions.friendlyFire &&
|
||||||
|
projectile.getPlayer() != null && projectile.getPlayer().getTeam() != null &&
|
||||||
|
projectile.getPlayer().getTeam().equals(player.getTeam())
|
||||||
|
) continue;
|
||||||
|
|
||||||
Vector3f headPos = player.getEyePosition();
|
Vector3f headPos = player.getEyePosition();
|
||||||
Vector3f bodyPos = new Vector3f(player.getPosition());
|
Vector3f bodyPos = new Vector3f(player.getPosition());
|
||||||
|
@ -128,25 +139,10 @@ public class ProjectileManager {
|
||||||
// If we hit the world before the player,
|
// If we hit the world before the player,
|
||||||
if (hit != null && (playerHit == null || worldHitDist < playerHitDist)) {
|
if (hit != null && (playerHit == null || worldHitDist < playerHitDist)) {
|
||||||
// Bullet struck the world first.
|
// Bullet struck the world first.
|
||||||
server.getWorld().setBlockAt(hit.pos().x, hit.pos().y, hit.pos().z, (byte) 0);
|
handleProjectileBlockHit(hit, projectile);
|
||||||
server.getPlayerManager().broadcastUdpMessage(ChunkUpdateMessage.fromWorld(hit.pos(), server.getWorld()));
|
|
||||||
int soundVariant = ThreadLocalRandom.current().nextInt(1, 6);
|
|
||||||
server.getPlayerManager().broadcastUdpMessage(new SoundMessage("bullet_impact_" + soundVariant, 1, hit.rawPos()));
|
|
||||||
deleteProjectile(projectile);
|
|
||||||
} else if (playerHit != null && (hit == null || playerHitDist < worldHitDist)) {
|
} else if (playerHit != null && (hit == null || playerHitDist < worldHitDist)) {
|
||||||
// Bullet struck the player first.
|
// Bullet struck the player first.
|
||||||
float damage = 0.4f;
|
handleProjectilePlayerHit(playerHitType, hitPlayer, projectile);
|
||||||
if (playerHitType == 1) damage *= 2;
|
|
||||||
hitPlayer.setHealth(hitPlayer.getHealth() - damage);
|
|
||||||
int soundVariant = ThreadLocalRandom.current().nextInt(1, 4);
|
|
||||||
server.getPlayerManager().broadcastUdpMessage(new SoundMessage("hurt_" + soundVariant, 1, hitPlayer.getPosition(), hitPlayer.getVelocity()));
|
|
||||||
if (hitPlayer.getHealth() == 0) {
|
|
||||||
System.out.println("Player killed!!!");
|
|
||||||
server.getPlayerManager().playerKilled(hitPlayer);
|
|
||||||
} else {
|
|
||||||
server.getPlayerManager().getHandler(hitPlayer).sendDatagramPacket(new ClientHealthMessage(hitPlayer.getHealth()));
|
|
||||||
}
|
|
||||||
deleteProjectile(projectile);
|
|
||||||
} else {
|
} else {
|
||||||
// Bullet struck nothing.
|
// Bullet struck nothing.
|
||||||
projectile.getPosition().add(movement);
|
projectile.getPosition().add(movement);
|
||||||
|
@ -158,6 +154,28 @@ public class ProjectileManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleProjectileBlockHit(Hit hit, ServerProjectile projectile) {
|
||||||
|
server.getWorld().setBlockAt(hit.pos().x, hit.pos().y, hit.pos().z, (byte) 0);
|
||||||
|
server.getPlayerManager().broadcastUdpMessage(ChunkUpdateMessage.fromWorld(hit.pos(), server.getWorld()));
|
||||||
|
int soundVariant = ThreadLocalRandom.current().nextInt(1, 6);
|
||||||
|
server.getPlayerManager().broadcastUdpMessage(new SoundMessage("bullet_impact_" + soundVariant, 1, hit.rawPos()));
|
||||||
|
deleteProjectile(projectile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleProjectilePlayerHit(int playerHitType, ServerPlayer hitPlayer, ServerProjectile projectile) {
|
||||||
|
float damage = 0.4f;
|
||||||
|
if (playerHitType == 1) damage *= 2;
|
||||||
|
hitPlayer.setHealth(hitPlayer.getHealth() - damage);
|
||||||
|
int soundVariant = ThreadLocalRandom.current().nextInt(1, 4);
|
||||||
|
server.getPlayerManager().broadcastUdpMessage(new SoundMessage("hurt_" + soundVariant, 1, hitPlayer.getPosition(), hitPlayer.getVelocity()));
|
||||||
|
if (hitPlayer.getHealth() == 0) {
|
||||||
|
server.getPlayerManager().playerKilled(hitPlayer);
|
||||||
|
} else {
|
||||||
|
server.getPlayerManager().getHandler(hitPlayer).sendDatagramPacket(new ClientHealthMessage(hitPlayer.getHealth()));
|
||||||
|
}
|
||||||
|
deleteProjectile(projectile);
|
||||||
|
}
|
||||||
|
|
||||||
private void deleteProjectile(ServerProjectile p) {
|
private void deleteProjectile(ServerProjectile p) {
|
||||||
removalQueue.add(p);
|
removalQueue.add(p);
|
||||||
server.getPlayerManager().broadcastUdpMessage(p.toMessage(true));
|
server.getPlayerManager().broadcastUdpMessage(p.toMessage(true));
|
||||||
|
|
|
@ -25,5 +25,6 @@ public class ServerConfig {
|
||||||
public float resupplyCooldown = 30;
|
public float resupplyCooldown = 30;
|
||||||
public float resupplyRadius = 3;
|
public float resupplyRadius = 3;
|
||||||
public float movementAccuracyDecreaseFactor = 0.01f;
|
public float movementAccuracyDecreaseFactor = 0.01f;
|
||||||
|
public boolean friendlyFire = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue