mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-02-04 14:53:12 +08:00
change property
This commit is contained in:
49
src/app.js
49
src/app.js
@@ -568,45 +568,22 @@ class App{
|
||||
});
|
||||
});
|
||||
|
||||
const records = this.#life.getRecord();
|
||||
const s = (type, func)=>{
|
||||
const value = func(records.map(({[type]:v})=>v));
|
||||
const summaryData = this.#life.getSummary();
|
||||
const format = (discription, type)=>{
|
||||
const value = summaryData[type];
|
||||
const { judge, grade } = summary(type, value);
|
||||
return { judge, grade, value };
|
||||
return `<li class="grade${grade}"><span>${discription}:</span><span>${value} ${judge}</span></li>`;
|
||||
};
|
||||
|
||||
judge.append([
|
||||
(()=>{
|
||||
const { judge, grade, value } = s('CHR', max);
|
||||
return `<li class="grade${grade}"><span>颜值:</span><span>${value} ${judge}</span></li>`
|
||||
})(),
|
||||
(()=>{
|
||||
const { judge, grade, value } = s('INT', max);
|
||||
return `<li class="grade${grade}"><span>智力:</span><span>${value} ${judge}</span></li>`
|
||||
})(),
|
||||
(()=>{
|
||||
const { judge, grade, value } = s('STR', max);
|
||||
return `<li class="grade${grade}"><span>体质:</span><span>${value} ${judge}</span></li>`
|
||||
})(),
|
||||
(()=>{
|
||||
const { judge, grade, value } = s('MNY', max);
|
||||
return `<li class="grade${grade}"><span>家境:</span><span>${value} ${judge}</span></li>`
|
||||
})(),
|
||||
(()=>{
|
||||
const { judge, grade, value } = s('SPR', max);
|
||||
return `<li class="grade${grade}"><span>快乐:</span><span>${value} ${judge}</span></li>`
|
||||
})(),
|
||||
(()=>{
|
||||
const { judge, grade, value } = s('AGE', max);
|
||||
return `<li class="grade${grade}"><span>享年:</span><span>${value} ${judge}</span></li>`
|
||||
})(),
|
||||
(()=>{
|
||||
const m = type=>max(records.map(({[type]: value})=>value));
|
||||
const value = Math.floor(sum(m('CHR'), m('INT'), m('STR'), m('MNY'), m('SPR'))*2 + m('AGE')/2);
|
||||
const { judge, grade } = summary('SUM', value);
|
||||
return `<li class="grade${grade}"><span>总评:</span><span>${value} ${judge}</span></li>`
|
||||
})(),
|
||||
].join(''));
|
||||
judge.append(`
|
||||
${format('颜值', 'CHR')}
|
||||
${format('智力', 'INT')}
|
||||
${format('体质', 'STR')}
|
||||
${format('家境', 'MNY')}
|
||||
${format('快乐', 'SPR')}
|
||||
${format('享年', 'AGE')}
|
||||
${format('总评', 'SUM')}
|
||||
`);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
23
src/life.js
23
src/life.js
@@ -29,7 +29,7 @@ class Life {
|
||||
this.#triggerTalents = {};
|
||||
this.#property.restart(allocation);
|
||||
this.doTalent();
|
||||
this.#property.record();
|
||||
this.#property.restartLastStep();
|
||||
}
|
||||
|
||||
getTalentAllocationAddition(talents) {
|
||||
@@ -45,7 +45,6 @@ class Life {
|
||||
|
||||
const talentContent = this.doTalent(talent);
|
||||
const eventContent = this.doEvent(this.random(event));
|
||||
this.#property.record();
|
||||
|
||||
const isEnd = this.#property.isEnd();
|
||||
|
||||
@@ -104,15 +103,27 @@ class Life {
|
||||
}
|
||||
|
||||
talentRandom() {
|
||||
return this.#talent.talentRandom(JSON.parse(localStorage.extendTalent||'null'));
|
||||
return this.#talent.talentRandom(this.getLastExtendTalent());
|
||||
}
|
||||
|
||||
talentExtend(talentId) {
|
||||
localStorage.extendTalent = JSON.stringify(talentId);
|
||||
this.#property.set(this.#property.TYPES.EXT, talentId);
|
||||
}
|
||||
|
||||
getRecord() {
|
||||
return this.#property.getRecord();
|
||||
getLastExtendTalent() {
|
||||
return this.#property.get(this.#property.TYPES.EXT);
|
||||
}
|
||||
|
||||
getSummary() {
|
||||
return {
|
||||
AGE: this.#property.get(this.#property.TYPES.HAGE),
|
||||
CHR: this.#property.get(this.#property.TYPES.HCHR),
|
||||
INT: this.#property.get(this.#property.TYPES.HINT),
|
||||
STR: this.#property.get(this.#property.TYPES.HSTR),
|
||||
MNY: this.#property.get(this.#property.TYPES.HMNY),
|
||||
SPR: this.#property.get(this.#property.TYPES.HSPR),
|
||||
SUM: this.#property.get(this.#property.TYPES.SUM),
|
||||
};
|
||||
}
|
||||
|
||||
getLastRecord() {
|
||||
|
||||
183
src/property.js
183
src/property.js
@@ -1,9 +1,10 @@
|
||||
import { clone } from './functions/util.js';
|
||||
import { max, min, sum, clone } from './functions/util.js';
|
||||
|
||||
class Property {
|
||||
constructor() {}
|
||||
|
||||
TYPES = {
|
||||
// 本局
|
||||
AGE: "AGE", // 年龄 age AGE
|
||||
CHR: "CHR", // 颜值 charm CHR
|
||||
INT: "INT", // 智力 intelligence INT
|
||||
@@ -14,11 +15,33 @@ class Property {
|
||||
TLT: "TLT", // 天赋 talent TLT
|
||||
EVT: "EVT", // 事件 event EVT
|
||||
TMS: "TMS", // 次数 times TMS
|
||||
|
||||
// Auto calc
|
||||
LAGE: "LAGE", // 最低年龄 Low Age
|
||||
HAGE: "HAGE", // 最高年龄 High Age
|
||||
LCHR: "LCHR", // 最低颜值 Low Charm
|
||||
HCHR: "HCHR", // 最高颜值 High Charm
|
||||
LINT: "LINT", // 最低智力 Low Intelligence
|
||||
HINT: "HINT", // 最高智力 High Intelligence
|
||||
LSTR: "LSTR", // 最低体质 Low Strength
|
||||
HSTR: "HSTR", // 最高体质 High Strength
|
||||
LMNY: "LMNY", // 最低家境 Low Money
|
||||
HMNY: "HMNY", // 最高家境 High Money
|
||||
LSPR: "LSPR", // 最低快乐 Low Spirit
|
||||
HSPR: "HSPR", // 最高快乐 High Spirit
|
||||
|
||||
SUM: "SUM", // 总评 summary SUM
|
||||
|
||||
EXT: "EXT", // 继承天赋
|
||||
|
||||
// 总计
|
||||
// Achievement Total
|
||||
ATLT: "ATLT", // 拥有过的天赋 Achieve Talent
|
||||
AEVT: "AEVT", // 触发过的事件 Achieve Event
|
||||
};
|
||||
|
||||
#ageData;
|
||||
#data;
|
||||
#record;
|
||||
|
||||
initial({age}) {
|
||||
|
||||
@@ -46,18 +69,49 @@ class Property {
|
||||
restart(data) {
|
||||
this.#data = {
|
||||
[this.TYPES.AGE]: -1,
|
||||
|
||||
[this.TYPES.CHR]: 0,
|
||||
[this.TYPES.INT]: 0,
|
||||
[this.TYPES.STR]: 0,
|
||||
[this.TYPES.MNY]: 0,
|
||||
[this.TYPES.SPR]: 0,
|
||||
|
||||
[this.TYPES.LIF]: 1,
|
||||
|
||||
[this.TYPES.TLT]: [],
|
||||
[this.TYPES.EVT]: [],
|
||||
|
||||
[this.TYPES.LAGE]: Infinity,
|
||||
[this.TYPES.LCHR]: Infinity,
|
||||
[this.TYPES.LINT]: Infinity,
|
||||
[this.TYPES.LSTR]: Infinity,
|
||||
[this.TYPES.LSPR]: Infinity,
|
||||
[this.TYPES.LMNY]: Infinity,
|
||||
|
||||
[this.TYPES.HAGE]: -Infinity,
|
||||
[this.TYPES.HCHR]: -Infinity,
|
||||
[this.TYPES.HINT]: -Infinity,
|
||||
[this.TYPES.HSTR]: -Infinity,
|
||||
[this.TYPES.HMNY]: -Infinity,
|
||||
[this.TYPES.HSPR]: -Infinity,
|
||||
};
|
||||
for(const key in data)
|
||||
this.change(key, data[key]);
|
||||
this.#record = [];
|
||||
}
|
||||
|
||||
restartLastStep() {
|
||||
this.#data[this.TYPES.LAGE] = this.get(this.TYPES.AGE);
|
||||
this.#data[this.TYPES.LCHR] = this.get(this.TYPES.CHR);
|
||||
this.#data[this.TYPES.LINT] = this.get(this.TYPES.INT);
|
||||
this.#data[this.TYPES.LSTR] = this.get(this.TYPES.STR);
|
||||
this.#data[this.TYPES.LSPR] = this.get(this.TYPES.SPR);
|
||||
this.#data[this.TYPES.LMNY] = this.get(this.TYPES.MNY);
|
||||
this.#data[this.TYPES.HAGE] = this.get(this.TYPES.AGE);
|
||||
this.#data[this.TYPES.HCHR] = this.get(this.TYPES.CHR);
|
||||
this.#data[this.TYPES.HINT] = this.get(this.TYPES.INT);
|
||||
this.#data[this.TYPES.HSTR] = this.get(this.TYPES.STR);
|
||||
this.#data[this.TYPES.HMNY] = this.get(this.TYPES.MNY);
|
||||
this.#data[this.TYPES.HSPR] = this.get(this.TYPES.SPR);
|
||||
}
|
||||
|
||||
get(prop) {
|
||||
@@ -72,11 +126,61 @@ class Property {
|
||||
case this.TYPES.TLT:
|
||||
case this.TYPES.EVT:
|
||||
return clone(this.#data[prop]);
|
||||
case this.TYPES.LAGE:
|
||||
case this.TYPES.LCHR:
|
||||
case this.TYPES.LINT:
|
||||
case this.TYPES.LSTR:
|
||||
case this.TYPES.LMNY:
|
||||
case this.TYPES.LSPR:
|
||||
return min(
|
||||
this.#data[prop],
|
||||
this.get(this.fallback(prop))
|
||||
);
|
||||
case this.TYPES.HAGE:
|
||||
case this.TYPES.HCHR:
|
||||
case this.TYPES.HINT:
|
||||
case this.TYPES.HSTR:
|
||||
case this.TYPES.HMNY:
|
||||
case this.TYPES.HSPR:
|
||||
return max(
|
||||
this.#data[prop],
|
||||
this.get(this.fallback(prop))
|
||||
);
|
||||
case this.TYPES.SUM:
|
||||
const HAGE = this.get(this.TYPES.HAGE);
|
||||
const HCHR = this.get(this.TYPES.HCHR);
|
||||
const HINT = this.get(this.TYPES.HINT);
|
||||
const HSTR = this.get(this.TYPES.HSTR);
|
||||
const HMNY = this.get(this.TYPES.HMNY);
|
||||
const HSPR = this.get(this.TYPES.HSPR);
|
||||
return Math.floor(sum(HCHR, HINT, HSTR, HMNY, HSPR)*2 + HAGE/2);
|
||||
case this.TYPES.TMS:
|
||||
return JSON.parse(localStorage.times||'0') || 0;
|
||||
return this.lsget('times') || 0;
|
||||
case this.TYPES.EXT:
|
||||
return this.lsget('extendTalent') || null;
|
||||
case this.TYPES.ATLT:
|
||||
case this.TYPES.AEVT:
|
||||
return this.lsget(prop) || [];
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
fallback(prop) {
|
||||
switch(prop) {
|
||||
case this.TYPES.LAGE:
|
||||
case this.TYPES.HAGE: return this.TYPES.AGE;
|
||||
case this.TYPES.LCHR:
|
||||
case this.TYPES.HCHR: return this.TYPES.CHR;
|
||||
case this.TYPES.LINT:
|
||||
case this.TYPES.HINT: return this.TYPES.INT;
|
||||
case this.TYPES.LSTR:
|
||||
case this.TYPES.HSTR: return this.TYPES.STR;
|
||||
case this.TYPES.LMNY:
|
||||
case this.TYPES.HMNY: return this.TYPES.MNY;
|
||||
case this.TYPES.LSPR:
|
||||
case this.TYPES.HSPR: return this.TYPES.SPR;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
set(prop, value) {
|
||||
switch(prop) {
|
||||
@@ -89,17 +193,21 @@ class Property {
|
||||
case this.TYPES.LIF:
|
||||
case this.TYPES.TLT:
|
||||
case this.TYPES.EVT:
|
||||
this.#data[prop] = clone(value);
|
||||
this.hl(prop, this.#data[prop] = clone(value));
|
||||
this.achieve(prop, value);
|
||||
return;
|
||||
case this.TYPES.TMS:
|
||||
localStorage.times = JSON.stringify(parseInt(value) || 0);
|
||||
this.lsset('times', parseInt(value) || 0);
|
||||
return;
|
||||
case this.TYPES.EXT:
|
||||
this.lsset('extendTalent', value);
|
||||
return
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
record() {
|
||||
this.#record.push({
|
||||
getLastRecord() {
|
||||
return clone({
|
||||
[this.TYPES.AGE]: this.get(this.TYPES.AGE),
|
||||
[this.TYPES.CHR]: this.get(this.TYPES.CHR),
|
||||
[this.TYPES.INT]: this.get(this.TYPES.INT),
|
||||
@@ -109,14 +217,6 @@ class Property {
|
||||
});
|
||||
}
|
||||
|
||||
getRecord() {
|
||||
return clone(this.#record);
|
||||
}
|
||||
|
||||
getLastRecord() {
|
||||
return clone(this.#record[this.#record.length - 1]);
|
||||
}
|
||||
|
||||
change(prop, value) {
|
||||
if(Array.isArray(value)) {
|
||||
for(const v of value)
|
||||
@@ -131,7 +231,7 @@ class Property {
|
||||
case this.TYPES.MNY:
|
||||
case this.TYPES.SPR:
|
||||
case this.TYPES.LIF:
|
||||
this.#data[prop] += Number(value);
|
||||
this.hl(prop, this.#data[prop] += Number(value));
|
||||
return;
|
||||
case this.TYPES.TLT:
|
||||
case this.TYPES.EVT:
|
||||
@@ -141,6 +241,7 @@ class Property {
|
||||
if(index!=-1) v.splice(index,1);
|
||||
}
|
||||
if(!v.includes(value)) v.push(value);
|
||||
this.achieve(prop, value);
|
||||
return;
|
||||
case this.TYPES.TMS:
|
||||
this.set(
|
||||
@@ -172,6 +273,54 @@ class Property {
|
||||
return clone(this.#ageData[age]);
|
||||
}
|
||||
|
||||
hl(prop, value) {
|
||||
let keys;
|
||||
switch(prop) {
|
||||
case this.TYPES.AGE: keys = [this.TYPES.LAGE, this.TYPES.HAGE]; break;
|
||||
case this.TYPES.CHR: keys = [this.TYPES.LCHR, this.TYPES.HCHR]; break;
|
||||
case this.TYPES.INT: keys = [this.TYPES.LINT, this.TYPES.HINT]; break;
|
||||
case this.TYPES.STR: keys = [this.TYPES.LSTR, this.TYPES.HSTR]; break;
|
||||
case this.TYPES.MNY: keys = [this.TYPES.LMNY, this.TYPES.HMNY]; break;
|
||||
case this.TYPES.SPR: keys = [this.TYPES.LSPR, this.TYPES.HSPR]; break;
|
||||
default: return;
|
||||
}
|
||||
const [l, h] = keys;
|
||||
this.#data[l] = min(this.#data[l], value);
|
||||
this.#data[h] = max(this.#data[h], value);
|
||||
}
|
||||
|
||||
achieve(prop, newData = []) {
|
||||
let key;
|
||||
switch(prop) {
|
||||
case this.TYPES.TLT: key = this.TYPES.ATLT; break;
|
||||
case this.TYPES.EVT: key = this.TYPES.AEVT; break;
|
||||
default: return;
|
||||
}
|
||||
const lastData = this.lsget(key) || [];
|
||||
this.lsset(
|
||||
key,
|
||||
Array.from(
|
||||
new Set(
|
||||
lastData
|
||||
.concat(newData)
|
||||
.flat()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
lsget(key) {
|
||||
const data = localStorage.getItem(key);
|
||||
if(data === null) return;
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
lsset(key, value) {
|
||||
localStorage.setItem(
|
||||
key,
|
||||
JSON.stringify(value)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Property;
|
||||
Reference in New Issue
Block a user