This commit is contained in:
Vick Scarlet
2021-08-17 17:07:14 +08:00
parent 776bc33de1
commit dd194c899a
20 changed files with 2660 additions and 573 deletions

View File

@@ -6,6 +6,11 @@ class Talent {
initial({talents}) {
this.#talents = talents;
for(const id in talents) {
const talent = talents[id];
talent.id= Number(id);
talent.grade = Number(talent.grade);
}
}
check(talentId) {
@@ -20,16 +25,53 @@ class Talent {
}
information(talentId) {
const { rate, name, description } = this.get(talentId)
return { rate, name, description };
const { grade, name, description } = this.get(talentId)
return { grade, name, description };
}
talentRandom() {
// 1000, 100, 10, 1
const talentList = {};
for(const talentId in this.#talents) {
const { id, grade, name, description } = this.#talents[talentId];
if(!talentList[grade]) talentList[grade] = [{ grade, name, description, id }];
else talentList[grade].push({ grade, name, description, id });
}
return new Array(10)
.fill(1).map(()=>{
const gradeRandom = Math.random();
let grade;
if(gradeRandom>=0.111) grade = 0;
else if(gradeRandom>=0.011) grade = 1;
else if(gradeRandom>=0.001) grade = 2;
else grade = 3;
while(talentList[grade].length == 0) grade--;
const length = talentList[grade].length;
const random = Math.floor(Math.random()*length) % length;
return talentList[grade].splice(random,1)[0];
});
}
allocationAddition(talents) {
if(Array.isArray(talents)) {
let addition = 0;
for(const talent of talents)
addition += this.allocationAddition(talent);
return addition;
}
return this.get(talents).status || 0;
}
do(talentId) {
const { effect, condition, initiative, rate, name, description } = this.get(talentId);
const { effect, condition, initiative, grade, name, description } = this.get(talentId);
if(!initiative) return null;
if(condition && !checkCondition(condition))
return null;
return { effect, rate, name, description };
return { effect, grade, name, description };
}
}