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

@ -13,85 +13,85 @@ var $gameMapsExt = null;
//=============================================================================
/*:
* @plugindesc This plugin provide extra event.
* @author Salted Fish
*
* @param ExportMapExtraEvent
* @desc Export map extra event to json file.
* only available in nwjs.
* @default false
* @type boolean
*
* @help
* ============================================================================
* Introduction 介绍
* ============================================================================
*
* This plugin provide extra event.
* 这个插件提供额外的事件
*
* put in event note:
* 把这东西放进事件的note中来将这个事件导出
* <SF_EXTRA_EVENT: eventExtId>
*
*
* ============================================================================
* Plugin Commands 插件命令
* ============================================================================
*
* SF_Extra_Event Insert_Event <mapId> <evenExttId>
* Add an event to the map.
* 将一个额外事件添加到地图中
*
* SF_Extra_Event Remove_Event <mapId> <eventExtId>
* Remove an event from the map.
* 将一个额外事件从地图中移除
*
* SF_Extra_Event Ext Show_Balloon_Icon <eventExtId> <ballonId> <waitForComplete>
* 用来将不在地图上的事件能添加 显示气球图标 的命令
* 这个命令会在导出事件的时候将其转换成对应的事件指令
* eventExtId 事件的额外ID
* ballonId 要显示的气球的ID 从1开始计数
* waifForComplete 是否要等待完成使用 true false其余样式会作为false来生成
*
* SF_Extra_Event Ext Set_Event_Location <eventExtId> <direct|variables|exchange> <param1> <param2> <direction>
* 用来设置额外事件的位置
* eventExtId 是设置额外事件的对象
* 设置的位置有三种方式 direct variables exchange
* direct是直接指定目标位置param1和param2就是目标的x,y坐标
* variables是用变量来计算目标的位置 param1和param2就是目标x,y坐标所在的变量标号
* exchange是与地图上的事件进行对换
* param1为normal或ext代表与普通事件或额外事件对换
* param2则指定事件的Id使用0则代指自身
* direction则是指定事件的朝向 使用stay, down, left, right, up来代指朝向
*
* 在设置移动路线时填入脚本$gameMapsExt.set_route_target(eventExtId)来修改本次移动路线
* 设置的事件对象只有最后一次有效这个脚本是无法执行的要经过导出转成语义可用的
*
* ============================================================================
* Script Calls
* ============================================================================
*
* $gameMapsExt.insert_event_to_need(mapId, eventExtId)
* Add an event to the map.
*
* $gameMapsExt.remove_event_from_need(mapId, eventExtId)
* Remove an event from the map.
*
* ============================================================================
* Compatibility
* ============================================================================
*
* This plugin is compatible with xdRs_MiniMap.js
*
*
* ============================================================================
* Changelog
* ============================================================================
*
* Version 1.0:
* - Release
*/
* @plugindesc This plugin provide extra event.
* @author Salted Fish
*
* @param ExportMapExtraEvent
* @desc Export map extra event to json file.
* only available in nwjs.
* @default false
* @type boolean
*
* @help
* ============================================================================
* Introduction 介绍
* ============================================================================
*
* This plugin provide extra event.
* 这个插件提供额外的事件
*
* put in event note:
* 把这东西放进事件的note中来将这个事件导出
* <SF_EXTRA_EVENT: eventExtId>
*
*
* ============================================================================
* Plugin Commands 插件命令
* ============================================================================
*
* SF_Extra_Event Insert_Event <mapId> <evenExttId>
* Add an event to the map.
* 将一个额外事件添加到地图中
*
* SF_Extra_Event Remove_Event <mapId> <eventExtId>
* Remove an event from the map.
* 将一个额外事件从地图中移除
*
* SF_Extra_Event Ext Show_Balloon_Icon <eventExtId> <ballonId> <waitForComplete>
* 用来将不在地图上的事件能添加 显示气球图标 的命令
* 这个命令会在导出事件的时候将其转换成对应的事件指令
* eventExtId 事件的额外ID
* ballonId 要显示的气球的ID 从1开始计数
* waifForComplete 是否要等待完成使用 true false其余样式会作为false来生成
*
* SF_Extra_Event Ext Set_Event_Location <eventExtId> <direct|variables|exchange> <param1> <param2> <direction>
* 用来设置额外事件的位置
* eventExtId 是设置额外事件的对象
* 设置的位置有三种方式 direct variables exchange
* direct是直接指定目标位置param1和param2就是目标的x,y坐标
* variables是用变量来计算目标的位置 param1和param2就是目标x,y坐标所在的变量标号
* exchange是与地图上的事件进行对换
* param1为normal或ext代表与普通事件或额外事件对换
* param2则指定事件的Id使用0则代指自身
* direction则是指定事件的朝向 使用stay, down, left, right, up来代指朝向
*
* 在设置移动路线时填入脚本$gameMapsExt.set_route_target(eventExtId)来修改本次移动路线
* 设置的事件对象只有最后一次有效这个脚本是无法执行的要经过导出转成语义可用的
*
* ============================================================================
* Script Calls
* ============================================================================
*
* $gameMapsExt.insert_event_to_need(mapId, eventExtId)
* Add an event to the map.
*
* $gameMapsExt.remove_event_from_need(mapId, eventExtId)
* Remove an event from the map.
*
* ============================================================================
* Compatibility
* ============================================================================
*
* This plugin is compatible with xdRs_MiniMap.js
*
*
* ============================================================================
* Changelog
* ============================================================================
*
* Version 1.0:
* - Release
*/
//=============================================================================
(function () {
@ -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) {
@ -178,7 +178,7 @@ var $gameMapsExt = null;
window.Game_MapsExt = Game_MapsExt;
Game_MapsExt.prototype.initialize = function () {
this._need_insert_events_id = {};// key: mapId, value: [eventId]
this._need_insert_events_id = {}; // key: mapId, value: [eventId]
};
// Get Extra event Ids
@ -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) {
@ -215,7 +215,7 @@ var $gameMapsExt = null;
}
};
// Get Extra events in the map
// Get Extra events in the map
// return {eventId: event}
Game_MapsExt.prototype.need_insert_events = function (mapId) {
var events_id = this.need_insert_events_id(mapId);
@ -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,17 +614,17 @@ var $gameMapsExt = null;
Window_MiniMap.prototype.removeEvent = function (event) {
this._sprite.removeEvent(event);
}
};
//=============================================================================
// Sprite_MiniMap
// Sprite_MiniMap
//=============================================================================
Sprite_MiniMap.prototype.addEvent = function (event) {
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