-
Notifications
You must be signed in to change notification settings - Fork 6
/
Config.cs
288 lines (244 loc) · 7.15 KB
/
Config.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
namespace AssortedCrazyThings
{
public class ContentConfig : ServerConfigBase
{
public static ContentConfig Instance => ModContent.GetInstance<ContentConfig>();
internal ContentType FilterFlags { private set; get; }
[Header("TogglesSpecial")]
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(152, 150, 113)]
public bool Bosses { get; set; }
[ReloadRequired]
[DefaultValue(false)]
[BackgroundColor(123, 164, 255)]
public bool CuteSlimes { get; set; }
[Header("NPCs")]
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(227, 160, 147)]
public bool HostileNPCs { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(227, 160, 147)]
public bool FriendlyNPCs { get; set; }
[Header("Items")]
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool DroppedPets { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool OtherPets { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool Weapons { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool Tools { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool PlaceablesFunctional { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool PlaceablesDecorative { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool Armor { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool VanityArmor { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool Accessories { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool VanityAccessories { get; set; }
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(194, 147, 227)]
public bool BossConsolation { get; set; }
[Header("Other")]
[ReloadRequired]
[DefaultValue(true)]
[BackgroundColor(89, 106, 159)]
public bool AommSupport { get; set; }
/// <summary>
/// Affects the way Cute Slimes spawn and how the Jellied Ale works
/// </summary>
[DefaultValue(true)]
public bool CuteSlimesPotionOnly { get; set; }
[Header("HintClientConfig")]
[JsonIgnore]
[ShowDespiteJsonIgnore]
public bool Hint => true;
public override void OnChanged()
{
SetFlags();
}
private void SetFlags()
{
//Inverted, sets a flag if toggle is false
FilterFlags = ContentType.Always;
if (!Bosses)
{
FilterFlags |= ContentType.Bosses;
}
if (!CuteSlimes)
{
FilterFlags |= ContentType.CuteSlimes;
}
if (!HostileNPCs)
{
FilterFlags |= ContentType.HostileNPCs;
}
if (!FriendlyNPCs)
{
FilterFlags |= ContentType.FriendlyNPCs;
}
if (!DroppedPets)
{
FilterFlags |= ContentType.DroppedPets;
}
if (!OtherPets)
{
FilterFlags |= ContentType.OtherPets;
}
if (!Weapons)
{
FilterFlags |= ContentType.Weapons;
}
if (!Tools)
{
FilterFlags |= ContentType.Tools;
}
if (!PlaceablesFunctional)
{
FilterFlags |= ContentType.PlaceablesFunctional;
}
if (!PlaceablesDecorative)
{
FilterFlags |= ContentType.PlaceablesDecorative;
}
if (!Armor)
{
FilterFlags |= ContentType.Armor;
}
if (!VanityArmor)
{
FilterFlags |= ContentType.VanityArmor;
}
if (!Accessories)
{
FilterFlags |= ContentType.Accessories;
}
if (!VanityAccessories)
{
FilterFlags |= ContentType.VanityAccessories;
}
if (!BossConsolation)
{
FilterFlags |= ContentType.BossConsolation;
}
if (!AommSupport || !ModLoader.HasMod("AmuletOfManyMinions")) //Using instead of API.AommMod as that references the not-yet-registered config itself
{
//Automatically filter aomm content if the mod is disabled
FilterFlags |= ContentType.AommSupport;
}
}
}
public class ClientConfig : ModConfig
{
public static ClientConfig Instance => ModContent.GetInstance<ClientConfig>();
public override ConfigScope Mode => ConfigScope.ClientSide;
//Old data
[JsonExtensionData]
private IDictionary<string, JToken> _additionalData = new Dictionary<string, JToken>();
[Header("GoblinUnderling")]
[DefaultValue(true)]
[BackgroundColor(125, 217, 124)]
public bool GoblinUnderlingAutosummon { get; set; }
[DefaultValue(true)]
[BackgroundColor(125, 217, 124)]
public bool GoblinUnderlingVisibleArmor { get; set; }
[DefaultValue(true)]
[BackgroundColor(125, 217, 124)]
public bool GoblinUnderlingVisibleRocketBoots { get; set; }
public const int GoblinUnderlingChatterFreq_Min = 0;
public const int GoblinUnderlingChatterFreq_Max = 500;
[DefaultValue(100)]
[BackgroundColor(125, 217, 124)]
[Slider]
[Increment(10)]
[Range(GoblinUnderlingChatterFreq_Min, GoblinUnderlingChatterFreq_Max)]
public int GoblinUnderlingChatterFreq { get; set; }
internal bool GoblinUnderlingChatterDisabled => GoblinUnderlingChatterFreq == 0;
[Header("HintServerConfig")]
[JsonIgnore]
[ShowDespiteJsonIgnore]
public bool Hint => true;
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
//port "SatchelofGoodiesAutosummon" -> GoblinUnderlingAutosummon
//and "SatchelofGoodiesVisibleArmor" -> GoblinUnderlingVisibleArmor
//and "SatchelofGoodiesChatterFreq" -> GoblinUnderlingChatterFreq
JToken token;
if (_additionalData.TryGetValue("SatchelofGoodiesAutosummon", out token))
{
GoblinUnderlingAutosummon = token.ToObject<bool>();
}
if (_additionalData.TryGetValue("SatchelofGoodiesVisibleArmor", out token))
{
GoblinUnderlingVisibleArmor = token.ToObject<bool>();
}
if (_additionalData.TryGetValue("SatchelofGoodiesChatterFreq", out token))
{
GoblinUnderlingChatterFreq = token.ToObject<int>();
}
_additionalData.Clear(); // Clear this or it'll crash.
GoblinUnderlingChatterFreq = Utils.Clamp(GoblinUnderlingChatterFreq, GoblinUnderlingChatterFreq_Min, GoblinUnderlingChatterFreq_Max);
}
}
public abstract class ServerConfigBase : ModConfig
{
public override ConfigScope Mode => ConfigScope.ServerSide;
public static bool IsPlayerLocalServerOwner(int whoAmI)
{
if (Main.netMode == NetmodeID.MultiplayerClient)
{
return Netplay.Connection.Socket.GetRemoteAddress().IsLocalHost();
}
return NetMessage.DoesPlayerSlotCountAsAHost(whoAmI);
}
public override bool AcceptClientChanges(ModConfig pendingConfig, int whoAmI, ref NetworkText message)
{
if (Main.netMode == NetmodeID.SinglePlayer) return true;
else if (!IsPlayerLocalServerOwner(whoAmI))
{
message = NetworkText.FromKey("tModLoader.ModConfigRejectChangesNotHost"); //"Only the host can change this config"
return false;
}
return base.AcceptClientChanges(pendingConfig, whoAmI, ref message);
}
}
}