Refactor hero resource balance action

This commit is contained in:
2020-04-19 10:38:48 +03:00
parent a6cc1b5383
commit 84ac56d052
42 changed files with 182 additions and 76 deletions

View File

@ -1,5 +1,15 @@
import { GrabError } from '../Errors';
import { HeroAllResources, HeroResourceType, ResourceMapping, ResourceType } from '../Game';
import { ActionError, GrabError } from '../Errors';
import { HeroAllResources, HeroAttributes, HeroResourceType, ResourceMapping, ResourceType } from '../Game';
import { getNumber } from '../utils';
export function grabHeroAttributes(): HeroAttributes {
const healthElement = jQuery('#attributes .attribute.health .powervalue .value');
if (healthElement.length !== 1) {
throw new GrabError('Health dom element not found');
}
return new HeroAttributes(getNumber(healthElement.text()));
}
export function grabCurrentHeroResource(): HeroResourceType {
for (let mp of ResourceMapping) {
@ -44,7 +54,7 @@ function heroResourceTypeToNumber(type: HeroResourceType): number {
export function grabHeroVillage(): string | undefined {
const status = jQuery('.heroStatusMessage').text();
const hrefText = jQuery('.heroStatusMessage a').text();
if (status.includes('в родной деревне')) {
if (status.toLowerCase().includes('в родной деревне')) {
return hrefText || undefined;
} else {
return undefined;