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

Commit

Permalink
Merge pull request #163 from ferreira-tb/162-navegação-desnecessária-…
Browse files Browse the repository at this point in the history
…para-a-próxima-página-do-as

fix: impede troca de página desnecessária quando usando o modelo C
  • Loading branch information
ferreira-tb authored Apr 19, 2023
2 parents eabc914 + 5e4dd48 commit c10a0c3
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions browser/lib/plunder/next.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toRaw } from 'vue';
import { nextTick, toRaw } from 'vue';
import { ipcInvoke, ipcSend } from '$renderer/ipc';
import { getAllTemplates } from '$lib/plunder/templates';
import { queryAvailableUnits } from '$lib/plunder/units';
Expand All @@ -12,6 +12,7 @@ import type { PlunderTargetInfo } from '$lib/plunder/targets';
export async function handleLackOfTargets(groupInfo: PlunderGroupType | null) {
try {
await queryAvailableUnits();
await nextTick();
const config = usePlunderConfigStore();
const wentToNextPage = await navigateToNextPage(config, groupInfo);
if (wentToNextPage || !config.groupAttack || !groupInfo) return;
Expand All @@ -23,8 +24,7 @@ export async function handleLackOfTargets(groupInfo: PlunderGroupType | null) {

async function navigateToNextPage(config: ReturnType<typeof usePlunderConfigStore>, groupInfo: PlunderGroupType | null) {
try {
// Verifica se há tropas disponíveis em algum dos modelos.
if (!canSomeTemplateAttack(config)) return false;
if (!canSomeTemplateAttack()) return false;

let maxDistance = config.maxDistance;
if (config.groupAttack && groupInfo) {
Expand Down Expand Up @@ -53,7 +53,7 @@ function navigateToNextVillage(config: ReturnType<typeof usePlunderConfigStore>,
if (groupVillage.done) return;

if (
!canSomeTemplateAttack(config) ||
!canSomeTemplateAttack() ||
isOverWaveMaxDistance(config, groupVillage) ||
isOverTemplateCMaxDistance(config, groupVillage)
) {
Expand All @@ -71,13 +71,9 @@ function navigateToNextVillage(config: ReturnType<typeof usePlunderConfigStore>,
};

/** Verifica se algum dos modelos pode ser usado para atacar. */
function canSomeTemplateAttack(config: ReturnType<typeof usePlunderConfigStore>) {
function canSomeTemplateAttack() {
const templatesMap = getAllTemplates();

// Se os ataques com o modelo C não estiverem habilitados, remove-o da lista.
let allTemplates = Array.from(templatesMap.values());
if (!config.useC) allTemplates = allTemplates.filter((template) => template.type !== 'c');

const allTemplates = Array.from(templatesMap.values()).filter((template) => template.type !== 'c');
const status = allTemplates.map((template) => template.ok.value);
return status.some((ok) => ok);
};
Expand Down

0 comments on commit c10a0c3

Please sign in to comment.