mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-18 18:58:06 +08:00
Squashed commit of the following:
commitb421082374Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Dec 31 20:26:20 2021 +0800 update specialthanks commit765a69294bAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 19:10:03 2021 +0800 fix ios goto commit8eb8c3ca72Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 19:03:37 2021 +0800 add event grade commitab705dd46cAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:48:42 2021 +0800 build version commita1e4232369Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:47:05 2021 +0800 change talent replace before property allocate commitf4d7b3ae3cAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:06:18 2021 +0800 add event grade commit0567e40ddcAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 21:28:10 2021 +0800 add particle commitf17003925eAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 20:14:26 2021 +0800 change ui commitf8beda1d8fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 19:08:30 2021 +0800 change popup message ui commit915a2aa17dAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 18:34:29 2021 +0800 new build commitb5edabc104Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 18:18:46 2021 +0800 add hint message commita143feadafAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 17:57:31 2021 +0800 fix copy bug commiteab1975791Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 17:56:28 2021 +0800 add save/load commitacf9b92134Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 14:35:33 2021 +0800 add theme switch commit488a6054abAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Dec 1 18:30:36 2021 +0800 fix uiManager bug commitf0317eaf14Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Dec 1 16:07:03 2021 +0800 add message popup commiteb02d1ee6fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 21:22:54 2021 +0800 change relocation commit60503eae47Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:27:16 2021 +0800 change ScaleButton -> Laya.runtime.ScaleButton commit52ef5909c1Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:26:31 2021 +0800 change ScaleButton -> Laya.runtime.ScaleButton commit0284f6aa71Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:05:24 2021 +0800 config webpack commit0e272ffd99Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 13:17:41 2021 +0800 add thanks commite1e2ab4701Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 11:40:21 2021 +0800 add light theme commit4f55c00f86Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 27 22:27:39 2021 +0800 fix bug commit1d07bdfc46Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 27 21:48:47 2021 +0800 daily update commit52d6a0ca8fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Nov 24 23:10:04 2021 +0800 daily update commitf8dd720d4dAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Nov 24 19:08:13 2021 +0800 daily update commitd088c1a862Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 21 21:41:46 2021 +0800 remove useless commita711fcf3edAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Nov 16 00:53:05 2021 +0800 add achievement popup add page adaptive add talent extends commit05e02de3dbAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 13 01:24:04 2021 +0800 add github and discord commitbff0109cc5Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 13 00:30:01 2021 +0800 add trajectory auto mode commit54c04f65c2Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Nov 12 19:54:31 2021 +0800 fix property judge negative number bug commit660739530bAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Nov 12 19:48:58 2021 +0800 update achievement commitc94e9e7433Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Nov 11 21:37:45 2021 +0800 update daily commitc06cd9ea62Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Nov 9 00:08:05 2021 +0800 update daily commit2666983f89Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 7 23:00:22 2021 +0800 add uiManager auto scan and load skin resource commit22fa5d755aAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 7 22:17:04 2021 +0800 update framework commitf40698d63eAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Oct 31 00:13:22 2021 +0800 add laya
This commit is contained in:
201
src/modules/talent.js
Normal file
201
src/modules/talent.js
Normal file
@@ -0,0 +1,201 @@
|
||||
import { clone, weightRandom } from '../functions/util.js';
|
||||
import { checkCondition, extractMaxTriggers } from '../functions/condition.js';
|
||||
|
||||
class Talent {
|
||||
constructor() {}
|
||||
|
||||
#talents;
|
||||
#talentPullCount;
|
||||
#talentRate;
|
||||
#additions;
|
||||
|
||||
initial({talents}) {
|
||||
this.#talents = talents;
|
||||
for(const id in talents) {
|
||||
const talent = talents[id];
|
||||
talent.id= Number(id);
|
||||
talent.grade = Number(talent.grade);
|
||||
talent.max_triggers = extractMaxTriggers(talent.condition);
|
||||
if(talent.replacement) {
|
||||
for(let key in talent.replacement) {
|
||||
const obj = {};
|
||||
for(let value of talent.replacement[key]) {
|
||||
value = `${value}`.split('*');
|
||||
obj[value[0]||0] = Number(value[1]) || 1;
|
||||
}
|
||||
talent.replacement[key] = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.count;
|
||||
}
|
||||
|
||||
get count() {
|
||||
return Object.keys(this.#talents).length;
|
||||
}
|
||||
|
||||
config({
|
||||
talentPullCount = 10, // number of talents to pull from the talent pool
|
||||
talentRate = { 1:100, 2:10, 3:1, total: 1000 }, // rate of talent pull
|
||||
additions = {}, // additional additions
|
||||
} = {}) {
|
||||
this.#talentPullCount = talentPullCount;
|
||||
this.#talentRate = talentRate;
|
||||
this.#additions = additions;
|
||||
}
|
||||
|
||||
|
||||
check(talentId, property) {
|
||||
const { condition } = this.get(talentId);
|
||||
return checkCondition(property, condition);
|
||||
}
|
||||
|
||||
get(talentId) {
|
||||
const talent = this.#talents[talentId];
|
||||
if(!talent) throw new Error(`[ERROR] No Talent[${talentId}]`);
|
||||
return clone(talent);
|
||||
}
|
||||
|
||||
information(talentId) {
|
||||
const { grade, name, description } = this.get(talentId)
|
||||
return { grade, name, description };
|
||||
}
|
||||
|
||||
exclusive(talends, exclusiveId) {
|
||||
const { exclusive } = this.get(exclusiveId);
|
||||
if(!exclusive) return null;
|
||||
for(const talent of talends) {
|
||||
for(const e of exclusive) {
|
||||
if(talent == e) return talent;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getAddition(type, value) {
|
||||
if(!this.#additions[type]) return {};
|
||||
for(const [min, addition] of this.#additions[type]) {
|
||||
if(value >= min) return addition;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
getRate(additionValues = {}) {
|
||||
const rate = clone(this.#talentRate);
|
||||
const addition = { 1:1, 2:1, 3:1, };
|
||||
|
||||
Object.keys(additionValues).forEach(key => {
|
||||
const addi = this.getAddition(key, additionValues[key])
|
||||
for(const grade in addi)
|
||||
addition[grade] += addi[grade];
|
||||
});
|
||||
|
||||
for(const grade in addition)
|
||||
rate[grade] *= addition[grade];
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
talentRandom(include, additionValues) {
|
||||
const rate = this.getRate(additionValues);
|
||||
|
||||
const randomGrade = () => {
|
||||
let randomNumber = Math.floor(Math.random() * rate.total);
|
||||
if((randomNumber -= rate[3]) < 0) return 3;
|
||||
if((randomNumber -= rate[2]) < 0) return 2;
|
||||
if((randomNumber -= rate[1]) < 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const talentList = {};
|
||||
for(const talentId in this.#talents) {
|
||||
const { id, grade, name, description } = this.#talents[talentId];
|
||||
if(id == include) {
|
||||
include = { grade, name, description, id };
|
||||
continue;
|
||||
}
|
||||
if(!talentList[grade]) talentList[grade] = [{ grade, name, description, id }];
|
||||
else talentList[grade].push({ grade, name, description, id });
|
||||
}
|
||||
|
||||
return new Array(this.#talentPullCount)
|
||||
.fill(1).map((v, i)=>{
|
||||
if(!i && include) return include;
|
||||
let grade = randomGrade();
|
||||
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 Number(this.get(talents).status) || 0;
|
||||
}
|
||||
|
||||
do(talentId, property) {
|
||||
const { effect, condition, grade, name, description } = this.get(talentId);
|
||||
if(condition && !checkCondition(property, condition))
|
||||
return null;
|
||||
return { effect, grade, name, description };
|
||||
}
|
||||
|
||||
replace(talents) {
|
||||
const getReplaceList = (talent, talents) => {
|
||||
const { replacement } = this.get(talent);
|
||||
if(!replacement) return null;
|
||||
const list = [];
|
||||
if(replacement.grade) {
|
||||
this.forEach(({id, grade})=>{
|
||||
if(!replacement.grade[grade]) return;
|
||||
if(this.exclusive(talents, id)) return;
|
||||
list.push([id, replacement.grade[grade]]);
|
||||
})
|
||||
}
|
||||
if(replacement.talent) {
|
||||
for(let id in replacement.talent) {
|
||||
id = Number(id);
|
||||
if(this.exclusive(talents, id)) continue;
|
||||
list.push([id, replacement.talent[id]]);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
const replace = (talent, talents) => {
|
||||
const replaceList = getReplaceList(talent, talents);
|
||||
if(!replaceList) return talent;
|
||||
const rand = weightRandom(replaceList);
|
||||
return replace(
|
||||
rand, talents.concat(rand)
|
||||
);
|
||||
}
|
||||
|
||||
const newTalents = clone(talents);
|
||||
const result = {};
|
||||
for(const talent of talents) {
|
||||
const replaceId = replace(talent, newTalents);
|
||||
if(replaceId != talent) {
|
||||
result[talent] = replaceId;
|
||||
newTalents.push(replaceId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
forEach(callback) {
|
||||
if(typeof callback != 'function') return;
|
||||
for(const id in this.#talents)
|
||||
callback(clone(this.#talents[id]), id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Talent;
|
||||
Reference in New Issue
Block a user