diff --git a/data/age.json b/data/age.json index 29c283e..8bcf0e4 100644 --- a/data/age.json +++ b/data/age.json @@ -25,7 +25,7 @@ }, "6": { "age": "6", - "event": "10007,10012,10014,10022,10023,10036,10037,10038,10043,10044,10045,1004710048,10049,10050,10052,10054,10057,10058,10061,10065,10067,10069,10072,10073,10075,10076,10077,10078,10089,10091,10093,10094,10095,10096,10098,10099,10100,10101*100,10123,10124,10125,10126,10127*4,10128*4,10130,10140,10141,10142,10143,10144,10045,10046,10047,10048,10150,10153,10166,10168,10169,10172,10178,10179,10183,10224" + "event": "10007,10012,10014,10022,10023,10036,10037,10038,10043,10044,10045,10047,10048,10049,10050,10052,10054,10057,10058,10061,10065,10067,10069,10072,10073,10075,10076,10077,10078,10089,10091,10093,10094,10095,10096,10098,10099,10100,10101*100,10123,10124,10125,10126,10127*4,10128*4,10130,10140,10141,10142,10143,10144,10045,10046,10047,10048,10150,10153,10166,10168,10169,10172,10178,10179,10183,10224" }, "7": { "age": "7", @@ -193,7 +193,7 @@ }, "48": { "age": "48", - "event": "10069,10070,10071,10087,10253,10254,10255,10256,10257,10273,10274,10275,10276,10277,10278,10279*0.01,10281,10282*0.001,10286,10287,10288,10289*0.1,10290*0.01,10292,10293,10291*0.01,10295,10296,10297,10298,10299,10300,10301,10302,10303,10304,10305,10306,10308,10317,10318,10319,10320.10322" + "event": "10069,10070,10071,10087,10253,10254,10255,10256,10257,10273,10274,10275,10276,10277,10278,10279*0.01,10281,10282*0.001,10286,10287,10288,10289*0.1,10290*0.01,10292,10293,10291*0.01,10295,10296,10297,10298,10299,10300,10301,10302,10303,10304,10305,10306,10308,10317,10318,10319,10320,10322" }, "49": { "age": "49", @@ -213,7 +213,7 @@ }, "53": { "age": "53", - "event": "10069,10070,10071,10253,10254,10255,10256,10257,10273,10274,10275,10276,10277,10278,10279*0.01,10281,10282*0.001,10286,1028+B577,10288,10290*0.01,10291*0.01,10295,10296,10297,10298,10299,10300,10301,10302,10303,10304,10305,10306,10307,10317,10318,10319,10320,10321" + "event": "10069,10070,10071,10253,10254,10255,10256,10257,10273,10274,10275,10276,10277,10278,10279*0.01,10281,10282*0.001,10286,10287,10288,10290*0.01,10291*0.01,10295,10296,10297,10298,10299,10300,10301,10302,10303,10304,10305,10306,10307,10317,10318,10319,10320,10321" }, "54": { "age": "54", diff --git a/data/events.json b/data/events.json index c0bcbe2..b23e3fd 100644 --- a/data/events.json +++ b/data/events.json @@ -2,6 +2,9 @@ "10000": { "id": 10000, "event": "你死了。", + "effect": { + "LIF": -1 + }, "NoRandom": 1 }, "10001": { @@ -17,7 +20,7 @@ "10003": { "id": 10003, "event": "你生了场重病。", - "PostEvent": "家里花了不少钱。", + "postEvent": "家里花了不少钱。", "effect": { "MNY": -1 }, @@ -36,7 +39,7 @@ "10005": { "id": 10005, "event": "刚学会走路,你意外从桌子上跌落。", - "PostEvent": "受了轻伤。", + "postEvent": "受了轻伤。", "exclude": "INT>7", "branch": [ "TLT?[1002]:10006", @@ -125,7 +128,7 @@ "10016": { "id": 10016, "event": "你的母亲因病去世。", - "PostEvent": "家庭更加困难了。", + "postEvent": "家庭更加困难了。", "effect": { "MNY": -1 }, @@ -139,7 +142,7 @@ "10017": { "id": 10017, "event": "你的父亲因病去世。", - "PostEvent": "家庭更加困难了。", + "postEvent": "家庭更加困难了。", "effect": { "MNY": -2 }, @@ -153,7 +156,7 @@ "10018": { "id": 10018, "event": "你的父亲在种地时意外发现一箱金条。", - "PostEvent": "家境有所好转。", + "postEvent": "家境有所好转。", "effect": { "MNY": 2 }, @@ -191,7 +194,7 @@ "10022": { "id": 10022, "event": "你什么事都要让着妹妹。", - "PostEvent": "不开心。", + "postEvent": "不开心。", "effect": { "SPR": -1 }, @@ -201,7 +204,7 @@ "10023": { "id": 10023, "event": "你什么事都要让着弟弟。", - "PostEvent": "不开心。", + "postEvent": "不开心。", "effect": { "SPR": -1 }, @@ -211,7 +214,7 @@ "10024": { "id": 10024, "event": "父母到城里务工。", - "PostEvent": "你在农村留守。", + "postEvent": "你在农村留守。", "effect": { "SPR": -1 }, @@ -238,7 +241,7 @@ "10027": { "id": 10027, "event": "你的母亲救了个人,得到了很多感谢金。", - "PostEvent": "家境有所好转。", + "postEvent": "家境有所好转。", "effect": { "MNY": 2 }, @@ -265,7 +268,7 @@ "10030": { "id": 10030, "event": "你的脸意外被开水烫伤。", - "PostEvent": "毁容了。", + "postEvent": "毁容了。", "effect": { "CHR": -3 }, @@ -279,7 +282,7 @@ "10031": { "id": 10031, "event": "你被邻居叔叔绑架了。", - "PostEvent": "没勒索到钱,你被放了。", + "postEvent": "没勒索到钱,你被放了。", "effect": { "SPR": -1 }, @@ -293,7 +296,7 @@ "10032": { "id": 10032, "event": "叔叔向你父母勒索了很多现金。", - "PostEvent": "你被放了回家。", + "postEvent": "你被放了回家。", "effect": { "MNY": -2 }, @@ -302,7 +305,7 @@ "10033": { "id": 10033, "event": "叔叔侵犯了你。", - "PostEvent": "你被放了回家。", + "postEvent": "你被放了回家。", "effect": { "SPR": -2 }, @@ -347,7 +350,7 @@ "10038": { "id": 10038, "event": "你玩父母手机时被诈骗。", - "PostEvent": "损失了父母一年的心血。", + "postEvent": "损失了父母一年的心血。", "effect": { "MNY": -1 }, @@ -368,7 +371,7 @@ "10040": { "id": 10040, "event": "你告诉父母后,打电话举报。", - "PostEvent": "损失被追回。", + "postEvent": "损失被追回。", "effect": { "MNY": 1 }, @@ -377,7 +380,7 @@ "10041": { "id": 10041, "event": "你和村里小孩打架。", - "PostEvent": "战斗力提高了。", + "postEvent": "战斗力提高了。", "effect": { "STR": 1 }, @@ -391,7 +394,7 @@ "10042": { "id": 10042, "event": "你失手把一个小孩打死了。", - "PostEvent": "父母赔了很多钱。", + "postEvent": "父母赔了很多钱。", "effect": { "MNY": -2 }, @@ -416,7 +419,7 @@ "10045": { "id": 10045, "event": "你有次去池塘边玩时掉进了水里。", - "PostEvent": "差点淹死。", + "postEvent": "差点淹死。", "include": "EVT?[10044,10047,10180]", "exclude": "EVT?[10045]", "branch": [ @@ -509,7 +512,7 @@ "10058": { "id": 10058, "event": "下暴雨,发洪水。", - "PostEvent": "田都被淹了。", + "postEvent": "田都被淹了。", "effect": { "MNY": -1 }, @@ -559,7 +562,7 @@ "10062": { "id": 10062, "event": "你的情绪越来越低落,尝试自杀。", - "PostEvent": "没有成功。", + "postEvent": "没有成功。", "NoRandom": 1, "branch": [ "SPR<1:10000" @@ -604,7 +607,7 @@ "10067": { "id": 10067, "event": "有一只鸟撞在了你家窗户上。", - "PostEvent": "你把它养好后放了。", + "postEvent": "你把它养好后放了。", "include": "EVT?[10009]", "exclude": "EVT?[10067]", "branch": [ @@ -646,7 +649,7 @@ "10073": { "id": 10073, "event": "你意外挖到一个上了锁的盒子。", - "PostEvent": "你打不开,只好扔了。", + "postEvent": "你打不开,只好扔了。", "include": "EVT?[10009]", "exclude": "EVT?[10073,10025]", "branch": [ @@ -656,7 +659,7 @@ "10074": { "id": 10074, "event": "你想方设法打开了锁。", - "PostEvent": "里面有大量珠宝。", + "postEvent": "里面有大量珠宝。", "effect": { "MNY": 2 }, @@ -696,14 +699,14 @@ "10080": { "id": 10080, "event": "有人将你发在了网上,你小有名气。", - "PostEvent": "很多人来你家拍短视频。", + "postEvent": "很多人来你家拍短视频。", "include": "(CHR>8)&(EVT?[10079])", "exclude": "EVT?[10080]" }, "10081": { "id": 10081, "event": "有星探和公司想带你去大城市发展。", - "PostEvent": "你没有同意。", + "postEvent": "你没有同意。", "include": "EVT?[10080]", "exclude": "EVT?[10081]", "branch": [ @@ -713,7 +716,7 @@ "10082": { "id": 10082, "event": "你来到了一线城市,住进了一家网络公司。", - "PostEvent": "你开始直播生活。", + "postEvent": "你开始直播生活。", "effect": { "MNY": 2 }, @@ -723,7 +726,7 @@ "10083": { "id": 10083, "event": "你过气了,被公司解除了协议。", - "PostEvent": "你回到了乡下。", + "postEvent": "你回到了乡下。", "include": "EVT?[10082]", "exclude": "EVT?[10083]", "branch": [ @@ -733,7 +736,7 @@ "10084": { "id": 10084, "event": "你过惯了奢靡的生活,无法再回乡下了。", - "PostEvent": "你开始出卖身体维持生活质量。", + "postEvent": "你开始出卖身体维持生活质量。", "effect": { "STR": -1 }, @@ -795,7 +798,7 @@ "10090": { "id": 10090, "event": "你的智力过高,被外星人抓走做实验。", - "PostEvent": "又放了回来。", + "postEvent": "又放了回来。", "effect": { "INT": -1 }, @@ -819,7 +822,7 @@ "10092": { "id": 10092, "event": "你被一只蛇咬了。", - "PostEvent": "还好没有毒。", + "postEvent": "还好没有毒。", "include": "EVT?[10009]", "exclude": "EVT?[10092]", "branch": [ @@ -855,21 +858,21 @@ "10096": { "id": 10096, "event": "你听说国外发生了很多大事。", - "PostEvent": "但感觉离你很遥远。", + "postEvent": "但感觉离你很遥远。", "include": "EVT?[10009]", "exclude": "EVT?[10096]" }, "10097": { "id": 10097, "event": "隔壁村的一个孩子淹死了。", - "PostEvent": "你的父母一年都没让你去池塘玩。", + "postEvent": "你的父母一年都没让你去池塘玩。", "include": "EVT?[10009]", "exclude": "EVT?[10097,10015,10016,10017,10024]" }, "10098": { "id": 10098, "event": "你听了轮回转世的神话故事。", - "PostEvent": "感觉好像似曾相识。", + "postEvent": "感觉好像似曾相识。", "include": "INT>4", "exclude": "EVT?[10098]" }, @@ -933,7 +936,7 @@ "10107": { "id": 10107, "event": "你期末考试全都不及格。", - "PostEvent": "老师来家访。", + "postEvent": "老师来家访。", "effect": { "SPR": -1 }, @@ -968,7 +971,7 @@ "10112": { "id": 10112, "event": "同学总是欺负你。", - "PostEvent": "还嘲笑你的长相。", + "postEvent": "还嘲笑你的长相。", "effect": { "SPR": -2 }, @@ -978,7 +981,7 @@ "10113": { "id": 10113, "event": "同学总是欺负你。", - "PostEvent": "还嘲笑你的成绩。", + "postEvent": "还嘲笑你的成绩。", "effect": { "SPR": -2 }, @@ -988,7 +991,7 @@ "10114": { "id": 10114, "event": "同学总是欺负你。", - "PostEvent": "嘲笑你不男不女。", + "postEvent": "嘲笑你不男不女。", "effect": { "SPR": -2 }, @@ -1055,14 +1058,14 @@ "10123": { "id": 10123, "event": "村中阿婆家新盖了小洋房。", - "PostEvent": "听说是孩子在外面赚了大钱。", + "postEvent": "听说是孩子在外面赚了大钱。", "include": "EVT?[10009]", "exclude": "EVT?[10123,10025]" }, "10124": { "id": 10124, "event": "夏日的一天村里鞭炮齐鸣。", - "PostEvent": "听说是人家的孩子考上了重点大学。", + "postEvent": "听说是人家的孩子考上了重点大学。", "include": "EVT?[10009]", "exclude": "EVT?[10124,10025]" }, @@ -1163,14 +1166,14 @@ "10136": { "id": 10136, "event": "老师在班上进行了IQ测试。", - "PostEvent": "你获得了145分", + "postEvent": "你获得了145分", "include": "(INT>7)&(EVT?[10101])", "exclude": "EVT?[10136]" }, "10137": { "id": 10137, "event": "老师在班上进行了IQ测试。", - "PostEvent": "你获得了135分", + "postEvent": "你获得了135分", "include": "(INT>6)&(EVT?[10101])", "exclude": "EVT?[10137]" }, @@ -1258,7 +1261,7 @@ "10149": { "id": 10149, "event": "教室里唯一较好的窗户也破了。", - "PostEvent": "下雨天靠窗完全不能坐人了。", + "postEvent": "下雨天靠窗完全不能坐人了。", "include": "EVT?[10101]", "exclude": "EVT?[10149,10025]" }, @@ -1330,7 +1333,7 @@ "10158": { "id": 10158, "event": "你买彩票中了个小奖。", - "PostEvent": "虽然钱不多但很快乐。", + "postEvent": "虽然钱不多但很快乐。", "effect": { "SPR": 1 }, @@ -1396,7 +1399,7 @@ "10167": { "id": 10167, "event": "用牙齿咬欺凌自己的人,反而被告老师。", - "PostEvent": "很委屈。", + "postEvent": "很委屈。", "effect": { "SPR": -1 }, @@ -1439,21 +1442,21 @@ "10173": { "id": 10173, "event": "学自行车摔得膝盖流血。", - "PostEvent": "没学会。", + "postEvent": "没学会。", "include": "(STR<4)&(EVT?[10009])", "exclude": "TLT?[1038]" }, "10174": { "id": 10174, "event": "尝试自学自行车。", - "PostEvent": "没学会。", + "postEvent": "没学会。", "include": "(INT<5)&(STR<5)&(EVT?[10009])", "exclude": "TLT?[1038]" }, "10175": { "id": 10175, "event": "尝试自学自行车。", - "PostEvent": "学会了。", + "postEvent": "学会了。", "include": "(INT>1)&(STR>1)&(EVT?[10009])", "exclude": "EVT?[10175]" }, @@ -1556,7 +1559,7 @@ "10190": { "id": 10190, "event": "游戏水平很高,远近网吧闻名。", - "PostEvent": "网吧老板允许你免费上网。", + "postEvent": "网吧老板允许你免费上网。", "effect": { "SPR": 1 }, @@ -1566,14 +1569,14 @@ "10191": { "id": 10191, "event": "被公司发掘,进入电竞培训队。", - "PostEvent": "前往大城市。", + "postEvent": "前往大城市。", "include": "EVT?[10190]", "exclude": "EVT?[10191]" }, "10192": { "id": 10192, "event": "开始为战队打比赛。", - "PostEvent": "但并没有打出什么成绩。", + "postEvent": "但并没有打出什么成绩。", "effect": { "STR": -1 }, @@ -1604,7 +1607,7 @@ "10195": { "id": 10195, "event": "巅峰时期退役。", - "PostEvent": "转行游戏主播。", + "postEvent": "转行游戏主播。", "include": "EVT?[10193]", "exclude": "EVT?[10195,10196,10197]" }, @@ -1620,7 +1623,7 @@ "10197": { "id": 10197, "event": "退役。", - "PostEvent": "转行游戏主播。", + "postEvent": "转行游戏主播。", "include": "EVT?[10192]", "exclude": "EVT?[10195,10196,10197]" }, @@ -1657,7 +1660,7 @@ "10203": { "id": 10203, "event": "进入省队。", - "PostEvent": "刻苦训练。", + "postEvent": "刻苦训练。", "include": "EVT?[10202]", "exclude": "EVT?[10203,10204]", "branch": [ @@ -1693,7 +1696,7 @@ "10207": { "id": 10207, "event": "参加奥运会。", - "PostEvent": "夺得奖牌。", + "postEvent": "夺得奖牌。", "effect": { "MNY": 1 }, @@ -1725,7 +1728,7 @@ "10210": { "id": 10210, "event": "退役。", - "PostEvent": "开始当教练。", + "postEvent": "开始当教练。", "include": "EVT?[10203]", "exclude": "EVT?[10210]" }, @@ -1806,7 +1809,7 @@ "10220": { "id": 10220, "event": "你吸毒被捕。", - "PostEvent": "进了戒毒所。", + "postEvent": "进了戒毒所。", "effect": { "STR": -1 }, @@ -1861,7 +1864,7 @@ "10224": { "id": 10224, "event": "去城里看亲戚。", - "PostEvent": "你很羡慕他们家什么都有。", + "postEvent": "你很羡慕他们家什么都有。", "include": "(MNY<5)&(EVT?[10009])", "exclude": "EVT?[10224]" }, @@ -2003,7 +2006,7 @@ "10243": { "id": 10243, "event": "你漏了一节思修课没上,打开了开关。", - "PostEvent": "之后经常翘课了。", + "postEvent": "之后经常翘课了。", "include": "EVT?[10237,10238,10239]", "exclude": "EVT?[10243]" }, @@ -2034,7 +2037,7 @@ "10247": { "id": 10247, "event": "遭到了附近的恶霸殴打,报警不管,举报无门。", - "PostEvent": "只能忍气吞声。", + "postEvent": "只能忍气吞声。", "effect": { "SPR": -2 }, @@ -2047,7 +2050,7 @@ "10248": { "id": 10248, "event": "你怀恨在心,买了水果刀将恶霸捅死了。", - "PostEvent": "你被刑事拘留。", + "postEvent": "你被刑事拘留。", "effect": { "SPR": 1 }, @@ -2091,7 +2094,7 @@ "10253": { "id": 10253, "event": "你的父亲因病去世。", - "PostEvent": "母亲也随之去世。", + "postEvent": "母亲也随之去世。", "include": "EVT?[10009]", "exclude": "EVT?[10253,10016,10017,10125,10126,10254,10255,10256,10257]" }, @@ -2163,7 +2166,7 @@ "10264": { "id": 10264, "event": "你退伍了。", - "PostEvent": "在县城当上了保安。", + "postEvent": "在县城当上了保安。", "effect": { "MNY": 1 }, @@ -2190,7 +2193,7 @@ "10267": { "id": 10267, "event": "你在一次演习中发生了意外。", - "PostEvent": "运气好,没有受伤。", + "postEvent": "运气好,没有受伤。", "include": "EVT?[10259]", "exclude": "EVT?[10267]", "branch": [ @@ -2224,7 +2227,7 @@ "10271": { "id": 10271, "event": "生不出孩子,医院检查发现你功能有问题。", - "PostEvent": "你们离婚了。", + "postEvent": "你们离婚了。", "include": "(EVT?[10235,10236,10234,10233,10231,10230,10229,10088,10236])&(TLT?[1046])", "exclude": "EVT?[10271,10279]" }, @@ -2240,7 +2243,7 @@ "10273": { "id": 10273, "event": "普通的家庭生活。", - "PostEvent": "你感觉时间过得越来越快。", + "postEvent": "你感觉时间过得越来越快。", "include": "EVT?[10235,10236,10234,10233,10231,10230,10229,10088,10236]", "exclude": "EVT?[10279]" }, @@ -2270,7 +2273,7 @@ "10277": { "id": 10277, "event": "小时候一件小事你都能记很久。", - "PostEvent": "现在你却连上个月的事都记不清了。", + "postEvent": "现在你却连上个月的事都记不清了。", "effect": { "STR": -1 }, @@ -2427,7 +2430,7 @@ "10295": { "id": 10295, "event": "你后悔年轻时没有做更多的事。", - "PostEvent": "大人的生活真的很无趣。", + "postEvent": "大人的生活真的很无趣。", "include": "EVT?[10235,10236,10234,10233,10231,10230,10229,10088,10236]", "exclude": "EVT?[10295]" }, @@ -2627,7 +2630,7 @@ "10322": { "id": 10322, "event": "你发现孩子不是亲生的。", - "PostEvent": "你装作不知道。", + "postEvent": "你装作不知道。", "effect": { "SPR": -2 }, @@ -2640,7 +2643,7 @@ "10323": { "id": 10323, "event": "你从盒子中获得了练气法门,突破到凝气一层。", - "PostEvent": "寿元提升到200年。", + "postEvent": "寿元提升到200年。", "effect": { "CHR": 3 }, @@ -2653,7 +2656,7 @@ "10324": { "id": 10324, "event": "练气。", - "PostEvent": "体质提升。", + "postEvent": "体质提升。", "effect": { "STR": 1 }, @@ -2734,7 +2737,7 @@ "10333": { "id": 10333, "event": "你突破到筑基一层。", - "PostEvent": "寿元提升到300年。", + "postEvent": "寿元提升到300年。", "effect": { "INT": 1 }, @@ -2762,7 +2765,7 @@ "10336": { "id": 10336, "event": "锻体。", - "PostEvent": "体质提升。", + "postEvent": "体质提升。", "effect": { "STR": 2 }, @@ -2843,7 +2846,7 @@ "10345": { "id": 10345, "event": "你突破到金丹一层。", - "PostEvent": "寿元提升到400年。", + "postEvent": "寿元提升到400年。", "effect": { "STR": 20 }, @@ -2881,7 +2884,7 @@ "10349": { "id": 10349, "event": "图你美色,一个境界极高的人强行和你双修。", - "PostEvent": "体质大幅提升。", + "postEvent": "体质大幅提升。", "effect": { "STR": 100 }, @@ -2891,7 +2894,7 @@ "10350": { "id": 10350, "event": "你发现一种加快修行速度的方法。", - "PostEvent": "体质大幅提升。", + "postEvent": "体质大幅提升。", "effect": { "STR": 50 }, diff --git a/data/events.xlsx b/data/events.xlsx index aa8192d..49ecbe0 100644 Binary files a/data/events.xlsx and b/data/events.xlsx differ diff --git a/src/event.js b/src/event.js index b52de99..8dbb9ab 100644 --- a/src/event.js +++ b/src/event.js @@ -2,9 +2,9 @@ import { clone } from './functions/util.js'; import { checkCondition } from './functions/condition.js'; class Event { - constructor(initialData={}) { - this.initial(initialData); - } + constructor() {} + + #events; initial({events}) { this.#events = events; @@ -19,10 +19,10 @@ class Event { } } - check(eventId) { + check(eventId, property) { const { include, exclude } = this.get(eventId); - if(exclude && checkCondition(exclude)) return false; - if(include) return checkCondition(include); + if(exclude && checkCondition(property, exclude)) return false; + if(include) return checkCondition(property, include); return true; } @@ -32,17 +32,18 @@ class Event { return clone(event); } - description(eventId) { - return this.get(eventId).description; + information(eventId) { + const { event: description } = this.get(eventId) + return { description }; } - do(eventId) { - const { effect, branch } = this.get(eventId); + do(eventId, property) { + const { effect, branch, event: description, postEvent } = this.get(eventId); if(branch) for(const [cond, next] of branch) - if(checkCondition(cond)) - return { effect, next }; - return { effect }; + if(checkCondition(property, cond)) + return { effect, next, description }; + return { effect, postEvent, description }; } } diff --git a/src/functions/condition.js b/src/functions/condition.js index 226f6ba..59a2342 100644 --- a/src/functions/condition.js +++ b/src/functions/condition.js @@ -53,7 +53,7 @@ function checkParsedConditions(property, conditions) { if(conditions.length == 0) return true; if(conditions.length == 1) return checkParsedConditions(property, conditions[0]); - let ret = checkParsedConditions(conditions[0]); + let ret = checkParsedConditions(property, conditions[0]); for(let i=1; i!this.#triggerTalents.has(talentId)); + + const contents = []; + for(const talentId of talents) { + const result = this.#talent.do(talentId); + if(!result) continue; + this.#triggerTalents.add(talentId); + const { effect, name, desctiption } = result; + contents.push({ + type: this.#property.TYPES.TLT, + name, + rate, + desctiption, + }) + if(!result.effect) continue; + this.#property.effect(effect); + } + return contents; + } + + doEvent(eventId) { + const { effect, next, description, postEvent } = this.#event.do(eventId, this.#property); + this.#property.change(this.#property.TYPES.EVT, eventId); + this.#property.effect(effect); + const content = { + type: this.#property.TYPES.EVT, + description, + postEvent, + } + if(next) return [content, this.doEvent(next)].flat(); + return [content]; } random(events) { - events.filter(([eventId])=>this.#event.check(eventId)); + events = events.filter(([eventId])=>this.#event.check(eventId, this.#property)); let totalWeights = 0; for(const [, weight] of events) @@ -41,6 +89,7 @@ class Life { for(const [eventId, weight] of events) if((random-=weight)<0) return eventId; + return events[events.length-1]; } } diff --git a/src/property.js b/src/property.js index 540ac95..3deff2f 100644 --- a/src/property.js +++ b/src/property.js @@ -1,9 +1,7 @@ import { clone } from './functions/util.js'; class Property { - constructor(initialData={}) { - this.initial(initialData); - } + constructor() {} TYPES = { AGE: "AGE", @@ -17,15 +15,19 @@ class Property { EVT: "EVT", }; + #ageData; + #data; + initial({age}) { this.#ageData = age; - for(const age in a) - a[age].event = a[age].event?.map(v=>{ + for(const a in age) { + age[a].event = age[a].event?.split(',').map(v=>{ const value = v.split('*').map(n=>Number(n)); if(value.length==1) value.push(1); return value; }); + } } restart(data) { @@ -41,7 +43,7 @@ class Property { [this.TYPES.EVT]: [], }; for(const key in data) - this.change(key, value); + this.change(key, data[key]); } get(prop) { @@ -80,7 +82,7 @@ class Property { change(prop, value) { if(Array.isArray(value)) { for(const v of value) - this.change(prop, v); + this.change(prop, Number(v)); return; } switch(prop) { @@ -118,7 +120,7 @@ class Property { ageNext() { this.change(this.TYPES.AGE, 1); const age = this.get(this.TYPES.AGE); - const {event, talent} = this.getAge(age); + const {event, talent} = this.getAgeData(age); return {age, event, talent}; } diff --git a/src/talent.js b/src/talent.js index 20a2f60..1ffd052 100644 --- a/src/talent.js +++ b/src/talent.js @@ -1,10 +1,11 @@ +import { clone } from './functions/util.js'; class Talent { - constructor(initialData={}) { - this.initial(initialData); - } + constructor() {} - initial({talent}) { - this.#talent = talent; + #talents; + + initial({talents}) { + this.#talents = talents; } check(talentId) { @@ -13,20 +14,22 @@ class Talent { } get(talentId) { - const talent = this.#talent[talentId]; + const talent = this.#talents[talentId]; if(!talent) throw new Error(`[ERROR] No Talent[${talentId}]`); return clone(talent); } - description(talentId) { - return this.get(talentId).description; + information(talentId) { + const { rate, name, description } = this.get(talentId) + return { rate, name, description }; } do(talentId) { - const { effect, condition } = this.get(talentId); + const { effect, condition, initiative, rate, name, description } = this.get(talentId); + if(!initiative) return null; if(condition && !checkCondition(condition)) return null; - return { effect }; + return { effect, rate, name, description }; } } diff --git a/test.js b/test.js index 79f4c2c..10cf60b 100644 --- a/test.js +++ b/test.js @@ -203,3 +203,54 @@ // import Property from './src/property.js'; // import Condition from './src/condition.js'; // import Event from './src/event.js'; + + +import { readFile } from 'fs/promises'; +import Life from './src/life.js' + +global.json = filePath => readFile(filePath); + +async function debug() { + + const life = new Life(); + await life.initial(); + + life.restart({ + CHR: 5, // 颜值 charm CHR + INT: 5, // 智力 intelligence INT + STR: 5, // 体质 strength STR + MNY: 5, // 家境 money MNY + SPR: 5, // 快乐 spirit SPR + TLT: [1004, 1005, 1009], // 天赋 talent TLT + }); + const lifeTrajectory = []; + let trajectory; + do{ + try{ + trajectory = life.next(); + } catch(e) { + console.error(e); + // debugger + throw e; + } + lifeTrajectory.push(lifeTrajectory); + const { age, content } = trajectory; + console.debug(`---------------------------------`); + console.debug(`-- ${age} 岁`); + console.debug(' ', + content.map( + ({type, description, rate, name, postEvent}) => { + switch(type) { + case 'TLT': + return `天赋【${name}】发动:${description}`; + case 'EVT': + return description + (postEvent?`\n ${postEvent}`:''); + } + } + ).join('\n ') + ); + } while(!trajectory.isEnd) + // debugger; +} + +debug(); \ No newline at end of file