forked from JavidPack/ItemChecklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemChecklistGlobalItem.cs
41 lines (38 loc) · 1.3 KB
/
ItemChecklistGlobalItem.cs
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
using Terraria;
using Terraria.ModLoader;
namespace ItemChecklist
{
class ItemChecklistGlobalItem : GlobalItem
{
// OnPIckup only called on LocalPlayer: I think
public override void OnCraft(Item item, Recipe recipe)
{
ItemReceived(item);
}
// OnPIckup only called on LocalPlayer: i == Main.myPlayer
public override bool OnPickup(Item item, Player player)
{
ItemReceived(item);
return true;
}
// TODO, unloaded items, check against??
internal void ItemReceived(Item item)
{
var itemChecklistPlayer = Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>(mod);
if (!itemChecklistPlayer.foundItem[item.type] && itemChecklistPlayer.findableItems[item.type])
{
Item newItem = new Item();
newItem.SetDefaults(item.type);
itemChecklistPlayer.foundItems.Add(newItem);
itemChecklistPlayer.totalItemsFound++;
itemChecklistPlayer.foundItem[item.type] = true;
ItemChecklist.instance.ItemChecklistUI.UpdateNeeded(item.type);
if (ItemChecklistUI.announce)
{
Main.NewText($"You found your first {item.Name}. {itemChecklistPlayer.totalItemsFound}/{itemChecklistPlayer.totalItemsToFind} {(100f*itemChecklistPlayer.totalItemsFound/itemChecklistPlayer.totalItemsToFind).ToString("0.00")}%");
}
ItemChecklist.instance.NewItem(item.type);
}
}
}
}