//-----------------------------------------------------
//
//-----------------------------------------------------
/*:
* @plugindesc 学习galv大佬写的复制事件脚本。
* @author 仇九
*
* @help
* 一共三个指令。
* 写在脚本指令里而非插件指令里!!!
* 1.
* HG.Spawn.spawnEvent(mapid,eventId,x,y);
* 将id为mapid的地图上id为eventId的事件复制到当前地图的(x,y)位置。
* 2.
* HG.Spawn.clearEvent(id);
* 删除本地图指定id的事件。
* 若是删除本事件,那么就写成HG.Spawn.clearEvent(this._eventId)
* 若在非“复制事件”的事件中执行,那么无效。
* 3.
* HG.Spawn.clearMap(id);
* 删除本地图的所有复制事件。
*
*/
//-----------------------------------------------------
//
//-----------------------------------------------------
var HG = HG || {};
HG.Spawn = HG.Spawn || {};
var $dataSpawnMap=null;
HG.Spawn.spawnEvent = function(mapid,eventId,x,y) {//默认为本地图的xy
DataManager.loadSpawnMapData(0,mapid,eventId,x,y);
};
HG.Spawn.clearEvent = function(id) {
$gameMap.clearEvent(id);
};
HG.Spawn.clearMap = function() {
$gameMap.clearMap();
};
HG.Spawn.clearSwitches = function(mapId,eventId) {
var switches = ['A','B','C','D'];
for (var s = 0; s < switches.length; s++) {
var key = mapId + "," + eventId + "," + switches[s];
$gameSelfSwitches.setValue(key,false);
};
};
DataManager.loadSpawnMapData = function(bid,mapid,eventId,x,y) {
if (Number(mapid) > 0) {
var src = 'Map%1.json'.format(mapid.padZero(3));
var name='$dataSpawnMap';
var xhr = new XMLHttpRequest();
var url = 'data/' + src;
xhr.open('GET', url);
xhr.overrideMimeType('application/json');
xhr.onload = function() {
if (xhr.status < 400) {
window[name] = JSON.parse(xhr.responseText);
var object=window[name];
var array;
if (object === $dataSpawnMap) {
DataManager.extractMetadata(object);
array = object.events;
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) {
var data = array[i];
if (data && data.note !== undefined) {
DataManager.extractMetadata(data);
}
}
}
}
$gameMap.spawnEvent(bid,mapid,eventId,x,y);
}
};
xhr.send();
}
};
//-----------------------------------------------------
//
//-----------------------------------------------------
Game_Map.prototype.spawnEvent = function(bid,sourcemapid,sourceid,x,y) {
var maxid = this._events.length;
this._events[maxid] = new Game_SpawnEvent(bid,sourcemapid,sourceid,maxid,this._mapId,x,y);
SceneManager._scene._spriteset.createSpawnEvent(maxid);
};
Game_Map.prototype.clearEvent = function(id) {
this._events[id] = null;
SceneManager._scene._spriteset.clearEvent(id);
HG.Spawn.clearSwitches(this._mapId,id);
this.clearId();
};
Game_Map.prototype.clearMap = function() {
for (var i=1;i<this._events.length;i++) {
if (this._events[i]._sourceid!=null) {
$gameMap.clearEvent(i);
i-=1;
}
}
};
Game_Map.prototype.clearId = function() {
for (var i = this._events.length - 1; i > 0; i--) {
if (this._events[i] === null) this._events.splice(i, 1);
else return;
};
};
//-----------------------------------------------------
//
//-----------------------------------------------------
Spriteset_Map.prototype.clearEvent = function(id) {
for (var i = 0; i < this._characterSprites.length; i++) {
var event = this._characterSprites[i]._character;
if (event._sourceid!=null && id == event._eventId) {
for (var s = 0; s < this._characterSprites[i]._animationSprites.length; s++) {
this._tilemap.removeChild(this._characterSprites[i]._animationSprites[s]);
};
this._tilemap.removeChild(this._characterSprites[i]);
};
};
};
Spriteset_Map.prototype.createSpawnEvent = function(id) {
var event = $gameMap._events[id];
var sId = this._characterSprites.length;
this._characterSprites[sId] = new Sprite_Character(event);
this._characterSprites[sId].update();
this._tilemap.addChild(this._characterSprites[sId])
};
//-----------------------------------------------------
//
//-----------------------------------------------------
function Game_SpawnEvent() {
this.initialize.apply(this, arguments);
}
Game_SpawnEvent.prototype = Object.create(Game_Event.prototype);
Game_SpawnEvent.prototype.constructor = Game_SpawnEvent;
Game_SpawnEvent.prototype.initialize = function(bid,sourcemapid,sourceid,maxid,mapid,x,y) {
this._bid = bid;
this._sourcemapid = sourcemapid;
this._sourceid = sourceid;
this._eventId = maxid;
this._mapId = mapid;
this._sx = x;
this._sy = y;
this._event = $dataSpawnMap.events[this._sourceid];
this._event.x = x;
this._event.y = y;
Game_Event.prototype.initialize.call(this,mapid,maxid);
DataManager.extractMetadata(this.event());
this.refresh();
};
Game_SpawnEvent.prototype.event = function() {
return this._event;
};
Game_SpawnEvent.prototype.locate = function(x,y) {
Game_Event.prototype.locate.call(this, x, y);
};
Game_SpawnEvent.prototype.bid = function() {
return this._bid;
};