diff --git a/Backend/generic-food.js b/Backend/generic-food.js index 4116749..67b0b1d 100644 --- a/Backend/generic-food.js +++ b/Backend/generic-food.js @@ -255,6 +255,12 @@ var filteredWords = [ "Clam", "Squid", "Shrimp", +"Onigiri", +"Alan Wang", +"Keke", +"Software Engineering", +"Cat Corp the Cat", +"Microplastics", "Crayfish", "Flatfish", "Piglet", diff --git a/Backend/user.js b/Backend/user.js index 8aaa8db..e66caea 100644 --- a/Backend/user.js +++ b/Backend/user.js @@ -13,7 +13,7 @@ export async function checkUsernameAvailable(username) { // This function does NOT do any checks for unique usernames, etc. export async function registerAccount(username, password) { const hashedPassword = await bcrypt.hash(password, 10); - const user = await getUserDB().insertOne({ "username": username, "password": hashedPassword, "lastLogin": Date.now(), "gems": 0, "cats": [] }) + const user = await getUserDB().insertOne({ "username": username, "password": hashedPassword, "lastLogin": Date.now(), "gems": 0, "cats": [], "streak": 0 }) return user.insertedId } @@ -109,6 +109,11 @@ export async function getCanvasUserId(session) { } export async function cashSubmissions(session, courses) { + let streakMult = await getUserProperty(session, "streak"); + if (isNaN(streakMult)) { + await setUserProperty(session, "streak", 0) + streakMult = 0; + } var sum = 0 courses.forEach((course, i) => { var temp = course[3]; @@ -137,15 +142,16 @@ export async function cashSubmissions(session, courses) { const frac = (due - sub) / (due - unlock); multiplier *= Math.min(Math.max((Math.cbrt(frac) + .5), .000000001), 1.5); } + + multiplier *= (1 + streakMult/20); // submission.push(Math.ceil(multiplier * 100)) this works too??? sum += Math.ceil(multiplier * 100); courses[i][3][j].push(Math.ceil(multiplier * 100)) }) }) - - - const results = await updateClasses(session, courses) + + const results = await updateClasses(session, courses); await incrementUserProperty(session, "gems", sum); await updateLastLogin(session); return [courses, sum, results[0], results[1]]; @@ -241,11 +247,21 @@ async function updateClasses(session, courses) { } } - effects.push(effect) + if (effect.result !== undefined) { + effects.push(effect) + } bosses.push([data.courseName, data.courseId, data.users]); } })) + if (effects.length > 0) { + const wonAll = effects.every(effect => effect.result === "win") + if (wonAll) { + await incrementUserProperty(session, "streak", 1) + } else if (effects.some(e => e.result === "lose")) { + await setUserProperty(session, "streak", 0) + } + } return [effects, bosses] } diff --git a/Frontend/src/Home.jsx b/Frontend/src/Home.jsx index deb74b3..4d3c190 100644 --- a/Frontend/src/Home.jsx +++ b/Frontend/src/Home.jsx @@ -42,7 +42,7 @@ function Home({ userData, setUserData, courses, setCourses, bossData, overlay, s
{ overlay == "rewards" ? - + : overlay == "checklist" ? : overlay == "store" ? diff --git a/Frontend/src/Rewards.jsx b/Frontend/src/Rewards.jsx index 2774645..3af6153 100644 --- a/Frontend/src/Rewards.jsx +++ b/Frontend/src/Rewards.jsx @@ -3,7 +3,7 @@ import PropTypes from "prop-types"; import "./css/Rewards.css" import gem from "../src/img/gem.png" -export default function Rewards({ courses, setOverlay }) { +export default function Rewards({ courses, setOverlay, streak }) { const [index, setIndex] = useState(0) const newSubmissions = courses @@ -17,6 +17,7 @@ export default function Rewards({ courses, setOverlay }) { return (

Gems earned:

+

Boss Fight Win Streak: {streak}

{newSubmissions.length != 0 ?
@@ -46,7 +47,7 @@ export default function Rewards({ courses, setOverlay }) {
:

No assignments submitted since last login!

} - +
) } @@ -54,4 +55,5 @@ export default function Rewards({ courses, setOverlay }) { Rewards.propTypes = { courses: PropTypes.object, setOverlay: PropTypes.func, + streak: PropTypes.number } \ No newline at end of file diff --git a/Frontend/src/css/Rewards.css b/Frontend/src/css/Rewards.css index ca59c91..9619569 100644 --- a/Frontend/src/css/Rewards.css +++ b/Frontend/src/css/Rewards.css @@ -36,6 +36,11 @@ margin-top: 5%; } +.rewardsStreak { + color: grey; + margin-top: -0%; +} + .rewardsList { overflow-y: auto; align-items: center;