mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-16 12:52:41 +08:00
增加微信小程序版
This commit is contained in:
129
liferestartWX/utils/liferestart/functions/condition.js
Normal file
129
liferestartWX/utils/liferestart/functions/condition.js
Normal file
@@ -0,0 +1,129 @@
|
||||
function parseCondition(condition) {
|
||||
|
||||
const conditions = [];
|
||||
const length = condition.length;
|
||||
const stack = [];
|
||||
stack.unshift(conditions);
|
||||
let cursor = 0;
|
||||
const catchString = i => {
|
||||
const str = condition.substring(cursor, i).trim();
|
||||
cursor = i;
|
||||
if(str) stack[0].push(str);
|
||||
};
|
||||
|
||||
for(let i=0; i<length; i++) {
|
||||
switch(condition[i]) {
|
||||
case ' ': continue;
|
||||
|
||||
case '(':
|
||||
catchString(i);
|
||||
cursor ++;
|
||||
const sub = [];
|
||||
stack[0].push(sub);
|
||||
stack.unshift(sub);
|
||||
break;
|
||||
|
||||
case ')':
|
||||
catchString(i);
|
||||
cursor ++;
|
||||
stack.shift();
|
||||
break;
|
||||
|
||||
case '|':
|
||||
case '&':
|
||||
catchString(i);
|
||||
catchString(i+1);
|
||||
break;
|
||||
default: continue;
|
||||
}
|
||||
}
|
||||
|
||||
catchString(length);
|
||||
|
||||
return conditions;
|
||||
}
|
||||
|
||||
function checkCondition(property, condition) {
|
||||
const conditions = parseCondition(condition);
|
||||
return checkParsedConditions(property, conditions);
|
||||
}
|
||||
|
||||
function checkParsedConditions(property, conditions) {
|
||||
if(!Array.isArray(conditions)) return checkProp(property, conditions);
|
||||
if(conditions.length == 0) return true;
|
||||
if(conditions.length == 1) return checkParsedConditions(property, conditions[0]);
|
||||
|
||||
let ret = checkParsedConditions(property, conditions[0]);
|
||||
for(let i=1; i<conditions.length; i+=2) {
|
||||
switch(conditions[i]) {
|
||||
case '&':
|
||||
if(ret) ret = checkParsedConditions(property, conditions[i+1]);
|
||||
break;
|
||||
case '|':
|
||||
if(ret) return true;
|
||||
ret = checkParsedConditions(property, conditions[i+1]);
|
||||
break;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function checkProp(property, condition) {
|
||||
|
||||
const length = condition.length;
|
||||
let i = condition.search(/[><\!\?=]/);
|
||||
|
||||
const prop = condition.substring(0,i);
|
||||
const symbol = condition.substring(i, i+=(condition[i+1]=='='?2:1));
|
||||
const d = condition.substring(i, length);
|
||||
|
||||
const propData = property.get(prop);
|
||||
const conditionData = d[0]=='['? JSON.parse(d): Number(d);
|
||||
|
||||
switch(symbol) {
|
||||
case '>': return propData > conditionData;
|
||||
case '<': return propData < conditionData;
|
||||
case '>=': return propData >= conditionData;
|
||||
case '<=': return propData <= conditionData;
|
||||
case '=':
|
||||
if(Array.isArray(propData))
|
||||
return propData.includes(conditionData);
|
||||
return propData == conditionData;
|
||||
case '!=':
|
||||
if(Array.isArray(propData))
|
||||
return !propData.includes(conditionData);
|
||||
return propData == conditionData;
|
||||
case '?':
|
||||
if(Array.isArray(propData)) {
|
||||
for(const p of propData)
|
||||
if(conditionData.includes(p)) return true;
|
||||
return false;
|
||||
}
|
||||
return conditionData.includes(propData);
|
||||
case '!':
|
||||
if(Array.isArray(propData)) {
|
||||
for(const p of propData)
|
||||
if(conditionData.includes(p)) return false;
|
||||
return true;
|
||||
}
|
||||
return !conditionData.includes(propData);
|
||||
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
89
liferestartWX/utils/liferestart/functions/summary.js
Normal file
89
liferestartWX/utils/liferestart/functions/summary.js
Normal file
@@ -0,0 +1,89 @@
|
||||
const data = {
|
||||
"CHR": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
],
|
||||
"MNY": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
],
|
||||
"SPR": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不幸", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "幸福", "grade": 1},
|
||||
{"min":9, "judge": "极乐", "grade": 2},
|
||||
{"min":11, "judge": "天命", "grade": 3},
|
||||
],
|
||||
"INT": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
{"min":21, "judge": "识海", "grade": 3},
|
||||
{"min":131, "judge": "元神", "grade": 3},
|
||||
{"min":501, "judge": "仙魂", "grade": 3},
|
||||
],
|
||||
"STR": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
{"min":21, "judge": "凝气", "grade": 3},
|
||||
{"min":101, "judge": "筑基", "grade": 3},
|
||||
{"min":401, "judge": "金丹", "grade": 3},
|
||||
{"min":1001, "judge": "元婴", "grade": 3},
|
||||
{"min":2001, "judge": "仙体", "grade": 3},
|
||||
],
|
||||
"AGE": [
|
||||
{"judge": "胎死腹中", "grade": 0},
|
||||
{"min":1, "judge": "早夭", "grade": 0},
|
||||
{"min":10, "judge": "少年", "grade": 0},
|
||||
{"min":18, "judge": "盛年", "grade": 0},
|
||||
{"min":40, "judge": "中年", "grade": 0},
|
||||
{"min":60, "judge": "花甲", "grade": 1},
|
||||
{"min":70, "judge": "古稀", "grade": 1},
|
||||
{"min":80, "judge": "杖朝", "grade": 2},
|
||||
{"min":90, "judge": "南山", "grade": 2},
|
||||
{"min":95, "judge": "不老", "grade": 3},
|
||||
{"min":100, "judge": "修仙", "grade": 3},
|
||||
{"min":500, "judge": "仙寿", "grade": 3},
|
||||
],
|
||||
"SUM": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":41, "judge": "折磨", "grade": 0},
|
||||
{"min":50, "judge": "不佳", "grade": 0},
|
||||
{"min":60, "judge": "普通", "grade": 0},
|
||||
{"min":80, "judge": "优秀", "grade": 1},
|
||||
{"min":100, "judge": "罕见", "grade": 2},
|
||||
{"min":110, "judge": "逆天", "grade": 3},
|
||||
{"min":120, "judge": "传说", "grade": 3},
|
||||
]
|
||||
}
|
||||
|
||||
function summary(type, value) {
|
||||
let length = data[type].length;
|
||||
while(length--) {
|
||||
const {min, judge, grade} = data[type][length];
|
||||
if(min==void 0 || value >= min) return {judge, grade};
|
||||
}
|
||||
}
|
||||
|
||||
export { summary };
|
||||
31
liferestartWX/utils/liferestart/functions/util.js
Normal file
31
liferestartWX/utils/liferestart/functions/util.js
Normal file
@@ -0,0 +1,31 @@
|
||||
function clone(value) {
|
||||
switch(typeof value) {
|
||||
case 'object':
|
||||
if(Array.isArray(value)) return value.map(v=>clone(v));
|
||||
const newObj = {};
|
||||
for(const key in value) newObj[key] = clone(value[key]);
|
||||
return newObj;
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
|
||||
function max(...arr) {
|
||||
return Math.max(...arr.flat());
|
||||
}
|
||||
|
||||
function min(...arr) {
|
||||
return Math.min(...arr.flat());
|
||||
}
|
||||
|
||||
function sum(...arr) {
|
||||
let s = 0;
|
||||
arr.flat().forEach(v=>s+=v);
|
||||
return s;
|
||||
}
|
||||
|
||||
function average(...arr) {
|
||||
const s = sum(...arr);
|
||||
return s / arr.flat().length;
|
||||
}
|
||||
|
||||
export { clone, max, min, sum, average };
|
||||
Reference in New Issue
Block a user