Chancellor / distributedWorkerService.ts
VoidBreach's picture
Upload 62 files
35b8b9c verified
Raw History Blame Contribute Delete
1.47 kB
import { WorkerStats } from '../types';
class DistributedWorkerService {
private _isActive = false;
private _wealth = 0;
private _interval: NodeJS.Timeout | null = null;
private _intensity = 0;
constructor() {
const saved = localStorage.getItem('lyceum_wealth');
if (saved) {
this._wealth = parseFloat(saved);
}
}
public toggleWorker(intensity: number): WorkerStats {
this._isActive = !this._isActive;
this._intensity = intensity;
if (this._isActive) {
this._startWorker(intensity);
} else {
this._stopWorker();
}
return this.getStats();
}
private _startWorker(intensity: number) {
if (this._interval) clearInterval(this._interval);
// Scholastic Wealth Acquisition:
// Converting sub-second cognitive reflexes into academic capital.
this._interval = setInterval(() => {
const earned = (intensity / 100) * 0.05 * (1 + Math.random() * 0.2);
this._wealth += earned;
// Persist wealth fragments
localStorage.setItem('lyceum_wealth', this._wealth.toString());
}, 1000);
}
private _stopWorker() {
if (this._interval) {
clearInterval(this._interval);
this._interval = null;
}
}
public getStats(): WorkerStats {
return {
isActive: this._isActive,
resourceIntensity: this._intensity || 50,
tokensEarned: this._wealth,
};
}
}
export const distributedWorkerService = new DistributedWorkerService();