Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AchievementsHelper.cs
Go to the documentation of this file.
2
4{
5 public delegate void ItemPickupEvent(Player player, short itemId, int count);
6
7 public delegate void ItemCraftEvent(short itemId, int count);
8
9 public delegate void TileDestroyedEvent(Player player, ushort tileId);
10
11 public delegate void NPCKilledEvent(Player player, short npcId);
12
13 public delegate void ProgressionEventEvent(int eventID);
14
15 private static bool _isMining;
16
17 private static bool mayhemOK;
18
19 private static bool mayhem1down;
20
21 private static bool mayhem2down;
22
23 private static bool mayhem3down;
24
25 public static bool CurrentlyMining
26 {
27 get
28 {
29 return _isMining;
30 }
31 set
32 {
33 _isMining = value;
34 }
35 }
36
37 public static event ItemPickupEvent OnItemPickup;
38
39 public static event ItemCraftEvent OnItemCraft;
40
42
43 public static event NPCKilledEvent OnNPCKilled;
44
46
47 public static void NotifyTileDestroyed(Player player, ushort tile)
48 {
50 {
52 }
53 }
54
55 public static void NotifyItemPickup(Player player, Item item)
56 {
58 {
59 AchievementsHelper.OnItemPickup(player, (short)item.netID, item.stack);
60 }
61 }
62
63 public static void NotifyItemPickup(Player player, Item item, int customStack)
64 {
66 {
67 AchievementsHelper.OnItemPickup(player, (short)item.netID, customStack);
68 }
69 }
70
71 public static void NotifyItemCraft(Recipe recipe)
72 {
74 {
76 }
77 }
78
79 public static void Initialize()
80 {
81 Player.Hooks.OnEnterWorld += OnPlayerEnteredWorld;
82 }
83
84 internal static void OnPlayerEnteredWorld(Player player)
85 {
87 {
88 for (int i = 0; i < 58; i++)
89 {
90 AchievementsHelper.OnItemPickup(player, (short)player.inventory[i].type, player.inventory[i].stack);
91 }
92 for (int j = 0; j < player.armor.Length; j++)
93 {
94 AchievementsHelper.OnItemPickup(player, (short)player.armor[j].type, player.armor[j].stack);
95 }
96 for (int k = 0; k < player.dye.Length; k++)
97 {
98 AchievementsHelper.OnItemPickup(player, (short)player.dye[k].type, player.dye[k].stack);
99 }
100 for (int l = 0; l < player.miscEquips.Length; l++)
101 {
102 AchievementsHelper.OnItemPickup(player, (short)player.miscEquips[l].type, player.miscEquips[l].stack);
103 }
104 for (int m = 0; m < player.miscDyes.Length; m++)
105 {
106 AchievementsHelper.OnItemPickup(player, (short)player.miscDyes[m].type, player.miscDyes[m].stack);
107 }
108 for (int n = 0; n < player.bank.item.Length; n++)
109 {
110 AchievementsHelper.OnItemPickup(player, (short)player.bank.item[n].type, player.bank.item[n].stack);
111 }
112 for (int num = 0; num < player.bank2.item.Length; num++)
113 {
114 AchievementsHelper.OnItemPickup(player, (short)player.bank2.item[num].type, player.bank2.item[num].stack);
115 }
116 for (int num2 = 0; num2 < player.bank3.item.Length; num2++)
117 {
118 AchievementsHelper.OnItemPickup(player, (short)player.bank3.item[num2].type, player.bank3.item[num2].stack);
119 }
120 for (int num3 = 0; num3 < player.bank4.item.Length; num3++)
121 {
122 AchievementsHelper.OnItemPickup(player, (short)player.bank4.item[num3].type, player.bank4.item[num3].stack);
123 }
124 for (int num4 = 0; num4 < player.Loadouts.Length; num4++)
125 {
126 Item[] armor = player.Loadouts[num4].Armor;
127 for (int num5 = 0; num5 < armor.Length; num5++)
128 {
129 AchievementsHelper.OnItemPickup(player, (short)armor[num5].type, armor[num5].stack);
130 }
131 armor = player.Loadouts[num4].Dye;
132 for (int num6 = 0; num6 < armor.Length; num6++)
133 {
134 AchievementsHelper.OnItemPickup(player, (short)armor[num6].type, armor[num6].stack);
135 }
136 }
137 }
138 if (player.statManaMax > 20)
139 {
140 Main.Achievements.GetCondition("STAR_POWER", "Use").Complete();
141 }
142 if (player.statLifeMax == 500 && player.statManaMax == 200)
143 {
144 Main.Achievements.GetCondition("TOPPED_OFF", "Use").Complete();
145 }
146 if (player.miscEquips[4].type > 0)
147 {
148 Main.Achievements.GetCondition("HOLD_ON_TIGHT", "Equip").Complete();
149 }
150 if (player.miscEquips[3].type > 0)
151 {
152 Main.Achievements.GetCondition("THE_CAVALRY", "Equip").Complete();
153 }
154 for (int num7 = 0; num7 < player.armor.Length; num7++)
155 {
156 if (player.armor[num7].wingSlot > 0)
157 {
158 Main.Achievements.GetCondition("HEAD_IN_THE_CLOUDS", "Equip").Complete();
159 break;
160 }
161 }
162 if (player.armor[0].stack > 0 && player.armor[1].stack > 0 && player.armor[2].stack > 0)
163 {
164 Main.Achievements.GetCondition("MATCHING_ATTIRE", "Equip").Complete();
165 }
166 if (player.armor[10].stack > 0 && player.armor[11].stack > 0 && player.armor[12].stack > 0)
167 {
168 Main.Achievements.GetCondition("FASHION_STATEMENT", "Equip").Complete();
169 }
170 bool flag = true;
171 for (int num8 = 0; num8 < 10; num8++)
172 {
173 if (player.IsItemSlotUnlockedAndUsable(num8) && (player.dye[num8].type < 1 || player.dye[num8].stack < 1))
174 {
175 flag = false;
176 }
177 }
178 if (flag)
179 {
180 Main.Achievements.GetCondition("DYE_HARD", "Equip").Complete();
181 }
182 if (player.unlockedBiomeTorches)
183 {
184 Main.Achievements.GetCondition("GAIN_TORCH_GODS_FAVOR", "Use").Complete();
185 }
187 }
188
189 public static void NotifyNPCKilled(NPC npc)
190 {
191 if (Main.netMode == 0)
192 {
194 {
196 }
197 return;
198 }
199 for (int i = 0; i < 255; i++)
200 {
201 if (npc.playerInteraction[i])
202 {
203 NetMessage.SendData(97, i, -1, null, npc.netID);
204 }
205 }
206 }
207
208 public static void NotifyNPCKilledDirect(Player player, int npcNetID)
209 {
211 {
212 AchievementsHelper.OnNPCKilled(player, (short)npcNetID);
213 }
214 }
215
216 public static void NotifyProgressionEvent(int eventID)
217 {
218 if (Main.netMode == 2)
219 {
220 NetMessage.SendData(98, -1, -1, null, eventID);
221 }
222 else if (AchievementsHelper.OnProgressionEvent != null)
223 {
225 }
226 }
227
228 public static void HandleOnEquip(Player player, Item item, int context)
229 {
230 if (context == 16)
231 {
232 Main.Achievements.GetCondition("HOLD_ON_TIGHT", "Equip").Complete();
233 }
234 if (context == 17)
235 {
236 Main.Achievements.GetCondition("THE_CAVALRY", "Equip").Complete();
237 }
238 if ((context == 10 || context == 11) && item.wingSlot > 0)
239 {
240 Main.Achievements.GetCondition("HEAD_IN_THE_CLOUDS", "Equip").Complete();
241 }
242 if (context == 8 && player.armor[0].stack > 0 && player.armor[1].stack > 0 && player.armor[2].stack > 0)
243 {
244 Main.Achievements.GetCondition("MATCHING_ATTIRE", "Equip").Complete();
245 }
246 if (context == 9 && player.armor[10].stack > 0 && player.armor[11].stack > 0 && player.armor[12].stack > 0)
247 {
248 Main.Achievements.GetCondition("FASHION_STATEMENT", "Equip").Complete();
249 }
250 if (context != 12 && context != 33)
251 {
252 return;
253 }
254 for (int i = 0; i < 10; i++)
255 {
256 if (player.IsItemSlotUnlockedAndUsable(i) && (player.dye[i].type < 1 || player.dye[i].stack < 1))
257 {
258 return;
259 }
260 }
261 for (int j = 0; j < player.miscDyes.Length; j++)
262 {
263 if (player.miscDyes[j].type < 1 || player.miscDyes[j].stack < 1)
264 {
265 return;
266 }
267 }
268 Main.Achievements.GetCondition("DYE_HARD", "Equip").Complete();
269 }
270
271 public static void HandleSpecialEvent(Player player, int eventID)
272 {
273 if (player.whoAmI != Main.myPlayer)
274 {
275 return;
276 }
277 switch (eventID)
278 {
279 case 1:
280 Main.Achievements.GetCondition("STAR_POWER", "Use").Complete();
281 if (player.statLifeMax == 500 && player.statManaMax == 200)
282 {
283 Main.Achievements.GetCondition("TOPPED_OFF", "Use").Complete();
284 }
285 break;
286 case 2:
287 Main.Achievements.GetCondition("GET_A_LIFE", "Use").Complete();
288 if (player.statLifeMax == 500 && player.statManaMax == 200)
289 {
290 Main.Achievements.GetCondition("TOPPED_OFF", "Use").Complete();
291 }
292 break;
293 case 3:
294 Main.Achievements.GetCondition("NOT_THE_BEES", "Use").Complete();
295 break;
296 case 4:
297 Main.Achievements.GetCondition("WATCH_YOUR_STEP", "Hit").Complete();
298 break;
299 case 6:
300 Main.Achievements.GetCondition("YOU_AND_WHAT_ARMY", "Spawn").Complete();
301 break;
302 case 5:
303 Main.Achievements.GetCondition("RAINBOWS_AND_UNICORNS", "Use").Complete();
304 break;
305 case 7:
306 Main.Achievements.GetCondition("THROWING_LINES", "Use").Complete();
307 break;
308 case 17:
309 Main.Achievements.GetCondition("FLY_A_KITE_ON_A_WINDY_DAY", "Use").Complete();
310 break;
311 case 8:
312 Main.Achievements.GetCondition("LUCKY_BREAK", "Hit").Complete();
313 break;
314 case 9:
315 Main.Achievements.GetCondition("VEHICULAR_MANSLAUGHTER", "Hit").Complete();
316 break;
317 case 10:
318 Main.Achievements.GetCondition("ROCK_BOTTOM", "Reach").Complete();
319 break;
320 case 11:
321 Main.Achievements.GetCondition("INTO_ORBIT", "Reach").Complete();
322 break;
323 case 12:
324 Main.Achievements.GetCondition("WHERES_MY_HONEY", "Reach").Complete();
325 break;
326 case 13:
327 Main.Achievements.GetCondition("JEEPERS_CREEPERS", "Reach").Complete();
328 break;
329 case 14:
330 Main.Achievements.GetCondition("ITS_GETTING_HOT_IN_HERE", "Reach").Complete();
331 break;
332 case 15:
333 Main.Achievements.GetCondition("FUNKYTOWN", "Reach").Complete();
334 break;
335 case 16:
336 Main.Achievements.GetCondition("I_AM_LOOT", "Peek").Complete();
337 break;
338 case 18:
339 Main.Achievements.GetCondition("FOUND_GRAVEYARD", "Reach").Complete();
340 break;
341 case 19:
342 Main.Achievements.GetCondition("GO_LAVA_FISHING", "Do").Complete();
343 break;
344 case 20:
345 Main.Achievements.GetCondition("TALK_TO_NPC_AT_MAX_HAPPINESS", "Do").Complete();
346 break;
347 case 21:
348 Main.Achievements.GetCondition("PET_THE_PET", "Do").Complete();
349 break;
350 case 22:
351 Main.Achievements.GetCondition("FIND_A_FAIRY", "Do").Complete();
352 break;
353 case 23:
354 Main.Achievements.GetCondition("DIE_TO_DEAD_MANS_CHEST", "Do").Complete();
355 break;
356 case 24:
357 Main.Achievements.GetCondition("GAIN_TORCH_GODS_FAVOR", "Use").Complete();
358 break;
359 case 25:
360 Main.Achievements.GetCondition("DRINK_BOTTLED_WATER_WHILE_DROWNING", "Use").Complete();
361 break;
362 case 26:
363 Main.Achievements.GetCondition("PLAY_ON_A_SPECIAL_SEED", "Do").Complete();
364 break;
365 case 27:
366 Main.Achievements.GetCondition("PURIFY_ENTIRE_WORLD", "Do").Complete();
367 break;
368 }
369 }
370
371 public static void HandleNurseService(int coinsSpent)
372 {
373 ((CustomFloatCondition)Main.Achievements.GetCondition("FREQUENT_FLYER", "Pay")).Value += coinsSpent;
374 }
375
376 public static void HandleAnglerService()
377 {
378 Main.Achievements.GetCondition("SERVANT_IN_TRAINING", "Finish").Complete();
379 ((CustomIntCondition)Main.Achievements.GetCondition("GOOD_LITTLE_SLAVE", "Finish")).Value++;
380 ((CustomIntCondition)Main.Achievements.GetCondition("TROUT_MONKEY", "Finish")).Value++;
381 ((CustomIntCondition)Main.Achievements.GetCondition("FAST_AND_FISHIOUS", "Finish")).Value++;
382 ((CustomIntCondition)Main.Achievements.GetCondition("SUPREME_HELPER_MINION", "Finish")).Value++;
383 }
384
385 public static void HandleRunning(float pixelsMoved)
386 {
387 ((CustomFloatCondition)Main.Achievements.GetCondition("MARATHON_MEDALIST", "Move")).Value += pixelsMoved;
388 }
389
390 public static void HandleMining()
391 {
392 ((CustomIntCondition)Main.Achievements.GetCondition("BULLDOZER", "Pick")).Value++;
393 }
394
395 public static void CheckMechaMayhem(int justKilled = -1)
396 {
397 if (!mayhemOK)
398 {
399 if (NPC.AnyNPCs(127) && NPC.AnyNPCs(134) && NPC.AnyNPCs(126) && NPC.AnyNPCs(125))
400 {
401 mayhemOK = true;
402 mayhem1down = false;
403 mayhem2down = false;
404 mayhem3down = false;
405 }
406 return;
407 }
408 if (justKilled == 125 || justKilled == 126)
409 {
410 mayhem1down = true;
411 }
412 else if (!NPC.AnyNPCs(125) && !NPC.AnyNPCs(126) && !mayhem1down)
413 {
414 mayhemOK = false;
415 return;
416 }
417 if (justKilled == 134)
418 {
419 mayhem2down = true;
420 }
421 else if (!NPC.AnyNPCs(134) && !mayhem2down)
422 {
423 mayhemOK = false;
424 return;
425 }
426 if (justKilled == 127)
427 {
428 mayhem3down = true;
429 }
430 else if (!NPC.AnyNPCs(127) && !mayhem3down)
431 {
432 mayhemOK = false;
433 return;
434 }
436 {
438 }
439 }
440}
Item[] item
Definition Chest.cs:41
static void HandleSpecialEvent(Player player, int eventID)
delegate void NPCKilledEvent(Player player, short npcId)
delegate void TileDestroyedEvent(Player player, ushort tileId)
delegate void ItemPickupEvent(Player player, short itemId, int count)
static void NotifyItemPickup(Player player, Item item)
static void HandleOnEquip(Player player, Item item, int context)
delegate void ItemCraftEvent(short itemId, int count)
static void NotifyNPCKilledDirect(Player player, int npcNetID)
static void NotifyTileDestroyed(Player player, ushort tile)
static void NotifyItemPickup(Player player, Item item, int customStack)
int stack
Definition Item.cs:149
int netID
Definition Item.cs:291
sbyte wingSlot
Definition Item.cs:213
static AchievementManager Achievements
Definition Main.cs:2756
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static bool gameMenu
Definition Main.cs:1926
static Player[] player
Definition Main.cs:1803
static bool AnyNPCs(int Type)
Definition NPC.cs:86689
bool[] playerInteraction
Definition NPC.cs:113
int netID
Definition NPC.cs:531
static void SendData(int msgType, int remoteClient=-1, int ignoreClient=-1, NetworkText text=null, int number=0, float number2=0f, float number3=0f, float number4=0f, int number5=0, int number6=0, int number7=0)
Definition NetMessage.cs:88
bool unlockedBiomeTorches
Definition Player.cs:1663
EquipmentLoadout[] Loadouts
Definition Player.cs:2721
Item[] miscEquips
Definition Player.cs:1171
bool IsItemSlotUnlockedAndUsable(int slot)
Definition Player.cs:11968
Item[] miscDyes
Definition Player.cs:1173
Item[] inventory
Definition Player.cs:1257
Item createItem
Definition Recipe.cs:27
static void CheckAchievement_RealEstateAndTownSlimes()
Definition WorldGen.cs:2158