Skip to content

Commit

Permalink
Second Life (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyvg authored Feb 29, 2024
1 parent 0232936 commit f3633dc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/arena/magics/__snapshots__/secondLife.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`paralysis target should sleep and not be able to attack 1`] = `
"*asperiores* использовал _Вторая жизнь_ на *asperiores* с эффектом 10
\\[ 📖80 ]"
`;
1 change: 1 addition & 0 deletions src/arena/magics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export { default as bodySpirit } from './bodySpirit';
export { default as blight } from './blight';
export { default as dustShield } from './dustShield';
export { default as lightShield } from './lightShield';
export { default as secondLife } from './secondLife';
export { default as sleep } from './sleep';
export { default as magicWall } from './magicWall';
42 changes: 42 additions & 0 deletions src/arena/magics/secondLife.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import casual from 'casual';
import CharacterService from '@/arena/CharacterService';
import GameService from '@/arena/GameService';
import TestUtils from '@/utils/testUtils';
import secondLife from './secondLife';

// npm t src/arena/magics/secondLife.test.ts

describe('secondLife', () => {
let game: GameService;

beforeAll(() => {
casual.seed(1);
});

beforeEach(async () => {
const initiator = await TestUtils.createCharacter({ prof: 'p', magics: { secondLife: 1 } });

await CharacterService.getCharacterById(initiator.id);

game = new GameService([initiator.id]);
});

beforeEach(() => {
jest.spyOn(global.Math, 'random').mockReturnValue(0.5);
});

afterEach(() => {
jest.spyOn(global.Math, 'random').mockRestore();
});

it('target should be alive', async () => {
game.players.players[0].proc = 1;
game.players.players[0].stats.set(secondLife.costType, secondLife.cost);
game.players.players[0].stats.set('hp', -10);

secondLife.cast(game.players.players[0], game.players.players[0], game);

expect(game.players.players[0].stats.val('hp')).toBe(0.05);
expect(TestUtils.normalizeRoundHistory(game.getRoundResults())).toMatchSnapshot();
});
});
21 changes: 14 additions & 7 deletions src/arena/magics/secondLife.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { CommonMagic } from '../Constuructors/CommonMagicConstructor';

/**
* Затмение
* Вторая жизнь
* Основное описание магии общее требовани есть в конструкторе
*/
class SecondLife extends CommonMagic {
constructor() {
super({
// @ts-expect-error не используется
name: 'secondLife',
displayName: 'Вторая жизнь',
desc: 'Воскрешает цель',
cost: 20,
baseExp: 8,
costType: 'mp',
lvl: 3,
orderType: 'all',
orderType: 'team',
aoeType: 'target',
magType: 'good',
chance: [
Expand All @@ -27,11 +26,19 @@ class SecondLife extends CommonMagic {
});
}

// eslint-disable-next-line class-methods-use-this
calculateExp(effect: number, baseExp = 0) {
return Math.round(effect * baseExp * this.params.initiator.proc);
}

run() {
// if hp < 0 , wasHP = |hp|
// set hp 0.05
// set exp wasHP * baseExp
const { target } = this.params;
const hp = target.stats.val('hp');

if (hp <= 0) {
target.stats.set('hp', 0.05);
target.resetKiller();
this.status.effect = Math.abs(hp);
}
}
}

Expand Down

0 comments on commit f3633dc

Please sign in to comment.