Refactor hero resource balance action
This commit is contained in:
src
Action
ActionController.tsBalanceHeroResourcesAction.tsBuildBuildingAction.tsCheckBuildingRemainingTimeAction.tsClickButtonAction.tsCompleteTaskAction.tsGoToHeroVillageAction.tsGoToPageAction.tsGrabHeroAttributesAction.tsSendOnAdventureAction.tsStoreVillageState.tsTrainTrooperAction.tsUpdateBuildingTaskResourcesAction.tsUpgradeBuildingAction.tsUpgradeResourceToLevel.ts
Command.tsControlPanel.tsDataStorage.tsErrors.tsExecutor.tsGame.tsGrabber
HeroPageGrabber.tsResourceGrabber.tsStateGrabber.tsStateGrabberManager.tsVillageOverviewPageGrabber.ts
Page
Queue
Scheduler.tsState
Task
BalanceHeroResourcesTask.tsBuildBuildingTask.tsGrabVillageState.tsResourcesToLevel.tsSendOnAdventureTask.tsTaskController.tsTrainTroopTask.tsUpdateResourceContracts.tsUpgradeBuildingTask.ts
TaskQueueRenderer.ts@@ -1,6 +1,6 @@
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { DataStorage } from '../Storage/DataStorage';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { DataStorage } from '../DataStorage';
|
||||
import { Scheduler } from '../Scheduler';
|
||||
|
||||
const actionMap: { [name: string]: Function | undefined } = {};
|
||||
|
@@ -1,15 +1,24 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { grabResources, grabResourceStorage } from '../Page/ResourcesBlock';
|
||||
import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage';
|
||||
import { HeroAllResources, Resources } from '../Game';
|
||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||
import { HeroState } from '../State/HeroState';
|
||||
|
||||
@registerAction
|
||||
export class BalanceHeroResourcesAction extends ActionController {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
const resources = this.getRequirements();
|
||||
const activeVillageId = grabActiveVillageId();
|
||||
const heroVillageId = new HeroState().getVillageId();
|
||||
|
||||
if (heroVillageId === undefined || activeVillageId !== heroVillageId) {
|
||||
changeHeroResource(HeroAllResources);
|
||||
return;
|
||||
}
|
||||
|
||||
const resources = this.getRequirements(heroVillageId);
|
||||
|
||||
const resourcesAsList = resources.asList();
|
||||
const currentType = grabCurrentHeroResource();
|
||||
@@ -17,8 +26,11 @@ export class BalanceHeroResourcesAction extends ActionController {
|
||||
const sorted = resourcesAsList.sort((x, y) => y.value - x.value);
|
||||
const maxRequirement = sorted[0];
|
||||
const minRequirement = sorted[sorted.length - 1];
|
||||
const delta = maxRequirement.value - minRequirement.value;
|
||||
const eps = maxRequirement.value / 10;
|
||||
const delta = Math.abs(maxRequirement.value - minRequirement.value);
|
||||
const eps = Math.abs(maxRequirement.value / 10);
|
||||
|
||||
console.log('REQUIREMENTS', sorted);
|
||||
console.log('REQUIREMENTS', maxRequirement, minRequirement, delta, eps);
|
||||
|
||||
const resType = delta > eps ? maxRequirement.type : HeroAllResources;
|
||||
if (resType !== currentType) {
|
||||
@@ -26,11 +38,12 @@ export class BalanceHeroResourcesAction extends ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
private getRequirements() {
|
||||
private getRequirements(heroVillageId) {
|
||||
const resources = grabResources();
|
||||
const requiredResources = this.scheduler.getVillageRequiredResources(heroVillageId);
|
||||
|
||||
const villageId = grabActiveVillageId();
|
||||
const requiredResources = this.scheduler.getVillageRequiredResources(villageId);
|
||||
console.log('RESOURCES', resources);
|
||||
console.log('REQUIRED', requiredResources);
|
||||
|
||||
if (requiredResources) {
|
||||
return new Resources(
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Args } from '../Command';
|
||||
import { ActionError, GrabError, TryLaterError } from '../Errors';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { clickBuildButton } from '../Page/BuildingPage';
|
||||
|
||||
@registerAction
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { PostponeAllBuildingsError, GrabError } from '../Errors';
|
||||
import { grabActiveVillageId, grabBuildingQueueInfo } from '../Page/VillageBlock';
|
||||
import { BuildingQueueInfo } from '../Game';
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
|
||||
@registerAction
|
||||
export class ClickButtonAction extends ActionController {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
|
||||
@registerAction
|
||||
export class CompleteTaskAction extends ActionController {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { grabVillageList } from '../Page/VillageBlock';
|
||||
import { grabHeroVillage } from '../Page/HeroPage';
|
||||
import { path } from '../utils';
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
|
||||
@registerAction
|
||||
export class GoToPageAction extends ActionController {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { ActionError } from '../Errors';
|
||||
import { getNumber } from '../utils';
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { trimPrefix } from '../utils';
|
||||
import { AbortTaskError } from '../Errors';
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { StateGrabberManager } from '../State/StateGrabberManager';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { StateGrabberManager } from '../Grabber/StateGrabberManager';
|
||||
|
||||
@registerAction
|
||||
export class StoreVillageState extends ActionController {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Args } from '../Command';
|
||||
import { ActionError, TryLaterError } from '../Errors';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { getNumber, toNumber } from '../utils';
|
||||
|
||||
@registerAction
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { grabContractResources } from '../Page/BuildingPage';
|
||||
|
||||
@registerAction
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Args } from '../Command';
|
||||
import { ActionError, GrabError, PostponeAllBuildingsError } from '../Errors';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { clickUpgradeButton } from '../Page/BuildingPage';
|
||||
|
||||
@registerAction
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Args } from '../Command';
|
||||
import { ActionError, GrabError, TryLaterError } from '../Errors';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { clickUpgradeButton } from '../Page/BuildingPage';
|
||||
import { grabResourceDeposits } from '../Page/SlotBlock';
|
||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
||||
|
Reference in New Issue
Block a user