设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 367|回复: 0
打印 上一主题 下一主题

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

[复制链接]

Lv4.逐梦者

梦石
2
星屑
9766
在线时间
757 小时
注册时间
2025-2-2
帖子
268
跳转到指定楼层
1
发表于 2026-4-23 09:14:15 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

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


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

RUBY 代码复制
  1. //=============================================================================
  2. // RPG Maker Plugin - Formula Interpreter
  3. // FormulaInterpreter.js
  4. //=============================================================================
  5.  
  6. /*:
  7. * @target MZ
  8. * @plugindesc 公式解析器
  9. * @author Limpid
  10. * * @help
  11. * * 【语法说明】
  12. * v[id] / V[id] : 变量 (小写初始化获取,大写实时获取)
  13. * s[id] / S[id] : 开关 (1/0)
  14. * r[n]  / R[n]  : 随机数 (0 到 n)
  15. * g / G         : 金钱
  16. * i[id] / I[id] : 物品数量
  17. * l[id] / L[id] : 角色等级
  18. * p[id.attr] / P[id.attr] : 角色特定属性 (P[1.hp])
  19. * ^prop^        : 动态引用宿主对象的属性 (如 ^x^, ^target.hp^)
  20. * @^prop^       : 静态引用宿主对象的属性 (初始化时固定)
  21. * * 内置函数: a(x) [绝对值], s(max, i) [正弦], c(max, i) [余弦]
  22. */
  23.  
  24. var Imported = Imported || {};
  25. Imported.FormulaInterpreter = true;
  26.  
  27. function FormulaInterpreter() {
  28.     throw new Error("This is a static class");
  29. }
  30.  
  31. /**
  32. * 内部数学方法映射 (内联化处理)
  33. */
  34. FormulaInterpreter.methods = {
  35.     a: "Math.abs",
  36.     s: "(max, i) => Math.sin((Math.PI / 2) / (Number(max) || 1) * (Number(i) || 0))",
  37.     c: "(max, i) => Math.cos((Math.PI / 2) / (Number(max) || 1) * (Number(i) || 0))"
  38. };
  39.  
  40. /**
  41. * 语法解析注册表
  42. */
  43. FormulaInterpreter.registry = {
  44.     static: {
  45.         'v': (id) => $gameVariables.value(Number(id)),
  46.         's': (id) => $gameSwitches.value(Number(id)) ? 1 : 0,
  47.         'r': (n) => Math.random() * Number(n),
  48.         'g': () => $gameParty.gold(),
  49.         'i': (id) => $gameParty.numItems($dataItems[Number(id)]),
  50.         'l': (id) => $gameActors.actor(Number(id))?.level || 0,
  51.         'p': (id_attr) => {
  52.             const [id, attr] = id_attr.split('.');
  53.             return $gameActors.actor(Number(id))?.[attr] || 0;
  54.         }
  55.     },
  56.     dynamic: {
  57.         'V': (id) => `$gameVariables.value(${id})`,
  58.         'S': (id) => `($gameSwitches.value(${id}) ? 1 : 0)`,
  59.         'R': (id) => `(Math.random() * ${id})`,
  60.         'G': () => `$gameParty.gold()`,
  61.         'I': (id) => `$gameParty.numItems($dataItems[${id}])`,
  62.         'L': (id) => `$gameActors.actor(${id})?.level || 0`,
  63.         'P': (id_attr) => {
  64.             const [id, attr] = id_attr.split('.');
  65.             return `$gameActors.actor(${id})?.${attr} || 0`;
  66.         }
  67.     }
  68. };
  69. FormulaInterpreter._compilePool = new Map();
  70. /**
  71. * 创建响应式参数对象
  72. * @param {Object} config - 公式配置库,如 { x: "^t^ * 2" }
  73. * @param {Object} origin - 宿主对象
  74. */
  75. FormulaInterpreter.create = function (config, origin) {
  76.     if (!origin.params) origin.params = {};
  77.     if (!origin._fCache) origin._fCache = {};
  78.     if (!origin._fFrame) origin._fFrame = {};
  79.     for (let key in config) {
  80.         const formula = config[key];
  81.         const compiled = this.compile(formula, origin);
  82.  
  83.         if (compiled.type === 'dynamic') {
  84.             const func = compiled.func;
  85.             Object.defineProperty(origin.params, key, {
  86.                 get: function () {
  87.                     const now = Graphics.frameCount;
  88.                     if (origin._fFrame[key] === now) return origin._fCache[key];
  89.                     const val = func(origin) ?? 0;
  90.                     origin._fCache[key] = val;
  91.                     origin._fFrame[key] = now;
  92.                     return val;
  93.                 },
  94.                 enumerable: true,
  95.                 configurable: true
  96.             });
  97.         } else {
  98.             origin.params[key] = compiled.value;
  99.         }
  100.     }
  101. };
  102. /**
  103. * 核心编译逻辑
  104. */
  105. FormulaInterpreter.compile = function (formula, origin) {
  106.     if (typeof formula !== 'string') return { type: 'static', value: Number(formula) || 0 };
  107.     if (this._compilePool.has(formula)) return this._compilePool.get(formula);
  108.     let f = formula;
  109.     f = f.replace(/@\^([\w.]+)\^/g, (_, p) => {
  110.         return p.split('.').reduce((acc, k) => (acc && acc[k] !== undefined ? acc[k] : 0), origin);
  111.     });
  112.     let last;
  113.     const staticRegex = /([a-z])\[([^\[\]]+)\]/g;
  114.     do {
  115.         last = f;
  116.         f = f.replace(staticRegex, (match, type, content) => {
  117.             const handler = this.registry.static[type];
  118.             return (handler && !match.includes('(')) ? handler(content) : match;
  119.         });
  120.         staticRegex.lastIndex = 0;
  121.     } while (last !== f);
  122.  
  123.     const isDynamic = /\^|[A-Z]\[/.test(f);
  124.     const jsSyntax = this._toJsSyntax(f);
  125.     let result;
  126.     if (!isDynamic) {
  127.         try {
  128.             const val = new Function(`return (${jsSyntax})`)();
  129.             result = { type: 'static', value: Number(val) || 0 };
  130.         } catch (e) {
  131.             result = { type: 'static', value: 0 };
  132.         }
  133.     } else {
  134.         result = {
  135.             type: 'dynamic',
  136.             func: new Function('origin', `return (${jsSyntax});`)
  137.         };
  138.     }
  139.     this._compilePool.set(formula, result);
  140.     return result;
  141. };
  142. /**
  143. * 语法转换
  144. */
  145. FormulaInterpreter._toJsSyntax = function (f) {
  146.     let js = f;
  147.     js = js.replace(/\^([\w.]+)\^/g, (_, p) => {
  148.         const chain = p.split('.').join('?.');
  149.         return `(origin?.${chain} ?? 0)`;
  150.     });
  151.     const dynamicRegex = /([A-Z]+)\[([^\[\]]+)\]/g;
  152.     while (dynamicRegex.test(js)) {
  153.         js = js.replace(dynamicRegex, (match, type, content) => {
  154.             const handler = this.registry.dynamic[type];
  155.             return handler ? handler(content) : match;
  156.         });
  157.         dynamicRegex.lastIndex = 0;
  158.     }
  159.     js = js.replace(/([a-z]\w*)\(([^)]*)\)/gi, (m, name, args) => {
  160.         const method = this.methods[name.toLowerCase()];
  161.         if (!method) return m;
  162.         return name.toLowerCase() === 'a' ? `Math.abs(${args})` : `(${method})(${args})`;
  163.     });
  164.     return js;
  165. };
  166. //=============================================================================
  167. // 示例注入:Scene_Base
  168. //=============================================================================
  169.  
  170. const _Scene_Base_initialize = Scene_Base.prototype.initialize;
  171. Scene_Base.prototype.initialize = function() {
  172.     _Scene_Base_initialize.call(this);
  173.  
  174.     // 示例数据结构
  175.     let data = {
  176.         x1: "^t^+R[100]", // 随 startX, t 和 变量1 实时变化
  177.         y1: "R[100]",                         // 每次访问 y1 都会获得一个新的随机数
  178.         size1: "r[100]",                      // 仅在初始化时生成一个随机数,之后固定
  179.         color1: "'#1e90ff'"                   // 静态字符串
  180.     };
  181.  
  182.     // 假设宿主有一些基础属性
  183.     this.startX = 100;
  184.     this.t = 0;
  185.  
  186.     FormulaInterpreter.create(data, this);
  187. };
  188.  
  189. const _Scene_Base_update = Scene_Base.prototype.update;
  190. Scene_Base.prototype.update = function() {
  191.     _Scene_Base_update.call(this);
  192.  
  193.     this.t++;
  194.  
  195.     if (this.params) {
  196.         console.log("Current Y1:", this.params.x1);
  197.     }
  198. };

Cache_-7dab9ff6232f98cf.gif (672.6 KB, 下载次数: 11)

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2026-6-5 01:12

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表