Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NPCKillsTracker.cs
Go to the documentation of this file.
2using System.IO;
4using Terraria.ID;
5using Terraria.Net;
6
8
10{
11 private object _entryCreationLock = new object();
12
13 public const int POSITIVE_KILL_COUNT_CAP = 999999999;
14
16
21
22 public void RegisterKill(NPC npc)
23 {
26 value++;
28 {
29 _killCountsByNpcId[bestiaryCreditId] = Utils.Clamp(value, 0, 999999999);
30 }
31 if (Main.netMode == 2)
32 {
34 }
35 }
36
37 public int GetKillCount(NPC npc)
38 {
41 }
42
43 public void SetKillCountDirectly(string persistentId, int killCount)
44 {
46 {
47 _killCountsByNpcId[persistentId] = Utils.Clamp(killCount, 0, 999999999);
48 }
49 }
50
51 public int GetKillCount(string persistentId)
52 {
54 return value;
55 }
56
57 public void Save(BinaryWriter writer)
58 {
60 {
61 writer.Write(_killCountsByNpcId.Count);
63 {
64 writer.Write(item.Key);
65 writer.Write(item.Value);
66 }
67 }
68 }
69
71 {
72 int num = reader.ReadInt32();
73 for (int i = 0; i < num; i++)
74 {
75 string key = reader.ReadString();
76 int value = reader.ReadInt32();
77 _killCountsByNpcId[key] = value;
78 }
79 }
80
82 {
83 int num = reader.ReadInt32();
84 for (int i = 0; i < num; i++)
85 {
86 reader.ReadString();
87 reader.ReadInt32();
88 }
89 }
90
91 public void Reset()
92 {
94 }
95
97 {
99 {
100 if (ContentSamples.NpcNetIdsByPersistentIds.TryGetValue(item.Key, out var value))
101 {
102 NetManager.Instance.SendToClient(NetBestiaryModule.SerializeKillCount(value, item.Value), playerIndex);
103 }
104 }
105 }
106}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
virtual string ReadString()
virtual int ReadInt32()
void ValidateWorld(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Load(BinaryReader reader, int gameVersionSaveWasMadeOn)
void SetKillCountDirectly(string persistentId, int killCount)
static NetPacket SerializeKillCount(int npcNetId, int killcount)
static Dictionary< string, int > NpcNetIdsByPersistentIds
static int netMode
Definition Main.cs:2095
string GetBestiaryCreditId()
Definition NPC.cs:91802
int netID
Definition NPC.cs:531
static readonly NetManager Instance
Definition NetManager.cs:18