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