update data

add replacemant talent
add random property
This commit is contained in:
Vick Scarlet
2021-09-12 22:04:45 +08:00
parent b833713afe
commit 866acdb8b2
17 changed files with 654 additions and 29 deletions

View File

@@ -328,7 +328,7 @@ class App{
this.hint(`你多使用了${total() - this.#totalMax}属性点`);
return;
}
this.#life.restart({
const contents = this.#life.restart({
CHR: groups.CHR.get(),
INT: groups.INT.get(),
STR: groups.STR.get(),
@@ -337,7 +337,7 @@ class App{
TLT: Array.from(this.#talentSelected).map(({id})=>id),
});
this.switch('trajectory');
this.#pages.trajectory.born();
this.#pages.trajectory.born(contents);
// $(document).keydown(function(event){
// if(event.which == 32 || event.which == 13){
// $('#lifeTrajectory').click();
@@ -646,7 +646,15 @@ class App{
trajectoryPage.find('#auto2x').show();
this.#isEnd = false;
},
born: ()=>{
born: contents => {
if(contents.length > 0)
$('#lifeTrajectory')
.append(`<li><span>初始:</span><span>${
contents.map(
({source, target}) => `天赋${source.name}发动替换为天赋${target.name}`
).join('<br>')
}</span></li>`);
trajectoryPage.find('#lifeTrajectory').trigger("click");
}
},

View File

@@ -28,4 +28,20 @@ function average(...arr) {
return s / arr.flat().length;
}
export { clone, max, min, sum, average };
function weightRandom(list) {
let totalWeights = 0;
for(const [, weight] of list)
totalWeights += weight;
let random = Math.random() * totalWeights;
for(const [id, weight] of list)
if((random-=weight)<0)
return id;
return list[list.length-1];
}
function listRandom(list) {
return list[Math.floor(Math.random() * list.length)];
}
export { clone, max, min, sum, average, weightRandom, listRandom };

View File

@@ -1,3 +1,4 @@
import { weightRandom } from './functions/util.js'
import Property from './property.js';
import Event from './event.js';
import Talent from './talent.js';
@@ -32,13 +33,15 @@ class Life {
restart(allocation) {
this.#triggerTalents = {};
const contents = this.talentReplace(allocation.TLT);
this.#property.restart(allocation);
this.doTalent();
this.doTalent()
this.#property.restartLastStep();
this.#achievement.achieve(
this.#achievement.Opportunity.START,
this.#property
)
return contents;
}
getTalentAllocationAddition(talents) {
@@ -65,6 +68,21 @@ class Life {
return { age, content, isEnd };
}
talentReplace(talents) {
const result = this.#talent.replace(talents);
const contents = [];
for(const id in result) {
talents.push(result[id]);
const source = this.#talent.get(id);
const target = this.#talent.get(result[id]);
contents.push({
type: 'talentReplace',
source, target
});
}
return contents;
}
doTalent(talents) {
if(talents) this.#property.change(this.#property.TYPES.TLT, talents);
talents = this.#property.get(this.#property.TYPES.TLT)
@@ -102,17 +120,11 @@ class Life {
}
random(events) {
events = events.filter(([eventId])=>this.#event.check(eventId, this.#property));
let totalWeights = 0;
for(const [, weight] of events)
totalWeights += weight;
let random = Math.random() * totalWeights;
for(const [eventId, weight] of events)
if((random-=weight)<0)
return eventId;
return events[events.length-1];
return weightRandom(
events.filter(
([eventId])=>this.#event.check(eventId, this.#property)
)
);
}
talentRandom() {

View File

@@ -1,4 +1,4 @@
import { max, min, sum, clone } from './functions/util.js';
import { max, min, sum, clone, listRandom } from './functions/util.js';
class Property {
constructor() {}
@@ -44,8 +44,22 @@ class Property {
CEVT: "REVT", // 事件收集数 Count Event
CACHV: "CACHV", // 成就达成数 Count Achievement
// SPECIAL
RDM: 'RDM', // 随机属性 random RDM
};
// 特殊类型
SPECIAL = {
RDM: [ // 随机属性 random RDM
this.TYPES.CHR,
this.TYPES.INT,
this.TYPES.STR,
this.TYPES.MNY,
this.TYPES.SPR,
]
}
#ageData;
#data = {};
@@ -270,9 +284,19 @@ class Property {
}
}
hookSpecial(prop) {
switch(prop) {
case this.TYPES.RDM: return listRandom(this.SPECIAL.RDM);
default: return prop;
}
}
effect(effects) {
for(const prop in effects)
this.change(prop, Number(effects[prop]));
for(let prop in effects)
this.change(
this.hookSpecial(prop),
Number(effects[prop])
);
}
isEnd() {

View File

@@ -1,4 +1,4 @@
import { clone } from './functions/util.js';
import { clone, weightRandom } from './functions/util.js';
import { checkCondition, extractMaxTriggers } from './functions/condition.js';
import { getRate } from './functions/addition.js';
@@ -14,6 +14,16 @@ class Talent {
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;
}
}
}
}
@@ -111,6 +121,56 @@ class Talent {
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;