Skip to content

Commit

Permalink
Rocket launcher support (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
beverly-hills-money-gangster authored Dec 19, 2024
1 parent 6038ecf commit f1dcc24
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 141 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Game server can be configured using the following environment variables:
- `GAME_SERVER_DEFAULT_SHOTGUN_DAMAGE` Gunshot damage. Default - `20`.
- `GAME_SERVER_DEFAULT_RAILGUN_DAMAGE` Railgun damage. Default - `75`.
- `GAME_SERVER_DEFAULT_PUNCH_DAMAGE` Punch damage. Default - `50`.
- `GAME_SERVER_DEFAULT_ROCKET_DAMAGE` Rocket damage. Default - `75`.
- `GAME_SERVER_DEFAULT_MINIGUN_DAMAGE` Minigun damage. Default - `5`.
- `GAME_SERVER_FAST_TCP` Enables fast TCP configurations(used mostly for testing, not recommended to
be set to `false` in prod). Default - `true`.
Expand All @@ -71,6 +72,7 @@ Game server can be configured using the following environment variables:
all players' speed. Anybody moving faster than `GAME_SERVER_PLAYER_SPEED` will be kicked-out.
Default - `10_000`
- `GAME_SERVER_PUNCH_DELAY_MLS` Punch attack delay(in milliseconds). Default - `300`
- `GAME_SERVER_ROCKET_LAUNCHER_DELAY_MLS` Rocket launcher delay(in milliseconds). Default - `1_500`.
- `GAME_SERVER_SHOTGUN_DELAY_MLS` Shotgun attack delay(in milliseconds). Default - `450`
- `GAME_SERVER_RAILGUN_DELAY_MLS` Railgun attack delay(in milliseconds). Default - `1_700`
- `GAME_SERVER_MINIGUN_DELAY_MLS` Minigun attack delay(in milliseconds). Default - `155`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions schema/src/main/resources/server-common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum WeaponType {
SHOTGUN = 1;
RAILGUN = 2;
MINIGUN = 3;
ROCKET_LAUNCHER = 4;
ROCKET = 5;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class AntiCheat {
// 20% error
private static final double MAX_DISTANCE_TRAVELLED_IN_ONE_SEC = ServerConfig.PLAYER_SPEED * 1.2;

public boolean isAttackingTooFar(final Vector shooterPosition, final Vector victimPosition,
public boolean isAttackingTooFar(final Vector position, final Vector victimPosition,
final AttackType attackType) {
return Vector.getDistance(shooterPosition, victimPosition) > MAX_ATTACK_DISTANCE.get(
return Vector.getDistance(position, victimPosition) > MAX_ATTACK_DISTANCE.get(
attackType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public interface ServerConfig {
int DEFAULT_MINIGUN_DAMAGE = NumberUtils.toInt(
System.getenv("GAME_SERVER_DEFAULT_MINIGUN_DAMAGE"), 5);


int DEFAULT_ROCKET_DAMAGE = NumberUtils.toInt(
System.getenv("GAME_SERVER_DEFAULT_ROCKET_DAMAGE"), 75);

int DEFAULT_PUNCH_DAMAGE = NumberUtils.toInt(System.getenv("GAME_SERVER_DEFAULT_PUNCH_DAMAGE"),
50);

Expand Down Expand Up @@ -71,6 +75,8 @@ public interface ServerConfig {
int PUNCH_DELAY_MLS = NumberUtils.toInt(System.getenv("GAME_SERVER_PUNCH_DELAY_MLS"), 300);
int SHOTGUN_DELAY_MLS = NumberUtils.toInt(System.getenv("GAME_SERVER_SHOTGUN_DELAY_MLS"), 450);
int RAILGUN_DELAY_MLS = NumberUtils.toInt(System.getenv("GAME_SERVER_RAILGUN_DELAY_MLS"), 1_700);
int ROCKET_LAUNCHER_DELAY_MLS = NumberUtils.toInt(
System.getenv("GAME_SERVER_ROCKET_LAUNCHER_DELAY_MLS"), 1_500);
int MINIGUN_DELAY_MLS = NumberUtils.toInt(System.getenv("GAME_SERVER_MINIGUN_DELAY_MLS"), 155);

int PLAYER_STATS_TIMEOUT_MLS = NumberUtils.toInt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ private static WeaponType getWeaponType(AttackType attackType) {
case SHOTGUN -> WeaponType.SHOTGUN;
case RAILGUN -> WeaponType.RAILGUN;
case MINIGUN -> WeaponType.MINIGUN;
case ROCKET -> WeaponType.ROCKET;
case ROCKET_LAUNCHER -> WeaponType.ROCKET_LAUNCHER;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.beverly.hills.money.gang.state.Game;
import com.beverly.hills.money.gang.state.PlayerStateChannel;
import com.beverly.hills.money.gang.state.entity.PlayerAttackingGameState;
import com.beverly.hills.money.gang.state.entity.PlayerState;
import com.beverly.hills.money.gang.state.entity.PlayerState.Coordinates;
import com.beverly.hills.money.gang.state.entity.Vector;
import com.beverly.hills.money.gang.util.NetworkUtil;
import io.netty.channel.Channel;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected void handleGameEvents(Game game, PushGameEventCommand gameCommand,
MDC.put(MDC_PLAYER_ID, String.valueOf(playerState.getPlayerState().getPlayerId()));
MDC.put(MDC_PLAYER_NAME, playerState.getPlayerState().getPlayerName());
MDC.put(MDC_IP_ADDRESS, playerState.getPrimaryChannelAddress());
MDC.put(MDC_PING_MLS, Optional.ofNullable(playerState.getPlayerState().getPingMls())
MDC.put(MDC_PING_MLS, Optional.of(playerState.getPlayerState().getPingMls())
.map(String::valueOf).orElse(""));

PushGameEventCommand.GameEventType gameEventType = gameCommand.getEventType();
Expand Down Expand Up @@ -260,7 +260,7 @@ private void handleAttackingEvents(Game game, PushGameEventCommand gameCommand)
}

private boolean isAttackCheating(PushGameEventCommand gameCommand, Game game) {
var newPlayerPosition = Vector.builder()
var position = Vector.builder()
.x(gameCommand.getPosition().getX())
.y(gameCommand.getPosition().getY())
.build();
Expand All @@ -270,7 +270,7 @@ private boolean isAttackCheating(PushGameEventCommand gameCommand, Game game) {
return game.getPlayersRegistry()
.getPlayerState(gameCommand.getAffectedPlayerId())
.map(affectedPlayerState -> antiCheat.isAttackingTooFar(
newPlayerPosition, affectedPlayerState.getCoordinates().getPosition(),
position, affectedPlayerState.getCoordinates().getPosition(),
getAttackType(gameCommand))).orElse(false);
}

Expand All @@ -280,13 +280,15 @@ private AttackType getAttackType(PushGameEventCommand gameCommand) {
case PUNCH -> AttackType.PUNCH;
case RAILGUN -> AttackType.RAILGUN;
case MINIGUN -> AttackType.MINIGUN;
case ROCKET -> AttackType.ROCKET;
case ROCKET_LAUNCHER -> AttackType.ROCKET_LAUNCHER;
default -> throw new IllegalArgumentException(
"Not supported attack type " + gameCommand.getEventType());
};
}

private PlayerState.PlayerCoordinates createCoordinates(PushGameEventCommand gameCommand) {
return PlayerState.PlayerCoordinates
private Coordinates createCoordinates(PushGameEventCommand gameCommand) {
return Coordinates
.builder()
.direction(Vector.builder()
.x(gameCommand.getDirection().getX()).y(gameCommand.getDirection().getY()).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.beverly.hills.money.gang.state.Game;
import com.beverly.hills.money.gang.state.PlayerStateChannel;
import com.beverly.hills.money.gang.state.entity.PlayerState;
import com.beverly.hills.money.gang.state.entity.PlayerState.PlayerCoordinates;
import com.beverly.hills.money.gang.state.entity.PlayerState.Coordinates;
import com.beverly.hills.money.gang.state.entity.Vector;
import com.beverly.hills.money.gang.teleport.Teleport;
import java.util.HashMap;
Expand All @@ -24,22 +23,22 @@ public class Spawner {
public static final List<Teleport> TELEPORTS = List.of(
Teleport.builder().id(1)
.location(Vector.builder().x(-25f).y(23f).build())
.teleportCoordinates(PlayerCoordinates.builder()
.teleportCoordinates(Coordinates.builder()
.position(Vector.builder().x(8.045f + 0.3f).y(21.556356f).build())
.direction(Vector.builder().x(0.0076999734f).y(-0.99996966f).build())
.build()).build(),
Teleport.builder().id(2)
.location(Vector.builder().x(8.045f).y(23.0f).build())
.teleportCoordinates(
PlayerCoordinates.builder()
Coordinates.builder()
.position(Vector.builder().x(-22.39956f).y(23.152378f + 0.2f).build())
.direction(Vector.builder().x(0.9999982f).y(-0.0021766382f).build())
.build()
).build(),
Teleport.builder().id(3)
.location(Vector.builder().x(8.045f).y(13.0f).build())
.teleportCoordinates(
PlayerCoordinates.builder()
Coordinates.builder()
.position(Vector.builder().x(-24.676086f).y(9.441682f).build())
.direction(Vector.builder().x(-0.008718174f).y(0.99996203f).build())
.build()
Expand All @@ -58,54 +57,54 @@ public class Spawner {
private static final Vector HEALTH_SPAWN_POSITION
= Vector.builder().x(-14.810499f-0.2f).y(27.771694f-0.7f).build();

public static final List<PlayerState.PlayerCoordinates> SPAWNS = List.of(
public static final List<Coordinates> SPAWNS = List.of(

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-20.251183F).y(28.641932F).build())
.direction(
Vector.builder().x(-0.9999984F).y(0.0018975139F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-29.052916F).y(28.827929F).build())
.direction(
Vector.builder().x(0.9985066F).y(0.05463622F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-30.03456F).y(19.154572F).build())
.direction(
Vector.builder().x(-0.0112161245F).y(0.99993724F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-19.544775F).y(20.086754F).build())
.direction(
Vector.builder().x(-0.032291915F).y(0.99947816F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-30.80954F).y(23.183435F).build())
.direction(
Vector.builder().x(0.9999779F).y(0.0065644206F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-19.638683F).y(9.2295475F).build())
.direction(
Vector.builder().x(-0.99999154F).y(0.0042496235F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-29.331905F).y(9.307028F).build())
.direction(
Vector.builder().x(0.9999444F).y(-0.010604665F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-29.125614F).y(14.255738F).build())
.direction(
Vector.builder().x(0.99985945F).y(-0.01679205f).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-20.50718F).y(14.282006F).build())
.direction(
Vector.builder().x(-0.9999949F).y(-0.0032620127F).build()).build(),

PlayerState.PlayerCoordinates.builder().position(
Coordinates.builder().position(
Vector.builder().x(-13.015404F).y(23.23161F).build())
.direction(
Vector.builder().x(-0.99998957F).y(-0.004201251F).build()).build()
Expand All @@ -128,7 +127,7 @@ public Vector spawnInvisibility() {
return INVISIBILITY_SPAWN_POSITION;
}

public PlayerState.PlayerCoordinates spawnPlayer(Game game) {
public Coordinates spawnPlayer(Game game) {
var players = game.getPlayersRegistry()
.allPlayers()
.map(PlayerStateChannel::getPlayerState)
Expand All @@ -137,7 +136,7 @@ public PlayerState.PlayerCoordinates spawnPlayer(Game game) {
// get random spawns
var randomSpawns = getRandomSpawns();

var playersAroundSpawn = new HashMap<Integer, PlayerCoordinates>();
var playersAroundSpawn = new HashMap<Integer, Coordinates>();
// get the least populated among them
randomSpawns.forEach(spawn -> {
var playersAround = (int) players.stream()
Expand All @@ -149,12 +148,12 @@ public PlayerState.PlayerCoordinates spawnPlayer(Game game) {
return playersAroundSpawn.values().stream().findFirst().get();
}

public List<PlayerState.PlayerCoordinates> getRandomSpawns() {
public List<Coordinates> getRandomSpawns() {
return Stream.generate(this::getRandomSpawn)
.limit(SPAWNS.size() / 2).collect(Collectors.toList());
}

private PlayerState.PlayerCoordinates getRandomSpawn() {
private Coordinates getRandomSpawn() {
return SPAWNS.get(RANDOM.nextInt(SPAWNS.size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,30 @@ public enum AttackType {
// shotgun damage increases as the player gets closer to the victim
SHOTGUN(distance -> {
if (distance < 1) {
return 3;
return 3.0;
} else if (distance < 2) {
return 2;
return 2.0;
}
return 1;
}),
PUNCH(distance -> 1),
RAILGUN(distance -> 1),
MINIGUN(distance -> 1);
return 1.0;
}, false),
PUNCH(distance -> 1.0, false),
RAILGUN(distance -> 1.0, false),
MINIGUN(distance -> 1.0, false),

ROCKET(distance -> {
if (distance < 1) {
return 1.0;
}
return 1 / distance;
}, true),

// rocket launcher itself doesn't do any damage
ROCKET_LAUNCHER(distance -> 0.0, false);

@Getter
private final Function<Double, Integer> distanceDamageAmplifier;
private final Function<Double, Double> distanceDamageAmplifier;

@Getter
private final boolean projectile;

}
Loading

0 comments on commit f1dcc24

Please sign in to comment.