Added support for reset at certain points to golf

This commit is contained in:
2022-05-29 21:31:52 -04:00
parent cc461ec382
commit ec3afbfb92
4 changed files with 24 additions and 9 deletions

View File

@@ -164,9 +164,9 @@ function readyGame($game) {
if ($USERNAME) {
if (array_key_exists("game", $_GET)){ // Gets the game
# Finds all games the player is still playing.
$playing = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks, skipTime, skipTurns FROM golfGame WHERE EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY turnStartTime DESC");
$playing = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks, skipTime, skipTurns, resetPoints FROM golfGame WHERE EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY turnStartTime DESC");
# Finds all open games.
$data = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks, skipTime, skipTurns FROM golfGame WHERE players != playersToStart and NOT EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY players DESC");
$data = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks, skipTime, skipTurns, resetPoints FROM golfGame WHERE players != playersToStart and NOT EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY players DESC");
foreach ($data as $id => $entry) { // Makes sure to not leak the password
if ($entry["password"]) {
$data[$id]["password"] = true;
@@ -260,11 +260,18 @@ if ($USERNAME) {
dbCommand("UPDATE golfGamePlayers SET lastMode='$action' WHERE gameID='$id' and user='$USERNAME'");
$id = $game["ID"];
if (! dbRequest2("SELECT * FROM golfGamePlayers WHERE gameID='$id' and (lastMode='switch' or lastMode='')")) { // The code for when a new round is started
if (dbRequest2("SELECT * FROM golfGamePlayers WHERe gameID='$id' and not lastMode='eliminated'")) {
if (dbRequest2("SELECT * FROM golfGamePlayers WHERE gameID='$id' and not lastMode='eliminated'")) { // Makes sure that not all the players are eliminated
$length = count($players);
$resetPoints = $game["resetPoints"];
writeLog(0, "RAN THIS CODE with resetPonts=$resetPoints");
for ($i=0;$i<$length; $i++) { // Will calculate points for every player and add them to the total
$name = $players[$i]["user"];
$newPoints = $players[$i]["points"] + calculatePoints($name, $game["ID"]);
if ($resetPoints > 0) { // Makes sure that resetPoints is enabled
if ($newPoints % $resetPoints == 0) { // Checks if the points are at a resetable amount
$newPoints = 0;
}
}
dbCommand("UPDATE golfGamePlayers SET points=$newPoints WHERE gameID=$id and user='$name'");
}
$game = readyGame($id);
@@ -359,6 +366,7 @@ if ($USERNAME) {
$decks = intval($_POST["decks"]);
$skipTime = intval($_POST["skipTime"]);
$skipTurns = intval($_POST["skipTurns"]);
$resetPoints = intval($_POST["resetPoints"]);
$time = time();
if (array_key_exists("password", $_POST)) {
$password = $_POST["password"];
@@ -391,8 +399,11 @@ if ($USERNAME) {
} elseif ($skipTurns < 0) {
http_response_code(400);
echo "Only positive amount of turns skiped are allowed";
} elseif ($resetPoints < 0) {
http_response_code(400);
echo "Reset points must be a positive number or 0";
} else {
dbCommand("INSERT INTO golfGame (deck, discard, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, name, password, players, playersToStart, currentPlayer, turnStartTime, decks, skipTime, timeLeft, skipTurns) VALUES ('[]', '[]', $cardNumber, $flipNumber, $multiplierForFlip, $pointsToEnd, '$name', '$password', 0, $playersToStart, -1, $time, $decks, $skipTime, $skipTime, $skipTurns)");
dbCommand("INSERT INTO golfGame (deck, discard, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, name, password, players, playersToStart, currentPlayer, turnStartTime, decks, skipTime, timeLeft, skipTurns, resetPoints) VALUES ('[]', '[]', $cardNumber, $flipNumber, $multiplierForFlip, $pointsToEnd, '$name', '$password', 0, $playersToStart, -1, $time, $decks, $skipTime, $skipTime, $skipTurns, $resetPoints)");
echo "Created Game";
writeLog(14, "$USERNAME created game for $playersToStart players, $cardNumber cards, $decks decks, and name $name with ip of $address");
}

View File

@@ -1,5 +1,5 @@
function update(repeat=false) { // Will update the game.
var text = "<tr><th>Name</th><th>Players</th><th>Max Players</th><th>Skip Time</th><th>Skip Turns</th><th>Multiplier for Flipping Last Card</th><th>Points to Out</th><th>Password</th><th>Cards</th><th>Cards to flip</th><th>Decks</th></tr>";
var text = "<tr><th>Name</th><th>Players</th><th>Max Players</th><th>Skip Time</th><th>Skip Turns</th><th>Multiplier for Flipping Last Card</th><th>Points to Out</th><th>Password</th><th>Cards</th><th>Cards to flip</th><th>Decks</th><th>Reset Points</th></tr>";
const ajax = new XMLHttpRequest();
ajax.onload = function() {
if (ajax.status == 200) {
@@ -8,7 +8,7 @@ function update(repeat=false) { // Will update the game.
if (element.players == element.playersToStart) {
joinText = "Continue";
}
text += `<tr><td>${element.name} <button onClick='joinGame(${element.ID})'>${joinText}</button></td><td>${element.players}</td><td>${element.playersToStart}</td><td>${element.skipTime}</td><td>${element.skipTurns}</td><td>${element.multiplierForFlip}</td><td>${element.pointsToEnd}</td><td>${element.password ? `true` : "false"}</td><td>${element.cardNumber}</td><td>${element.flipNumber}</td><td>${element.decks}</td></tr>`;
text += `<tr><td>${element.name} <button onClick='joinGame(${element.ID})'>${joinText}</button></td><td>${element.players}</td><td>${element.playersToStart}</td><td>${element.skipTime}</td><td>${element.skipTurns}</td><td>${element.multiplierForFlip}</td><td>${element.pointsToEnd}</td><td>${element.password ? `true` : "false"}</td><td>${element.cardNumber}</td><td>${element.flipNumber}</td><td>${element.decks}</td><td>${element.resetPoints}</td></tr>`;
});
$("#games").html(text);
} else {
@@ -40,7 +40,7 @@ function create() { // Will create a game
if ($("#password").val()) {
password = `&password=${$("#password").val()}`;
}
ajax.send(`create=${$("#name").val()}&cardNumber=${$("#cardNumber").val()}&flipNumber=${$("#flipNumber").val()}&playersToStart=${$("#playersToStart").val()}&multiplierForFlip=${$("#multiplierForFlip").val()}&pointsToEnd=${$("#pointsToEnd").val()}&decks=${$("#decks").val()}&skipTime=${$("#skipTime").val()}&skipTurns=${$("#skipTurns").val()}&key='${getCookie('user')}'${password}`);
ajax.send(`create=${$("#name").val()}&cardNumber=${$("#cardNumber").val()}&flipNumber=${$("#flipNumber").val()}&playersToStart=${$("#playersToStart").val()}&multiplierForFlip=${$("#multiplierForFlip").val()}&pointsToEnd=${$("#pointsToEnd").val()}&decks=${$("#decks").val()}&skipTime=${$("#skipTime").val()}&skipTurns=${$("#skipTurns").val()}&resetPoints=${$("#resetPoints").val()}&key='${getCookie('user')}'${password}`);
}
function joinGame(id) {
window.location = `game.php?game=${id}`;

View File

@@ -40,6 +40,7 @@
<label for="decks">Number of decks to use: </label><input type='number' value='1' id="decks"><br>
<label for="skipTime">Amount of time to wait before player is skipped(0 means infinite): </label><input type='number' value='0' id="skipTime"><br>
<label for="skipTurns">Amount of turns the player can skip(0 means infinite): </label><input type='number' value='0' id="skipTurns"><br>
<label for="resetPoints">The number of points that when a multiple of thsi number is reached your points will reset(0 disables this): </label><input type='number' value='0' id="resetPoints"><br>
<label for="password">Password(leave blank for none): </label><input type='password' value='' id="password"><br>
<button id='create'>Create</button>
</div>

View File

@@ -167,7 +167,7 @@ def repair(): # Repairs all tables or updates them if needed
"space3likes" : [["id", 1], ["account", 0]],
"golfGamePlayers" : [["gameID", 1], ["multiplier", 1], ["user", 0], ["points", 1], ["orderID", 1], ["lastMode", 0], ["upToDate", 6], ["turnsSkipped", 1]],
"golfGameCards" : [["gameID", 1], ["user", 0], ["card", 1], ["cardPlacement", 1], ["faceUp", 6]],
"golfGame" : [["ID", 5], ["deck", 4], ["discard", 4], ["cardNumber", 1], ["flipNumber", 1], ["multiplierForFlip", 1], ["pointsToEnd", 1], ["name", 0], ["password", 0], ["players", 1], ["playersToStart", 1], ["currentPlayer", 1], ["turnStartTime", 1], ["locked", 6], ["decks", 1], ["skipTime", 1], ["timeLeft", 1], ["skipTurns", 1]],
"golfGame" : [["ID", 5], ["deck", 4], ["discard", 4], ["cardNumber", 1], ["flipNumber", 1], ["multiplierForFlip", 1], ["pointsToEnd", 1], ["name", 0], ["password", 0], ["players", 1], ["playersToStart", 1], ["currentPlayer", 1], ["turnStartTime", 1], ["locked", 6], ["decks", 1], ["skipTime", 1], ["timeLeft", 1], ["skipTurns", 1], ["resetPoints", 1]],
"docker" : [["link", 0], ["action", 0], ["image", 0], ["password", 0], ["owner", 0], ["port", 1], ["ID", 0]],
"dockerImages" : [["realName", 0], ["shortName", 0]]
}
@@ -226,7 +226,7 @@ def repair(): # Repairs all tables or updates them if needed
changedTables.append(name)
elif name == "information": # Used to check the information table to see if the database can be updated in a better way.
version = trueSearch("SELECT data FROM information WHERE pointer='version'")
latest_version = "v2.3"
latest_version = "v2.4"
if version: # Checks if the version tag still exists.
try: # In here you can update the version to a new version
version = version[0][0]
@@ -265,6 +265,9 @@ def repair(): # Repairs all tables or updates them if needed
command("UPDATE golfGamePlayers SET turnsSkipped='0'")
version = "v2.3"
updatedVersions.append("v2.3")
if version == "v2.3": # Adds support for reset points when hitting a certain multiplier
command("ALTER table golfGame ADD resetPoints int")
command("UPDATE golfGame SET resetPoints='0'")
# Fixes the version if it is invalid to the latest version
if version != latest_version:
version = latest_version