General code question from a noob
 Posted: 20 Jan 2012, 22:16
Posted: 20 Jan 2012, 22:16When 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).
			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).