古树旋律 发表于 2023-2-17 15:29:23

修改初始化TP的方法

初始化TP的代码如下:

Game_Battler.prototype.initTp = function() {
    this.setTp(Math.randomInt(25));//默认代码中,角色的初始TP是随机0-25的整数
};

找到这个就好办了,看下面一段修改后的进阶代码:
Game_Battler.prototype.initTp = function () {
this.setTp(Math.randomInt(10));//改成了随机数0-10
      let addendTp = 0;//设置一个变量,用于记录每次增加的TP
      let RPGMZ_InitTp = 0;//设置一个变量,用于记录累计需要增加的TP
      let i = 0;
      if (this.isActor()) {
            for (i = 0; i < this.equips().length; i++) {
                addendTp = this.equips() ? parseInt(this.equips().meta.RPGMZ_InitTp, 10) : 0;
// 关于用 条件?ture:false 的代码写法,自行学习
//parseInt(XXXX,10) 是js中的写法,意思是将字符串转义为10进制整数
// 这段代码的意思是 遍历所有装备,提取META属性,即装备的备注栏<RPGMZ_InitTp:数字>
                if (addendTp) {
                  MNKR_InitTp += addendTp;
//将提取到的增加量进行累加
                }
            }
            for (i = 0; i < this.skills().length; i++) {
                addendTp = this.skills() ? parseInt(this.skills().meta.RPGMZ_InitTp, 10) : 0;
//同理,技能也是可以这样设置
                if (addendTp) {
                  MNKR_InitTp += addendTp;
                }
            }
      }
      this.gainTp(RPGMZ_InitTp);
//最终会在setTp(数值)的基础上,再增加gainTp(数值)的数量
    };

这样就可以设置一些技能或者装备,附带有增加初始TP的效果,然后分配给角色。
不同的角色有不同的初始TP技能,达到有不同初始TP的效果。
页: [1]
查看完整版本: 修改初始化TP的方法