Skip to content

Commit

Permalink
πŸͺπŸ¬ ↝ [SGV2-7 SGV2-21]: Calculating rewards for rover deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Apr 24, 2024
1 parent 3614c97 commit ed78c30
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/Content/Archive/ArchivedInventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions components/Gameplay/Automatons/BuildRover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function ViewRovers() {
if (!session || !session.user || !session.user.id) {
console.log("User session not available");
return;
}
};

setIsLoading(true);

Expand All @@ -117,7 +117,7 @@ export function ViewRovers() {

if (userRoversError) {
throw userRoversError;
}
};

if (userRovers && userRovers.length > 0) {
setUserRovers(userRovers);
Expand All @@ -132,7 +132,7 @@ export function ViewRovers() {
};
} else {
setUserRovers([]);
}
};
} catch (error) {
console.error("Error fetching rovers:", error.message);
} finally {
Expand All @@ -151,7 +151,7 @@ export function ViewRovers() {
// If the component is loading, you can display a loading indicator or message
if (isLoading) {
return <div>Loading...</div>;
}
};

// Render the list of rovers
return (
Expand All @@ -169,4 +169,4 @@ export function ViewRovers() {
))}
</div>
);
}
};
103 changes: 103 additions & 0 deletions components/Gameplay/Explore/CollectItem.tsx
Original file line number Diff line number Diff line change
@@ -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<any[]>([]);
const [selectedSector, setSelectedSector] = useState<any>(null);
const [selectedRover, setSelectedRover] = useState<any>(null);
const [timeOfDeploy, setTimeOfDeploy] = useState<Date | null>(null);
const [isDeployed, setIsDeployed] = useState<boolean>(false);
const [reward, setReward] = useState<number>(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 (
<div>
<h1>Collect Item from Sector</h1>
<h2>User Sectors</h2>
<ul>
{userSectors.map(sector => (
<li key={sector.id} onClick={() => handleSectorSelect(sector)}>
{sector.id} - {sector.name} - {sector.deposit}
</li>
))}
</ul>
<h2>Selected Sector</h2>
{selectedSector && (
<div>
<p>ID: {selectedSector.id}</p>
<p>Name: {selectedSector.name}</p>
<p>Deposit: {selectedSector.deposit}</p>
</div>
)}
<h2>Deploy Rover</h2>
<ViewRovers onRoverSelect={handleRoverSelect} />
<button onClick={deployRover}>Deploy Rover</button>
<h2>Reward</h2>
{isDeployed && (
<div>
<p>Reward: {reward}</p>
<button onClick={calculateReward}>Calculate Reward</button>
<button onClick={collectReward}>Collect Reward</button>
</div>
)}
</div>
);
}

0 comments on commit ed78c30

Please sign in to comment.