Help implementing a card
Moderators: BetaSteward, noxx, jeffwadsworth, JayDi, TheElk801, LevelX, North, CCGHQ Admins
Re: Help implementing a card
by Backfir3 » 09 Jul 2012, 16:51
I think it always return false, maybe you should return true somewhere after the case.jeffwadsworth wrote:
- Code: Select all
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case GAIN_LIFE:
if (event.getPlayerId().equals(source.getControllerId())) {
event.setAmount(event.getAmount() * 2);
}
}
return false;
}
Re: Help implementing a card
by jeffwadsworth » 10 Jul 2012, 01:03
I thought the same, but that simply results in a null event...Backfir3 wrote:I think it always return false, maybe you should return true somewhere after the case.jeffwadsworth wrote:
- Code: Select all
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case GAIN_LIFE:
if (event.getPlayerId().equals(source.getControllerId())) {
event.setAmount(event.getAmount() * 2);
}
}
return false;
}
I tested other cards using the same event.setAmount and they all work. It may be that life gain is not using it.
- jeffwadsworth
- Super Tester Elite
- Posts: 1172
- Joined: 20 Oct 2010, 04:47
- Location: USA
- Has thanked: 287 times
- Been thanked: 70 times
Re: Help implementing a card
by noxx » 12 Jul 2012, 01:26
I fixed both GAIN_LIFE and LOSE_LIFE events, now updated amount should be taken into account.
Also in replacement effects that _updates_ the event you should always return false. True should be returned only when one event is replaced by another or removed totally: usually it is used for effects saying that you do something different instead (e.g. "if a player would gain life, it loses that much life instead" or "players can't gain life").
Best Regards,
Noxx
Also in replacement effects that _updates_ the event you should always return false. True should be returned only when one event is replaced by another or removed totally: usually it is used for effects saying that you do something different instead (e.g. "if a player would gain life, it loses that much life instead" or "players can't gain life").
Best Regards,
Noxx
Re: Help implementing a card
by jeffwadsworth » 22 Jul 2012, 21:51
Working on Spelltwine. The following code does not exile any of the cards. Does anyone see the issue?
- Code: Select all
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.magic2013;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.filter.FilterCard;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInOpponentsGraveyard;
import mage.target.common.TargetCardInYourGraveyard;
/**
*
* @author jeffwadsworth
*/
public class Spelltwine extends CardImpl<Spelltwine> {
private final static FilterCard filter = new FilterCard("instant or sorcery card from your graveyard");
private final static FilterCard filter2 = new FilterCard("instant or sorcery card from an opponent's graveyard");
static {
filter.add(Predicates.or(
new CardTypePredicate(CardType.INSTANT),
new CardTypePredicate(CardType.SORCERY)));
}
static {
filter2.add(Predicates.or(
new CardTypePredicate(CardType.INSTANT),
new CardTypePredicate(CardType.SORCERY)));
}
public Spelltwine(UUID ownerId) {
super(ownerId, 68, "Spelltwine", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{5}{U}");
this.expansionSetCode = "M13";
this.color.setBlue(true);
// Exile target instant or sorcery card from your graveyard and target instant or sorcery card from an opponent's graveyard. Copy those cards. Cast the copies if able without paying their mana costs. Exile Spelltwine.
this.getSpellAbility().addEffect(new SpelltwineEffect());
this.getSpellAbility().addTarget(new TargetCardInYourGraveyard(filter));
this.getSpellAbility().addTarget(new TargetCardInOpponentsGraveyard(filter2));
}
public Spelltwine(final Spelltwine card) {
super(card);
}
@Override
public Spelltwine copy() {
return new Spelltwine(this);
}
}
class SpelltwineEffect extends OneShotEffect<SpelltwineEffect> {
public SpelltwineEffect() {
super(Constants.Outcome.PlayForFree);
staticText = "Exile target instant or sorcery card from your graveyard and target instant or sorcery card from an opponent's graveyard. Copy those cards. Cast the copies if able without paying their mana costs. Exile {this}";
}
public SpelltwineEffect(final SpelltwineEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Card cardOne = game.getCard(source.getTargets().get(0).getFirstTarget());
Card cardTwo = game.getCard(source.getTargets().get(1).getFirstTarget());
if (you != null) {
if (cardOne != null) {
cardOne.moveToExile(null, "Exiled card from your graveyard", source.getId(), game);
Card copyOne = cardOne.copy();
copyOne.setControllerId(source.getControllerId());
you.cast(copyOne.getSpellAbility(), game, true);
}
if (cardTwo != null) {
cardTwo.moveToExile(null, "Exiled card from opponent's graveyard", source.getId(), game);
Card copyTwo = cardTwo.copy();
copyTwo.setControllerId(source.getControllerId());
you.cast(copyTwo.getSpellAbility(), game, true);
}
Card spelltwine = game.getCard(source.getSourceId());
if (spelltwine != null) {
spelltwine.moveToExile(null, "Exiled Spelltwine", source.getId(), game);
}
return true;
}
return false;
}
@Override
public SpelltwineEffect copy() {
return new SpelltwineEffect(this);
}
}
- jeffwadsworth
- Super Tester Elite
- Posts: 1172
- Joined: 20 Oct 2010, 04:47
- Location: USA
- Has thanked: 287 times
- Been thanked: 70 times
Re: Help implementing a card
by noxx » 23 Jul 2012, 04:11
Hi,
First of all, the card you cast can't be exiled inside effect because it will go to graveyard on resolution anyway. What you need in such cases is PostResolveEffect to be implemented that will exile it instead.
And for "exile {this}" effects there is PostResolveEffect already created so all you need is just to add:
Next is about the cards you target in graveyard, exile and copy.
Whenever you call card.copy() you create exact copy of the card. You don't create a clone copy, but just make another reference to it. So your code exiles the same card, but then you cast it that again according to rules puts it to the graveyard so that's why it looks like the exile effect doesn't work: but it works, the game just puts the same card back to graveyard.
What should be done in such cases is giving new id to the copied card and adding it to the game so it could track it:
Noxx
First of all, the card you cast can't be exiled inside effect because it will go to graveyard on resolution anyway. What you need in such cases is PostResolveEffect to be implemented that will exile it instead.
And for "exile {this}" effects there is PostResolveEffect already created so all you need is just to add:
- Code: Select all
this.getSpellAbility().addEffect(ExileSpellEffect.getInstance());
Next is about the cards you target in graveyard, exile and copy.
Whenever you call card.copy() you create exact copy of the card. You don't create a clone copy, but just make another reference to it. So your code exiles the same card, but then you cast it that again according to rules puts it to the graveyard so that's why it looks like the exile effect doesn't work: but it works, the game just puts the same card back to graveyard.
What should be done in such cases is giving new id to the copied card and adding it to the game so it could track it:
- Code: Select all
if (cardTwo != null) {
cardTwo.moveToExile(null, "Exiled card from opponent's graveyard", source.getId(), game);
Card copyTwo = cardTwo.copy();
copyTwo.assignNewId();
copyTwo.setControllerId(source.getControllerId());
Set<Card> cards = new HashSet<Card>();
cards.add(copyTwo);
game.loadCards(cards, source.getControllerId());
you.cast(copyTwo.getSpellAbility(), game, true);
}
- Code: Select all
Card copyTwo = game.copyCard(cardTwo, source, newController);
Noxx
Re: Help implementing a card
by jeffwadsworth » 04 Aug 2012, 03:44
Working on Kederekt Parasite. The following code does not treat the ability as optional. Does anyone see the issue?
The card code:
The card code:
- Code: Select all
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.conflux;
import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.Constants.TargetController;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.DrawCardOpponentTriggeredAbility;
import mage.abilities.condition.common.ControlsPermanentCondition;
import mage.abilities.decorator.ConditionalTriggeredAbility;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.filter.FilterPermanent;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
/**
*
* @author jeffwadsworth
*/
public class KederektParasite extends CardImpl<KederektParasite> {
private static final FilterPermanent filter = new FilterPermanent("red permanent");
static {
filter.add(new ColorPredicate(ObjectColor.RED));
filter.add(new ControllerPredicate(TargetController.YOU));
}
public KederektParasite(UUID ownerId) {
super(ownerId, 48, "Kederekt Parasite", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{B}");
this.expansionSetCode = "CON";
this.subtype.add("Horror");
this.color.setBlack(true);
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// Whenever an opponent draws a card, if you control a red permanent, you may have Kederekt Parasite deal 1 damage to that player.
TriggeredAbility ability = new DrawCardOpponentTriggeredAbility(new DamageTargetEffect(1), true);
this.addAbility(new ConditionalTriggeredAbility(ability, new ControlsPermanentCondition(filter), "Whenever an opponent draws a card, if you control a red permanent, you may have {this} deal 1 damage to that player."));
}
public KederektParasite(final KederektParasite card) {
super(card);
}
@Override
public KederektParasite copy() {
return new KederektParasite(this);
}
}
- Code: Select all
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.Constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author jeffwadsworth
*/
public class DrawCardOpponentTriggeredAbility extends TriggeredAbilityImpl<DrawCardOpponentTriggeredAbility> {
public DrawCardOpponentTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
}
public DrawCardOpponentTriggeredAbility(final DrawCardOpponentTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DREW_CARD && !event.getPlayerId().equals(controllerId)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever an opponent draws a card, " + super.getRule();
}
@Override
public DrawCardOpponentTriggeredAbility copy() {
return new DrawCardOpponentTriggeredAbility(this);
}
}
- jeffwadsworth
- Super Tester Elite
- Posts: 1172
- Joined: 20 Oct 2010, 04:47
- Location: USA
- Has thanked: 287 times
- Been thanked: 70 times
Re: Help implementing a card
by noxx » 14 Aug 2012, 09:27
Do you still need a help with the card or was it finally implemented?
BR,
Noxx
BR,
Noxx
Re: Help implementing a card
by jeffwadsworth » 14 Aug 2012, 18:53
I moved on. It never did work. On a side note, alternative costs text does not display. Example: Firewild Borderpost
- jeffwadsworth
- Super Tester Elite
- Posts: 1172
- Joined: 20 Oct 2010, 04:47
- Location: USA
- Has thanked: 287 times
- Been thanked: 70 times
Re: Help implementing a card
by noxx » 15 Aug 2012, 06:34
Didn't know about Firewild Borderpost alternative cost not displayed.
Finally commited a failing test for it and made fix for rule text displayed that ignored alternative costs.
Best Regards,
Noxx
Finally commited a failing test for it and made fix for rule text displayed that ignored alternative costs.
Best Regards,
Noxx
Re: Help implementing a card
by cbt33 » 24 Aug 2012, 02:15
I made an attempt at Ali Baba and I'm iffy on these lines.
I have no experience with Java only MATLAB but am I on the right track so far?
- Code: Select all
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Wall");
static {
filter.add(new SubtypePredicate("Wall"));
}
Ability ability = new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new TapTargetEffect(), new ColoredManaCost(Constants.ColoredManaSymbol.R));
ability.addTarget(new TargetCreaturePermanent(filter));
this.addAbility(ability);
}
I have no experience with Java only MATLAB but am I on the right track so far?
Re: Help implementing a card
by Plopman » 27 Aug 2012, 14:06
Hi,
I created some new cards. Can you add it to the main projet. If you want, I can create more cards.
I created some new cards. Can you add it to the main projet. If you want, I can create more cards.
- Attachments
-
Plopman.zip- (7.55 KiB) Downloaded 488 times
Re: Help implementing a card
by North » 28 Aug 2012, 05:12
Thank you Plopman. I'll look over them and commit them to the project.Plopman wrote:Hi,
I created some new cards. Can you add it to the main projet. If you want, I can create more cards.
As for the second part, please do create more cards.
Re: Help implementing a card
by Plopman » 28 Aug 2012, 13:23
I create 10 new cards
- Attachments
-
ULG.zip- (3.88 KiB) Downloaded 457 times
Re: Help implementing a card
by North » 28 Aug 2012, 14:01
Thank you. I'll add this cards too.Plopman wrote:I create 10 new cards
Who is online
Users browsing this forum: No registered users and 2 guests