feat: add perks

This commit is contained in:
2026-06-19 04:01:32 -03:00
parent 44293bc7bc
commit b6fc18edfa
+69 -48
View File
@@ -5,15 +5,25 @@ export interface InventoryState {
unlockedCharacters: string[]; unlockedCharacters: string[];
unlockedCustomizations: string[]; unlockedCustomizations: string[];
unlockedDLCs: string[]; unlockedDLCs: string[];
unlockedPerks: string[];
items: Record<string, number>; items: Record<string, number>;
offerings: Record<string, number>; offerings: Record<string, number>;
addons: Record<string, number>;
toggleItem: (id: string, category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs') => void; spoofItems: boolean;
spoofPerks: boolean;
spoofCatalog: boolean;
spoofDLCs: boolean;
toggleItem: (id: string, category: 'characters' | 'customizations' | 'items' | 'offerings' | 'addons' | 'dlcs' | 'perks') => void;
setItemQuantity: (id: string, qty: number) => void; setItemQuantity: (id: string, qty: number) => void;
setOfferingQuantity: (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' | 'dlcs', allIds: string[], qty?: number) => void; unlockAllInCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'addons' | 'dlcs' | 'perks', allIds: string[], qty?: number) => void;
clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs') => void; clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'addons' | 'dlcs' | 'perks') => void;
clearAll: () => void; clearAll: () => void;
importProfile: (profile: any) => void; importProfile: (profile: any) => void;
} }
@@ -24,94 +34,101 @@ export const useInventoryStore = create<InventoryState>()(
unlockedCharacters: [], unlockedCharacters: [],
unlockedCustomizations: [], unlockedCustomizations: [],
unlockedDLCs: [], unlockedDLCs: [],
unlockedPerks: [],
items: {}, items: {},
offerings: {}, offerings: {},
addons: {},
spoofItems: false,
spoofPerks: false,
spoofCatalog: false,
spoofDLCs: false,
setToggle: (key, val) => set({ [key]: val }),
importToggles: (toggles) => set((state) => {
if (!toggles) return {};
return {
spoofItems: typeof toggles.spoofItems === 'boolean' ? toggles.spoofItems : state.spoofItems,
spoofPerks: typeof toggles.spoofPerks === 'boolean' ? toggles.spoofPerks : state.spoofPerks,
spoofCatalog: typeof toggles.spoofCatalog === 'boolean' ? toggles.spoofCatalog : state.spoofCatalog,
spoofDLCs: typeof toggles.spoofDLCs === 'boolean' ? toggles.spoofDLCs : state.spoofDLCs,
};
}),
toggleItem: (id, category) => set((state) => { toggleItem: (id, category) => set((state) => {
if (category === 'characters') { if (category === 'characters') {
const arr = state.unlockedCharacters; const arr = state.unlockedCharacters;
return { return { unlockedCharacters: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
unlockedCharacters: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id]
};
} else if (category === 'customizations') { } else if (category === 'customizations') {
const arr = state.unlockedCustomizations; const arr = state.unlockedCustomizations;
return { return { unlockedCustomizations: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
unlockedCustomizations: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id]
};
} else if (category === 'dlcs') { } else if (category === 'dlcs') {
const arr = state.unlockedDLCs; const arr = state.unlockedDLCs;
return { return { unlockedDLCs: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
unlockedDLCs: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] } else if (category === 'perks') {
}; const arr = state.unlockedPerks;
return { unlockedPerks: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] };
} else if (category === 'items') { } else if (category === 'items') {
const current = state.items[id] || 0;
const newItems = { ...state.items }; const newItems = { ...state.items };
if (current > 0) { if ((newItems[id] || 0) > 0) delete newItems[id]; else newItems[id] = 100;
delete newItems[id];
} else {
newItems[id] = 100;
}
return { items: newItems }; 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 { } else {
const current = state.offerings[id] || 0;
const newOfferings = { ...state.offerings }; const newOfferings = { ...state.offerings };
if (current > 0) { if ((newOfferings[id] || 0) > 0) delete newOfferings[id]; else newOfferings[id] = 100;
delete newOfferings[id];
} else {
newOfferings[id] = 100;
}
return { offerings: newOfferings }; return { offerings: newOfferings };
} }
}), }),
setItemQuantity: (id, qty) => set((state) => { setItemQuantity: (id, qty) => set((state) => {
const newItems = { ...state.items }; const newItems = { ...state.items };
if (qty <= 0) { if (qty <= 0) delete newItems[id]; else newItems[id] = Math.min(32767, Math.max(0, qty));
delete newItems[id];
} else {
newItems[id] = Math.min(32767, Math.max(0, qty));
}
return { items: newItems }; return { items: newItems };
}), }),
setOfferingQuantity: (id, qty) => set((state) => { setOfferingQuantity: (id, qty) => set((state) => {
const newOfferings = { ...state.offerings }; const newOfferings = { ...state.offerings };
if (qty <= 0) { if (qty <= 0) delete newOfferings[id]; else newOfferings[id] = Math.min(32767, Math.max(0, qty));
delete newOfferings[id];
} else {
newOfferings[id] = Math.min(32767, Math.max(0, qty));
}
return { offerings: newOfferings }; 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) => { unlockAllInCategory: (category, allIds, qty = 100) => set((state) => {
if (category === 'characters') { if (category === 'characters') return { unlockedCharacters: allIds };
return { unlockedCharacters: allIds }; if (category === 'customizations') return { unlockedCustomizations: allIds };
} else if (category === 'customizations') { if (category === 'dlcs') return { unlockedDLCs: allIds };
return { unlockedCustomizations: allIds }; if (category === 'perks') return { unlockedPerks: allIds };
} else if (category === 'dlcs') { if (category === 'items') {
return { unlockedDLCs: allIds };
} else if (category === 'items') {
const newItems = { ...state.items }; const newItems = { ...state.items };
allIds.forEach(id => { allIds.forEach(id => { newItems[id] = qty; });
newItems[id] = qty;
});
return { items: newItems }; return { items: newItems };
} else if (category === 'addons') {
const newAddons = { ...state.addons };
allIds.forEach(id => { newAddons[id] = qty; });
return { addons: newAddons };
} else { } else {
const newOfferings = { ...state.offerings }; const newOfferings = { ...state.offerings };
allIds.forEach(id => { allIds.forEach(id => { newOfferings[id] = qty; });
newOfferings[id] = qty;
});
return { offerings: newOfferings }; return { offerings: newOfferings };
} }
}), }),
clearCategory: (category) => set((state) => { clearCategory: (category) => set(() => {
if (category === 'characters') return { unlockedCharacters: [] }; if (category === 'characters') return { unlockedCharacters: [] };
if (category === 'customizations') return { unlockedCustomizations: [] }; if (category === 'customizations') return { unlockedCustomizations: [] };
if (category === 'dlcs') return { unlockedDLCs: [] }; if (category === 'dlcs') return { unlockedDLCs: [] };
if (category === 'perks') return { unlockedPerks: [] };
if (category === 'items') return { items: {} }; if (category === 'items') return { items: {} };
if (category === 'addons') return { addons: {} };
return { offerings: {} }; return { offerings: {} };
}), }),
@@ -119,8 +136,10 @@ export const useInventoryStore = create<InventoryState>()(
unlockedCharacters: [], unlockedCharacters: [],
unlockedCustomizations: [], unlockedCustomizations: [],
unlockedDLCs: [], unlockedDLCs: [],
unlockedPerks: [],
items: {}, items: {},
offerings: {}, offerings: {},
addons: {},
}), }),
importProfile: (profile) => set((state) => { importProfile: (profile) => set((state) => {
@@ -129,8 +148,10 @@ export const useInventoryStore = create<InventoryState>()(
unlockedCharacters: Array.isArray(profile.unlockedCharacters) ? profile.unlockedCharacters : state.unlockedCharacters, unlockedCharacters: Array.isArray(profile.unlockedCharacters) ? profile.unlockedCharacters : state.unlockedCharacters,
unlockedCustomizations: Array.isArray(profile.unlockedCustomizations) ? profile.unlockedCustomizations : state.unlockedCustomizations, unlockedCustomizations: Array.isArray(profile.unlockedCustomizations) ? profile.unlockedCustomizations : state.unlockedCustomizations,
unlockedDLCs: Array.isArray(profile.unlockedDLCs) ? profile.unlockedDLCs : state.unlockedDLCs, 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, items: (profile.items && typeof profile.items === 'object') ? profile.items : state.items,
offerings: (profile.offerings && typeof profile.offerings === 'object') ? profile.offerings : state.offerings, offerings: (profile.offerings && typeof profile.offerings === 'object') ? profile.offerings : state.offerings,
addons: (profile.addons && typeof profile.addons === 'object') ? profile.addons : state.addons,
}; };
}) })
}), }),