Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

fix: deixa de tentar atacar sem tropas ao destruir muralhas #143

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
7 changes: 5 additions & 2 deletions browser/lib/plunder/attack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEventListener, useMutationObserver } from '@vueuse/core';
import { assertInteger, isInstanceOf, assertString, assert } from '@tb-dev/ts-guard';
import { assertInteger, isInstanceOf, assertString } from '@tb-dev/ts-guard';
import { usePlunderConfigStore } from '$renderer/stores/plunder';
import { generateRandomDelay } from '$global/helpers';
import { wait } from '$browser/utils/helpers';
Expand Down Expand Up @@ -103,7 +103,10 @@ export async function sendAttackFromPlace(units: PlaceUnitsAmount): Promise<bool
assertString(unitName, `Could not determine unit name from class "${elClass}".`);
const unitAmount = unit.parseIntStrict(10, false);
assertInteger(unitAmount, `Could not determine ${unitName} amount.`);
assert(unitAmount === units[unitName], `${unitName} amount is not equal to the required amount.`);

if (unitAmount !== units[unitName]) {
throw new PlunderError(`${unitName} amount is not equal to the required amount.`);
};
};

await sendAttack(confirmationButton);
Expand Down
2 changes: 2 additions & 0 deletions browser/lib/plunder/wall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { openPlace } from '$lib/plunder/place';
import { sendAttackFromPlace } from '$lib/plunder/attack';
import { PlunderError } from '$browser/error';
import { PlunderAttackWithLoot } from '$lib/plunder/resources';
import { queryAvailableUnits } from '$lib/plunder/units';
import type { DemolitionTroops, StringWallLevel } from '$types/game';
import type { PlunderTargetInfo } from '$browser/lib/plunder/targets';

Expand All @@ -19,6 +20,7 @@ export async function destroyWall(info: PlunderTargetInfo): Promise<boolean> {
const neededUnits = demolitionTemplate.units[info.wallLevel.toString(10) as StringWallLevel];

// Verifica se há unidades o suficiente para destruir a muralha.
await queryAvailableUnits();
const unitStore = useUnitsStore();
for (const [key, value] of Object.entries(neededUnits) as [keyof DemolitionTroops, number][]) {
if (unitStore[key] < value) return false;
Expand Down