Skip to content

Commit

Permalink
Refactor Light Shield magic
Browse files Browse the repository at this point in the history
  • Loading branch information
kyvg committed Feb 26, 2024
1 parent 5f7363f commit 59484a1
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 46 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
'no-param-reassign': 0,
'no-underscore-dangle': 0,
'consistent-return': 0,
'no-use-before-define': 0,
camelcase: 0,
'lines-between-class-members': ["error", "always", {exceptAfterSingleLine: true}],
'no-void': ['error', { allowAsStatement: true }],
Expand Down
5 changes: 3 additions & 2 deletions src/arena/Constuructors/DmgMagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export abstract class DmgMagic extends Magic {
}

modifyEffect(effect: number, { initiator, target } = this.params): number {
effect = this.applyCasterModifiers(effect, initiator);
effect = this.applyTargetModifiers(effect, target);

if (this.dmgType !== 'clear') {
effect = this.applyCasterModifiers(effect, initiator);
effect = this.applyTargetModifiers(effect, target);
effect = this.applyResists(effect, target);
}

Expand Down
2 changes: 1 addition & 1 deletion src/arena/LogService/utils/format-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function formatMessage(msgObj: SuccessArgs | FailArgs, depth = 0): string

const affects = msgObj.affects.map((msgObj) => formatMessage(msgObj, depth + 1));

return `${indent}${formatAction(msgObj)}\n${indent}${formatExp(msgObj)}\n${affects.join('\n')}`;
return `${indent}${formatAction(msgObj)}\n${indent}${formatExp(msgObj)}\n\n${affects.join('\n\n')}`;
}

return formatError(msgObj);
Expand Down
16 changes: 9 additions & 7 deletions src/arena/magics/__snapshots__/lightShield.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ exports[`lightShield initiator should be hit by light shield 1`] = `
"*asperiores* использовал _Световой щит_ на *asperiores*
\\[ 📖6 ]
*asperiores* использовал _Световой щит_ на *asperiores*
\\[ 📖6 ]
*alias* рубанул *asperiores* _Эпическим Мечом_ и нанёс *11* урона
\\[ asperiores 👊 💔-11/-3 📖88 ]
*asperiores* сотворил _Световой щит_ на *alias* нанеся 3 урона
\\[ alias 💔-3/5 📖0 ]
*asperiores* сотворил _Световой щит_ на *alias* нанеся 3 урона
\\[ alias 💔-3/2 📖0 ]"
\\[ 📖3 ]
*alias* рубанул *asperiores* _Эпическим Мечом_ и нанёс *10.72* урона
\\[ asperiores 👊 💔-10.72/-2.72 📖86 ]
*asperiores* сотворил _Световой щит_ на *alias* нанеся 0.32 урона
\\[ alias 💔-0.32/7.68 📖9 ]
*asperiores* сотворил _Световой щит_ на *alias* нанеся 0.16 урона
\\[ alias 💔-0.16/7.52 📖7 ]"
`;
4 changes: 3 additions & 1 deletion src/arena/magics/lightShield.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('lightShield', () => {
});

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

afterEach(() => {
Expand All @@ -38,6 +38,8 @@ describe('lightShield', () => {
game.players.players[1].proc = 1;

lightShield.cast(game.players.players[0], game.players.players[0], game);
game.players.players[0].proc = 0.5;

lightShield.cast(game.players.players[0], game.players.players[0], game);
attack.cast(game.players.players[1], game.players.players[0], game);

Expand Down
83 changes: 48 additions & 35 deletions src/arena/magics/lightShield.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
import type { PostAffect } from '../Constuructors/interfaces/PostAffect';
import { LongDmgMagic } from '../Constuructors/LongDmgMagicConstructor';
import type { SuccessArgs } from '../Constuructors/types';
/* eslint-disable @typescript-eslint/no-use-before-define, max-classes-per-file */
import { DmgMagic } from '@/arena/Constuructors/DmgMagicConstructor';
import type { PostAffect } from '@/arena/Constuructors/interfaces/PostAffect';
import { LongMagic } from '@/arena/Constuructors/LongMagicConstructor';
import type { MagicArgs } from '@/arena/Constuructors/MagicConstructor';
import type { SuccessArgs } from '@/arena/Constuructors/types';
import type GameService from '@/arena/GameService';
import type { Player } from '@/arena/PlayersService';

/**
* Магический доспех
* Основное описание магии общее требование есть в конструкторе
*/
class LightShield extends LongDmgMagic implements PostAffect {
constructor() {
super({
name: 'lightShield',
displayName: 'Световой щит',
desc: 'Возвращает часть физического урона в виде чистого, атакующему цель под действием щита',
cost: 3,
baseExp: 6,
costType: 'mp',
lvl: 1,
orderType: 'team',
aoeType: 'target',
magType: 'good',
chance: [100, 100, 100],
effect: ['1d1', '3d3', '5d5'],
profList: ['m'],
dmgType: 'clear',
});

const params = {
name: 'lightShield',
displayName: 'Световой щит',
desc: 'Возвращает часть физического урона в виде чистого, атакующему цель под действием щита',
cost: 3,
baseExp: 6,
costType: 'mp',
lvl: 1,
orderType: 'team',
aoeType: 'target',
magType: 'good',
chance: ['1d80', '1d90', '1d100'],
effect: ['1d1', '3d3', '5d5'],
profList: ['m'],
} satisfies MagicArgs;

class LightShield extends DmgMagic {
cast(initiator: Player, target: Player, game: GameService): void {
this.params = { initiator, target, game };
this.run();
this.getExp();
this.checkTargetIsDead();
}

run() {
const { target } = this.params;
target.stats.down('hp', this.effectVal());
}
}

class LightShieldBuff extends LongMagic implements PostAffect {
run() {
const { target, initiator } = this.params;
target.flags.isLightShielded.push({ initiator: initiator.nick, val: initiator.proc });
Expand All @@ -37,22 +55,17 @@ class LightShield extends LongDmgMagic implements PostAffect {

postAffect(
{ initiator, target, game } = this.params,
{ effect } = { effect: 0 },
): void | SuccessArgs | SuccessArgs[] {
return target.flags.isLightShielded.map(() => {
const effect = this.effectVal({ initiator: target, target: initiator, game });

initiator.stats.down('hp', effect);

return super.getSuccessResult({ initiator: target, target: initiator, game });
return target.flags.isLightShielded.map(({ val }) => {
target.setProc(effect * val * 0.01);
lightShield.cast(target, initiator, game);
return lightShield.getSuccessResult({ initiator: target, target: initiator, game });
});
}

getSuccessResult({ initiator, target, game } = this.params): SuccessArgs {
return {
...super.getSuccessResult({ initiator, target, game }),
actionType: 'magic',
};
}
}

export default new LightShield();
const lightShield = new LightShield({ ...params, dmgType: 'clear' });
const lightShieldBuff = new LightShieldBuff(params);

export default lightShieldBuff;

0 comments on commit 59484a1

Please sign in to comment.