Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NPCKilledCondition.cs
Go to the documentation of this file.
3
5
7{
8 private const string Identifier = "NPC_KILLED";
9
11
12 private static bool _isListenerHooked;
13
14 private short[] _npcIds;
15
17 : base("NPC_KILLED_" + npcId)
18 {
19 _npcIds = new short[1] { npcId };
20 ListenForPickup(this);
21 }
22
23 private NPCKilledCondition(short[] npcIds)
24 : base("NPC_KILLED_" + npcIds[0])
25 {
27 ListenForPickup(this);
28 }
29
30 private static void ListenForPickup(NPCKilledCondition condition)
31 {
33 {
34 AchievementsHelper.OnNPCKilled += NPCKilledListener;
35 _isListenerHooked = true;
36 }
37 for (int i = 0; i < condition._npcIds.Length; i++)
38 {
39 if (!_listeners.ContainsKey(condition._npcIds[i]))
40 {
41 _listeners[condition._npcIds[i]] = new List<NPCKilledCondition>();
42 }
43 _listeners[condition._npcIds[i]].Add(condition);
44 }
45 }
46
47 private static void NPCKilledListener(Player player, short npcId)
48 {
49 if (player.whoAmI != Main.myPlayer || !_listeners.ContainsKey(npcId))
50 {
51 return;
52 }
53 foreach (NPCKilledCondition item in _listeners[npcId])
54 {
55 item.Complete();
56 }
57 }
58
60 {
61 return new NPCKilledCondition(npcIds);
62 }
63
64 public static AchievementCondition Create(short npcId)
65 {
66 return new NPCKilledCondition(npcId);
67 }
68
69 public static AchievementCondition[] CreateMany(params short[] npcs)
70 {
72 for (int i = 0; i < npcs.Length; i++)
73 {
74 array[i] = new NPCKilledCondition(npcs[i]);
75 }
76 return array;
77 }
78}
static Dictionary< short, List< NPCKilledCondition > > _listeners
static AchievementCondition Create(short npcId)
static AchievementCondition[] CreateMany(params short[] npcs)
static AchievementCondition Create(params short[] npcIds)
static void NPCKilledListener(Player player, short npcId)
static void ListenForPickup(NPCKilledCondition condition)
static int myPlayer
Definition Main.cs:1801