Skip to content

Commit

Permalink
Fixed card detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rembound committed Apr 13, 2018
1 parent 014ba1f commit 3503201
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 117 deletions.
114 changes: 62 additions & 52 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public string Author

public Version Version
{
get { return new Version("0.9.0"); }
get { return new Version("0.9.1"); }
}

public MenuItem MenuItem
Expand Down Expand Up @@ -1411,69 +1411,79 @@ private void PickHero(int heroindex)
private async Task SearchCards()
{
Card[] cards = new Card[3];
bool valid = false;

Log.Info("GetArenaDraftChoices");
List<HearthMirror.Objects.Card> choices = Reflection.GetArenaDraftChoices();
if (choices != null)

if (choices == null)
return;

if (choices.Count != 3)
return;

// Check if cards are valid and not hero cards
int validCards = 0;
for (int i = 0; i < 3; i++)
{
if (choices.Count == 3)
{
for (int i = 0; i < 3; i++)
{
cards[i] = GetCard(choices[i].Id);
Log.Info("Choice: " + choices[i].Id);
}
cards[i] = GetCard(choices[i].Id);

// Check for same cards
bool samecardsdetected = false;
if (previouscards.Count == 3)
{
int samecards = 0;
for (int i = 0; i < 3; i++)
{
if (previouscards[i].Id == cards[i].Id)
{
samecards++;
}
}
if (cards[i].Type != "Hero") {
validCards++;
Log.Info("Choice: " + choices[i].Id);
}
}

if (samecards == 3)
{
// All the same cards, can be valid but unlikely
samecardsdetected = true;
}
}
if (validCards != 3)
return;

// Save card choices
previouscards.Clear();
for (int i = 0; i < 3; i++)
// Check for same cards
bool samecardsdetected = false;
if (previouscards.Count == 3)
{
int samecards = 0;
for (int i = 0; i < 3; i++)
{
if (previouscards[i].Id == cards[i].Id)
{
previouscards.Add(cards[i]);
samecards++;
}
}

// Wait for confirmations when same cards detected
if (samecardsdetected)
{
if (!samecarddelay)
{
Log.Info("Same cards detected: delaying");
samecardtime = DateTime.Now;
samecarddelay = true;
}
else if (DateTime.Now.Subtract(samecardtime).TotalMilliseconds >= samecardmaxtime)
{
samecarddelay = false;
valid = true;
}
if (samecards == 3)
{
// All the same cards, can be valid but unlikely
samecardsdetected = true;
}
}

}
else
{
samecarddelay = false;
valid = true;
}
// Save card choices
previouscards.Clear();
for (int i = 0; i < 3; i++)
{
previouscards.Add(cards[i]);
}

bool valid = false;
// Wait for confirmations when same cards detected
if (samecardsdetected)
{
if (!samecarddelay)
{
Log.Info("Same cards detected: delaying");
samecardtime = DateTime.Now;
samecarddelay = true;
}
else if (DateTime.Now.Subtract(samecardtime).TotalMilliseconds >= samecardmaxtime)
{
samecarddelay = false;
valid = true;
}

}
else
{
samecarddelay = false;
valid = true;
}

if (valid)
Expand Down
83 changes: 19 additions & 64 deletions data/cardtier.json
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,7 @@
"value": [
"102",
"103",
"112",
"111",
"103",
"100",
"112",
Expand Down Expand Up @@ -5118,7 +5118,7 @@
"id": "GIL_653",
"name": "Woodcutter's Axe",
"value": [
"173",
"196",
"",
"",
"",
Expand Down Expand Up @@ -5238,7 +5238,7 @@
"id": "ICC_064",
"name": "Blood Razor",
"value": [
"124",
"156",
"",
"",
"",
Expand Down Expand Up @@ -5373,15 +5373,15 @@
"id": "GIL_624",
"name": "Night Prowler",
"value": [
"76",
"74",
"77",
"75",
"68",
"77",
"69",
"77",
"78",
"70",
"68",
"76",
"77"
"76"
]
},
{
Expand Down Expand Up @@ -5898,15 +5898,15 @@
"id": "UNG_072",
"name": "Stonehill Defender",
"value": [
"122",
"130",
"149",
"120",
"124",
"135",
"110",
"132",
"126"
"134",
"142",
"163",
"145",
"137",
"148",
"129",
"145",
"138"
]
},
{
Expand Down Expand Up @@ -7626,7 +7626,7 @@
"",
"",
"",
"169*",
"201*",
"",
"",
"",
Expand Down Expand Up @@ -8999,21 +8999,6 @@
""
]
},
{
"id": "EX1_295",
"name": "Ice Block",
"value": [
"",
"",
"",
"",
"",
"",
"",
"48",
""
]
},
{
"id": "NEW1_040",
"name": "Hogger",
Expand Down Expand Up @@ -10431,7 +10416,7 @@
"",
"",
"",
"158",
"178",
"",
"",
"",
Expand Down Expand Up @@ -11189,21 +11174,6 @@
"104"
]
},
{
"id": "EX1_050",
"name": "Coldlight Oracle",
"value": [
"34",
"34",
"34",
"31",
"32",
"34",
"26",
"34",
"34"
]
},
{
"id": "LOOT_365",
"name": "Gemstudded Golem",
Expand Down Expand Up @@ -11384,21 +11354,6 @@
""
]
},
{
"id": "EX1_620",
"name": "Molten Giant",
"value": [
"30",
"29",
"30",
"27",
"28",
"30",
"26",
"30",
"31"
]
},
{
"id": "GIL_835",
"name": "Squashling",
Expand Down
2 changes: 1 addition & 1 deletion data/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"hashlist": "0.1.3",
"tierlist": "0.1.64"
"tierlist": "0.1.65"
}

0 comments on commit 3503201

Please sign in to comment.