Page 1 of 1

General code question from a noob

PostPosted: 20 Jan 2012, 22:16
by moomarc
When I originally copied Persist to add Undying to Forge I came across something in CombatUtil that I wonder if anyone can clarify for me (I'm trying to learn bit of coding by following patterns so notice things like this). The relevant bits of code are these (from CanDestroyBlocker/Attacker blocks):

if (((attacker.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(attacker) && !withoutAbilities)) && !(defender
.hasKeyword("Wither") || defender.hasKeyword("Infect")))
|| (attacker.hasKeyword("Persist") && !attacker.canHaveCountersPlacedOnIt(Counters.M1M1)
&& attacker.getCounters(Counters.M1M1) == 0)
|| (attacker.hasKeyword("Undying") && !attacker.canHaveCountersPlacedOnIt(Counters.P1P1)
&& attacker.getCounters(Counters.P1P1) == 0)) {

if (((defender.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(defender) && !withoutAbilities)) && !(attacker
.hasKeyword("Wither") || attacker.hasKeyword("Infect")))
|| (defender.hasKeyword("Persist") && !defender.canHaveCountersPlacedOnIt(Counters.M1M1))
&& defender.getCounters(Counters.M1M1) == 0
|| (defender.hasKeyword("Undying") && !defender.canHaveCountersPlacedOnIt(Counters.P1P1))
&& defender.getCounters(Counters.P1P1) == 0) {

I'm just wondering why the two blocks are bracketed differently and if it makes any difference. Not important really, just interested to find out. I identified the differences in red/green (the first one looks more right to me because it encapsulates the whole condition, but I don't know).

Re: General code question from a noob

PostPosted: 21 Jan 2012, 08:13
by Sloth
You are right, the first one is correct the second one needs to be fixed.

Re: General code question from a noob

PostPosted: 21 Jan 2012, 08:55
by moomarc
Glad I finally asked about it then. I've committed the fix.