mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-15 11:51:56 +08:00
update data
add replacemant talent add random property
This commit is contained in:
36
src/life.js
36
src/life.js
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user