mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-18 18:58:06 +08:00
commit870d711162Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Jan 27 16:50:19 2022 +0800 update event commitb327eb1765Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Jan 27 16:36:02 2022 +0800 update event commit4e845bc2ebAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Jan 27 16:35:56 2022 +0800 fix ui feel commitbd508913c5Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Jan 27 16:35:22 2022 +0800 update special thanks commitd097b3bc15Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Jan 27 16:04:55 2022 +0800 add unique character commit8d71b73e94Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Jan 25 21:27:29 2022 +0800 fix: bug save load commit286828abe7Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Jan 25 18:15:22 2022 +0800 add game mode commit0e3c885ad3Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Jan 6 20:09:20 2022 +0800 update special thanks 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
310 lines
9.4 KiB
JavaScript
310 lines
9.4 KiB
JavaScript
import * as util from '../functions/util.js';
|
|
import * as fCondition from '../functions/condition.js';
|
|
|
|
import Property from './property.js';
|
|
import Event from './event.js';
|
|
import Talent from './talent.js';
|
|
import Achievement from './achievement.js';
|
|
import Character from './character.js';
|
|
|
|
class Life {
|
|
constructor() {
|
|
this.#property = new Property(this);
|
|
this.#event = new Event(this);
|
|
this.#talent = new Talent(this);
|
|
this.#achievement = new Achievement(this);
|
|
this.#character = new Character(this);
|
|
}
|
|
|
|
Module = {
|
|
PROPERTY: 'PROPERTY',
|
|
TALENT: 'TALENT',
|
|
EVENT: 'EVENT',
|
|
ACHIEVEMENT: 'ACHIEVEMENT',
|
|
CHARACTER: 'CHARACTER',
|
|
}
|
|
|
|
Function = {
|
|
CONDITION: 'CONDITION',
|
|
UTIL: 'UTIL',
|
|
}
|
|
|
|
#property;
|
|
#event;
|
|
#talent;
|
|
#achievement;
|
|
#character;
|
|
#triggerTalents;
|
|
#defaultPropertyPoints;
|
|
#talentSelectLimit;
|
|
#propertyAllocateLimit;
|
|
#defaultPropertys;
|
|
#specialThanks;
|
|
#initialData;
|
|
|
|
async initial(i18nLoad, commonLoad) {
|
|
const [age, talents, events, achievements, characters, specialThanks] = await Promise.all([
|
|
i18nLoad('age'),
|
|
i18nLoad('talents'),
|
|
i18nLoad('events'),
|
|
i18nLoad('achievement'),
|
|
i18nLoad('character'),
|
|
commonLoad('specialthanks'),
|
|
]);
|
|
this.#specialThanks = specialThanks;
|
|
|
|
const total = {
|
|
[this.PropertyTypes.TACEV]: this.#achievement.initial({achievements}),
|
|
[this.PropertyTypes.TEVT]: this.#event.initial({events}),
|
|
[this.PropertyTypes.TTLT]: this.#talent.initial({talents}),
|
|
};
|
|
this.#property.initial({age, total});
|
|
this.#character.initial({characters});
|
|
}
|
|
|
|
config({
|
|
defaultPropertyPoints = 20, // default number of points for a property
|
|
talentSelectLimit = 3, // max number of talents that can be selected
|
|
propertyAllocateLimit = [0, 10], // scoop of properties that can be allocated
|
|
defaultPropertys = {}, // default propertys
|
|
talentConfig, // config for talent
|
|
propertyConfig, // config for property
|
|
characterConfig, // config for character
|
|
} = {}) {
|
|
this.#defaultPropertyPoints = defaultPropertyPoints;
|
|
this.#talentSelectLimit = talentSelectLimit;
|
|
this.#propertyAllocateLimit = propertyAllocateLimit;
|
|
this.#defaultPropertys = defaultPropertys;
|
|
this.#talent.config(talentConfig);
|
|
this.#property.config(propertyConfig);
|
|
this.#character.config(characterConfig);
|
|
}
|
|
|
|
request(module) {
|
|
switch (module) {
|
|
case this.Module.ACHIEVEMENT: return this.#achievement;
|
|
case this.Module.CHARACTER: return this.#character;
|
|
case this.Module.EVENT: return this.#event;
|
|
case this.Module.PROPERTY: return this.#property;
|
|
case this.Module.TALENT: return this.#talent;
|
|
default: return null;
|
|
}
|
|
}
|
|
|
|
function(type) {
|
|
switch (type) {
|
|
case this.Function.CONDITION: return fCondition;
|
|
case this.Function.UTIL: return util;
|
|
}
|
|
}
|
|
|
|
check(condition) {
|
|
return fCondition.checkCondition(this.#property,condition);
|
|
}
|
|
|
|
clone(...args) {
|
|
return util.clone(...args);
|
|
}
|
|
|
|
remake(talents) {
|
|
this.#initialData = util.clone(this.#defaultPropertys);
|
|
this.#initialData.TLT = util.clone(talents);
|
|
this.#triggerTalents = {};
|
|
return this.talentReplace(this.#initialData.TLT);
|
|
}
|
|
|
|
start(allocation) {
|
|
for(const key in allocation) {
|
|
this.#initialData[key] = util.clone(allocation[key]);
|
|
}
|
|
this.#property.restart(this.#initialData);
|
|
this.doTalent()
|
|
this.#property.restartLastStep();
|
|
this.#achievement.achieve(this.AchievementOpportunity.START);
|
|
}
|
|
|
|
getPropertyPoints() {
|
|
return this.#defaultPropertyPoints + this.#talent.allocationAddition(this.#initialData.TLT);
|
|
}
|
|
|
|
getTalentCurrentTriggerCount(talentId) {
|
|
return this.#triggerTalents[talentId] || 0;
|
|
}
|
|
|
|
next() {
|
|
const {age, event, talent} = this.#property.ageNext();
|
|
|
|
const talentContent = this.doTalent(talent);
|
|
const eventContent = this.doEvent(this.random(event));
|
|
|
|
const isEnd = this.#property.isEnd();
|
|
|
|
const content = [talentContent, eventContent].flat();
|
|
this.#achievement.achieve(this.AchievementOpportunity.TRAJECTORY);
|
|
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.PropertyTypes.TLT, talents);
|
|
talents = this.#property.get(this.PropertyTypes.TLT)
|
|
.filter(talentId => this.getTalentCurrentTriggerCount(talentId) < this.#talent.get(talentId).max_triggers);
|
|
|
|
const contents = [];
|
|
for(const talentId of talents) {
|
|
const result = this.#talent.do(talentId);
|
|
if(!result) continue;
|
|
this.#triggerTalents[talentId] = this.getTalentCurrentTriggerCount(talentId) + 1;
|
|
const { effect, name, description, grade } = result;
|
|
contents.push({
|
|
type: this.PropertyTypes.TLT,
|
|
name,
|
|
grade,
|
|
description,
|
|
})
|
|
if(!effect) continue;
|
|
this.#property.effect(effect);
|
|
}
|
|
return contents;
|
|
}
|
|
|
|
doEvent(eventId) {
|
|
const { effect, next, description, postEvent, grade } = this.#event.do(eventId);
|
|
this.#property.change(this.PropertyTypes.EVT, eventId);
|
|
this.#property.effect(effect);
|
|
const content = {
|
|
type: this.PropertyTypes.EVT,
|
|
description,
|
|
postEvent,
|
|
grade,
|
|
}
|
|
if(next) return [content, this.doEvent(next)].flat();
|
|
return [content];
|
|
}
|
|
|
|
random(events) {
|
|
return util.weightRandom(
|
|
events.filter(
|
|
([eventId])=>this.#event.check(eventId, this.#property)
|
|
)
|
|
);
|
|
}
|
|
|
|
talentRandom() {
|
|
return this.#talent.talentRandom(
|
|
this.lastExtendTalent,
|
|
this.#getPropertys(
|
|
this.PropertyTypes.TMS,
|
|
this.PropertyTypes.CACHV,
|
|
)
|
|
);
|
|
}
|
|
|
|
characterRandom() {
|
|
const characters = this.#character.random();
|
|
const replaceTalent = v=>v.talent=v.talent.map(
|
|
id=>this.#talent.get(id)
|
|
);
|
|
characters.normal.forEach(replaceTalent);
|
|
if(characters.unique && characters.unique.talent)
|
|
replaceTalent(characters.unique);
|
|
return characters;
|
|
}
|
|
|
|
talentExtend(talentId) {
|
|
this.#property.set(this.PropertyTypes.EXT, talentId);
|
|
}
|
|
|
|
exclude(talents, exclusive) {
|
|
return this.#talent.exclude(talents, exclusive);
|
|
}
|
|
|
|
generateUnique() {
|
|
this.#character.generateUnique();
|
|
}
|
|
|
|
#getJudges(...types) {
|
|
return util.getListValuesMap(types.flat(), key => this.#property.judge(key));
|
|
}
|
|
|
|
#getPropertys(...types) {
|
|
return util.getListValuesMap(types.flat(), key => this.#property.get(key));
|
|
}
|
|
|
|
get lastExtendTalent() {
|
|
return this.#property.get(this.PropertyTypes.EXT);
|
|
}
|
|
|
|
get summary() {
|
|
this.#achievement.achieve(this.AchievementOpportunity.SUMMARY);
|
|
|
|
const pt = this.PropertyTypes;
|
|
|
|
return this.#getJudges(pt.SUM,
|
|
pt.HAGE, pt.HCHR, pt.HINT,
|
|
pt.HSTR, pt.HMNY, pt.HSPR,
|
|
);
|
|
}
|
|
|
|
get statistics() {
|
|
const pt = this.PropertyTypes;
|
|
|
|
return this.#getJudges( pt.TMS,
|
|
pt.CACHV, pt.RTLT, pt.REVT,
|
|
);
|
|
}
|
|
get achievements() {
|
|
const ticks = {};
|
|
this.#property
|
|
.get(this.PropertyTypes.ACHV)
|
|
.forEach(([id, tick]) => ticks[id] = tick);
|
|
return this
|
|
.#achievement
|
|
.list(this.#property)
|
|
.sort((
|
|
{id: a, grade: ag, hide: ah},
|
|
{id: b, grade: bg, hide: bh}
|
|
)=>{
|
|
a = ticks[a];
|
|
b = ticks[b];
|
|
if(a&&b) return b - a;
|
|
if(!a&&!b) {
|
|
if(ah&&bh) return bg - ag;
|
|
if(ah) return 1;
|
|
if(bh) return -1;
|
|
return bg - ag;
|
|
}
|
|
if(!a) return 1;
|
|
if(!b) return -1;
|
|
});
|
|
}
|
|
|
|
get PropertyTypes() { return this.#property.TYPES; }
|
|
get AchievementOpportunity() { return this.#achievement.Opportunity; }
|
|
get talentSelectLimit() { return this.#talentSelectLimit; }
|
|
get propertyAllocateLimit() { return util.clone(this.#propertyAllocateLimit); }
|
|
|
|
get propertys() { return this.#property.getPropertys(); }
|
|
get times() { return this.#property.get(this.PropertyTypes.TMS) || 0; }
|
|
set times(v) {
|
|
this.#property.set(this.PropertyTypes.TMS, v);
|
|
this.#achievement.achieve(this.AchievementOpportunity.END);
|
|
}
|
|
get specialThanks() { return this.#specialThanks; }
|
|
}
|
|
|
|
export default Life; |