Can't attack or block alone
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
10 posts
• Page 1 of 1
Can't attack or block alone
by 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):
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).
- 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;
}
}
}
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
-
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
by 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
by moomarc » 10 Jul 2012, 20:21
I think AllZone.getCombat().blocked.clear(); should work, but 'blocked' is private. Is there another method around? I also see in Combat.removeFromCombat: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.
- 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);
}
}
}
}
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
-
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
by friarsol » 10 Jul 2012, 20:28
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.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.
- 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
by 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!
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
by moomarc » 10 Jul 2012, 21:30
Thanks guys. Assuming I can find my way through phases, I should get this done early tomorrow. 

-Marc
-
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
by 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...
Now to try crack the blocking part...

-Marc
-
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
by moomarc » 11 Jul 2012, 13:26

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
-
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
by 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?
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
-
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
by Sloth » 11 Jul 2012, 14:39
Commit. I can take a look at AI combat then.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?
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 34 guests