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

Project1

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

[有事请教] 悬赏插件

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1390
在线时间
231 小时
注册时间
2017-10-24
帖子
209
跳转到指定楼层
1
发表于 2017-11-26 20:12:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
30星屑
(function() {
        'use strict';
        function removeEscape(string) {
                return +string.replace(/\\S\[(\d+)\]/gi, function() {
                        return arguments[1];
                }).replace(/\\V\[(\d+)\]/gi, function() {
                        return arguments[1];
                });
        }

        function toNumber(string) {
                return +string.replace(/\\V\[(\d+)\]/gi, function() {
                        return $gameVariables.value(parseInt(arguments[1]));
                });
        }

        function canHappen(timeEvent) {
                var condition = timeEvent.condition.replace(/\\S\[(\d+)\]/gi, function() {
                        return $gameSwitches.value(parseInt(arguments[1]));
                }).replace(/\\V\[(\d+)\]/gi, function() {
                        return $gameVariables.value(parseInt(arguments[1]));
                });
                var condition2 = timeEvent.condition2.replace(/\\S\[(\d+)\]/gi, function() {
                        return $gameSwitches.value(parseInt(arguments[1]));
                }).replace(/\\V\[(\d+)\]/gi, function() {
                        return $gameVariables.value(parseInt(arguments[1]));
                });
                return Math.random() < timeEvent.rate && eval(condition) && eval(condition2);
        }

        function isEvery(timeEvent) {
                return timeEvent.command.slice(-5) === 'every';
        }

        Game_System.prototype.addTimeEvent = function(args) {
                this._timeEvents = (this._timeEvents || []).filter(function(timeEvent) {return !!timeEvent;});
                var command = args[0].toLowerCase();
                var timeEvent = {command: command, minutes: parseFloat(args[1]), rate: parseFloat(args[2]) / 100, target: args[3]};
                switch (command) {
                        case 'everystop':
                                this._timeEvents.forEach(function(timeEvent, index, timeEvents) {
                                        if (isEvery(timeEvent)) delete timeEvents[index];
                                });
                                return;
                        case 'add':
                        case 'addevery':
                                timeEvent.increase = args[4];
                                timeEvent.condition = args[5] || 'true';
                                timeEvent.condition2 = args[6] || 'true';
                                break;
                        case 'reset':
                        case 'alloff':
                                args.shift();
                                timeEvent = {command: command, list: args};
                                break;
                        default:
                                timeEvent.condition = args[4] || 'true';
                                timeEvent.condition2 = args[5] || 'true';
                                break;
                }
                if (isEvery(timeEvent)) timeEvent.plusMinutes = timeEvent.minutes;
                timeEvent.time = Date.now();
                this._timeEvents.push(timeEvent);
        };

        Game_System.prototype.executeTimeEvents = function() {
                if (this._timeEvents) this._timeEvents.forEach(function(timeEvent, index, timeEvents) {
                        if (!(timeEvent && timeEvent.time + timeEvent.minutes * 60 * 1000 < Date.now())) return;
                        var target = removeEscape(timeEvent.target);
                        if (canHappen(timeEvent)) switch (isEvery(timeEvent) ? timeEvent.command.slice(0, -5) : timeEvent.command) {
                                case 'on':
                                        $gameSwitches.setValue(target, true);
                                        break;
                                case 'off':
                                        $gameSwitches.setValue(target, false);
                                        break;
                                case 'get':
                                        $gameParty.gainItem($dataItems[target], 1);
                                        break;
                                case 'join':
                                        $gameParty.addActor(target);
                                        break;
                                case 'byebye':
                                        $gameParty.removeActor(target);
                                        break;
                                case 'common':
                                        $gameTemp.enqueueCommonEvent(target);
                                        break;
                                case 'add':
                                        $gameVariables.setValue(target, $gameVariables.value(target) + toNumber(timeEvent.increase));
                                        break;
                                default:
                                        break;
                        }
                        if (isEvery(timeEvent)) timeEvent.minutes += timeEvent.plusMinutes;
                        else delete timeEvents[index];
                });
        };

        var _Game_System_onAfterLoad = Game_System.prototype.onAfterLoad;
        Game_System.prototype.onAfterLoad = function() {
                _Game_System_onAfterLoad.apply(this, arguments);
                if (this._timeEvents) this._timeEvents.forEach(function(timeEvent, index, timeEvents) {
                        if (timeEvent && timeEvent.command === 'reset') {
                                timeEvent.list.forEach(function(variableId) {
                                        $gameVariables.setValue(removeEscape(variableId), 0);
                                });
                                delete timeEvents[index];
                        }
                        if (timeEvent && timeEvent.command === 'alloff') {
                                timeEvent.list.forEach(function(switchId) {
                                        $gameSwitches.setValue(removeEscape(switchId), false);
                                });
                                delete timeEvents[index];
                        }
                });
        };

        var _Game_Temp_initialize = Game_Temp.prototype.initialize;
        Game_Temp.prototype.initialize = function() {
                _Game_Temp_initialize.apply(this, arguments);
                this._commonEventQueue = [];
        };

        Game_Temp.prototype.enqueueCommonEvent = function(commonEventId) {
                this._commonEventQueue.push(commonEventId);
        };

        Game_Temp.prototype.updateCommonEventQueue = function() {
                if (this._commonEventQueue.length !== 0 && !this.isCommonEventReserved()) {
                        this.reserveCommonEvent(this._commonEventQueue.shift());
                }
        };

        var _Scene_Map_update = Scene_Map.prototype.update;
        Scene_Map.prototype.update = function() {
                $gameSystem.executeTimeEvents();
                $gameTemp.updateCommonEventQueue();
                _Scene_Map_update.apply(this, arguments);
        };

        var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
        Game_Interpreter.prototype.pluginCommand = function(command, args) {
                _Game_Interpreter_pluginCommand.apply(this, arguments);
                if (command.toLowerCase() === 'timeevent') {
                        $gameSystem.addTimeEvent(args);
                }
        };
})();

以上是一个经过一定的时间后,可以概率得到东西或修改变量的插件。这个时间判断是获取当地时间,离线后时间也运行,再次上线后生效。我想修改成判断网络时间,并且判断如果进入游戏时,玩家没有联网时,则物品不获得,变量不改变。如果再次进入游戏后联网,则获得相应的物品和变量值。其实如果大神能看懂代码我就不用多说了,简单的说,1:把经过当地时间修改成经过一定的网络时间,2:防止玩家作弊,判断游戏进入后是否联网,如果不联网,则直接去掉把事件中的内容清除,不让玩家获得奖励。

Lv3.寻梦者

梦石
0
星屑
1390
在线时间
231 小时
注册时间
2017-10-24
帖子
209
2
 楼主| 发表于 2017-11-27 10:33:15 | 只看该作者
酬谢可以增加红包,没问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-5-8 12:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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