查看: 654|回复: 0

[原创发布] 【神秘脚本】弹幕科技-001

[复制链接]
梦石
2
星屑
10631
在线时间
821 小时
注册时间
2025-2-2
回帖
242
发表于 2026-4-23 09:14:15 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 糜腥珊瑚态耄耋 于 2026-4-23 09:16 编辑


分享一个弹幕系统黑科技
具体能干嘛,应用场景是啥 一两句话也解释不明白
建议复制代码问AI

[pre lang="ruby"]//=============================================================================
// RPG Maker Plugin - Formula Interpreter
// FormulaInterpreter.js
//=============================================================================

/*:
* @target MZ
* @plugindesc 公式解析器
* @author Limpid
* * @help
* * 【语法说明】
* v[id] / V[id] : 变量 (小写初始化获取,大写实时获取)
* s[id] / S[id] : 开关 (1/0)
* r[n]  / R[n]  : 随机数 (0 到 n)
* g / G         : 金钱
* i[id] / I[id] : 物品数量
* l[id] / L[id] : 角色等级
* p[id.attr] / P[id.attr] : 角色特定属性 (如 P[1.hp])
* ^prop^        : 动态引用宿主对象的属性 (如 ^x^, ^target.hp^)
* @^prop^       : 静态引用宿主对象的属性 (初始化时固定)
* * 内置函数: a(x) [绝对值], s(max, i) [正弦], c(max, i) [余弦]
*/

var Imported = Imported || {};
Imported.FormulaInterpreter = true;

function FormulaInterpreter() {
    throw new Error("This is a static class");
}

/**
* 内部数学方法映射 (内联化处理)
*/
FormulaInterpreter.methods = {
    a: "Math.abs",
    s: "(max, i) => Math.sin((Math.PI / 2) / (Number(max) || 1) * (Number(i) || 0))",
    c: "(max, i) => Math.cos((Math.PI / 2) / (Number(max) || 1) * (Number(i) || 0))"
};

/**
* 语法解析注册表
*/
FormulaInterpreter.registry = {
    static: {
        'v': (id) => $gameVariables.value(Number(id)),
        's': (id) => $gameSwitches.value(Number(id)) ? 1 : 0,
        'r': (n) => Math.random() * Number(n),
        'g': () => $gameParty.gold(),
        'i': (id) => $gameParty.numItems($dataItems[Number(id)]),
        'l': (id) => $gameActors.actor(Number(id))?.level || 0,
        'p': (id_attr) => {
            const [id, attr] = id_attr.split('.');
            return $gameActors.actor(Number(id))?.[attr] || 0;
        }
    },
    dynamic: {
        'V': (id) => `$gameVariables.value(${id})`,
        'S': (id) => `($gameSwitches.value(${id}) ? 1 : 0)`,
        'R': (id) => `(Math.random() * ${id})`,
        'G': () => `$gameParty.gold()`,
        'I': (id) => `$gameParty.numItems($dataItems[${id}])`,
        'L': (id) => `$gameActors.actor(${id})?.level || 0`,
        'P': (id_attr) => {
            const [id, attr] = id_attr.split('.');
            return `$gameActors.actor(${id})?.${attr} || 0`;
        }
    }
};
FormulaInterpreter._compilePool = new Map();
/**
* 创建响应式参数对象
* @param {Object} config - 公式配置库,如 { x: "^t^ * 2" }
* @param {Object} origin - 宿主对象
*/
FormulaInterpreter.create = function (config, origin) {
    if (!origin.params) origin.params = {};
    if (!origin._fCache) origin._fCache = {};
    if (!origin._fFrame) origin._fFrame = {};
    for (let key in config) {
        const formula = config[key];
        const compiled = this.compile(formula, origin);

        if (compiled.type === 'dynamic') {
            const func = compiled.func;
            Object.defineProperty(origin.params, key, {
                get: function () {
                    const now = Graphics.frameCount;
                    if (origin._fFrame[key] === now) return origin._fCache[key];
                    const val = func(origin) ?? 0;
                    origin._fCache[key] = val;
                    origin._fFrame[key] = now;
                    return val;
                },
                enumerable: true,
                configurable: true
            });
        } else {
            origin.params[key] = compiled.value;
        }
    }
};
/**
* 核心编译逻辑
*/
FormulaInterpreter.compile = function (formula, origin) {
    if (typeof formula !== 'string') return { type: 'static', value: Number(formula) || 0 };
    if (this._compilePool.has(formula)) return this._compilePool.get(formula);
    let f = formula;
    f = f.replace(/@\^([\w.]+)\^/g, (_, p) => {
        return p.split('.').reduce((acc, k) => (acc && acc[k] !== undefined ? acc[k] : 0), origin);
    });
    let last;
    const staticRegex = /([a-z])\[([^\[\]]+)\]/g;
    do {
        last = f;
        f = f.replace(staticRegex, (match, type, content) => {
            const handler = this.registry.static[type];
            return (handler && !match.includes('(')) ? handler(content) : match;
        });
        staticRegex.lastIndex = 0;
    } while (last !== f);
   
    const isDynamic = /\^|[A-Z]\[/.test(f);
    const jsSyntax = this._toJsSyntax(f);
    let result;
    if (!isDynamic) {
        try {
            const val = new Function(`return (${jsSyntax})`)();
            result = { type: 'static', value: Number(val) || 0 };
        } catch (e) {
            result = { type: 'static', value: 0 };
        }
    } else {
        result = {
            type: 'dynamic',
            func: new Function('origin', `return (${jsSyntax});`)
        };
    }
    this._compilePool.set(formula, result);
    return result;
};
/**
* 语法转换
*/
FormulaInterpreter._toJsSyntax = function (f) {
    let js = f;
    js = js.replace(/\^([\w.]+)\^/g, (_, p) => {
        const chain = p.split('.').join('?.');
        return `(origin?.${chain} ?? 0)`;
    });
    const dynamicRegex = /([A-Z]+)\[([^\[\]]+)\]/g;
    while (dynamicRegex.test(js)) {
        js = js.replace(dynamicRegex, (match, type, content) => {
            const handler = this.registry.dynamic[type];
            return handler ? handler(content) : match;
        });
        dynamicRegex.lastIndex = 0;
    }
    js = js.replace(/([a-z]\w*)\(([^)]*)\)/gi, (m, name, args) => {
        const method = this.methods[name.toLowerCase()];
        if (!method) return m;
        return name.toLowerCase() === 'a' ? `Math.abs(${args})` : `(${method})(${args})`;
    });
    return js;
};
//=============================================================================
// 示例注入:Scene_Base
//=============================================================================

const _Scene_Base_initialize = Scene_Base.prototype.initialize;
Scene_Base.prototype.initialize = function() {
    _Scene_Base_initialize.call(this);

    // 示例数据结构
    let data = {
        x1: "^t^+R[100]", // 随 startX, t 和 变量1 实时变化
        y1: "R[100]",                         // 每次访问 y1 都会获得一个新的随机数
        size1: "r[100]",                      // 仅在初始化时生成一个随机数,之后固定
        color1: "'#1e90ff'"                   // 静态字符串
    };

    // 假设宿主有一些基础属性
    this.startX = 100;
    this.t = 0;

    FormulaInterpreter.create(data, this);
};

const _Scene_Base_update = Scene_Base.prototype.update;
Scene_Base.prototype.update = function() {
    _Scene_Base_update.call(this);
   
    this.t++;

    if (this.params) {
        console.log("Current Y1:", this.params.x1);
    }
};[/pre]
Cache_-7dab9ff6232f98cf.gif
呵,你能做什么?能做游戏?连自己的想法都不相信,还能相信谁呢?rpgmaker在你的手里不过是个玩具,一个你玩不好的玩具。
劝你还是赶快找个班上吧,这种水平做独立游戏是没意义的。不要制造自己解决不了的麻烦,也不要许下兑现不了的承诺。
别侮辱大伙都智商了,我赌这些时尚小垃圾一样的游戏里没有任何玩法。
你很蠢很笨,又情绪化;也不太冷静,不擅长用大脑思考问题,但却觉得自己很聪明,你早晚会栽在自己的小聪明上。
我在想像你这样的人要怎么能改变呢?嗯?你不会改变
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部