Skip to content

Commit

Permalink
Finish migrating base cards and adding no-op effects
Browse files Browse the repository at this point in the history
  • Loading branch information
micahstairs committed Sep 22, 2024
1 parent 8d4dbe4 commit d6aeea8
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 105 deletions.
14 changes: 14 additions & 0 deletions modules/Innovation/Cards/AbstractCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,12 @@ protected function hasIcon(?array $card, int $icon): bool
return $this->game->hasRessource($card, $icon);
}

protected function hasDemandEffect(int $cardId): bool
{
$card = $this->game->getCardInfo($cardId);
return $card['has_demand'] == true;
}

protected function getBonuses(int $playerId = null): array
{
return $this->game->getVisibleBonusesOnBoard(self::coercePlayerId($playerId));
Expand Down Expand Up @@ -981,6 +987,14 @@ protected static function getValue(?array $card): int
return Locations::isFaceup($card['location']) ? intval($card['faceup_age']) : intval($card['age']);
}

protected static function getFaceupValue(?array $card): int
{
if (!$card) {
return 0;
}
return intval($card['faceup_age']);
}

protected static function getId(?array $card): int|null
{
if (!$card) {
Expand Down
4 changes: 2 additions & 2 deletions modules/Innovation/Cards/Artifacts/Card197_3E.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function initialExecution()
self::setMaxSteps(1);
} else {
foreach (self::getTopCards() as $card) {
if ($card['has_demand'] == true) {
if (self::hasDemandEffect($card)) {
self::draw(10);
return;
}
Expand All @@ -40,7 +40,7 @@ public function getInteractionOptions(): array
public function compelMightBeEffective(): bool
{
foreach (self::getTopCards() as $card) {
if ($card['has_demand'] == true) {
if (self::hasDemandEffect($card)) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/Innovation/Cards/Artifacts/Card197_4E.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function initialExecution()
{
if (self::isCompel()) {
foreach (self::getTopCards() as $card) {
if ($card['has_demand'] == true) {
if (self::hasDemandEffect($card)) {
self::transferToScorePile(self::getBottomCardOfColor($card['color']), self::getLauncherId());
self::transferToScorePile(self::getBottomCardOfColor($card['color']), self::getLauncherId());
}
Expand All @@ -43,7 +43,7 @@ public function handleCardChoice(array $card)
public function compelMightBeEffective(): bool
{
foreach (self::getTopCards() as $card) {
if ($card['has_demand'] == true) {
if (self::hasDemandEffect($card)) {
return true;
}
}
Expand Down
39 changes: 18 additions & 21 deletions modules/Innovation/Cards/Base/Card440.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Innovation\Cards\Base;

use Innovation\Cards\AbstractCard;
use Innovation\Enums\Locations;

class Card440 extends AbstractCard
{
Expand All @@ -26,32 +27,16 @@ public function getInteractionOptions(): array
{
if (self::isDemand()) {
if (self::isFirstInteraction()) {
return [
'player_id' => self::getLauncherId(),
'choose_icon_type' => true,
// TODO(4E): Non-standard icons should be an option too here.
'icon' => [1, 3, 4, 5, 6, 7],
];
// TODO(4E): Non-standard icons should be an option too here (and use constants).
return self::youMust()->chooseIcon([1, 3, 4, 5, 6, 7])->ofMyChoice()->build();
} else {
return [
'location_from' => 'board',
'return_keyword' => true,
'with_icon' => self::getAuxiliaryValue(),
];
return self::youMust()->return()->exactly(2)->fromYourBoard()->withIcon(self::getAuxiliaryValue())->refreshingSelection()->build();
}
}
if (self::isFirstInteraction()) {
return [
'location_from' => 'board',
'return_keyword' => true,
];
return self::youMust()->return()->fromYourBoard()->build();
} else {
return [
'n' => 'all',
'location_from' => 'score',
'return_keyword' => true,
'age_min' => self::getAuxiliaryValue(),
];
return self::youMust()->return()->all()->fromYourScore()->minValue(self::getAuxiliaryValue())->build();
}
}

Expand All @@ -71,4 +56,16 @@ public function handleIconChoice(int $icon)
self::notifyIconChoice($icon);
self::setAuxiliaryValue($icon);
}

public function demandMightBeEffective(): bool
{
// NOTE: This could be improved by filtering out stacks where the top card has only [HEALTH] icons.
return self::hasCards(Locations::BOARD);
}

public function nonDemandsMightBeEffective(): bool
{
return self::hasCards(Locations::BOARD) || self::hasCards(Locations::SCORE);
}

}
8 changes: 1 addition & 7 deletions modules/Innovation/Cards/Base/Card441.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ public function initialExecution()

public function getInteractionOptions(): array
{
return [
'n' => 'all',
'location_from' => 'pile',
'return_keyword' => true,
'color' => [self::getAuxiliaryValue()],
'card_ids_are_in_auxiliary_array' => true,
];
return self::youMust()->return()->all()->fromYourBoard()->withColor(self::getAuxiliaryValue())->onlyCardsInAuxiliaryArray()->build();
}

public function afterInteraction()
Expand Down
2 changes: 1 addition & 1 deletion modules/Innovation/Cards/Base/Card442.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function initialExecution()
{
if (self::isFirstNonDemand()) {
$revealedCard = self::drawAndReveal(11);
$color = $revealedCard['color'];
$color = self::getColor($revealedCard);
if (self::splayAslant($color)) {
$stack = self::getStack($color);
for ($i = 0; $i < count($stack) - 4; $i++) {
Expand Down
17 changes: 7 additions & 10 deletions modules/Innovation/Cards/Base/Card443.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Innovation\Cards\Base;

use Innovation\Cards\AbstractCard;
use Innovation\Enums\Locations;

class Card443 extends AbstractCard
{
Expand All @@ -20,16 +19,9 @@ public function initialExecution()
public function getInteractionOptions(): array
{
if (self::isFirstInteraction()) {
return [
'choose_value' => true,
'age' => self::getAuxiliaryArray(),
];
return self::youMust()->chooseValue(self::getAuxiliaryArray())->build();
} else {
return [
'location_from' => Locations::BOARD,
'score_keyword' => true,
'age' => self::getAuxiliaryValue(),
];
return self::youMust()->score()->fromYourBoard()->value(self::getAuxiliaryValue())->build();
}
}

Expand All @@ -46,4 +38,9 @@ public function handleValueChoice(int $value)
self::setAuxiliaryValue($value); // Track value to score next
}

public function nonDemandsMightBeEffective(): bool
{
return count(self::filterByValue(self::getTopCards(), [11])) > 0;
}

}
25 changes: 8 additions & 17 deletions modules/Innovation/Cards/Base/Card444.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Innovation\Cards\Base;

use Innovation\Cards\AbstractCard;
use Innovation\Enums\Locations;

class Card444 extends AbstractCard
{
Expand All @@ -26,25 +25,17 @@ public function getInteractionOptions(): array
if (self::isFirstInteraction()) {
$topCards = self::getTopCards();
$colors = self::getColorsMatchingValues($topCards, self::getRepeatedValues($topCards));
return [
'location_from' => Locations::BOARD,
'return_keyword' => true,
'color' => $colors,
];
return self::youMust()->return()->fromYourBoard()->withColor($colors)->build();
} else if (self::isSecondInteraction()) {
return [
'location_from' => Locations::BOARD,
'return_keyword' => true,
'age' => self::getLastSelectedFaceUpAge(),
];
return self::youMust()->return()->fromYourBoard()->value(self::getAuxiliaryValue())->non(self::getLastSelectedColor())->build();
} else {
return [
'n' => 'all',
'location_from' => Locations::HAND_OR_SCORE,
'return_keyword' => true,
'age_max' => self::getLastSelectedFaceUpAge(),
];
return self::youMust()->return()->all()->fromYourHandOrScore()->maxValue(self::getAuxiliaryValue())->build();
}
}

public function demandMightBeEffective(): bool
{
return count(self::getRepeatedValues(self::getTopCards())) > 0;
}

}
4 changes: 2 additions & 2 deletions modules/Innovation/Cards/Base/Card445.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function initialExecution()
{
do {
$card = self::drawAndTuck(11);
$color = $card['color'];
$color = self::getColor($card);
$stack = self::getStack($color);

if (count($stack) >= 2 && self::getValue($stack[1]) === 11) {
self::lose();
return;
Expand Down
22 changes: 12 additions & 10 deletions modules/Innovation/Cards/Base/Card446.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ class Card446 extends AbstractCard

public function getInteractionOptions(): array
{
$maxScoreValue = self::getMaxValueInLocation(Locations::SCORE);
if (self::isDemand()) {
return [
'player_id' => self::getLauncherId(),
'choose_value' => true,
];
return self::youMust()->chooseValue()->ofMyChoice()->build();
} else {
return [
'location_from' => Locations::SCORE,
'location_to' => Locations::REVEALED,
'age' => $maxScoreValue,
];
return self::youMust()->reveal()->highest()->fromYourScore()->build();
}
}

Expand All @@ -44,4 +36,14 @@ public function handleCardChoice(array $card)
}
}

public function demandMightBeEffective(): bool
{
return self::hasCards(Locations::SCORE);
}

public function nonDemandsMightBeEffective(): bool
{
return self::hasCards(Locations::SCORE);
}

}
14 changes: 4 additions & 10 deletions modules/Innovation/Cards/Base/Card447.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,14 @@ public function getInteractionOptions(): array
$cardIds = [];
foreach (self::getStack($color) as $card) {
if ($card['position'] < 3) {
$cardIds[] = $card['id'];
$cardIds[] = self::getId($card);
}
}
self::setAuxiliaryArray($cardIds);

self::setAuxiliaryValue2(0); // Track the sum of the values of the cards being returned

return [
'n' => count($cardIds),
'location_from' => Locations::PILE,
'color' => [$color],
'return_keyword' => true,
'card_ids_are_in_auxiliary_array' => true,
];
return self::youMust()->return()->exactly(count($cardIds))->yourStack($color)->onlyCardsInAuxiliaryArray()->build();
}

public function handleAbortedInteraction()
Expand All @@ -51,14 +45,14 @@ public function handleAbortedInteraction()

public function handleCardChoice(array $card)
{
self::incrementAuxiliaryValue2($card['faceup_age']);
self::incrementAuxiliaryValue2(self::getFaceupValue($card));
}

public function afterInteraction()
{
$card = self::drawAndMeld(ceil(self::getAuxiliaryValue2() / 2));
if (self::getNumChosen() === 3) {
self::setAuxiliaryValue($card['color']);
self::setAuxiliaryValue(self::getColor($card));
self::setNextStep(1);
}
}
Expand Down
19 changes: 8 additions & 11 deletions modules/Innovation/Cards/Base/Card448.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ class Card448 extends AbstractCard
public function getInteractionOptions(): array
{
if (self::isFirstInteraction()) {
return ['choose_from' => Locations::HAND];
self::setAuxiliaryValue(-1); // Track the ID of the junked card
return self::youMust()->chooseCardFrom(Locations::HAND)->build();
} else {
return [
'n' => 'all',
'location_from' => Locations::HAND,
'return_keyword' => true,
'age' => self::getLastSelectedFaceUpAge(),
];
return self::youMust()->return()->all()->fromYourHand()->value(self::getLastSelectedFaceUpAge())->build();
}
}

Expand All @@ -31,7 +27,7 @@ public function handleCardChoice(array $card)
if (self::isFirstInteraction()) {
$this->game->revealCardWithoutMoving(self::getPlayerId(), $card);
self::junk($card);
self::setAuxiliaryValue($card['id']);
self::setAuxiliaryValue(self::getId($card));
self::setMaxSteps(2);
}
}
Expand All @@ -40,9 +36,10 @@ public function afterInteraction()
{
if (self::isSecondInteraction()) {
$card = self::getCard(self::getAuxiliaryValue());
self::draw($card['faceup_age']);
self::draw($card['faceup_age']);
self::draw($card['faceup_age']);
$value = self::getFaceupValue($card);
self::draw($value);
self::draw($value);
self::draw($value);
self::selfExecute($card);
}
}
Expand Down
19 changes: 11 additions & 8 deletions modules/Innovation/Cards/Base/Card449.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ class Card449 extends AbstractCard

public function getInteractionOptions(): array
{
return [
'n' => 'all',
'owner_from' => self::getPlayerId(),
'location_from' => Locations::BOARD,
'owner_to' => self::getLauncherId(),
'location_to' => Locations::BOARD,
'has_demand_effect' => true,
];
return self::youMust()->all()->withDemandEffect()->fromYourBoard()->toMine()->build();
}

public function afterInteraction()
Expand All @@ -39,4 +32,14 @@ public function afterInteraction()
}
}

public function demandMightBeEffective(): bool
{
foreach (self::getTopCards() as $card) {
if (self::hasDemandEffect($card)) {
return true;
}
}
return false;
}

}
Loading

0 comments on commit d6aeea8

Please sign in to comment.