From 871e5e9ce2a02b215c559e98367ead574edb9eb3 Mon Sep 17 00:00:00 2001 From: theelk801 Date: Fri, 20 Jun 2025 12:51:11 -0400 Subject: [PATCH] [PIP] Implement Inventory Management --- .../src/mage/cards/i/InventoryManagement.java | 109 ++++++++++++++++++ Mage.Sets/src/mage/sets/Fallout.java | 8 +- 2 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/i/InventoryManagement.java diff --git a/Mage.Sets/src/mage/cards/i/InventoryManagement.java b/Mage.Sets/src/mage/cards/i/InventoryManagement.java new file mode 100644 index 00000000000..ecaf2f9f119 --- /dev/null +++ b/Mage.Sets/src/mage/cards/i/InventoryManagement.java @@ -0,0 +1,109 @@ +package mage.cards.i; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.SplitSecondAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; +import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.Predicates; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetImpl; +import mage.target.TargetPermanent; +import mage.target.common.TargetControlledCreaturePermanent; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * @author TheElk801 + */ +public final class InventoryManagement extends CardImpl { + + public InventoryManagement(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{R}{W}"); + + // Split second + this.addAbility(new SplitSecondAbility()); + + // For each Aura and Equipment you control, you may attach it to a creature you control. + this.getSpellAbility().addEffect(new InventoryManagementEffect()); + } + + private InventoryManagement(final InventoryManagement card) { + super(card); + } + + @Override + public InventoryManagement copy() { + return new InventoryManagement(this); + } +} + +class InventoryManagementEffect extends OneShotEffect { + + private static final FilterPermanent filter = new FilterControlledPermanent("Aura or Equipment you control"); + + static { + filter.add(Predicates.or( + SubType.AURA.getPredicate(), + SubType.EQUIPMENT.getPredicate() + )); + } + + InventoryManagementEffect() { + super(Outcome.Benefit); + staticText = "for each Aura and Equipment you control, you may attach it to a creature you control"; + } + + private InventoryManagementEffect(final InventoryManagementEffect effect) { + super(effect); + } + + @Override + public InventoryManagementEffect copy() { + return new InventoryManagementEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null + || !game.getBattlefield().contains(filter, source, game, 1) + || !game.getBattlefield().contains(StaticFilters.FILTER_CONTROLLED_CREATURE, source, game, 1)) { + return false; + } + TargetPermanent target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true); + target.withChooseHint("to attach to a creature you control"); + player.choose(outcome, target, source, game); + List permanents = target + .getTargets() + .stream() + .map(game::getPermanent) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + if (permanents.isEmpty()) { + return false; + } + for (Permanent permanent : permanents) { + TargetPermanent targetCreature = new TargetControlledCreaturePermanent(0, 1); + targetCreature.withNotTarget(true); + targetCreature.withChooseHint("to attach " + permanent.getLogName() + " to"); + Optional.ofNullable(targetCreature) + .map(TargetImpl::getFirstTarget) + .map(game::getPermanent) + .ifPresent(p -> p.addAttachment(permanent.getId(), source, game)); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/Fallout.java b/Mage.Sets/src/mage/sets/Fallout.java index 0cf9a4160b3..03a71793216 100644 --- a/Mage.Sets/src/mage/sets/Fallout.java +++ b/Mage.Sets/src/mage/sets/Fallout.java @@ -430,10 +430,10 @@ public final class Fallout extends ExpansionSet { cards.add(new SetCardInfo("Intelligence Bobblehead", 1061, Rarity.UNCOMMON, mage.cards.i.IntelligenceBobblehead.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Intelligence Bobblehead", 134, Rarity.UNCOMMON, mage.cards.i.IntelligenceBobblehead.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Intelligence Bobblehead", 662, Rarity.UNCOMMON, mage.cards.i.IntelligenceBobblehead.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("Inventory Management", 105, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("Inventory Management", 342, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("Inventory Management", 633, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("Inventory Management", 870, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Inventory Management", 105, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Inventory Management", 342, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Inventory Management", 633, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Inventory Management", 870, Rarity.RARE, mage.cards.i.InventoryManagement.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Irrigated Farmland", 1027, Rarity.RARE, mage.cards.i.IrrigatedFarmland.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Irrigated Farmland", 268, Rarity.RARE, mage.cards.i.IrrigatedFarmland.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Irrigated Farmland", 499, Rarity.RARE, mage.cards.i.IrrigatedFarmland.class, NON_FULL_USE_VARIOUS));