|
| 1 | +import { CraftingRec, ShipCrops } from "@utility/JSON" |
| 2 | +import type { achievementType, cropsShippedType, generalFormatedItemType, itemsCraftedType, maxMonoType } from "types/displayDataTypes" |
| 3 | +import type { itemsType } from "types/savefile" |
| 4 | +import { GetImages, ValidateKnown } from "./Utils" |
| 5 | +import { Monoculture, Polyculture } from "@media/Achievements"; |
| 6 | + |
| 7 | +let CropsAchievements = [{ |
| 8 | + goal: 15, |
| 9 | + image: Monoculture, |
| 10 | + name: 'Monoculture', |
| 11 | + done: false, |
| 12 | + description: 'Ship 15 of each crop', |
| 13 | + hoverDesc: '' |
| 14 | + },{ |
| 15 | + goal: 30, |
| 16 | + image: Polyculture, |
| 17 | + name: 'Polyculture', |
| 18 | + done: false, |
| 19 | + description: 'Ship 300 of one crop', |
| 20 | + hoverDesc: '' |
| 21 | + } |
| 22 | +]; |
| 23 | + |
| 24 | + |
| 25 | +export const GetCropsAchievements = (allShipped: itemsType[]) : cropsShippedType => { |
| 26 | + const poly_crops: generalFormatedItemType[] = [] |
| 27 | + const mono_extras: generalFormatedItemType[] = [] |
| 28 | + let polycultureCount = 0; |
| 29 | + let maxMono: maxMonoType = { name: "undefined", shipped: 0 }; |
| 30 | + |
| 31 | + ShipCrops.forEach(cropItem => { |
| 32 | + const shippedCount = getShippedCount(allShipped, cropItem.id); |
| 33 | + const cropData = createCropData(cropItem, shippedCount); |
| 34 | + |
| 35 | + if (!maxMono || shippedCount > maxMono.shipped) { |
| 36 | + maxMono = { |
| 37 | + name: cropItem.name, |
| 38 | + shipped: shippedCount |
| 39 | + }; |
| 40 | + } |
| 41 | + |
| 42 | + if (cropItem.isPolyCrop) { |
| 43 | + if (shippedCount >= 15) polycultureCount++; |
| 44 | + poly_crops.push(cropData); |
| 45 | + } else { |
| 46 | + mono_extras.push(cropData); |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + if (CropsAchievements[0]) { |
| 51 | + CropsAchievements[0].done = polycultureCount === 28; |
| 52 | + CropsAchievements[0].hoverDesc = |
| 53 | + CropsAchievements[0].done ? |
| 54 | + "You have shipped at least 15 of each polyculture crop" : |
| 55 | + `You have shipped ${polycultureCount} out of 28 polyculture crops at least 15 times`; |
| 56 | + } |
| 57 | + if (CropsAchievements[1]) { |
| 58 | + CropsAchievements[1].done = maxMono ? maxMono?.shipped >= 300 : false; |
| 59 | + CropsAchievements[1].hoverDesc = |
| 60 | + CropsAchievements[1].done ? |
| 61 | + `You have shipped at least 300 of ${maxMono.name}` : |
| 62 | + `You have shipped ${maxMono.shipped} out of 300 required for ${maxMono.name}, your most shipped crop`; |
| 63 | + } |
| 64 | + console.log('CropsAchievements', CropsAchievements); |
| 65 | + return { |
| 66 | + achievements: CropsAchievements, |
| 67 | + poly_crops, |
| 68 | + mono_extras |
| 69 | + }; |
| 70 | +} |
| 71 | + |
| 72 | +const getShippedCount = (allShipped: itemsType[], cropId: number): number => { |
| 73 | + if (!allShipped?.length) return 0; |
| 74 | + const shippedItem = allShipped.find(item => item.key.int === cropId); |
| 75 | + return shippedItem?.value?.int || 0; |
| 76 | +}; |
| 77 | + |
| 78 | +const createCropData = (cropItem: any, shippedCount: number): generalFormatedItemType => ({ |
| 79 | + name: cropItem.name, |
| 80 | + image: GetImages(cropItem.name), |
| 81 | + id: cropItem.id, |
| 82 | + shipped: shippedCount |
| 83 | +}); |
0 commit comments