Page 1 of 1

Can't attack or block alone

PostPosted: 10 Jul 2012, 19:42
by moomarc
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).

Re: Can't attack or block alone

PostPosted: 10 Jul 2012, 19:50
by friarsol
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.

Re: Can't attack or block alone

PostPosted: 10 Jul 2012, 20:21
by moomarc
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.

Re: Can't attack or block alone

PostPosted: 10 Jul 2012, 20:28
by friarsol
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.

Re: Can't attack or block alone

PostPosted: 10 Jul 2012, 21:21
by silly freak
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.

Re: Can't attack or block alone

PostPosted: 10 Jul 2012, 21:30
by moomarc
Thanks guys. Assuming I can find my way through phases, I should get this done early tomorrow. =D>

Re: Can't attack or block alone

PostPosted: 11 Jul 2012, 09:45
by moomarc
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~

Re: Can't attack or block alone

PostPosted: 11 Jul 2012, 13:26
by moomarc
\: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.

Re: Can't attack or block alone

PostPosted: 11 Jul 2012, 14:15
by moomarc
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?

Re: Can't attack or block alone

PostPosted: 11 Jul 2012, 14:39
by Sloth
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.