add talent life

This commit is contained in:
Vick Scarlet
2021-08-16 23:28:54 +08:00
parent dcc9cd2383
commit df85e62138
18 changed files with 5703 additions and 335 deletions

5
.gitignore vendored
View File

@@ -103,6 +103,5 @@ dist
# TernJS port file # TernJS port file
.tern-port .tern-port
excel/ view/
data/ utils/xlsxTransform-*
view/

1809
data/age.json Normal file

File diff suppressed because it is too large Load Diff

BIN
data/age.xlsx Normal file

Binary file not shown.

2960
data/events.json Normal file

File diff suppressed because it is too large Load Diff

BIN
data/events.xlsx Normal file

Binary file not shown.

537
data/talents.json Normal file
View File

@@ -0,0 +1,537 @@
{
"1001": {
"id": "1001",
"name": "随身玉佩",
"description": "2岁时不会死",
"rare": "0"
},
"1002": {
"id": "1002",
"name": "红肚兜",
"description": "3岁时不会死",
"rare": "0"
},
"1003": {
"id": "1003",
"name": "生而为男",
"description": "性别一定为男",
"rare": "1"
},
"1004": {
"id": "1004",
"name": "生而为女",
"description": "性别一定为女",
"rare": "1"
},
"1005": {
"id": "1005",
"name": "动漫高手",
"description": "入宅的可能性翻6倍",
"rare": "2"
},
"1006": {
"id": "1006",
"name": "乐天派",
"description": "快乐+1",
"rare": "0",
"effect": {
"SPR": "1"
}
},
"1007": {
"id": "1007",
"name": "天赋异禀",
"description": "初始可用属性点+2",
"rare": "1",
"status": "2"
},
"1008": {
"id": "1008",
"name": "天生抑郁",
"description": "快乐-3",
"rare": "0",
"effect": {
"SPR": "-3"
}
},
"1009": {
"id": "1009",
"name": "网络巨魔",
"description": "快乐+2",
"rare": "1",
"effect": {
"SPR": "2"
}
},
"1010": {
"id": "1010",
"name": "天龙人",
"description": "你拥有北京户口",
"rare": "2"
},
"1011": {
"id": "1011",
"name": "独生子女",
"description": "你没有兄弟姐妹",
"rare": "0"
},
"1012": {
"id": "1012",
"name": "乡间微风",
"description": "你出生在农村",
"rare": "0"
},
"1013": {
"id": "1013",
"name": "城中高楼",
"description": "你出生在城市",
"rare": "0"
},
"1014": {
"id": "1014",
"name": "美籍华人",
"description": "你有美国国籍",
"rare": "2",
"effect": {
"MNY": "3"
}
},
"1015": {
"id": "1015",
"name": "家中老大",
"description": "你最受父母宠爱",
"rare": "1"
},
"1016": {
"id": "1016",
"name": "水性良好",
"description": "不会被淹死",
"rare": "0"
},
"1017": {
"id": "1017",
"name": "先天免疫",
"description": "你不会得艾滋病",
"rare": "0"
},
"1018": {
"id": "1018",
"name": "天选之人",
"description": "所有属性+1",
"rare": "2",
"effect": {
"SPR": "1"
},
"MNY": "1",
"CHR": "1",
"STR": "1",
"INT": "1"
},
"1019": {
"id": "1019",
"name": "超凡",
"description": "初始可用属性点+3",
"rare": "2"
},
"1020": {
"id": "1020",
"name": "父母美貌",
"description": "颜值+2",
"rare": "1"
},
"1021": {
"id": "1021",
"name": "红颜薄命",
"description": "颜值+2体质-2",
"rare": "0"
},
"1022": {
"id": "1022",
"name": "属蛇",
"description": "不会被蛇咬死",
"rare": "0"
},
"1023": {
"id": "1023",
"name": "半神",
"description": "所有属性+2",
"rare": "3",
"effect": {
"SPR": "2"
},
"MNY": "2",
"CHR": "2",
"STR": "2",
"INT": "2"
},
"1024": {
"id": "1024",
"name": "人中龙凤",
"description": "天生双重性别",
"rare": "2"
},
"1025": {
"id": "1025",
"name": "阴阳之外",
"description": "天生无性别",
"rare": "2"
},
"1026": {
"id": "1026",
"name": "彩虹之下",
"description": "可能和同性交往",
"rare": "0"
},
"1027": {
"id": "1027",
"name": "斩情证道",
"description": "终生不恋爱结婚",
"rare": "1"
},
"1028": {
"id": "1028",
"name": "桃花连连",
"description": "恋爱机会提升",
"rare": "0"
},
"1029": {
"id": "1029",
"name": "平安童年",
"description": "12岁前父母都健在",
"rare": "1"
},
"1030": {
"id": "1030",
"name": "宠物大师",
"description": "宠物不会意外死亡",
"rare": "0"
},
"1031": {
"id": "1031",
"name": "天生残疾",
"description": "体质-2",
"rare": "0",
"effect": {
"STR": "-2"
}
},
"1032": {
"id": "1032",
"name": "早产儿",
"description": "所有属性-1",
"rare": "0",
"effect": {
"SPR": "-1"
},
"MNY": "-1",
"CHR": "-1",
"STR": "-1",
"INT": "-1"
},
"1033": {
"id": "1033",
"name": "十死无生",
"description": "体质-10",
"rare": "0"
},
"1034": {
"id": "1034",
"name": "家运不顺",
"description": "家境-2",
"rare": "0"
},
"1035": {
"id": "1035",
"name": "头着地",
"description": "智力-2",
"rare": "0"
},
"1036": {
"id": "1036",
"name": "胎教",
"description": "智力+1",
"rare": "0"
},
"1037": {
"id": "1037",
"name": "班中红人",
"description": "和同学容易处好关系",
"rare": "0"
},
"1038": {
"id": "1038",
"name": "骑士",
"description": "能轻松学会骑车",
"rare": "0"
},
"1039": {
"id": "1039",
"name": "永远的神",
"description": "电竞天才",
"rare": "1"
},
"1040": {
"id": "1040",
"name": "黄帝",
"description": "赌毒不沾",
"rare": "0"
},
"1041": {
"id": "1041",
"name": "丁克",
"description": "不生孩子",
"rare": "1"
},
"1042": {
"id": "1042",
"name": "少数民族",
"description": "高考+5分",
"rare": "0"
},
"1043": {
"id": "1043",
"name": "老司机",
"description": "你的家人不会发生车祸",
"rare": "0"
},
"1044": {
"id": "1044",
"name": "低压",
"description": "你的家人不会心脏病",
"rare": "0"
},
"1045": {
"id": "1045",
"name": "战功",
"description": "你退伍后会当官",
"rare": "0"
},
"1046": {
"id": "1046",
"name": "不孕不育",
"description": "你生不出孩子",
"rare": "1"
},
"1047": {
"id": "1047",
"name": "白头偕老",
"description": "爱人至少能活到70岁",
"rare": "1"
},
"1048": {
"id": "1048",
"name": "一个小盒子",
"description": "100岁时才能开启",
"rare": "3"
},
"1049": {
"id": "1049"
},
"1050": {
"id": "1050"
},
"1051": {
"id": "1051"
},
"1052": {
"id": "1052"
},
"1053": {
"id": "1053"
},
"1054": {
"id": "1054"
},
"1055": {
"id": "1055"
},
"1056": {
"id": "1056"
},
"1057": {
"id": "1057"
},
"1058": {
"id": "1058"
},
"1059": {
"id": "1059"
},
"1060": {
"id": "1060"
},
"1061": {
"id": "1061"
},
"1062": {
"id": "1062"
},
"1063": {
"id": "1063"
},
"1064": {
"id": "1064"
},
"1065": {
"id": "1065"
},
"1066": {
"id": "1066"
},
"1067": {
"id": "1067"
},
"1068": {
"id": "1068"
},
"1069": {
"id": "1069"
},
"1070": {
"id": "1070"
},
"1071": {
"id": "1071"
},
"1072": {
"id": "1072"
},
"1073": {
"id": "1073"
},
"1074": {
"id": "1074"
},
"1075": {
"id": "1075"
},
"1076": {
"id": "1076"
},
"1077": {
"id": "1077"
},
"1078": {
"id": "1078"
},
"1079": {
"id": "1079"
},
"1080": {
"id": "1080"
},
"1081": {
"id": "1081"
},
"1082": {
"id": "1082"
},
"1083": {
"id": "1083"
},
"1084": {
"id": "1084"
},
"1085": {
"id": "1085"
},
"1086": {
"id": "1086"
},
"1087": {
"id": "1087"
},
"1088": {
"id": "1088"
},
"1089": {
"id": "1089"
},
"1090": {
"id": "1090"
},
"1091": {
"id": "1091"
},
"1092": {
"id": "1092"
},
"1093": {
"id": "1093"
},
"1094": {
"id": "1094"
},
"1095": {
"id": "1095"
},
"1096": {
"id": "1096"
},
"1097": {
"id": "1097"
},
"1098": {
"id": "1098"
},
"1099": {
"id": "1099"
},
"1100": {
"id": "1100"
},
"1101": {
"id": "1101"
},
"1102": {
"id": "1102"
},
"1103": {
"id": "1103"
},
"1104": {
"id": "1104"
},
"1105": {
"id": "1105"
},
"1106": {
"id": "1106"
},
"1107": {
"id": "1107"
},
"1108": {
"id": "1108"
},
"1109": {
"id": "1109"
},
"1110": {
"id": "1110"
},
"1111": {
"id": "1111"
},
"1112": {
"id": "1112"
},
"1113": {
"id": "1113"
},
"1114": {
"id": "1114"
},
"1115": {
"id": "1115"
},
"1116": {
"id": "1116"
},
"1117": {
"id": "1117"
},
"1118": {
"id": "1118"
}
}

BIN
data/talents.xlsx Normal file

Binary file not shown.

View File

@@ -2,6 +2,9 @@
"name": "xlsx_transform", "name": "xlsx_transform",
"type": "module", "type": "module",
"bin": "convert.js", "bin": "convert.js",
"scripts": {
"xlsxTransform": "node utils/xlsxTransform.js data"
},
"dependencies": { "dependencies": {
"xlsx": "^0.17.0" "xlsx": "^0.17.0"
} }

View File

@@ -1,133 +0,0 @@
class Condition {
constructor(initialData={}) {
this.initial(initialData);
}
initial({prop}) {
if(prop) this.prop = prop;
}
parse(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;
}
check(condition) {
const conditions = this.parse(condition);
return this.checkParsedConditions(conditions);
}
checkParsedConditions(conditions) {
if(!Array.isArray(conditions)) return this.checkProp(conditions);
if(conditions.length == 0) return true;
if(conditions.length == 1) return this.checkParsedConditions(conditions[0]);
let ret = this.checkParsedConditions(conditions[0]);
for(let i=1; i<conditions.length; i+=2) {
switch(conditions[i]) {
case '&':
if(ret) ret = this.checkParsedConditions(conditions[i+1]);
break;
case '|':
if(ret) return true;
ret = this.checkParsedConditions(conditions[i+1]);
break;
default: return false;
}
}
return ret;
}
checkProp(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 = this.getProp(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;
}
}
getProp(prop) {
return this.prop.get(prop);
}
get prop() {return this._prop;}
set prop(p) {this._prop = p;}
}
export default Condition;

View File

@@ -1,86 +1,15 @@
import {clone} from './util.js'; import { clone } from './functions/util.js';
import { checkCondition } from './functions/condition.js';
class Event { class Event {
constructor(initialData={}) { constructor(initialData={}) {
this.initial(initialData); this.initial(initialData);
} }
initial({prop, condition, events, pools}) { initial({events}) {
if(prop) this.prop = prop; this.#events = events;
if(condition) this.condition = condition; for(const id in events) {
if(events) this.events = events; const event = events[id];
if(pools) this.pools = pools;
}
random() {
const age = this.getProp(this.prop.TYPES.AGE);
const pool = this.filterPool(
this.getPool(age)
);
let totalWeights = 0;
for(const [,weight] of pool)
totalWeights += weight;
let random = Math.random() * totalWeights;
for(const [event,weight] of pool)
if((random-=weight)<0)
return event;
}
check(eventId) {
const { Include, Exclude } = this.get(eventId);
if(Exclude && this.checkCondition(Exclude)) return false;
if(Include) return this.checkCondition(Include);
return true;
}
checkCondition(condition) {
return this.condition.check(condition);
}
filterPool(pool) {
return pool.filter(([event])=>this.check(event));
}
get(eventId) {
const event = this.events[eventId];
if(!event) console.error(`[ERROR] No Event[${eventId}]`);
return clone(event);
}
getPool(age) {
return clone(this.pools[age].Pool) || [];
}
getProp(prop) {
return this.prop.get(prop);
}
get prop() {return this._prop;}
set prop(p) {this._prop = p;}
get condition() {return this._condition;}
set condition(c) {this._condition = c;}
get pools() {return this._pools;}
set pools(p) {
this._pools = p;
for(const age in p)
p[age].Pool = p[age].Pool?.map(v=>{
const value = v.split('*').map(n=>Number(n));
if(value.length==1) value.push(1);
return value;
});
}
get events() {return this._events;}
set events(e) {
this._events = e;
for(const id in e) {
const event = e[id];
if(!event.branch) continue; if(!event.branch) continue;
event.branch = event.branch.map(b=>{ event.branch = event.branch.map(b=>{
b = b.split(':'); b = b.split(':');
@@ -90,6 +19,32 @@ class Event {
} }
} }
check(eventId) {
const { include, exclude } = this.get(eventId);
if(exclude && checkCondition(exclude)) return false;
if(include) return checkCondition(include);
return true;
}
get(eventId) {
const event = this.#events[eventId];
if(!event) throw new Error(`[ERROR] No Event[${eventId}]`);
return clone(event);
}
description(eventId) {
return this.get(eventId).description;
}
do(eventId) {
const { effect, branch } = this.get(eventId);
if(branch)
for(const [cond, next] of branch)
if(checkCondition(cond))
return { effect, next };
return { effect };
}
} }
export default Event; export default Event;

116
src/functions/condition.js Normal file
View File

@@ -0,0 +1,116 @@
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(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;
}
}
export { checkCondition };

47
src/life.js Normal file
View File

@@ -0,0 +1,47 @@
import { readFile } from 'fs/promises';
import Property from './property.js';
import Event from './event.js';
import Talent from './talent.js';
class Life {
constructor() {
this.#property = new Property();
this.#event = new Event();
this.#talent = new Talent();
}
async initial() {
const age = JSON.parse(await readFile('data/age.json'));
const talents = JSON.parse(await readFile('data/talents.json'));
const events = JSON.parse(await readFile('data/events.json'));
this.#property.initial({age});
this.#talent.initial({talents});
this.#event.initial({events});
}
restart(allocation) {
this.#prop.restart(allocation);
}
next() {
const {age, event, talent} = this.#prop.ageNext();
const eventId = this.random(event);
}
random(events) {
events.filter(([eventId])=>this.#event.check(eventId));
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;
}
}
export default Life;

View File

@@ -1,88 +0,0 @@
import {clone} from './util.js';
class Prop {
constructor(initialData={}) {
this.initial(initialData);
}
initial(data) {
this._data = {
AGE: 0
};
for(const key in data)
this.set(key, data[key]);
}
get(prop) {
switch(prop) {
case this.TYPES.AGE:
case this.TYPES.CHR:
case this.TYPES.INT:
case this.TYPES.STR:
case this.TYPES.MNY:
case this.TYPES.SPR:
case this.TYPES.LIF:
case this.TYPES.TLT:
case this.TYPES.EVT:
return this._data[prop];
default: return 0;
}
}
set(prop, value) {
switch(prop) {
case this.TYPES.AGE:
case this.TYPES.CHR:
case this.TYPES.INT:
case this.TYPES.STR:
case this.TYPES.MNY:
case this.TYPES.SPR:
case this.TYPES.LIF:
case this.TYPES.TLT:
case this.TYPES.EVT:
this._data[prop] = clone(value);
break;
default: return 0;
}
}
change(prop, value) {
switch(prop) {
case this.TYPES.AGE:
case this.TYPES.CHR:
case this.TYPES.INT:
case this.TYPES.STR:
case this.TYPES.MNY:
case this.TYPES.SPR:
case this.TYPES.LIF:
this._data[prop] += value;
break;
case this.TYPES.TLT:
case this.TYPES.EVT:
const v = this._data[prop];
if(value<0) {
const index = v.indexOf(value);
if(index!=-1) v.splice(index,1);
}
if(!v.includes(value)) v.push(value);
break;
default: return;
}
}
get TYPES() {
return {
AGE: "AGE",
CHR: "CHR",
INT: "INT",
STR: "STR",
MNY: "MNY",
SPR: "SPR",
LIF: "LIF",
TLT: "TLT",
EVT: "EVT",
};
}
}
export default Prop;

131
src/property.js Normal file
View File

@@ -0,0 +1,131 @@
import { clone } from './functions/util.js';
class Property {
constructor(initialData={}) {
this.initial(initialData);
}
TYPES = {
AGE: "AGE",
CHR: "CHR",
INT: "INT",
STR: "STR",
MNY: "MNY",
SPR: "SPR",
LIF: "LIF",
TLT: "TLT",
EVT: "EVT",
};
initial({age}) {
this.#ageData = age;
for(const age in a)
a[age].event = a[age].event?.map(v=>{
const value = v.split('*').map(n=>Number(n));
if(value.length==1) value.push(1);
return value;
});
}
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]: [],
};
for(const key in data)
this.change(key, value);
}
get(prop) {
switch(prop) {
case this.TYPES.AGE:
case this.TYPES.CHR:
case this.TYPES.INT:
case this.TYPES.STR:
case this.TYPES.MNY:
case this.TYPES.SPR:
case this.TYPES.LIF:
case this.TYPES.TLT:
case this.TYPES.EVT:
return clone(this.#data[prop]);
default: return 0;
}
}
set(prop, value) {
switch(prop) {
case this.TYPES.AGE:
case this.TYPES.CHR:
case this.TYPES.INT:
case this.TYPES.STR:
case this.TYPES.MNY:
case this.TYPES.SPR:
case this.TYPES.LIF:
case this.TYPES.TLT:
case this.TYPES.EVT:
this.#data[prop] = clone(value);
break;
default: return 0;
}
}
change(prop, value) {
if(Array.isArray(value)) {
for(const v of value)
this.change(prop, v);
return;
}
switch(prop) {
case this.TYPES.AGE:
case this.TYPES.CHR:
case this.TYPES.INT:
case this.TYPES.STR:
case this.TYPES.MNY:
case this.TYPES.SPR:
case this.TYPES.LIF:
this.#data[prop] += Number(value);
break;
case this.TYPES.TLT:
case this.TYPES.EVT:
const v = this.#data[prop];
if(value<0) {
const index = v.indexOf(value);
if(index!=-1) v.splice(index,1);
}
if(!v.includes(value)) v.push(value);
break;
default: return;
}
}
effect(effects) {
for(const prop in effects)
this.change(prop, Number(effects[prop]));
}
isEnd() {
return !this.get(this.TYPES.LIF);
}
ageNext() {
this.change(this.TYPES.AGE, 1);
const age = this.get(this.TYPES.AGE);
const {event, talent} = this.getAge(age);
return {age, event, talent};
}
getAgeData(age) {
return clone(this.#ageData[age]);
}
}
export default Property;

33
src/talent.js Normal file
View File

@@ -0,0 +1,33 @@
class Talent {
constructor(initialData={}) {
this.initial(initialData);
}
initial({talent}) {
this.#talent = talent;
}
check(talentId) {
const { condition } = this.get(talentId);
return checkCondition(condition);
}
get(talentId) {
const talent = this.#talent[talentId];
if(!talent) throw new Error(`[ERROR] No Talent[${talentId}]`);
return clone(talent);
}
description(talentId) {
return this.get(talentId).description;
}
do(talentId) {
const { effect, condition } = this.get(talentId);
if(condition && !checkCondition(condition))
return null;
return { effect };
}
}
export default Talent;

55
test.js
View File

@@ -151,13 +151,6 @@
// return conditions; // return conditions;
// } // }
import {readFile} from 'fs/promises';
import Prop from './src/prop.js';
import Condition from './src/condition.js';
import Event from './src/event.js';
// function debug(...conditions) { // function debug(...conditions) {
// for(const cond of conditions) // for(const cond of conditions)
// console.debug(condition.check(cond), '\t', cond); // console.debug(condition.check(cond), '\t', cond);
@@ -179,28 +172,34 @@ import Event from './src/event.js';
// const events = await axios('excel/events.json'); // const events = await axios('excel/events.json');
// const pools = await axios('excel/pools.json'); // const pools = await axios('excel/pools.json');
async function debug() { // async function debug() {
const events = JSON.parse(await readFile('excel/events.json')); // const events = JSON.parse(await readFile('data/events.json'));
const pools = JSON.parse(await readFile('excel/pools.json')); // const pools = JSON.parse(await readFile('data/age.json'));
const prop = new Prop(); // const property = new Property();
const condition = new Condition(); // const condition = new Condition();
const event = new Event(); // const event = new Event();
prop.initial({ // property.initial({
CHR: 5, // 颜值 charm CHR // CHR: 5, // 颜值 charm CHR
INT: 5, // 智力 intelligence INT // INT: 5, // 智力 intelligence INT
STR: 5, // 体质 strength STR // STR: 5, // 体质 strength STR
MNY: 5, // 家境 money MNY // MNY: 5, // 家境 money MNY
SPR: 5, // 快乐 spirit SPR // SPR: 5, // 快乐 spirit SPR
LIF: 5, // 生命 life LIF // LIF: 5, // 生命 life LIF
TLT: [5], // 天赋 talent TLT // TLT: [5], // 天赋 talent TLT
EVT: [5], // 事件 event EVT // EVT: [5], // 事件 event EVT
}); // });
condition.initial({prop}); // condition.initial({prop: property});
event.initial({events, pools, prop, condition}); // event.initial({events, pools, prop: property, condition});
console.debug(event.random()); // console.debug(event.random());
} // }
debug(); // debug();
// import {readFile} from 'fs/promises';
// import Property from './src/property.js';
// import Condition from './src/condition.js';
// import Event from './src/event.js';

View File

@@ -1,10 +1,10 @@
// import { readFile, writeFile, stat, readdir } from 'fs/promises'; import { readFile, writeFile, stat, readdir } from 'fs/promises';
// import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
// import { join, extname, dirname } from 'path'; import { join, extname, dirname } from 'path';
const { readFile, writeFile, stat, readdir } = require('fs/promises'); // const { readFile, writeFile, stat, readdir } = require('fs/promises');
const XLSX = require('xlsx'); // const XLSX = require('xlsx');
const { join, extname, dirname } = require('path'); // const { join, extname, dirname } = require('path');
async function transform(filePath) { async function transform(filePath) {
const xlsxFileBuffer = await readFile(filePath); const xlsxFileBuffer = await readFile(filePath);