It is currently 25 Apr 2024, 20:53
   
Text Size

"Blocking, or being blocked by"

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

"Blocking, or being blocked by"

Postby zerker2000 » 26 Jun 2009, 20:11

Quick question: what is the easiest way to get the canTarget cardList / CanPlay for an ability that targets creatures "blocking, or being blocked by" something? Also, is there a method "getOpponent(String player)" somewhere, or should I just put the
Code: Select all
String opponent;
if (card.getController==Constant.Player.Human)opponent=
Constant.Player.Computer/*.clone()?*/;
else opponent=Constant.Player.Human/*.clone()?*/;
in everywhere I need it?
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: "Blocking, or being blocked by"

Postby DennisBergkamp » 27 Jun 2009, 12:36

There is an AllZone.GameAction.getOpponent(String player) (a lot of the cards in CardFactory.java use it).

As for your first question, I'm not sure if there's an easy way of doing this, you'll have to play around with it... I know there's an AllZone.Combat.isBlocked(Card attacker) and an AllZone.Combat.getAllBlockers() (or AllZone.Combat.getBlockers(Card attacker)).
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: "Blocking, or being blocked by"

Postby zerker2000 » 01 Jul 2009, 07:40

Should this work?:
Code: Select all
    final Ability_Tap ability = new Ability_Tap(card){
       public boolean canPlay()
       {
          return card.isUntapped() && !card.hasSickness() && AllZone.GameAction.isCardInPlay(card) && (AllZone.Combat.isBlocked(card) || AllZone.Combat.getAllBlockers().contains(card));
       }
        public boolean canPlayAI()
        {
          return false;
          //TODO
        }
       public void resolve()
       {
          AllZone.GameAction.destroy(getTargetCard());
       }//resolve()
    };
    Input runtime = new Input()
    {
       public void showMessage()
       {
          CardList targets;
          if(AllZone.Combat.isBlocked(card) || AllZone.Combat.getAllBlockers().contains(card)){
             if (AllZone.Combat.isBlocked(card)){ targets = AllZone.Combat.getBlockers(card); }
             else {
                targets = new CardList();
                for (Card c : AllZone.Combat.getAttackers()){
                   if (AllZone.Combat.isBlocked(c))
                      if (AllZone.Combat.getBlockers(c).contains(card)) targets.add(c);
                }
             }
          }
          stopSetNext(CardFactoryUtil.input_targetSpecific(ability, targets, "Select target blocking or blocked by " + card, true));
       }
    };
    ability.setBeforePayMana(runtime);
    card.addSpellAbility(ability);
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: "Blocking, or being blocked by"

Postby DennisBergkamp » 01 Jul 2009, 15:41

Yes it should! Might not, but I think it will... by the way, for which card is this?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: "Blocking, or being blocked by"

Postby mtgrares » 02 Jul 2009, 18:40

Maybe you should add the "blocking, or being blocked by" code to Combat because you could reuse the code for other cards. Combat.isBlockedOrBeingBlocked(Card) and return a boolean.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 73 guests


Who is online

In total there are 73 users online :: 0 registered, 0 hidden and 73 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 73 guests

Login Form