File size: 1,472 Bytes
35b8b9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 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();
|