mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-13 17:27:46 +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
|
||||
*/
|
||||
public int getTotalPreventionShieldAmount(GameEntity o) {
|
||||
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(o);
|
||||
repParams.put(AbilityKey.Prevention, true);
|
||||
repParams.put(AbilityKey.DamageAmount, 1);
|
||||
List<ReplacementEffect> list = getReplacementList(ReplacementType.DamageDone, repParams, ReplacementLayer.Other);
|
||||
if (list.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
final List<ReplacementEffect> list = Lists.newArrayList();
|
||||
game.forEachCardInGame(new Visitor<Card>() {
|
||||
@Override
|
||||
public boolean visit(Card c) {
|
||||
for (final ReplacementEffect re : c.getReplacementEffects()) {
|
||||
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;
|
||||
for (ReplacementEffect re : list) {
|
||||
if (re.getOverridingAbility() != null) {
|
||||
SpellAbility sa = re.getOverridingAbility();
|
||||
if (ApiType.ReplaceDamage == sa.getApi() && sa.hasParam("Amount")) {
|
||||
String varValue = sa.getParam("Amount");
|
||||
if (StringUtils.isNumeric(varValue)) {
|
||||
totalAmount += Integer.parseInt(varValue);
|
||||
} else {
|
||||
varValue = sa.getSVar(varValue);
|
||||
if (StringUtils.isNumeric(varValue)) {
|
||||
totalAmount += Integer.parseInt(varValue);
|
||||
} else if (varValue.startsWith("Number$")) {
|
||||
totalAmount += Integer.parseInt(varValue.substring(7));
|
||||
}
|
||||
SpellAbility sa = re.getOverridingAbility();
|
||||
if (sa.hasParam("Amount")) {
|
||||
String varValue = sa.getParam("Amount");
|
||||
if (StringUtils.isNumeric(varValue)) {
|
||||
totalAmount += Integer.parseInt(varValue);
|
||||
} else {
|
||||
varValue = sa.getSVar(varValue);
|
||||
if (varValue.startsWith("Number$")) {
|
||||
totalAmount += Integer.parseInt(varValue.substring(7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user