This iswas an actual question for for me. And I have one idea about it.
like says above, we need to implements buffs list and buff-logic updater
As previously said, we need to implement aBufflist and a logic updater for the buffs.change all specific player settings every frame in subclasses of Buff class
We then need to change all specific player settings every frame in subclasses of theBuffclass.get current player settings from changable settings-field
class Player { settings: AllPlayerStats;
private buffs: Array = []; private baseSettings: AllPlayerStats;
constructor(settings: AllPlayerStats) { this.baseSettings = settings; this.resetSettings(); }
addBuff(buff: Buff): void { this.buffs.push(buff); buff.start(this); }
findBuff(predcate(buff: Buff) => boolean): Buff {...}
removeBuff(buff: Buff): void {...}
update(dt: number): void { this.resetSettings(); this.buffs.forEach((item) => item.update(dt)); }
private resetSettings(): void { //some way to copy base to settings this.settings = this.baseSettings.copy(); } }
class Buff { private owner: Player;
start(owner: Player) { this.owner = owner; } update(dt: number): void { //here we change anything we want in subclasses like this.owner.settings.hp += 15; //if we need base value, just make owner.baseSettings public but don't change it! only read //also here logic for removal buff by time or something }}
We then get the current player settings from changable settings field.
class Player {
settings: AllPlayerStats;
private buffs: Array<Buff> = [];
private baseSettings: AllPlayerStats;
constructor(settings: AllPlayerStats) {
this.baseSettings = settings;
this.resetSettings();
}
addBuff(buff: Buff): void {
this.buffs.push(buff);
buff.start(this);
}
findBuff(predcate(buff: Buff) => boolean): Buff {...}
removeBuff(buff: Buff): void {...}
update(dt: number): void {
this.resetSettings();
this.buffs.forEach((item) => item.update(dt));
}
private resetSettings(): void {
//some way to copy base to settings
this.settings = this.baseSettings.copy();
}
}
class Buff {
private owner: Player;
start(owner: Player) { this.owner = owner; }
update(dt: number): void {
//here we change anything we want in subclasses like
this.owner.settings.hp += 15;
//if we need base value, just make owner.baseSettings public but don't change it! only read
//also here logic for removal buff by time or something
}
}
weIn this way, it can be easy to add new player statstats, with no change in buff-subclassesto the logic of the Buff subclasses.