Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Physical Sadness #284

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
},
plugins: ['@typescript-eslint', 'import'],
rules: {
'arrow-body-style': 'off',
'class-methods-use-this': 'off',
'no-plusplus': 'off',
'no-useless-constructor': 'off',
Expand Down
1 change: 0 additions & 1 deletion src/arena/BattleLog/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/arena/BattleLog/utils/format-message.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/arena/Constuructors/AoeDmgMagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export abstract class AoeDmgMagic extends DmgMagic {
dmgType: this.dmgType,
};

game.addHistoryDamage(args);
game.battleLog.success(args);
game.recordOrderResult(args);
}
}
3 changes: 1 addition & 2 deletions src/arena/Constuructors/DmgMagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export abstract class DmgMagic extends Magic {
dmgType: this.dmgType,
};

game.addHistoryDamage(args);
game.battleLog.success(args);
game.recordOrderResult(args);
}
}
8 changes: 3 additions & 5 deletions src/arena/Constuructors/HealMagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export abstract class Heal {
// this.backToLife();
this.next();
} catch (e) {
const { battleLog } = this.params.game;
battleLog.fail(e);
game.recordOrderResult(e);
}
}

Expand Down Expand Up @@ -130,8 +129,7 @@ export abstract class Heal {
* Функция положительного прохождения
*/
next(): void {
const { target, initiator } = this.params;
const { battleLog } = this.params.game;
const { target, initiator, game } = this.params;
const exp: ExpArr[number] = {
id: initiator.id,
name: initiator.nick,
Expand All @@ -147,6 +145,6 @@ export abstract class Heal {
effect: this.status.val,
hp: target.stats.val('hp'),
};
battleLog.success(args);
game.recordOrderResult(args);
}
}
9 changes: 4 additions & 5 deletions src/arena/Constuructors/LongDmgMagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export abstract class LongDmgMagic extends DmgMagic {
this.next();
this.postRun(initiator, target, game);
} catch (failMsg) {
const { battleLog } = this.params.game;
battleLog.fail(failMsg);
game.recordOrderResult(failMsg);
} finally {
this.resetStatus();
}
Expand Down Expand Up @@ -91,7 +90,7 @@ export abstract class LongDmgMagic extends DmgMagic {
this.checkTargetIsDead(); // проверка трупов в длительных магиях
this.longNext(initiator, target);
} catch (e) {
game.battleLog.fail(e);
game.recordOrderResult(e);
}
});
const filteredLongArray = longArray.filter((item) => item.duration !== 0);
Expand Down Expand Up @@ -139,7 +138,7 @@ export abstract class LongDmgMagic extends DmgMagic {
dmgType: this.dmgType,
msg: this.longCustomMessage?.bind(this),
};
game.addHistoryDamage(dmgObj);
game.battleLog.success(dmgObj);

game.recordOrderResult(dmgObj);
}
}
17 changes: 8 additions & 9 deletions src/arena/Constuructors/LongMagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export abstract class LongMagic extends CommonMagic {
this.next();
this.postRun(initiator, target, game);
} catch (failMsg) {
const { battleLog } = this.params.game;
battleLog.fail(failMsg);
game.recordOrderResult(failMsg);
} finally {
this.resetStatus();
}
Expand Down Expand Up @@ -91,7 +90,7 @@ export abstract class LongMagic extends CommonMagic {
this.checkTargetIsDead(); // проверка трупов в длительных магиях
this.longNext(initiator, target);
} catch (e) {
game.battleLog.fail(e);
game.recordOrderResult(e);
}
});
const filteredLongArray = longArray.filter((item) => item.duration !== 0);
Expand Down Expand Up @@ -121,16 +120,16 @@ export abstract class LongMagic extends CommonMagic {
}

next(): void {
const { battleLog } = this.params.game;
const { initiator, target, game } = this.params;
const args: MagicNext = {
exp: this.status.exp,
action: this.displayName,
actionType: 'magic',
target: this.params.target.nick,
initiator: this.params.initiator.nick,
target: target.nick,
initiator: initiator.nick,
msg: this.customMessage?.bind(this),
};
battleLog.success(args);
game.recordOrderResult(args);
}

/**
Expand All @@ -139,7 +138,7 @@ export abstract class LongMagic extends CommonMagic {
* @param target
*/
longNext(initiator: Player, target: Player): void {
const { battleLog } = this.params.game;
const { game } = this.params;
const args: LongMagicNext = {
exp: this.status.exp,
action: this.displayName,
Expand All @@ -148,7 +147,7 @@ export abstract class LongMagic extends CommonMagic {
initiator: initiator.nick,
msg: this.longCustomMessage?.bind(this),
};
battleLog.success(args);
game.recordOrderResult(args);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/arena/Constuructors/MagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ export abstract class Magic {

this.next();
} catch (failMsg) {
const bl = this.params.game.battleLog;
// @fixme прокидываем ошибку выше для длительных кастов
if (this.isLong) throw (failMsg);
bl.fail(failMsg);
game.recordOrderResult(failMsg);
} finally {
this.resetStatus();
}
Expand Down Expand Up @@ -299,7 +298,7 @@ export abstract class Magic {
* @todo тут нужен вывод требуемых параметров
*/
next(): void {
const { battleLog } = this.params.game;
battleLog.success(this.getNextArgs());
const { game } = this.params;
game.recordOrderResult(this.getNextArgs());
}
}
8 changes: 3 additions & 5 deletions src/arena/Constuructors/PhysConstructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ class PhysConstructor {
* Функция агрегации данных после выполннения действия
*/
next(failMsg) {
const { initiator, target } = this.params;
const { game } = this.params;
const { initiator, target, game } = this.params;
const weapon = initiator.weapon ? arena.items[initiator.weapon.code] : {};
if (failMsg) {
game.battleLog.fail({ ...failMsg, weapon });
game.recordOrderResult({ ...failMsg, weapon });
} else {
const msg = {
exp: this.status.exp,
Expand All @@ -187,8 +186,7 @@ class PhysConstructor {
weapon,
dmgType: 'physical',
};
game.addHistoryDamage(msg);
game.battleLog.success(msg);
game.recordOrderResult(msg);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/arena/Constuructors/SkillConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export abstract class Skill {
this.next();
this.getExp(initiator);
} catch (failMsg) {
game.battleLog.fail(failMsg);
game.recordOrderResult(failMsg);
}
}

Expand Down Expand Up @@ -111,15 +111,17 @@ export abstract class Skill {
* Успешное прохождение скила и отправка записи в BattleLog
*/
next(): void {
const { initiator, target, game } = this.params;
const args: SkillNext = {
exp: this.baseExp,
action: this.displayName,
actionType: 'skill',
target: this.params.target.nick,
initiator: this.params.initiator.nick,
target: target.nick,
initiator: initiator.nick,
msg: this.customMessage?.bind(this),
};
this.params.game.battleLog.success(args);

game.recordOrderResult(args);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/arena/Constuructors/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { FailArgs, SuccessArgs } from '../types';

export const isSuccessResult = (result: SuccessArgs | FailArgs): result is SuccessArgs => {
return !('message' in result);
};

export const isSuccessDamageResult = (result: SuccessArgs | FailArgs) => {
if (isSuccessResult(result)) {
return ('dmg' in result);
}

return false;
};
30 changes: 15 additions & 15 deletions src/arena/GameService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { createGame } from '@/api/game';
import { Profs } from '../data';
import * as channelHelper from '../helpers/channelHelper';
import type { Game } from '../models/game';
import { BattleLog } from './BattleLog';
import type { LongItem } from './Constuructors/LongMagicConstructor';
import { engine } from './engineService';
import HistoryService, { historyObj } from './HistoryService';
import { HistoryService, type HistoryItem } from './HistoryService';
import { LogService } from './LogService';
import type * as magics from './magics';
import OrderService from './OrderService';
import PlayersService, { Player } from './PlayersService';
import PlayersService, { type Player } from './PlayersService';
import { RoundService, RoundStatus } from './RoundService';
import testGame from './testGame';
import arena from './index';
Expand Down Expand Up @@ -37,7 +37,7 @@ export default class GameService {
players: PlayersService;
round = new RoundService();
orders = new OrderService();
battleLog = new BattleLog();
logger = new LogService();
history = new HistoryService();
longActions: Partial<Record<keyof typeof magics, LongItem[]>> = {};
info!: Game;
Expand Down Expand Up @@ -87,7 +87,7 @@ export default class GameService {
}

get checkRoundDamage(): boolean {
return !!this.history.getRoundDamage(this.round.count).length;
return !!this.history.hasDamageForRound(this.round.count);
}

/**
Expand Down Expand Up @@ -224,11 +224,12 @@ export default class GameService {
}
}

addHistoryDamage(dmgObj: Omit<historyObj, 'round'>): void {
this.history.addDamage({
...dmgObj,
round: this.round.count,
});
recordOrderResult(item: HistoryItem) {
this.history.addHistoryForRound(item, this.round.count);
}

getRoundResults() {
return this.history.getHistoryForRound(this.round.count);
}

/**
Expand Down Expand Up @@ -281,10 +282,9 @@ export default class GameService {
this.flags.global = {};
}

async sendMessages(): Promise<void> {
const messages = this.battleLog.format();
await channelHelper.sendBattleLogMessages(messages);
this.battleLog.reset();
async sendMessages(messages: HistoryItem[]): Promise<void> {
console.log(messages);
await this.logger.sendBattleLog(messages);
}

/**
Expand All @@ -300,7 +300,7 @@ export default class GameService {
break;
}
case RoundStatus.END_ROUND: {
void this.sendMessages();
void this.sendMessages(this.getRoundResults());
this.sortDead();
this.players.reset();
this.orders.reset();
Expand Down
50 changes: 0 additions & 50 deletions src/arena/HistoryService.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/arena/HistoryService/HistoryService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { FailArgs, SuccessArgs } from '@/arena/Constuructors/types';
import { isSuccessDamageResult } from '@/arena/Constuructors/utils';

export type HistoryItem = SuccessArgs | FailArgs;

/**
* Класс для хранения истории выполненных заказов
*/
export class HistoryService {
private roundsHistoryMap = new Map<number, HistoryItem[]>();

getHistoryForRound(round: number) {
return this.roundsHistoryMap.get(round) ?? [];
}

addHistoryForRound(item: HistoryItem, round: number) {
const roundHistory = this.getHistoryForRound(round);

roundHistory.push(item);
this.roundsHistoryMap.set(round, roundHistory);
}

hasDamageForRound(round: number) {
const roundHistory = this.getHistoryForRound(round);
return roundHistory.some(isSuccessDamageResult);
}
}
Loading
Loading