Skip to content

Commit

Permalink
Invincible checks defender buffs
Browse files Browse the repository at this point in the history
  • Loading branch information
SharpnelXu committed Aug 17, 2024
1 parent 8657714 commit 7b2cf37
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 36 deletions.
124 changes: 91 additions & 33 deletions lib/app/battle/functions/damage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,43 +239,101 @@ class Damage {
}

final skipDamage = await shouldSkipDamage(battleData, activator, target, currentCard);
if (!skipDamage) {
final hasPierceDefense =
await activator.hasBuff(battleData, BuffAction.pierceDefence, other: target, card: currentCard);
// no corresponding code found, copying logic of pierceDefence
final hasPierceSubDamage =
await activator.hasBuff(battleData, BuffAction.pierceSubdamage, other: target, card: currentCard);
damageParameters
..cardResist =
await target.getBuffValue(battleData, BuffAction.commandDef, other: activator, card: currentCard)
..defenseBuff = damageFunction?.funcType == FuncType.damageNpPierce || hasPierceDefense
? await target.getBuffValue(battleData, BuffAction.defencePierce, other: activator, card: currentCard)
: await target.getBuffValue(battleData, BuffAction.defence, other: activator, card: currentCard)
..specificDefenseBuff =
await target.getBuffValue(battleData, BuffAction.selfdamage, other: activator, card: currentCard)
..percentDefenseBuff =
await target.getBuffValue(battleData, BuffAction.specialdefence, other: activator, card: currentCard)
..damageReceiveAdditionBuff = (hasPierceSubDamage
? await target.getBuffValue(battleData, BuffAction.receiveDamagePierce,
other: activator, card: currentCard)
: await target.getBuffValue(battleData, BuffAction.receiveDamage,
other: activator, card: currentCard)) +
await target.getBuffValue(battleData, BuffAction.specialReceiveDamage,
other: activator, card: currentCard);

atkNpParameters.cardResist =
await target.getBuffValue(battleData, BuffAction.commandNpDef, other: activator, card: currentCard);
final hasPierceDefense =
await activator.hasBuff(battleData, BuffAction.pierceDefence, other: target, card: currentCard);
// no corresponding code found, copying logic of pierceDefence
final hasPierceSubDamage =
await activator.hasBuff(battleData, BuffAction.pierceSubdamage, other: target, card: currentCard);

damageParameters
..cardResist = await target.getBuffValue(
battleData,
BuffAction.commandDef,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)
..defenseBuff = damageFunction?.funcType == FuncType.damageNpPierce || hasPierceDefense
? await target.getBuffValue(
battleData,
BuffAction.defencePierce,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)
: await target.getBuffValue(
battleData,
BuffAction.defence,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)
..specificDefenseBuff = await target.getBuffValue(
battleData,
BuffAction.selfdamage,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)
..percentDefenseBuff = await target.getBuffValue(
battleData,
BuffAction.specialdefence,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)
..damageReceiveAdditionBuff = (hasPierceSubDamage
? await target.getBuffValue(
battleData,
BuffAction.receiveDamagePierce,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)
: await target.getBuffValue(
battleData,
BuffAction.receiveDamage,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)) +
await target.getBuffValue(
battleData,
BuffAction.specialReceiveDamage,
other: activator,
card: currentCard,
skipDamage: skipDamage,
);

atkNpParameters.cardResist = await target.getBuffValue(
battleData,
BuffAction.commandNpDef,
other: activator,
card: currentCard,
skipDamage: skipDamage,
);

starParameters
..cardResist = await target.getBuffValue(
battleData,
BuffAction.commandStarDef,
other: activator,
card: currentCard,
skipDamage: skipDamage,
)
..enemyStarGenResist = await target.getBuffValue(
battleData,
BuffAction.criticalStarDamageTaken,
other: activator,
card: currentCard,
skipDamage: skipDamage,
);

starParameters
..cardResist =
await target.getBuffValue(battleData, BuffAction.commandStarDef, other: activator, card: currentCard)
..enemyStarGenResist = await target.getBuffValue(battleData, BuffAction.criticalStarDamageTaken,
other: activator, card: currentCard);
}
final multiAttack = await activator.getMultiAttackBuffValue(battleData, currentCard, target);

// real
int totalDamage = await DamageAdjustor.show(battleData, activator, target, damageParameters, currentCard, multiAttack,);
int totalDamage =
await DamageAdjustor.show(battleData, activator, target, damageParameters, currentCard, multiAttack);
if (funcType == FuncType.damageNpSafe && target.hp > 0 && totalDamage >= target.hp) {
totalDamage = target.hp - 1;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/app/battle/interactions/damage_adjustor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ class DamageAdjustor extends StatefulWidget {
barrierDismissible: false,
builder: (context, _) {
return DamageAdjustor(
battleData: battleData, activator: activator, target: target, damageParameters: damageParameters, currentCard: currentCard, multiAttack: multiAttack,);
battleData: battleData,
activator: activator,
target: target,
damageParameters: damageParameters,
currentCard: currentCard,
multiAttack: multiAttack,
);
},
);
battleData.replayDataRecord.damageSelections.add(damage);
Expand Down
9 changes: 9 additions & 0 deletions lib/app/battle/models/svt_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ class BattleServantData {
final CommandCardData? card,
final bool isAttack = true,
final List<NiceTrait>? addTraits,
final bool skipDamage = false, // special logic for defender in damage calculation
}) async {
final actionDetails = ConstData.buffActions[buffAction];
// not actionable if no actionDetails present
Expand All @@ -1527,6 +1528,14 @@ class BattleServantData {
final List<NiceTrait>? otherTraits =
fetchOtherTraits(buffAction, buff, other, cardData: card, isAttack: !isAttack, addTraits: addTraits);
if (await buff.shouldActivateBuff(battleData, selfTraits, opTraits: otherTraits)) {
// here is a special logic we found that says plusTypes for defender buffs are ignored when damage is skipped.
// It behaves like how pierceDefence acts on defence related buffs, but we did not find actual code for it.
// This fix is still necessary so that defenceDown buffs get used correctly
// ref: https://discord.com/channels/839788731108032532/1078568994170228736/1274409425586753647
if (skipDamage && actionDetails.plusTypes.contains(buff.buff.type)) {
continue;
}

buff.setUsed(this);

int value = buff.getValue(this, other);
Expand Down
4 changes: 2 additions & 2 deletions lib/app/modules/quest/quest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class _QuestDetailPageState extends State<QuestDetailPage> {
if (phase > 0) initHash = (phase, widget.enemyHash);
} else if (_quest!.isAnyFree && _quest!.phases.isNotEmpty) {
phase = _quest!.phases.last;
// } else if (_quest!.phases.length > 3) {
// phase = _quest!.phases.first;
// } else if (_quest!.phases.length > 3) {
// phase = _quest!.phases.first;
}
}
_resolveQuest();
Expand Down
29 changes: 29 additions & 0 deletions test/app/battle/models/battle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,35 @@ void main() async {
expect(maqin.skillInfoList[2].chargeTurn, 5);
});

test('hitting invincible enemy', () async {
final List<PlayerSvtData> setting = [
PlayerSvtData.id(2800100)..tdLv = 1..lv = 1..atkFou = 0,
PlayerSvtData.id(1100600)..tdLv = 1..lv = 1..atkFou = 0..skillLvs = [1, 1, 1],
];
final battle = BattleData();
final quest = db.gameData.questPhases[9300040603]!;
await battle.init(quest, setting, null);

final enemy = battle.onFieldEnemies[0]!;
expect(await enemy.getBuffValue(battle, BuffAction.defence), 1000);

await battle.activateSvtSkill(1, 2);
expect(await enemy.getBuffValue(battle, BuffAction.defence), 800);
final previousHp = enemy.hp;

final oberon = battle.onFieldAllyServants[0]!;
final salieri = battle.onFieldAllyServants[1]!;
oberon.np = 10000;
await battle.playerTurn([
CombatAction(oberon, oberon.getNPCard()!),
CombatAction(salieri, salieri.getCards()[0]),
CombatAction(salieri, salieri.getCards()[1]),
]);

expect(await enemy.getBuffValue(battle, BuffAction.defence), 1000);
expect(previousHp - enemy.hp, 2753);
});

group('Summer Eresh related tests', () {
test('bond & starting position & dmgBattlePoint', () async {
final List<PlayerSvtData?> setting = [
Expand Down

0 comments on commit 7b2cf37

Please sign in to comment.