forked from ffhighwind/PoE-Price-Lister
/
FilterWriter.cs
437 lines (399 loc) · 20.9 KB
/
FilterWriter.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PoE_Price_Lister
{
public class FilterWriter
{
private const string header10c =
@"#------#
# 10c+ #
#------#
# White background
# High value. Do not miss these.";
private const string header2to10c =
@"#-------#
# 2-10c #
#-------#
# White border
# Usually worth selling. Not extremely rare or valuable.
# May share a BaseType with an extremely valuable item, League Specific, or boss drop only.";
private const string header1c =
@"#------#
# 1-2c #
#------#
# Yellow border
# Sellable but rarely worth much.";
private const string headerLess1c =
"#-----#\n" +
"# <1c #\n" +
"#-----#\n" +
"# Orange border\n" +
"# Usually < 1c or nearly worthless.\n\n" +
"Show # Uniques - <1c - ilvl <67\n" +
"\tRarity = Unique\n" +
"\tItemLevel < 67\n" +
"\tSetFontSize 40\n" +
"\tSetTextColor 255 128 64 # Unique\n" +
"\tSetBackgroundColor 50 25 12 # Unique\n" +
"\tSetBorderColor 180 90 45 # Unique (<1c)\n" +
"\tPlayAlertSound 4 200 # Mid Value\n" +
"\tMinimapIcon 0 Brown Square\n" +
"\tPlayEffect Brown";
private const string loreweaveStr =
"# Loreweave (60x rings)\n" +
"Show # Uniques - 1-2c\n" +
"\tRarity = Unique\n" +
"\tClass Rings\n" +
"\tSetFontSize 40\n" +
"\tSetTextColor 255 128 64 # Unique\n" +
"\tSetBackgroundColor 50 25 12 # Unique\n" +
"\tSetBorderColor 255 255 0 # Unique (1-2c)\n" +
"\tPlayAlertSound 4 200 # Mid Value\n" +
"\tMinimapIcon 0 Brown Square\n" +
"\tPlayEffect Brown";
private const string style10c =
"\tSetFontSize 45\n" +
"\tSetTextColor 255 128 64 # Unique (10c+)\n" +
"\tSetBackgroundColor 255 255 255 255 # Unique (10c+)\n" +
"\tSetBorderColor 255 128 64 # Unique (10c+)\n" +
"\tPlayAlertSound 1 200 # High Value\n" +
"\tMinimapIcon 0 Red Square\n" +
"\tPlayEffect Red";
private const string style2to10c =
"\tSetFontSize 45\n" +
"\tSetTextColor 255 128 64 # Unique\n" +
"\tSetBackgroundColor 50 25 12 # Unique\n" +
"\tSetBorderColor 255 255 255 # Unique (2-10c)\n" +
"\tPlayAlertSound 1 200 # High Value\n" +
"\tMinimapIcon 0 Brown Square\n" +
"\tPlayEffect Brown";
private const string style1c =
"\tSetFontSize 40\n" +
"\tSetTextColor 255 128 64 # Unique\n" +
"\tSetBackgroundColor 50 25 12 # Unique\n" +
"\tSetBorderColor 255 255 0 # Unique (1-2c)\n" +
"\tPlayAlertSound 4 200 # Mid Value\n" +
"\tMinimapIcon 0 Brown Square\n" +
"\tPlayEffect Brown";
private const string styleLess1c =
"\tSetFontSize 40\n" +
"\tSetTextColor 255 128 64 # Unique\n" +
"\tSetBackgroundColor 50 25 12 # Unique\n" +
"\tSetBorderColor 180 90 45 # Unique (<1c)\n" +
"\tPlayAlertSound 4 200 # Mid Value\n" +
"\tMinimapIcon 0 Brown Square\n" +
"\tPlayEffect Brown";
private const string uniqueNewOrWorthless =
"Show # Uniques - New or Worthless\n" +
"\tRarity = Unique\n" +
"\tSetFontSize 36\n" +
"\tSetTextColor 255 128 64 # Unique\n" +
"\tSetBackgroundColor 50 25 12 # Unique\n" +
"\tSetBorderColor 180 90 45 # Unique (<1c)\n" +
"\tPlayAlertSound 4 200 # Mid Value\n" +
"\tMinimapIcon 0 Brown Square\n" +
"\tPlayEffect Brown";
private const string styleDiv10c =
"\tSetFontSize 45\n" +
"\tSetTextColor 255 0 175 # Divination Card (10c+)\n" +
"\tSetBackgroundColor 255 255 255 255 # Divination Card (10c+)\n" +
"\tSetBorderColor 255 0 175 # Divination Card (10c+)\n" +
"\tPlayAlertSound 1 200 # High Value\n" +
"\tMinimapIcon 0 Red Triangle\n" +
"\tPlayEffect Red";
private const string styleDiv1c =
"\tSetFontSize 45\n" +
"\tSetTextColor 255 255 255 # Divination Card (1c+)\n" +
"\tSetBackgroundColor 255 0 175 255 # Divination Card (1c+)\n" +
"\tSetBorderColor 255 255 255 # Divination Card (1c+)\n" +
"\tPlayAlertSound 5 200 # Divination Card (1c+)\n" +
"\tMinimapIcon 0 Brown Triangle\n" +
"\tPlayEffect Brown";
private const string styleDivLess1c =
"\tSetFontSize 40\n" +
"\tSetTextColor 0 0 0 # Divination Card (<1c)\n" +
"\tSetBackgroundColor 255 0 175 230 # Divination Card (<1c)\n" +
"\tSetBorderColor 150 30 100 # Divination Card (<1c)\n" +
"\tPlayAlertSound 5 100 # Divination Card (Low)\n" +
"\tPlayEffect Brown";
private const string styleDivNearlyWorthless =
"\tSetFontSize 36\n" +
"\tSetTextColor 0 0 0 # Divination Card (Nearly Worthless)\n" +
"\tSetBackgroundColor 255 0 175 170 # Divination Card (Nearly Worthless)\n" +
"\tSetBorderColor 0 0 0 # Divination Card (Nearly Worthless)\n" +
"\tPlayAlertSound 5 0 # Divination Card (Nearly Worthless)";
private const string styleDivWorthless =
"\tSetFontSize 32\n" +
"\tSetTextColor 0 0 0 # Divination Card (Worthless)\n" +
"\tSetBackgroundColor 255 0 175 120 # Divination Card (Worthless)\n" +
"\tSetBorderColor 255 0 175 50 # Divination Card (Worthless)\n" +
"\tDisableDropSound";
private const string divNewOrWorthless =
"Show # Divination Cards - New (Error)\n" +
"\tClass Divination\n" +
"\tSetFontSize 40\n" +
"\tSetTextColor 255 255 255 # Divination Card (1c+)\n" +
"\tSetBackgroundColor 255 0 175 255 # Divination Card (1c+)\n" +
"\tSetBorderColor 0 255 0 # Error\n" +
"\tPlayAlertSound 5 200 # Divination Card (1c+)\n" +
"\tMinimapIcon 0 White Triangle\n" +
"\tPlayEffect White";
private const string headerDiv =
@"##########################################
############ DIVINATION CARDS ############
##########################################
# Section: Divination Cards
# Ordered most expensive first to prevent future name conflicts!
# Prices attained from poe.ninja.
# Future values will fluctuate based on league challenges and the meta.";
private readonly IReadOnlyList<string> Uniques;
private readonly IReadOnlyList<string> DivinationCards;
private readonly Dictionary<string, UniqueBaseType> UniquesSC;
private readonly Dictionary<string, UniqueBaseType> UniquesHC;
private readonly Dictionary<string, DivinationCard> DivinationSC;
private readonly Dictionary<string, DivinationCard> DivinationHC;
private readonly IReadOnlyList<IReadOnlyList<string>> Conflicts;
private StreamWriter Writer { get; set; }
private bool Safe { get; set; }
private bool HCFriendly { get; set; }
public FilterWriter(DataModel model)
{
DivinationCards = model.DivinationCards;
Uniques = model.Uniques;
UniquesSC = model.SC.Uniques;
UniquesHC = model.HC.Uniques;
DivinationHC = model.HC.DivinationCards;
DivinationSC = model.SC.DivinationCards;
Conflicts = model.DivinationCardNameConflicts;
}
public void Create(string path, bool safe, bool hcFriendly)
{
try {
Safe = safe;
HCFriendly = hcFriendly;
using (Writer = new StreamWriter(path, false, Encoding.UTF8)) {
Writer.WriteLine();
Writer.WriteLine(GenerateUniquesString());
Writer.Write(GenerateDivinationString());
}
Writer = null;
}
catch (Exception ex) {
MessageBox.Show(ex.Message, "FilterWriter.Create", MessageBoxButtons.OK);
}
}
private string GenerateDivinationConflictsString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("# Potential Conflicts!!! (They have been separated but may need to be reorganized)");
foreach (List<string> list in Conflicts) {
sb.Append("# ");
foreach (string str in list) {
string baseTy = str;
if (baseTy.Contains(' '))
baseTy = "\"" + baseTy + "\"";
sb.Append(baseTy).Append(' ');
}
sb.Remove(sb.Length - 1, 1).AppendLine();
}
return sb.ToString();
}
private string GenerateUniquesString()
{
List<string> list10c = new List<string>();
List<string> list2to10c = new List<string>();
List<string> list1to2c = new List<string>();
List<string> listLess1c = new List<string>();
List<string> listLess1cShared = new List<string>();
List<string> listLess1cLeague = new List<string>();
List<string> listLess1cBoss = new List<string>();
List<string> listLess1cCrafted = new List<string>();
List<string> listLess1cLabyrinth = new List<string>();
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, UniqueBaseType> uniq in UniquesSC) {
UniqueBaseType entry = uniq.Value;
string baseTy = uniq.Key;
UniqueValue expectedVal = entry.ExpectedFilterValue;
UniqueValue filterVal = entry.FilterValue;
string outputBaseTy = baseTy;
int index = baseTy.IndexOf('ö');
if(index > 0) {
outputBaseTy = outputBaseTy.Substring(0, index);
}
UniqueBaseType entryHC = UniquesHC[baseTy];
UniqueValue expectedValHC = entryHC.ExpectedFilterValue;
if (entry.SeverityLevel == 0)
expectedVal = filterVal;
else if (Safe && filterVal.Tier > expectedVal.Tier) {
if (entry.Items.Count > 1 || filterVal.LowValue < entry.Items[0].ChaosValue) {
expectedVal = UniqueValue.FromTier(expectedVal.Tier + 1);
}
}
//if SC <1c and HC 4c+ then 1-2c
if (HCFriendly && expectedVal.Tier < 2 && expectedValHC.Tier > 2 && entryHC.Items.Any(i => i.IsCoreDrop && i.ChaosValue > 4.0f)) {
expectedVal = UniqueValue.Chaos1to2;
}
switch (expectedVal.Value) {
case UniqueValueEnum.Chaos10:
list10c.Add(outputBaseTy);
break;
case UniqueValueEnum.Chaos2to10:
list2to10c.Add(outputBaseTy);
break;
case UniqueValueEnum.Chaos1to2:
list1to2c.Add(outputBaseTy);
break;
case UniqueValueEnum.ChaosLess1:
listLess1c.Add(outputBaseTy);
break;
case UniqueValueEnum.ChaosLess1League:
listLess1cLeague.Add(outputBaseTy);
break;
case UniqueValueEnum.ChaosLess1Boss:
listLess1cBoss.Add(outputBaseTy);
break;
case UniqueValueEnum.ChaosLess1Shared:
listLess1cShared.Add(outputBaseTy);
break;
case UniqueValueEnum.ChaosLess1Crafted:
listLess1cCrafted.Add(outputBaseTy);
break;
case UniqueValueEnum.ChaosLess1Labyrinth:
listLess1cLabyrinth.Add(outputBaseTy);
break;
default:
break;
}
}
if (list10c.Count > 0) {
sb.AppendLine(header10c).AppendLine();
sb.AppendLine("Show # Uniques - 10c+").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(list10c)).AppendLine(style10c).AppendLine();
}
if (list2to10c.Count > 0) {
sb.AppendLine(header2to10c).AppendLine();
sb.AppendLine("Show # Uniques - 2-10c").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(list2to10c)).AppendLine(style2to10c).AppendLine();
}
sb.AppendLine(header1c).AppendLine();
if (list1to2c.Count > 0) {
sb.AppendLine("Show # Uniques - 1-2c").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(list1to2c)).AppendLine(style1c).AppendLine();
}
sb.AppendLine(loreweaveStr).AppendLine();
sb.AppendLine(headerLess1c).AppendLine();
if (listLess1cLeague.Count > 0)
sb.AppendLine("Show # Uniques - <1c - League").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(listLess1cLeague)).AppendLine(styleLess1c).AppendLine();
if (listLess1cBoss.Count > 0)
sb.AppendLine("Show # Uniques - <1c - Boss Prophecy").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(listLess1cBoss)).AppendLine(styleLess1c).AppendLine();
if (listLess1cShared.Count > 0)
sb.AppendLine("Show # Uniques - <1c - Shared").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(listLess1cShared)).AppendLine(styleLess1c).AppendLine();
if (listLess1cCrafted.Count > 0)
sb.AppendLine("Show # Uniques - <1c - Crafted Fated Purchased").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(listLess1cCrafted)).AppendLine(styleLess1c).AppendLine();
if (listLess1cLabyrinth.Count > 0)
sb.AppendLine("Show # Uniques - <1c - Labyrinth").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(listLess1cLabyrinth)).AppendLine(styleLess1c).AppendLine();
if (listLess1c.Count > 0)
sb.AppendLine("Show # Uniques - <1c - Nearly Worthless").AppendLine("\tRarity = Unique").Append('\t').AppendLine(BaseTypeList(listLess1c)).AppendLine(styleLess1c).AppendLine();
sb.AppendLine(uniqueNewOrWorthless);
return sb.ToString();
}
//IEnumerable<string> lines
private string GenerateDivinationString()
{
List<string> list1to10cConflict = new List<string>();
List<string> listLess1cConflict = new List<string>();
List<string> listNearlyWorthlessConflict = new List<string>();
List<string> listWorthlessConflict = new List<string>();
List<string> list10c = new List<string>();
List<string> list1to10c = new List<string>();
List<string> listLess1c = new List<string>();
List<string> listNearlyWorthless = new List<string>();
List<string> listWorthless = new List<string>();
StringBuilder sb = new StringBuilder();
foreach (string divCard in DivinationCards) {
DivinationCard data = DivinationSC[divCard];
DivinationValue expectedVal = data.ExpectedFilterValue;
DivinationValue filterVal = data.FilterValue;
DivinationCard dataHC = DivinationHC[divCard];
DivinationValue expectedValHC = dataHC.ExpectedFilterValue;
if (data.SeverityLevel == 0)
expectedVal = filterVal;
else if (Safe && filterVal.LowValue < data.ChaosValue) {
expectedVal = DivinationValue.FromTier(expectedVal.Tier + 1);
}
//if SC <1c and HC 4c+ then +1 tier
if (HCFriendly && expectedVal.Tier < 2 && dataHC.ChaosValue > 4.0f) {
expectedVal = DivinationValue.FromTier(expectedVal.Tier + 1);
}
switch (expectedVal.Value) {
case DivinationValueEnum.Chaos10:
list10c.Add(divCard);
break;
case DivinationValueEnum.Chaos1to10:
if (list10c.Exists(str => divCard.Contains(str)))
list1to10cConflict.Add(divCard);
else
list1to10c.Add(divCard);
break;
case DivinationValueEnum.ChaosLess1:
if (list10c.Exists(str => divCard.Contains(str)) || list1to10c.Exists(str => divCard.Contains(str)))
listLess1cConflict.Add(divCard);
else
listLess1c.Add(divCard);
break;
case DivinationValueEnum.NearlyWorthless:
if (list10c.Exists(str => divCard.Contains(str)) || list1to10c.Exists(str => divCard.Contains(str)) || listLess1c.Exists(str => divCard.Contains(str)))
listNearlyWorthlessConflict.Add(divCard);
else
listNearlyWorthless.Add(data.Name);
break;
case DivinationValueEnum.Worthless:
if (list10c.Exists(str => divCard.Contains(str)) || list1to10c.Exists(str => divCard.Contains(str))
|| listLess1c.Exists(str => divCard.Contains(str)) || listNearlyWorthless.Exists(str => divCard.Contains(str))) {
listWorthlessConflict.Add(divCard);
}
else
listWorthless.Add(divCard);
break;
default:
break;
}
}
sb.AppendLine(headerDiv).AppendLine();
sb.AppendLine(GenerateDivinationConflictsString()).AppendLine();
if (list1to10cConflict.Count > 0)
sb.AppendLine("Show # Divination Cards - 1c+ (Conflicts)").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(list1to10cConflict)).AppendLine(styleDiv1c).AppendLine();
if (listLess1cConflict.Count > 0)
sb.AppendLine("Show # Divination Cards - <1c (Conflicts)").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(listLess1cConflict)).AppendLine(styleDivLess1c).AppendLine();
if (listNearlyWorthlessConflict.Count > 0)
sb.AppendLine("Show # Divination Cards - Nearly Worthless (Conflicts)").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(listNearlyWorthlessConflict)).AppendLine(styleDivNearlyWorthless).AppendLine();
if (listWorthlessConflict.Count > 0)
sb.AppendLine("Hide # Divination Cards - Worthless (Conflicts)").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(listWorthlessConflict)).AppendLine(styleDivWorthless).AppendLine();
if (list10c.Count > 0)
sb.AppendLine("Show # Divination Cards - 10c+").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(list10c)).AppendLine(styleDiv10c).AppendLine();
if (list1to10c.Count > 0)
sb.AppendLine("Show # Divination Cards - 1c+").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(list1to10c)).AppendLine(styleDiv1c).AppendLine();
if (listLess1c.Count > 0)
sb.AppendLine("Show # Divination Cards - <1c").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(listLess1c)).AppendLine(styleDivLess1c).AppendLine();
if (listNearlyWorthless.Count > 0)
sb.AppendLine("Show # Divination Cards - Nearly Worthless").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(listNearlyWorthless)).AppendLine(styleDivNearlyWorthless).AppendLine();
if (listWorthless.Count > 0)
sb.AppendLine("Show # Divination Cards - Worthless").AppendLine("\tClass Divination").Append('\t').AppendLine(BaseTypeList(listWorthless)).AppendLine(styleDivWorthless).AppendLine();
sb.AppendLine(divNewOrWorthless);
return sb.ToString();
}
private string BaseTypeList(List<string> baseTypes)
{
StringBuilder sb = new StringBuilder();
sb.Append("BaseType ");
foreach (string baseTy in baseTypes) {
string result = baseTy;
if (baseTy.Contains(' '))
result = "\"" + baseTy + "\"";
sb.Append(result).Append(' ');
}
return sb.Remove(sb.Length - 1, 1).ToString();
}
}
}