/*:
* @target MZ
* @plugindesc Always pass bartender QTE success checks without skipping content. Leaves waitress hazards (Tripped! / Groped!) untouched.
* @author Groomtinger (+ helper)
*/
(() => {
'use strict';
const QTE_ACTIVE_SWITCH = 3;
const VAR_MART_POS = 6; // Martini cursor offset
const VAR_MART_STAGE = 27; // Martini tally 0..3
const PERFECT_MART_POS = 0; // centered, inside -130..130
const PERFECT_MART_STAGE = 3; // perfect result branch
const _gvValue = Game_Variables.prototype.value;
Game_Variables.prototype.value = function(id) {
const real = _gvValue.call(this, id);
if (id === VAR_MART_POS) return PERFECT_MART_POS;
if (id === VAR_MART_STAGE) return PERFECT_MART_STAGE;
return real;
};
const PHRASES_PERFECT = [
"Perfect Fill"
];
function deepClone(o){ return JSON.parse(JSON.stringify(o)); }
function isExactSingleLineShowTextAt(list, i, phrases) {
const cmd = list[i];
if (!cmd || cmd.code !== 401) return false;
const txt = cmd.parameters?.[0];
if (typeof txt !== 'string' || !phrases.includes(txt)) return false;
if (!(i > 0 && list[i - 1]?.code === 101)) return false;
if (i + 1 < list.length && list[i + 1]?.code === 401) return false;
return true;
}
function findOwningIfIndex(list, i) {
const needIndent = Math.max(0, (list[i]?.indent ?? 0) - 1);
for (let j = i - 1; j >= 0; j--) {
const c = list[j];
if (!c) continue;
if (c.code === 111 && c.indent === needIndent) return j;
if (c.indent < needIndent) break;
}
return -1;
}
function alreadyPatched(cev) {
const first = cev?.list?.[0];
return first && first.code === 108 && String(first.parameters?.[0]||'').startsWith('AUTO PERFECT (rewrite)');
}
function patchCommonEvent(cev) {
if (!cev || !Array.isArray(cev.list) || alreadyPatched(cev)) return false;
let changed = false;
const L = cev.list;
for (let i = 0; i < L.length; i++) {
if (!isExactSingleLineShowTextAt(L, i, PHRASES_PERFECT)) continue;
const ifIdx = findOwningIfIndex(L, i);
if (ifIdx < 0) continue;
const branch = L[ifIdx];
if (branch && branch.code === 111) {
const b2 = deepClone(branch);
b2.parameters = [12, "true"];
L[ifIdx] = b2;
changed = true;
}
}
if (changed) {
L.unshift({ code:108, indent:0, parameters:['AUTO PERFECT (rewrite): perfect-branch condition set to true'] });
}
return changed;
}
const _DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function() {
if (!_DataManager_isDatabaseLoaded.call(this)) return false;
if (!DataManager._autoPerfectRewriteDone) {
DataManager._autoPerfectRewriteDone = true;
if (Array.isArray($dataCommonEvents)) {
for (let i = 1; i < $dataCommonEvents.length; i++) {
try { patchCommonEvent($dataCommonEvents[i]); } catch(e){ console.error(e); }
}
}
}
return true;
};
})();