v3.1.0: shield buffs now have a priority order in which they are used

This commit is contained in:
Evan Debenham
2025-03-28 12:46:52 -04:00
parent 0534c3a8dd
commit fe5a6dee85
5 changed files with 42 additions and 7 deletions

View File

@@ -901,13 +901,7 @@ public abstract class Char extends Actor {
}
int shielded = dmg;
//FIXME: when I add proper damage properties, should add an IGNORES_SHIELDS property to use here.
if (!(src instanceof Hunger)){
for (ShieldBuff s : buffs(ShieldBuff.class)){
dmg = s.absorbDamage(dmg);
if (dmg == 0) break;
}
}
dmg = ShieldBuff.processDamage(this, dmg, src);
shielded -= dmg;
HP -= dmg;

View File

@@ -24,10 +24,20 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public abstract class ShieldBuff extends Buff {
private int shielding;
//higher priority shielding buffs are consumed first if multiple exist
//currently we have the following:
// 2: relatively weak and short term shields like blocking buff
// 1: larger but still short-term shields from Cleric's ascended form
// 0: everything else, mostly the various sources of generic barrier
protected int shieldUsePriority = 0;
protected boolean detachesAtZero = true;
@Override
@@ -93,6 +103,30 @@ public abstract class ShieldBuff extends Buff {
if (target != null) target.needsShieldUpdate = true;
return dmg;
}
public static int processDamage( Char target, int damage, Object src ){
//hunger damage is not affected by shielding
if (src instanceof Hunger){
return damage;
}
ArrayList<ShieldBuff> buffs = new ArrayList<>(target.buffs(ShieldBuff.class));
if (!buffs.isEmpty()){
//sort in descending order based on shield use priority
Collections.sort(buffs, new Comparator<ShieldBuff>() {
@Override
public int compare(ShieldBuff a, ShieldBuff b) {
return b.shieldUsePriority - a.shieldUsePriority;
}
});
for (ShieldBuff buff : buffs){
damage = buff.absorbDamage(damage);
if (damage == 0) break;
}
}
return damage;
}
private static final String SHIELDING = "shielding";

View File

@@ -77,6 +77,7 @@ public class AscendedForm extends ArmorAbility {
type = buffType.POSITIVE;
detachesAtZero = false;
shieldUsePriority = 1;
}
public static float DURATION = 10f;

View File

@@ -93,6 +93,10 @@ public class DivineIntervention extends ClericSpell {
public static class DivineShield extends ShieldBuff{
{
shieldUsePriority = 1;
}
@Override
public boolean act() {

View File

@@ -70,6 +70,8 @@ public class Blocking extends Weapon.Enchantment {
{
type = buffType.POSITIVE;
shieldUsePriority = 2;
}
@Override