-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathsocial.ts
More file actions
153 lines (134 loc) · 4.66 KB
/
social.ts
File metadata and controls
153 lines (134 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import villagers from "@/data/villagers.json";
export function findChildren(
SaveGame: any
): Map<string, number> {
// for now we only care about the number of children, may have to adjust
// if we want to include names for some reason
let children: Map<string, number> = new Map();
try {
// loop through every game location looking for children
for (const location of SaveGame.locations.GameLocation) {
// check if location has characters
if (!location.characters) continue;
// check multiple characters in location
if (Array.isArray(location.characters.NPC)) {
// multiple characters in location
for (const NPC of location.characters.NPC) {
if (!Object.keys(NPC).some(e => e.endsWith(':type'))) continue;
if (Object.entries(NPC).some(([k, v]) => k.endsWith(':type') && v == 'Child')) {
// found a child, increment count, or add to map if not present
children.set(
NPC.idOfParent,
(children.get(NPC.idOfParent) ?? 0) + 1
);
}
}
} else {
// only one character in location, check if it's a child
let NPC = location.characters.NPC;
if (Object.entries(NPC).some(([k, v]) => k.endsWith(':type') && v == 'Child')) {
// found a child, increment count, or add to map if not present
children.set(NPC.idOfParent, (children.get(NPC.idOfParent) ?? 0) + 1);
}
}
}
} catch (err) {
if (err instanceof Error)
throw new Error(`Error in findChildren: ${err.message}`);
throw new Error(`Error in findChildren: ${err}`);
}
return children;
}
interface Relationship {
points: number;
status?: string;
}
export interface SocialRet {
childrenCount?: number;
houseUpgradeLevel?: number;
spouse?: string | null;
relationships: { [key: string]: Relationship };
}
export function parseSocial(
player: any,
children: Map<string, number>,
farmerFriendships?: any
): SocialRet {
/*
Achievements Relevant:
- Moving Up (house upgrade #1).
- Living Large (house upgrade #2).
- Full House (married + 2 kids).
- A New Friend (5 hearts with any NPC).
- Cliques (5 hearts with 4 NPCs).
- Networking (5 hearts with 10 NPCs).
- Popular (5 hearts with 20 NPCs).
- Best Friends (10 hearts with any NPC).
- The Beloved Farmer (10 hearts with 8 NPCs).
*/
if (farmerFriendships) {
if (Array.isArray(farmerFriendships.item)) {
for (const idx in farmerFriendships.item) {
if (farmerFriendships.item[idx].value.Friendship.Status === "Married") {
player.spouse = "Other player";
}
}
} else {
if (farmerFriendships.item.value.Friendship.Status === "Married") {
player.spouse = "Other player";
}
}
}
let childrenCount = 0;
let relationships: { [key: string]: Relationship } = {};
let houseUpgradeLevel: number = player.houseUpgradeLevel;
let spouse = player.spouse ? player.spouse : undefined;
// look up the number of children by UniqueMultiplayerID if it exists in children map
childrenCount = children.get(player.UniqueMultiplayerID) ?? 0;
// loop through friendshipData to find relationships
if (!player.friendshipData) {
return {
childrenCount,
houseUpgradeLevel,
spouse,
relationships,
};
}
if (Array.isArray(player.friendshipData.item)) {
// multiple relationships
for (const idx in player.friendshipData.item) {
const relationship = player.friendshipData.item[idx];
const name = relationship.key.string;
// check if NPC is a valid NPC
if (!(name in villagers)) continue;
// TODO: if we need to check children, we can do it here
const friendshipPoints = relationship.value.Friendship.Points;
const status = relationship.value.Friendship.Status;
if (status === "Married" || status === "Dating") {
relationships[name] = { points: friendshipPoints, status };
} else {
relationships[name] = { points: friendshipPoints };
}
}
} else {
// only one relationship
const relationship = player.friendshipData.item;
const name = relationship.key.string;
// check if NPC is a valid NPC
if (name in villagers) {
const friendshipPoints = relationship.value.Friendship.Points;
const status = relationship.value.Friendship.Status;
if (status === "Married" || status === "Dating") {
relationships[name] = { points: friendshipPoints, status };
} else {
relationships[name] = { points: friendshipPoints };
}
}
}
return {
childrenCount,
houseUpgradeLevel,
spouse,
relationships,
};
}