From f7d8d4954ca0746592f5a7358c07dbdd175459df Mon Sep 17 00:00:00 2001 From: Andrew Ferreira Date: Tue, 18 Apr 2023 16:04:15 -0300 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20diminui=20o=20valor=20padr=C3=A3o=20?= =?UTF-8?q?de=20`maxDistanceC`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/database/plunder.ts | 2 +- electron/stores/plunder.ts | 2 +- renderer/stores/plunder.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/electron/database/plunder.ts b/electron/database/plunder.ts index d6584974..7554b1f0 100644 --- a/electron/database/plunder.ts +++ b/electron/database/plunder.ts @@ -211,7 +211,7 @@ PlunderConfig.init({ maxDistanceC: { type: DataTypes.FLOAT, allowNull: false, - defaultValue: 20, + defaultValue: 10, validate: { min: 1, isFloat: true diff --git a/electron/stores/plunder.ts b/electron/stores/plunder.ts index 87e9ed6b..ed5a45d5 100644 --- a/electron/stores/plunder.ts +++ b/electron/stores/plunder.ts @@ -95,7 +95,7 @@ export function definePlunderConfigStore(mechanus: Mechanus) { const plunderedResourcesRatio = ref(1, ratioValidator()); const pageDelay = ref(2000, delayValidator()); const villageDelay = ref(2000, delayValidator()); - const maxDistanceC = ref(20, maxDistanceValidator()); + const maxDistanceC = ref(10, maxDistanceValidator()); const plunderGroupId = ref(null, positiveIntegerOrNullRef); const fieldsPerWave = ref(10, maxDistanceValidator(5)); diff --git a/renderer/stores/plunder.ts b/renderer/stores/plunder.ts index 34c2802c..be9c9008 100644 --- a/renderer/stores/plunder.ts +++ b/renderer/stores/plunder.ts @@ -39,7 +39,7 @@ export const usePlunderConfigStore = defineStore('plunder-config', () => { const plunderedResourcesRatio = ref(1); const pageDelay = ref(2000); const villageDelay = ref(2000); - const maxDistanceC = ref(20); + const maxDistanceC = ref(10); const plunderGroupId = ref(null); const fieldsPerWave = ref(10); From 9922d4fb91f395c09d85729c46158bebcabde24f Mon Sep 17 00:00:00 2001 From: Andrew Ferreira Date: Tue, 18 Apr 2023 17:15:52 -0300 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20prepara=20a=20interface=20para=20as?= =?UTF-8?q?=20novas=20op=C3=A7=C3=B5es=20do=20modelo=20C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/database/plunder.ts | 175 +++++++++++------- electron/stores/plunder.ts | 94 +++++----- .../components/ConfigPlunderGridAttack.vue | 2 +- .../components/ConfigPlunderGridTemplateC.vue | 53 +++++- renderer/stores/plunder.ts | 93 ++++++---- types/plunder.ts | 72 ++++--- 6 files changed, 305 insertions(+), 184 deletions(-) diff --git a/electron/database/plunder.ts b/electron/database/plunder.ts index 7554b1f0..9b063216 100644 --- a/electron/database/plunder.ts +++ b/electron/database/plunder.ts @@ -31,25 +31,33 @@ export class PlunderConfig extends Model, InferCr declare readonly ignoreDelay: boolean; declare readonly blindAttack: boolean; - // Configurações - declare readonly wallLevelToIgnore: WallLevel; - declare readonly wallLevelToDestroy: WallLevel; - declare readonly destroyWallMaxDistance: number; - declare readonly attackDelay: number; - declare readonly resourceRatio: number; - declare readonly minutesUntilReload: number; + // Ataque declare readonly maxDistance: number; declare readonly ignoreOlderThan: number; - declare readonly plunderedResourcesRatio: number; - declare readonly pageDelay: number; - declare readonly villageDelay: number; + declare readonly attackDelay: number; + declare readonly resourceRatio: number; + declare readonly blindAttackPattern: BlindAttackPattern; + + // Modelo C + declare readonly useCPattern: UseCPattern; declare readonly maxDistanceC: number; + declare readonly ignoreOlderThanC: number; + declare readonly useCWhenResourceRatioIsBiggerThan: number; + // Grupo declare readonly plunderGroupId: number | null; declare readonly fieldsPerWave: number; + declare readonly villageDelay: number; - declare readonly blindAttackPattern: BlindAttackPattern; - declare readonly useCPattern: UseCPattern; + // Muralha + declare readonly wallLevelToIgnore: WallLevel; + declare readonly wallLevelToDestroy: WallLevel; + declare readonly destroyWallMaxDistance: number; + + // Outros + declare readonly minutesUntilReload: number; + declare readonly plunderedResourcesRatio: number; + declare readonly pageDelay: number; }; PlunderConfig.init({ @@ -65,6 +73,7 @@ PlunderConfig.init({ } }, + // Painel active: { type: DataTypes.BOOLEAN, allowNull: false, @@ -101,34 +110,22 @@ PlunderConfig.init({ defaultValue: false }, - wallLevelToIgnore: { - type: DataTypes.INTEGER, + // Ataque + maxDistance: { + type: DataTypes.FLOAT, allowNull: false, - defaultValue: 1, + defaultValue: 20, validate: { - isWallLevel(value: unknown) { - assertWallLevel(value, DatabaseError); - } + min: 1, + isFloat: true } }, - - wallLevelToDestroy: { + ignoreOlderThan: { type: DataTypes.INTEGER, allowNull: false, - defaultValue: 1, - validate: { - isWallLevel(value: unknown) { - assertWallLevel(value, DatabaseError); - } - } - }, - destroyWallMaxDistance: { - type: DataTypes.FLOAT, - allowNull: false, - defaultValue: 20, + defaultValue: 10, validate: { - min: 1, - isFloat: true + isInt: true } }, attackDelay: { @@ -151,51 +148,63 @@ PlunderConfig.init({ isFloat: true } }, - minutesUntilReload: { - type: DataTypes.INTEGER, + blindAttackPattern: { + type: DataTypes.STRING, allowNull: false, - defaultValue: 10, + defaultValue: 'smaller' satisfies BlindAttackPattern, validate: { - min: 1, - max: 60, - isInt: true + isIn: [['smaller', 'bigger'] satisfies BlindAttackPattern[]] } }, - maxDistance: { + + // Modelo C + useCPattern: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 'normal' satisfies UseCPattern, + validate: { + isIn: [['excess', 'normal', 'only'] satisfies UseCPattern[]] + } + }, + maxDistanceC: { type: DataTypes.FLOAT, allowNull: false, - defaultValue: 20, + defaultValue: 10, validate: { min: 1, isFloat: true } }, - ignoreOlderThan: { + ignoreOlderThanC: { type: DataTypes.INTEGER, allowNull: false, - defaultValue: 10, + defaultValue: 5, validate: { isInt: true } }, - plunderedResourcesRatio: { + useCWhenResourceRatioIsBiggerThan: { type: DataTypes.FLOAT, allowNull: false, - defaultValue: 1, + defaultValue: 1.5, validate: { - min: 0.2, - max: 1, + min: 1, isFloat: true } }, - pageDelay: { + + // Grupo + plunderGroupId: { type: DataTypes.INTEGER, + allowNull: true + }, + fieldsPerWave: { + type: DataTypes.FLOAT, allowNull: false, - defaultValue: 2000, + defaultValue: 10, validate: { - min: 100, - max: 60000, - isInt: true + min: 5, + isFloat: true } }, villageDelay: { @@ -208,46 +217,70 @@ PlunderConfig.init({ isInt: true } }, - maxDistanceC: { + + // Muralha + wallLevelToIgnore: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 1, + validate: { + isWallLevel(value: unknown) { + assertWallLevel(value, DatabaseError); + } + } + }, + + wallLevelToDestroy: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 1, + validate: { + isWallLevel(value: unknown) { + assertWallLevel(value, DatabaseError); + } + } + }, + destroyWallMaxDistance: { type: DataTypes.FLOAT, allowNull: false, - defaultValue: 10, + defaultValue: 20, validate: { min: 1, isFloat: true } }, - plunderGroupId: { + // Outros + minutesUntilReload: { type: DataTypes.INTEGER, - allowNull: true - }, - fieldsPerWave: { - type: DataTypes.FLOAT, allowNull: false, defaultValue: 10, validate: { - min: 5, - isFloat: true + min: 1, + max: 60, + isInt: true } }, - - blindAttackPattern: { - type: DataTypes.STRING, + plunderedResourcesRatio: { + type: DataTypes.FLOAT, allowNull: false, - defaultValue: 'smaller' satisfies BlindAttackPattern, + defaultValue: 1, validate: { - isIn: [['smaller', 'bigger'] satisfies BlindAttackPattern[]] + min: 0.2, + max: 1, + isFloat: true } }, - useCPattern: { - type: DataTypes.STRING, + pageDelay: { + type: DataTypes.INTEGER, allowNull: false, - defaultValue: 'normal' satisfies UseCPattern, + defaultValue: 2000, validate: { - isIn: [['normal', 'only'] satisfies UseCPattern[]] + min: 100, + max: 60000, + isInt: true } - } + } }, { sequelize, tableName: 'plunder_config', timestamps: true }); export class PlunderHistory extends Model, InferCreationAttributes> implements PlunderHistoryType { diff --git a/electron/stores/plunder.ts b/electron/stores/plunder.ts index ed5a45d5..e298f332 100644 --- a/electron/stores/plunder.ts +++ b/electron/stores/plunder.ts @@ -1,4 +1,5 @@ import { ref } from 'mechanus'; +import { Kronos } from '$global/constants'; import { isInteger, isFiniteNumber } from '$global/guards'; import type { WallLevel } from '$types/game'; import type { Mechanus, MechanusRefOptions } from 'mechanus'; @@ -40,43 +41,29 @@ export function definePlunderStore(mechanus: Mechanus) { // Patterns. const blindAttackPatterns: BlindAttackPattern[] = ['smaller', 'bigger']; -const useCPatterns: UseCPattern[] = ['normal', 'only']; +const useCPatterns: UseCPattern[] = ['excess', 'normal', 'only']; export function definePlunderConfigStore(mechanus: Mechanus) { - const delayValidator = (): MechanusRefOptions => { - const refOptions = { ...positiveIntegerRef }; - refOptions.validator = (value: unknown): value is number => { - return isInteger(value) && value >= 100 && value <= 60000; - }; - return refOptions; - }; - - const ratioValidator = (): MechanusRefOptions => { + const finiteValidator = (min: number, max: number | null = null): MechanusRefOptions => { const refOptions = { ...positiveNumberRef }; refOptions.validator = (value: unknown): value is number => { - return isFiniteNumber(value) && value >= 0.2 && value <= 1; + if (max) return isFiniteNumber(value) && value >= min && value <= max; + return isFiniteNumber(value) && value >= min; }; return refOptions; }; - const minutesUntilReloadValidator = (): MechanusRefOptions => { + const integerValidator = (min: number, max: number | null = null): MechanusRefOptions => { const refOptions = { ...positiveIntegerRef }; refOptions.validator = (value: unknown): value is number => { - return isInteger(value) && value >= 1 && value <= 60; - }; - return refOptions; - }; - - const maxDistanceValidator = (min: number = 1): MechanusRefOptions => { - const refOptions = { ...positiveNumberRef }; - refOptions.validator = (value: unknown): value is number => { - return isFiniteNumber(value) && value >= min; + if (max) return isInteger(value) && value >= min && value <= max; + return isInteger(value) && value >= min; }; return refOptions; }; + // Painel const active = ref(false, booleanRef); - const ignoreWall = ref(false, booleanRef); const destroyWall = ref(false, booleanRef); const groupAttack = ref(false, booleanRef); @@ -84,24 +71,33 @@ export function definePlunderConfigStore(mechanus: Mechanus) { const ignoreDelay = ref(false, booleanRef); const blindAttack = ref(false, booleanRef); - const wallLevelToIgnore = ref(1, wallLevelRef); - const wallLevelToDestroy = ref(1, wallLevelRef); - const destroyWallMaxDistance = ref(20, maxDistanceValidator()); - const attackDelay = ref(200, delayValidator()); - const resourceRatio = ref(0.8, ratioValidator()); - const minutesUntilReload = ref(10, minutesUntilReloadValidator()); - const maxDistance = ref(20, maxDistanceValidator()); + // Ataque + const maxDistance = ref(20, finiteValidator(1)); const ignoreOlderThan = ref(10, positiveIntegerRef); - const plunderedResourcesRatio = ref(1, ratioValidator()); - const pageDelay = ref(2000, delayValidator()); - const villageDelay = ref(2000, delayValidator()); - const maxDistanceC = ref(10, maxDistanceValidator()); + const attackDelay = ref(200, integerValidator(100, Kronos.Minute)); + const resourceRatio = ref(0.8, finiteValidator(0.2, 1)); + const blindAttackPattern = ref('smaller', arrayIncludesRef(blindAttackPatterns)); + + // Modelo C + const useCPattern = ref('normal', arrayIncludesRef(useCPatterns)); + const maxDistanceC = ref(10, finiteValidator(1)); + const ignoreOlderThanC = ref(5, positiveIntegerRef); + const useCWhenResourceRatioIsBiggerThan = ref(1.5, finiteValidator(1)); + // Grupo const plunderGroupId = ref(null, positiveIntegerOrNullRef); - const fieldsPerWave = ref(10, maxDistanceValidator(5)); + const fieldsPerWave = ref(10, finiteValidator(5)); + const villageDelay = ref(2000, integerValidator(100, Kronos.Minute)); - const blindAttackPattern = ref('smaller', arrayIncludesRef(blindAttackPatterns)); - const useCPattern = ref('normal', arrayIncludesRef(useCPatterns)); + // Muralha + const wallLevelToIgnore = ref(1, wallLevelRef); + const wallLevelToDestroy = ref(1, wallLevelRef); + const destroyWallMaxDistance = ref(20, finiteValidator(1)); + + // Outros + const minutesUntilReload = ref(10, integerValidator(1, 60)); + const plunderedResourcesRatio = ref(1, finiteValidator(0.2, 1)); + const pageDelay = ref(2000, integerValidator(100, Kronos.Minute)); return mechanus.define('plunderConfig', { active, @@ -112,24 +108,28 @@ export function definePlunderConfigStore(mechanus: Mechanus) { ignoreDelay, blindAttack, - wallLevelToIgnore, - wallLevelToDestroy, - destroyWallMaxDistance, - attackDelay, - resourceRatio, - minutesUntilReload, maxDistance, ignoreOlderThan, - plunderedResourcesRatio, - pageDelay, - villageDelay, + attackDelay, + resourceRatio, + blindAttackPattern, + + useCPattern, maxDistanceC, + ignoreOlderThanC, + useCWhenResourceRatioIsBiggerThan, plunderGroupId, fieldsPerWave, + villageDelay, - blindAttackPattern, - useCPattern + wallLevelToIgnore, + wallLevelToDestroy, + destroyWallMaxDistance, + + minutesUntilReload, + plunderedResourcesRatio, + pageDelay } satisfies MechanusPlunderConfigStoreType); }; diff --git a/modules/components/ConfigPlunderGridAttack.vue b/modules/components/ConfigPlunderGridAttack.vue index 535306b5..209caa33 100644 --- a/modules/components/ConfigPlunderGridAttack.vue +++ b/modules/components/ConfigPlunderGridAttack.vue @@ -50,7 +50,7 @@ const blindAttackOptions = [ - + Se o último ataque ocorreu a uma quantidade de horas superior a indicada, o Ares não atacará a aldeia. diff --git a/modules/components/ConfigPlunderGridTemplateC.vue b/modules/components/ConfigPlunderGridTemplateC.vue index 2385aca2..49db9171 100644 --- a/modules/components/ConfigPlunderGridTemplateC.vue +++ b/modules/components/ConfigPlunderGridTemplateC.vue @@ -1,7 +1,7 @@ @@ -55,7 +60,51 @@ const useCOptions = [ - + + + + + + + + O Ares não atacará usando o modelo C se o último ataque ocorreu a uma quantidade de horas superior a indicada. + + + + + + + + + + + + Uma razão de saque alta indica que a aldeia tem recursos além do que os modelos podem saquear. + Através dessa opção, é possível atacar essas aldeias com recursos em excesso usando o modelo C. + + + + + diff --git a/renderer/stores/plunder.ts b/renderer/stores/plunder.ts index be9c9008..cc8716d0 100644 --- a/renderer/stores/plunder.ts +++ b/renderer/stores/plunder.ts @@ -27,25 +27,33 @@ export const usePlunderConfigStore = defineStore('plunder-config', () => { const ignoreDelay = ref(false); const blindAttack = ref(false); - // Configurações - const wallLevelToIgnore = ref(1); - const wallLevelToDestroy = ref(1); - const destroyWallMaxDistance = ref(20); - const attackDelay = ref(200); - const resourceRatio = ref(0.8); - const minutesUntilReload = ref(10); + // Ataque const maxDistance = ref(20); const ignoreOlderThan = ref(10); - const plunderedResourcesRatio = ref(1); - const pageDelay = ref(2000); - const villageDelay = ref(2000); + const attackDelay = ref(200); + const resourceRatio = ref(0.8); + const blindAttackPattern = ref('smaller'); + + // Modelo C + const useCPattern = ref('normal'); const maxDistanceC = ref(10); + const ignoreOlderThanC = ref(5); + const useCWhenResourceRatioIsBiggerThan = ref(1.5); + // Grupo const plunderGroupId = ref(null); const fieldsPerWave = ref(10); + const villageDelay = ref(2000); - const blindAttackPattern = ref('smaller'); - const useCPattern = ref('normal'); + // Muralha + const wallLevelToIgnore = ref(1); + const wallLevelToDestroy = ref(1); + const destroyWallMaxDistance = ref(20); + + // Outros + const minutesUntilReload = ref(10); + const plunderedResourcesRatio = ref(1); + const pageDelay = ref(2000); function raw(): PlunderConfigType { return { @@ -57,28 +65,33 @@ export const usePlunderConfigStore = defineStore('plunder-config', () => { ignoreDelay: ignoreDelay.value, blindAttack: blindAttack.value, - wallLevelToIgnore: wallLevelToIgnore.value, - wallLevelToDestroy: wallLevelToDestroy.value, - destroyWallMaxDistance: destroyWallMaxDistance.value, - attackDelay: attackDelay.value, - resourceRatio: resourceRatio.value, - minutesUntilReload: minutesUntilReload.value, maxDistance: maxDistance.value, ignoreOlderThan: ignoreOlderThan.value, - plunderedResourcesRatio: plunderedResourcesRatio.value, - pageDelay: pageDelay.value, - villageDelay: villageDelay.value, + attackDelay: attackDelay.value, + resourceRatio: resourceRatio.value, + blindAttackPattern: blindAttackPattern.value, + + useCPattern: useCPattern.value, maxDistanceC: maxDistanceC.value, + ignoreOlderThanC: ignoreOlderThanC.value, + useCWhenResourceRatioIsBiggerThan: useCWhenResourceRatioIsBiggerThan.value, plunderGroupId: plunderGroupId.value, fieldsPerWave: fieldsPerWave.value, + villageDelay: villageDelay.value, - blindAttackPattern: blindAttackPattern.value, - useCPattern: useCPattern.value + wallLevelToIgnore: wallLevelToIgnore.value, + wallLevelToDestroy: wallLevelToDestroy.value, + destroyWallMaxDistance: destroyWallMaxDistance.value, + + minutesUntilReload: minutesUntilReload.value, + plunderedResourcesRatio: plunderedResourcesRatio.value, + pageDelay: pageDelay.value }; }; return { + // Painel active, ignoreWall, destroyWall, @@ -87,25 +100,35 @@ export const usePlunderConfigStore = defineStore('plunder-config', () => { ignoreDelay, blindAttack, - wallLevelToIgnore, - wallLevelToDestroy, - destroyWallMaxDistance, - attackDelay, - resourceRatio, - minutesUntilReload, + // Ataque maxDistance, ignoreOlderThan, - plunderedResourcesRatio, - pageDelay, - villageDelay, + attackDelay, + resourceRatio, + blindAttackPattern, + + // Modelo C + useCPattern, maxDistanceC, + ignoreOlderThanC, + useCWhenResourceRatioIsBiggerThan, + // Grupo plunderGroupId, fieldsPerWave, + villageDelay, - blindAttackPattern, - useCPattern, - + // Muralha + wallLevelToIgnore, + wallLevelToDestroy, + destroyWallMaxDistance, + + // Outros + minutesUntilReload, + plunderedResourcesRatio, + pageDelay, + + // Funções raw } satisfies PiniaPlunderConfigStoreType; }); diff --git a/types/plunder.ts b/types/plunder.ts index 56e0958f..c459c5c8 100644 --- a/types/plunder.ts +++ b/types/plunder.ts @@ -19,20 +19,23 @@ export type PlunderInfoType = { /** * Padrão de ataque quando o Plunder não tem informações dos exploradores. * - * bigger: Ataca com a maior capacidade de carga possível. + * `bigger`: Ataca com a maior capacidade de carga possível. * - * smaller: Ataca com a menor capacidade de carga possível. + * `smaller`: Ataca com a menor capacidade de carga possível. */ export type BlindAttackPattern = 'bigger' | 'smaller'; /** * Padrão de ataque quando o Plunder está usando o modelo C. * - * normal: Tenta utilizar o modelo C, se não for possível, utiliza outro modelo. + * `normal`: Tenta utilizar o modelo C, se não for possível, utiliza outro. * - * only: Utiliza apenas o modelo C. + * `excess`: Utiliza o modelo C apenas se a razão entre a quantidade de recursos esperados e a + * capacidade de carga do modelo atacante for maior que o valor indicado em `useCWhenResourceRatioIsBiggerThan`. + * + * `only`: Utiliza apenas o modelo C. */ -export type UseCPattern = 'normal' | 'only'; +export type UseCPattern = 'excess' | 'normal' | 'only'; export type PlunderConfigType = { // Painel @@ -51,23 +54,50 @@ export type PlunderConfigType = { /** Se ativado, o Plunder não levará em consideração as informações dos exploradores. */ blindAttack: boolean; - // Configurações + // Ataque + /** Distância máxima para os ataques normais do Plunder. */ + maxDistance: number; + /** Ignora aldeias cujo último ataque ocorreu há uma quantidade de horas superior à indicada. */ + ignoreOlderThan: number; + /** Delay médio entre os ataques. */ + attackDelay: number; + /** Razão entre a quantidade de recursos esperados e a capacidade de carga do modelo atacante. */ + resourceRatio: number; + /** Determina o padrão de ataque quando o Plunder não tem informações dos exploradores. */ + blindAttackPattern: BlindAttackPattern; + + // Modelo C + /** Determina o padrão de ataque quando o Plunder está usando o modelo C. */ + useCPattern: UseCPattern; + /** Distância máxima para ataques usando o modelo C. */ + maxDistanceC: number; + /** Ao usar o modelo C, ignora aldeias cujo último ataque ocorreu há uma quantidade de horas superior à indicada. */ + ignoreOlderThanC: number; + /** + * Utiliza o modelo C apenas se a razão entre a quantidade de recursos esperados e a + * capacidade de carga do modelo atacante for maior que o valor indicado. + */ + useCWhenResourceRatioIsBiggerThan: number; + + // Grupo + /** ID do grupo que será utilizado para atacar. */ + plunderGroupId: number | null; + /** Máximo de campos por onda. */ + fieldsPerWave: number; + /** Delay médio entre cada troca de aldeia. */ + villageDelay: number; + + // Muralha /** Nível da muralha a partir do qual ele deve ignorar. */ wallLevelToIgnore: number; /** Nível da muralha a partir do qual ele deve demolir. */ wallLevelToDestroy: number; /** Distância máxima para ataques de destruição de muralha. */ destroyWallMaxDistance: number; - /** Delay médio entre os ataques. */ - attackDelay: number; - /** Razão entre a quantidade de recursos esperados e a capacidade de carga do modelo atacante. */ - resourceRatio: number; + + // Outros /** Minutos até que a página seja recarregada automaticamente. */ minutesUntilReload: number; - /** Distância máxima para os ataques normais do Plunder. */ - maxDistance: number; - /** Ignora aldeias cujo último ataque ocorreu há uma quantidade de horas superior à indicada. */ - ignoreOlderThan: number; /** * Por padrão, o Plunder sempre assume que o modelo saqueou 100% de sua capacidade de carga. * No entanto, essa opção permite ao usuário alterar o valor padrão. @@ -75,20 +105,6 @@ export type PlunderConfigType = { plunderedResourcesRatio: number; /** Delay médio entre cada troca de página. */ pageDelay: number; - /** Delay médio entre cada troca de aldeia. */ - villageDelay: number; - - /** ID do grupo que será utilizado para atacar. */ - plunderGroupId: number | null; - /** Máximo de campos por onda. */ - fieldsPerWave: number; - /** Distância máxima para ataques usando o modelo C. */ - maxDistanceC: number; - - /** Determina o padrão de ataque quando o Plunder não tem informações dos exploradores. */ - blindAttackPattern: BlindAttackPattern; - /** Determina o padrão de ataque quando o Plunder está usando o modelo C. */ - useCPattern: UseCPattern; }; export type PlunderPanelConfig = Pick Date: Tue, 18 Apr 2023 17:56:30 -0300 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20aumenta=20o=20valor=20padr=C3=A3o=20?= =?UTF-8?q?de=20`useCWhenResourceRatioIsBiggerThan`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/database/plunder.ts | 2 +- electron/stores/plunder.ts | 2 +- renderer/stores/plunder.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/electron/database/plunder.ts b/electron/database/plunder.ts index 9b063216..7d02e672 100644 --- a/electron/database/plunder.ts +++ b/electron/database/plunder.ts @@ -186,7 +186,7 @@ PlunderConfig.init({ useCWhenResourceRatioIsBiggerThan: { type: DataTypes.FLOAT, allowNull: false, - defaultValue: 1.5, + defaultValue: 3, validate: { min: 1, isFloat: true diff --git a/electron/stores/plunder.ts b/electron/stores/plunder.ts index e298f332..6d5952aa 100644 --- a/electron/stores/plunder.ts +++ b/electron/stores/plunder.ts @@ -82,7 +82,7 @@ export function definePlunderConfigStore(mechanus: Mechanus) { const useCPattern = ref('normal', arrayIncludesRef(useCPatterns)); const maxDistanceC = ref(10, finiteValidator(1)); const ignoreOlderThanC = ref(5, positiveIntegerRef); - const useCWhenResourceRatioIsBiggerThan = ref(1.5, finiteValidator(1)); + const useCWhenResourceRatioIsBiggerThan = ref(3, finiteValidator(1)); // Grupo const plunderGroupId = ref(null, positiveIntegerOrNullRef); diff --git a/renderer/stores/plunder.ts b/renderer/stores/plunder.ts index cc8716d0..e87a4d3d 100644 --- a/renderer/stores/plunder.ts +++ b/renderer/stores/plunder.ts @@ -38,7 +38,7 @@ export const usePlunderConfigStore = defineStore('plunder-config', () => { const useCPattern = ref('normal'); const maxDistanceC = ref(10); const ignoreOlderThanC = ref(5); - const useCWhenResourceRatioIsBiggerThan = ref(1.5); + const useCWhenResourceRatioIsBiggerThan = ref(3); // Grupo const plunderGroupId = ref(null); From 6f91698cbfd4b53b55312cf6386e3e8ea80671e1 Mon Sep 17 00:00:00 2001 From: Andrew Ferreira Date: Tue, 18 Apr 2023 17:57:05 -0300 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20adiciona=20novas=20op=C3=A7=C3=B5es?= =?UTF-8?q?=20para=20o=20modelo=20C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser/lib/plunder/templates.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/browser/lib/plunder/templates.ts b/browser/lib/plunder/templates.ts index 66a5a590..56fbc6c6 100644 --- a/browser/lib/plunder/templates.ts +++ b/browser/lib/plunder/templates.ts @@ -3,6 +3,7 @@ import { ipcRenderer } from 'electron'; import { isKeyOf, assertInteger, isInteger } from '$global/guards'; import { useUnitsStore } from '$renderer/stores/units'; import { assertFarmUnit } from '$global/guards'; +import { Kronos } from '$global/constants'; import { PlunderError } from '$browser/error'; import { ipcInvoke } from '$renderer/ipc'; import type { usePlunderConfigStore } from '$renderer/stores/plunder'; @@ -152,6 +153,15 @@ function parseUnitAmount(row: 'a' | 'b', fields: Element[]) { }; }; +/** + * Calcula a razão entre a quantidade de recursos na aldeia-alvo e a capacidade de carga do modelo. + * @param resources Recursos na aldeia-alvo. + * @param template Modelo atacante. + */ +function calcResourceRatio(resources: number, template: PlunderTemplate) { + return resources / template.carry.value; +}; + /** * Filtra todos os modelos de saque disponíveis de acordo com a quantidade de recursos na aldeia-alvo. * Caso a função retorne uma lista vazia, o ataque não deve ser enviado. @@ -200,12 +210,12 @@ async function filterTemplates(info: PlunderTargetInfo, config: ReturnType resources / template.carry.value >= config.resourceRatio); + bigger = bigger.filter((template) => calcResourceRatio(resources, template) >= config.resourceRatio); return [...smaller, ...bigger]; }; export async function pickBestTemplate(info: PlunderTargetInfo, config: ReturnType) { - if (config.useC) { + if (config.useC && config.useCPattern !== 'excess') { const templateC = await getTemplateC(info, config); if (templateC) return templateC; @@ -221,13 +231,24 @@ export async function pickBestTemplate(info: PlunderTargetInfo, config: ReturnTy config.blindAttack && config.blindAttackPattern === 'smaller' ) { - // Se a opção `blindAttack` estiver ativada e o padrão de seleção for `smaller`, - // seleciona o modelo com menor capacidade de carga. + // Se não houver informações sobre os recursos, a opção `blindAttack` estiver ativada + // e o padrão de seleção for `smaller`, seleciona o modelo com menor capacidade de carga. return templates.reduce((prev, curr) => prev.carry < curr.carry ? prev : curr); }; // Do contrário, apenas seleciona o modelo com maior capacidade de carga. - return templates.reduce((prev, curr) => prev.carry > curr.carry ? prev : curr); + const best = templates.reduce((prev, curr) => prev.carry > curr.carry ? prev : curr); + + if ( + config.useC && + config.useCPattern === 'excess' && + calcResourceRatio(info.res.total, best) > config.useCWhenResourceRatioIsBiggerThan + ) { + const templateC = await getTemplateC(info, config); + if (templateC) return templateC; + }; + + return best; }; async function getTemplateC(info: PlunderTargetInfo, config: ReturnType) { @@ -236,6 +257,7 @@ async function getTemplateC(info: PlunderTargetInfo, config: ReturnType config.maxDistanceC) return null; + if ((Date.now() - info.lastAttack) > config.ignoreOlderThanC * Kronos.Hour) return null; const json = button.getAttributeStrict('data-units-forecast'); const cUnits = JSON.parse(json) as UnitAmount;