Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #391: Homes #392

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0ab4534
Fix issue #391: Homes
openhands-agent Feb 21, 2025
90dcf85
Fix pr #392: Fix issue #391: Homes
openhands-agent Feb 21, 2025
c4ba4c7
Fix pr #392: Fix issue #391: Homes
openhands-agent Feb 21, 2025
267f38d
Change user home to object.
Phrosfire Feb 21, 2025
fcc5109
Fix pr #392: Fix issue #391: Homes
openhands-agent Feb 24, 2025
febe83e
Merge branch 'main' into openhands-fix-issue-391
Phrosfire Feb 24, 2025
d1ff4a7
Make userQuests optional
Phrosfire Feb 24, 2025
d9ba9d8
change userQuests requirement
Phrosfire Feb 24, 2025
da0a960
revert profile.ts
Phrosfire Feb 24, 2025
b2989e7
Add home to validators/user.ts
Phrosfire Feb 24, 2025
e5701aa
Add home to profile.ts
Phrosfire Feb 24, 2025
709c99e
made adjustment for if success is false
Phrosfire Feb 25, 2025
63bf556
change user.ryo to user.money
Phrosfire Feb 25, 2025
3a2f313
Changes references from ryo to money
Phrosfire Feb 25, 2025
3a00244
Fix apostrophe causing error
Phrosfire Feb 25, 2025
bc956e0
Create tables for Home
Phrosfire Feb 25, 2025
574f96a
Add regenBonus from home
Phrosfire Feb 25, 2025
61448ba
add hometype to fetchupdateduser
Phrosfire Feb 25, 2025
b86e243
Fix bracket
Phrosfire Feb 25, 2025
832d9c2
Fix another bracket
Phrosfire Feb 25, 2025
d52b521
Fix bracket - Third times the charm?
Phrosfire Feb 25, 2025
78039a0
Add home to fetch
Phrosfire Feb 25, 2025
2023035
fix home structure
Phrosfire Feb 25, 2025
b6ee965
add userQuests
Phrosfire Feb 25, 2025
0ccfa04
add userquest handling
Phrosfire Feb 25, 2025
6558c81
return if user not found
Phrosfire Feb 25, 2025
4c3a5ec
revert profile.ts to working state
Phrosfire Feb 25, 2025
e05241f
Revert anbu.ts to default
Phrosfire Feb 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/drizzle/migrations/0195_add_home_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
CREATE TABLE `HomeType` (
`id` varchar(191) PRIMARY KEY NOT NULL,
`name` varchar(191) NOT NULL,
`regenBonus` int NOT NULL,
`storageSlots` int NOT NULL,
`cost` int NOT NULL,
`createdAt` datetime(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP(3)),
`updatedAt` datetime(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP(3))
);

CREATE TABLE `UserHome` (
`id` varchar(191) PRIMARY KEY NOT NULL,
`userId` varchar(191) NOT NULL,
`homeTypeId` varchar(191) NOT NULL,
`createdAt` datetime(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP(3)),
`updatedAt` datetime(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP(3)),
INDEX `UserHome_userId_idx` (`userId`),
INDEX `UserHome_homeTypeId_idx` (`homeTypeId`)
-- Optionally, add foreign key constraints if desired:
-- FOREIGN KEY (`userId`) REFERENCES `UserData`(`userId`),
-- FOREIGN KEY (`homeTypeId`) REFERENCES `HomeType`(`id`)
);

CREATE TABLE `UserHomeStorage` (
`id` varchar(191) PRIMARY KEY NOT NULL,
`userHomeId` varchar(191) NOT NULL,
`itemId` varchar(191) NOT NULL,
`slot` int NOT NULL,
`createdAt` datetime(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP(3)),
`updatedAt` datetime(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP(3)),
INDEX `UserHomeStorage_userHomeId_idx` (`userHomeId`),
INDEX `UserHomeStorage_slot_idx` (`slot`)
-- Optionally, add a foreign key:
-- FOREIGN KEY (`userHomeId`) REFERENCES `UserHome`(`id`)
);

INSERT INTO `HomeType` (`id`, `name`, `regenBonus`, `storageSlots`, `cost`)
VALUES
('one-bed-apartment', 'One Bed Room Apartment', 20, 5, 3000000),
('studio-apartment', 'Studio Apartment', 30, 10, 7000000),
('two-bed-house', 'Two Bed Room House', 40, 15, 13000000),
('town-house', 'Town House', 50, 20, 30000000),
('small-mansion', 'Small Mansion', 60, 25, 40000000),
('small-estate', 'Small Estate', 70, 30, 50000000),
('large-estate', 'Large Estate', 100, 40, 70000000);
92 changes: 92 additions & 0 deletions app/drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,94 @@ export const bloodlineRollsRelations = relations(bloodlineRolls, ({ one }) => ({
}),
}));

export const homeType = mysqlTable(
"HomeType",
{
id: varchar("id", { length: 191 }).primaryKey().notNull(),
name: varchar("name", { length: 191 }).notNull(),
regenBonus: int("regenBonus").notNull(),
storageSlots: int("storageSlots").notNull(),
cost: bigint("cost", { mode: "number" }).notNull(),
createdAt: datetime("createdAt", { mode: "date", fsp: 3 })
.default(sql`(CURRENT_TIMESTAMP(3))`)
.notNull(),
updatedAt: datetime("updatedAt", { mode: "date", fsp: 3 })
.default(sql`(CURRENT_TIMESTAMP(3))`)
.notNull(),
},
(table) => {
return {
nameKey: uniqueIndex("HomeType_name_key").on(table.name),
};
},
);

export const userHome = mysqlTable(
"UserHome",
{
id: varchar("id", { length: 191 }).primaryKey().notNull(),
userId: varchar("userId", { length: 191 }).notNull(),
homeTypeId: varchar("homeTypeId", { length: 191 }).notNull(),
createdAt: datetime("createdAt", { mode: "date", fsp: 3 })
.default(sql`(CURRENT_TIMESTAMP(3))`)
.notNull(),
updatedAt: datetime("updatedAt", { mode: "date", fsp: 3 })
.default(sql`(CURRENT_TIMESTAMP(3))`)
.notNull(),
},
(table) => {
return {
userIdKey: uniqueIndex("UserHome_userId_key").on(table.userId),
};
},
);

export const userHomeStorage = mysqlTable(
"UserHomeStorage",
{
id: varchar("id", { length: 191 }).primaryKey().notNull(),
userHomeId: varchar("userHomeId", { length: 191 }).notNull(),
itemId: varchar("itemId", { length: 191 }).notNull(),
slot: int("slot").notNull(),
createdAt: datetime("createdAt", { mode: "date", fsp: 3 })
.default(sql`(CURRENT_TIMESTAMP(3))`)
.notNull(),
updatedAt: datetime("updatedAt", { mode: "date", fsp: 3 })
.default(sql`(CURRENT_TIMESTAMP(3))`)
.notNull(),
},
(table) => {
return {
storageKey: uniqueIndex("UserHomeStorage_storage_key").on(
table.userHomeId,
table.slot
),
};
},
);

export const userHomeRelations = relations(userHome, ({ one }) => ({
user: one(userData, {
fields: [userHome.userId],
references: [userData.userId],
}),
homeType: one(homeType, {
fields: [userHome.homeTypeId],
references: [homeType.id],
}),
}));

export const userHomeStorageRelations = relations(userHomeStorage, ({ one }) => ({
userHome: one(userHome, {
fields: [userHomeStorage.userHomeId],
references: [userHome.id],
}),
item: one(item, {
fields: [userHomeStorage.itemId],
references: [item.id],
}),
}));

export const captcha = mysqlTable(
"Captcha",
{
Expand Down Expand Up @@ -1513,6 +1601,10 @@ export const userDataRelations = relations(userData, ({ one, many }) => ({
fields: [userData.userId],
references: [userNindo.userId],
}),
home: one(userHome, {
fields: [userData.userId],
references: [userHome.userId],
}),
userQuests: many(questHistory),
conversations: many(user2conversation),
items: many(userItem),
Expand Down
119 changes: 115 additions & 4 deletions app/src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@ export default function Home() {
const { userData, sectorVillage, access, ownVillage, updateUser } =
useRequireInVillage("/home");

const { data, refetch } = api.home.getHome.useQuery(undefined, {
enabled: !!access && !!ownVillage,
});

const { mutate: upgradeHome, isPending: isUpgrading } =
api.home.upgradeHome.useMutation({
onSuccess: async (data) => {
showMutationToast(data);
if (data.success) {
await refetch();
await updateUser({ home: data.home });
}
},
});

const { mutate: storeItem, isPending: isStoringItem } =
api.home.storeItem.useMutation({
onSuccess: async (data) => {
showMutationToast(data);
if (data.success) {
await refetch();
}
},
});

const { mutate: removeItem, isPending: isRemovingItem } =
api.home.removeItem.useMutation({
onSuccess: async (data) => {
showMutationToast(data);
if (data.success) {
await refetch();
}
},
});

const { mutate: toggleSleep, isPending: isTogglingSleep } =
api.home.toggleSleep.useMutation({
onSuccess: async (data) => {
Expand Down Expand Up @@ -98,13 +133,89 @@ export default function Home() {
<>
<ContentBox
title="Overview"
subtitle="Decorate, upgrade, host parties"
subtitle="Upgrade your home for better regeneration and storage"
initialBreak={true}
>
WIP
<div className="space-y-4">
{data?.home ? (
<div className="text-center">
<h3 className="text-lg font-bold">{data.home.name}</h3>
<p>Regeneration Bonus: +{data.home.regenBonus}</p>
<p>Storage Slots: {data.home.storageSlots}</p>
</div>
) : (
<p className="text-center italic">You don&apos;t own a home yet</p>

)}

<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{data?.availableHomes.map((home) => (
<div
key={home.id}
className={`p-4 border rounded-lg ${
data.home?.id === home.id
? "border-green-500"
: "border-gray-300"
}`}
>
<h4 className="font-bold">{home.name}</h4>
<p>Regeneration: +{home.regenBonus}</p>
<p>Storage: {home.storageSlots} slots</p>
<p>Cost: {home.cost.toLocaleString()} Ryo</p>
{data.home?.id !== home.id && (
<button
className="mt-2 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
onClick={() => upgradeHome({ homeTypeId: home.id })}
disabled={isUpgrading}
>
{isUpgrading ? "Upgrading..." : "Upgrade"}
</button>
)}
</div>
))}
</div>
</div>
</ContentBox>
<ContentBox title="Item Storage" subtitle="Store items" initialBreak={true}>
WIP
<ContentBox
title="Item Storage"
subtitle={`${data?.storage?.length ?? 0}/${
data?.home?.storageSlots ?? 0
} slots used`}
initialBreak={true}
>
{data?.home ? (
<div className="grid grid-cols-5 gap-4">
{Array.from({ length: data.home.storageSlots }).map((_, i) => {
const storedItem = data.storage?.find((s) => s.slot === i);
return (
<div
key={i}
className="aspect-square border border-gray-300 rounded-lg p-2 flex items-center justify-center"
>
{storedItem ? (
<button
className="text-red-500 hover:text-red-600"
onClick={() => removeItem({ slot: i })}
disabled={isRemovingItem}
>
Remove Item
</button>
) : (
<button
className="text-blue-500 hover:text-blue-600"
onClick={() => storeItem({ itemId: "some-item", slot: i })}
disabled={isStoringItem}
>
Store Item
</button>
)}
</div>
);
})}
</div>
) : (
<p className="text-center italic">Purchase a home to store items</p>
)}
</ContentBox>
</>
)}
Expand Down
14 changes: 13 additions & 1 deletion app/src/libs/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,19 @@ export const deduceActiveUserRegen = (
clan?: Clan | null;
bloodline?: Bloodline | null;
village?: (Village & { structures?: VillageStructure[] }) | null;
home?: {
id: string;
name: string;
regenBonus: number;
storageSlots: number;
cost: number;
};
},
settings: GameSetting[],
) => {
let regeneration = user.regeneration;

// // Bloodline
// Bloodline
if (user.bloodline?.regenIncrease) {
regeneration = regeneration + user.bloodline.regenIncrease;
}
Expand All @@ -206,6 +213,11 @@ export const deduceActiveUserRegen = (
regeneration *= 0.5;
}

// Home bonus boost
if (user.status === "ASLEEP" && user.home?.regenBonus) {
regeneration = regeneration + user.home.regenBonus;
}

// Increase by event
const setting = getGameSettingBoost("regenGainMultiplier", settings);
const gameFactor = setting?.value || 1;
Expand Down
Loading