mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-03-24 21:37:40 +08:00
change triggered talents to a map + make age related talents multi-triggerable
This commit is contained in:
@@ -113,4 +113,17 @@ function checkProp(property, condition) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { checkCondition };
|
function extractMaxTriggers(condition) {
|
||||||
|
// Assuming only age related talents can be triggered multiple times.
|
||||||
|
const RE_AGE_CONDITION = /AGE\?\[([0-9\,]+)\]/;
|
||||||
|
const match_object = RE_AGE_CONDITION.exec(condition);
|
||||||
|
if (match_object == null) {
|
||||||
|
// Not age related, single trigger.
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const age_list = match_object[1].split(",");
|
||||||
|
return age_list.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { checkCondition, extractMaxTriggers };
|
||||||
10
src/life.js
10
src/life.js
@@ -26,7 +26,7 @@ class Life {
|
|||||||
}
|
}
|
||||||
|
|
||||||
restart(allocation) {
|
restart(allocation) {
|
||||||
this.#triggerTalents = new Set();
|
this.#triggerTalents = {};
|
||||||
this.#property.restart(allocation);
|
this.#property.restart(allocation);
|
||||||
this.doTalent();
|
this.doTalent();
|
||||||
this.#property.record();
|
this.#property.record();
|
||||||
@@ -36,6 +36,10 @@ class Life {
|
|||||||
return this.#talent.allocationAddition(talents);
|
return this.#talent.allocationAddition(talents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTalentCurrentTriggerCount(talentId) {
|
||||||
|
return this.#triggerTalents[talentId] || 0;
|
||||||
|
}
|
||||||
|
|
||||||
next() {
|
next() {
|
||||||
const {age, event, talent} = this.#property.ageNext();
|
const {age, event, talent} = this.#property.ageNext();
|
||||||
|
|
||||||
@@ -52,13 +56,13 @@ class Life {
|
|||||||
doTalent(talents) {
|
doTalent(talents) {
|
||||||
if(talents) this.#property.change(this.#property.TYPES.TLT, talents);
|
if(talents) this.#property.change(this.#property.TYPES.TLT, talents);
|
||||||
talents = this.#property.get(this.#property.TYPES.TLT)
|
talents = this.#property.get(this.#property.TYPES.TLT)
|
||||||
.filter(talentId=>!this.#triggerTalents.has(talentId));
|
.filter(talentId => this.getTalentCurrentTriggerCount(talentId) < this.#talent.get(talentId).max_triggers);
|
||||||
|
|
||||||
const contents = [];
|
const contents = [];
|
||||||
for(const talentId of talents) {
|
for(const talentId of talents) {
|
||||||
const result = this.#talent.do(talentId, this.#property);
|
const result = this.#talent.do(talentId, this.#property);
|
||||||
if(!result) continue;
|
if(!result) continue;
|
||||||
this.#triggerTalents.add(talentId);
|
this.#triggerTalents[talentId] = this.getTalentCurrentTriggerCount(talentId) + 1;
|
||||||
const { effect, name, description, grade } = result;
|
const { effect, name, description, grade } = result;
|
||||||
contents.push({
|
contents.push({
|
||||||
type: this.#property.TYPES.TLT,
|
type: this.#property.TYPES.TLT,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { clone } from './functions/util.js';
|
import { clone } from './functions/util.js';
|
||||||
import { checkCondition } from './functions/condition.js';
|
import { checkCondition, extractMaxTriggers } from './functions/condition.js';
|
||||||
|
|
||||||
class Talent {
|
class Talent {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
@@ -12,6 +12,7 @@ class Talent {
|
|||||||
const talent = talents[id];
|
const talent = talents[id];
|
||||||
talent.id= Number(id);
|
talent.id= Number(id);
|
||||||
talent.grade = Number(talent.grade);
|
talent.grade = Number(talent.grade);
|
||||||
|
talent.max_triggers = extractMaxTriggers(talent.condition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user