Skip to content

Commit

Permalink
Fix protect calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
kyvg committed Mar 2, 2024
1 parent dce72f5 commit 19a4a89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/arena/actions/__snapshots__/protect.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`protect should not get exp if protect enemy 1`] = `
"*corporis* пытался атаковать *quisquam*, но у него не получилось
_Защита_ *quisquam*: 📖43,*corporis*: 📖0"
_Защита_ *quisquam*: 📖33,*corporis*: 📖0"
`;

exports[`protect should protect player 1`] = `
Expand Down
6 changes: 2 additions & 4 deletions src/arena/actions/protect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ describe('protect', () => {

it('should protect player', () => {
game.players.players[0].proc = 1;
game.players.players[0].stats.set('pdef', 100);
game.players.players[1].proc = 0.1;
game.players.players[1].proc = 1;

protect.cast(game.players.players[0], game.players.players[0], game);
attack.cast(game.players.players[1], game.players.players[0], game);
Expand All @@ -45,8 +44,7 @@ describe('protect', () => {

it('should not get exp if protect enemy', () => {
game.players.players[0].proc = 1;
game.players.players[0].stats.set('pdef', 10);
game.players.players[1].proc = 0.1;
game.players.players[1].proc = 1;

protect.cast(game.players.players[0], game.players.players[0], game);
protect.cast(game.players.players[1], game.players.players[0], game);
Expand Down
5 changes: 2 additions & 3 deletions src/arena/actions/protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ class Protect extends AffectableAction implements PreAffect {
const attackValue = initiator.stats.val('patk') * initiator.proc;
const protectValue = target.flags.isProtected.length > 0 ? target.stats.val('pdef') : 0.1;
const ratio = floatNumber(Math.round(attackValue / protectValue));
console.log('at', ratio);

const randomValue = MiscService.rndm('1d100');
const chance = 20 * ratio + 50;
const chance = Math.round(Math.sqrt(ratio) + (10 * ratio) + 5);
const result = chance > randomValue;
console.log('chance', chance, 'random', randomValue, 'result', result);

Expand Down Expand Up @@ -82,7 +81,7 @@ class Protect extends AffectableAction implements PreAffect {
}

const protect = Math.floor(flag.val * 100) / pdef;
const exp = Math.round(expMultiplier * 0.8 * protect);
const exp = Math.round(expMultiplier * 0.08 * protect);
defender.stats.up('exp', exp);

return {
Expand Down

0 comments on commit 19a4a89

Please sign in to comment.