Skip to content

Commit a651eaa

Browse files
committed
Fixes + New options
* Fixes champions not being found when loading + Options for trait optimization
1 parent 681b998 commit a651eaa

5 files changed

Lines changed: 181 additions & 20 deletions

File tree

TFT Comp Creator 2/Form1.Designer.cs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TFT Comp Creator 2/Form1.cs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public Form1()
108108
include_spatula,
109109
bronze_traits,
110110
carryCheck,
111-
carryCheck_unspecified
111+
carryCheck_unspecified,
112+
mustMaxOutTraitLevel,
113+
mustMaxOutTraitLevelCurrent
112114

113115
);
114116

@@ -252,6 +254,8 @@ public void Creation()
252254
List<string> tempIncludeTrait = include_trait.Items.Cast<string>().ToList();
253255
List<string> tempIncludeSpatula = include_spatula.Items.Cast<string>().ToList();
254256

257+
trait_snake = default_trait.Items[k].ToString();
258+
255259
if (ForceStop)
256260
{
257261
CreateButton.Enabled = false;
@@ -282,7 +286,7 @@ public void Creation()
282286

283287
Print(String.Join("-", tempIncludeTrait));
284288

285-
trait_snake = default_trait.Items[k].ToString();
289+
286290
int bp_total = Master["TraitList"][trait_snake]["Breakpoints"].Count;
287291
int biggest_bp = Master["TraitList"][trait_snake]["Breakpoints"][bp_total - 1];
288292
int emblems_required = biggest_bp - Master["TraitChampions"][trait_snake].Count;
@@ -386,13 +390,50 @@ public void Creation()
386390

387391

388392

389-
ConcurrentDictionary<List<string>, int> parallel_results = FindCombinations2(size, nodes, excluded_comp_champions, tempIncludeTrait, tempIncludeSpatula);
393+
ConcurrentDictionary<List<string>, int> parallel_results = FindCombinations2(size, nodes, excluded_comp_champions, tempIncludeTrait, tempIncludeSpatula, trait_snake);
394+
395+
ConcurrentDictionary<List<string>, int> parallel_results_best = new ConcurrentDictionary<List<string>, int>();
396+
if (mustMaxOutTraitLevelCurrent.Checked)
397+
{
398+
foreach (List<string> compParallel in parallel_results.Keys)
399+
{
400+
JObject JTraits = constructJTraits(compParallel);
401+
if (!JTraits.ContainsKey(trait_snake)) { continue; } // Ignore if trait isn't present
402+
403+
int maxTotalChamps = Master["TraitChampions"][trait_snake].Count;
404+
JArray breakpoints = Master["TraitList"][trait_snake]["Breakpoints"] as JArray;
405+
406+
// Get the highest breakpoint that can be reached without emblems
407+
int maxValidBP = breakpoints.Where(bp => (int)bp <= maxTotalChamps).DefaultIfEmpty(0).Max(bp => (int)bp);
408+
409+
int result = (int)JTraits[trait_snake];
410+
411+
// If the highest breakpoint is unreachable without emblems, check previous valid BP
412+
if (maxValidBP < breakpoints.Max(bp => (int)bp)) // There's a higher BP that we can't reach
413+
{
414+
if (result == maxValidBP)
415+
parallel_results_best[compParallel] = parallel_results[compParallel];
416+
}
417+
else
418+
{
419+
if (result == maxValidBP) // No need for `-1`, just compare with maxValidBP
420+
parallel_results_best[compParallel] = parallel_results[compParallel];
421+
}
422+
}
423+
424+
}
425+
else
426+
{
427+
parallel_results_best = parallel_results;
428+
}
429+
430+
390431

391432
// Filter, sort, and take the top 10
392-
var top10 = parallel_results
433+
var top10 = parallel_results_best
393434
.Where(entry => entry.Value > Pet_SynergyBest)
394435
.OrderByDescending(entry => entry.Value)
395-
.Take(10);
436+
.Take(20);
396437

397438
foreach (var obj in top10)
398439
{
@@ -599,7 +640,9 @@ private void applySet_Click(object sender, EventArgs e)
599640
include_spatula,
600641
bronze_traits,
601642
carryCheck,
602-
carryCheck_unspecified
643+
carryCheck_unspecified,
644+
mustMaxOutTraitLevel,
645+
mustMaxOutTraitLevelCurrent
603646

604647
);
605648

TFT Comp Creator 2/Scoring.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class Scoring
3131
private static CheckBox bronze_traits = new CheckBox();
3232
private static CheckBox carryCheck = new CheckBox();
3333
private static CheckBox carryCheck_unspecified = new CheckBox();
34+
private static CheckBox mustMaxOutTraitLevel = new CheckBox();
35+
private static CheckBox mustMaxOutTraitLevelCurrent = new CheckBox();
3436

3537

3638
public static ListBox include_spatula = new ListBox();
@@ -59,7 +61,9 @@ public static void SetFromScoring(
5961
ListBox include_spatula_,
6062
CheckBox bronze_traits_,
6163
CheckBox carryCheck_,
62-
CheckBox carryCheck_unspecified_
64+
CheckBox carryCheck_unspecified_,
65+
CheckBox mustMaxOutTraitLevel_,
66+
CheckBox mustMaxOutTraitLevelCurrent_
6367
)
6468
{
6569
Master = M;
@@ -88,6 +92,8 @@ CheckBox carryCheck_unspecified_
8892
carryCheck = carryCheck_;
8993
carryCheck_unspecified = carryCheck_unspecified_;
9094

95+
mustMaxOutTraitLevel = mustMaxOutTraitLevel_;
96+
mustMaxOutTraitLevelCurrent = mustMaxOutTraitLevelCurrent_;
9197
}
9298

9399
/// <summary>
@@ -335,19 +341,23 @@ public static bool CheckCompValidity(List<string> comp, List<string> excluded_co
335341
if (include_champion.Items.Count > 0 && carryCheck.Checked)
336342
{
337343
List<string> carry = new List<string>();
338-
foreach(string champion in include_champion.Items)
344+
foreach (string champion in include_champion.Items)
339345
{
340346
carry.Add(champion);
341347
}
342348
if (!CarryWorth3(JTraits, carry)) { return false; }
349+
350+
//
351+
352+
343353
}
344354

345-
if(carryCheck_unspecified.Checked)
355+
if (carryCheck_unspecified.Checked)
346356
{
347-
if(!isCarryPresent(JTraits, comp))
357+
if (!isCarryPresent(JTraits, comp))
348358
return false;
349359
}
350-
360+
351361
// Only comps with at least one trait that reaches BP 3 (gold) are considered valid.
352362
// Note: traits that only have 2 BP (therefore gold at 2) are ignored
353363
if (goldTrait.Checked)
@@ -403,12 +413,25 @@ public static bool CheckCompValidity(List<string> comp, List<string> excluded_co
403413
}
404414

405415

406-
407416
// Included / Excluded trait check
408417
foreach (string Trait in include_trait.Items)
409418
{
410419
if (!isTraitActive(JTraits, Trait))
411420
return false;
421+
422+
if (mustMaxOutTraitLevel.Checked)
423+
{
424+
// compute max potential without a spatula
425+
List<string> wantedTraitList = new List<string>();
426+
427+
foreach (dynamic item in include_trait.Items)
428+
{
429+
wantedTraitList.Add(item.ToString());
430+
}
431+
if (!isTraitMaxedOutNoSpatula(JTraits, wantedTraitList))
432+
return false;
433+
//int amount = JTraitsMaster["TraitChampions"]
434+
}
412435
}
413436

414437
foreach (string Trait in exclude_trait.Items)
@@ -427,9 +450,9 @@ public static bool CheckCompValidity(List<string> comp, List<string> excluded_co
427450
}
428451
}
429452

430-
431453

432-
454+
455+
433456

434457
// Ensure specified emblems are used
435458
foreach (string Trait in include_spatula.Items)
@@ -450,7 +473,7 @@ public static bool CheckCompValidity(List<string> comp, List<string> excluded_co
450473
if (bronze_traits.Checked)
451474
{
452475
int BP = CheckBreakPointAmount(JTraits, Trait);
453-
if(BP > 1) { return false; }
476+
if (BP > 1) { return false; }
454477
}
455478

456479
if (isTraitActive(JTraits, Trait))

TFT Comp Creator 2/Setup.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ public static dynamic FirstRun(int setData_ID)
206206

207207

208208

209-
210209
// Create population of champions
211210
i = 0;
212211
foreach (dynamic items in ChampionList)
@@ -215,17 +214,18 @@ public static dynamic FirstRun(int setData_ID)
215214

216215
string ChampionName = (string)JDownload["setData"][setData_ID]["champions"][i]["name"];
217216

218-
if(ChampionName == null) { continue; }
217+
if (ChampionName == null) { i++; continue; }
219218

220219
ChampionName = ChampionName.Replace(" & Willump", "");
221220
ChampionName = ChampionName.Replace("'", "");
222221

223222
string apiName = (string)JDownload["setData"][setData_ID]["champions"][i]["apiName"];
224-
223+
225224

226225
// Ignore duplicates, unless the same champion is considered different (compare its traits first)
227226
if (Master["Champions"].ContainsKey(ChampionName))
228227
{
228+
229229

230230
JArray LoggedChampionTraits = Master["Champions"][ChampionName]["Traits"];
231231
var PotentialNew = JDownload["setData"][setData_ID]["champions"][i]["traits"];
@@ -353,7 +353,10 @@ public static dynamic FirstRun(int setData_ID)
353353
foreach (JToken token in champions) // Iterate over the array
354354
{
355355
string ChampName = (string)token["display_name"];
356-
if(ChampName == null) { continue; }
356+
357+
358+
359+
if (ChampName == null) { continue; }
357360

358361
ChampName = ChampName.Replace("'", "");
359362

TFT Comp Creator 2/Utility.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public static List<string> GetTraitsFromChampion(string champion)
208208
return traits;
209209
}
210210

211+
211212
public static bool isGoldTraitPresent(JObject JTraits)
212213
{
213214
foreach (var item in JTraits.Properties())
@@ -242,6 +243,71 @@ public static int CheckBreakPointAmount(JObject JTraits, string Trait)
242243
return BP;
243244
}
244245

246+
public static JObject constructJTraits(List<string> comp)
247+
{
248+
JObject JTraits = new JObject();
249+
List<string> TraitsInComp = new List<string>();
250+
251+
foreach (string champion in comp)
252+
{
253+
// Add the trait to the list
254+
dynamic Traits = Master["Champions"][champion]["Traits"];
255+
foreach (string Trait in Traits)
256+
{
257+
if (TraitsInComp.Contains(Trait))
258+
continue;
259+
260+
TraitsInComp.Add(Trait);
261+
JProperty item_properties = new JProperty(Trait, 0);
262+
JTraits.Add(item_properties);
263+
}
264+
265+
// Populate JTraits
266+
int ChampionTraitsAmount = (int)Master["Champions"][champion]["Traits"].Count;
267+
268+
dynamic TraitsArray = Master["Champions"][champion]["Traits"];
269+
270+
for (int k = 0; k < ChampionTraitsAmount; k++)
271+
{
272+
string CurrentTrait = (string)TraitsArray[k];
273+
274+
if (TraitsInComp.Contains(CurrentTrait))
275+
{
276+
JTraits[CurrentTrait] = (int)JTraits[CurrentTrait] + 1;
277+
}
278+
}
279+
}
280+
return JTraits;
281+
}
282+
public static bool isTraitMaxedOutNoSpatula(JObject JTraits, List<string> wantedTraitList)
283+
{
284+
foreach (string trait in wantedTraitList)
285+
{
286+
JArray breakpoints = Master["TraitList"][trait]["Breakpoints"] as JArray;
287+
int maxTotalChamps = Master["TraitChampions"][trait].Count;
288+
289+
// Get the highest achievable breakpoint
290+
int maxValidBP = breakpoints.Where(bp => (int)bp <= maxTotalChamps).DefaultIfEmpty(0).Max(bp => (int)bp);
291+
292+
if (!JTraits.ContainsKey(trait)) return false; // Trait not present at all
293+
294+
int result = (int)JTraits[trait];
295+
296+
// If the highest breakpoint is unreachable without emblems, check the previous one
297+
if (maxValidBP < breakpoints.Max(bp => (int)bp)) // If there's a higher BP that we can't reach
298+
{
299+
if (result != maxValidBP)
300+
return false;
301+
}
302+
else
303+
{
304+
if (result != maxValidBP) // Don't subtract 1, use the highest valid BP
305+
return false;
306+
}
307+
}
308+
return true;
309+
}
310+
245311
// (test function) ensure champions with 3 or more traits have all of them active
246312
// note: doesn't actually produce better comps, just weird ones, but cool function to have just in case
247313
public static bool CarryWorth(JObject JTraits, List<string> comp)
@@ -561,7 +627,7 @@ public static List<string> GetTopTraits(List<string> championList, int depthLeve
561627
*/
562628

563629

564-
public static ConcurrentDictionary<List<string>, int> FindCombinations2(int CompSize, List<string> items, List<string> excluded_comp_champions, List<string> tempIncludeTrait, List<string> tempIncludeSpatula)
630+
public static ConcurrentDictionary<List<string>, int> FindCombinations2(int CompSize, List<string> items, List<string> excluded_comp_champions, List<string> tempIncludeTrait, List<string> tempIncludeSpatula, string trait_snake)
565631
{
566632
var combinations = GetCombs(items.Count(), CompSize);
567633

0 commit comments

Comments
 (0)