mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Various NPE fixes based on server log
This commit is contained in:
parent
ebbbc1daf1
commit
bee12d709c
3 changed files with 46 additions and 41 deletions
|
@ -102,7 +102,7 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
|
||||||
rules.add(sbRule.toString());
|
rules.add(sbRule.toString());
|
||||||
}
|
}
|
||||||
String rule = ability.getRule();
|
String rule = ability.getRule();
|
||||||
if (rule.length() > 0) {
|
if (rule != null && rule.length() > 0) {
|
||||||
rules.add(Character.toUpperCase(rule.charAt(0)) + rule.substring(1));
|
rules.add(Character.toUpperCase(rule.charAt(0)) + rule.substring(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,37 +62,40 @@ public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
if (((ZoneChangeEvent) event).isDiesEvent()) {
|
if (((ZoneChangeEvent) event).isDiesEvent()) {
|
||||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||||
boolean triggered = false;
|
boolean triggered = false;
|
||||||
if (zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
|
if (zEvent != null) {
|
||||||
triggered = true;
|
if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
|
||||||
} else {
|
triggered = true;
|
||||||
// If both (attachment and attached went to graveyard at the same time, the attachemnets can be already removed from the attached object.)
|
} else {
|
||||||
// So check here with the LKI of the enchantment
|
// If both (attachment and attached went to graveyard at the same time, the attachemnets can be already removed from the attached object.)
|
||||||
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
// So check here with the LKI of the enchantment
|
||||||
if (attachment != null
|
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
||||||
&& zEvent.getTargetId() != null && attachment.getAttachedTo() != null
|
if (attachment != null
|
||||||
&& zEvent.getTargetId().equals(attachment.getAttachedTo())) {
|
&& zEvent.getTargetId() != null && attachment.getAttachedTo() != null
|
||||||
Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo());
|
&& zEvent.getTargetId().equals(attachment.getAttachedTo())) {
|
||||||
if (attachedTo != null
|
Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo());
|
||||||
&& attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent
|
if (attachedTo != null
|
||||||
triggered = true;
|
&& attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent
|
||||||
}
|
triggered = true;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (triggered) {
|
|
||||||
for (Effect effect : getEffects()) {
|
|
||||||
effect.setValue("attachedTo", zEvent.getTarget());
|
|
||||||
if (setTargetPointer.equals(SetTargetPointer.ATTACHED_TO_CONTROLLER)) {
|
|
||||||
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
|
||||||
if (attachment != null && attachment.getAttachedTo() != null) {
|
|
||||||
Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
|
|
||||||
if (attachedTo != null) {
|
|
||||||
effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
if (triggered) {
|
||||||
|
for (Effect effect : getEffects()) {
|
||||||
|
if (zEvent.getTarget() != null) {
|
||||||
|
effect.setValue("attachedTo", zEvent.getTarget());
|
||||||
|
if (setTargetPointer.equals(SetTargetPointer.ATTACHED_TO_CONTROLLER)) {
|
||||||
|
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
||||||
|
if (attachment != null && attachment.getAttachedTo() != null) {
|
||||||
|
Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
|
||||||
|
if (attachedTo != null) {
|
||||||
|
effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -120,19 +120,21 @@ public class AwakenAbility extends SpellAbility {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
UUID targetId = null;
|
UUID targetId = null;
|
||||||
for (Target target : source.getTargets()) {
|
if (source != null && source.getTargets() != null) {
|
||||||
if (target.getFilter().getMessage().equals(filterMessage)) {
|
for (Target target : source.getTargets()) {
|
||||||
targetId = target.getFirstTarget();
|
if (target.getFilter() != null && target.getFilter().getMessage().equals(filterMessage)) {
|
||||||
|
targetId = target.getFirstTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetId != null) {
|
||||||
|
FixedTarget fixedTarget = new FixedTarget(targetId);
|
||||||
|
ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.Custom);
|
||||||
|
continuousEffect.setTargetPointer(fixedTarget);
|
||||||
|
game.addEffect(continuousEffect, source);
|
||||||
|
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(awakenValue));
|
||||||
|
effect.setTargetPointer(fixedTarget);
|
||||||
|
return effect.apply(game, source);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (targetId != null) {
|
|
||||||
FixedTarget fixedTarget = new FixedTarget(targetId);
|
|
||||||
ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.Custom);
|
|
||||||
continuousEffect.setTargetPointer(fixedTarget);
|
|
||||||
game.addEffect(continuousEffect, source);
|
|
||||||
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(awakenValue));
|
|
||||||
effect.setTargetPointer(fixedTarget);
|
|
||||||
return effect.apply(game, source);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue