From ed78c30c625ac9cbead46466d0a35599cb7220db Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Sun, 21 Apr 2024 12:53:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=81=F0=9F=90=AC=20=E2=86=9D=20[SGV2-7?= =?UTF-8?q?=20SGV2-21]:=20Calculating=20rewards=20for=20rover=20deployment?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Content/Archive/ArchivedInventory.tsx | 2 +- components/Gameplay/Automatons/BuildRover.tsx | 10 +- .../Vehicles/MySpaceships.tsx | 0 components/Gameplay/Explore/CollectItem.tsx | 103 ++++++++++++++++++ 4 files changed, 109 insertions(+), 6 deletions(-) rename components/Gameplay/{ => Automatons}/Vehicles/MySpaceships.tsx (100%) create mode 100644 components/Gameplay/Explore/CollectItem.tsx diff --git a/components/Content/Archive/ArchivedInventory.tsx b/components/Content/Archive/ArchivedInventory.tsx index 4dc64b8b..a87c70b1 100644 --- a/components/Content/Archive/ArchivedInventory.tsx +++ b/components/Content/Archive/ArchivedInventory.tsx @@ -3,7 +3,7 @@ import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react"; import Layout from "../../_Core/Section/Layout"; import OwnedPlanetsList from "./UserOwnedPlanets"; // Potentially this should be in a lists component dir import OwnedItemsList from "../Inventory/UserOwnedItems"; -import MySpaceships from "../../Gameplay/Vehicles/MySpaceships"; +import MySpaceships from "../../Gameplay/Automatons/Vehicles/MySpaceships"; export default function V1Inventory() { // Inventory items for v1 of public schema, see notes below const supabase = useSupabaseClient(); diff --git a/components/Gameplay/Automatons/BuildRover.tsx b/components/Gameplay/Automatons/BuildRover.tsx index 55d27471..36e07432 100644 --- a/components/Gameplay/Automatons/BuildRover.tsx +++ b/components/Gameplay/Automatons/BuildRover.tsx @@ -105,7 +105,7 @@ export function ViewRovers() { if (!session || !session.user || !session.user.id) { console.log("User session not available"); return; - } + }; setIsLoading(true); @@ -117,7 +117,7 @@ export function ViewRovers() { if (userRoversError) { throw userRoversError; - } + }; if (userRovers && userRovers.length > 0) { setUserRovers(userRovers); @@ -132,7 +132,7 @@ export function ViewRovers() { }; } else { setUserRovers([]); - } + }; } catch (error) { console.error("Error fetching rovers:", error.message); } finally { @@ -151,7 +151,7 @@ export function ViewRovers() { // If the component is loading, you can display a loading indicator or message if (isLoading) { return
Loading...
; - } + }; // Render the list of rovers return ( @@ -169,4 +169,4 @@ export function ViewRovers() { ))} ); -} +}; \ No newline at end of file diff --git a/components/Gameplay/Vehicles/MySpaceships.tsx b/components/Gameplay/Automatons/Vehicles/MySpaceships.tsx similarity index 100% rename from components/Gameplay/Vehicles/MySpaceships.tsx rename to components/Gameplay/Automatons/Vehicles/MySpaceships.tsx diff --git a/components/Gameplay/Explore/CollectItem.tsx b/components/Gameplay/Explore/CollectItem.tsx new file mode 100644 index 00000000..9f026e86 --- /dev/null +++ b/components/Gameplay/Explore/CollectItem.tsx @@ -0,0 +1,103 @@ +import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react" +import React, { useEffect, useState } from "react" +import { ViewRovers } from "../Automatons/BuildRover"; + +export default function CollectItemFromSector() { + const supabase = useSupabaseClient(); + const session = useSession(); + + const [userSectors, setUserSectors] = useState([]); + const [selectedSector, setSelectedSector] = useState(null); + const [selectedRover, setSelectedRover] = useState(null); + const [timeOfDeploy, setTimeOfDeploy] = useState(null); + const [isDeployed, setIsDeployed] = useState(false); + const [reward, setReward] = useState(0); + + useEffect(() => { + fetchUserSectors(); + }, [session]); + + const fetchUserSectors = async () => { + try { + const { data, error } = await supabase + .from("basePlanetSectors") + .select("*") + .eq("owner", session?.user?.id); + + if (error) { + throw error; + } + + if (data) { + setUserSectors(data); + } + } catch (error) { + console.error("Error fetching user sectors:", error.message); + } + }; + + const handleSectorSelect = (sector: any) => { + setSelectedSector(sector); + }; + + const handleRoverSelect = (rover: any) => { + setSelectedRover(rover); + }; + + const deployRover = () => { + // Set the time of deployment to the current time + setTimeOfDeploy(new Date()); + setIsDeployed(true); + }; + + const calculateReward = () => { + // Calculate the time difference between the current time and the time of deployment + if (timeOfDeploy) { + const currentTime = new Date(); + const timeDifference = currentTime.getTime() - timeOfDeploy.getTime(); + // Convert milliseconds to hours + const hoursDeployed = timeDifference / (1000 * 60 * 60); + // For now, let's say 1 item per hour + setReward(Math.min(Math.floor(hoursDeployed), 6)); + } + }; + + const collectReward = () => { + // Here you can add the reward to the user's inventory + // For now, let's just log the reward + console.log("Collected reward:", reward); + }; + + return ( +
+

Collect Item from Sector

+

User Sectors

+
    + {userSectors.map(sector => ( +
  • handleSectorSelect(sector)}> + {sector.id} - {sector.name} - {sector.deposit} +
  • + ))} +
+

Selected Sector

+ {selectedSector && ( +
+

ID: {selectedSector.id}

+

Name: {selectedSector.name}

+

Deposit: {selectedSector.deposit}

+
+ )} +

Deploy Rover

+ + +

Reward

+ {isDeployed && ( +
+

Reward: {reward}

+ + +
+ )} +
+ ); +} \ No newline at end of file