Skip to content

Commit 2c2b788

Browse files
committed
Unlock conditions check + crash fixes
1 parent e25b3fa commit 2c2b788

5 files changed

Lines changed: 267 additions & 33 deletions

File tree

TFT Comp Creator 2/Form1.Designer.cs

Lines changed: 13 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: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace TFT_Comp_Creator_2
1515
{
1616

17+
1718
public partial class Form1 : Form
1819
{
1920
public static string status;
@@ -41,12 +42,16 @@ public struct ChampionStats
4142

4243
public struct UnlockConditions
4344
{
44-
public string[] Champions;
45-
public int minChampions; // Field 5 Yordles or Bilgewater units + Level 7
46-
public string[] Traits;
47-
public int[] TraitMinBP;
48-
public int minLevel;
45+
public List<string> Champions;
46+
public List<int> minChampions; // Field 5 Yordles or Bilgewater units + Level 7
4947

48+
public List<string> Traits;
49+
public List<int> TraitMinBP;
50+
51+
public List<string> ChampTraitCount;
52+
public List<int> minChampTraitCount;
53+
54+
public int minLevel;
5055
public bool isAnd; // eg. unlock requires 2 champions or either one of them
5156
}
5257

@@ -71,7 +76,21 @@ public struct Champion
7176
public static Dictionary<string, Trait> TraitList = new Dictionary<string, Trait>();
7277

7378

79+
public struct CompKey : IEquatable<CompKey>
80+
{
81+
public readonly string Key;
82+
public readonly List<string> Comp;
7483

84+
public CompKey(List<string> comp)
85+
{
86+
Comp = comp;
87+
Key = string.Join(",", comp); // stable hash
88+
}
89+
90+
public bool Equals(CompKey other) => Key == other.Key;
91+
public override bool Equals(object obj) => obj is CompKey other && Equals(other);
92+
public override int GetHashCode() => Key.GetHashCode();
93+
}
7594

7695

7796
public bool ForceStop = false;
@@ -152,7 +171,8 @@ public Form1()
152171
carryCheck_unspecified,
153172
mustMaxOutTraitLevel,
154173
mustMaxOutTraitLevelCurrent,
155-
isSpatulaGolem
174+
isSpatulaGolem,
175+
ignoreUnlock
156176

157177
);
158178

@@ -476,14 +496,16 @@ public void n_choose_k(int size, List<string> nodes, List<string> tempIncludeTra
476496
{
477497
JObject champions_found = new JObject();
478498

479-
ConcurrentDictionary<List<string>, int> parallel_results = FindCombinations2(size, nodes, tempIncludeTrait, tempIncludeSpatula, current_trait, comp);
499+
ConcurrentDictionary<CompKey, int> parallel_results = FindCombinations2(size, nodes, tempIncludeTrait, tempIncludeSpatula, current_trait, comp);
480500

481-
ConcurrentDictionary<List<string>, int> parallel_results_best = new ConcurrentDictionary<List<string>, int>();
501+
ConcurrentDictionary<CompKey, int> parallel_results_best = new ConcurrentDictionary<CompKey, int>();
482502

483503
if (mustMaxOutTraitLevelCurrent.Checked)
484504
{
485-
foreach (List<string> compParallel in parallel_results.Keys)
505+
foreach (var compKey in parallel_results.Keys)
486506
{
507+
List<string> compParallel = compKey.Comp;
508+
487509
JObject JTraits = constructJTraits(compParallel);
488510
if (!JTraits.ContainsKey(current_trait)) { continue; }
489511

@@ -502,12 +524,12 @@ public void n_choose_k(int size, List<string> nodes, List<string> tempIncludeTra
502524
if (maxValidBP < breakpoints.Max(bp => (int)bp))
503525
{
504526
if (result == maxValidBP)
505-
parallel_results_best[compParallel] = parallel_results[compParallel];
527+
parallel_results_best[compKey] = parallel_results[compKey];
506528
}
507529
else
508530
{
509531
if (result == maxValidBP)
510-
parallel_results_best[compParallel] = parallel_results[compParallel];
532+
parallel_results_best[compKey] = parallel_results[compKey];
511533
}
512534
}
513535
}
@@ -525,8 +547,10 @@ public void n_choose_k(int size, List<string> nodes, List<string> tempIncludeTra
525547
emblemMaxBP = breakpoints.DefaultIfEmpty(0).Max(bp => (int)bp);
526548
}
527549

528-
foreach (List<string> compParallel in parallel_results.Keys)
550+
foreach (var compKey in parallel_results.Keys)
529551
{
552+
List<string> compParallel = compKey.Comp;
553+
530554
JObject JTraits = constructJTraits(compParallel);
531555
if (!JTraits.ContainsKey(selectedEmblemTrait)) { continue; }
532556

@@ -538,7 +562,7 @@ public void n_choose_k(int size, List<string> nodes, List<string> tempIncludeTra
538562

539563
if (result == emblemMaxBP)
540564
{
541-
parallel_results_best[compParallel] = parallel_results[compParallel];
565+
parallel_results_best[compKey] = parallel_results[compKey];
542566
}
543567
}
544568
}
@@ -561,11 +585,11 @@ public void n_choose_k(int size, List<string> nodes, List<string> tempIncludeTra
561585
if (obj.Value > Pet_SynergyBest)
562586
Pet_SynergyBest = obj.Value;
563587

564-
PrintComp(obj.Key, obj.Value);
588+
PrintComp(obj.Key.Comp, obj.Value);
565589

566590
// analysis
567591
//champions_found
568-
foreach (string champion_in_comp in obj.Key)
592+
foreach (string champion_in_comp in obj.Key.Comp)
569593
{
570594
if (champions_found[champion_in_comp] != null)
571595
{

TFT Comp Creator 2/Scoring.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class Scoring
3434
private static CheckBox mustMaxOutTraitLevel = new CheckBox();
3535
private static CheckBox mustMaxOutTraitLevelCurrent = new CheckBox();
3636
private static CheckBox isSpatulaGolem = new CheckBox();
37+
private static CheckBox ignoreUnlock = new CheckBox();
3738

3839

3940
public static ListBox include_spatula = new ListBox();
@@ -64,7 +65,8 @@ public static void SetFromScoring(
6465
CheckBox carryCheck_unspecified_,
6566
CheckBox mustMaxOutTraitLevel_,
6667
CheckBox mustMaxOutTraitLevelCurrent_,
67-
CheckBox isSpatulaGolem_
68+
CheckBox isSpatulaGolem_,
69+
CheckBox ignoreUnlock_
6870
)
6971
{
7072
no_error = NO;
@@ -95,6 +97,8 @@ CheckBox isSpatulaGolem_
9597
mustMaxOutTraitLevel = mustMaxOutTraitLevel_;
9698
mustMaxOutTraitLevelCurrent = mustMaxOutTraitLevelCurrent_;
9799
isSpatulaGolem = isSpatulaGolem_;
100+
101+
ignoreUnlock = ignoreUnlock_;
98102
}
99103
public static double CalculateVerticalityScore(List<string> comp, JObject JTraits)
100104
{
@@ -446,6 +450,12 @@ public static bool CheckCompValidity(List<string> comp)
446450

447451
}
448452

453+
// set 16
454+
if(!ignoreUnlock.Checked)
455+
{
456+
if(!checkUnlockConditions(JTraits, comp)) { return false; }
457+
}
458+
449459
if (carryCheck_unspecified.Checked)
450460
{
451461
if (!isCarryPresent(JTraits, comp))

0 commit comments

Comments
 (0)