赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 15 |
经验 | 0 |
最后登录 | 2024-12-9 |
在线时间 | 243 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 1515
- 在线时间
- 243 小时
- 注册时间
- 2017-10-24
- 帖子
- 209
|
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:防止玩家作弊,判断游戏进入后是否联网,如果不联网,则直接去掉把事件中的内容清除,不让玩家获得奖励。
|
|