人生重开模拟器 的主逻辑:每一年先判断天赋再判断事件

人生重开模拟器 git
https://github.com/VickScarlet/lifeRestart

1.表

他的表很好懂,或者说其实看了表之后都不用强求看代码了hhh策划狂喜

天赋:
额外天赋,替换,互斥
在这里插入图片描述
在这里插入图片描述

事件:

属性是否大于小于或者是否有某天赋

在这里插入图片描述

年龄:

在这里插入图片描述

有没有一种可能
人生重来模拟器
是把每一年可能遇到的事件都枚举出来的

成就:
属性是否大于小于某一值,是否有某一事件

2.痛苦阅读代码的过程

windows11 系统下,根据 readme,使用 npm 开头的系列指令启动游戏

在这里插入图片描述

进入人生模拟之后使用 f10,然后很快发现在 life.js 中,他每过一年就是调用一次 next()

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 };
    }

this 是这个类的实例自己,往上看,这是一个 life 类

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;

	//后略

#property 是这个类的属性,ageNext() 在 property.js

ageNext() {
   
        this.change(this.TYPES.AGE, 1);
        const age = this.get(this.TYPES.AGE);
        const {
   event, talent} = this.getAgeData(age);
        return {
   age, event, talent};
    }

这个函数中,thisProperty 类的实例

class Property {
   
    constructor(system) {
   
        this.#system = system;
    }

    TYPES = {
   
        // 本局
        AGE: "AGE", // 年龄 age AGE
        CHR: "CHR", // 颜值 charm CHR
        INT: "INT", // 智力 intelligence INT
        STR: "STR", // 体质 strength STR
        MNY: "MNY", // 家境 money MNY
        SPR: "SPR", // 快乐 spirit SPR
        LIF: "LIF", // 生命 life LIFE
        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
        ACHV: "ACHV", // 达成的成就 Achievement

        CTLT: "CTLT", // 天赋选择数 Count Talent
        CEVT: "CEVT", // 事件收集数 Count Event
        CACHV: "CACHV", // 成就达成数 Count Achievement

        // 总数
        TTLT: "TTLT", // 总天赋数 Total Talent
        TEVT: "TEVT", // 总事件数 Total Event
        TACHV: "TACHV", // 总成就数 Total Achievement

        // 比率
        REVT: "REVT", // 事件收集率 Rate Event
        RTLT: "RTLT", // 天赋选择率 Rate Talent
        RACHV: "RACHV", // 成就达成率 Rate Achievement

        // SPECIAL
        RDM: 'RDM', // 随机属性 random RDM

    };

    // 特殊类型
    SPECIAL = {
   
        RDM: [ // 随机属性 random RDM
            this.TYPES.CHR,
            this.TYPES.INT,
            this.TYPES.STR,
            this.TYPES.MNY,
            this.TYPES.SPR,
        ]
    }

    #system;
    #ageData;
    #data = {
   };
    #total;
    #judge;

	//后略

change() 是类的方法

    change(prop, value) {
   
        if(Array.isArray(value)) {
   
            for(const v of value)
                this.change(prop, Number(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.hl(prop, this.#data[prop] += Number(value));
                return;
            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);
                this.achieve(prop, value);
                return;
            case this.TYPES.TMS:
                this.set(
                    prop,
                    this.get(prop) + parseInt(value)
                );
                return;
            default: return;
        }
    }

如果输入了一个 value 是向量,就 foreach 这个向量,然后对每一个向量元素都对 prop

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值