Simplify some code
This commit is contained in:
parent
d03894c89d
commit
d4ad7ec40c
@ -40,8 +40,6 @@ export enum ReceiveResourcesMode {
|
||||
Optimum = 'optimum',
|
||||
}
|
||||
|
||||
export type VillageList = Array<Village>;
|
||||
|
||||
export interface VillageSettings {
|
||||
sendResourcesThreshold: number;
|
||||
sendResourcesMultiplier: number;
|
||||
|
@ -25,35 +25,24 @@ export interface ExecutionSettings {
|
||||
}
|
||||
|
||||
export class Executor {
|
||||
private readonly version: string;
|
||||
private readonly scheduler: Scheduler;
|
||||
private readonly villageFactory: VillageFactory;
|
||||
private readonly grabberManager: GrabberManager;
|
||||
private readonly statistics: Statistics;
|
||||
private readonly executionState: ExecutionStorage;
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
version: string,
|
||||
scheduler: Scheduler,
|
||||
villageFactory: VillageFactory,
|
||||
grabberManager: GrabberManager,
|
||||
statistics: Statistics,
|
||||
logger: Logger
|
||||
private readonly version: string,
|
||||
private readonly scheduler: Scheduler,
|
||||
private readonly villageFactory: VillageFactory,
|
||||
private readonly grabberManager: GrabberManager,
|
||||
private readonly statistics: Statistics,
|
||||
private readonly logger: Logger
|
||||
) {
|
||||
this.version = version;
|
||||
this.scheduler = scheduler;
|
||||
this.villageFactory = villageFactory;
|
||||
this.grabberManager = grabberManager;
|
||||
this.statistics = statistics;
|
||||
this.executionState = new ExecutionStorage();
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
async run() {
|
||||
await waitForLoad();
|
||||
await sleepMicro();
|
||||
|
||||
this.scheduler.scheduleRegularTasks();
|
||||
this.renderInfo();
|
||||
|
||||
const sleep = createExecutionLoopSleeper();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { GrabError } from '../Errors';
|
||||
import { Resources } from '../Core/Resources';
|
||||
import { Coordinates, Village, VillageList } from '../Core/Village';
|
||||
import { Coordinates, Village } from '../Core/Village';
|
||||
import { BuildingQueueInfo } from '../Core/BuildingQueueInfo';
|
||||
import { getNumber } from '../Helpers/Convert';
|
||||
import { parseLocation } from '../Helpers/Browser';
|
||||
@ -13,8 +13,8 @@ function getVillageListItems() {
|
||||
return $elements;
|
||||
}
|
||||
|
||||
export function grabVillageList(): VillageList {
|
||||
const villageList: VillageList = [];
|
||||
export function grabVillageList(): Array<Village> {
|
||||
const villageList: Array<Village> = [];
|
||||
const $elements = getVillageListItems();
|
||||
$elements.each((idx, el) => {
|
||||
villageList.push(grabVillageInfo(jQuery(el)));
|
||||
|
@ -22,29 +22,15 @@ interface NextExecution {
|
||||
}
|
||||
|
||||
export class Scheduler {
|
||||
private readonly taskQueue: TaskQueue;
|
||||
private readonly actionQueue: ActionQueue;
|
||||
private readonly villageRepository: VillageRepositoryInterface;
|
||||
private readonly villageControllerFactory: VillageFactory;
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
taskQueue: TaskQueue,
|
||||
actionQueue: ActionQueue,
|
||||
villageRepository: VillageRepositoryInterface,
|
||||
villageControllerFactory: VillageFactory,
|
||||
logger: Logger
|
||||
) {
|
||||
this.taskQueue = taskQueue;
|
||||
this.actionQueue = actionQueue;
|
||||
this.villageRepository = villageRepository;
|
||||
this.villageControllerFactory = villageControllerFactory;
|
||||
this.logger = logger;
|
||||
|
||||
// this.taskQueue.push(GrabVillageStateTask.name, {}, timestamp());
|
||||
// this.taskQueue.push(UpdateResourceContractsTask.name, {}, timestamp());
|
||||
// this.taskQueue.push(BalanceHeroResourcesTask.name, {}, timestamp());
|
||||
private readonly taskQueue: TaskQueue,
|
||||
private readonly actionQueue: ActionQueue,
|
||||
private readonly villageRepository: VillageRepositoryInterface,
|
||||
private readonly villageControllerFactory: VillageFactory,
|
||||
private readonly logger: Logger
|
||||
) {}
|
||||
|
||||
scheduleRegularTasks() {
|
||||
const villages = this.villageRepository.all();
|
||||
for (let village of villages) {
|
||||
this.createUniqTaskTimer(5 * 60, RunVillageProductionTask.name, {
|
||||
@ -53,10 +39,12 @@ export class Scheduler {
|
||||
}
|
||||
|
||||
this.createUniqTaskTimer(10 * 60, GrabVillageStateTask.name);
|
||||
// @todo Только если деревень больше одной
|
||||
// this.createUniqTaskTimer(10 * 60, SendResourcesTask.name);
|
||||
if (villages.length > 1) {
|
||||
this.createUniqTaskTimer(10 * 60, SendResourcesTask.name);
|
||||
}
|
||||
this.createUniqTaskTimer(10 * 60, BalanceHeroResourcesTask.name);
|
||||
this.createUniqTaskTimer(20 * 60, UpdateResourceContractsTask.name);
|
||||
|
||||
// @todo Нужна отдельная настройка для запуска задачи
|
||||
// this.createUniqTaskTimer(60 * 60, SendOnAdventureTask.name);
|
||||
}
|
||||
|
@ -6,11 +6,7 @@ import { VillageState, VillageStateFactory } from './VillageState';
|
||||
import { Village } from '../Core/Village';
|
||||
|
||||
export class VillageFactory {
|
||||
private readonly villageRepository: VillageRepositoryInterface;
|
||||
|
||||
constructor(villageRepository: VillageRepositoryInterface) {
|
||||
this.villageRepository = villageRepository;
|
||||
}
|
||||
constructor(private readonly villageRepository: VillageRepositoryInterface) {}
|
||||
|
||||
getById(villageId: number): IntVillageFactory {
|
||||
return this.makeInternalFactory(this.villageRepository.getById(villageId));
|
||||
|
@ -10,13 +10,7 @@ import { Task, withResources, withTime } from '../Queue/Task';
|
||||
import { TaskId, uniqTaskId } from '../Queue/TaskId';
|
||||
|
||||
export class VillageTaskCollection {
|
||||
private readonly storage: VillageStorage;
|
||||
private readonly villageId: number;
|
||||
|
||||
constructor(villageId: number, storage: VillageStorage) {
|
||||
this.villageId = villageId;
|
||||
this.storage = storage;
|
||||
}
|
||||
constructor(private readonly villageId: number, private readonly storage: VillageStorage) {}
|
||||
|
||||
getTasks(): Array<Task> {
|
||||
return this.storage.getTasks();
|
||||
|
Loading…
Reference in New Issue
Block a user