Skip to content

Commit

Permalink
#147 Exorcism, Anathema, Dispel (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyvg authored Mar 2, 2024
1 parent f3633dc commit dce72f5
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/arena/Constuructors/MagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export abstract class Magic extends AffectableAction {
*/
getCost(initiator: Player): void {
const costValue = +initiator.stats.val(this.costType) - this.cost;
console.log(initiator.id, 'MP:', costValue);
if (costValue >= 0) {
initiator.stats.set(this.costType, costValue);
} else {
Expand Down Expand Up @@ -197,7 +196,6 @@ export abstract class Magic extends AffectableAction {
const x = (initiator.stats.val('mga') / target.stats.val('mgp')) * 3;
result += x;
}
console.log('chance is :', result, 'total', result * initiator.proc);
return result * initiator.proc;
}

Expand Down
2 changes: 1 addition & 1 deletion src/arena/Constuructors/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const isPhysicalDamageResult = (result: Result): result is SuccessArgs =>
};

export const findByTarget = (target: string) => {
return (result: Result) => {
return (result: { target: string }) => {
return result.target === target;
};
};
4 changes: 1 addition & 3 deletions src/arena/LogService/LogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export class LogService {
});

try {
const x = this.format();
console.log(x);
await this.writer(x);
await this.writer(this.format());
} catch (e) {
console.log('sendBattleLog: ', e);
} finally {
Expand Down
20 changes: 7 additions & 13 deletions src/arena/magics/anathema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import arena from '@/arena';
import { bold, italic } from '../../utils/formatString';
import { CommonMagic } from '../Constuructors/CommonMagicConstructor';
import type { LongItem } from '../Constuructors/LongMagicConstructor';
import type { SuccessArgs } from '../Constuructors/types';
import arena from '../index';

type LongActionsEntry = [magic: string, item?: LongItem[]]
/**
* Экзорцизм
* Основное описание магии общее требовани есть в конструкторе
Expand All @@ -23,25 +21,21 @@ class Anathema extends CommonMagic {
aoeType: 'target',
magType: 'bad',
chance: ['1d60', '1d70', '1d85'],
profList: ['m'],
profList: ['p'],
effect: [],
});
}

run() {
// Очищаем все "bad" магии в которых target является target данной магии
const { game, target } = this.params;
const { longActions } = game;
const entries = Object.entries(longActions) as LongActionsEntry[];
entries.reduce((sum, [key, items]) => {
if (!items) return sum;
const entries = Object.entries(game.longActions);

entries.forEach(([key, items]) => {
const magic = arena.magics[key];
if (magic.magType === 'good') {
const newItem = items.filter((item) => item.target !== target.id);
sum[key] = newItem;
game.longActions[key] = items.filter((item) => item.target !== target.id);
}
return sum;
}, {} as typeof longActions);
});
}

customMessage(args: SuccessArgs) {
Expand Down
22 changes: 6 additions & 16 deletions src/arena/magics/dispel.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import _ from 'lodash';
import { bold } from '../../utils/formatString';
import { bold, italic } from '../../utils/formatString';
import { CommonMagic } from '../Constuructors/CommonMagicConstructor';
import type { LongItem } from '../Constuructors/LongMagicConstructor';
import type { SuccessArgs } from '../Constuructors/types';

/**
* Снятие магии
* Основное описание магии общее требовани есть в конструкторе
*/
class Dispel extends CommonMagic {
dispelled!: Record<string, LongItem[]>; // закладка для customMessage

constructor() {
super({
name: 'dispel',
Expand All @@ -30,23 +26,17 @@ class Dispel extends CommonMagic {
}

run() {
const { target, game } = this.params;
const { game, target } = this.params;
const entries = Object.entries(game.longActions);
entries.forEach(([name, items]) => {
const [dispelled, rest] = _.partition(items, (item) => item.target === target.id);
this.dispelled[name] = dispelled;
game.longActions[name] = rest;
});
}

next() {
super.next();
this.dispelled = {};
entries.forEach(([key, items]) => {
game.longActions[key] = items.filter((item) => item.target !== target.id);
});
}

customMessage(args: SuccessArgs) {
const { initiator, target } = args;
return `${bold(initiator)} снимает все длительные магии с ${target}, используя заклинание ${this.displayName}`;
return `${bold(initiator)} снимает все длительные магии с ${bold(target)}, используя заклинание ${italic(this.displayName)}`;
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/arena/magics/exorcism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import arena from '../index';
class Exorcism extends CommonMagic {
constructor() {
super({
// @ts-expect-error не используется
name: 'exorcism',
displayName: 'Экзорцизм',
desc: 'Экзорцизм снимает все отрицательные эффекты с цели',
Expand All @@ -22,20 +21,20 @@ class Exorcism extends CommonMagic {
aoeType: 'target',
magType: 'good',
chance: ['1d60', '1d70', '1d80'],
profList: ['m'],
profList: ['p'],
effect: [],
});
}

run() {
// Очищаем все "bad" магии в которых target является target данной магии
const { game, target } = this.params;
const { ordersList } = game.orders;
game.orders.ordersList = ordersList.filter((order) => {
if (order.target === target.id) {
return arena.magics[order.action]?.magType !== 'bad';
const entries = Object.entries(game.longActions);

entries.forEach(([key, items]) => {
const magic = arena.magics[key];
if (magic.magType === 'bad') {
game.longActions[key] = items.filter((item) => item.target !== target.id);
}
return true;
});
}

Expand Down
1 change: 1 addition & 0 deletions src/arena/magics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export { default as lightShield } from './lightShield';
export { default as secondLife } from './secondLife';
export { default as sleep } from './sleep';
export { default as magicWall } from './magicWall';
export { default as exorcism } from './exorcism';
2 changes: 1 addition & 1 deletion src/arena/magics/lightShield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const params = {
cost: 3,
baseExp: 6,
costType: 'mp',
lvl: 1,
lvl: 4,
orderType: 'team',
aoeType: 'target',
magType: 'good',
Expand Down

0 comments on commit dce72f5

Please sign in to comment.