/*:
@target MZ
@plugindesc v1.1.0 - 状态叠层系统
@author TheoAllen
@url [url]https://github.com/theoallen/RMMZ/tree/master/Plugins[/url]
@help
♦ 关于:
允许同一个状态多次叠加,并可在达到特定层数时触发额外效果
♦ 使用方法:
1. 基础叠层功能:
在状态的备注栏中添加标签 <stack: n>
n = 最大叠加层数
2. 层数触发效果:
在状态的备注栏中添加标签 <stack_effect: x, stateId>
x = 每叠多少层触发一次
stateId = 要触发的状态ID
示例:<stack_effect: 5, 10>
表示每叠5层时,自动添加10号状态
在5层、10层、15层等倍数层数时都会触发
♦ 使用条款:
- [url]https://github.com/theoallen/RMMZ/blob/master/README.md[/url]
*/
// v1.1.0 - 新增层数触发效果功能
var Theo = Theo || {}
Theo.StackingStates = function(){
const $ = Theo.StackingStates
$._version = '1.1.0'
// 移除重复项
if(!Array.prototype.uniq){
Array.prototype.uniq = function() {
const copy = this.concat();
const len = copy.length
for(var i=0; i<len; ++i) {
for(var j=i+1; j<len; ++j) {
if(copy[i] === copy[j])
copy.splice(j--, 1);
}
}
return copy;
};
}
// 解析层数触发效果
$.parseStackEffect = function(stateId) {
const state = $dataStates[stateId];
if (!state || !state.meta) return [];
const effects = [];
for (const key in state.meta) {
if (key.toLowerCase() === 'stack_effect') {
const value = state.meta[key].trim();
const match = value.match(/(\d+)\s*,\s*(\d+)/);
if (match) {
const step = parseInt(match[1]);
const effectStateId = parseInt(match[2]);
if (!isNaN(step) && !isNaN(effectStateId)) {
effects.push({ step, stateId: effectStateId });
}
}
}
}
return effects;
};
// 覆盖原方法
Game_Battler.prototype.addState = function(stateId) {
if (this.isStateAddable(stateId)) {
const wasAffected = this.isStateAffected(stateId);
if (!wasAffected || !this.isMaxStack(stateId)) {
this.addNewState(stateId);
const currentStack = this.stateStack(stateId);
// 检查并触发层数效果
const effects = $.parseStackEffect(stateId);
for (const effect of effects) {
if (currentStack % effect.step === 0) {
this.addState(effect.stateId);
}
}
this.refresh();
}
this.resetStateCounts(stateId);
this._result.pushAddedState(stateId);
}
};
Game_Battler.prototype.isMaxStack = function(stateId){
const data = $dataStates[stateId]
const max = data.meta.stack ? Number(data.meta.stack) : 1
return max === this.stateStack(stateId)
}
Game_Battler.prototype.stateStack = function(stateId){
return this._states.filter(id => id === stateId).length
}
// 覆盖原方法
Game_Battler.prototype.updateStateTurns = function() {
const updated = []
for (const stateId of this._states) {
if (this._stateTurns[stateId] > 0 && !updated.includes(stateId)) {
this._stateTurns[stateId]--;
updated.push(stateId)
}
}
};
}
Theo.StackingStates()