Skip to content

Instantly share code, notes, and snippets.

@utilForever
Created March 27, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utilForever/26c3d8ae5759bc8a909c70df9c97226d to your computer and use it in GitHub Desktop.
Save utilForever/26c3d8ae5759bc8a909c70df9c97226d to your computer and use it in GitHub Desktop.
The logic of card 'Envoy of Lazul' (DRG_306)
// ---------------------------------------- MINION - PRIEST
// [DRG_306] Envoy of Lazul - COST:2 [ATK:2/HP:2]
// - Set: Dragons, Rarity: Epic
// --------------------------------------------------------
// Text: <b>Battlecry:</b> Look at 3 cards.
// Guess which one is in your opponent's hand
// to get a copy of it.
// --------------------------------------------------------
// GameTag:
// - BATTLECRY = 1
// --------------------------------------------------------
power.ClearData();
power.AddPowerTask(std::make_shared<CustomTask>(
[](Player* player, Entity* source, [[maybe_unused]] Playable* target) {
// Envoy of Lazul attempts to show three cards: one card in the
// opponent's hand, and two cards that are in the opponent's current
// deck but not in the opponent's hand.
auto opHandCards = player->opponent->GetHandZone()->GetAll();
// If the opponent has no cards in hand,
// Envoy of Lazul's Battlecry does nothing.
if (opHandCards.empty())
{
return;
}
std::vector<Card*> result;
result.reserve(3);
// For the one card in the opponent's hand:
// The card being shown in the opponent's hand does not have
// to be a card that started in the opponent's deck.
const auto idx =
Random::get<std::size_t>(0, opHandCards.size() - 1);
result.emplace_back(opHandCards[idx]->card);
// For the two cards not in the opponent's hand:
std::vector<Card*> opDeckCards;
for (auto& deckCard : player->opponent->GetDeckZone()->GetAll())
{
// Pass if it exists in hand zone
bool existInHand = false;
for (auto& handCard : opHandCards)
{
if (handCard->card->id == deckCard->card->id)
{
existInHand = true;
break;
}
}
if (existInHand)
{
continue;
}
// Pass if it exists in opponent deck cards
bool existInDeck = false;
for (auto& opDeckCard : opDeckCards)
{
if (opDeckCard->id == deckCard->card->id)
{
existInDeck = true;
break;
}
}
if (existInDeck)
{
continue;
}
opDeckCards.emplace_back(deckCard->card);
}
// If the opponent's current deck is empty, two cards that had
// started in the opponent's deck will be picked instead.
// If the opponent's current deck has only one card left, the same
// thing happens; two cards that had started in the opponent's deck
// will be picked instead.
if (opDeckCards.size() < 2)
{
const auto startDeck =
player->game->GetPlayerDeck(player->opponent->playerType);
auto twoCards = ChooseNElements(startDeck, 2);
result.emplace_back(twoCards[0]);
result.emplace_back(twoCards[1]);
}
else
{
auto twoCards = ChooseNElements(opDeckCards, 2);
result.emplace_back(twoCards[0]);
result.emplace_back(twoCards[1]);
}
Random::shuffle(result.begin(), result.end());
Generic::CreateChoiceCards(player, source, ChoiceType::GENERAL,
ChoiceAction::ENVOY_OF_LAZUL, result);
}));
cards.emplace("DRG_306", CardDef(power));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment