Skip to content

Commit

Permalink
Status effects cannot go negative.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 791f721e6363322666b42c5a32968b3b8f506b15
  • Loading branch information
cpojer committed Nov 1, 2024
1 parent 45c4052 commit 02fd39c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
20 changes: 20 additions & 0 deletions apollo/__tests__/Skill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
Saboteur,
SmallTank,
Sniper,
SuperTank,
Zombie,
} from '@deities/athena/info/Unit.tsx';
import { generateUnitName } from '@deities/athena/info/UnitNames.tsx';
import getDefenseStatusEffect from '@deities/athena/lib/getDefenseStatusEffect.tsx';
import updatePlayer from '@deities/athena/lib/updatePlayer.tsx';
import withModifiers from '@deities/athena/lib/withModifiers.tsx';
import { Charge, MaxCharges } from '@deities/athena/map/Configuration.tsx';
Expand Down Expand Up @@ -682,3 +684,21 @@ test('the Charge skill increases charge accumulation', async () => {
state1.getPlayer(1).charge,
);
});

test('defense cannot go negative', async () => {
const skills = new Set([
Skill.DecreaseUnitCostAttackAndDefenseDecreaseMinor,
Skill.BuyUnitZombieDefenseDecreaseMajor,
Skill.UnlockZombie,
]);
const mapA = map.copy({
teams: updatePlayer(map.teams, map.getPlayer(1).copy({ skills })),
units: map.units
.set(fromA, SuperTank.create(1))
.set(toA, SmallTank.create(2)),
});

expect(
getDefenseStatusEffect(mapA, mapA.units.get(fromA)!, null),
).toBeGreaterThanOrEqual(0);
});
13 changes: 7 additions & 6 deletions athena/lib/getAttackStatusEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export default function getAttackStatusEffect(
? CrystalAttackEffect
: 0;

return (
return Math.max(
0,
1 +
crystalEffect +
buildingEffect +
unitEffect +
(unit.isLeader() ? LeaderStatusEffect : 0) +
getSkillAttackStatusEffects(unit, tile, player)
crystalEffect +
buildingEffect +
unitEffect +
(unit.isLeader() ? LeaderStatusEffect : 0) +
getSkillAttackStatusEffects(unit, tile, player),
);
}
17 changes: 9 additions & 8 deletions athena/lib/getDefenseStatusEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export default function getDefenseStatusEffect(
tile: TileInfo | null,
) {
const player = map.getPlayer(entity);
return (
return Math.max(
0,
1 +
(isUnit(entity) && entity.isLeader() ? LeaderStatusEffect : 0) +
getSkillDefenseStatusEffects(
entity,
tile,
player.skills,
player.activeSkills,
)
(isUnit(entity) && entity.isLeader() ? LeaderStatusEffect : 0) +
getSkillDefenseStatusEffects(
entity,
tile,
player.skills,
player.activeSkills,
),
);
}

0 comments on commit 02fd39c

Please sign in to comment.