RPG MAKER MZ 每天签到插件


/*:
* @target MZ
* @plugindesc 每日签到奖励插件(MZ专用版 / 已修复 ReferenceError)
* @author AI Assistant
*
* @param goldAmount
* @text 奖励金币数
* @desc 每次成功签到获得的金币数量。
* @type number
* @min 0
* @default 1000
*
* @param successMessage
* @text 签到成功提示
* @desc 签到成功时弹出的提示文字。
* @type string
* @default 签到成功!获得 1000 金币!
*
* @param alreadyMessage
* @text 已签到提示
* @desc 当天已经签到过时弹出的提示文字。
* @type string
* @default 今天已经签过到啦,明天再来吧!
*
* @command checkIn
* @text 执行签到
* @desc 检查玩家今天是否已签到,未签到则发放奖励。
*/
(() => {
// 获取插件参数
const pluginName = document.currentScript.src.match(/^.*\/(.+)\.js$/)[1];
const parameters = PluginManager.parameters(pluginName);
const goldAmount = Number(parameters['goldAmount'] || 1000);
const successMessage = String(parameters['successMessage'] || '签到成功!获得 1000 金币!');
const alreadyMessage = String(parameters['alreadyMessage'] || '今天已经签过到啦,明天再来吧!');

// 存储键名
const STORAGE_KEY = 'MZ_DailyCheckIn_LastDate';

// 获取当前真实日期的字符串格式 (YYYY-MM-DD)
const getCurrentDateStr = () => {
const d = new Date();
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
};

// 统一提示:优先用 Window_AlertPopup(若你确实装了该类插件),否则降级到系统消息框。
// 关键修复:用 typeof 检测“未声明”的全局变量,typeof 对不存在的标识符不会抛 ReferenceError。
const showTip = (text) => {
if (typeof window.Window_AlertPopup === 'object' && window.Window_AlertPopup
&& typeof window.Window_AlertPopup.show === 'function') {
window.Window_AlertPopup.show(text);
} else {
$gameMessage.add(text);
}
};

// 注册插件命令
PluginManager.registerCommand(pluginName, "checkIn", function () {
const today = getCurrentDateStr();
const lastDate = localStorage.getItem(STORAGE_KEY);

if (lastDate === today) {
// 已经签到过
showTip(alreadyMessage);
} else {
// 签到成功
localStorage.setItem(STORAGE_KEY, today);
$gameParty.gainGold(goldAmount);

// 替换提示文案中的动态金币数(参数被修改后的情况)
const msg = successMessage.replace(/\d+/, goldAmount);
showTip(msg);
}
});
})();


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注