Fix Critical Hit Miss And MiniMap Erase Event

尝试修复: #27
- 必中攻击闪避的问题
- 消除事件对小地图无效的问题
main
xian18 2 years ago
parent 49f0025fa1
commit 0f564939e0
Signed by: SaltedFish
GPG Key ID: B0C26448E9EF40CA

@ -99,14 +99,14 @@ var $gameMapsExt = null;
SF_Plugins.SF_ExtraEvent = SF_ExtraEvent;
SF_ExtraEvent.version = 1.0;
SF_ExtraEvent.EventExtIdStart = 100000
SF_ExtraEvent.EventExtIdStart = 100000;
//=============================================================================
// Parameter
//=============================================================================
SF_ExtraEvent.Parameters = PluginManager.parameters('SF_ExtraEvent');
SF_ExtraEvent.ExportMapExtraEvent = String(SF_ExtraEvent.Parameters['ExportMapExtraEvent'] || 'false') === 'true';
SF_ExtraEvent.Parameters = PluginManager.parameters("SF_ExtraEvent");
SF_ExtraEvent.ExportMapExtraEvent = String(SF_ExtraEvent.Parameters["ExportMapExtraEvent"] || "false") === "true";
//=============================================================================
// DataManager
@ -116,8 +116,8 @@ var $gameMapsExt = null;
DataManager.loadMapData = function (mapId) {
SF_ExtraEvent.DataManager_loadMapData.call(this, mapId);
if (mapId > 0) {
var filename = 'Map%1Ext.json'.format(mapId.padZero(3));
this.loadDataFile('$dataMapExt', filename);
var filename = "Map%1Ext.json".format(mapId.padZero(3));
this.loadDataFile("$dataMapExt", filename);
} else {
this.makeEmptyMapExt();
}
@ -132,7 +132,7 @@ var $gameMapsExt = null;
DataManager.isMapLoaded = function () {
if (!SF_ExtraEvent.DataManager_isMapLoaded.call(this)) return false;
return !!$dataMapExt;
}
};
SF_ExtraEvent.DataManager_onLoad = DataManager.onLoad;
DataManager.onLoad = function (object) {
@ -187,7 +187,7 @@ var $gameMapsExt = null;
this._need_insert_events_id[mapId] = [];
}
return this._need_insert_events_id[mapId];
}
};
// Insert an event to the need List
Game_MapsExt.prototype.insert_event_to_need = function (mapId, eventId) {
@ -235,7 +235,7 @@ var $gameMapsExt = null;
Game_Map.prototype.initialize = function () {
SF_ExtraEvent.Game_Map_initialize.call(this);
this._events = {};
}
};
SF_ExtraEvent.Game_Map_setupEvents = Game_Map.prototype.setupEvents;
Game_Map.prototype.setupEvents = function () {
@ -257,7 +257,7 @@ var $gameMapsExt = null;
});
this.refreshTileEvents();
}
};
SF_ExtraEvent.Game_Map_events = Game_Map.prototype.events;
Game_Map.prototype.events = function () {
@ -267,7 +267,7 @@ var $gameMapsExt = null;
events.push(event);
}
return events;
}
};
Game_Map.prototype.addEvent = function (eventId) {
this._events[eventId] = new Game_Event(this.mapId(), eventId);
@ -276,7 +276,7 @@ var $gameMapsExt = null;
}
this._events[eventId].refresh();
this.requestRefresh();
}
};
Game_Map.prototype.removeEvent = function (eventId) {
this._events[eventId].erase();
@ -285,7 +285,7 @@ var $gameMapsExt = null;
}
delete this._events[eventId];
this.requestRefresh();
}
};
//=============================================================================
// Game_Event
@ -308,7 +308,7 @@ var $gameMapsExt = null;
var sprite = new Sprite_Character(event);
this._characterSprites.push(sprite);
this._tilemap.addChild(sprite);
}
};
Spriteset_Map.prototype.removeEvent = function (event) {
var sprite = this._characterSprites.filter(function (sprite) {
@ -320,7 +320,7 @@ var $gameMapsExt = null;
});
this._tilemap.removeChild(sprite);
}
};
//=============================================================================
// Game_Interpreter
@ -329,34 +329,34 @@ var $gameMapsExt = null;
SF_ExtraEvent.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
SF_ExtraEvent.Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === 'sf_extra_event') {
if (command.toLowerCase() === "sf_extra_event") {
switch (args[0].toLowerCase()) {
case 'insert_event':
case "insert_event":
var mapId = Number(args[1]);
var eventId = Number(args[2]);
$gameMapsExt.insert_event_to_need(mapId, eventId);
break;
case 'remove_event':
case "remove_event":
var mapId = Number(args[1]);
var eventId = Number(args[2]);
$gameMapsExt.remove_event_from_need(mapId, eventId);
break;
case 'ext':
case "ext":
throw new Error("在运行之前要先导出,完成生成过程");
}
}
}
};
//=============================================================================
// Try To Export Extra Event to MapExt json
//=============================================================================
if (Utils.isNwjs() && Utils.isOptionValid('test') && SF_ExtraEvent.ExportMapExtraEvent) {
var fs = require('fs');
var path = require('path');
if (Utils.isNwjs() && Utils.isOptionValid("test") && SF_ExtraEvent.ExportMapExtraEvent) {
var fs = require("fs");
var path = require("path");
var note_reg = new RegExp(/<SF_EXTRA_EVENT:\s*(\d*)>/i);
var move_route_target = new RegExp(/\$gameMapsExt\.set_route_target\(\s*(\d+)\s*\)/)
var move_route_target = new RegExp(/\$gameMapsExt\.set_route_target\(\s*(\d+)\s*\)/);
function processCommand213(command, map_events) {
if (command.parameters[0] > 0) {
@ -414,38 +414,37 @@ var $gameMapsExt = null;
}
target = Number(match[1]) + SF_ExtraEvent.EventExtIdStart;
return false;
})
});
command.parameters[0] = target;
command.parameters[1]["list"] = list;
}
function toCommand213(command, args, map_event) {
var event_id = Number(args[2]) + SF_ExtraEvent.EventExtIdStart
var event_id = Number(args[2]) + SF_ExtraEvent.EventExtIdStart;
command.code = 213;
command.parameters = [event_id, Number(args[3]), args[4].toLowerCase() === 'true'];
command.parameters = [event_id, Number(args[3]), args[4].toLowerCase() === "true"];
}
function toCommand203(command, args, map_event) {
var event_id = Number(args[2]) + SF_ExtraEvent.EventExtIdStart
var event_id = Number(args[2]) + SF_ExtraEvent.EventExtIdStart;
command.code = 203;
command.parameters = [event_id, 0, 0, 0, 0];
switch (args[3].toLowerCase()) {
case 'direct':
case "direct":
command.parameters[1] = 0;
command.parameters[2] = Number(args[4]);
command.parameters[3] = Number(args[5]);
break;
case 'variables':
case "variables":
command.parameters[1] = 1;
command.parameters[2] = Number(args[4]);
command.parameters[3] = Number(args[5]);
break;
case 'exchange':
case "exchange":
command.parameters[1] = 2;
if (args[4].toLowerCase() === 'normal') {
if (args[4].toLowerCase() === "normal") {
command.parameters[2] = Number(args[5]);
} else if (args[4].toLowerCase() === 'ext') {
} else if (args[4].toLowerCase() === "ext") {
command.parameters[2] = Number(args[5]) + SF_ExtraEvent.EventExtIdStart;
} else {
throw new Error("not support excahnge target");
@ -455,10 +454,14 @@ var $gameMapsExt = null;
throw new Error("not support event location mode");
}
const dirct_map = {
'stay': 0, 'down': 1, 'left': 2, 'right': 3, 'up': 4
stay: 0,
down: 1,
left: 2,
right: 3,
up: 4,
};
command.parameters[4] = dirct_map[args[6].toLowerCase()];
if ((typeof (command.parameters[4])).toLowerCase() !== 'number') {
if ((typeof command.parameters[4]).toLowerCase() !== "number") {
throw new Error("not support direction");
}
}
@ -466,23 +469,22 @@ var $gameMapsExt = null;
function processCommand365(command, map_event) {
var args = command.parameters[0].split(" ");
var com = args.shift();
if (com.toLowerCase() !== 'sf_extra_event' || args[0].toLowerCase() !== 'ext') {
if (com.toLowerCase() !== "sf_extra_event" || args[0].toLowerCase() !== "ext") {
return;
}
switch (args[1].toLowerCase()) {
case 'show_balloon_icon':
case "show_balloon_icon":
toCommand213(com, args, map_event);
break;
case 'set_event_location':
case "set_event_location":
toCommand203(com, args, map_event);
}
}
function exportExtraEvent(mapId) {
var map_data_path = path.join(process.cwd(), 'data/Map%1.json'.format(mapId.padZero(3)));
var map_ext_data_path = path.join(process.cwd(), 'data/Map%1Ext.json'.format(mapId.padZero(3)));
var map_data = JSON.parse(fs.readFileSync(map_data_path, 'utf8'));
var map_data_path = path.join(process.cwd(), "data/Map%1.json".format(mapId.padZero(3)));
var map_ext_data_path = path.join(process.cwd(), "data/Map%1Ext.json".format(mapId.padZero(3)));
var map_data = JSON.parse(fs.readFileSync(map_data_path, "utf8"));
var map_events = map_data.events;
var map_ext_event_list = [];
@ -517,7 +519,7 @@ var $gameMapsExt = null;
return true;
}
return false;
})
});
}
}
}
@ -535,17 +537,17 @@ var $gameMapsExt = null;
map_event_list.push(event);
}
} else {
map_event_list.push(null)
map_event_list.push(null);
}
}
map_data.events = map_event_list;
fs.writeFileSync(map_data_path, JSON.stringify(map_data), 'utf8');
fs.writeFileSync(map_data_path, JSON.stringify(map_data), "utf8");
var map_ext_data = null;
var old_ext_data = null;
if (fs.existsSync(map_ext_data_path)) {
map_ext_data = JSON.parse(fs.readFileSync(map_ext_data_path, 'utf8'));
map_ext_data = JSON.parse(fs.readFileSync(map_ext_data_path, "utf8"));
old_ext_data = map_ext_data.events;
} else {
old_ext_data = {};
@ -556,12 +558,11 @@ var $gameMapsExt = null;
old_ext_data[event.ext_id] = event;
});
map_ext_data.events = old_ext_data;
fs.writeFileSync(map_ext_data_path, JSON.stringify(map_ext_data), 'utf8');
fs.writeFileSync(map_ext_data_path, JSON.stringify(map_ext_data), "utf8");
}
var mapInfoPath = path.join(process.cwd(), 'data/MapInfos.json');
var mapInfos = JSON.parse(fs.readFileSync(mapInfoPath, 'utf8'));
var mapInfoPath = path.join(process.cwd(), "data/MapInfos.json");
var mapInfos = JSON.parse(fs.readFileSync(mapInfoPath, "utf8"));
mapInfos.forEach(function (mapInfo) {
if (mapInfo) {
exportExtraEvent(mapInfo.id);
@ -569,8 +570,6 @@ var $gameMapsExt = null;
});
}
//=============================================================================
// Compatible with xdRs_MiniMap
//=============================================================================
@ -596,8 +595,15 @@ var $gameMapsExt = null;
if (SceneManager._scene instanceof Scene_Map && SceneManager._scene._miniMap) {
SceneManager._scene._miniMap.removeEvent(this._events[eventId]);
}
}
};
SF_ExtraEvent.xdRs_MiniMap.Game_Map_eraseEvent = Game_Map.prototype.eraseEvent;
Game_Map.prototype.eraseEvent = function (eventId) {
SF_ExtraEvent.xdRs_MiniMap.Game_Map_eraseEvent.call(this, eventId);
if (SceneManager._scene instanceof Scene_Map && SceneManager._scene._miniMap) {
SceneManager._scene._miniMap.removeEvent(this._events[eventId]);
}
};
//=============================================================================
// Window_MiniMap
//=============================================================================
@ -608,7 +614,7 @@ var $gameMapsExt = null;
Window_MiniMap.prototype.removeEvent = function (event) {
this._sprite.removeEvent(event);
}
};
//=============================================================================
// Sprite_MiniMap
@ -618,7 +624,7 @@ var $gameMapsExt = null;
var sprite = new Sprite_MiniPart(event);
this._parts.push(sprite);
this.addChild(sprite);
}
};
Sprite_MiniMap.prototype.removeEvent = function (event) {
var sprite = this._parts.filter(function (sprite) {
@ -630,8 +636,6 @@ var $gameMapsExt = null;
});
this.removeChild(sprite);
};
}
}
})();

@ -41,7 +41,10 @@ var SF_Plugins = SF_Plugins || {};
result.clear();
result.used = this.testApply(target);
result.missed = false;
result.evaded = !result.missed && Math.random() >= this.attackHit(target) - this.itemEva(target);
result.evaded =
!result.missed &&
!this.isCertainHit() &&
Math.random() >= this.attackHit(target) - this.itemEva(target);
result.physical = this.isPhysical();
result.drain = this.isDrain();
if (result.isHit()) {

Loading…
Cancel
Save