$min = 1000;
$storage = $min_array = ['Common' => array(), 'Uncommon' => array(), 'Rare' => array()];
for ($i = 1; $i <= $t->handSize(); $i++) {
$cur_card = $t->getCard($t->myData()->Hand[$i]);
$rarity = $cur_card->getRarity();
if ($i != $t->cardPos() && ($cur_card->hasKeyword('Barbarian') || $cur_card->hasKeyword('Soldier'))) {
$recruits_cost = $cur_card->getResources('Recruits');
$storage[$rarity][$i] = $recruits_cost;
$min = min($recruits_cost, $min);
}
}
if ((count($storage['Common']) + count($storage['Uncommon']) + count($storage['Rare'])) > 0) {
foreach ($storage as $rarity => $rarity_cards) {
foreach ($rarity_cards as $c_pos => $c_cost) {
if ($c_cost == $min) {
$min_array[$rarity][] = $c_pos;
}
}
}
shuffle($min_array['Common']);
shuffle($min_array['Uncommon']);
shuffle($min_array['Rare']);
$min_array = array_merge($min_array['Common'], $min_array['Uncommon'], $min_array['Rare']);
$discarded_pos = array_shift($min_array);
$t->setCard('my', $discarded_pos, $t->drawCard($t->myDeck(), $t->myData()->Hand, $discarded_pos, 'drawCardRandom'));
$t->myData()->addStock(3);
}