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