mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-13 09:17:59 +00:00
Merge branch 'fix_get_total_shield_npe' into 'master'
Fix NPE in getTotalPreventionShieldAmount Closes #1827 See merge request core-developers/forge!4678
This commit is contained in:
@@ -446,28 +446,36 @@ public class ReplacementHandler {
|
|||||||
* @return total shield amount
|
* @return total shield amount
|
||||||
*/
|
*/
|
||||||
public int getTotalPreventionShieldAmount(GameEntity o) {
|
public int getTotalPreventionShieldAmount(GameEntity o) {
|
||||||
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(o);
|
final List<ReplacementEffect> list = Lists.newArrayList();
|
||||||
repParams.put(AbilityKey.Prevention, true);
|
game.forEachCardInGame(new Visitor<Card>() {
|
||||||
repParams.put(AbilityKey.DamageAmount, 1);
|
@Override
|
||||||
List<ReplacementEffect> list = getReplacementList(ReplacementType.DamageDone, repParams, ReplacementLayer.Other);
|
public boolean visit(Card c) {
|
||||||
if (list.isEmpty()) {
|
for (final ReplacementEffect re : c.getReplacementEffects()) {
|
||||||
return 0;
|
if (re.getMode() == ReplacementType.DamageDone
|
||||||
}
|
&& re.getLayer() == ReplacementLayer.Other
|
||||||
|
&& re.hasParam("PreventionEffect")
|
||||||
|
&& re.zonesCheck(game.getZoneOf(c))
|
||||||
|
&& re.getOverridingAbility() != null
|
||||||
|
&& re.getOverridingAbility().getApi() == ApiType.ReplaceDamage) {
|
||||||
|
list.add(re);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
int totalAmount = 0;
|
int totalAmount = 0;
|
||||||
for (ReplacementEffect re : list) {
|
for (ReplacementEffect re : list) {
|
||||||
if (re.getOverridingAbility() != null) {
|
SpellAbility sa = re.getOverridingAbility();
|
||||||
SpellAbility sa = re.getOverridingAbility();
|
if (sa.hasParam("Amount")) {
|
||||||
if (ApiType.ReplaceDamage == sa.getApi() && sa.hasParam("Amount")) {
|
String varValue = sa.getParam("Amount");
|
||||||
String varValue = sa.getParam("Amount");
|
if (StringUtils.isNumeric(varValue)) {
|
||||||
if (StringUtils.isNumeric(varValue)) {
|
totalAmount += Integer.parseInt(varValue);
|
||||||
totalAmount += Integer.parseInt(varValue);
|
} else {
|
||||||
} else {
|
varValue = sa.getSVar(varValue);
|
||||||
varValue = sa.getSVar(varValue);
|
if (varValue.startsWith("Number$")) {
|
||||||
if (StringUtils.isNumeric(varValue)) {
|
totalAmount += Integer.parseInt(varValue.substring(7));
|
||||||
totalAmount += Integer.parseInt(varValue);
|
|
||||||
} else if (varValue.startsWith("Number$")) {
|
|
||||||
totalAmount += Integer.parseInt(varValue.substring(7));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user