var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = 
{
    "init": function () {
	this._afterLoadResources = function () {
		// 本函数将在所有资源加载完毕后，游戏开启前被执行
	}

	//手册绘制调整
	core.ui.setFontForMaxWidth = function (name, text, maxWidth, font) {
		var ctx = this.getContextByName(name);
		if (font) core.setFont(name, font);
		var font = ctx.font,
			u = /(\d+)px/.exec(font);
		if (u == null) return font;
		for (var font_size = parseInt(u[1]); font_size >= 8; font_size--) {
			ctx.font = font.replace(/(\d+)px/, font_size + "px");
			if (ctx.measureText(text).width <= maxWidth) return font_size;
		}
	}

	core.ui._drawBook_drawName = function (index, enemy, top, left, width) {
		// 绘制第零列（名称和特殊属性）
		// 如果需要添加自己的比如怪物的称号等，也可以在这里绘制
		core.setTextAlign('ui', 'center');
		if (enemy.specialText.length == 0) {
			core.fillText('ui', enemy.name, left + width / 2,
				top + 35, '#DDDDDD', this._buildFont(17, true), width);
		} else {
			core.fillText('ui', enemy.name, left + width / 2,
				top + 28, '#DDDDDD', this._buildFont(17, true), width);
			switch (enemy.specialText.length) {
			case 1:
				core.fillText('ui', enemy.specialText[0], left + width / 2,
					top + 50, core.arrayToRGBA((enemy.specialColor || [])[0] || '#FF6A6A'),
					this._buildFont(15, true), width);
				break;
			case 2:
				// Step 1: 计算字体
				var text = enemy.specialText[0] + "  " + enemy.specialText[1];
				var fSize = core.setFontForMaxWidth('ui', text, width, this._buildFont(15, true));
				if (fSize <= 9) { //分两行
					text = enemy.specialText[0].length > enemy.specialText[1].length ? enemy.specialText[0] : enemy.specialText[1];
					core.setFontForMaxWidth('ui', text, width, this._buildFont(10, true));
					core.fillText('ui', enemy.specialText[0], left + width / 2,
						top + 44, core.arrayToRGBA((enemy.specialColor || [])[0] || '#FF6A6A'));
					core.fillText('ui', enemy.specialText[1], left + width / 2,
						top + 56, core.arrayToRGBA((enemy.specialColor || [])[1] || '#FF6A6A'));
				} else { //一行
					// Step 2: 计算总宽度
					var totalWidth = core.calWidth('ui', text);
					var leftWidth = core.calWidth('ui', enemy.specialText[0]);
					var rightWidth = core.calWidth('ui', enemy.specialText[1]);
					// Step 3: 绘制
					core.fillText('ui', enemy.specialText[0], left + (width + leftWidth - totalWidth) / 2,
						top + 50, core.arrayToRGBA((enemy.specialColor || [])[0] || '#FF6A6A'));
					core.fillText('ui', enemy.specialText[1], left + (width + totalWidth - rightWidth) / 2,
						top + 50, core.arrayToRGBA((enemy.specialColor || [])[1] || '#FF6A6A'));
				}

				break;
			default:
				core.fillText('ui', '多属性...', left + width / 2,
					top + 50, '#FF6A6A', this._buildFont(15, true), width);
			}
		}
	}

	core.ui._drawBookDetail_turnAndCriticals = function (enemy, floorId, texts) {
		if (!enemy.x && enemy.locs) {
			enemy.x = enemy.locs[0][0];
			enemy.y = enemy.locs[0][1];
		}
		var damageInfo = core.getDamageInfo(enemy.id, null, enemy.x, enemy.y, floorId);
		texts.push("\r[#FF6A6A]\\d战斗回合数：\\d\r[]" + ((damageInfo || {}).turn || 0));
		// 临界表
		var criticals = core.enemys.nextCriticals(enemy.id, 8, enemy.x, enemy.y, floorId).map(function (v) {
			return core.formatBigNumber(v[0]) + ":" + core.formatBigNumber(v[1]);
		});
		while (criticals[0] == '0:0') criticals.shift();
		texts.push("\r[#FF6A6A]\\d临界表：\\d\r[]" + JSON.stringify(criticals));
	}

	core.ui.drawBook = function (index) {
		var floorId = core.floorIds[(core.status.event.ui || {}).index] || core.status.floorId;
		// 清除浏览地图时的光环缓存
		if (floorId != core.status.floorId && core.status.checkBlock) {
			core.status.checkBlock.cache = {};
		}
		var enemys = core.enemys.getCurrentEnemys(floorId);
		if (core.getFlag('book_MT12', false)) enemys = core.enemys.getCurrentEnemys('MT12').filter(ele => ele.id == 'greenKingPro'); //MT12的特效特判
		core.clearUI();
		core.clearMap('data');
		// 生成groundPattern
		core.maps.generateGroundPattern(floorId);
		this._drawBook_drawBackground();
		core.setAlpha('ui', 1);

		if (enemys.length == 0) {
			return this._drawBook_drawEmpty();
		}

		index = core.clamp(index, 0, enemys.length - 1);
		core.status.event.data = index;
		var pageinfo = this._drawBook_pageinfo();
		var perpage = pageinfo.per_page,
			page = parseInt(index / perpage) + 1,
			totalPage = Math.ceil(enemys.length / perpage);

		var start = (page - 1) * perpage;
		enemys = enemys.slice(start, page * perpage);

		for (var i = 0; i < enemys.length; i++)
			this._drawBook_drawOne(floorId, i, enemys[i], pageinfo, index == start + i);

		core.drawBoxAnimate();
		this.drawPagination(page, totalPage);
		core.setTextAlign('ui', 'center');
		core.fillText('ui', '返回游戏', core._PX_ - 46, core._PY_ - 13, '#DDDDDD', this._buildFont(15, true));
	}

	core.ui._drawBookDetail = function (index) {
		if (core.getFlag('book_MT12', false)) { //MT12的特效特判
			index = core.enemys.getCurrentEnemys('MT12').findIndex(ele => ele.id == 'greenKingPro');
		}
		var info = this._drawBookDetail_getInfo(index),
			enemy = info[0];
		if (!enemy) return;
		var content = info[1].join("\n");
		core.status.event.id = 'book-detail';
		core.animateFrame.tip = null;
		core.clearMap('data');

		var left = 10,
			width = core._PX_ - 2 * left,
			right = left + width;
		var content_left = left + 25,
			validWidth = right - content_left - 13;
		var height = Math.max(this.getTextContentHeight(content, { fontSize: 16, lineHeight: 24, maxWidth: validWidth }) + 58, 80),
			top = (core._PY_ - height) / 2,
			bottom = top + height;

		core.setAlpha('data', 0.9);
		core.fillRect('data', left, top, width, height, '#000000');
		core.setAlpha('data', 1);
		core.strokeRect('data', left - 1, top - 1, width + 1, height + 1,
			core.arrayToRGBA(core.status.globalAttribute.borderColor), 2);
		core.playSound('确定');
		this._drawBookDetail_drawContent(enemy, content, { top: top, content_left: content_left, bottom: bottom, validWidth: validWidth });
	}

	/* 宝石血瓶左下角显示数值
	 * 注意！！！不要在道具属性中直接操作flags，使用core.status.hero.flags或core.setFlag系列函数代替！
	 * 需要将 变量：itemDetail改为true才可正常运行
	 * 请尽量减少勇士的属性数量，否则可能会出现严重卡顿（划掉，现在你放一万个属性也不会卡）
	 * 注意：这里的属性必须是core.status.hero里面的，flag无法显示
	 * 如果不想显示，可以core.setFlag("itemDetail", false);
	 * 然后再core.getItemDetail();
	 * 如有bug在大群或造塔群@古祠
	 */

	// 忽略的道具
	const ignore = ['superPotion'];

	// 取消注释下面这句可以减少超大地图的判定。
	// 如果地图宝石过多，可能会略有卡顿，可以尝试取消注释下面这句话来解决。
	// core.bigmap.threshold = 256;
	const origin = core.control.updateStatusBar;
	core.updateStatusBar = core.control.updateStatusBar = function () {
		if (core.getFlag('__statistics__')) return;
		else return origin.apply(core.control, arguments);
	}

	core.control.updateDamage = function (floorId, ctx) {
		floorId = floorId || core.status.floorId;
		if (!floorId || core.status.gameOver || main.mode != 'play') return;
		const onMap = ctx == null;

		// 没有怪物手册
		if (!core.hasItem('book')) return;
		core.status.damage.posX = core.bigmap.posX;
		core.status.damage.posY = core.bigmap.posY;
		if (!onMap) {
			const width = core.floors[floorId].width,
				height = core.floors[floorId].height;
			// 地图过大的缩略图不绘制显伤
			if (width * height > core.bigmap.threshold) return;
		}
		this._updateDamage_damage(floorId, onMap);
		this._updateDamage_extraDamage(floorId, onMap);
		core.getItemDetail(floorId); // 宝石血瓶详细信息
		this.drawDamage(ctx);
	};

	// 绘制
	function drawItemDetail(diff, x, y) {
		const px = 32 * x + 2,
			py = 32 * y + 30;
		let content = '';
		// 获得数据和颜色
		let i = 0;
		for (const name in diff) {
			if (!diff[name]) continue;
			let color = '#fff';

			if (typeof diff[name] === 'number')
				content = core.formatBigNumber(diff[name], true);
			else content = diff[name];
			switch (name) {
			case 'atk':
			case 'atkper':
				color = '#FF7A7A';
				break;
			case 'def':
			case 'defper':
				color = '#00E6F1';
				break;
			case 'mdef':
			case 'mdefper':
				color = '#6EFF83';
				break;
			case 'hp':
				color = '#A4FF00';
				break;
			case 'hpmax':
			case 'hpmaxper':
				color = '#F9FF00';
				break;
			case 'mana':
				color = '#c66';
				break;
			}
			// 绘制
			core.status.damage.data.push({
				text: content,
				px: px,
				py: py - 10 * i,
				color: color
			});
			i++;
		}
	}

	// 获取宝石信息 并绘制
	this.getItemDetail = function (floorId) {
		if (!core.getFlag('itemDetail')) return;
		if (!core.status.thisMap) return;
		floorId = floorId ?? core.status.thisMap.floorId;
		const beforeRatio = core.status.thisMap.ratio;
		core.status.thisMap.ratio = core.status.maps[floorId].ratio;
		let diff = {};
		const before = core.status.hero;
		const hero = core.clone(core.status.hero);
		const handler = {
			set(target, key, v) {
				diff[key] = v - (target[key] || 0);
				if (!diff[key]) diff[key] = void 0;
				return true;
			}
		};
		core.status.hero = new Proxy(hero, handler);
		core.status.maps[floorId].blocks.forEach(function (block) {
			if (
				block.event.cls !== 'items' ||
				ignore.includes(block.event.id) ||
				block.disable
			)
				return;
			const x = block.x,
				y = block.y;
			// v2优化，只绘制范围内的部分
			if (core.bigmap.v2) {
				if (
					x < core.bigmap.posX - core.bigmap.extend ||
					x > core.bigmap.posX + core._WIDTH_ + core.bigmap.extend ||
					y < core.bigmap.posY - core.bigmap.extend ||
					y > core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend
				) {
					return;
				}
			}
			diff = {};
			const id = block.event.id;
			const item = core.material.items[id];
			if (item.cls === 'equips') {
				// 装备也显示
				const diff = item.equip.value ?? {};
				const per = item.equip.percentage ?? {};
				for (const name in per) {
					diff[name + 'per'] = per[name].toString() + '%';
				}
				drawItemDetail(diff, x, y);
				return;
			}
			// 跟数据统计原理一样 执行效果 前后比较
			core.setFlag('__statistics__', true);
			try {
				eval(item.itemEffect);
			} catch (error) {}
			drawItemDetail(diff, x, y);
		});
		core.status.thisMap.ratio = beforeRatio;
		core.status.hero = before;
		window.hero = before;
		window.flags = before.flags;
	};
},
    "drawLight": function () {

	// 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...)
	// 【参数说明】
	// name：必填，要绘制到的画布名；可以是一个系统画布，或者是个自定义画布；如果不存在则创建
	// color：可选，只能是一个0~1之间的数，为不透明度的值。不填则默认为0.9。
	// lights：可选，一个数组，定义了每个独立的灯光。
	//        其中每一项是三元组 [x,y,r] x和y分别为该灯光的横纵坐标，r为该灯光的半径。
	// lightDec：可选，0到1之间，光从多少百分比才开始衰减（在此范围内保持全亮），不设置默认为0。
	//        比如lightDec为0.5代表，每个灯光部分内圈50%的范围全亮，50%以后才开始快速衰减。
	// 【调用样例】
	// core.plugin.drawLight('curtain'); // 在curtain层绘制全图不透明度0.9，等价于更改画面色调为[0,0,0,0.9]。
	// core.plugin.drawLight('ui', 0.95, [[25,11,46]]); // 在ui层绘制全图不透明度0.95，其中在(25,11)点存在一个半径为46的灯光效果。
	// core.plugin.drawLight('test', 0.2, [[25,11,46,0.1]]); // 创建一个test图层，不透明度0.2，其中在(25,11)点存在一个半径为46的灯光效果，灯光中心不透明度0.1。
	// core.plugin.drawLight('test2', 0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 创建test2图层，且存在三个灯光效果，分别是中心(25,11)半径46，中心(105,121)半径88，中心(301,221)半径106。
	// core.plugin.drawLight('xxx', 0.3, [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果，它们在内圈40%范围内保持全亮，40%后才开始衰减。
	this.drawLight = function (name, color, lights, lightDec) {

		// 清空色调层；也可以修改成其它层比如animate/weather层，或者用自己创建的canvas
		var ctx = core.getContextByName(name);
		if (ctx == null) {
			if (typeof name == 'string')
				ctx = core.createCanvas(name, 0, 0, core._PX_ || core.__PIXELS__, core._PY_ || core.__PIXELS__, 98);
			else return;
		}

		ctx.mozImageSmoothingEnabled = false;
		ctx.webkitImageSmoothingEnabled = false;
		ctx.msImageSmoothingEnabled = false;
		ctx.imageSmoothingEnabled = false;

		core.clearMap(name);
		// 绘制色调层，默认不透明度
		if (color == null) color = 0.9;
		ctx.fillStyle = "rgba(0,0,0," + color + ")";
		ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);

		lightDec = core.clamp(lightDec, 0, 1);

		// 绘制每个灯光效果
		ctx.globalCompositeOperation = 'destination-out';
		lights.forEach(function (light) {
			// 坐标，半径，中心不透明度
			var x = light[0],
				y = light[1],
				r = light[2];
			// 计算衰减距离
			var decDistance = parseInt(r * lightDec);
			// 正方形区域的直径和左上角坐标
			var grd = ctx.createRadialGradient(x, y, decDistance, x, y, r);
			grd.addColorStop(0, "rgba(0,0,0,1)");
			grd.addColorStop(1, "rgba(0,0,0,0)");
			ctx.beginPath();
			ctx.fillStyle = grd;
			ctx.arc(x, y, r, 0, 2 * Math.PI);
			ctx.fill();
		});
		ctx.globalCompositeOperation = 'source-over';
		// 可以在任何地方（如afterXXX或自定义脚本事件）调用函数，方法为  core.plugin.xxx();
	}
},
    "shop": function () {
	// 【全局商店】相关的功能
	// 
	// 打开一个全局商店
	// shopId：要打开的商店id；noRoute：是否不计入录像
	this.openShop = function (shopId, noRoute) {
		var shop = core.status.shops[shopId];
		// Step 1: 检查能否打开此商店
		if (!this.canOpenShop(shopId)) {
			core.drawTip("该商店尚未开启");
			return false;
		}

		// Step 2: （如有必要）记录打开商店的脚本事件
		if (!noRoute) {
			core.status.route.push("shop:" + shopId);
		}

		// Step 3: 检查道具商店 or 公共事件
		if (shop.item) {
			if (core.openItemShop) {
				core.openItemShop(shopId);
			} else {
				core.playSound('操作失败');
				core.insertAction("道具商店插件不存在！请检查是否存在该插件！");
			}
			return;
		}
		if (shop.commonEvent) {
			core.insertCommonEvent(shop.commonEvent, shop.args);
			return;
		}

		_shouldProcessKeyUp = true;

		// Step 4: 执行标准公共商店    
		core.insertAction(this._convertShop(shop));
		return true;
	}

	////// 将一个全局商店转变成可预览的公共事件 //////
	this._convertShop = function (shop) {
		return [
			{ "type": "function", "function": "function() {core.addFlag('@temp@shop', 1);}" },
			{
				"type": "while",
				"condition": "true",
				"data": [
					// 检测能否访问该商店
					{
						"type": "if",
						"condition": "core.isShopVisited('" + shop.id + "')",
						"true": [
							// 可以访问，直接插入执行效果
							{ "type": "function", "function": "function() { core.plugin._convertShop_replaceChoices('" + shop.id + "', false) }" },
						],
						"false": [
							// 不能访问的情况下：检测能否预览
							{
								"type": "if",
								"condition": shop.disablePreview,
								"true": [
									// 不可预览，提示并退出
									{ "type": "playSound", "name": "操作失败" },
									"当前无法访问该商店！",
									{ "type": "break" },
								],
								"false": [
									// 可以预览：将商店全部内容进行替换
									{ "type": "tip", "text": "当前处于预览模式，不可购买" },
									{ "type": "function", "function": "function() { core.plugin._convertShop_replaceChoices('" + shop.id + "', true) }" },
								]
							}
						]
					}
				]
			},
			{ "type": "function", "function": "function() {core.addFlag('@temp@shop', -1);}" }
		];
	}

	this._convertShop_replaceChoices = function (shopId, previewMode) {
		var shop = core.status.shops[shopId];
		var choices = (shop.choices || []).filter(function (choice) {
			if (choice.condition == null || choice.condition == '') return true;
			try { return core.calValue(choice.condition); } catch (e) { return true; }
		}).map(function (choice) {
			var ableToBuy = core.calValue(choice.need);
			return {
				"text": choice.text,
				"icon": choice.icon,
				"color": ableToBuy && !previewMode ? choice.color : [153, 153, 153, 1],
				"action": ableToBuy && !previewMode ? ((shopId == 'shop4' ? [] : [{ "type": "playSound", "name": "商店" }]).concat(choice.action)) : [
					{ "type": "playSound", "name": "操作失败" },
					{ "type": "tip", "text": previewMode ? "预览模式下不可购买" : "购买条件不足" }
				],
			};
		}).concat({ "text": "离开", "action": [{ "type": "playSound", "name": "取消" }, { "type": "break" }] });
		core.insertAction({ "type": "choices", "text": shop.text, "choices": choices });
	}

	/// 是否访问过某个快捷商店
	this.isShopVisited = function (id) {
		if (!core.hasFlag("__shops__")) core.setFlag("__shops__", {});
		var shops = core.getFlag("__shops__");
		if (!shops[id]) shops[id] = {};
		return shops[id].visited;
	}

	/// 当前应当显示的快捷商店列表
	this.listShopIds = function () {
		return Object.keys(core.status.shops).filter(function (id) {
			return core.isShopVisited(id) || !core.status.shops[id].mustEnable;
		});
	}

	/// 是否能够打开某个商店
	this.canOpenShop = function (id) {
		if (this.isShopVisited(id)) return true;
		var shop = core.status.shops[id];
		if (shop.item || shop.commonEvent || shop.mustEnable) return false;
		return true;
	}

	/// 启用或禁用某个快捷商店
	this.setShopVisited = function (id, visited) {
		if (!core.hasFlag("__shops__")) core.setFlag("__shops__", {});
		var shops = core.getFlag("__shops__");
		if (!shops[id]) shops[id] = {};
		if (visited) shops[id].visited = true;
		else delete shops[id].visited;
	}

	/// 能否使用快捷商店
	this.canUseQuickShop = function (id) {
		// 如果返回一个字符串，表示不能，字符串为不能使用的提示
		// 返回null代表可以使用

		// 检查当前楼层的canUseQuickShop选项是否为false
		if (core.status.thisMap.canUseQuickShop === false)
			return '当前楼层不能使用快捷商店。';
		return null;
	}

	var _shouldProcessKeyUp = true;

	/// 允许商店X键退出
	core.registerAction('keyUp', 'shops', function (keycode) {
		if (!core.status.lockControl || core.status.event.id != 'action') return false;
		if ((keycode == 13 || keycode == 32) && !_shouldProcessKeyUp) {
			_shouldProcessKeyUp = true;
			return true;
		}

		if (!core.hasFlag("@temp@shop") || core.status.event.data.type != 'choices') return false;
		var data = core.status.event.data.current;
		var choices = data.choices;
		var topIndex = core.actions._getChoicesTopIndex(choices.length);
		if (keycode == 88 || keycode == 27) { // X, ESC
			core.actions._clickAction(core._HALF_WIDTH_ || core.__HALF_SIZE__, topIndex + choices.length - 1);
			return true;
		}
		return false;
	}, 60);

	/// 允许长按空格或回车连续执行操作
	core.registerAction('keyDown', 'shops', function (keycode) {
		if (!core.status.lockControl || !core.hasFlag("@temp@shop") || core.status.event.id != 'action') return false;
		if (core.status.event.data.type != 'choices') return false;
		core.status.onShopLongDown = true;
		var data = core.status.event.data.current;
		var choices = data.choices;
		var topIndex = core.actions._getChoicesTopIndex(choices.length);
		if (keycode == 13 || keycode == 32) { // Space, Enter
			core.actions._clickAction(core._HALF_WIDTH_ || core.__HALF_SIZE__, topIndex + core.status.event.selection);
			_shouldProcessKeyUp = false;
			return true;
		}
		return false;
	}, 60);

	// 允许长按屏幕连续执行操作
	core.registerAction('longClick', 'shops', function (x, y, px, py) {
		if (!core.status.lockControl || !core.hasFlag("@temp@shop") || core.status.event.id != 'action') return false;
		if (core.status.event.data.type != 'choices') return false;
		var data = core.status.event.data.current;
		var choices = data.choices;
		var topIndex = core.actions._getChoicesTopIndex(choices.length);
		if (Math.abs(x - (core._HALF_WIDTH_ || core.__HALF_SIZE__)) <= 2 && y >= topIndex && y < topIndex + choices.length) {
			core.actions._clickAction(x, y);
			return true;
		}
		return false;
	}, 60);
},
    "removeMap": function () {
		// 高层塔砍层插件，删除后不会存入存档，不可浏览地图也不可飞到。
		// 推荐用法：
		// 对于超高层或分区域塔，当在1区时将2区以后的地图删除；1区结束时恢复2区，进二区时删除1区地图，以此类推
		// 这样可以大幅减少存档空间，以及加快存读档速度

		// 删除楼层
		// core.removeMaps("MT1", "MT300") 删除MT1~MT300之间的全部层
		// core.removeMaps("MT10") 只删除MT10层
		this.removeMaps = function (fromId, toId) {
			toId = toId || fromId;
			var fromIndex = core.floorIds.indexOf(fromId),
				toIndex = core.floorIds.indexOf(toId);
			if (toIndex < 0) toIndex = core.floorIds.length - 1;
			flags.__visited__ = flags.__visited__ || {};
			flags.__removed__ = flags.__removed__ || [];
			flags.__disabled__ = flags.__disabled__ || {};
			flags.__leaveLoc__ = flags.__leaveLoc__ || {};
			for (var i = fromIndex; i <= toIndex; ++i) {
				var floorId = core.floorIds[i];
				if (core.status.maps[floorId].deleted) continue;
				delete flags.__visited__[floorId];
				flags.__removed__.push(floorId);
				delete flags.__disabled__[floorId];
				delete flags.__leaveLoc__[floorId];
				(core.status.autoEvents || []).forEach(function (event) {
					if (event.floorId == floorId && event.currentFloor) {
						core.autoEventExecuting(event.symbol, false);
						core.autoEventExecuted(event.symbol, false);
					}
				});
				core.status.maps[floorId].deleted = true;
				core.status.maps[floorId].canFlyTo = false;
				core.status.maps[floorId].canFlyFrom = false;
				core.status.maps[floorId].cannotViewMap = true;
			}
		}

		// 恢复楼层
		// core.resumeMaps("MT1", "MT300") 恢复MT1~MT300之间的全部层
		// core.resumeMaps("MT10") 只恢复MT10层
		this.resumeMaps = function (fromId, toId) {
			toId = toId || fromId;
			var fromIndex = core.floorIds.indexOf(fromId),
				toIndex = core.floorIds.indexOf(toId);
			if (toIndex < 0) toIndex = core.floorIds.length - 1;
			flags.__removed__ = flags.__removed__ || [];
			for (var i = fromIndex; i <= toIndex; ++i) {
				var floorId = core.floorIds[i];
				if (!core.status.maps[floorId].deleted) continue;
				flags.__removed__ = flags.__removed__.filter(function (f) { return f != floorId; });
				core.status.maps[floorId] = core.loadFloor(floorId);
			}
		}

		// 分区砍层相关
		var inAnyPartition = function (floorId) {
			var inPartition = false;
			(core.floorPartitions || []).forEach(function (floor) {
				var fromIndex = core.floorIds.indexOf(floor[0]);
				var toIndex = core.floorIds.indexOf(floor[1]);
				var index = core.floorIds.indexOf(floorId);
				if (fromIndex < 0 || index < 0) return;
				if (toIndex < 0) toIndex = core.floorIds.length - 1;
				if (index >= fromIndex && index <= toIndex) inPartition = true;
			});
			return inPartition;
		}

		// 分区砍层
		this.autoRemoveMaps = function (floorId) {
			if (main.mode != 'play' || !inAnyPartition(floorId)) return;
			// 根据分区信息自动砍层与恢复
			(core.floorPartitions || []).forEach(function (floor) {
				var fromIndex = core.floorIds.indexOf(floor[0]);
				var toIndex = core.floorIds.indexOf(floor[1]);
				var index = core.floorIds.indexOf(floorId);
				if (fromIndex < 0 || index < 0) return;
				if (toIndex < 0) toIndex = core.floorIds.length - 1;
				if (index >= fromIndex && index <= toIndex) {
					core.resumeMaps(core.floorIds[fromIndex], core.floorIds[toIndex]);
				} else {
					core.removeMaps(core.floorIds[fromIndex], core.floorIds[toIndex]);
				}
			});
		}
	},
    "fiveLayers": function () {
		// 是否启用五图层（增加背景2层和前景2层） 将__enable置为true即会启用；启用后请保存后刷新编辑器
		// 背景层2将会覆盖背景层 被事件层覆盖 前景层2将会覆盖前景层
		// 另外 请注意加入两个新图层 会让大地图的性能降低一些
		// 插件作者：ad
		var __enable = false;
		if (!__enable) return;

		// 创建新图层
		function createCanvas (name, zIndex) {
			if (!name) return;
			var canvas = document.createElement('canvas');
			canvas.id = name;
			canvas.className = 'gameCanvas anti-aliasing';
			// 编辑器模式下设置zIndex会导致加入的图层覆盖优先级过高
			if (main.mode != "editor") canvas.style.zIndex = zIndex || 0;
			// 将图层插入进游戏内容
			document.getElementById('gameDraw').appendChild(canvas);
			var ctx = canvas.getContext('2d');
			core.canvas[name] = ctx;
			canvas.width = core._PX_ || core.__PIXELS__;
			canvas.height = core._PY_ || core.__PIXELS__;
			return canvas;
		}

		var bg2Canvas = createCanvas('bg2', 20);
		var fg2Canvas = createCanvas('fg2', 63);
		// 大地图适配
		core.bigmap.canvas = ["bg2", "fg2", "bg", "event", "event2", "fg", "damage"];
		core.initStatus.bg2maps = {};
		core.initStatus.fg2maps = {};

		if (main.mode == 'editor') {
			/*插入编辑器的图层 不做此步新增图层无法在编辑器显示*/
			// 编辑器图层覆盖优先级 eui > efg > fg(前景层) > event2(48*32图块的事件层) > event(事件层) > bg(背景层)
			// 背景层2(bg2) 插入事件层(event)之前(即bg与event之间)
			document.getElementById('mapEdit').insertBefore(bg2Canvas, document.getElementById('event'));
			// 前景层2(fg2) 插入编辑器前景(efg)之前(即fg之后)
			document.getElementById('mapEdit').insertBefore(fg2Canvas, document.getElementById('ebm'));
			// 原本有三个图层 从4开始添加
			var num = 4;
			// 新增图层存入editor.dom中
			editor.dom.bg2c = core.canvas.bg2.canvas;
			editor.dom.bg2Ctx = core.canvas.bg2;
			editor.dom.fg2c = core.canvas.fg2.canvas;
			editor.dom.fg2Ctx = core.canvas.fg2;
			editor.dom.maps.push('bg2map', 'fg2map');
			editor.dom.canvas.push('bg2', 'fg2');

			// 创建编辑器上的按钮
			var createCanvasBtn = function (name) {
				// 电脑端创建按钮
				var input = document.createElement('input');
				// layerMod4/layerMod5
				var id = 'layerMod' + num++;
				// bg2map/fg2map
				var value = name + 'map';
				input.type = 'radio';
				input.name = 'layerMod';
				input.id = id;
				input.value = value;
				editor.dom[id] = input;
				input.onchange = function () {
					editor.uifunctions.setLayerMod(value);
				}
				return input;
			};

			var createCanvasBtn_mobile = function (name) {
				// 手机端往选择列表中添加子选项
				var input = document.createElement('option');
				var id = 'layerMod' + num++;
				var value = name + 'map';
				input.name = 'layerMod';
				input.value = value;
				editor.dom[id] = input;
				return input;
			};
			if (!editor.isMobile) {
				var input = createCanvasBtn('bg2');
				var input2 = createCanvasBtn('fg2');
				// 获取事件层及其父节点
				var child = document.getElementById('layerMod'),
					parent = child.parentNode;
				// 背景层2插入事件层前
				parent.insertBefore(input, child);
				// 不能直接更改背景层2的innerText 所以创建文本节点
				var txt = document.createTextNode('bg2');
				// 插入事件层前(即新插入的背景层2前)
				parent.insertBefore(txt, child);
				// 向最后插入前景层2(即插入前景层后)
				parent.appendChild(input2);
				var txt2 = document.createTextNode('fg2');
				parent.appendChild(txt2);
				parent.childNodes[2].replaceWith("bg");
				parent.childNodes[6].replaceWith("事件");
				parent.childNodes[8].replaceWith("fg");
			} else {
				var input = createCanvasBtn_mobile('bg2');
				var input2 = createCanvasBtn_mobile('fg2');
				// 手机端因为是选项 所以可以直接改innerText
				input.innerText = '背景层2';
				input2.innerText = '前景层2';
				var parent = document.getElementById('layerMod');
				parent.insertBefore(input, parent.children[1]);
				parent.appendChild(input2);
			}
		}

		var _loadFloor_doNotCopy = core.maps._loadFloor_doNotCopy;
		core.maps._loadFloor_doNotCopy = function () {
			return ["bg2map", "fg2map"].concat(_loadFloor_doNotCopy());
		}
		////// 绘制背景和前景层 //////
		core.maps._drawBg_draw = function (floorId, toDrawCtx, cacheCtx, config) {
			config.ctx = cacheCtx;
			core.maps._drawBg_drawBackground(floorId, config);
			// ------ 调整这两行的顺序来控制是先绘制贴图还是先绘制背景图块；后绘制的覆盖先绘制的。
			core.maps._drawFloorImages(floorId, config.ctx, 'bg', null, null, config.onMap);
			core.maps._drawBgFgMap(floorId, 'bg', config);
			if (config.onMap) {
				core.drawImage(toDrawCtx, cacheCtx.canvas, core.bigmap.v2 ? -32 : 0, core.bigmap.v2 ? -32 : 0);
				core.clearMap('bg2');
				core.clearMap(cacheCtx);
			}
			core.maps._drawBgFgMap(floorId, 'bg2', config);
			if (config.onMap) core.drawImage('bg2', cacheCtx.canvas, core.bigmap.v2 ? -32 : 0, core.bigmap.v2 ? -32 : 0);
			config.ctx = toDrawCtx;
		}
		core.maps._drawFg_draw = function (floorId, toDrawCtx, cacheCtx, config) {
			config.ctx = cacheCtx;
			// ------ 调整这两行的顺序来控制是先绘制贴图还是先绘制前景图块；后绘制的覆盖先绘制的。
			core.maps._drawFloorImages(floorId, config.ctx, 'fg', null, null, config.onMap);
			core.maps._drawBgFgMap(floorId, 'fg', config);
			if (config.onMap) {
				core.drawImage(toDrawCtx, cacheCtx.canvas, core.bigmap.v2 ? -32 : 0, core.bigmap.v2 ? -32 : 0);
				core.clearMap('fg2');
				core.clearMap(cacheCtx);
			}
			core.maps._drawBgFgMap(floorId, 'fg2', config);
			if (config.onMap) core.drawImage('fg2', cacheCtx.canvas, core.bigmap.v2 ? -32 : 0, core.bigmap.v2 ? -32 : 0);
			config.ctx = toDrawCtx;
		}
		////// 移动判定 //////
		core.maps._generateMovableArray_arrays = function (floorId) {
			return {
				bgArray: this.getBgMapArray(floorId),
				fgArray: this.getFgMapArray(floorId),
				eventArray: this.getMapArray(floorId),
				bg2Array: this._getBgFgMapArray('bg2', floorId),
				fg2Array: this._getBgFgMapArray('fg2', floorId)
			};
		}
	},
    "itemShop": function () {
		// 道具商店相关的插件
		// 可在全塔属性-全局商店中使用「道具商店」事件块进行编辑（如果找不到可以在入口方块中找）

		var shopId = null; // 当前商店ID
		var type = 0; // 当前正在选中的类型，0买入1卖出
		var selectItem = 0; // 当前正在选中的道具
		var selectCount = 0; // 当前已经选中的数量
		var page = 0;
		var totalPage = 0;
		var totalMoney = 0;
		var list = [];
		var shopInfo = null; // 商店信息
		var choices = []; // 商店选项
		var use = 'money';
		var useText = '金币';

		var bigFont = core.ui._buildFont(20, false),
			middleFont = core.ui._buildFont(18, false);

		this._drawItemShop = function () {
			// 绘制道具商店

			// Step 1: 背景和固定的几个文字
			core.ui._createUIEvent();
			core.clearMap('uievent');
			core.ui.clearUIEventSelector();
			core.setTextAlign('uievent', 'left');
			core.setTextBaseline('uievent', 'top');
			core.fillRect('uievent', 0, 0, 416, 416, 'black');
			core.drawWindowSkin('winskin.png', 'uievent', 0, 0, 416, 56);
			core.drawWindowSkin('winskin.png', 'uievent', 0, 56, 312, 56);
			core.drawWindowSkin('winskin.png', 'uievent', 0, 112, 312, 304);
			core.drawWindowSkin('winskin.png', 'uievent', 312, 56, 104, 56);
			core.drawWindowSkin('winskin.png', 'uievent', 312, 112, 104, 304);
			core.setFillStyle('uievent', 'white');
			core.setStrokeStyle('uievent', 'white');
			core.fillText("uievent", "购买", 32, 74, 'white', bigFont);
			core.fillText("uievent", "卖出", 132, 74);
			core.fillText("uievent", "离开", 232, 74);
			core.fillText("uievent", "当前" + useText, 324, 66, null, middleFont);
			core.setTextAlign("uievent", "right");
			core.fillText("uievent", core.formatBigNumber(core.status.hero[use]), 405, 89);
			core.setTextAlign("uievent", "left");
			core.ui.drawUIEventSelector(1, "winskin.png", 22 + 100 * type, 66, 60, 33);
			if (selectItem != null) {
				core.setTextAlign('uievent', 'center');
				core.fillText("uievent", type == 0 ? "买入个数" : "卖出个数", 364, 320, null, bigFont);
				core.fillText("uievent", "<   " + selectCount + "   >", 364, 350);
				core.fillText("uievent", "确定", 364, 380);
			}

			// Step 2：获得列表并展示
			list = choices.filter(function (one) {
				if (one.condition != null && one.condition != '') {
					try { if (!core.calValue(one.condition)) return false; } catch (e) { }
				}
				return (type == 0 && one.money != null) || (type == 1 && one.sell != null);
			});
			var per_page = 6;
			totalPage = Math.ceil(list.length / per_page);
			page = Math.floor((selectItem || 0) / per_page) + 1;

			// 绘制分页
			if (totalPage > 1) {
				var half = 156;
				core.setTextAlign('uievent', 'center');
				core.fillText('uievent', page + " / " + totalPage, half, 388, null, middleFont);
				if (page > 1) core.fillText('uievent', '上一页', half - 80, 388);
				if (page < totalPage) core.fillText('uievent', '下一页', half + 80, 388);
			}
			core.setTextAlign('uievent', 'left');

			// 绘制每一项
			var start = (page - 1) * per_page;
			for (var i = 0; i < per_page; ++i) {
				var curr = start + i;
				if (curr >= list.length) break;
				var item = list[curr];
				core.drawIcon('uievent', item.id, 10, 125 + i * 40);
				core.setTextAlign('uievent', 'left');
				core.fillText('uievent', core.material.items[item.id].name, 50, 132 + i * 40, null, bigFont);
				core.setTextAlign('uievent', 'right');
				core.fillText('uievent', (type == 0 ? core.calValue(item.money) : core.calValue(item.sell)) + useText + "/个", 300, 133 + i * 40, null, middleFont);
				core.setTextAlign("uievent", "left");
				if (curr == selectItem) {
					// 绘制描述，文字自动放缩
					var text = core.material.items[item.id].text || "该道具暂无描述";
					try { text = core.replaceText(text); } catch (e) { }
					for (var fontSize = 20; fontSize >= 8; fontSize -= 2) {
						var config = { left: 10, fontSize: fontSize, maxWidth: 403 };
						var height = core.getTextContentHeight(text, config);
						if (height <= 50) {
							config.top = (56 - height) / 2;
							core.drawTextContent("uievent", text, config);
							break;
						}
					}
					core.ui.drawUIEventSelector(2, "winskin.png", 8, 120 + i * 40, 295, 40);
					if (type == 0 && item.number != null) {
						core.fillText("uievent", "存货", 324, 132, null, bigFont);
						core.setTextAlign("uievent", "right");
						core.fillText("uievent", item.number, 406, 132, null, null, 40);
					} else if (type == 1) {
						core.fillText("uievent", "数量", 324, 132, null, bigFont);
						core.setTextAlign("uievent", "right");
						core.fillText("uievent", core.itemCount(item.id), 406, 132, null, null, 40);
					}
					core.setTextAlign("uievent", "left");
					core.fillText("uievent", "预计" + useText, 324, 250);
					core.setTextAlign("uievent", "right");
					totalMoney = selectCount * (type == 0 ? core.calValue(item.money) : core.calValue(item.sell));
					core.fillText("uievent", core.formatBigNumber(totalMoney), 405, 280);

					core.setTextAlign("uievent", "left");
					core.fillText("uievent", type == 0 ? "已购次数" : "已卖次数", 324, 170);
					core.setTextAlign("uievent", "right");
					core.fillText("uievent", (type == 0 ? item.money_count : item.sell_count) || 0, 405, 200);
				}
			}

			core.setTextAlign('uievent', 'left');
			core.setTextBaseline('uievent', 'alphabetic');
		}

		var _add = function (item, delta) {
			if (item == null) return;
			selectCount = core.clamp(
				selectCount + delta, 0,
				Math.min(type == 0 ? Math.floor(core.status.hero[use] / core.calValue(item.money)) : core.itemCount(item.id),
					type == 0 && item.number != null ? item.number : Number.MAX_SAFE_INTEGER)
			);
		}

		var _confirm = function (item) {
			if (item == null || selectCount == 0) return;
			if (type == 0) {
				core.status.hero[use] -= totalMoney;
				core.getItem(item.id, selectCount);
				core.stopSound();
				core.playSound('确定');
				if (item.number != null) item.number -= selectCount;
				item.money_count = (item.money_count || 0) + selectCount;
			} else {
				core.status.hero[use] += totalMoney;
				core.removeItem(item.id, selectCount);
				core.playSound('确定');
				core.drawTip("成功卖出" + selectCount + "个" + core.material.items[item.id].name, item.id);
				if (item.number != null) item.number += selectCount;
				item.sell_count = (item.sell_count || 0) + selectCount;
			}
			selectCount = 0;
		}

		this._performItemShopKeyBoard = function (keycode) {
			var item = list[selectItem] || null;
			// 键盘操作
			switch (keycode) {
				case 38: // up
					if (selectItem == null) break;
					if (selectItem == 0) selectItem = null;
					else selectItem--;
					selectCount = 0;
					break;
				case 37: // left
					if (selectItem == null) {
						if (type > 0) type--;
						break;
					}
					_add(item, -1);
					break;
				case 39: // right
					if (selectItem == null) {
						if (type < 2) type++;
						break;
					}
					_add(item, 1);
					break;
				case 40: // down
					if (selectItem == null) {
						if (list.length > 0) selectItem = 0;
						break;
					}
					if (list.length == 0) break;
					selectItem = Math.min(selectItem + 1, list.length - 1);
					selectCount = 0;
					break;
				case 13:
				case 32: // Enter/Space
					if (selectItem == null) {
						if (type == 2)
							core.insertAction({ "type": "break" });
						else if (list.length > 0)
							selectItem = 0;
						break;
					}
					_confirm(item);
					break;
				case 27: // ESC
					if (selectItem == null) {
						core.insertAction({ "type": "break" });
						break;
					}
					selectItem = null;
					break;
			}
		}

		this._performItemShopClick = function (px, py) {
			var item = list[selectItem] || null;
			// 鼠标操作
			if (px >= 22 && px <= 82 && py >= 71 && py <= 102) {
				// 买
				if (type != 0) {
					type = 0;
					selectItem = null;
					selectCount = 0;
				}
				return;
			}
			if (px >= 122 && px <= 182 && py >= 71 && py <= 102) {
				// 卖
				if (type != 1) {
					type = 1;
					selectItem = null;
					selectCount = 0;
				}
				return;
			}
			if (px >= 222 && px <= 282 && py >= 71 && py <= 102) // 离开
				return core.insertAction({ "type": "break" });
			// < >
			if (px >= 318 && px <= 341 && py >= 348 && py <= 376)
				return _add(item, -1);
			if (px >= 388 && px <= 416 && py >= 348 && py <= 376)
				return _add(item, 1);
			// 确定
			if (px >= 341 && px <= 387 && py >= 380 && py <= 407)
				return _confirm(item);

			// 上一页/下一页
			if (px >= 45 && px <= 105 && py >= 388) {
				if (page > 1) {
					selectItem -= 6;
					selectCount = 0;
				}
				return;
			}
			if (px >= 208 && px <= 268 && py >= 388) {
				if (page < totalPage) {
					selectItem = Math.min(selectItem + 6, list.length - 1);
					selectCount = 0;
				}
				return;
			}

			// 实际区域
			if (px >= 9 && px <= 300 && py >= 120 && py < 360) {
				if (list.length == 0) return;
				var index = parseInt((py - 120) / 40);
				var newItem = 6 * (page - 1) + index;
				if (newItem >= list.length) newItem = list.length - 1;
				if (newItem != selectItem) {
					selectItem = newItem;
					selectCount = 0;
				}
				return;
			}
		}

		this._performItemShopAction = function () {
			if (flags.type == 0) return this._performItemShopKeyBoard(flags.keycode);
			else return this._performItemShopClick(flags.px, flags.py);
		}

		this.openItemShop = function (itemShopId) {
			shopId = itemShopId;
			type = 0;
			page = 0;
			selectItem = null;
			selectCount = 0;
			core.isShopVisited(itemShopId);
			shopInfo = flags.__shops__[shopId];
			if (shopInfo.choices == null) shopInfo.choices = core.clone(core.status.shops[shopId].choices);
			choices = shopInfo.choices;
			use = core.status.shops[shopId].use;
			if (use != 'exp') use = 'money';
			useText = use == 'money' ? '金币' : '经验';

			core.insertAction([{
				"type": "while",
				"condition": "true",
				"data": [
					{ "type": "function", "function": "function () { core.plugin._drawItemShop(); }" },
					{ "type": "wait" },
					{ "type": "function", "function": "function() { core.plugin._performItemShopAction(); }" }
				]
			},
			{
				"type": "function",
				"function": "function () { core.deleteCanvas('uievent'); core.ui.clearUIEventSelector(); }"
			}
			]);
		}

	},
    "enemyLevel": function () {
		// 此插件将提供怪物手册中的怪物境界显示
		// 使用此插件需要先给每个怪物定义境界，方法如下：
		// 点击怪物的【配置表格】，找到“【怪物】相关的表格配置”，然后在【名称】仿照增加境界定义：
		/*
		 "level": {
			  "_leaf": true,
			  "_type": "textarea",
			  "_string": true,
			  "_data": "境界"
		 },
		 */
		// 然后保存刷新，可以看到怪物的属性定义中出现了【境界】。再开启本插件即可。

		// 是否开启本插件，默认禁用；将此改成 true 将启用本插件。
		var __enable = false;
		if (!__enable) return;

		// 这里定义每个境界的显示颜色；可以写'red', '#RRGGBB' 或者[r,g,b,a]四元数组
		var levelToColors = {
			"萌新一阶": "red",
			"萌新二阶": "#FF0000",
			"萌新三阶": [255, 0, 0, 1],
		};

		// 复写 _drawBook_drawName
		var originDrawBook = core.ui._drawBook_drawName;
		core.ui._drawBook_drawName = function (index, enemy, top, left, width) {
			// 如果没有境界，则直接调用原始代码绘制
			if (!enemy.level) return originDrawBook.call(core.ui, index, enemy, top, left, width);
			// 存在境界，则额外进行绘制
			core.setTextAlign('ui', 'center');
			if (enemy.specialText.length == 0) {
				core.fillText('ui', enemy.name, left + width / 2,
					top + 27, '#DDDDDD', this._buildFont(17, true));
				core.fillText('ui', enemy.level, left + width / 2,
					top + 51, core.arrayToRGBA(levelToColors[enemy.level] || '#DDDDDD'), this._buildFont(14, true));
			} else {
				core.fillText('ui', enemy.name, left + width / 2,
					top + 20, '#DDDDDD', this._buildFont(17, true), width);
				switch (enemy.specialText.length) {
					case 1:
						core.fillText('ui', enemy.specialText[0], left + width / 2,
							top + 38, core.arrayToRGBA((enemy.specialColor || [])[0] || '#FF6A6A'),
							this._buildFont(14, true), width);
						break;
					case 2:
						// Step 1: 计算字体
						var text = enemy.specialText[0] + "  " + enemy.specialText[1];
						core.setFontForMaxWidth('ui', text, width, this._buildFont(14, true));
						// Step 2: 计算总宽度
						var totalWidth = core.calWidth('ui', text);
						var leftWidth = core.calWidth('ui', enemy.specialText[0]);
						var rightWidth = core.calWidth('ui', enemy.specialText[1]);
						// Step 3: 绘制
						core.fillText('ui', enemy.specialText[0], left + (width + leftWidth - totalWidth) / 2,
							top + 38, core.arrayToRGBA((enemy.specialColor || [])[0] || '#FF6A6A'));
						core.fillText('ui', enemy.specialText[1], left + (width + totalWidth - rightWidth) / 2,
							top + 38, core.arrayToRGBA((enemy.specialColor || [])[1] || '#FF6A6A'));
						break;
					default:
						core.fillText('ui', '多属性...', left + width / 2,
							top + 38, '#FF6A6A', this._buildFont(14, true), width);
				}
				core.fillText('ui', enemy.level, left + width / 2,
					top + 56, core.arrayToRGBA(levelToColors[enemy.level] || '#DDDDDD'), this._buildFont(14, true));
			}
		}

		// 也可以复写其他的属性颜色如怪物攻防等，具体参见下面的例子的注释部分
		core.ui._drawBook_drawRow1 = function (index, enemy, top, left, width, position) {
			// 绘制第一行
			core.setTextAlign('ui', 'left');
			var b13 = this._buildFont(13, true),
				f13 = this._buildFont(13, false);
			var col1 = left,
				col2 = left + width * 9 / 25,
				col3 = left + width * 17 / 25;
			core.fillText('ui', '生命', col1, position, '#DDDDDD', f13);
			core.fillText('ui', core.formatBigNumber(enemy.hp || 0), col1 + 30, position, /*'red' */ null, b13);
			core.fillText('ui', '攻击', col2, position, null, f13);
			core.fillText('ui', core.formatBigNumber(enemy.atk || 0), col2 + 30, position, /* '#FF0000' */ null, b13);
			core.fillText('ui', '防御', col3, position, null, f13);
			core.fillText('ui', core.formatBigNumber(enemy.def || 0), col3 + 30, position, /* [255, 0, 0, 1] */ null, b13);
		}
	},
    "multiHeros": function () {
		// 多角色插件
		// Step 1: 启用本插件
		// Step 2: 定义每个新的角色各项初始数据（参见下方注释）
		// Step 3: 在游戏中的任何地方都可以调用 `core.changeHero()` 进行切换；也可以 `core.changeHero(1)` 来切换到某个具体的角色上

		// 是否开启本插件，默认禁用；将此改成 true 将启用本插件。
		var __enable = false;
		if (!__enable) return;

		// 在这里定义全部的新角色属性
		// 请注意，在这里定义的内容不会多角色共用，在切换时会进行恢复。
		// 你也可以自行新增或删除，比如不共用金币则可以加上"money"的初始化，不共用道具则可以加上"items"的初始化，
		// 多角色共用hp的话则删除hp，等等。总之，不共用的属性都在这里进行定义就好。
		var hero1 = {
			"floorId": "MT0", // 该角色初始楼层ID；如果共用楼层可以注释此项
			"image": "brave.png", // 角色的行走图名称；此项必填不然会报错
			"name": "1号角色",
			"lv": 1,
			"hp": 10000, // 如果HP共用可注释此项
			"atk": 1000,
			"def": 1000,
			"mdef": 0,
			// "money": 0, // 如果要不共用金币则取消此项注释
			// "exp": 0, // 如果要不共用经验则取消此项注释
			"loc": { "x": 0, "y": 0, "direction": "up" }, // 该角色初始位置；如果共用位置可注释此项
			"items": {
				"tools": {}, // 如果共用消耗道具（含钥匙）则可注释此项
				// "constants": {}, // 如果不共用永久道具（如手册）可取消注释此项
				"equips": {}, // 如果共用在背包的装备可注释此项
			},
			"equipment": [], // 如果共用装备可注释此项；此项和上面的「共用在背包的装备」需要拥有相同状态，不然可能出现问题
		};
		// 也可以类似新增其他角色
		// 新增的角色，各项属性共用与不共用的选择必须和上面完全相同，否则可能出现问题。
		// var hero2 = { ...

		var heroCount = 2; // 包含默认角色在内总共多少个角色，该值需手动修改。

		this.initHeros = function () {
			core.setFlag("hero1", core.clone(hero1)); // 将属性值存到变量中
			// core.setFlag("hero2", core.clone(hero2)); // 更多的角色也存入变量中；每个定义的角色都需要新增一行

			// 检测是否存在装备
			if (hero1.equipment) {
				if (!hero1.items || !hero1.items.equips) {
					alert('多角色插件的equipment和道具中的equips必须拥有相同状态！');
				}
				// 存99号套装为全空
				var saveEquips = core.getFlag("saveEquips", []);
				saveEquips[99] = [];
				core.setFlag("saveEquips", saveEquips);
			} else {
				if (hero1.items && hero1.items.equips) {
					alert('多角色插件的equipment和道具中的equips必须拥有相同状态！');
				}
			}
		}

		// 在游戏开始注入initHeros
		var _startGame_setHard = core.events._startGame_setHard;
		core.events._startGame_setHard = function () {
			_startGame_setHard.call(core.events);
			core.initHeros();
		}

		// 切换角色
		// 可以使用 core.changeHero() 来切换到下一个角色
		// 也可以 core.changeHero(1) 来切换到某个角色（默认角色为0）
		this.changeHero = function (toHeroId) {
			var currHeroId = core.getFlag("heroId", 0); // 获得当前角色ID
			if (toHeroId == null) {
				toHeroId = (currHeroId + 1) % heroCount;
			}
			if (currHeroId == toHeroId) return;

			var saveList = Object.keys(hero1);

			// 保存当前内容
			var toSave = {};
			// 暂时干掉 drawTip 和 音效，避免切装时的提示
			var _drawTip = core.ui.drawTip;
			core.ui.drawTip = function () { };
			var _playSound = core.control.playSound;
			core.control.playSound = function () { }
			// 记录当前录像，因为可能存在换装问题
			core.clearRouteFolding();
			var routeLength = core.status.route.length;
			// 优先判定装备
			if (hero1.equipment) {
				core.items.quickSaveEquip(100 + currHeroId);
				core.items.quickLoadEquip(99);
			}

			saveList.forEach(function (name) {
				if (name == 'floorId') toSave[name] = core.status.floorId; // 楼层单独设置
				else if (name == 'items') {
					toSave.items = core.clone(core.status.hero.items);
					Object.keys(toSave.items).forEach(function (one) {
						if (!hero1.items[one]) delete toSave.items[one];
					});
				} else toSave[name] = core.clone(core.status.hero[name]); // 使用core.clone()来创建新对象
			});

			core.setFlag("hero" + currHeroId, toSave); // 将当前角色信息进行保存
			var data = core.getFlag("hero" + toHeroId); // 获得要切换的角色保存内容

			// 设置角色的属性值
			saveList.forEach(function (name) {
				if (name == "floorId");
				else if (name == "items") {
					Object.keys(core.status.hero.items).forEach(function (one) {
						if (data.items[one]) core.status.hero.items[one] = core.clone(data.items[one]);
					});
				} else {
					core.status.hero[name] = core.clone(data[name]);
				}
			});
			// 最后装上装备
			if (hero1.equipment) {
				core.items.quickLoadEquip(100 + toHeroId);
			}

			core.ui.drawTip = _drawTip;
			core.control.playSound = _playSound;
			core.status.route = core.status.route.slice(0, routeLength);
			core.control._bindRoutePush();

			// 插入事件：改变角色行走图并进行楼层切换
			var toFloorId = data.floorId || core.status.floorId;
			var toLoc = data.loc || core.status.hero.loc;
			core.insertAction([
				{ "type": "setHeroIcon", "name": data.image || "hero.png" }, // 改变行走图
				// 同层则用changePos，不同层则用changeFloor；这是为了避免共用楼层造成触发eachArrive
				toFloorId != core.status.floorId ? {
					"type": "changeFloor",
					"floorId": toFloorId,
					"loc": [toLoc.x, toLoc.y],
					"direction": toLoc.direction,
					"time": 0 // 可以在这里设置切换时间
				} : { "type": "changePos", "loc": [toLoc.x, toLoc.y], "direction": toLoc.direction }
				// 你还可以在这里执行其他事件，比如增加或取消跟随效果
			]);
			core.setFlag("heroId", toHeroId); // 保存切换到的角色ID
		}
	},
    "heroFourFrames": function () {
		// 样板的勇士/跟随者移动时只使用2、4两帧，观感较差。本插件可以将四帧全用上。

		// 是否启用本插件
		var __enable = true;
		if (!__enable) return;

		["up", "down", "left", "right"].forEach(function (one) {
			// 指定中间帧动画
			core.material.icons.hero[one].midFoot = 2;
		});

		var heroMoving = function (timestamp) {
			if (core.status.heroMoving <= 0) return;
			if (timestamp - core.animateFrame.moveTime > core.values.moveSpeed) {
				core.animateFrame.leftLeg++;
				core.animateFrame.moveTime = timestamp;
			}
			core.drawHero(['stop', 'leftFoot', 'midFoot', 'rightFoot'][core.animateFrame.leftLeg % 4], 4 * core.status.heroMoving);
		}
		core.registerAnimationFrame('heroMoving', true, heroMoving);

		core.events._eventMoveHero_moving = function (step, moveSteps) {
			var curr = moveSteps[0];
			var direction = curr[0], x = core.getHeroLoc('x'), y = core.getHeroLoc('y');
			// ------ 前进/后退
			var o = direction == 'backward' ? -1 : 1;
			if (direction == 'forward' || direction == 'backward') direction = core.getHeroLoc('direction');
			var faceDirection = direction;
			if (direction == 'leftup' || direction == 'leftdown') faceDirection = 'left';
			if (direction == 'rightup' || direction == 'rightdown') faceDirection = 'right';
			core.setHeroLoc('direction', direction);
			if (curr[1] <= 0) {
				core.setHeroLoc('direction', faceDirection);
				moveSteps.shift();
				return true;
			}
			if (step <= 4) core.drawHero('stop', 4 * o * step);
			else if (step <= 8) core.drawHero('leftFoot', 4 * o * step);
			else if (step <= 12) core.drawHero('midFoot', 4 * o * (step - 8));
			else if (step <= 16) core.drawHero('rightFoot', 4 * o * (step - 8)); // if (step == 8) {
			if (step == 8 || step == 16) {
				core.setHeroLoc('x', x + o * core.utils.scan2[direction].x, true);
				core.setHeroLoc('y', y + o * core.utils.scan2[direction].y, true);
				core.updateFollowers();
				curr[1]--;
				if (curr[1] <= 0) moveSteps.shift();
				core.setHeroLoc('direction', faceDirection);
				return step == 16;
			}
			return false;
		}
	},
    "routeFixing": function () {
		// 是否开启本插件，true 表示启用，false 表示禁用。
		var __enable = true;
		if (!__enable) return;
		/*
		 使用说明：启用本插件后，录像回放时您可以用数字键1或6分别切换到原速或24倍速，
		 暂停播放时按数字键7（电脑按N）可以单步播放。（手机端可以点击难度单词切换出数字键）
		 数字键2-5可以进行录像自助精修，具体描述见下（实际弹窗请求您输入时不要带有任何空格）：
		 
		 up down left right 勇士向某个方向「行走一步或撞击」
		 item:ID 使用某件道具，如 item:bomb 表示使用炸弹
		 unEquip:n 卸掉身上第(n+1)件装备（n从0开始），如 unEquip:1 默认表示卸掉盾牌
		 equip:ID 穿上某件装备，如 equip:sword1 表示装上铁剑
		 saveEquip:n 将身上的当前套装保存到第n套快捷套装（n从0开始）
		 loadEquip:n 快捷换上之前保存好的第n套套装
		 fly:ID 使用楼传飞到某一层，如 fly:MT10 表示飞到主塔10层
		 choices:none 确认框/选择项「超时」（作者未设置超时时间则此项视为缺失）
		 choices:n 确认框/选择项选择第(n+1)项（选择项n从0开始，确认框n为0表示「确定」，1表示「取消」）
		 选择项n为负数时表示选择倒数第 -n 项，如 -1 表示最后一项（V2.8.2起标准全局商店的「离开」项）
		 此项缺失的话，确认框将选择作者指定的默认项（初始光标位置），选择项将弹窗请求补选（后台录像验证中选最后一项，可以复写函数来修改）
		 shop:ID 打开某个全局商店，如 shop:itemShop 表示打开道具商店。因此连载塔千万不要中途修改商店ID！
		 turn 单击勇士（Z键）转身，core.turnHero() 会产生此项，因此通过事件等方式强制让勇士转向应该用 core.setHeroLoc()
		 turn:dir 勇士转向某个方向，dir 可以为 up down left right（此项一般是读取自动存档产生的，属于样板的不良特性，请勿滥用）
		 getNext 轻按获得身边道具，优先获得面前的（面前没有则按上下左右顺序依次获得），身边如果没有道具则此项会被跳过
		 input:none “等待用户操作事件”中超时（作者未设置超时时间则此项会导致报错）
		 input:xxx 可能表示“等待用户操作事件”的一个操作（如按键操作将直接记录 input:keycode ），
		 也可能表示一个“接受用户输入数字”的输入，后者的情况下 xxx 为输入的整数。此项缺失的话前者将直接报错，后者将用0代替（后者现在支持负数了）
		 input2:xxx 可能表示“读取全局存储（core.getGlobal）”读取到的值，也可能表示一个“接受用户输入文本”的输入，
		 两种情况下 xxx 都为 base64 编码。此项缺失的话前者将重新现场读取，后者将用空字符串代替
		 no 走到可穿透的楼梯上不触发楼层切换事件，通过本插件可以让勇士停在旁边没有障碍物的楼梯上哦～
		 move:x:y 尝试瞬移到 [x,y] 点（不改变朝向），该点甚至可以和勇士相邻或者位于视野外
		 key:n 松开键值为n的键，如 key:49 表示松开大键盘数字键1，默认会触发使用破墙镐
		 click:n:px:py 点击自绘状态栏，n为0表示横屏1表示竖屏，[px,py] 为点击的像素坐标
		 random:n 生成了随机数n，即 core.rand2(num) 的返回结果，n必须在 [0,num-1] 范围，num必须为正整数。此项缺失将导致现场重新随机生成数值，可能导致回放结果不一致！
		 作者自定义的新项（一般为js对象，可以先JSON.stringify()再core.encodeBase64()得到纯英文数字的内容）需要用(半角圆括弧)括起来。
		 
		 当您使用数字键5将一些项追加到即将播放内容的开头时，请注意要逆序逐项追加，或者每追加一项就按下数字键7或字母键N单步播放一步。
		 但是【input input2 random choices】是被动读取的，单步播放如果触发了相应的事件就会连续读取，这时候只能提前逐项追加好。
		 电脑端熟练以后推荐直接在控制台操作 core.status.route 和 core.status.replay.toReplay（后者录像回放时才有），配合 core.push() 和 core.unshift() 更加灵活自由哦！
		 */
		core.actions.registerAction('onkeyUp', '_sys_onkeyUp_replay', function (e) {
			if (this._checkReplaying()) {
				if (e.keyCode == 27) // ESCAPE
					core.stopReplay();
				else if (e.keyCode == 90) // Z
					core.speedDownReplay();
				else if (e.keyCode == 67) // C
					core.speedUpReplay();
				else if (e.keyCode == 32) // SPACE
					core.triggerReplay();
				else if (e.keyCode == 65) // A
					core.rewindReplay();
				else if (e.keyCode == 83) // S
					core.control._replay_SL();
				else if (e.keyCode == 88) // X
					core.control._replay_book();
				else if (e.keyCode == 33 || e.keyCode == 34) // PgUp/PgDn
					core.control._replay_viewMap();
				else if (e.keyCode == 78) // N
					core.stepReplay();
				else if (e.keyCode == 84) // T
					core.control._replay_toolbox();
				else if (e.keyCode == 81) // Q
					core.control._replay_equipbox();
				else if (e.keyCode == 66) // B
					core.ui._drawStatistics();
				else if (e.keyCode == 49 || e.keyCode == 54) // 1/6，原速/24倍速播放
					core.setReplaySpeed(e.keyCode == 49 ? 1 : 24);
				else if (e.keyCode > 49 && e.keyCode < 54) { // 2-5，录像精修
					switch (e.keyCode - 48) {
						case 2: // pop
							alert("您已移除已录制内容的最后一项：" + core.status.route.pop());
							break;
						case 3: // push
							core.utils.myprompt("请输入您要追加到已录制内容末尾的项：", "", function (value) {
								if (value != null) core.status.route.push(value);
							});
							break;
						case 4: // shift
							alert("您已移除即将播放内容的第一项：" + core.status.replay.toReplay.shift());
							break;
						case 5: // unshift
							core.utils.myprompt("请输入您要追加到即将播放内容开头的项：", "", function (value) {
								if (value != null) core.status.replay.toReplay.unshift(value);
							});
					}
				}
				return true;
			}
		}, 100);
	},
    "numpad": function () {
		// 样板自带的整数输入事件为白屏弹窗且可以误输入任意非法内容但不支持负整数，观感较差。本插件可以将其美化成仿RM样式，使其支持负整数同时带有音效
		// 另一方面，4399等第三方平台不允许使用包括 core.myprompt() 和 core.myconfirm() 在内的弹窗，因此也需要此插件来替代，不然类似生命魔杖的道具就不好实现了
		// 关于负整数输入，V2.8.2原生支持其录像的压缩和解压，只是默认的 core.events._action_input() 函数将负数取了绝对值，可以只复写下面的 core.isReplaying() 部分来取消

		// 是否启用本插件，false表示禁用，true表示启用
		var __enable = true;
		if (!__enable) return;

		core.events._action_input = function (data, x, y, prefix) { // 复写整数输入事件
			if (core.isReplaying()) { // 录像回放时，处理方式不变，但增加负整数支持
				core.events.__action_getInput(core.replaceText(data.text, prefix), false, function (value) {
					value = parseInt(value) || 0; // 去掉了取绝对值的步骤
					core.status.route.push("input:" + value);
					core.setFlag("input", value);
					core.doAction();
				});
			} else {
				// 正常游戏中，采用暂停录制的方式然后用事件流循环“绘制-等待-变量操作”三板斧实现（按照13*13适配的）。
				// 您可以自行修改循环内的内容来适配15*15或其他需求，或干脆作为公共事件编辑。
				core.insertAction([
					// 记录当前录像长度，下面的循环结束后裁剪。达到“暂停录制”的效果
					{ "type": "function", "function": "function(){flags['@temp@length']=core.status.route.length}" },
					{ "type": "setValue", "name": "flag:input", "value": "0" },
					{
						"type": "while",
						"condition": "true",
						"data": [
							{ "type": "drawBackground", "background": "winskin.png", "x": 16, "y": 16, "width": 384, "height": 384 },
							{ "type": "drawIcon", "id": "X10181", "x": 32, "y": 288 },
							{ "type": "drawIcon", "id": "X10185", "x": 64, "y": 288 },
							{ "type": "drawIcon", "id": "X10186", "x": 96, "y": 288 },
							{ "type": "drawIcon", "id": "X10187", "x": 128, "y": 288 },
							{ "type": "drawIcon", "id": "X10188", "x": 160, "y": 288 },
							{ "type": "drawIcon", "id": "X10189", "x": 192, "y": 288 },
							{ "type": "drawIcon", "id": "X10193", "x": 224, "y": 288 },
							{ "type": "drawIcon", "id": "X10194", "x": 256, "y": 288 },
							{ "type": "drawIcon", "id": "X10195", "x": 288, "y": 288 },
							{ "type": "drawIcon", "id": "X10196", "x": 320, "y": 288 },
							{ "type": "drawIcon", "id": "X10197", "x": 352, "y": 288 },
							{ "type": "drawIcon", "id": "X10286", "x": 32, "y": 352 },
							{ "type": "drawIcon", "id": "X10169", "x": 96, "y": 352 },
							{ "type": "drawIcon", "id": "X10232", "x": 128, "y": 352 },
							{ "type": "drawIcon", "id": "X10185", "x": 320, "y": 352 },
							{ "type": "drawIcon", "id": "X10242", "x": 352, "y": 352 },
							{ "type": "fillBoldText", "x": 48, "y": 256, "style": [255, 255, 255, 1], "font": "bold 32px Consolas", "text": "${flag:input}" },
							{ "type": "fillBoldText", "x": 32, "y": 48, "style": [255, 255, 255, 1], "font": "16px Consolas", "text": core.replaceText(data.text, prefix) },
							{
								"type": "wait",
								"forceChild": true,
								"data": [{
									"case": "keyboard",
									"keycode": "48,49,50,51,52,53,54,55,56,57",
									"action": [
										// 按下数字键，追加到已输入内容的末尾，但禁止越界。变量：keycode-48就是末位数字
										{ "type": "playSound", "name": "光标移动" },
										{
											"type": "if",
											"condition": "(flag:input<0)",
											"true": [
												{ "type": "setValue", "name": "flag:input", "value": "10*flag:input-(flag:keycode-48)" },
											],
											"false": [
												{ "type": "setValue", "name": "flag:input", "value": "10*flag:input+(flag:keycode-48)" },
											]
										},
										{ "type": "setValue", "name": "flag:input", "value": "core.clamp(flag:input,-9e15,9e15)" },
									]
								},
								{
									"case": "keyboard",
									"keycode": "189",
									"action": [
										// 按下减号键，变更已输入内容的符号
										{ "type": "playSound", "name": "跳跃" },
										{ "type": "setValue", "name": "flag:input", "value": "-flag:input" },
									]
								},
								{
									"case": "keyboard",
									"keycode": "8",
									"action": [
										// 按下退格键，从已输入内容的末尾删除一位
										{ "type": "playSound", "name": "取消" },
										{ "type": "setValue", "name": "flag:input", "operator": "//=", "value": "10" },
									]
								},
								{
									"case": "keyboard",
									"keycode": "27",
									"action": [
										// 按下ESC键，清空已输入内容
										{ "type": "playSound", "name": "读档" },
										{ "type": "setValue", "name": "flag:input", "value": "0" },
									]
								},
								{
									"case": "keyboard",
									"keycode": "13",
									"action": [
										// 按下回车键，确定
										{ "type": "break", "n": 1 },
									]
								},
								{
									"case": "mouse",
									"px": [32, 63],
									"py": [288, 320],
									"action": [
										// 点击减号，变号。右边界写63防止和下面重叠
										{ "type": "playSound", "name": "跳跃" },
										{ "type": "setValue", "name": "flag:input", "value": "-flag:input" },
									]
								},
								{
									"case": "mouse",
									"px": [64, 384],
									"py": [288, 320],
									"action": [
										// 点击数字，追加到已输入内容的末尾，但禁止越界。变量：x-2就是末位数字
										{ "type": "playSound", "name": "光标移动" },
										{
											"type": "if",
											"condition": "(flag:input<0)",
											"true": [
												{ "type": "setValue", "name": "flag:input", "value": "10*flag:input-(flag:x-2)" },
											],
											"false": [
												{ "type": "setValue", "name": "flag:input", "value": "10*flag:input+(flag:x-2)" },
											]
										},
										{ "type": "setValue", "name": "flag:input", "value": "core.clamp(flag:input,-9e15,9e15)" },
									]
								},
								{
									"case": "mouse",
									"px": [32, 64],
									"py": [352, 384],
									"action": [
										// 点击左箭头，退格
										{ "type": "playSound", "name": "取消" },
										{ "type": "setValue", "name": "flag:input", "operator": "//=", "value": "10" },
									]
								},
								{
									"case": "mouse",
									"px": [96, 160],
									"py": [352, 384],
									"action": [
										// 点击CE，清空
										{ "type": "playSound", "name": "读档" },
										{ "type": "setValue", "name": "flag:input", "value": "0" },
									]
								},
								{
									"case": "mouse",
									"px": [320, 384],
									"py": [352, 384],
									"action": [
										// 点击OK，确定
										{ "type": "break", "n": 1 },
									]
								}
								]
							}
						]
					},
					{ "type": "clearMap" },
					// 裁剪录像，只保留'input:n'，然后继续录制
					{ "type": "function", "function": "function(){core.status.route.splice(flags['@temp@length']);core.status.route.push('input:'+core.getFlag('input',0))}" }
				], x, y);
				core.events.doAction();
			}
		}
	},
    "sprites": function () {
		// 基于canvas的sprite化，摘编整理自万宁魔塔
		// 
		// ---------------------------------------- 第一部分 js代码 （必装） --------------------------------------- //

		/* ---------------- 用法说明 ---------------- *
		 * 1. 创建sprite: var sprite = new Sprite(x, y, w, h, z, reference, name);
		 *   其中x y w h为画布的横纵坐标及长宽，reference为参考系，只能填game（相对于游戏画面）和window（相对于窗口）
		 *   且当为相对游戏画面时，长宽与坐标将会乘以放缩比例（相当于用createCanvas创建）
		 *   z为纵深，表示不同元素之间的覆盖关系，大的覆盖小的
		 *   name为自定义名称，可以不填
		 * 2. 删除: sprite.destroy();
		 * 3. 设置css特效: sprite.setCss(css);
		 *   其中css直接填 box-shadow: 0px 0px 10px black;的形式即可，与style标签与css文件内写法相同
		 *   对于已设置的特效，如果之后不需要再次设置，可以不填
		 * 4. 添加事件监听器: sprite.addEventListener(); 用法与html元素的addEventListener完全一致
		 * 5. 移除事件监听器: sprite.removeEventListener(); 用法与html元素的removeEventListener完全一致
		 * 6. 属性列表
		 *   (1) sprite.x | sprite.y | sprite.width | sprite.height | sprite.zIndex | sprite.reference 顾名思义
		 *   (2) sprite.canvas 该sprite的画布
		 *   (3) sprite.context 该画布的CanvasRenderingContext2d对象，即样板中常见的ctx
		 *   (4) sprite.count 不要改这个玩意
		 * 7. 使用样板api进行绘制
		 *   示例：
		 *   var ctx = sprite.context;
		 *   core.fillText(ctx, 'xxx', 100, 100);
		 *   core.fillRect(ctx, 0, 0, 50, 50);
		 *   当然也可以使用原生js
		 *   ctx.moveTo(0, 0);
		 *   ctx.bezierCurveTo(50, 50, 100, 0, 100, 50);
		 *   ctx.stroke();
		 * ---------------- 用法说明 ---------------- */

		var count = 0;

		/** 创建一个sprite画布
		 * @param {number} x
		 * @param {number} y
		 * @param {number} w
		 * @param {number} h
		 * @param {number} z
		 * @param {'game' | 'window'} reference 参考系，游戏画面或者窗口
		 * @param {string} name 可选，sprite的名称，方便通过core.dymCanvas获取
		 */
		function Sprite (x, y, w, h, z, reference, name) {
			this.x = x;
			this.y = y;
			this.width = w;
			this.height = h;
			this.zIndex = z;
			this.reference = reference;
			this.canvas = null;
			this.context = null;
			this.count = 0;
			this.name = name || '_sprite_' + count;
			this.style = null;
			/** 初始化 */
			this.init = function () {
				if (reference === 'window') {
					var canvas = document.createElement('canvas');
					this.canvas = canvas;
					this.context = canvas.getContext('2d');
					canvas.width = w;
					canvas.height = h;
					canvas.style.width = w + 'px';
					canvas.style.height = h + 'px';
					canvas.style.position = 'absolute';
					canvas.style.top = y + 'px';
					canvas.style.left = x + 'px';
					canvas.style.zIndex = z.toString();
					document.body.appendChild(canvas);
					this.style = canvas.style;
				} else {
					this.context = core.createCanvas(this.name || '_sprite_' + count, x, y, w, h, z);
					this.canvas = this.context.canvas;
					this.canvas.style.pointerEvents = 'auto';
					this.style = this.canvas.style;
				}
				this.count = count;
				count++;
			}
			this.init();

			/** 设置css特效
			 * @param {string} css
			 */
			this.setCss = function (css) {
				css = css.replace('\n', ';').replace(';;', ';');
				var effects = css.split(';');
				var self = this;
				effects.forEach(function (v) {
					var content = v.split(':');
					var name = content[0];
					var value = content[1];
					name = name.trim().split('-').reduce(function (pre, curr, i, a) {
						if (i === 0 && curr !== '') return curr;
						if (a[0] === '' && i === 1) return curr;
						return pre + curr.toUpperCase()[0] + curr.slice(1);
					}, '');
					var canvas = self.canvas;
					if (name in canvas.style) canvas.style[name] = value;
				});
				return this;
			}

			/** 
			 * 移动sprite
			 * @param {boolean} isDelta 是否是相对位置，如果是，那么sprite会相对于原先的位置进行移动
			 */
			this.move = function (x, y, isDelta) {
				if (x !== undefined && x !== null) this.x = x;
				if (y !== undefined && y !== null) this.y = y;
				if (this.reference === 'window') {
					var ele = this.canvas;
					ele.style.left = x + (isDelta ? parseFloat(ele.style.left) : 0) + 'px';
					ele.style.top = y + (isDelta ? parseFloat(ele.style.top) : 0) + 'px';
				} else core.relocateCanvas(this.context, x, y, isDelta);
				return this;
			}

			/** 
			 * 重新设置sprite的大小
			 * @param {boolean} styleOnly 是否只修改css效果，如果是，那么将会不高清，如果不是，那么会清空画布
			 */
			this.resize = function (w, h, styleOnly) {
				if (w !== undefined && w !== null) this.w = w;
				if (h !== undefined && h !== null) this.h = h;
				if (reference === 'window') {
					var ele = this.canvas;
					ele.style.width = w + 'px';
					ele.style.height = h + 'px';
					if (!styleOnly) {
						ele.width = w;
						ele.height = h;
					}
				} else core.resizeCanvas(this.context, w, h, styleOnly);
				return this;
			}

			/**
			 * 旋转画布
			 */
			this.rotate = function (angle, cx, cy) {
				if (this.reference === 'window') {
					var left = this.x;
					var top = this.y;
					this.canvas.style.transformOrigin = (cx - left) + 'px ' + (cy - top) + 'px';
					if (angle === 0) {
						canvas.style.transform = '';
					} else {
						canvas.style.transform = 'rotate(' + angle + 'deg)';
					}
				} else {
					core.rotateCanvas(this.context, angle, cx, cy);
				}
				return this;
			}

			/**
			 * 清除sprite
			 */
			this.clear = function (x, y, w, h) {
				if (this.reference === 'window') {
					this.context.clearRect(x, y, w, h);
				} else {
					core.clearMap(this.context, x, y, w, h);
				}
				return this;
			}

			/** 删除 */
			this.destroy = function () {
				if (this.reference === 'window') {
					if (this.canvas) document.body.removeChild(this.canvas);
				} else {
					core.deleteCanvas(this.name || '_sprite_' + this.count);
				}
			}

			/** 添加事件监听器 */
			this.addEventListener = function () {
				this.canvas.addEventListener.apply(this.canvas, arguments);
			}

			/** 移除事件监听器 */
			this.removeEventListener = function () {
				this.canvas.removeEventListener.apply(this.canvas, arguments);
			}
		}

		window.Sprite = Sprite;
	},
    "hotReload": function () {
		/* ---------- 功能说明 ---------- *

		1. 当 libs/ main.js index.html 中的任意一个文件被更改后，会自动刷新塔的页面
		2. 修改楼层文件后自动在塔的页面上显示出来，不需要刷新
		3. 修改脚本编辑或插件编写后也能自动更新更改的插件或脚本，但不保证不会出问题（一般都不会有问题的
		4. 修改图块属性、怪物属性等后会自动更新
		5. 当全塔属性被修改时，会自动刷新塔的页面
		6. 样板的 styles.css 被修改后也可以直接显示，不需要刷新
		7. 其余内容修改后不会自动更新也不会刷新

		/* ---------- 使用方式 ---------- *

		1. 前往 https://nodejs.org/en/ 下载node.js的LTS版本（点左边那个绿色按钮）并安装
		2. 将该插件复制到插件编写中
		3. 在造塔群的群文件-魔塔样板·改中找到server.js，下载并放到塔的根目录（与启动服务同一级）
		4. 在该目录下按下shift+鼠标右键（win11只按右键即可），选择在终端打开或在powershell打开
		5. 运行node server.js即可

		*/

		if (main.mode !== 'play' || main.replayChecking) return;

		/**
		 * 发送请求
		 * @param {string} url
		 * @param {string} type
		 * @param {string} data
		 * @returns {Promise<string>}
		 */
		async function post(url, type, data) {
			const xhr = new XMLHttpRequest();
			xhr.open(type, url);
			xhr.send(data);
			const res = await new Promise(res => {
				xhr.onload = e => {
					if (xhr.status !== 200) {
						console.error(`hot reload: http ${xhr.status}`);
						res('@error');
					} else res('success');
				};
				xhr.onerror = e => {
					res('@error');
					console.error(`hot reload: error on connection`);
				};
			});
			if (res === 'success') return xhr.response;
			else return '@error';
		}

		/**
		 * 热重载css
		 * @param {string} data
		 */
		function reloadCss(data) {
			const all = Array.from(document.getElementsByTagName('link'));
			all.forEach(v => {
				if (v.rel !== 'stylesheet') return;
				if (v.href === `http://127.0.0.1:3000/${data}`) {
					v.remove();
					const link = document.createElement('link');
					link.rel = 'stylesheet';
					link.type = 'text/css';
					link.href = data;
					document.head.appendChild(link);
					console.log(`css hot reload: ${data}`);
				}
			});
		}

		/**
		 * 热重载楼层
		 * @param {string} data
		 */
		async function reloadFloor(data) {
			// 首先重新加载main.floors对应的楼层
			await import(`/project/floors/${data}.js?v=${Date.now()}`);
			// 然后写入core.floors并解析
			core.floors[data] = main.floors[data];
			const floor = core.loadFloor(data);
			if (core.isPlaying()) {
				core.status.maps[data] = floor;
				delete core.status.mapBlockObjs[data];
				core.extractBlocks(data);
				if (data === core.status.floorId) {
					core.drawMap(data);
					core.setWeather(
						core.animateFrame.weather.type,
						core.animateFrame.weather.level
					);
				}
				core.updateStatusBar(true, true);
			}
			console.log(`floor hot reload: ${data}`);
		}

		/**
		 * 热重载脚本编辑及插件编写
		 * @param {string} data
		 */
		async function reloadScript(data) {
			if (data === 'plugins') {
				// 插件编写比较好办
				const before = plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1;
				// 这里不能用动态导入，因为动态导入会变成模块，变量就不是全局的了
				const script = document.createElement('script');
				script.src = `/project/plugins.js?v=${Date.now()}`;
				document.body.appendChild(script);
				await new Promise(res => {
					script.onload = () => res('success');
				});
				const after = plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1;
				// 找到差异的函数
				for (const id in before) {
					const fn = before[id];
					if (typeof fn !== 'function') continue;
					if (fn.toString() !== after[id]?.toString()) {
						try {
							core.plugin[id] = after[id];
							core.plugin[id].call(core.plugin);
							core.updateStatusBar(true, true);
							console.log(`plugin hot reload: ${id}`);
						} catch (e) {
							console.error(e);
						}
					}
				}
			} else if (data === 'functions') {
				// 脚本编辑略微麻烦点
				const before = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a;
				// 这里不能用动态导入，因为动态导入会变成模块，变量就不是全局的了
				const script = document.createElement('script');
				script.src = `/project/functions.js?v=${Date.now()}`;
				document.body.appendChild(script);
				await new Promise(res => {
					script.onload = () => res('success');
				});
				const after = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a;
				// 找到差异的函数
				for (const mod in before) {
					const fns = before[mod];
					for (const id in fns) {
						const fn = fns[id];
						if (typeof fn !== 'function' || id === 'hasSpecial')
							continue;
						const now = after[mod][id];
						if (fn.toString() !== now.toString()) {
							try {
								if (mod === 'events') {
									core.events.eventdata[id] = now;
								} else if (mod === 'enemys') {
									core.enemys.enemydata[id] = now;
								} else if (mod === 'actions') {
									core.actions.actionsdata[id] = now;
								} else if (mod === 'control') {
									core.control.controldata[id] = now;
								} else if (mod === 'ui') {
									core.ui.uidata[id] = now;
								}
								core.updateStatusBar(true, true);
								console.log(
									`function hot reload: ${mod}.${id}`
								);
							} catch (e) {
								console.error(e);
							}
						}
					}
				}
			}
		}

		/**
		 * 属性热重载，包括全塔属性等
		 * @param {string} data
		 */
		async function reloadData(data) {
			const script = document.createElement('script');
			script.src = `/project/${data}.js?v=${Date.now()}`;
			document.body.appendChild(script);
			await new Promise(res => {
				script.onload = () => res('success');
			});

			let after;
			if (data === 'data')
				after = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d;
			if (data === 'enemys')
				after = enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80;
			if (data === 'icons')
				after = icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1;
			if (data === 'items')
				after = items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a;
			if (data === 'maps')
				after = maps_90f36752_8815_4be8_b32b_d7fad1d0542e;
			if (data === 'events')
				after = events_c12a15a8_c380_4b28_8144_256cba95f760;

			if (data === 'enemys') {
				core.enemys.enemys = after;
				for (var enemyId in after) {
					core.enemys.enemys[enemyId].id = enemyId;
				}
				core.material.enemys = core.getEnemys();
			} else if (data === 'icons') {
				core.icons.icons = after;
				core.material.icons = core.getIcons();
			} else if (data === 'items') {
				core.items.items = after;
				for (var itemId in after) {
					core.items.items[itemId].id = itemId;
				}
				core.material.items = core.getItems();
			} else if (data === 'maps') {
				core.maps.blocksInfo = after;
				core.status.mapBlockObjs = {};
				core.status.number2block = {};
				Object.values(core.status.maps).forEach(v => delete v.blocks);
				core.extractBlocks();
				core.setWeather(
					core.animateFrame.weather.type,
					core.animateFrame.weather.level
				);
				core.drawMap();
			} else if (data === 'events') {
				core.events.commonEvent = after.commonEvent;
			} else if (data === 'data') {
				location.reload();
			}
			core.updateStatusBar(true, true);
			console.log(`data hot reload: ${data}`);
		}

		// 初始化
		(async function () {
			const data = await post('/reload', 'POST', 'test');
			if (data === '@error') {
				console.log(`未检测到node服务，热重载插件将无法使用`);
			} else {
				console.log(`热重载插件加载成功`);
				// reload
				setInterval(async () => {
					const res = await post('/reload', 'POST');
					if (res === '@error') return;
					if (res === 'true') location.reload();
					else return;
				}, 1000);

				// hot reload
				setInterval(async () => {
					const res = await post('/hotReload', 'POST');
					const data = res.split('@@');
					data.forEach(v => {
						if (v === '') return;
						const [type, file] = v.split(':');
						if (type === 'css') reloadCss(file);
						if (type === 'data') reloadData(file);
						if (type === 'floor') reloadFloor(file);
						if (type === 'script') reloadScript(file);
					});
				}, 1000);
			}
		})();
	},
    "skill": function () {

	this._init = function () { //初始化数据，包括道具、技能等
		core.setFlag('MT9D1', 0);
		core.setFlag('MT13expShop', false);
		core.setFlag('goldShopMdef', 0);
		core.setFlag('autoGem', false);
		core.setFlag('autoEnemy', false);
		core.setFlag('tryQingS', 0);
		core.setFlag('tryGuanX', 0);
		core.setFlag('discount1', 0);
		core.setFlag('discount2', 0);
		core.setFlag('buyFly', 0);
		core.setFlag('exempt', 0);
		core.setFlag('star', 0);
		core.setFlag('superPickaxe', 0);
		core.setFlag('skills', { guanX: 0, qingS: 0, qiX: 0 });
		core.setFlag('select', { x: -1, y: -1, blockId: null });
		core.setFlag('hp', {});
		core.setFlag('guanX', { status: 'select', loc: [], selected: [] });
		let qingS = {};
		for (let i in core.floorIds) {
			qingS[core.floorIds[i]] = { valid: true, enemys: [] };
		}
		core.setFlag('qingS', qingS);
		core.addItem('book', 1);
		core.addItem('fly', 1);
		core.addItem('greenKey', 1);
		core.addItem('setting', 1);
		try {
			core.updateStatusBar();
		} catch (e) {
			console.log('注意：未能刷新状态栏')
		}
		//增加详细数据统计
		core.status.hero.statistics.zeroDamage = 0;
		core.status.hero.statistics.thrDamage = 0;
		core.status.hero.statistics.hunDamage = 0;
		core.status.hero.statistics.bigDamage = 0;
		core.status.hero.statistics.maxDamage = { damage: 0, id: '' };
	}

	//情势对阻击怪造成伤害后，触发阻击需要修改对应flags.hp
	//由于自动清理也需要修改core.control._checkBlock_repulse，合并到自动清理插件中 

	this.drawQingS = function () {
		let loc = core.getFlag('tmp_loc', []),
			select = core.getFlag('tmp_select', { x: -1, y: -1 });

		core.clearMap('skillCanvas');
		core.setAlpha('skillCanvas', 0.5);
		core.fillRect('skillCanvas', 0, 0, 416, 416, "#444444"); //绘制一个灰色半透明背景层
		core.setAlpha('skillCanvas', 1);

		for (let i in loc) {
			core.clearMap('skillCanvas', loc[i].x * 32, loc[i].y * 32, 32, 32); //将灰色的背景擦掉
		}
		if (select.x > 0 && select.x < 12 && select.y > 0 && select.y < 12) { //绘制选中的图块
			core.strokeRect('skillCanvas', select.x * 32, select.y * 32, 32, 32, '#CC5533', 4);
		}
	}

	this.processQingS = function () {
		let x = flags.x,
			y = flags.y,
			loc = core.getFlag('tmp_loc', []),
			select = core.getFlag('tmp_select', { x: -1, y: -1 });

		if (flags.type === 0) { //按键盘，无视
			return;
		}

		if (select.x == x && select.y == y) { //如果点击了高亮区域，那么发动技能的二选项
			let hp = core.getFlag('hp', {}); //类似火计，计入伤害
			if (!hp[core.status.floorId]) {
				hp[core.status.floorId] = new Array(13).fill(0).map(() => {
					return new Array(13).fill(0);
				}); //如果没有对应楼层的记录，则创建一个空白记录；
			}
			hp[core.status.floorId][x][y] += Math.floor(core.status.hero.atk * 1.5); //伤害值=攻击力*1.5

			let floorId = core.status.floorId,
				enemyId = core.getBlock(x, y, floorId).event.id,
				special = core.getEnemyValue(enemyId, 'special', x, y, floorId);
			if (core.hasSpecial(special, 3)) hp[core.status.floorId][x][y] -= Math.floor(core.status.hero.atk * 1.5) - 1; //坚固怪只受到1点伤害

			core.setFlag('hp', hp);
			core.removeFlag('tmp_select');
			core.insertAction({ "type": "break" });
			return;
		}

		for (let i in loc) {
			if (loc[i].x == x && loc[i].y == y) { //如果点击了合法区域
				select = { x: x, y: y }; //重新设置高亮坐标
				core.setFlag("tmp_select", select);
				return;
			}
		}
		//点击其他位置一律无视
	}

	this.doQingS = function (enemyId, x, y, floorId) { //对一名其他敌人造成伤害
		let loc = [];
		for (let i = 1; i < 12; i++) {
			for (let j = 1; j < 12; j++) {
				if (x == i && y == j) continue; //跳过当前位置
				let id = core.getBlockId(i, j),
					cls = core.getBlockCls(i, j);
				if (cls && cls == 'enemys' && ['bowman', 'purpleBowman'].indexOf(id) == -1) { //记录所有其他敌人的位置，除无视技能的
					loc.push({ x: i, y: j });
				}
			}
		}

		core.setFlag('tmp_loc', loc);
		core.createCanvas('skillCanvas', 0, 0, 416, 416, 150);

		//等待玩家点击图块
		core.insertAction([{
				"type": "while",
				"condition": "true",
				"data": [
					{ "type": "function", "function": "function(){\ncore.plugin.drawQingS();\n}" },
					{ "type": "wait" },
					{ "type": "function", "function": "function(){\ncore.plugin.processQingS();\n}" },
				],
			},
			{ "type": "function", "function": "function(){\ncore.clearMap('skillCanvas'); core.deleteCanvas('skillCanvas'); core.status.hero.flags.select = { x: -1, y: -1, blockId: null }\n}" },
		]);
	}

	this.qingS = function (enemyId, x, y, floorId) { //情势
		let qingS = core.getFlag('qingS', {});
		if (!qingS[floorId].valid || qingS[floorId].enemys.indexOf(enemyId) != -1) return; //本楼层情势失效/本楼层中已对该敌人发动过情势的话，直接返回
		for (let i = 0; i <= 12; i++) {
			for (let j = 0; j <= 12; j++) {
				if (x == i && y == j) continue; //跳过当前敌人
				let blockId = core.getBlockId(i, j);
				if (enemyId == blockId) { //检测到同名敌人
					qingS[floorId].enemys.push(enemyId); //记录敌人名称；如果不发动，则再删去此记录
					let todo = [];
					core.setFlag('fSize', 12);
					todo.push({
						"type": "choices",
						"text": "你满足了技能情势的发动条件，请选择一项",
						"choices": [{
								"text": "本次战斗中，你造成的伤害+" + (core.status.hero.lv * 5 || 5) + "(等级×5)",
								"need": "(flags.must_extra_dmg || !flags.must_extra_ad) && (core.status.floorId !== 'EX1' || flags.ex1)",
								"action": [
									{ "type": "setValue", "name": "flag:extra_dmg", "value": (core.status.hero.lv * 5 || 5) },
								]
							},
							{
								"text": "对本楼层一名其他敌人造成" + Math.floor(core.status.hero.atk * 1.5) + "点伤害(攻击力×1.5)",
								"need": "!flags.must_extra_dmg && !flags.must_extra_ad",
								"action": [
									{ "type": "function", "function": "function(){\ncore.plugin.doQingS(\'" + enemyId + "\'," + x + "," + y + ", \'" + floorId + "\');\n}" },
								]
							},
							{
								"text": "获得" + Math.min(5, Math.ceil(core.status.hero.lv * 0.35)) + "点攻防，然后情势在本层失效(等级×0.35，上整且至多为5)",
								"need": "(!flags.must_extra_dmg || flags.must_extra_ad) && (core.status.floorId !== 'EX1' || flags.ex1)",
								"action": [
									{ "type": "setValue", "name": "status:atk", "operator": "+=", "value": Math.min(5, Math.ceil(core.status.hero.lv * 0.35)) },
									{ "type": "setValue", "name": "status:def", "operator": "+=", "value": Math.min(5, Math.ceil(core.status.hero.lv * 0.35)) },
									{ "type": "function", "function": "function(){\ncore.status.hero.flags.qingS[core.status.floorId].valid = false;\n}" },
								]
							},
							{
								"text": "不发动此技能",
								"need": "!flags.must_extra_dmg && !flags.must_extra_ad",
								"action": [
									{ "type": "function", "function": "function(){\ncore.status.hero.flags.qingS[core.status.floorId].enemys.pop();\n}" },

								]
							},
						]
					}, { "type": "function", "function": "function(){\ncore.removeFlag('fSize');\n}" }, );
					core.insertAction(todo);
					return;
				}
			}
		}
	}

	//由于发动情势增伤时，可以和未破防的敌人战斗，所以需要修改events.battle

	core.events.battle = function (id, x, y, force, callback) { //覆写此函数
		core.saveAndStopAutomaticRoute();
		id = id || core.getBlockId(x, y);
		if (!id) return core.clearContinueAutomaticRoute(callback);
		// 非强制战斗
		if (!core.enemys.canBattle(id, x, y) && !force && !core.status.event.id) {
			let qingS = core.getFlag('qingS', {}),
				floorId = core.status.floorId,
				canQingS = false;
			if ((core.status.hero.flags.skills.qingS == 1) && qingS[floorId].valid && qingS[floorId].enemys.indexOf(id) == -1) {
				//如果拥有技能情势，且本楼层情势未失效 & 本楼层中未对该敌人发动过情势的话
				for (let i = 0; i <= 12; i++) {
					for (let j = 0; j <= 12; j++) {
						if (x == i && y == j) continue; //跳过当前位置
						let blockId = core.getBlockId(i, j);
						if (id == blockId) { //检测到同名敌人
							canQingS = true;
							break;
						}
					}
				}
				if (canQingS && ['bowman', 'purpleBowman'].indexOf(id) == -1) { //如果可以发动情势，计算增伤/增加攻防后能否战斗
					let extra_dmg = false,
						extra_ad = false;
					core.setFlag('extra_dmg', core.status.hero.lv * 5 || 5);
					if (core.enemys.canBattle(id, x, y)) extra_dmg = true;
					core.setFlag('extra_dmg', 0);

					core.status.hero.atk += Math.min(5, Math.ceil(core.status.hero.lv * 0.35));
					core.status.hero.def += Math.min(5, Math.ceil(core.status.hero.lv * 0.35));
					if (core.enemys.canBattle(id, x, y)) extra_ad = true;
					core.status.hero.atk -= Math.min(5, Math.ceil(core.status.hero.lv * 0.35));
					core.status.hero.def -= Math.min(5, Math.ceil(core.status.hero.lv * 0.35));

					if (!extra_ad && !extra_dmg) { //如果均不行，则无法战斗
						core.stopSound();
						core.playSound('操作失败');
						core.drawTip("你打不过此怪物！", id);
						return core.clearContinueAutomaticRoute(callback);
					}

					//记录可行的选项
					core.setFlag('must_extra_dmg', extra_dmg);
					core.setFlag('must_extra_ad', extra_ad);
				} else { //无法发动情势
					core.stopSound();
					core.playSound('操作失败');
					core.drawTip("你打不过此怪物！", id);
					return core.clearContinueAutomaticRoute(callback);
				}
			} else { //没有技能情势，照常
				core.stopSound();
				core.playSound('操作失败');
				core.drawTip("你打不过此怪物！", id);
				return core.clearContinueAutomaticRoute(callback);
			}

		}
		// 自动存档
		if (!core.status.event.id) core.autosave(true);
		// 战前事件
		if (!this.beforeBattle(id, x, y))
			return core.clearContinueAutomaticRoute(callback);
		// 战后事件
		this.afterBattle(id, x, y);
		if (callback) callback();
	}

	//观星
	this.drawGuanX = function () { //绘制和处理其实都放在这个函数里了
		let x = core.getFlag('select', { x: -1, y: -1, blockId: null }).x,
			y = core.getFlag('select', { x: -1, y: -1, blockId: null }).y, //当前点击的图块坐标
			block = core.getBlockId(x, y),
			add = true,
			guanX = core.getFlag('guanX', { status: 'select', loc: [], selected: [] }); //loc记录选中的所有图块（2-6个），selected记录已经选择交换的图块坐标

		core.clearMap('skillCanvas');
		core.setAlpha('skillCanvas', 0.6);
		core.fillRect('skillCanvas', 0, 0, 416, 416, "#111111"); //绘制一个灰色半透明背景层
		core.setAlpha('skillCanvas', 1);

		if (guanX.status == 'select') { //选择图块时
			for (let i in guanX.loc) {
				if (guanX.loc[i].x == x && guanX.loc[i].y == y) { //如果选中的图块已在记录内，则取消选择
					guanX.loc.splice(i, 1);
					add = false;
					break;
				}
			}
			if (core.hasFlag('limit_guanX')) {
				if (x < 0 || y < 0 || x > 12 || y > 12) add = false; //不合法的图块不计入loc
			} else {
				if (x <= 0 || y <= 0 || x >= 12 || y >= 12) add = false; //不合法的图块不计入loc
			}
			let id = core.getBlockId(x, y) || '',
				forbid = ['Shop', 'sword', 'shield', 'specialDoor', 'Floor', 'bowman', 'purpleBowman', 'KingPro', 'wallUB', 'trader', 'wizard'];
			if (!id || forbid.some(ele => id.indexOf(ele) != -1)) add = false; //上下楼梯、空地、装备、机关门、商店、无视技能的怪不可选取
			if (core.hasFlag('limit_guanX') && id === 'redDoor') add = false; //限定时，不能选择红门
			if (add && guanX.loc.length <= Math.min(5, Math.ceil(core.status.hero.lv * 0.5))) { //未达到选取数量上限
				guanX.loc.push({ x: x, y: y });
			}
			core.fillBoldText('skillCanvas', '最多可选择' + Math.min(6, Math.ceil(core.status.hero.lv * 0.5 + 1)) + '个图块', 120, 24, '#FFFFFF', '#3399CC', 'bold 24px STKaiTi');
			core.fillBoldText('skillCanvas', '确认选择', 168, 408, '#FFFFFF', '#3399CC', 'bold 24px STKaiTi');
			//注意font内属性的顺序：依次是italic small-caps bold 10px SongTi，没有或者选择默认值的项跳过
			core.setFlag('guanX', guanX);
		}

		for (let i in guanX.loc) { //将loc内记录的图块的灰色擦掉			
			core.clearMap('skillCanvas', guanX.loc[i].x * 32, guanX.loc[i].y * 32, 32, 32);
		}

		if (guanX.status == 'exchange') { //交换图块时
			let pos = core.getFlag('redDoorSelected', []);
			for (let i in pos) { //红门加框高亮
				core.strokeRect('skillCanvas', pos[i].x * 32, pos[i].y * 32, 32, 32, '#DDDD44', 3);
			}
			if (guanX.selected.length == 1) { //已经选中一个待交换图块时
				if (guanX.selected[0].x == x && guanX.selected[0].y == y) {
					guanX.selected.pop(); //选择已选中图块时，取消选择
				} else { //点击其他图块时，检查是否在loc记录内
					for (let i in guanX.loc) {
						if (guanX.loc[i].x == x && guanX.loc[i].y == y) { //如果在，则交换2个图块的位置
							let todo = [];
							todo.push({ "type": "jump", "from": [x, y], "dxy": [guanX.selected[0].x - x, guanX.selected[0].y - y], "time": 300, "keep": true, "async": true }, );
							todo.push({ "type": "jump", "from": [guanX.selected[0].x, guanX.selected[0].y], "dxy": [x - guanX.selected[0].x, y - guanX.selected[0].y], "time": 300, "keep": true, "async": true }, );
							todo.push({ "type": "waitAsync" });
							core.insertAction(todo);
							guanX.selected.pop();
						}
					}
				}
			} else { //没有待交换图块时，检查并计入selected
				for (let i in guanX.loc) {
					if (guanX.loc[i].x == x && guanX.loc[i].y == y) {
						guanX.selected.push({ x: x, y: y });
					}
				}
			}
			core.setFlag('guanX', guanX); // 计入flag
			//然后绘制
			core.fillBoldText('skillCanvas', '交换阶段', 168, 24, '#FFFFFF', '#3399CC', 'bold 24px STKaiTi');
			core.fillBoldText('skillCanvas', '结束交换图块', 144, 408, '#FFFFFF', '#3399CC', 'bold 24px STKaiTi');
			if (guanX.selected.length) { //绘制已选中图块的标记
				for (let i in guanX.selected) {
					core.strokeRect('skillCanvas', guanX.selected[i].x * 32, guanX.selected[i].y * 32, 32, 32, '#CC5533', 4);
				}
			}
		}
	}

	this.checkRed = function (type) { //移动红门失去生命
		if (type == 'select') {
			let pos = [],
				guanX = core.getFlag('guanX', { status: 'select', loc: [], selected: [] });
			for (let i in guanX.loc) {
				let id = core.getBlockId(guanX.loc[i].x, guanX.loc[i].y) || '';
				if (id && id == 'redDoor') pos.push({ x: guanX.loc[i].x, y: guanX.loc[i].y });
			}
			return pos;
		} else {
			if (core.status.hero.flags.hard == 1) { // easy不扣血
				core.insertAction({ "type": "break" });
				return;
			}
			let pos = core.getFlag('redDoorSelected', []),
				count = 0;
			if (!pos.length) {
				core.insertAction({ "type": "break" });
				return;
			}
			for (let i in pos) {
				let id = core.getBlockId(pos[i].x, pos[i].y);
				if (id && id != 'redDoor') count++;
			}
			if (!count) {
				core.insertAction({ "type": "break" });
				return;
			}
			let height = 0;
			try {
				height = parseInt(core.floors[core.status.floorId].name);
			} catch (e) {
				console.log('楼层名称设置错误');
				core.insertAction(['楼层名称设置错误，请向作者进行反馈']);
				return;
			}
			core.clearMap('skillCanvas');
			if (core.status.hero.hp > Math.max(0, count * 100 * height)) {
				core.status.hero.hp -= Math.max(0, count * 100 * height);
				if (count) core.insertAction(['你移动了' + count + '个红门，失去了' + count * 100 * height + '点生命', { "type": "break" }]);
				return;
			} else {
				core.insertAction(['你移动了' + count + '个红门，但生命值不足' + count * 100 * height + '点，无法进行此交换操作，请重新交换']);
				core.removeFlag('select');
				let guanX = core.getFlag('guanX', { status: 'select', loc: [], selected: [] });
				guanX.selected = [];
				core.setFlag('guanX', guanX);
			}
		}
	}

	this.processGuanX = function () {
		let x = flags.x,
			y = flags.y;

		let guanX = core.getFlag('guanX', { status: 'select', loc: [], selected: [] });
		if (y == 12) { //点击最地图下方
			if (guanX.status == 'select') { //确认图块后，进入交换阶段
				guanX.status = 'exchange';
				core.setFlag('redDoorSelected', this.checkRed('select'));
				core.setFlag('guanX', guanX);
				core.setFlag('select', { x: -1, y: -1, blockId: null });
				return;
			} else { //结束交换阶段
				this.checkRed('settle');
				if (core.hasFlag('limit_guanX')) core.removeFlag('limit_guanX'); //移除限定标记
				return;
			}
		}
		if ((x == 0 || y == 0 || x == 12) && !core.hasFlag('limit_guanX')) { //非限定。限定1次的观星中，允许点击除下边缘的地图边缘位置
			core.status.hero.flags.select = { x: -1, y: -1, blockId: null };
			return; //点击其他边缘位置，忽略
		}
		//其余情况，记录下点击的位置
		core.status.hero.flags.select = { x: x, y: y, blockId: null };
		return;
	}

	this.guanX = function () { //观星
		if (!core.status.hero.flags.skills.guanX) return;
		core.createCanvas('skillCanvas', 0, 0, 416, 416, 150);
		core.clearMap('skillCanvas');
		core.setAlpha('skillCanvas', 0.5);
		core.fillRect('skillCanvas', 0, 0, 416, 416, "#444444"); //绘制一个灰色半透明背景层
		core.setAlpha('skillCanvas', 1);

		core.setFlag('guanX', { status: 'select', loc: [], selected: [] });
		core.setFlag('select', { x: -1, y: -1, blockId: null });
		core.setFlag('redDoorSelected', []);
		//等待玩家点击图块
		core.insertAction([{
				"type": "while",
				"condition": "true",
				"data": [
					{ "type": "function", "function": "function(){\ncore.plugin.drawGuanX();\n}" },
					{ "type": "wait" },
					{ "type": "function", "function": "function(){\ncore.plugin.processGuanX();\n}" },
				],
			},
			{ "type": "function", "function": "function(){\ncore.clearMap('skillCanvas'); core.deleteCanvas('skillCanvas'); core.status.hero.flags.select = { x: -1, y: -1, blockId: null }; core.plugin.autoClean()\n}" },
		]);

	}

	this.qiX = function () { //七星
		if (core.status.hero.flags.skills.qiX !== 1) return;
		core.status.route.push("key:50"); // 将按键记在录像中
		core.setFlag('fSize', 14);
		core.insertAction({
			"type": "while",
			"condition": "true",
			"data": [{
				"type": "choices",
				"text": "你发动了技能“七星”(当前剩余${flags.star || 0}枚星)",
				"choices": [{
						"text": "移除1枚星，+12%减伤 (乘法叠加，当前${((1- Math.pow(0.88, flags.exempt || 0)) * 100).toFixed(1)}%)",
						"need": "flags.star >=1",
						"action": [
							{ "type": "setValue", "name": "flag:star", "operator": "-=", "value": "1" },
							{ "type": "setValue", "name": "flag:exempt", "operator": "+=", "value": "1" },
						]
					},
					{
						"text": "移除1枚星，获得飞/破各1个",
						"need": "flags.star >=1",
						"action": [
							{ "type": "setValue", "name": "flag:star", "operator": "-=", "value": "1" },
							{ "type": "setValue", "name": "item:pickaxe", "operator": "+=", "value": "1" },
							{ "type": "setValue", "name": "item:centerFly", "operator": "+=", "value": "1" },
						]
					},
					{
						"text": "移除3枚星，获得1圣水（生命×2）",
						"need": "flags.star >=3",
						"action": [
							{ "type": "setValue", "name": "flag:star", "operator": "-=", "value": "3" },
							{ "type": "setValue", "name": "item:superPotion", "operator": "+=", "value": "1" },
						]
					},
					{
						"text": "移除1枚星，获得1超级破墙稿（可破深色墙）（限1次）",
						"need": "flags.star >=1",
						"condition": "flags.superPickaxe == 0",
						"action": [
							{ "type": "setValue", "name": "flag:star", "operator": "-=", "value": "1" },
							{ "type": "setValue", "name": "item:superPickaxe", "operator": "+=", "value": "1" },
							{ "type": "setValue", "name": "flag:superPickaxe", "operator": "+=", "value": "1" },
						]
					},
					{
						"text": "结束技能",
						"action": [
							{ "type": "function", "function": "function(){\ncore.removeFlag('fSize');\n}" },
							{ "type": "exit" },
						]
					},
				]
			}, ],
		})
	}
},
    "MT12": function () {
	// 在此增加新插件
	this.focusEnemy = function (x, y, time) {
		if (core.isReplaying()) return; //回放录像直接跳过
		if (x == null || y == null) return;
		time = time || 500;

		var px = x * 32 + 16 - 208,
			py = y * 32 + 16 - 208,
			count = 0,
			animation = setInterval(() => { //动画效果：灯光从中心移动到焦点位置，光圈从150一点点收缩到32
				if (count >= time) {
					clearInterval(animation);
					return;
				}
				count += 50;
				let ratio = count / time;
				core.plugin.drawLight('ui', 0.8, [
					[208 + px * ratio, 208 + py * ratio, 150 - 118 * ratio, 1]
				])
			}, 50)
	}
},
    "animate": function () {
	// -------------------- 插件说明 -------------------- //

	// github仓库：https://github.com/unanmed/animate
	// npm包名：mutate-animate
	// npm地址：https://www.npmjs.com/package/mutate-animate

	// 不要去尝试读这个插件，这个插件是经过了打包的，不是人类可读的(
	// 想读的话可以去github读

	// 该插件是一个轻量型多功能动画插件，可以允许你使用内置或自定义的速率曲线或轨迹等
	// 除此之外，你还可以自定义绘制函数，来让你的动画可视化

	// -------------------- 安装说明 -------------------- //

	// 直接复制到插件中即可，注意所有插件中不能出现插件名为animate的插件
	// 该插件分为动画和渐变两部分，教程分开，动画在前，渐变在后

	// -------------------- 动画使用教程 -------------------- //

	// 1. 首先创建一个异步函数
	//   async function ani() { }

	// 2. 引入插件中的类和函数，引入内容要看个人需求，所有可用的函数在本插件末尾可以看到
	//   const { Animation, linear, bezier, circle, hyper, trigo, power, inverseTrigo, shake, sleep } = core.plugin.animate

	// 3. 在函数内部创建一个动画
	//   const animate = new Animation();

	// 4. 为动画创建一个绘制函数，这里以绘制一个矩形为例，当然也可以使用core.fillRect替代ctx.fillRect来绘制矩形
	//   const ctx = core.createCanvas('animate', 0, 0, 416, 416, 100);
	//   ctx.save();
	//   const fn = () => {
	//      ctx.restore();
	//      ctx.save();
	//      ctx.clearRect(0, 0, 800, 800);
	//      ctx.translate(animate.x, animate.y);
	//      ctx.rotate(animate.angle * Math.PI / 180);
	//      const size = animate.size;
	//      ctx.fillRect(-30 * size, -30 * size, 60 * size, 60 * size);
	//   }
	//   animate.ticker.add(fn);

	// 5. 执行动画

	//   下面先对一些概念进行解释

	//   动画分为很多种，内置的有move(移动至某一点)  rotate(旋转)  scale(放缩)  moveAs(以指定路径移动)  shake(震动)
	//   对于不同的动画种类，其所对应的属性也不同，move moveAs shake均对应x和y这两个属性
	//   rotate对应angle，scale对应size。你也可以自定义属性，这个之后会提到

	//   除了执行动画之外，这里还提供了三个等待函数，可以等待某个动画执行完毕，以及一个等待指定时长的函数
	//   分别是animate.n(等待指定数量的动画执行完毕)
	//   animate.w(等待指定类型的动画执行完毕，也可以是自定义类型)
	//   animate.all(等待所有动画执行完毕)
	//   sleep(等待指定时长)

	//   执行动画时，要求一个渐变函数，当然这个插件内置了非常丰富的渐变函数，也就是速率曲线。

	//   线性渐变函数  linear()，该函数返回一个线性变化函数

	//   三角渐变函数  trigo('sin' | 'sec', EaseMode)，该函数返回一个指定属性的三角函数变化函数
	//       其中EaseMode可以填'in' 'out' 'in-out' 'center'
	//       分别表示 慢-快  快-慢  慢-快-慢  快-慢-快

	//   幂函数渐变  power(n, EaseMode)，该函数返回一个以x^n变化的函数，n是指数

	//   双曲渐变函数  hyper('sin' | 'tan' | 'sec', EaseMode)，该函数返回一个双曲函数，分别是双曲正弦、双曲正切、双曲正割

	//   反三角渐变函数  inverseTrigo('sin' | 'tan', EaseMode)，该函数返回一个反三角函数

	//   贝塞尔曲线渐变函数  bezier(...cps)，参数为贝塞尔曲线的控制点纵坐标（横坐标不能自定义，毕竟一个时刻不能对应多个速率）
	//       示例：bezier(0.4, 0.2, 0.7); // 三个控制点的四次贝塞尔曲线渐变函数

	//   了解完渐变函数以后，这里还有一个特殊的渐变函数-shake
	//   shake(power, timing)，这个函数是一个震荡函数，会让一个值来回变化，实现震动的效果
	//       其中power是震动的最大值，timing是渐变函数，描述了power在震动时大小的变化

	//   下面，我们就可以进行动画的执行了，我们以 运动 + 旋转 + 放缩为例

	//   animate.mode(hyper('sin', 'out'))  // 设置渐变函数为 双曲正弦 快 -> 慢，注意不能加分号
	//       .time(1000)  // 设置动画的执行时间为1000毫秒
	//       .move(300, 300)  // 移动至[300, 300]的位置
	//       .relative()  // 设置相对模式为相对之前，与之前为相加的关系
	//       .mode(power(3, 'center'))  // 设置为 x^3 快-慢-快 的渐变函数
	//       .time(3000)
	//       .rotate(720)  // 旋转720度
	//       .absolute()  // 设置相对模式为绝对
	//       .mode(trigo('sin', 'in'))  // 设置渐变函数为 正弦 慢 -> 快
	//       .time(1500)
	//       .scale(3);  // 放缩大小至3倍

	//   这样，我们就把三种基础动画都执行了一遍，同时，这种写法非常直观，出现问题时也可以很快地找到问题所在
	//   下面，我们需要等待动画执行完毕，因为同一种动画不可能同时执行两个

	//   await animate.n(1); // 等待任意一个动画执行完毕，别把await忘了
	//   await animate.w('scale'); // 等待放缩动画执行完毕
	//   await animate.all(); // 等待所有动画执行完毕
	//   await sleep(1000); // 等待1000毫秒

	//   下面，还有一个特殊的动画函数-moveAs
	//   这是一个非常强大的函数，它允许你让你的物体按照指定路线运动
	//   说到这，我们需要先了解一下运动函数。
	//   该插件内置了两个运动函数，分别是圆形运动和贝塞尔曲线运动

	//   圆形运动 circle(r, n, timing, inverse)，r是圆的半径，n是圈数，timing描述半径大小的变化，inverse说明了是否翻转timing函数，后面三个可以不填

	//   贝塞尔曲线 bezierPath(start, end, ...cps)
	//       其中start和end是起点和结束点，应当填入[x, y]数组，cps是控制点，也是[x, y]数组
	//       示例：bezierPath([0, 0], [200, 200], [100, 50], [300, 150], [200, 180]);
	//       这是一个起点为 [0, 0]，终点为[200, 200]，有三个控制点的四次贝塞尔曲线

	//   下面，我们就可以使用路径函数了

	//   animate.mode(hyper('sin', 'in-out'))  // 设置渐变曲线
	//       .time(5000)
	//       .relative()  // 设置为相对模式，这个比较必要，不然的话很可能出现瞬移
	//       .moveAs(circle(100, 5, linear()))  // 创建一个5圈的半径从0至100逐渐变大的圆轨迹（是个螺旋线）并让物体沿着它运动
	//       
	//   最后，还有一个震动函数 shake(x, y)，x和y表示了在横向上和纵向上的震动幅度，1表示为震动幅度的100%
	//   示例：
	//   animate.mode(shake(5, hyper('sin', 'in')), true) // 这里第二个参数说明是震动函数
	//       .time(2000)
	//       .shake(1, 0.5)

	//   这样，所有内置动画就已经介绍完毕

	// 6. 自定义动画属性

	//   本插件允许你自定义一个动画属性，但功能可能不会像自带的属性那么强大
	//   你可以在创建动画之后使用animate.register(key, init)来注册一个自定义属性
	//   其中key是自定义属性的名称，init是自定义属性的初始值，这个值应当在0-1之间变化

	//   你可以通过animate.value[key]来获取你注册的自定义属性

	//   对于自定义属性的动画，你应当使用animate.apply(key, n, first)
	//   其中，key是你的自定义属性的名称，n是其目标值，first是一个布尔值，说明了是否将该动画插入到目前所有的动画之前，即每帧会优先执行该动画

	//   下面是一个不透明度的示例

	//   animate.register('opacity', 1); // 这句话应该放到刚创建动画之后

	//   ctx.globalAlpha = animate.value.opacity; // 这句话应当放到每帧绘制的函数里面，放在绘制之前

	//   animate.mode(bezier(0.9, 0.1, 0.05))  // 设置渐变函数
	//       .time(2000)
	//       .absolute()
	//       .apply('opacity', 0.3);  // 将不透明度按照渐变曲线更改为0.3

	// 7. 运行动画

	//   还记得刚开始定义的async function 吗，直接调用它就能执行动画了！
	//   示例：ani(); // 执行刚刚写的所有动画

	// 8. 自定义速率曲线和路径

	//   该插件中，速率曲线和路径均可自定义

	//   对于速率曲线，其类型为  (input: number) => number
	//   它接受一个范围在 0-1 的值，输出一个 0-1 的值，表示了动画的完成度，1表示动画已完成，0表示动画刚开始（当前大于1小于0也不会报错，也会执行相应的动画）

	//   对于路径，其类型为  (input: number) => [number, number]
	//   它与速率曲线类似，接收一个 0-1 的值，输出一个坐标数组

	// 9. 多个属性绑定

	//   该插件中，你可以绑定多个动画属性，你可以使用ani.bind(...attr)来绑定。
	//   绑定之后，这三个动画属性可以被一个返回了长度为3的数组的渐变函数执行。
	//   绑定使用ani.bind，设置渐变函数仍然使用ani.mode，注意它与单个动画属性是分开的，也就是它不会影响正常的渐变函数。
	//   然后使用ani.applyMulti即可执行动画

	//   例如：
	//   // 自定义的一个三属性渐变函数
	//   function b(input) {
	//       return [input * 100, input ** 2 * 100, input ** 3 * 100];
	//   }
	//   ani.bind('a', 'b', 'c') // 这样会绑定abc这三个动画属性
	//       .mode(b) // 自定义的一个返回了长度为3的数组的函数
	//       .time(5000)
	//       .absolute()
	//       .applyMulti(); // 执行这个动画

	// 9. 监听  动画的生命周期钩子

	//   这个插件还允许你去监听动画的状态，可以监听动画的开始、结束、运行
	//   你可以使用 animate.listen(type, fn)来监听，fn的类型是 (a: Animation, type: string) => void
	//   当然，一般情况下你不会用到这个功能，插件中已经帮你包装了三个等待函数，他们就是以这些监听为基础的

	// 10. 自定义时间获取函数

	//   你可以修改ani.getTime来修改动画的时间获取函数，例如想让动画速度变成一半可以写ani.getTime = () => Date.now() / 2
	//   这样可以允许你随意控制动画的运行速度，暂停，甚至是倒退。该值默认为`Date.now`

	// -------------------- 渐变使用教程 -------------------- //

	// 相比于动画，渐变属于一种较为简便的动画，它可以让你在设置一个属性后使属性缓慢变化值目标值而不是突变至目标值
	// 现在假设你已经了解了动画的使用，下面我们来了解渐变。

	// 1. 创建一个渐变实例
	//   与动画类似，你需要使用new来实例化一个渐变，当然别忘了引入
	//   const { Transition } = core.plugin.animate;
	//   const tran = new Transition();

	// 2. 绘制
	//   const ctx = core.createCanvas('transition', 0, 0, 416, 416, 100);
	//   ctx.save();
	//   const fn = () => {
	//      ctx.restore();
	//      ctx.save();
	//      ctx.clearRect(0, 0, 800, 800);
	//      ctx.beginPath();
	//      ctx.arc(tran.value.x, tran.value.y, 50, 0, Math.PI * 2); // 使用tran.value.xxx获取当前的属性
	//      ctx.fill();
	//      // 当然也可以用样板的api，例如core.fillCircle();等
	//   }
	//   animate.ticker.add(fn);

	// 3. 设置渐变
	//   同样，与动画类似，你可以使用tran.time()设置渐变时间，使用tran.mode()设置渐变函数，使用tran.absolute()和tran.relative()设置相对模式
	//   例如：
	//   tran.time(1000)
	//       .mode(hyper('sin', 'out'))
	//       .absolute();

	// 4. 初始化渐变属性
	//   与动画不同的是，动画在执行一个自定义属性前都需要register，而渐变不需要。
	//   你可以通过tran.value.xxx = yyy来设置动画属性或使用tran.transition('xxx', yyy)来设置
	//   你的首次赋值即是初始化了渐变属性，这时是不会执行渐变的，例如：
	//   tran.value.x = 200;
	//   tran.transition('y', 200);
	//   上述例子便是将 x 和 y 初始化成了200

	// 5. 执行渐变
	//   初始化完成后，便可以直接执行渐变了，有两种方法
	//   tran.value.x = 400; // 将 x 缓慢移动至400
	//   tran.transition('y', 400); // 将 y 缓慢移动至400

	// 6. 自定义时间获取函数
	//   与动画类似，你依然可以通过修改tran.getTime来修改时间获取函数

	if (main.replayChecking) return core.plugin.animate = {};

	var M = Object.defineProperty;
	var E = (n, i, t) => i in n ? M(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t;
	var o = (n, i, t) => (E(n, typeof i != "symbol" ? i + "" : i, t), t);
	let w = [];
	const k = (n) => {
		for (const i of w)
			if (i.status === "running")
				try {
					for (const t of i.funcs)
						t(n - i.startTime);
				} catch (t) {
					i.destroy(), console.error(t);
				}
		requestAnimationFrame(k);
	};
	requestAnimationFrame(k);
	class I {
		constructor() {
			o(this, "funcs", /* @__PURE__ */ new Set());
			o(this, "status", "stop");
			o(this, "startTime", 0);
			this.status = "running", w.push(this), requestAnimationFrame((i) => this.startTime = i);
		}
		add(i) {
			return this.funcs.add(i), this;
		}
		remove(i) {
			return this.funcs.delete(i), this;
		}
		clear() {
			this.funcs.clear();
		}
		destroy() {
			this.clear(), this.stop();
		}
		stop() {
			this.status = "stop", w = w.filter((i) => i !== this);
		}
	}
	class F {
		constructor() {
			o(this, "timing");
			o(this, "relation", "absolute");
			o(this, "easeTime", 0);
			o(this, "applying", {});
			o(this, "getTime", Date.now);
			o(this, "ticker", new I());
			o(this, "value", {});
			o(this, "listener", {});
			this.timing = (i) => i;
		}
		async all() {
			if (Object.values(this.applying).every((i) => i === !0))
				throw new ReferenceError("There is no animates to be waited.");
			await new Promise((i) => {
				const t = () => {
					Object.values(this.applying).every((e) => e === !1) && (this.unlisten("end", t), i("all animated."));
				};
				this.listen("end", t);
			});
		}
		async n(i) {
			const t = Object.values(this.applying).filter((s) => s === !0).length;
			if (t < i)
				throw new ReferenceError(
					`You are trying to wait ${i} animate, but there are only ${t} animate animating.`
				);
			let e = 0;
			await new Promise((s) => {
				const r = () => {
					e++, e === i && (this.unlisten("end", r), s(`${i} animated.`));
				};
				this.listen("end", r);
			});
		}
		async w(i) {
			if (this.applying[i] === !1)
				throw new ReferenceError(`The ${i} animate is not animating.`);
			await new Promise((t) => {
				const e = () => {
					this.applying[i] === !1 && (this.unlisten("end", e), t(`${i} animated.`));
				};
				this.listen("end", e);
			});
		}
		listen(i, t) {
			var e, s;
			(s = (e = this.listener)[i]) != null || (e[i] = []), this.listener[i].push(t);
		}
		unlisten(i, t) {
			const e = this.listener[i].findIndex((s) => s === t);
			if (e === -1)
				throw new ReferenceError(
					"You are trying to remove a nonexistent listener."
				);
			this.listener[i].splice(e, 1);
		}
		hook(...i) {
			const t = Object.entries(this.listener).filter(
				(e) => i.includes(e[0])
			);
			for (const [e, s] of t)
				for (const r of s)
					r(this, e);
		}
	}

	function y(n) {
		return n != null;
	}
	async function R(n) {
		return new Promise((i) => setTimeout(i, n));
	}
	class j extends F {
		constructor() {
			super();
			o(this, "shakeTiming");
			o(this, "path");
			o(this, "multiTiming");
			o(this, "value", {});
			o(this, "size", 1);
			o(this, "angle", 0);
			o(this, "targetValue", {
				system: {
					move: [0, 0],
					moveAs: [0, 0],
					resize: 0,
					rotate: 0,
					shake: 0,
					"@@bind": []
				},
				custom: {}
			});
			o(this, "animateFn", {
				system: {
					move: [() => 0, () => 0],
					moveAs: () => 0,
					resize: () => 0,
					rotate: () => 0,
					shake: () => 0,
					"@@bind": () => 0
				},
				custom: {}
			});
			o(this, "ox", 0);
			o(this, "oy", 0);
			o(this, "sx", 0);
			o(this, "sy", 0);
			o(this, "bindInfo", []);
			this.timing = (t) => t, this.shakeTiming = (t) => t, this.multiTiming = (t) => [t, t], this.path = (t) => [t, t], this.applying = {
				move: !1,
				scale: !1,
				rotate: !1,
				shake: !1
			}, this.ticker.add(() => {
				const { running: t } = this.listener;
				if (y(t))
					for (const e of t)
						e(this, "running");
			});
		}
		get x() {
			return this.ox + this.sx;
		}
		get y() {
			return this.oy + this.sy;
		}
		mode(t, e = !1) {
			return typeof t(0) == "number" ? e ? this.shakeTiming = t : this.timing = t : this.multiTiming = t, this;
		}
		time(t) {
			return this.easeTime = t, this;
		}
		relative() {
			return this.relation = "relative", this;
		}
		absolute() {
			return this.relation = "absolute", this;
		}
		bind(...t) {
			return this.applying["@@bind"] === !0 && this.end(!1, "@@bind"), this.bindInfo = t, this;
		}
		unbind() {
			return this.applying["@@bind"] === !0 && this.end(!1, "@@bind"), this.bindInfo = [], this;
		}
		move(t, e) {
			return this.applying.move && this.end(!0, "move"), this.applySys("ox", t, "move"), this.applySys("oy", e, "move"), this;
		}
		rotate(t) {
			return this.applySys("angle", t, "rotate"), this;
		}
		scale(t) {
			return this.applySys("size", t, "resize"), this;
		}
		shake(t, e) {
			this.applying.shake === !0 && this.end(!0, "shake"), this.applying.shake = !0;
			const { easeTime: s, shakeTiming: r } = this, l = this.getTime();
			if (this.hook("start", "shakestart"), s <= 0)
				return this.end(!1, "shake"), this;
			const a = () => {
				const c = this.getTime() - l;
				if (c > s) {
					this.ticker.remove(a), this.applying.shake = !1, this.sx = 0, this.sy = 0, this.hook("end", "shakeend");
					return;
				}
				const h = c / s,
					m = r(h);
				this.sx = m * t, this.sy = m * e;
			};
			return this.ticker.add(a), this.animateFn.system.shake = a, this;
		}
		moveAs(t) {
			this.applying.moveAs && this.end(!0, "moveAs"), this.applying.moveAs = !0, this.path = t;
			const { easeTime: e, relation: s, timing: r } = this, l = this.getTime(), [a, u] = [this.x, this.y], [c, h] = (() => {
				if (s === "absolute")
					return t(1); {
					const [d, f] = t(1);
					return [a + d, u + f];
				}
			})();
			if (this.hook("start", "movestart"), e <= 0)
				return this.end(!1, "moveAs"), this;
			const m = () => {
				const f = this.getTime() - l;
				if (f > e) {
					this.end(!0, "moveAs");
					return;
				}
				const g = f / e,
					[v, x] = t(r(g));
				s === "absolute" ? (this.ox = v, this.oy = x) : (this.ox = a + v, this.oy = u + x);
			};
			return this.ticker.add(m), this.animateFn.system.moveAs = m, this.targetValue.system.moveAs = [c, h], this;
		}
		register(t, e) {
			if (typeof this.value[t] == "number")
				return this.error(
					`Property ${t} has been regietered twice.`,
					"reregister"
				);
			this.value[t] = e, this.applying[t] = !1;
		}
		apply(t, e) {
			this.applying[t] === !0 && this.end(!1, t), t in this.value || this.error(
				`You are trying to execute nonexistent property ${t}.`
			), this.applying[t] = !0;
			const s = this.value[t],
				r = this.getTime(),
				{ timing: l, relation: a, easeTime: u } = this,
				c = a === "absolute" ? e - s : e;
			if (this.hook("start"), u <= 0)
				return this.end(!1, t), this;
			const h = () => {
				const d = this.getTime() - r;
				if (d > u) {
					this.end(!1, t);
					return;
				}
				const f = d / u,
					g = l(f);
				this.value[t] = s + g * c;
			};
			return this.ticker.add(h), this.animateFn.custom[t] = h, this.targetValue.custom[t] = c + s, this;
		}
		applyMulti() {
			this.applying["@@bind"] === !0 && this.end(!1, "@@bind"), this.applying["@@bind"] = !0;
			const t = this.bindInfo,
				e = t.map((h) => this.value[h]),
				s = this.getTime(),
				{ multiTiming: r, relation: l, easeTime: a } = this,
				u = r(1);
			if (u.length !== e.length)
				throw new TypeError(
					`The number of binded animate attributes and timing function returns's length does not match. binded: ${t.length}, timing: ${u.length}`
				);
			if (this.hook("start"), a <= 0)
				return this.end(!1, "@@bind"), this;
			const c = () => {
				const m = this.getTime() - s;
				if (m > a) {
					this.end(!1, "@@bind");
					return;
				}
				const d = m / a,
					f = r(d);
				t.forEach((g, v) => {
					l === "absolute" ? this.value[g] = f[v] : this.value[g] = e[v] + f[v];
				});
			};
			return this.ticker.add(c), this.animateFn.custom["@@bind"] = c, this.targetValue.system["@@bind"] = u, this;
		}
		applySys(t, e, s) {
			s !== "move" && this.applying[s] === !0 && this.end(!0, s), this.applying[s] = !0;
			const r = this[t],
				l = this.getTime(),
				a = this.timing,
				u = this.relation,
				c = this.easeTime,
				h = u === "absolute" ? e - r : e;
			if (this.hook("start", `${s}start`), c <= 0)
				return this.end(!0, s);
			const m = () => {
				const f = this.getTime() - l;
				if (f > c) {
					this.end(!0, s);
					return;
				}
				const g = f / c,
					v = a(g);
				this[t] = r + h * v, t !== "oy" && this.hook(s);
			};
			this.ticker.add(m), t === "ox" ? this.animateFn.system.move[0] = m : t === "oy" ? this.animateFn.system.move[1] = m : this.animateFn.system[s] = m, s === "move" ? (t === "ox" && (this.targetValue.system.move[0] = h + r), t === "oy" && (this.targetValue.system.move[1] = h + r)) : s !== "shake" && (this.targetValue.system[s] = h + r);
		}
		error(t, e) {
			throw e === "repeat" ? new Error(
				`Cannot execute the same animation twice. Info: ${t}`
			) : e === "reregister" ? new Error(
				`Cannot register an animated property twice. Info: ${t}`
			) : new Error(t);
		}
		end(t, e) {
			if (t === !0)
				if (this.applying[e] = !1, e === "move" ? (this.ticker.remove(this.animateFn.system.move[0]), this.ticker.remove(this.animateFn.system.move[1])) : e === "moveAs" ? this.ticker.remove(this.animateFn.system.moveAs) : e === "@@bind" ? this.ticker.remove(this.animateFn.system["@@bind"]) : this.ticker.remove(
						this.animateFn.system[e]
					), e === "move") {
					const [s, r] = this.targetValue.system.move;
					this.ox = s, this.oy = r, this.hook("moveend", "end");
				} else if (e === "moveAs") {
				const [s, r] = this.targetValue.system.moveAs;
				this.ox = s, this.oy = r, this.hook("moveend", "end");
			} else
				e === "rotate" ? (this.angle = this.targetValue.system.rotate, this.hook("rotateend", "end")) : e === "resize" ? (this.size = this.targetValue.system.resize, this.hook("resizeend", "end")) : e === "@@bind" ? this.bindInfo.forEach((r, l) => {
					this.value[r] = this.targetValue.system["@@bind"][l];
				}) : (this.sx = 0, this.sy = 0, this.hook("shakeend", "end"));
			else
				this.applying[e] = !1, this.ticker.remove(this.animateFn.custom[e]), this.value[e] = this.targetValue.custom[e], this.hook("end");
		}
	}
	class O extends F {
		constructor() {
			super();
			o(this, "now", {});
			o(this, "target", {});
			o(this, "transitionFn", {});
			o(this, "value");
			o(this, "handleSet", (t, e, s) => (this.transition(e, s), !0));
			o(this, "handleGet", (t, e) => this.now[e]);
			this.timing = (t) => t, this.value = new Proxy(this.target, {
				set: this.handleSet,
				get: this.handleGet
			});
		}
		mode(t) {
			return this.timing = t, this;
		}
		time(t) {
			return this.easeTime = t, this;
		}
		relative() {
			return this.relation = "relative", this;
		}
		absolute() {
			return this.relation = "absolute", this;
		}
		transition(t, e) {
			if (e === this.target[t])
				return this;
			if (!y(this.now[t]))
				return this.now[t] = e, this;
			this.applying[t] && this.end(t, !0), this.applying[t] = !0, this.hook("start");
			const s = this.getTime(),
				r = this.easeTime,
				l = this.timing,
				a = this.now[t],
				u = e + (this.relation === "absolute" ? 0 : a),
				c = u - a;
			this.target[t] = u;
			const h = () => {
				const d = this.getTime() - s;
				if (d >= r) {
					this.end(t);
					return;
				}
				const f = d / r;
				this.now[t] = l(f) * c + a, this.hook("running");
			};
			return this.transitionFn[t] = h, this.ticker.add(h), r <= 0 ? (this.end(t), this) : this;
		}
		end(t, e = !1) {
			const s = this.transitionFn[t];
			if (!y(s))
				throw new ReferenceError(
					`You are trying to end an ended transition: ${t}`
				);
			this.ticker.remove(this.transitionFn[t]), delete this.transitionFn[t], this.applying[t] = !1, this.hook("end"), e || (this.now[t] = this.target[t]);
		}
	}
	const T = (...n) => n.reduce((i, t) => i + t, 0),
		b = (n) => {
			if (n === 0)
				return 1;
			let i = n;
			for (; n > 1;)
				n--, i *= n;
			return i;
		},
		A = (n, i) => Math.round(b(i) / (b(n) * b(i - n))),
		p = (n, i, t = (e) => 1 - i(1 - e)) => n === "in" ? i : n === "out" ? t : n === "in-out" ? (e) => e < 0.5 ? i(e * 2) / 2 : 0.5 + t((e - 0.5) * 2) / 2 : (e) => e < 0.5 ? t(e * 2) / 2 : 0.5 + i((e - 0.5) * 2) / 2,
		$ = Math.cosh(2),
		z = Math.acosh(2),
		V = Math.tanh(3),
		P = Math.atan(5);

	function Y() {
		return (n) => n;
	}

	function q(...n) {
		const i = [0].concat(n);
		i.push(1);
		const t = i.length,
			e = Array(t).fill(0).map((s, r) => A(r, t - 1));
		return (s) => {
			const r = e.map((l, a) => l * i[a] * (1 - s) ** (t - a - 1) * s ** a);
			return T(...r);
		};
	}

	function U(n, i) {
		if (n === "sin") {
			const t = (s) => Math.sin(s * Math.PI / 2);
			return p(i, (s) => 1 - t(1 - s), t);
		}
		if (n === "sec") {
			const t = (s) => 1 / Math.cos(s);
			return p(i, (s) => t(s * Math.PI / 3) - 1);
		}
		throw new TypeError(
			"Unexpected parameters are delivered in trigo timing function."
		);
	}

	function C(n, i) {
		if (!Number.isInteger(n))
			throw new TypeError(
				"The first parameter of power timing function only allow integer."
			);
		return p(i, (e) => e ** n);
	}

	function G(n, i) {
		if (n === "sin")
			return p(i, (e) => (Math.cosh(e * 2) - 1) / ($ - 1));
		if (n === "tan") {
			const t = (s) => Math.tanh(s * 3) * 1 / V;
			return p(i, (s) => 1 - t(1 - s), t);
		}
		if (n === "sec") {
			const t = (s) => 1 / Math.cosh(s);
			return p(i, (s) => 1 - (t(s * z) - 0.5) * 2);
		}
		throw new TypeError(
			"Unexpected parameters are delivered in hyper timing function."
		);
	}

	function N(n, i) {
		if (n === "sin") {
			const t = (s) => Math.asin(s) / Math.PI * 2;
			return p(i, (s) => 1 - t(1 - s), t);
		}
		if (n === "tan") {
			const t = (s) => Math.atan(s * 5) / P;
			return p(i, (s) => 1 - t(1 - s), t);
		}
		throw new TypeError(
			"Unexpected parameters are delivered in inverse trigo timing function."
		);
	}

	function B(n, i = () => 1) {
		let t = -1;
		return (e) => (t *= -1, e < 0.5 ? n * i(e * 2) * t : n * i((1 - e) * 2) * t);
	}

	function D(n, i = 1, t = [0, 0], e = 0, s = (l) => 1, r = !1) {
		return (l) => {
			const a = i * l * Math.PI * 2 + e * Math.PI / 180,
				u = Math.cos(a),
				c = Math.sin(a),
				h = n * s(s(r ? 1 - l : l));
			return [h * u + t[0], h * c + t[1]];
		};
	}

	function H(n, i, ...t) {
		const e = [n].concat(t);
		e.push(i);
		const s = e.length,
			r = Array(s).fill(0).map((l, a) => A(a, s - 1));
		return (l) => {
			const a = r.map((c, h) => c * e[h][0] * (1 - l) ** (s - h - 1) * l ** h),
				u = r.map((c, h) => c * e[h][1] * (1 - l) ** (s - h - 1) * l ** h);
			return [T(...a), T(...u)];
		};
	}
	if ('animate' in core.plugin) throw new ReferenceError(`插件中已存在名为animate的属性！`);

	core.plugin.animate = {
		Animation: j,
		AnimationBase: F,
		Ticker: I,
		Transition: O,
		bezier: q,
		bezierPath: H,
		circle: D,
		hyper: G,
		linear: Y,
		power: C,
		shake: B,
		sleep: R,
		trigo: U,
		inverseTrigo: N,
	}

},
    "auto2": function () {
	//有战后战前事件的0伤怪视为不可通过
	//支持单向箭头，但不支持感叹号、滑冰和推箱子
	//flags.autoGem控制自动拾取
	//flags.autoEnemy控制自动清怪
	//战后、开门后、切换楼层后、推开阻击后、从有地图伤害的点走出后触发自动清理
	//移动操作不会触发自动清理，因此是否可以瞬移不影响本插件运行


	//古祠佬的高级动画相关，此部分请咨询古祠佬
	//需要安装高级动画插件，具体请查看古祠佬的插件说明
	const { Transition, hyper, Ticker } = core.plugin.animate;
	// 磁吸特效的时长，单位毫秒
	const transitionTime = 600;
	const transitionList = new Set();

	if (!main.replayChecking) {
		const ticker = new Ticker();
		ticker.add(() => {
			if (!core.isPlaying()) return;
			const ctx = core.getContextByName('_autoItem_');
			if (!ctx) return;
			core.clearMap(ctx);
		});
	}
	//

	function passThrough(x, y, floorId) { //当前位置是否可以通过
		floorId = floorId || core.status.floorId;
		if (x < 0 || y < 0 || x > 12 || y > 12) return false;

		const block = core.getBlock(x, y, floorId),
			id = core.getBlockId(x, y, floorId),
			cls = core.getBlockCls(x, y, floorId),
			pass = false,
			loc = [x, y].join(','),
			floor = core.floors[floorId],
			autoGem = core.getFlag('autoGem', false),
			autoEnemy = core.getFlag('autoEnemy', false);
		//当前格无阻击or捕捉事件，且地图伤害为0
		try {
			if (core.status.checkBlock.repulse[loc] || core.status.checkBlock.ambush[loc] || core.status.checkBlock.damage[loc]) return false;
		} catch (e) {}

		if (id === null) return true; //空地

		switch (cls) { //如果是物品or怪物or地板
		case 'items':
		case 'tools':
		case 'constants':
			if (autoGem && !floor.afterGetItem[loc]) return true; // 无拾取后事件
			break;
		case 'enemys':
		case 'enemy48':
			const damage = core.getDamage(id, x, y, floorId);
			if (autoEnemy && damage === 0 && block.event.trigger === 'battle' && !floor.afterBattle[loc] && !floor.beforeBattle[loc] && !core.enemys.enemys[id].afterBattle && !core.enemys.enemys[id].beforeBattle) return true; // 无战前战后事件且0伤
			break;
		case 'terrains':
			if (id === 'light') return false; //感叹号不支持
			if (block.event && block.event.trigger && block.event.trigger === 'ski') return false;
			//滑冰技术上暂时不支持，主要问题1：滑冰遇到阻挡后会停在冰上，以及阻挡块是门时还需要对钥匙判定（自动拾取的路上有无必须拾取的钥匙等等），可通行判断极其复杂
			//主要问题2：大面积滑冰连片后，（双）联通性极难判断
			if (!block.event.noPass) return true; //其他可穿透的地板
			break;
		}

		return false;
	}

	function canReturn(startX, startY) { //从某点出发能否返回角色当前位置：遇到带有单向箭头的地图时，获取后不可返回角色当前位置的物品/敌人不触发自动清理
		const endX = core.getHeroLoc('x'),
			endY = core.getHeroLoc('y');
		// 边界检查
		if (startX < 0 || startY < 0 || endX < 0 || endY < 0 || startX >= 13 || startY >= 13 || endX >= 13 || endY >= 13) return false;
		// 起点或终点不可通过
		if (!passThrough(startX, startY) || !passThrough(endX, endY)) return false;

		// 初始化队列和访问标记数组
		const q = [];
		const visited = Array(13).fill().map(() => Array(13).fill(false));

		q.push([startX, startY]); // 起点入队并标记
		visited[startX][startY] = true;
		while (q.length > 0) {
			const [cx, cy] = q.shift(); // 取队首坐标
			// 到达终点
			if (cx === endX && cy === endY) {
				return true;
			}
			// 遍历四个方向
			for (var dir of ['up', 'right', 'down', 'left']) {
				const nextx = cx + core.utils.scan[dir].x,
					nexty = cy + core.utils.scan[dir].y;
				if (core.canMoveHero(cx, cy, dir) && passThrough(nextx, nexty) && !visited[nextx][nexty]) {
					q.push([nextx, nexty]);
					visited[nextx][nexty] = true;
				}
			}
		}
		return false; // 队列为空未找到终点
	}

	function animationItem(id, sx, sy) {
		const px = sx * 32 - core.bigmap.offsetX;
		const py = sy * 32 - core.bigmap.offsetY;
		const t = new Transition();
		t.mode(hyper('sin', 'out'))
			.time(transitionTime)
			.absolute()
			.transition('x', px)
			.transition('y', py);
		const { x, y } = core.status.hero.loc;
		t.value.x = x * 32 - core.bigmap.offsetX;
		t.value.y = y * 32 - core.bigmap.offsetY;
		t.endLoc = { x: x, y: y }; //记录终点位置
		t.listen('running', function (ani, type) { //监听，动画还未结束角色位置已经改变时，改变动画终点
			const { x, y } = core.status.hero.loc,
				endX = ani.endLoc.x,
				endY = ani.endLoc.y;
			if (x !== endX || y !== endY) { //终点不一致则重设终点
				ani.value.x = x * 32 - core.bigmap.offsetX;
				ani.value.y = y * 32 - core.bigmap.offsetY;
				ani.endLoc = { x: x, y: y };
			}
		});
		transitionList.add(t);
		t.ticker.add(() => {
			core.drawIcon('_autoItem_', id, t.value.x, t.value.y, 32, 32);
			const { x, y } = core.status.hero.loc;
			if (Math.abs(t.value.x - x * 32 + core.bigmap.offsetX) < 0.05 && Math.abs(t.value.y - y * 32 + core.bigmap.offsetY) < 0.05) {
				t.ticker.destroy();
				transitionList.delete(t);
				if (transitionList.size === 0) core.removeFlag('endLoc');
			}
		});
	}

	function bfs(sx, sy, floorId) { //广搜可清理图块
		floorId = floorId || core.status.floorId;
		if (sx < 0 || sx > 12 || sy < 0 || sy > 12) return; //超过地图边缘

		const sLoc = [sx, sy].join(','),
			queue = [],
			checked = Array(13).fill().map(() => Array(13).fill(false));

		try { //如果当前点有地图伤害，则不清理，设置flag并在下次moveOneStep中清理
			if (core.status.checkBlock.repulse[sLoc] || core.status.checkBlock.damage[sLoc]) {
				//core.setFlag('onZone', true);
				return;
			}
		} catch (e) {}

		queue.push([sx, sy]); // 起点
		checked[sx][sy] = true;

		while (queue.length > 0) {
			const [x, y] = queue.shift(),
				loc = [x, y].join(','),
				cls = core.getBlockCls(x, y, floorId),
				id = core.getBlockId(x, y, floorId);
			//根据当前格子的可出方向，加周边格子加入检索范围
			for (var ele of ['up', 'right', 'down', 'left']) {
				const nx = x + core.utils.scan[ele].x,
					ny = y + core.utils.scan[ele].y;
				if (core.canMoveHero(x, y, ele) && passThrough(nx, ny) && (!checked[nx][ny])) {
					queue.push([nx, ny]);
					checked[nx][ny] = true;
				}
			}
			//当前格子是否可以清理
			if (passThrough(x, y) && canReturn(x, y)) {
				core.setFlag('__forbidSave__', true); //禁用自动存档
				if (cls && cls.startsWith('enemy')) {
					core.battle(id, x, y);
				}
				if (cls && ['items', 'tools', 'constants'].indexOf(cls) >= 0) { //物品有动画
					core.getItem(id, 1, x, y);
					if (!main.replayChecking) animationItem(id, x, y);
				}
				core.removeFlag('__forbidSave__'); //恢复
			}
		}
	}

	this.autoClean = function () {
		const autoGem = core.getFlag('autoGem', false),
			autoEnemy = core.getFlag('autoEnemy', false);
		if (!autoGem && !autoEnemy) return; //两者都未开启则不搜索，节约性能
		const ctx = core.getContextByName('_autoItem_');
		if (!ctx) core.createCanvas('_autoItem_', 0, 0, core._PX_ || core.__PIXELS__, core._PY_ || core.__PIXELS__, 75);
		//console.log(hero.loc, core.status.floorId,passThrough(4,4,'MT16'));
		bfs(core.status.hero.loc.x, core.status.hero.loc.y, core.status.floorId);
		//以下为古祠佬的动画
		if (main.replayChecking) return;
		transitionList.forEach(ani => {
			const { x, y } = core.status.hero.loc;
			ani.value.x = x * 32 - core.bigmap.offsetX;
			ani.value.y = y * 32 - core.bigmap.offsetY;
		})
	}

	core.events.afterChangeFloor = function (floorId) {
		if (main.mode != 'play') return;
		this.eventdata.afterChangeFloor(floorId);
		if (!core.hasFlag('__fromLoad__')) {
			core.updateCheckBlock(floorId); //更新地图伤害，以防万一。注：测试员发现此bug，但作者未成功复现
			core.plugin.autoClean();
		}
		return;
	}

	core.events.afterBattle = function (enemyId, x, y) {
		const res = this.eventdata.afterBattle(enemyId, x, y);
		//自动清理
		core.updateCheckBlock();
		core.plugin.autoClean();
		return res;
	}

	core.events.afterOpenDoor = function (doorId, x, y) {
		core.plugin.autoClean();
		return this.eventdata.afterOpenDoor(doorId, x, y);
	}

	core.control.checkBlock = function () {
		var x = core.getHeroLoc('x'),
			y = core.getHeroLoc('y'),
			loc = x + "," + y;
		var damage = core.status.checkBlock.damage[loc];
		if (damage) {
			core.status.hero.hp -= damage;
			core.setFlag('ontoZone', true); //走到有地图伤害的点时，如无法推开的阻击。此步在moveOneStep前，所以不能直接设置onZone
			var text = (Object.keys(core.status.checkBlock.type[loc] || {}).join("，")) || "伤害";
			core.drawTip("受到" + text + damage + "点");
			core.drawHeroAnimate("zone");
			this._checkBlock_disableQuickShop();
			core.status.hero.statistics.extraDamage += damage;
			if (core.status.hero.hp <= 0) {
				core.status.hero.hp = 0;
				core.updateStatusBar(false, true);
				core.events.lose();
				return;
			} else {
				core.updateStatusBar(false, true);
			}
		}
		this._checkBlock_ambush(core.status.checkBlock.ambush[loc]);
		this._checkBlock_repulse(core.status.checkBlock.repulse[loc]);
	}

	core.control._checkBlock_repulse = function (repulse) {
		const hp = core.getFlag('hp', {}),
			floorId = core.status.floorId;
		if (!repulse || repulse.length == 0) return;
		var actions = [];
		repulse.forEach(function (t) {
			const x = t[0],
				y = t[1],
				dir = t[3];
			if (hp && hp[floorId]) {
				const m = { 'up': { x: 0, y: -1 }, 'down': { x: 0, y: 1 }, 'left': { x: -1, y: 0 }, 'right': { x: 1, y: 0 } };
				if (hp[floorId][x][y]) { //阻击怪被情势揍过
					hp[floorId][x + m[dir].x][y + m[dir].y] = hp[floorId][x][y];
					hp[floorId][x][y] = 0;
					core.setFlag('hp', hp);
				}
			}
			actions.push({ "type": "move", "loc": [x, y], "steps": [dir], "time": 250, "keep": true, "async": true });
		});
		actions.push({ "type": "waitAsync" });
		actions.push({ "type": "function", "function": "function(){core.plugin.autoClean()}" }) //推开阻击后自动清理
		core.insertAction(actions);
	}

	core.control.moveOneStep = function (callback) {
		const res = this.controldata.moveOneStep(callback);
		if (core.hasFlag('onZone')) { //从有地图伤害的点走出时
			core.plugin.autoClean();
			core.removeFlag('onZone');
		} else if (core.hasFlag('ontoZone')) { //刚走入有地图伤害的点时
			core.removeFlag('ontoZone');
			core.setFlag('onZone', true);
		}
		return res;
	};
},
    "statisticsDetail": function () {

	core.ui._drawStatistics = function (floorIds) {
		core.playSound('打开界面');
		var obj = this._drawStatistics_buildObj();
		if (typeof floorIds == 'string') floorIds = [floorIds];
		(floorIds || core.floorIds).forEach(function (floorId) {
			core.ui._drawStatistics_floorId(floorId, obj);
		});
		var statistics = core.status.hero.statistics;
		core.setFlag("__replayText__", true);
		core.drawText([
			this._drawStatistics_generateText(obj, "全塔", obj.total),
			this._drawStatistics_generateText(obj, "当前", obj.current),
			this._drawStatistics_generateText(obj, "标记（浏览地图时B键或左下角）", obj.marked),
			"当前总步数：" + core.status.hero.steps + "，当前游戏时长：" + core.formatTime(statistics.currTime) +
			"，总游戏时长" + core.formatTime(statistics.totalTime) +
			"。\n瞬间移动次数：" + statistics.moveDirectly + "，共计少走" + statistics.ignoreSteps + "步。" +
			"\n\n总计通过血瓶恢复生命值为" + core.formatBigNumber(statistics.hp) + "点。\n\n" +
			"总计打死了" + statistics.battle + "个怪物，得到了" + core.formatBigNumber(statistics.money) + "宝珠，" + core.formatBigNumber(statistics.exp) + "点功勋。\n\n" +
			"受到的总伤害为" + core.formatBigNumber(statistics.battleDamage + statistics.poisonDamage + statistics.extraDamage) +
			"，其中战斗伤害" + core.formatBigNumber(statistics.battleDamage) + "点" +
			(core.flags.statusBarItems.indexOf('enableDebuff') >= 0 ? ("，中毒伤害" + core.formatBigNumber(statistics.poisonDamage) + "点") : "") +
			"，领域/夹击/阻击/血网伤害" + core.formatBigNumber(statistics.extraDamage) + "点。\n" +
			"\n击败\r[#55FFAA]0\r伤害敌人" + statistics.zeroDamage + "个，击败\r[#FFFF77]1-30\r伤害的敌人" + statistics.thrDamage + "个，击败\r[#FFAA55]31-100\r伤害的敌人" + statistics.hunDamage + "个，击败\r[#FF4444]500+\r伤害的敌人" + statistics.bigDamage + "个。最大战斗伤害为\r[#FF4444]" + statistics.maxDamage.damage + "\r点，来源为\r[#DD5588]" + (statistics.maxDamage.id ? core.getEnemys()[statistics.maxDamage.id].name : '无') + "\r。",
			"\t[说明]1. 地图数据统计的效果仅模拟当前立刻获得该道具的效果。\n2. 不会计算“不可被浏览地图”的隐藏层的数据。\n" +
			"3. 不会计算任何通过事件得到的道具（显示事件、改变图块、或直接增加道具等）。\n" +
			"4. 在自定义道具（例如其他宝石）后，需在脚本编辑的drawStatistics中注册，不然不会进行统计。\n" +
			"5. 道具不会统计通过插入事件或useItemEvent实现的效果。\n6. 所有统计信息仅供参考，如有错误，概不负责。"
		])
		core.removeFlag("__replayText__");
	}

	this.cal = function (gold) {
		let g = gold - 250,
			max = 0,
			plan = [];
		if (g <= 0) return 0;

		let spent = function (init, times) {
			return init * times + times * (times - 1) / 2;
		}

		let lim = Math.floor(Math.sqrt(g));
		for (let i = 0; i < lim; i++)
			for (let j = 0; j < lim; j++)
				for (let k = 0; k < lim; k++)
					if (spent(15, i) + spent(15 + Math.floor(i / 5), j) + spent(15 + Math.floor((Math.floor(i / 5) + j) / 2), k) <= g) {
						if (i + j + k > max) {
							max = i + j + k;
							plan = [
								[i, j, k]
							];
						} else if (i + j + k === max) plan.push([i, j, k]);
					}
		let text = '最多购买' + max + '次商店。共有' + plan.length + '种购买方案。购买A次后200宝珠降价，再购买B次后50宝珠降价，最后还能购买C次。下面是所有可能的ABC组合:';
		for (let i in plan) {
			text += plan[i] + '  ';
		}
		return text;
	}
}
}