Skip to content

Commit

Permalink
balance changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaktushose committed Jul 8, 2024
1 parent c48b663 commit 831276e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ private String getBonusXp(int karma) {
if (karma < 0) {
return "(-1 PLAY-Punkte)";
}
if (karma >= 300) {
return "(+3 PLAY-Punkte)";
}
if (karma >= 200) {
return "(+2 PLAY-Punkte)";
}
if (karma >= 100) {
return "(+1 PLAY-Punkte)";
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/db/migration/V1.0.3__patch_balance.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE FUNCTION add_random_xp(id BIGINT)
RETURNS TABLE (rank_changed BOOLEAN, previous_rank int, current_rank int, next_rank INT, current_xp INT) AS
$$
DECLARE
xp INT;
bonus_xp INT;
karma INT;
BEGIN
SELECT get_random_xp INTO xp FROM get_random_xp();
SELECT users.karma_points INTO karma FROM users WHERE users.user_id = id;
bonus_xp := 0;
IF karma < 0 THEN
bonus_xp := -1;
ELSIF karma >= 100 THEN
bonus_xp := 1;
END IF;
IF (SELECT EXISTS(SELECT 1 FROM transactions JOIN items ON transactions.item_id = items.item_id WHERE transactions.user_id=id AND type_id = 1)) THEN
bonus_xp := bonus_xp + 1;
END IF;
SELECT INTO rank_changed, previous_rank, current_rank, next_rank, current_xp * FROM add_xp(id, xp + bonus_xp);
RETURN NEXT;
END;
$$ LANGUAGE plpgsql;

0 comments on commit 831276e

Please sign in to comment.