Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --norandom to client to disable shot randomization #100

Merged
merged 1 commit into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions client/src/main/java/agolf/game/GameCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import agolf.GameContainer;
import agolf.Seed;
import agolf.SynchronizedBool;

import com.aapeli.client.Parameters;
import com.aapeli.client.StringDraw;
import com.aapeli.tools.Tools;

Expand Down Expand Up @@ -60,6 +62,7 @@ public class GameCanvas extends GameBackgroundCanvas implements Runnable, MouseM
private Graphics graphics;
private Thread aThread2842;
private boolean aBoolean2843;
private boolean norandom;

// aimbot stuff
final private boolean allowCheating = false;
Expand All @@ -74,6 +77,7 @@ protected GameCanvas(GameContainer var1, Image var2) {
this.anInt2833 = 0;
this.gameState = 0;
this.anInt2839 = anInt2838;
this.norandom = Parameters.getBooleanValue(var1.params.getParameter("norandom"));
}

public void update(Graphics g) {
Expand Down Expand Up @@ -947,8 +951,10 @@ private void doStroke(int playerId, boolean isLocalPlayer, int mouseX, int mouse
temp = Math.sqrt(this.speedX[playerId] * this.speedX[playerId] + this.speedY[playerId] * this.speedY[playerId]);
double speed = temp / 6.5D;
speed *= speed;
this.speedX[playerId] += speed * ((double) (this.rngSeed.next() % '\uc351') / 100000.0D - 0.25D);
this.speedY[playerId] += speed * ((double) (this.rngSeed.next() % '\uc351') / 100000.0D - 0.25D);
if (!this.norandom) {
this.speedX[playerId] += speed * ((double) (this.rngSeed.next() % '\uc351') / 100000.0D - 0.25D);
this.speedY[playerId] += speed * ((double) (this.rngSeed.next() % '\uc351') / 100000.0D - 0.25D);
}
this.isLocalPlayer = isLocalPlayer;
this.gameState = 2;
this.aBoolean2843 = false;
Expand Down
7 changes: 4 additions & 3 deletions client/src/main/java/org/moparforia/client/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class Game {
private static final int WIDTH = 735;
private static final int HEIGHT = 525;

public Game(JFrame frame, String server, int port, String lang, boolean verbose) {
public Game(JFrame frame, String server, int port, String lang, boolean verbose, boolean norandom) {
Applet game = new AGolf();


game.setStub(new Stub(server, lang, port, verbose));
game.setStub(new Stub(server, lang, port, verbose, norandom));
game.setSize(WIDTH, HEIGHT);
game.init();
game.start();
Expand All @@ -33,7 +33,7 @@ class Stub implements AppletStub {
private final Map<String, String> params;
private String server;

public Stub(String server, String lang, int port, boolean verbose) {
public Stub(String server, String lang, int port, boolean verbose, boolean norandom) {
if (server.indexOf(':') == -1) { // is ipv4
this.server = server;
} else { // is ipv6
Expand Down Expand Up @@ -72,6 +72,7 @@ public Stub(String server, String lang, int port, boolean verbose) {
params.put("localizationUrl", "");
params.put("sharedLocalizationUrl", "");
params.put("verbose", Boolean.toString(verbose));
params.put("norandom", Boolean.toString(norandom));

//if(serverBox.isSelected())
//params.put("tracktestmode", "true");
Expand Down
9 changes: 6 additions & 3 deletions client/src/main/java/org/moparforia/client/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class Launcher implements Callable<Void> {
@CommandLine.Option(names = {"--verbose", "-v"}, description = "Set if you want verbose information")
private static boolean verbose = false;

@CommandLine.Option(names = {"--norandom", "-n"}, description = "Set if you want to disable randomization for shots")
private static boolean norandom = false;

public static boolean debug() {
return verbose;
}
Expand Down Expand Up @@ -124,7 +127,7 @@ public Void call() throws Exception{
}
}

launchGame(frame, hostname, port, lang, verbose);
launchGame(frame, hostname, port, lang, verbose, norandom);
return null;
}

Expand All @@ -136,8 +139,8 @@ public JFrame createFrame() throws IOException {
return frame;
}

public Game launchGame(JFrame frame, String hostname, int port, Language lang, boolean verbose) {
return new Game(frame, hostname, port, lang.toString(), verbose);
public Game launchGame(JFrame frame, String hostname, int port, Language lang, boolean verbose, boolean norandom) {
return new Game(frame, hostname, port, lang.toString(), verbose, norandom);
}

public Image loadIcon() throws IOException {
Expand Down
14 changes: 9 additions & 5 deletions client/src/test/java/org/moparforia/client/LauncherCLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,41 @@ void testValidLang() {
eq(Launcher.DEFAULT_SERVER),
eq(Launcher.DEFAULT_PORT),
eq(Launcher.Language.EN_US),
anyBoolean(),
anyBoolean());

assertEquals(0, cmd.execute("--lang=Fi_fI"));
verify(launcher).launchGame(any(),
eq(Launcher.DEFAULT_SERVER),
eq(Launcher.DEFAULT_PORT),
eq(Launcher.Language.FI_FI),
anyBoolean(),
anyBoolean());
}

@Test
void testValidPortAndHostname() {
assertEquals(0, cmd.execute("-p", "1111", "-ip", "128.128.128.128"));
verify(launcher).launchGame(any(), eq("128.128.128.128"), eq(1111), any(), anyBoolean());
verify(launcher).launchGame(any(), eq("128.128.128.128"), eq(1111), any(), anyBoolean(), anyBoolean());

assertEquals(0, cmd.execute("-p=2222", "-ip=127.127.127.127"));
verify(launcher).launchGame(any(), eq("127.127.127.127"), eq(2222), any(), anyBoolean());
verify(launcher).launchGame(any(), eq("127.127.127.127"), eq(2222), any(), anyBoolean(), anyBoolean());

assertEquals(0, cmd.execute("-p=3333", "-ip=126.126.126.126"));
verify(launcher).launchGame(any(), eq("126.126.126.126"), eq(3333), any(), anyBoolean());
verify(launcher).launchGame(any(), eq("126.126.126.126"), eq(3333), any(), anyBoolean(), anyBoolean());
}

@Test
void testOnlyPort() {
assertEquals(0, cmd.execute("-p", "1111"));
verify(launcher).launchGame(any(), eq(Launcher.DEFAULT_SERVER), eq(1111), any(), anyBoolean());
verify(launcher).launchGame(any(), eq(Launcher.DEFAULT_SERVER), eq(1111), any(), anyBoolean(), anyBoolean());
}

@Test
void testOnlyHostname() {
assertEquals(0, cmd.execute("-ip", "127.127.127.127"));
verify(launcher).launchGame(any(), eq("127.127.127.127"), eq(Launcher.DEFAULT_PORT), any(), anyBoolean());
verify(launcher).launchGame(any(), eq("127.127.127.127"), eq(Launcher.DEFAULT_PORT), any(), anyBoolean(),
anyBoolean());
}

@Test
Expand All @@ -126,6 +129,7 @@ void testDefaultValues() {
eq(Launcher.DEFAULT_SERVER),
eq(Launcher.DEFAULT_PORT),
eq(Launcher.Language.EN_US),
eq(false),
eq(false)
);
}
Expand Down