Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Achievement.cs
Go to the documentation of this file.
2using Newtonsoft.Json;
3using Newtonsoft.Json.Linq;
6
8
9[JsonObject(/*Could not decode attribute arguments.*/)]
10public class Achievement
11{
12 public delegate void AchievementCompleted(Achievement achievement);
13
14 private static int _totalAchievements;
15
16 public readonly string Name;
17
18 public readonly LocalizedText FriendlyName;
19
20 public readonly LocalizedText Description;
21
22 public readonly int Id = _totalAchievements++;
23
25
27
28 [JsonProperty("Conditions")]
30
31 private int _completedCount;
32
34
35 public bool HasTracker => _tracker != null;
36
38
40
42 {
43 return _tracker;
44 }
45
46 public Achievement(string name)
47 {
48 Name = name;
49 FriendlyName = Language.GetText("Achievements." + name + "_Name");
50 Description = Language.GetText("Achievements." + name + "_Description");
51 }
52
53 public void ClearProgress()
54 {
57 {
58 condition.Value.Clear();
59 }
60 if (_tracker != null)
61 {
63 }
64 }
65
66 public void Load(Dictionary<string, JObject> conditions)
67 {
68 foreach (KeyValuePair<string, JObject> condition in conditions)
69 {
70 if (_conditions.TryGetValue(condition.Key, out var value))
71 {
72 value.Load(condition.Value);
73 if (value.IsCompleted)
74 {
76 }
77 }
78 }
79 if (_tracker != null)
80 {
81 _tracker.Load();
82 }
83 }
84
85 public void AddCondition(AchievementCondition condition)
86 {
87 _conditions[condition.Name] = condition;
88 condition.OnComplete += OnConditionComplete;
89 }
90
92 {
95 {
96 if (_tracker == null && SocialAPI.Achievements != null)
97 {
98 SocialAPI.Achievements.CompleteAchievement(Name);
99 }
100 if (this.OnCompleted != null)
101 {
102 this.OnCompleted(this);
103 }
104 }
105 }
106
108 {
109 tracker.ReportAs("STAT_" + Name);
111 }
112
117
127
128 public void UseConditionsCompletedTracker(params string[] conditions)
129 {
131 foreach (string key in conditions)
132 {
133 conditionsCompletedTracker.AddCondition(_conditions[key]);
134 }
136 }
137
138 public void ClearTracker()
139 {
140 _tracker = null;
141 }
142
144 {
145 return _conditions[name].GetAchievementTracker();
146 }
147
148 public void AddConditions(params AchievementCondition[] conditions)
149 {
150 for (int i = 0; i < conditions.Length; i++)
151 {
152 AddCondition(conditions[i]);
153 }
154 }
155
157 {
159 {
160 return value;
161 }
162 return null;
163 }
164
165 public void SetCategory(AchievementCategory category)
166 {
167 _category = category;
168 }
169}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void AddConditions(params AchievementCondition[] conditions)
void UseConditionsCompletedTracker(params string[] conditions)
void SetCategory(AchievementCategory category)
IAchievementTracker GetConditionTracker(string name)
AchievementCompleted OnCompleted
void OnConditionComplete(AchievementCondition condition)
readonly LocalizedText Description
readonly LocalizedText FriendlyName
AchievementCategory _category
AchievementCondition GetCondition(string conditionName)
delegate void AchievementCompleted(Achievement achievement)
void Load(Dictionary< string, JObject > conditions)
void UseTrackerFromCondition(string conditionName)
void AddCondition(AchievementCondition condition)
IAchievementTracker GetTracker()
void UseTracker(IAchievementTracker tracker)
Dictionary< string, AchievementCondition > _conditions
static LocalizedText GetText(string key)
Definition Language.cs:10
static Terraria.Social.Base.AchievementsSocialModule Achievements
Definition SocialAPI.cs:16