54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
import { Component } from '../core/Component.js';
|
|
|
|
export class Absorbable extends Component {
|
|
constructor() {
|
|
super('Absorbable');
|
|
this.evolutionData = {
|
|
human: 0,
|
|
beast: 0,
|
|
slime: 0
|
|
};
|
|
this.skillsGranted = []; // Array of skill IDs that can be absorbed
|
|
this.skillAbsorptionChance = 0.3; // 30% chance to absorb a skill
|
|
this.mutationChance = 0.1; // 10% chance for mutation
|
|
this.absorbed = false;
|
|
}
|
|
|
|
/**
|
|
* Set evolution data
|
|
*/
|
|
setEvolutionData(human, beast, slime) {
|
|
this.evolutionData = { human, beast, slime };
|
|
}
|
|
|
|
/**
|
|
* Add a skill that can be absorbed
|
|
*/
|
|
addSkill(skillId, chance = null) {
|
|
this.skillsGranted.push({
|
|
id: skillId,
|
|
chance: chance || this.skillAbsorptionChance
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get skills that were successfully absorbed (rolls for each)
|
|
*/
|
|
getAbsorbedSkills() {
|
|
const absorbed = [];
|
|
for (const skill of this.skillsGranted) {
|
|
if (Math.random() < skill.chance) {
|
|
absorbed.push(skill.id);
|
|
}
|
|
}
|
|
return absorbed;
|
|
}
|
|
|
|
/**
|
|
* Check if should mutate
|
|
*/
|
|
shouldMutate() {
|
|
return Math.random() < this.mutationChance;
|
|
}
|
|
}
|
|
|