It is currently 11 Sep 2025, 16:55
   
Text Size

Can't attack or block alone

Post MTG Forge Related Programming Questions Here

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

Can't attack or block alone

Postby moomarc » 10 Jul 2012, 19:42

I'm currently trying to get "CARDNAME can't attack or block alone." keyword working but need some rules clarification. So far the basic setup is this (in GameAction.checkStateEffects):
Code: Select all
// Handles removing cards like Mogg Flunkies from combat
                    if (c.hasKeyword("CARDNAME can't attack or block alone.")) {
                        if (c.isAttacking()) {
                            if (AllZone.getCombat().getAttackers().size() < 2
                                    && Singletons.getModel().getGameState().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY)) {
                                AllZone.getCombat().removeFromCombat(c);
                                checkAgain = true;
                            }
                        }
                        if (c.isBlocking()) {
                            if (AllZone.getCombat().getAllBlockers().size() < 2
                                    && Singletons.getModel().getGameState().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)) {
                                AllZone.getCombat().removeFromCombat(c);
                                checkAgain = true;
                            }
                        }
                    }
The problem is that the first time state effects are checked after declaring attackers and blockers is at the start of the respective Play Instants and Abilities steps. It doesn't affect the attack aspect too much because it is removed from combat before attack triggers (eg: Anthem of Rakdos) are run. For blocking though, the attacking creature becomes blocked as the phase changes even though the Flunkies are removed as blockers before 'becomes blocked' triggers (eg: Aisling Leprechaun). So is there a way to instead check state effects just before the phase actually changes?

Edit: Then another issue I'm not sure of is that if all other attackers or blockers are removed during the Play Instants and Abilities steps, the Flunkies are also removed from combat. Is that correct or is it as I suspect that they should only be removed during the Declare Attackers/Blockers step? I know that two Flunkies could attack or block together legally so they can't be removed as valid choices in CombatUtil.canAttack etc (unless you control no other creatures).
Last edited by moomarc on 10 Jul 2012, 20:23, edited 2 times in total.
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: Can't attack or block alone

Postby friarsol » 10 Jul 2012, 19:50

There's probably a way to remove it as a blocker, not just remove it from Combat which might do the trick. There's another similar card to it Orcish Conscripts that's even more useless than Mogg Flunkies.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Can't attack or block alone

Postby moomarc » 10 Jul 2012, 20:21

friarsol wrote:There's probably a way to remove it as a blocker, not just remove it from Combat which might do the trick. There's another similar card to it Orcish Conscripts that's even more useless than Mogg Flunkies.
I think AllZone.getCombat().blocked.clear(); should work, but 'blocked' is private. Is there another method around? I also see in Combat.removeFromCombat:
Code: Select all
        } else { // card is a blocker
            for (final Card a : att) {
                if (this.getBlockers(a).contains(c)) {
                    this.getBlockerList(a).remove(c);
                    // TODO if Declare Blockers and Declare Blockers (Abilities)
                    // merge this logic needs to be tweaked
                    if ((this.getBlockers(a).size() == 0)
                            && Singletons.getModel().getGameState().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
                        this.blocked.remove(a);
                    }
                }
            }
        }
I think that the phase restriction here is preventing the blocker from being cleared.

But I also added an edit to the first message which effects whether I should pursue this route further because I might have to find a way to clear it before this step.
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: Can't attack or block alone

Postby friarsol » 10 Jul 2012, 20:28

moomarc wrote:I think that the phase restriction here is preventing the blocker from being cleared.

But I also added an edit to the first message which effects whether I should pursue this route further.
The phase restriction is there so people can right click on blockers if they accidentally block with them. If this check you are trying to add just happens once at the end of Declare Blockers (before moving onto DB Abilities) and just uses removeFromCombat, it should work just fine.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Can't attack or block alone

Postby silly freak » 10 Jul 2012, 21:21

Blocker legality is only checked once, so friarsol's suggestion should be right. It's important what was declared. Everything after that is just how the game goes.
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Can't attack or block alone

Postby moomarc » 10 Jul 2012, 21:30

Thanks guys. Assuming I can find my way through phases, I should get this done early tomorrow. =D>
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: Can't attack or block alone

Postby moomarc » 11 Jul 2012, 09:45

Got the attack part working now. The initial filter is in CombatUtil.canAttack and disables the Flunkies as a valid attacker if it is the only creature the player controls. The second filter is in PhaseUtil.handleDeclareAttackers. Here it is removed from combat and from the attackers list before triggers etc. Checked with Gaze of Pain, Anthem of Rakdos etc and it came through with flying colors.

Now to try crack the blocking part... =P~
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: Can't attack or block alone

Postby moomarc » 11 Jul 2012, 13:26

\:D/ So I managed to get the blocker part working finally. I just had to use a slight variant on removeFromCombat that doesn't only remove an attacker from the blocked list if it's the Declare Blockers Step. I've also set it up in two parts, the first one prohibiting blocking if it's the only creature you control and the second one catching the ungrouped blocks attempted by sneaky players.

So the basic structure is there now, so just need to try make it so that the AI has some idea how to factor these guys in to it's attack plans. I might need a little help from Sloth in this area, but I'll try get some basics in at least.
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: Can't attack or block alone

Postby moomarc » 11 Jul 2012, 14:15

Sorry, I've had a look through CombatUtil and I'm just not good enough with the combat logic to see how to slot the Flunkies and friends in. I was hoping to at least get a basic scenario in where if the Mogg Flunkies is your only creature, the ai would attack into it. It seems like it should because the initial filter is in canBlock so in that situation, as far as I can tell, the moggs should return false. When I tested though the AI wouldn't attack until it was in a situation where it would attack into a normal 3/3.

The code is clean and rather basic in the end, with almost zero likelihood of messing other things. Its just not optimised for AI combat calculations. So should I commit the code or post a patch here?
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: Can't attack or block alone

Postby Sloth » 11 Jul 2012, 14:39

moomarc wrote:Sorry, I've had a look through CombatUtil and I'm just not good enough with the combat logic to see how to slot the Flunkies and friends in. I was hoping to at least get a basic scenario in where if the Mogg Flunkies is your only creature, the ai would attack into it. It seems like it should because the initial filter is in canBlock so in that situation, as far as I can tell, the moggs should return false. When I tested though the AI wouldn't attack until it was in a situation where it would attack into a normal 3/3.

The code is clean and rather basic in the end, with almost zero likelihood of messing other things. Its just not optimised for AI combat calculations. So should I commit the code or post a patch here?
Commit. I can take a look at AI combat then.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 34 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 34 users online :: 0 registered, 0 hidden and 34 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 34 guests

Login Form