feat: add perks

This commit is contained in:
2026-06-19 04:01:32 -03:00
parent 44293bc7bc
commit b6fc18edfa
+152 -131
View File
@@ -2,140 +2,161 @@ import { create } from 'zustand';
import { persist } from 'zustand/middleware'; import { persist } from 'zustand/middleware';
export interface InventoryState { export interface InventoryState {
unlockedCharacters: string[]; unlockedCharacters: string[];
unlockedCustomizations: string[]; unlockedCustomizations: string[];
unlockedDLCs: string[]; unlockedDLCs: string[];
items: Record<string, number>; unlockedPerks: string[];
offerings: Record<string, number>; items: Record<string, number>;
offerings: Record<string, number>;
toggleItem: (id: string, category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs') => void; addons: Record<string, number>;
setItemQuantity: (id: string, qty: number) => void;
setOfferingQuantity: (id: string, qty: number) => void; spoofItems: boolean;
spoofPerks: boolean;
unlockAllInCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs', allIds: string[], qty?: number) => void; spoofCatalog: boolean;
clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs') => void; spoofDLCs: boolean;
clearAll: () => void;
importProfile: (profile: any) => void; toggleItem: (id: string, category: 'characters' | 'customizations' | 'items' | 'offerings' | 'addons' | 'dlcs' | 'perks') => void;
setItemQuantity: (id: string, qty: number) => void;
setOfferingQuantity: (id: string, qty: number) => void;
setAddonQuantity: (id: string, qty: number) => void;
setToggle: (key: 'spoofItems' | 'spoofPerks' | 'spoofCatalog' | 'spoofDLCs', val: boolean) => void;
importToggles: (toggles: any) => void;
unlockAllInCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'addons' | 'dlcs' | 'perks', allIds: string[], qty?: number) => void;
clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'addons' | 'dlcs' | 'perks') => void;
clearAll: () => void;
importProfile: (profile: any) => void;
} }
export const useInventoryStore = create<InventoryState>()( export const useInventoryStore = create<InventoryState>()(
persist( persist(
(set) => ({ (set) => ({
unlockedCharacters: [], unlockedCharacters: [],
unlockedCustomizations: [], unlockedCustomizations: [],
unlockedDLCs: [], unlockedDLCs: [],
items: {}, unlockedPerks: [],
offerings: {}, items: {},
offerings: {},
addons: {},
toggleItem: (id, category) => set((state) => { spoofItems: false,
if (category === 'characters') { spoofPerks: false,
const arr = state.unlockedCharacters; spoofCatalog: false,
return { spoofDLCs: false,
unlockedCharacters: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id]
}; setToggle: (key, val) => set({ [key]: val }),
} else if (category === 'customizations') {
const arr = state.unlockedCustomizations; importToggles: (toggles) => set((state) => {
return { if (!toggles) return {};
unlockedCustomizations: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] return {
}; spoofItems: typeof toggles.spoofItems === 'boolean' ? toggles.spoofItems : state.spoofItems,
} else if (category === 'dlcs') { spoofPerks: typeof toggles.spoofPerks === 'boolean' ? toggles.spoofPerks : state.spoofPerks,
const arr = state.unlockedDLCs; spoofCatalog: typeof toggles.spoofCatalog === 'boolean' ? toggles.spoofCatalog : state.spoofCatalog,
return { spoofDLCs: typeof toggles.spoofDLCs === 'boolean' ? toggles.spoofDLCs : state.spoofDLCs,
unlockedDLCs: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
}; }),
} else if (category === 'items') {
const current = state.items[id] || 0; toggleItem: (id, category) => set((state) => {
const newItems = { ...state.items }; if (category === 'characters') {
if (current > 0) { const arr = state.unlockedCharacters;
delete newItems[id]; return { unlockedCharacters: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
} else { } else if (category === 'customizations') {
newItems[id] = 100; const arr = state.unlockedCustomizations;
} return { unlockedCustomizations: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
return { items: newItems }; } else if (category === 'dlcs') {
} else { const arr = state.unlockedDLCs;
const current = state.offerings[id] || 0; return { unlockedDLCs: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
const newOfferings = { ...state.offerings }; } else if (category === 'perks') {
if (current > 0) { const arr = state.unlockedPerks;
delete newOfferings[id]; return { unlockedPerks: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
} else { } else if (category === 'items') {
newOfferings[id] = 100; const newItems = { ...state.items };
} if ((newItems[id] || 0) > 0) delete newItems[id]; else newItems[id] = 100;
return { offerings: newOfferings }; return { items: newItems };
} else if (category === 'addons') {
const newAddons = { ...state.addons };
if ((newAddons[id] || 0) > 0) delete newAddons[id]; else newAddons[id] = 100;
return { addons: newAddons };
} else {
const newOfferings = { ...state.offerings };
if ((newOfferings[id] || 0) > 0) delete newOfferings[id]; else newOfferings[id] = 100;
return { offerings: newOfferings };
}
}),
setItemQuantity: (id, qty) => set((state) => {
const newItems = { ...state.items };
if (qty <= 0) delete newItems[id]; else newItems[id] = Math.min(32767, Math.max(0, qty));
return { items: newItems };
}),
setOfferingQuantity: (id, qty) => set((state) => {
const newOfferings = { ...state.offerings };
if (qty <= 0) delete newOfferings[id]; else newOfferings[id] = Math.min(32767, Math.max(0, qty));
return { offerings: newOfferings };
}),
setAddonQuantity: (id, qty) => set((state) => {
const newAddons = { ...state.addons };
if (qty <= 0) delete newAddons[id]; else newAddons[id] = Math.min(32767, Math.max(0, qty));
return { addons: newAddons };
}),
unlockAllInCategory: (category, allIds, qty = 100) => set((state) => {
if (category === 'characters') return { unlockedCharacters: allIds };
if (category === 'customizations') return { unlockedCustomizations: allIds };
if (category === 'dlcs') return { unlockedDLCs: allIds };
if (category === 'perks') return { unlockedPerks: allIds };
if (category === 'items') {
const newItems = { ...state.items };
allIds.forEach(id => { newItems[id] = qty; });
return { items: newItems };
} else if (category === 'addons') {
const newAddons = { ...state.addons };
allIds.forEach(id => { newAddons[id] = qty; });
return { addons: newAddons };
} else {
const newOfferings = { ...state.offerings };
allIds.forEach(id => { newOfferings[id] = qty; });
return { offerings: newOfferings };
}
}),
clearCategory: (category) => set(() => {
if (category === 'characters') return { unlockedCharacters: [] };
if (category === 'customizations') return { unlockedCustomizations: [] };
if (category === 'dlcs') return { unlockedDLCs: [] };
if (category === 'perks') return { unlockedPerks: [] };
if (category === 'items') return { items: {} };
if (category === 'addons') return { addons: {} };
return { offerings: {} };
}),
clearAll: () => set({
unlockedCharacters: [],
unlockedCustomizations: [],
unlockedDLCs: [],
unlockedPerks: [],
items: {},
offerings: {},
addons: {},
}),
importProfile: (profile) => set((state) => {
if (!profile) return {};
return {
unlockedCharacters: Array.isArray(profile.unlockedCharacters) ? profile.unlockedCharacters : state.unlockedCharacters,
unlockedCustomizations: Array.isArray(profile.unlockedCustomizations) ? profile.unlockedCustomizations : state.unlockedCustomizations,
unlockedDLCs: Array.isArray(profile.unlockedDLCs) ? profile.unlockedDLCs : state.unlockedDLCs,
unlockedPerks: Array.isArray(profile.unlockedPerks) ? profile.unlockedPerks : state.unlockedPerks,
items: (profile.items && typeof profile.items === 'object') ? profile.items : state.items,
offerings: (profile.offerings && typeof profile.offerings === 'object') ? profile.offerings : state.offerings,
addons: (profile.addons && typeof profile.addons === 'object') ? profile.addons : state.addons,
};
})
}),
{
name: 'hex-unlocked-inventory',
} }
}), )
setItemQuantity: (id, qty) => set((state) => {
const newItems = { ...state.items };
if (qty <= 0) {
delete newItems[id];
} else {
newItems[id] = Math.min(32767, Math.max(0, qty));
}
return { items: newItems };
}),
setOfferingQuantity: (id, qty) => set((state) => {
const newOfferings = { ...state.offerings };
if (qty <= 0) {
delete newOfferings[id];
} else {
newOfferings[id] = Math.min(32767, Math.max(0, qty));
}
return { offerings: newOfferings };
}),
unlockAllInCategory: (category, allIds, qty = 100) => set((state) => {
if (category === 'characters') {
return { unlockedCharacters: allIds };
} else if (category === 'customizations') {
return { unlockedCustomizations: allIds };
} else if (category === 'dlcs') {
return { unlockedDLCs: allIds };
} else if (category === 'items') {
const newItems = { ...state.items };
allIds.forEach(id => {
newItems[id] = qty;
});
return { items: newItems };
} else {
const newOfferings = { ...state.offerings };
allIds.forEach(id => {
newOfferings[id] = qty;
});
return { offerings: newOfferings };
}
}),
clearCategory: (category) => set((state) => {
if (category === 'characters') return { unlockedCharacters: [] };
if (category === 'customizations') return { unlockedCustomizations: [] };
if (category === 'dlcs') return { unlockedDLCs: [] };
if (category === 'items') return { items: {} };
return { offerings: {} };
}),
clearAll: () => set({
unlockedCharacters: [],
unlockedCustomizations: [],
unlockedDLCs: [],
items: {},
offerings: {},
}),
importProfile: (profile) => set((state) => {
if (!profile) return {};
return {
unlockedCharacters: Array.isArray(profile.unlockedCharacters) ? profile.unlockedCharacters : state.unlockedCharacters,
unlockedCustomizations: Array.isArray(profile.unlockedCustomizations) ? profile.unlockedCustomizations : state.unlockedCustomizations,
unlockedDLCs: Array.isArray(profile.unlockedDLCs) ? profile.unlockedDLCs : state.unlockedDLCs,
items: (profile.items && typeof profile.items === 'object') ? profile.items : state.items,
offerings: (profile.offerings && typeof profile.offerings === 'object') ? profile.offerings : state.offerings,
};
})
}),
{
name: 'hex-unlocked-inventory',
}
)
); );