CBR_h_event_data = null;

DataManager._databaseFiles.push({ name: "CBR_h_event_data", src: "CBR_h_event_data.json" });

Window_Base.prototype.drawTextS = function (text, x, y, maxWidth, align) {
	this.contents.drawTextS(text, x, y, maxWidth, this.lineHeight(), align);
};
Bitmap.prototype.drawTextS = function (text, x, y, maxWidth, lineHeight, align) {
	// [Note] Different browser makes different rendering with
	//   textBaseline == 'top'. So we use 'alphabetic' here.
	const context = this.context;
	const alpha = context.globalAlpha;
	maxWidth = maxWidth || 0xffffffff;
	let tx = x;
	let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35);
	if (align === "center") {
		tx += maxWidth / 2;
	}
	if (align === "right") {
		tx += maxWidth;
	}
	context.save();
	context.font = this._makeFontNameText();
	context.textAlign = align || "left";
	context.textBaseline = "alphabetic";
	context.globalAlpha = 1;
	//this._drawTextOutline(text, tx, ty, maxWidth);
	context.globalAlpha = alpha;
	this._drawTextBody(text, tx, ty, maxWidth);
	context.restore();
	this._baseTexture.update();
};

Window_Base.prototype.drawTextM = function (text, x, y, maxWidth, align) {
	this.contents.drawTextM(text, x, y, maxWidth, this.lineHeight(), align);
};
Bitmap.prototype.drawTextM = function (text, x, y, maxWidth, lineHeight, align) {
	// [Note] Different browser makes different rendering with
	//   textBaseline == 'top'. So we use 'alphabetic' here.
	const context = this.context;
	const alpha = context.globalAlpha;
	maxWidth = maxWidth || 0xffffffff;
	let tx = x;
	let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35);
	if (align === "center") {
		tx += maxWidth / 2;
	}
	if (align === "right") {
		tx += maxWidth;
	}
	context.save();
	context.font = this._makeFontNameText();
	context.textAlign = align || "left";
	context.textBaseline = "alphabetic";
	context.globalAlpha = 1;
	this._drawTextOutlineM(text, tx, ty, maxWidth);
	context.globalAlpha = alpha;
	this._drawTextBody(text, tx, ty, maxWidth);
	context.restore();
	this._baseTexture.update();
};

Bitmap.prototype._drawTextOutlineM = function (text, tx, ty, maxWidth) {
	const context = this.context;
	context.strokeStyle = this.textColor;
	context.lineWidth = 1;
	context.lineJoin = "round";
	context.strokeText(text, tx, ty, maxWidth);
};

Window_Base.prototype.drawTextExS = function (text, x, y, width) {
	//this.resetFontSettings();
	const textState = this.createTextState(text, x, y, width);
	this.processAllTextS(textState);
	return textState.outputWidth;
};

Window_Base.prototype.processAllTextS = function (textState) {
	while (textState.index < textState.text.length) {
		this.processCharacterS(textState);
	}
	this.flushTextStateS(textState);
};
Window_Base.prototype.processCharacterS = function (textState) {
	const c = textState.text[textState.index++];
	if (c.charCodeAt(0) < 0x20) {
		this.flushTextStateS(textState);
		this.processControlCharacterS(textState, c);
	} else {
		textState.buffer += c;
	}
};
Window_Base.prototype.processControlCharacterS = function (textState, c) {
	if (c === "\n") {
		this.processNewLineS(textState);
	}
	if (c === "\x1b") {
		const code = this.obtainEscapeCode(textState);
		this.processEscapeCharacter(code, textState);
	}
};

Window_Base.prototype.processNewLineS = function (textState) {
	textState.x = textState.startX;
	textState.y += textState.height - 3;
	textState.height = this.calcTextHeight(textState);
};

Window_Base.prototype.flushTextStateS = function (textState) {
	const text = textState.buffer;
	const rtl = textState.rtl;
	const width = this.textWidth(text);
	const height = textState.height;
	const x = rtl ? textState.x - width : textState.x;
	const y = textState.y;
	if (textState.drawing) {
		this.contents.drawTextS(text, x, y, width, height);
	}
	textState.x += rtl ? -width : width;
	textState.buffer = this.createTextBuffer(rtl);
	const outputWidth = Math.abs(textState.x - textState.startX);
	if (textState.outputWidth < outputWidth) {
		textState.outputWidth = outputWidth;
	}
	textState.outputHeight = y - textState.startY + height;
};

Window_Base.prototype.drawTextExM = function (text, x, y, width) {
	//this.resetFontSettings();
	const textState = this.createTextState(text, x, y, width);
	this.processAllTextM(textState);
	return textState.outputWidth;
};

Window_Base.prototype.processAllTextM = function (textState) {
	while (textState.index < textState.text.length) {
		this.processCharacterM(textState);
	}

	this.flushTextStateM(textState);
};
Window_Base.prototype.processCharacterM = function (textState) {
	const c = textState.text[textState.index++];
	if (c.charCodeAt(0) < 0x20) {
		this.flushTextStateM(textState);
		this.processControlCharacterM(textState, c);
	} else {
		textState.buffer += c;
	}
};
Window_Base.prototype.processControlCharacterM = function (textState, c) {
	if (c === "\n") {
		this.processNewLineM(textState);
	}
	if (c === "\x1b") {
		const code = this.obtainEscapeCode(textState);
		this.processEscapeCharacter(code, textState);
	}
};

Window_Base.prototype.processNewLineM = function (textState) {
	textState.x = textState.startX;
	textState.y += textState.height - 3;
	textState.height = this.calcTextHeight(textState);
};

Window_Base.prototype.flushTextStateM = function (textState) {
	const text = textState.buffer;
	const rtl = textState.rtl;
	const width = this.textWidth(text);
	const height = textState.height;
	const x = rtl ? textState.x - width : textState.x;
	const y = textState.y;
	if (textState.drawing) {
		this.contents.drawTextM(text, x, y, width, height);
	}
	textState.x += rtl ? -width : width;
	textState.buffer = this.createTextBuffer(rtl);
	const outputWidth = Math.abs(textState.x - textState.startX);
	if (textState.outputWidth < outputWidth) {
		textState.outputWidth = outputWidth;
	}
	textState.outputHeight = y - textState.startY + height;
};

//ゲージのラベルをちょっと右に
Sprite_Gauge.prototype.drawLabel = function () {
	const label = this.label();
	const x = this.labelOutlineWidth() / 2 + 4;
	const y = this.labelY();
	const width = this.bitmapWidth();
	const height = this.textHeight();
	this.setupLabelFont();
	this.bitmap.paintOpacity = this.labelOpacity();
	this.bitmap.drawText(label, x, y, width, height, "left");
	this.bitmap.paintOpacity = 255;
};
Sprite_Gauge.prototype.currentValue = function () {
	if (this._battler) {
		switch (this._statusType) {
			case "hp":
				return this._battler.hp;
			case "mp":
				return this._battler.mp;
			case "exp":
				return this._battler.nextLevelExp() - this._battler.currentLevelExp() - this._battler.nextRequiredExp();
			case "tp":
				return this._battler.tp;
			case "time":
				return this._battler.tpbChargeTime();
		}
	}
	return NaN;
};

Sprite_Gauge.prototype.currentMaxValue = function () {
	if (this._battler) {
		switch (this._statusType) {
			case "hp":
				return this._battler.mhp;
			case "mp":
				return this._battler.mmp;
			case "exp":
				return this._battler.nextLevelExp() - this._battler.currentLevelExp();
			case "tp":
				return this._battler.maxTp();
			case "time":
				return 1;
		}
	}
	return NaN;
};

//ゲージの数値
Sprite_Gauge.prototype.drawValue = function () {
	let currentValue = this.currentValue();
	switch (this._statusType) {
		case "hp":
			currentValue += ` / ${this._battler.mhp}`;
			break;
		case "mp":
			currentValue += ` / ${this._battler.mmp}`;
			break;
	}
	const width = this.bitmapWidth();
	const height = this.textHeight();
	this.setupValueFont();
	this.bitmap.drawText(currentValue, 0, 0, width, height, "right");
};

Sprite_Gauge.prototype.label = function () {
	switch (this._statusType) {
		case "hp":
			return TextManager.hpA;
		case "mp":
			return TextManager.mpA;
		case "exp":
			return "次のレベルまで";
		case "tp":
			return TextManager.tpA;
		default:
			return "";
	}
};
Sprite_Gauge.prototype.valueColor = function () {
	switch (this._statusType) {
		case "hp":
			return ColorManager.hpColor(this._battler);
		case "mp":
			return ColorManager.mpColor(this._battler);
		case "exp":
			return "#FFFFFF";
		case "tp":
			return ColorManager.tpColor(this._battler);
		default:
			return ColorManager.normalColor();
	}
};

Sprite_Gauge.prototype.gaugeColor1 = function () {
	switch (this._statusType) {
		case "hp":
			return "#00E19C";
		case "mp":
			return "#019BE1";
		case "exp":
			return "#FFFFFF";
		case "tp":
			return ColorManager.tpGaugeColor1();
		case "time":
			return ColorManager.ctGaugeColor1();
		default:
			return ColorManager.normalColor();
	}
};
Sprite_Gauge.prototype.gaugeColor2 = function () {
	switch (this._statusType) {
		case "hp":
			return "#00E19C";
		case "mp":
			return "#019BE1";
		case "exp":
			return "#FFFFFF";
		case "tp":
			return ColorManager.tpGaugeColor2();
		case "time":
			return ColorManager.ctGaugeColor2();
		default:
			return ColorManager.normalColor();
	}
};

function Sprite_Gauge_Battle() {
	this.initialize(...arguments);
}
Sprite_Gauge_Battle.prototype = Object.create(Sprite_Gauge.prototype);
Sprite_Gauge_Battle.prototype.constructor = Sprite_Gauge_Battle;
//ゲージセットの枠の位置
Sprite_Gauge_Battle.prototype.bitmapHeight = function () {
	return 48;
};

//ゲージの位置と大きさ調整
Sprite_Gauge_Battle.prototype.gaugeX = function () {
	return 0;
};
Sprite_Gauge_Battle.prototype.drawGauge = function () {
	const gaugeX = this.gaugeX();
	const gaugeY = this.textHeight() - this.gaugeHeight() + 12;
	const gaugewidth = this.bitmapWidth() - gaugeX;
	const gaugeHeight = this.gaugeHeight();
	this.drawGaugeRect(gaugeX, gaugeY, gaugewidth, gaugeHeight);
};
Sprite_Gauge_Battle.prototype.bitmapWidth = function () {
	return 156;
};
Sprite_Gauge_Battle.prototype.gaugeHeight = function () {
	return 12;
};

//ゲージのフォントと色
Sprite_Gauge_Battle.prototype.setupLabelFont = function () {
	this.bitmap.fontFace = this._statusType == "exp" ? "serif" : "Times New Roman";
	this.bitmap.fontSize = this._statusType == "exp" ? 18 : this.labelFontSize();
	this.bitmap.textColor = "#FFFFFF";
	this.bitmap.outlineColor = this.labelOutlineColor();
	this.bitmap.outlineWidth = this.labelOutlineWidth();
};

Sprite_Gauge_Battle.prototype.labelY = function () {
	return 0;
};
//フォント
Sprite_Gauge_Battle.prototype.setupValueFont = function () {
	this.bitmap.fontFace = this._statusType == "exp" ? "serif" : "Times New Roman";
	this.bitmap.fontSize = this._statusType == "exp" ? 18 : this.valueFontSize() + 2;
	this.bitmap.textColor = this.valueColor();
	this.bitmap.outlineColor = this.valueOutlineColor();
	this.bitmap.outlineWidth = this.valueOutlineWidth();
};

//メニュー画面で使うゲージ
function Sprite_Gauge_Menu() {
	this.initialize(...arguments);
}
Sprite_Gauge_Menu.prototype = Object.create(Sprite_Gauge_Battle.prototype);
Sprite_Gauge_Menu.prototype.constructor = Sprite_Gauge_Menu;

Sprite_Gauge_Menu.prototype.drawGaugeRect = function (x, y, width, height) {
	var padding = 4;
	x += padding;
	width -= padding * 2;

	const rate = this.gaugeRate();
	const fillW = Math.floor((width - 2) * rate);
	const fillH = height - 2;
	const color0 = this.gaugeBackColor();

	//グラデーションの描写
	const ctx = this.bitmap.context;
	if (this._statusType != "exp") {
		const grd = ctx.createLinearGradient(0, -20, 220, 0);
		if (this._statusType == "hp") {
			grd.addColorStop(0, "rgba(0,225,155,1)");
			grd.addColorStop(1, "rgba(0,0,0,0)");
		} else {
			grd.addColorStop(0, "rgba(0,155,225,1)");
			grd.addColorStop(1, "rgba(0,0,0,0)");
		}
		ctx.fillStyle = grd;
		ctx.fillRect(x - 10, y - 20, width + 10, height + 40);
	}

	ctx.fillStyle = "rgba(90, 90, 90, 1)";
	ctx.fillRect(x - 3, y + 8, width, height);

	const color1 = this.gaugeColor1();
	const color2 = this.gaugeColor2();
	y += padding;
	this.bitmap.fillRect(x, y, width, height, color0);
	this.bitmap.gradientFillRect(x + 1, y + 1, fillW, fillH, color1, color2);
};

//ゲージのラベルをちょっと右に
Sprite_Gauge_Menu.prototype.drawLabel = function () {
	const label = this.label();
	var x = this.labelOutlineWidth() / 2;
	var y = this.labelY();
	var width = this.bitmapWidth();
	const height = this.textHeight();

	var padding = 4;
	x += padding;
	width -= padding * 2;
	y += padding;

	this.setupLabelFont();
	this.bitmap.paintOpacity = this.labelOpacity();
	this.bitmap.drawText(label, x, y, width, height, "left");
	this.bitmap.paintOpacity = 255;
};
//ゲージの数値
Sprite_Gauge_Menu.prototype.drawValue = function () {
	let currentValue = this.currentValue();
	switch (this._statusType) {
		case "hp":
			currentValue += ` / ${this._battler.mhp}`;
			break;
		case "mp":
			currentValue += ` / ${this._battler.mmp}`;
			break;
	}
	var width = this.bitmapWidth();
	const height = this.textHeight();

	var padding = 4;
	width -= padding * 2;

	this.setupValueFont();
	this.bitmap.drawText(currentValue, 0, padding, width, height, "right");
};

Sprite_Gauge_Menu.prototype.bitmapWidth = function () {
	return 200;
};

function Sprite_Gauge_Main_Menu() {
	this.initialize(...arguments);
}
Sprite_Gauge_Main_Menu.prototype = Object.create(Sprite_Gauge_Menu.prototype);
Sprite_Gauge_Main_Menu.prototype.constructor = Sprite_Gauge_Main_Menu;

Sprite_Gauge_Main_Menu.prototype.bitmapWidth = function () {
	return 204;
};

Sprite_Gauge_Main_Menu.prototype.drawValue = function () {
	let currentValue = this.currentValue();
	switch (this._statusType) {
		case "hp":
			currentValue += ` / ${this._battler.mhp}`;
			break;
		case "mp":
			currentValue += ` / ${this._battler.mmp}`;
			break;
		case "exp":
			if (99 <= this._battler._level) {
				currentValue = 0;
			} else {
				currentValue = this.currentMaxValue() - currentValue;
			}
			break;
	}
	var width = this.bitmapWidth();
	const height = this.textHeight();

	var padding = 4;
	width -= padding * 2;

	this.setupValueFont();
	this.bitmap.drawText(currentValue, 0, padding, width, height, "right");
};

Window_Command.prototype.commandExt = function (index) {
	return this._list[index].ext;
};

Window_Options.prototype.volumeOffset = function () {
	return 10;
};

// 元の速度を取得し、1.3倍にするよう補正
Game_CharacterBase.prototype.realMoveSpeed = function () {
	return this._moveSpeed + (this.isDashing() ? 1 + 0.7 : 0.7);
};

Video._onEnd = function () {
	this._element.pause();
	this._updateVisibility(false);
};

// 他の奴に上書きされるけどねココ
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function () {
	_Scene_Map_update.call(this);

	// マウスクリック検知 & 動画再生中チェック
	if (Input.isTriggered("ok") || TouchInput.isTriggered()) {
		if (Video.isPlaying()) {
			Video._onEnd();
		}

		// MoviePicture.js
		if ($gameScreen._pictures[11] && $gameScreen._pictures[11].isVideoWait()) {
			$gameScreen.erasePicture(11);
		}
	}
};

Game_Action.prototype.applyGlobal = function () {
	for (const effect of this.item().effects) {
		if (effect.code === Game_Action.EFFECT_COMMON_EVENT) {
			if (!this.item().meta.disable_common_in_menu || SceneManager._scene.constructor.name !== "Scene_Item") {
				$gameTemp.reserveCommonEvent(effect.dataId);
			}
		}
	}
	this.updateLastUsed();
	this.updateLastSubject();
};

Sprite_Balloon.prototype.speed = function () {
	return 4;
};

(() => {
	// ▼ コマンドリストに「テスト」を追加
	const _Window_TitleCommand_makeCommandList = Window_TitleCommand.prototype.makeCommandList;
	Window_TitleCommand.prototype.makeCommandList = function () {
		_Window_TitleCommand_makeCommandList.call(this);
		this.addCommand("Extra", "extraTest");
	};

	// ▼ ハンドラを登録
	const _Scene_Title_createCommandWindow = Scene_Title.prototype.createCommandWindow;
	Scene_Title.prototype.createCommandWindow = function () {
		_Scene_Title_createCommandWindow.call(this);
		this._commandWindow.setHandler("extraTest", this.commandExtraTest.bind(this));
	};

	// ▼ 選択時の処理
	Scene_Title.prototype.commandExtraTest = function () {
		SceneManager.push(Scene_Extra);
	};

	// ピクチャの回想を追加
	const Game_Screen_showPicture = Game_Screen.prototype.showPicture;
	Game_Screen.prototype.showPicture = function (pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode) {
		Game_Screen_showPicture.call(this, pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode);

		var name_id = name.slice(0, 8);
		var data_idx = CBR_extra_pic_list.findIndex((item) => item.name === name_id);
		if (data_idx !== -1) {
			const ary = $gameVariables.value(521) || [];
			if (!ary.includes(data_idx)) {
				ary.push(data_idx);
				ary.sort(function (a, b) {
					a - b;
				});
				$gameVariables.setValue(521, ary);
			}
		}
	};
})();

// タイトルにエクストラ全開放を追加
(() => {
	const _Window_TitleCommand_makeCommandList = Window_TitleCommand.prototype.makeCommandList;
	Window_TitleCommand.prototype.makeCommandList = function () {
		_Window_TitleCommand_makeCommandList.apply(this, arguments);
		this.addCommand("Unlock Extra", "extra_open");
	};

	const _Scene_Title_createCommandWindow = Scene_Title.prototype.createCommandWindow;
	Scene_Title.prototype.createCommandWindow = function () {
		_Scene_Title_createCommandWindow.apply(this, arguments);
		this._commandWindow.setHandler("extra_open", this.commandToggleTest.bind(this));
	};

	Scene_Title.prototype.commandToggleTest = function () {
		SoundManager.playOk();
		$gameSwitches.setValue(778, !$gameSwitches.value(778)); // トグル状態を保持
		this._commandWindow.refresh();

		// 再び入力可能にする（重要）
		this._commandWindow.activate();
	};

	const _Window_TitleCommand_drawItem = Window_TitleCommand.prototype.drawItem;
	Window_TitleCommand.prototype.drawItem = function (index) {
		const rect = this.itemLineRect(index);
		const name = this.commandName(index);
		if (this.commandSymbol(index) === "extra_open") {
			//const color = !$gameSwitches.value(778) ? "#777777" : "#ffffff"; // 暗⇄明
			const color = !$gameSwitches.value(778) ? "#ffffff" : "#777777"; // 暗⇄明
			this.changeTextColor(color);
			this.drawText(name, rect.x, rect.y, rect.width, "center");
			this.resetTextColor();
			ConfigManager.saveCommonVariables();
		} else {
			_Window_TitleCommand_drawItem.apply(this, arguments);
		}
	};
})();

Scene_Title.prototype.commandWindowRect = function () {
	const offsetX = $dataSystem.titleCommandWindow.offsetX;
	const offsetY = $dataSystem.titleCommandWindow.offsetY;
	const ww = this.mainCommandWidth();
	const wh = this.calcWindowHeight(5, true);
	const wx = 100;
	const wy = 270;
	return new Rectangle(wx, wy, ww, wh);
};

// アイテムを使う時、使用効果でコモンがあると、defaultでtrueを返して使えてしまう
Game_Action.prototype.testItemEffect = function (target, effect) {
	switch (effect.code) {
		case Game_Action.EFFECT_RECOVER_HP:
			return target.hp < target.mhp || effect.value1 < 0 || effect.value2 < 0;
		case Game_Action.EFFECT_RECOVER_MP:
			return target.mp < target.mmp || effect.value1 < 0 || effect.value2 < 0;
		case Game_Action.EFFECT_ADD_STATE:
			return !target.isStateAffected(effect.dataId);
		case Game_Action.EFFECT_REMOVE_STATE:
			return target.isStateAffected(effect.dataId);
		case Game_Action.EFFECT_ADD_BUFF:
			return !target.isMaxBuffAffected(effect.dataId);
		case Game_Action.EFFECT_ADD_DEBUFF:
			return !target.isMaxDebuffAffected(effect.dataId);
		case Game_Action.EFFECT_REMOVE_BUFF:
			return target.isBuffAffected(effect.dataId);
		case Game_Action.EFFECT_REMOVE_DEBUFF:
			return target.isDebuffAffected(effect.dataId);
		case Game_Action.EFFECT_LEARN_SKILL:
			return target.isActor() && !target.isLearnedSkill(effect.dataId);
		case Game_Action.EFFECT_COMMON_EVENT: // コモン1132の場合のみ、コモン(default)でtrueとならずfalseを返す
			return effect.dataId !== 1132;
		default:
			return true;
	}
};

//----------------------------------------------------
//■コモンイベントの処理
//----------------------------------------------------
var SDN_EventAct = function (commonEventName) {
	var idx = $dataCommonEvents.findIndex((e) => e && e.name == commonEventName);
	if (idx === -1) {
		$gameMessage.add("未実装のイベントです");
	} else {
		$gameTemp.reserveCommonEvent(idx);
	}
};
//----------------------------------------------------
//■コモンイベントの番号を取得する
//----------------------------------------------------
var SDN_GetCommonEventID = function (commonEventName) {
	return $dataCommonEvents.findIndex((e) => e && e.name == commonEventName);
};
//----------------------------------------------------
//■改造セルフスイッチ
//----------------------------------------------------
var SDN_SelfSwith = function (MapId, EventId, SwitchName, Value) {
	key = [MapId, EventId, SwitchName];
	$gameSelfSwitches.setValue(key, Value);
};
//----------------------------------------------------
//■立ち絵の表示
//----------------------------------------------------
var SDN_SetFgImage = function (chara, posit, pose) {
	//キャラの座標を取得する
	if (chara == "sir" && pose == 1) {
		var pos = [390, 31, -80, 445];
	} else if (chara == "sir" && pose == 2) {
		var pos = [390, 31, -80, 445];
	} else if (chara == "sir" && pose == 3) {
		var pos = [330, 31, -100, 445];
	} else if (chara == "sir" && pose == 4) {
		var pos = [330, 31, -100, 445];
	} else if (chara == "yoz" && pose == 1) {
		var pos = [412, 19, -80, 445];
	} else if (chara == "yoz" && pose == 2) {
		var pos = [412, 19, -80, 445];
	} else if (chara == "yoz" && pose == 3) {
		var pos = [451, 22, -35, 445];
	} else if (chara == "yoz" && pose == 4) {
		var pos = [451, 22, -35, 445];
	} else if (chara == "rei" && pose == 1) {
		var pos = [350, 10, -140, 445];
	} else if (chara == "rei" && pose == 2) {
		var pos = [367, 37, -132, 440];
	} else if (chara == "kao" && pose == 1) {
		var pos = [390, 26, -80, 445];
	} else if (chara == "kur" && pose == 1) {
		var pos = [400, 130, -80, 465];
	} else if (chara == "chi" && pose == 1) {
		var pos = [390, 0, -80, 445];
	} else if (chara == "mir" && pose == 1) {
		var pos = [430, 51, -40, 445];
	} else if (chara == "aki" && pose == 1) {
		var pos = [444, -10, -50, 445];
	} else if (chara == "nar" && pose == 1) {
		var pos = [440, 0, -30, 445];
	} else if (chara == "kag" && pose == 1) {
		var pos = [269, 0, -220, 420];
	}
	//位置設定
	if (posit == "l") {
		var lay = 6;
		var x = pos[0] - 550;
		var y = pos[1];
	} else if (posit == "cl") {
		var lay = 4;
		var x = pos[0] - 350;
		var y = pos[1];
	} else if (posit == "c") {
		var lay = 8;
		var x = pos[0];
		var y = pos[1];
	} else if (posit == "cr") {
		var lay = 5;
		var x = pos[0] + 350;
		var y = pos[1];
	} else if (posit == "r") {
		var lay = 7;
		var x = pos[0] + 550;
		var y = pos[1];
	} else if (posit == "face") {
		var lay = 9;
		var x = pos[2];
		var y = pos[3];
	}
	//実行
	if (posit != "face") {
		$gameScreen.showPicture(lay, "", 0, x, y, 100, 100, 255, 0);
	} else {
		$gameScreen.showPicture(lay, "", 0, x, y, 80, 80, 255, 0);
	}
};

//----------------------------------------------------
//■操作キャラが妊娠しているかどうかを判別する
//----------------------------------------------------
var SDN_PlayerNowPregnancy = function () {
	if ($gameSwitches.value(117) && $gameVariables.value(204) >= 2) {
		return true;
	} else if ($gameSwitches.value(118) && $gameVariables.value(205) >= 2) {
		return true;
	} else {
		return false;
	}
};

//----------------------------------------------------
//■臨月中のキャラがいるかどうか？
//----------------------------------------------------
var SDN_CharaNowPregnancy = function () {
	if ($gameVariables.value(204) >= 2 || $gameVariables.value(205) >= 2) {
		return true;
	} else {
		return false;
	}
};
//----------------------------------------------------
//■ファストトラベル実行前
//----------------------------------------------------
//ファストトラベル可能な場所のスイッチをＯＮにするためのもの
var SDN_SetFastTravel = function () {
	//ファストトラベル設置用の開始スイッチＮＯを定義
	var FastSwNum = 371;
	//初期化
	for (var i = 371; i <= 399; i++) {
		$gameSwitches.setValue(i, false);
	}
	//抜けていた分の処理
	$gameSwitches.setValue(403, false);
	$gameSwitches.setValue(404, false);
	//ボテ腹状態ではない場合
	if (SDN_CharaNowPregnancy() == false) {
		//夜専用マップの設定
		var NightOnly = [343, 346, 354, 356, 358];
		var NightOnlySet = [372, 375, 383, 385, 387];
		//昼の場合（昼を表すスイッチＮＯは今回114）
		if ($gameSwitches.value(114) == true) {
			for (var i = 342; i <= 370; i++) {
				if ($gameSwitches.value(i) == true) {
					$gameSwitches.setValue(FastSwNum, true);
				}
				FastSwNum = FastSwNum + 1;
			}
			//昼夜分かれているＭＡＰで昼ＭＡＰは強制的にfalseにする
			for (var i = 0; i < NightOnlySet.length; i++) {
				$gameSwitches.setValue(NightOnlySet[i], false);
			}
			//抜け分の処理
			if ($gameSwitches.value(401)) {
				$gameSwitches.setValue(403, true);
			}
			if ($gameSwitches.value(402)) {
				$gameSwitches.setValue(404, true);
			}
		} else {
			//夜の場合
			for (var i = 0; i < NightOnly.length; i++) {
				if ($gameSwitches.value(NightOnly[i])) {
					$gameSwitches.setValue(NightOnlySet[i], true);
				}
			}
			//昼夜あるマップの例外処理
			if ($gameSwitches.value(367)) {
				$gameSwitches.setValue(396, true);
			}
		}
		//ボテ腹状態のもの
	} else {
		if ($gameSwitches.value(114)) {
			var PregnancyMap = [342, 345, 367];
			var PregnancyMapSet = [371, 374, 396];
		} else {
			var PregnancyMap = [343, 346, 367];
			var PregnancyMapSet = [372, 375, 396];
		}
		for (var i = 0; i < PregnancyMap.length; i++) {
			if ($gameSwitches.value(PregnancyMap[i])) {
				$gameSwitches.setValue(PregnancyMapSet[i], true);
			}
		}
	}
};
//----------------------------------------------------
//■宝箱の処理
//----------------------------------------------------
var SDN_ActChest = function (itemType, itemId, itemvalue) {
	//獲得するものの種類を定義する
	if (itemType == "I" || itemType == "アイテム" || itemType == "Item") {
		var setKey = "I";
	} else if (itemType == "W" || itemType == "アクセサリー" || itemType == "アクセ" || itemType == "Accessory") {
		var setKey = "W";
	} else if (itemType == "P" || itemType == "パッシブスキル" || itemType == "PS" || itemType == "PassiveSkill") {
		var setKey = "A";
	} else if (itemType == "M" || itemType == "お金" || itemType == "金" || itemType == "Money") {
		var setKey = "M";
	}
	//キーごとの取得処理
	if (setKey == "I") {
		$gameParty.gainItem($dataItems[itemId], itemvalue);
		//インフォ用の文字列取得
		$gameVariables.setValue(4, "『" + $dataItems[itemId].name + "』×" + itemvalue + " 入手！");
		$gameVariables.setValue(5, $dataItems[itemId].iconIndex);
	} else if (setKey == "W") {
		$gameParty.gainItem($dataWeapons[itemId], itemvalue);
		//インフォ用の文字列取得
		$gameVariables.setValue(4, "『" + $dataWeapons[itemId].name + "』×" + itemvalue + " 入手！");
		$gameVariables.setValue(5, $dataWeapons[itemId].iconIndex);
	} else if (setKey == "A") {
		$gameParty.gainItem($dataArmors[itemId], itemvalue);
		//インフォ用の文字列取得
		if ($dataArmors[itemId].atypeId == 1) {
			var chaTarget = "白雪が";
		} else {
			var chaTarget = "夜鶴が";
		}
		$gameVariables.setValue(4, chaTarget + "パッシブスキル『" + $dataArmors[itemId].name + "』を習得した");
		$gameVariables.setValue(5, $dataArmors[itemId].iconIndex);
		//説明用のコモンイベントトリガーを入れる処理
		if (!$gameSwitches.value(164)) {
			$gameSwitches.setValue(163, true);
		}
	} else if (setKey == "M") {
		$gameParty.gainGold(itemvalue);
		//インフォ用の文字列取得
		$gameVariables.setValue(4, itemvalue + "円" + " 入手！");
		$gameVariables.setValue(5, 87);
	}
};
//----------------------------------------------------
//■イベントＣＧの処理（ファイル名取得の処理）
//----------------------------------------------------
var SDN_GetEvFileName = function (fileName, costume) {
	if (costume == false) {
		var fileName = fileName;
	} else {
		//服装分岐、今作は変数３番を使用する
		var strCosNum = $gameVariables.value(3);
		if (fileName.substring(0, 3) == "eva") {
			strCosNum = $gameVariables.value(204);
		} else if (fileName.substring(0, 3) == "evb") {
			strCosNum = $gameVariables.value(205);
		}
		//例外処理
		var exfileName = fileName.substring(0, 8);
		if (exfileName == "eva_c051" || exfileName == "eva_c060" || exfileName == "eva_c061") {
			if ($gameVariables.value(204) == 2) {
				strCosNum = 0;
			} else if ($gameVariables.value(204) == 3) {
				strCosNum = 1;
			}
		}
		if (exfileName == "evb_c051" || exfileName == "evb_c060" || exfileName == "evb_c061") {
			if ($gameVariables.value(205) == 2) {
				strCosNum = 0;
			} else if ($gameVariables.value(205) == 3) {
				strCosNum = 1;
			}
		}
		var fileName = fileName + "_" + strCosNum.toString();
	}
	return fileName;
};
//----------------------------------------------------
//■現在いるＭＡＰのタイプを取得
//※スマフォ操作や妊娠システム関係で使うもの
// 1 : アイリスアカデミー
// 2 : 神宿
// 3 : 渋野
// 4 : ダリアのアジト
//----------------------------------------------------
var SDN_GetTownType = function () {
	//アイリスアカデミーかどうか？
	var ary = [
		10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
		45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56
	];
	for (let i = 0; i < ary.length; i++) {
		if (ary[i] == $gameMap.mapId()) {
			return 1;
		}
	}
	//神宿かどうか？
	var ary = [72, 73, 74, 75, 76, 77, 78, 81, 82, 83, 84, 85];
	for (let i = 0; i < ary.length; i++) {
		if (ary[i] == $gameMap.mapId()) {
			return 2;
		}
	}
	//渋野かどうか？
	var ary = [143, 144];
	for (let i = 0; i < ary.length; i++) {
		if (ary[i] == $gameMap.mapId()) {
			return 3;
		}
	}
	//ダリアのアジトかどうか？
	var ary = [225, 226, 227, 228, 229, 230, 231];
	for (let i = 0; i < ary.length; i++) {
		if (ary[i] == $gameMap.mapId()) {
			return 4;
		}
	}
	return 0;
};
//----------------------------------------------------
//■性周期の処理
// 性周期変更カウンター=変数131～
// 白雪性周期 = 65
// 夜鶴性周期 = 66
//----------------------------------------------------
var SDN_EstrousCycle = function (val) {
	var counterId_sir = [131, 65];
	var counterId_yoz = [132, 66];
	//カウンターに設定数値を＋する
	$gameVariables.setValue(counterId_sir[0], $gameVariables.value(counterId_sir[0]) + val);
	$gameVariables.setValue(counterId_yoz[0], $gameVariables.value(counterId_yoz[0]) + val);
	//性周期の変化 規定値は通常20で安全日と危険日は10で設定
	if ($gameVariables.value(counterId_sir[1]) == 1) {
		var countLimit = 20;
	} else {
		var countLimit = 10;
	}
	if ($gameVariables.value(counterId_sir[0]) >= countLimit) {
		$gameVariables.setValue(counterId_sir[1], $gameVariables.value(counterId_sir[1]) + 1);
		if ($gameVariables.value(counterId_sir[1]) == 4) {
			$gameVariables.setValue(counterId_sir[1], 0);
		}
		//性周期が変化したらカウンターをリセット
		$gameVariables.setValue(counterId_sir[0], 0);
	}
	//夜鶴の処理
	if ($gameVariables.value(counterId_yoz[1]) == 1) {
		var countLimit = 20;
	} else {
		var countLimit = 10;
	}
	if ($gameVariables.value(counterId_yoz[0]) >= countLimit) {
		$gameVariables.setValue(counterId_yoz[1], $gameVariables.value(counterId_yoz[1]) + 1);
		if ($gameVariables.value(counterId_yoz[1]) == 4) {
			$gameVariables.setValue(counterId_yoz[1], 0);
		}
		//性周期が変化したらカウンターをリセット
		$gameVariables.setValue(counterId_yoz[0], 0);
	}
};
//----------------------------------------------------
//■戦闘：開始ボイスの定義
//----------------------------------------------------
var SDN_BattleStartVoice = function () {
	// 先頭キャラのHPレートで判断
	if ($gameParty.allMembers()[0].name() == "Shirayuki") {
		var chaData = ["sir", 204];
	} else {
		var chaData = ["yoz", 205];
	}
	var hpRate = $gameParty.members()[0].hpRate();
	var chapter = $gameVariables.value(1);
	//ボイスファイルの取得
	if ($gameVariables.value(chaData[0]) == 0) {
		if (hpRate >= 0.8 && chapter < 307) {
			return "Vo_" + chaData[0] + "_9_0001";
		} else if (hpRate >= 0.25 && chapter < 307) {
			return "Vo_" + chaData[0] + "_9_0002";
		} else if (chapter < 307) {
			return "Vo_" + chaData[0] + "_9_0003";
		} else if (hpRate >= 0.8) {
			return "Vo_" + chaData[0] + "_9_0007";
		} else if (hpRate >= 0.25) {
			return "Vo_" + chaData[0] + "_9_0008";
		} else {
			return "Vo_" + chaData[0] + "_9_0009";
		}
	} else {
		if (hpRate >= 0.8 && chapter < 307) {
			return "Vo_" + chaData[0] + "_9_0004";
		} else if (hpRate >= 0.25 && chapter < 307) {
			return "Vo_" + chaData[0] + "_9_0005";
		} else if (chapter < 307) {
			return "Vo_" + chaData[0] + "_9_0006";
		} else if (hpRate >= 0.8) {
			return "Vo_" + chaData[0] + "_9_0010";
		} else if (hpRate >= 0.25) {
			return "Vo_" + chaData[0] + "_9_0011";
		} else {
			return "Vo_" + chaData[0] + "_9_0012";
		}
	}
};
//----------------------------------------------------
//■戦闘：コマンドボイス
//----------------------------------------------------
//ボイスファイル取得
var SDN_CommandVoiceFile = function (name, actorId, cosId) {
	//服装の状態を取得する
	var cosState = $gameVariables.value(cosId);
	//キャラIDを取得
	if (name == "Shirayuki") {
		var hpRate = $gameActors.actor(1).hpRate();
		var chaId = "sir";
		var roshutsuId = 267;
		var hparamId = [243, 244];
		var kousokuId = [136, 137];
	} else {
		var hpRate = $gameActors.actor(2).hpRate();
		var chaId = "yoz";
		var roshutsuId = 313;
		var hparamId = [289, 290];
		var kousokuId = [137, 136];
	}
	//ファイル名取得処理
	//絶頂時
	if ($gameActors.actor(actorId + 1).isStateAffected(90)) {
		if (!$gameSwitches.value(hparamId[0])) {
			return "Vo_" + chaId + "_9_0124";
		} else if (!$gameSwitches.value(hparamId[1])) {
			return "Vo_" + chaId + "_9_0125";
		} else {
			return "Vo_" + chaId + "_9_0126";
		}
	}
	//犯され後
	if ($gameActors.actor(actorId + 1).isStateAffected(89)) {
		if (!$gameSwitches.value(hparamId[0])) {
			return "Vo_" + chaId + "_9_0121";
		} else if (!$gameSwitches.value(hparamId[1])) {
			return "Vo_" + chaId + "_9_0122";
		} else {
			return "Vo_" + chaId + "_9_0123";
		}
	}
	//拘束時
	if ($gameVariables.value(kousokuId[0]) == 1) {
		if (!$gameSwitches.value(hparamId[0])) {
			return "Vo_" + chaId + "_9_0115";
		} else {
			if (!$gameSwitches.value(hparamId[1])) {
				return "Vo_" + chaId + "_9_0116";
			} else {
				return "Vo_" + chaId + "_9_0117";
			}
		}
	} else if ($gameVariables.value(kousokuId[0]) >= 2) {
		if (!$gameSwitches.value(hparamId[0])) {
			return "Vo_" + chaId + "_9_0118";
		} else {
			if (!$gameSwitches.value(hparamId[1])) {
				return "Vo_" + chaId + "_9_0119";
			} else {
				return "Vo_" + chaId + "_9_0120";
			}
		}
	}
	//味方キャラが拘束されている場合
	if ($gameVariables.value(kousokuId[1]) >= 1) {
		if (Math.round(Math.random() * 100) >= 50) {
			return "Vo_" + chaId + "_9_0127";
		} else {
			return "Vo_" + chaId + "_9_0128";
		}
	}
	//共通　バフ状態（31～49）
	for (let i = 48; i < 60; i++) {
		if ($gameActors.actor(actorId + 1).isStateAffected(i)) {
			return "Vo_" + chaId + "_9_0113";
		}
	}
	//共通　デバフ状態（7～29）
	for (let i = 7; i < 30; i++) {
		if ($gameActors.actor(actorId + 1).isStateAffected(i)) {
			return "Vo_" + chaId + "_9_0114";
		}
	}
	//着衣時
	if (cosState == 0) {
		if (hpRate >= 0.8 && $gameVariables.value(1) < 307) {
			return "Vo_" + chaId + "_9_0101";
		} else if (hpRate >= 0.25 && $gameVariables.value(1) < 307) {
			return "Vo_" + chaId + "_9_0102";
		} else if ($gameVariables.value(1) < 307) {
			return "Vo_" + chaId + "_9_0103";
		} else if (hpRate >= 0.8) {
			return "Vo_" + chaId + "_9_0104";
		} else if (hpRate >= 0.25) {
			return "Vo_" + chaId + "_9_0105";
		} else {
			return "Vo_" + chaId + "_9_0106";
		}
		//裸時
	} else {
		if (hpRate >= 0.8 && !$gameSwitches.value(roshutsuId)) {
			return "Vo_" + chaId + "_9_0107";
		} else if (hpRate >= 0.25 && !$gameSwitches.value(roshutsuId)) {
			return "Vo_" + chaId + "_9_0108";
		} else if (!$gameSwitches.value(roshutsuId)) {
			return "Vo_" + chaId + "_9_0109";
		} else if (hpRate >= 0.8) {
			return "Vo_" + chaId + "_9_0110";
		} else if (hpRate >= 0.25) {
			return "Vo_" + chaId + "_9_0111";
		} else {
			return "Vo_" + chaId + "_9_0112";
		}
	}
};
//コマンドボイス再生
var CBR_CommandVoice = function (name) {
	if (name == "Shirayuki") {
		voiceFile = SDN_CommandVoiceFile(name, 0, 204);
	} else {
		voiceFile = SDN_CommandVoiceFile(name, 1, 205);
	}
	//ボイスの再生
	AudioManager.playVoice({ name: voiceFile, volume: 100, pitch: 100, pan: 0 });
};
//----------------------------------------------------
//■戦闘：Ｈ攻撃関係
//----------------------------------------------------
//■パーティー状態の取得
var SDN_HactPartyState = function () {
	//パーティ状態を定義
	if ($gameParty.battleMembers().length == 2) {
		return 0; //２人
	} else if ($gameParty.battleMembers()[0].actorId() == 1) {
		return 1; //白雪のみ
	} else {
		return 2; //夜鶴のみ
	}
};
//■Ｈ攻撃発生させるかどうか？
var SDN_canHact = function () {
	//白雪・夜鶴が揃っている場合
	if (SDN_HactPartyState() == 0) {
		//二人とも完全処女の場合は発生しない
		if ($gameVariables.value(69) == 0 && $gameVariables.value(70) == 0) {
			return false;
		}
		//二人とも貞操具を着けている場合は発生しない
		if ($gameActors.actor(1).hasWeapon($dataWeapons[33]) && $gameActors.actor(2).hasWeapon($dataWeapons[33])) {
			return false;
		}
		//Ｈ攻撃フラグの抽選を開始（基本確率30%）サキュバスソウル装備時は70％に！
		if ($gameActors.actor(1).hasArmor($dataWeapons[16]) || $gameActors.actor(2).hasArmor($dataWeapons[17])) {
			var hactPer = 70;
		} else {
			var hactPer = 30;
		}
		//サガラダンジョンの時の処理
		if ($gameVariables.value(395) > 0) {
			var hactPer = $gameVariables.value(395);
		}
		if (Math.round(Math.random() * 100) >= 100 - hactPer) {
			return true;
		} else {
			return false;
		}
	}
	//白雪単独
	else if (SDN_HactPartyState() == 1) {
		if ($gameVariables.value(69) == 0) {
			return false;
		}
		//貞操具を着けている場合は発生しない
		if ($gameActors.actor(1).hasWeapon($dataWeapons[33])) {
			return false;
		}
		//Ｈ攻撃フラグの抽選を開始（基本確率30%）サキュバスソウル装備時は70％に！
		if ($gameActors.actor(1).hasArmor($dataWeapons[16])) {
			var hactPer = 70;
		} else {
			var hactPer = 30;
		}
		//サガラダンジョンの時の処理
		if ($gameVariables.value(395) > 0) {
			var hactPer = $gameVariables.value(395);
		}
		if (Math.round(Math.random() * 100) >= 100 - hactPer) {
			return true;
		} else {
			return false;
		}
	}
	//夜鶴単独
	else if (SDN_HactPartyState() == 2) {
		if ($gameVariables.value(70) == 0) {
			return false;
		}
		//貞操具を着けている場合は発生しない
		if ($gameActors.actor(2).hasWeapon($dataWeapons[33])) {
			return false;
		}
		//Ｈ攻撃フラグの抽選を開始（基本確率30%）サキュバスソウル装備時は70％に！
		if ($gameActors.actor(2).hasArmor($dataWeapons[17])) {
			var hactPer = 70;
		} else {
			var hactPer = 30;
		}
		//サガラダンジョンの時の処理
		if ($gameVariables.value(395) > 0) {
			var hactPer = $gameVariables.value(395);
		}
		if (Math.round(Math.random() * 100) >= 100 - hactPer) {
			return true;
		} else {
			return false;
		}
	}
};
//■両穴責めＨ攻撃（触手）を発生させるかどうか？
var SDN_canHactRyoana = function () {
	//白雪・夜鶴が揃っている場合
	if (SDN_HactPartyState() == 0) {
		//二人とも完全処女の場合は発生しない
		if ($gameVariables.value(69) == 0 && $gameVariables.value(70) == 0) {
			return false;
		}
		//二人とも貞操具を着けている場合は発生しない
		if ($gameActors.actor(1).hasWeapon($dataWeapons[33]) && $gameActors.actor(2).hasWeapon($dataWeapons[33])) {
			return false;
		}
		//どちらも両穴非処女じゃない場合は発生しない
		if ($gameVariables.value(69) != 3 && $gameVariables.value(70) != 3) {
			return false;
		}
		//Ｈ攻撃フラグの抽選を開始（基本確率30%）サキュバスソウル装備時は70％に！　オナニー実行中は90%
		if ($gameSwitches.value(240)) {
			var hactPer = 90;
			$gameSwitches.setValue(240, false);
		} else if ($gameActors.actor(1).hasArmor($dataWeapons[16]) || $gameActors.actor(2).hasArmor($dataWeapons[16])) {
			var hactPer = 70;
		} else {
			var hactPer = 30;
		}
		if (Math.round(Math.random() * 100) >= 100 - hactPer) {
			return true;
		} else {
			return false;
		}
	}
	//白雪単独
	else if (SDN_HactPartyState() == 1) {
		if ($gameVariables.value(69) < 3) {
			return false;
		}
		//二人とも貞操具を着けている場合は発生しない
		if ($gameActors.actor(1).hasWeapon($dataWeapons[33])) {
			return false;
		}
		//Ｈ攻撃フラグの抽選を開始（基本確率30%）サキュバスソウル装備時は70％に！　オナニー実行中は90%
		if ($gameSwitches.value(240)) {
			var hactPer = 90;
			$gameSwitches.setValue(240, false);
		} else if ($gameActors.actor(1).hasArmor($dataWeapons[16])) {
			var hactPer = 70;
		} else {
			var hactPer = 30;
		}
		if (Math.round(Math.random() * 100) >= 100 - hactPer) {
			return true;
		} else {
			return false;
		}
	}
	//夜鶴単独
	else if (SDN_HactPartyState() == 2) {
		if ($gameVariables.value(70) < 3) {
			return false;
		}
		//二人とも貞操具を着けている場合は発生しない
		if ($gameActors.actor(2).hasWeapon($dataWeapons[33])) {
			return false;
		}
		//Ｈ攻撃フラグの抽選を開始（基本確率30%）サキュバスソウル装備時は70％に！　オナニー実行中は90%
		if ($gameSwitches.value(240)) {
			var hactPer = 90;
			$gameSwitches.setValue(240, false);
		} else if ($gameActors.actor(2).hasArmor($dataWeapons[16])) {
			var hactPer = 70;
		} else {
			var hactPer = 30;
		}
		if (Math.round(Math.random() * 100) >= 100 - hactPer) {
			return true;
		} else {
			return false;
		}
	}
};
//■拘束時の処理（ターゲットの設定）
var SDN_HactSetTarget = function () {
	//触手のＨ攻撃以外
	if ($gameTemp.lastActionData(0) != 103) {
		//拘束相手の決定　ふたり揃っている場合
		if (SDN_HactPartyState() == 0) {
			if ($gameVariables.value(69) == 0 || $gameActors.actor(1).hasWeapon($dataWeapons[33])) {
				return 2;
			}
			if ($gameVariables.value(70) == 0 || $gameActors.actor(2).hasWeapon($dataWeapons[33])) {
				return 1;
			}
			if (Math.round(Math.random()) == 0) {
				return 1;
			} else {
				return 2;
			}
		}
		//拘束相手の決定　白雪のみ
		else if (SDN_HactPartyState() == 1) {
			return 1;
		}
		//拘束相手の決定　夜鶴のみ
		else if (SDN_HactPartyState() == 2) {
			return 2;
		}
	} else {
		//拘束相手の決定　ふたり揃っている場合
		if (SDN_HactPartyState() == 0) {
			if ($gameVariables.value(69) < 3 || $gameActors.actor(1).hasWeapon($dataWeapons[33])) {
				return 2;
			}
			if ($gameVariables.value(70) < 3 || $gameActors.actor(2).hasWeapon($dataWeapons[33])) {
				return 1;
			}
			if (Math.round(Math.random()) == 0) {
				return 1;
			} else {
				return 2;
			}
		}
		//拘束相手の決定　白雪のみ
		else if (SDN_HactPartyState() == 1) {
			return 1;
		}
		//拘束相手の決定　夜鶴のみ
		else if (SDN_HactPartyState() == 2) {
			return 2;
		}
	}
};
//■Ｈ攻撃のセッティング
var SDN_HactSetting = function (tgt) {
	//Ｈ部位の設定
	var ary = [0, 69, 70];
	if ($gameVariables.value(ary[tgt]) == 1) {
		$gameVariables.setValue(134, 1);
	} else if ($gameVariables.value(ary[tgt]) == 2) {
		$gameVariables.setValue(134, 2);
	} else if ($gameVariables.value(ary[tgt]) == 3) {
		$gameVariables.setValue(134, Math.round(Math.random()) + 1);
	}
	//触手の場合は強制的に１へ
	if ($gameVariables.value(138) == "触手") {
		$gameVariables.setValue(134, 1);
	}
};
//■Ｈ攻撃の設定
var SDN_HactSetHatk = function (val) {
	//敵タイプの取得処理
	var Htype = $gameVariables.value(138);
	if (val == 1) {
		if (Htype == "人間") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A01a_1", "BattleHAnime_A01a_2", "BattleHAnime_A01a_3"];
				} else {
					var ary = ["BattleHAnime_A01b_1", "BattleHAnime_A01b_2", "BattleHAnime_A01b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B01a_1", "BattleHAnime_B01a_2", "BattleHAnime_B01a_3"];
				} else {
					var ary = ["BattleHAnime_B01b_1", "BattleHAnime_B01b_2", "BattleHAnime_B01b_3"];
				}
			}
		} else if (Htype == "ゴブリン") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A03a_1", "BattleHAnime_A03a_2", "BattleHAnime_A03a_3"];
				} else {
					var ary = ["BattleHAnime_A03b_1", "BattleHAnime_A03b_2", "BattleHAnime_A03b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B03a_1", "BattleHAnime_B03a_2", "BattleHAnime_B03a_3"];
				} else {
					var ary = ["BattleHAnime_B03b_1", "BattleHAnime_B03b_2", "BattleHAnime_B03b_3"];
				}
			}
		} else if (Htype == "オーク") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A05a_1", "BattleHAnime_A05a_2", "BattleHAnime_A05a_3"];
				} else {
					var ary = ["BattleHAnime_A05b_1", "BattleHAnime_A05b_2", "BattleHAnime_A05b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B05a_1", "BattleHAnime_B05a_2", "BattleHAnime_B05a_3"];
				} else {
					var ary = ["BattleHAnime_B05b_1", "BattleHAnime_B05b_2", "BattleHAnime_B05b_3"];
				}
			}
		} else if (Htype == "スライム") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["eva_c123_00_00_01", "eva_c123_00_00_02", "eva_c123_00_00_03"];
				} else {
					var ary = ["BattleHAnime_A07a_1", "BattleHAnime_A07a_2", "BattleHAnime_A07a_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["evb_c123_00_00_01", "evb_c123_00_00_02", "evb_c123_00_00_03"];
				} else {
					var ary = ["BattleHAnime_B07a_1", "BattleHAnime_B07a_2", "BattleHAnime_B07a_3"];
				}
			}
		} else if (Htype == "魔犬") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A08a_1", "BattleHAnime_A08a_2", "BattleHAnime_A08a_3"];
				} else {
					var ary = ["BattleHAnime_A08b_1", "BattleHAnime_A08b_2", "BattleHAnime_A08b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B08a_1", "BattleHAnime_B08a_2", "BattleHAnime_B08a_3"];
				} else {
					var ary = ["BattleHAnime_B08b_1", "BattleHAnime_B08b_2", "BattleHAnime_B08b_3"];
				}
			}
		} else if (Htype == "魔豚") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A10a_1", "BattleHAnime_A10a_2", "BattleHAnime_A10a_3"];
				} else {
					var ary = ["BattleHAnime_A10b_1", "BattleHAnime_A10b_2", "BattleHAnime_A10b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B09a_1", "BattleHAnime_B09a_2", "BattleHAnime_B09a_3"];
				} else {
					var ary = ["BattleHAnime_B09b_1", "BattleHAnime_B09b_2", "BattleHAnime_B09b_3"];
				}
			}
		} else if (Htype == "妖馬") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A11a_1", "BattleHAnime_A11a_2", "BattleHAnime_A11a_3"];
				} else {
					var ary = ["BattleHAnime_A11b_1", "BattleHAnime_A11b_2", "BattleHAnime_A11b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B11a_1", "BattleHAnime_B11a_2", "BattleHAnime_B11a_3"];
				} else {
					var ary = ["BattleHAnime_B11b_1", "BattleHAnime_B11b_2", "BattleHAnime_B11b_3"];
				}
			}
		} else if (Htype == "触手") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A13a_1", "BattleHAnime_A13a_2", "BattleHAnime_A13a_3"];
				} else {
					var ary = ["BattleHAnime_A13b_1", "BattleHAnime_A13b_2", "BattleHAnime_A13b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B13a_1", "BattleHAnime_B13a_2", "BattleHAnime_B13a_3"];
				} else {
					var ary = ["BattleHAnime_B13b_1", "BattleHAnime_B13b_2", "BattleHAnime_B13b_3"];
				}
			}
		}
	}
	//アナルの処理
	else {
		if (Htype == "人間") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A02a_1", "BattleHAnime_A02a_2", "BattleHAnime_A02a_3"];
				} else {
					var ary = ["BattleHAnime_A02b_1", "BattleHAnime_A02b_2", "BattleHAnime_A02b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B02a_1", "BattleHAnime_B02a_2", "BattleHAnime_B02a_3"];
				} else {
					var ary = ["BattleHAnime_B02b_1", "BattleHAnime_B02b_2", "BattleHAnime_B02b_3"];
				}
			}
		} else if (Htype == "ゴブリン") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["eva_c121_00_01_01", "eva_c121_00_01_02", "eva_c121_00_01_03"];
				} else {
					var ary = ["BattleHAnime_A04b_1", "BattleHAnime_A04b_2", "BattleHAnime_A04b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["evb_c121_00_01_01", "evb_c121_00_01_02", "evb_c121_00_01_03"];
				} else {
					var ary = ["BattleHAnime_B04b_1", "BattleHAnime_B04b_2", "BattleHAnime_B04b_3"];
				}
			}
		} else if (Htype == "オーク") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["eva_c120_00_01_01", "eva_c120_00_01_02", "eva_c120_00_01_03"];
				} else {
					var ary = ["BattleHAnime_A06b_1", "BattleHAnime_A06b_2", "BattleHAnime_A06b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["evb_c120_00_01_01", "evb_c120_00_01_02", "evb_c120_00_01_03"];
				} else {
					var ary = ["BattleHAnime_B06b_1", "BattleHAnime_B06b_2", "BattleHAnime_B06b_3"];
				}
			}
		} else if (Htype == "スライム") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["eva_c123_00_01_01", "eva_c123_00_01_02", "eva_c123_00_01_03"];
				} else {
					var ary = ["BattleHAnime_A07b_1", "BattleHAnime_A07b_2", "BattleHAnime_A07b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["evb_c123_00_01_01", "evb_c123_00_01_02", "evb_c123_00_01_03"];
				} else {
					var ary = ["BattleHAnime_B07b_1", "BattleHAnime_B07b_2", "BattleHAnime_B07b_3"];
				}
			}
		} else if (Htype == "魔犬") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["eva_c125_00_01_01", "eva_c125_00_01_02", "eva_c125_00_01_03"];
				} else {
					var ary = ["BattleHAnime_A09b_1", "BattleHAnime_A09b_2", "BattleHAnime_A09b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["evb_c125_00_01_01", "evb_c125_00_01_02", "evb_c125_00_01_03"];
				} else {
					var ary = ["BattleHAnime_B15b_1", "BattleHAnime_B15b_2", "BattleHAnime_B15b_3"];
				}
			}
		} else if (Htype == "魔豚") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["eva_c126_00_01_01", "eva_c126_00_01_02", "eva_c126_00_01_03"];
				} else {
					var ary = ["BattleHAnime_A15b_1", "BattleHAnime_A15b_2", "BattleHAnime_A15b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["evb_c126_00_01_01", "evb_c126_00_01_02", "evb_c126_00_01_03"];
				} else {
					var ary = ["BattleHAnime_B10b_1", "BattleHAnime_B10b_2", "BattleHAnime_B10b_3"];
				}
			}
		} else if (Htype == "妖馬") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["eva_c127_00_01_01", "eva_c127_00_01_02", "eva_c127_00_01_03"];
				} else {
					var ary = ["BattleHAnime_A12b_1", "BattleHAnime_A12b_2", "BattleHAnime_A12b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["evb_c127_00_01_01", "evb_c127_00_01_02", "evb_c127_00_01_03"];
				} else {
					var ary = ["BattleHAnime_B12b_1", "BattleHAnime_B12b_2", "BattleHAnime_B12b_3"];
				}
			}
		} else if (Htype == "触手") {
			if ($gameVariables.value(133) == 1) {
				if ($gameVariables.value(204) == 0) {
					var ary = ["BattleHAnime_A13a_1", "BattleHAnime_A13a_2", "BattleHAnime_A13a_3"];
				} else {
					var ary = ["BattleHAnime_A13b_1", "BattleHAnime_A13b_2", "BattleHAnime_A13b_3"];
				}
			} else {
				if ($gameVariables.value(205) == 0) {
					var ary = ["BattleHAnime_B13a_1", "BattleHAnime_B13a_2", "BattleHAnime_B13a_3"];
				} else {
					var ary = ["BattleHAnime_B13b_1", "BattleHAnime_B13b_2", "BattleHAnime_B13b_3"];
				}
			}
		}
	}
	if ($gameVariables.value(133) == 1) {
		if ($gameVariables.value(136) == 1) {
			var aryNum = 0;
		} else if ($gameVariables.value(136) == 2 || $gameVariables.value(136) == 3) {
			var aryNum = 1;
		} else if ($gameVariables.value(136) == 4 || $gameVariables.value(136) == 5) {
			var aryNum = 2;
		} else {
			var aryNum = 0;
		}
	} else {
		if ($gameVariables.value(137) == 1) {
			var aryNum = 0;
		} else if ($gameVariables.value(137) == 2 || $gameVariables.value(137) == 3) {
			var aryNum = 1;
		} else if ($gameVariables.value(137) == 4 || $gameVariables.value(137) == 5) {
			var aryNum = 2;
		} else {
			var aryNum = 0;
		}
	}
	//Ｈアニメ回想登録処理
	var actFile = ary[aryNum];
	SDN_SetHanimeRef(actFile.slice(0, 17));
	return actFile;
};
//■拘束時画像の表示
var SDN_ShowKousokuImg = function (name) {
	//ベース設定
	if (name == "Shirayuki") {
		var evChara = "eva_d";
		var cosChara = $gameVariables.value(204);
		var kousokuState = $gameVariables.value(136);
		var idx = 9;
	} else {
		var evChara = "evb_d";
		var cosChara = $gameVariables.value(205);
		var kousokuState = $gameVariables.value(137);
		var idx = 5;
	}
	//拘束している敵の種類（変数138番）
	var Enemy = $gameVariables.value(138);
	var list = [
		{ type: "人間", id: "001" },
		{ type: "ゴブリン", id: "002" },
		{ type: "オーク", id: "003" },
		{ type: "魔犬", id: "004" },
		{ type: "魔豚", id: "005" },
		{ type: "妖馬", id: "006" },
		{ type: "スライム", id: "007" },
		{ type: "触手", id: "008" }
	];
	var evEnemy = list.find((e) => e.type === Enemy).id;

	//服装
	if (cosChara == 0) {
		var evCos = "00";
	} else {
		var evCos = "01";
	}
	//部位
	if ($gameVariables.value(134) == 1) {
		var evPos = "00";
	} else {
		var evPos = "01";
	}
	//拘束状態（１＝未挿入　２＝マンコ挿入　３＝アナル挿入）
	if (kousokuState < 2) {
		var evKousoku = "01";
	} else {
		var evKousoku = "02";
	}
	var dataName = evChara + evEnemy + "_" + evCos + "_" + evPos + "_" + evKousoku;
	$gameScreen.showPicture(10, dataName, 0, -128, -72, 120, 120, 0, 0);
	$gameScreen.movePicture(10, 0, 0, 0, 100, 100, 255, 0, 5);
};
//■戦闘行動の再定義
//※戦闘行動の条件をスイッチにしているスキルが
//スイッチがOFFになってるのに選ばれてしまう不具合に対応
const _BattleManager_processTurn = BattleManager.processTurn;
BattleManager.processTurn = function () {
	const subject = this._subject;
	//敵の場合のみ実行　拘束発生中（sw166）のみ実行
	if (subject.isEnemy() && $gameSwitches.value(169)) {
		const action = subject.currentAction();
		//行動前にアクションを再設定させる
		if (action) {
			subject.makeActions();
			subject._firstActionDone = true;
		}
	}
	//元処理を実行
	_BattleManager_processTurn.apply(this);
};

//----------------------------------------------------
//■ＡＤＶエッチアニメの処理
//----------------------------------------------------
//一時変数１・２と一時スイッチ１を使う
var SDN_SetAdvHanime = function (file, animeId, loop) {
	$gameVariables.setValue(4, file);
	$gameVariables.setValue(5, animeId);
	$gameSwitches.setValue(102, loop);
	//回想モード登録処理
	SDN_SetHanimeRef(file);
};

//----------------------------------------------------
//■Ｈなことして時間つぶしの処理
//----------------------------------------------------

var SDN_SetFreeEro = function (name, type) {
	//配列取得の数値
	if (name == "Shirayuki") {
		var num = 0;
	} else {
		var num = 1;
	}
	//typeを一時変数１に代入（Ｈ履歴取得処理のため）
	$gameVariables.setValue(4, type);
	//変数ＩＤの設定
	//Ｈ経験：人間相手
	var tgt = [259, 339];
	//Ｈ経験：人との性行為
	var seitgt = [288, 368];
	//セックス系
	//Ｈ経験：セックス
	var sex = [262, 342];
	//Ｈ経験：キス
	var kiss = [268, 348];
	//Ｈ経験：乳揉み
	var chichimomi = [269, 349];
	//Ｈ経験：手マン
	var teman = [271, 351];
	//アナル系
	//Ｈ経験：アナルセックス
	var anal = [263, 343];
	//Ｈ経験：尻揉み
	var sirimomi = [270, 350];
	//Ｈ経験：アナル弄り
	var analijiri = [272, 352];
	//セクハラ系
	//Ｈ経験：クンニ
	var kunni = [267, 347];
	//Ｈ経験：セクハラ
	var sexualharassment = [292, 372];
	//奉仕系
	//Ｈ経験：フェラチオ
	var fera = [264, 344];
	//Ｈ経験：パイズリ
	var paizuri = [265, 345];
	//Ｈ経験：手コキ
	var tekoki = [266, 346];
	//Ｈ経験：ご奉仕
	var houshi = [293, 373];
	//オナニー
	//Ｈ経験：オナニー
	var onanie = [273, 353];
	//Ｈ経験：アナニー
	var ananie = [274, 354];
	//Ｈ経験：露出プレイ
	var roshutsuplay = [276, 356];
	//開発度経験値
	//淫乱度
	var expInran = [252, 332];
	//口淫
	var expMouse = [253, 333];
	//乳房
	var expBust = [254, 334];
	//マンコ
	var expVagina = [255, 335];
	//アナル
	var expAnal = [256, 336];
	//露出
	var expRoshutsu = [257, 337];
	//奉仕
	var expHoushi = [258, 338];
	//絶頂
	var ecstasy = [281, 361];
	//潮吹き
	var ecstasy_sio = [282, 362];
	//母乳
	var ecstasy_milk = [287, 367];
	var ecstasy_milk_sw = [262, 308];
	//射精
	var bukkake = [283, 363];
	var nakadashi = [284, 364];
	var nakadashi_anal = [285, 365];
	var nakadashi_mouse = [286, 366];

	//実行処理
	//オナニーの場合
	if (type == 1) {
		var setValue = Math.round(Math.random() * 3) + 2;
		$gameVariables.setValue(onanie[num], $gameVariables.value(onanie[num]) + setValue);
		$gameVariables.setValue(expInran[num], $gameVariables.value(expInran[num]) + 30);
		$gameVariables.setValue(expVagina[num], $gameVariables.value(expVagina[num]) + 30);
		$gameVariables.setValue(expRoshutsu[num], $gameVariables.value(expRoshutsu[num]) + 30);
		//絶頂処理
		var setExValue = Math.round(Math.random() * 10) + 5;
		$gameVariables.setValue(ecstasy[num], $gameVariables.value(ecstasy[num]) + setExValue);
		setExValue = setExValue - Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		if ($gameSwitches.value(ecstasy_milk_sw[num])) {
			setExValue = Math.round(Math.random() * 200) + 80;
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		//アナニーの場合
	} else if (type == 2) {
		var setValue = Math.round(Math.random() * 3) + 2;
		$gameVariables.setValue(ananie[num], $gameVariables.value(ananie[num]) + setValue);
		$gameVariables.setValue(expInran[num], $gameVariables.value(expInran[num]) + 30);
		$gameVariables.setValue(expAnal[num], $gameVariables.value(expAnal[num]) + 30);
		$gameVariables.setValue(expRoshutsu[num], $gameVariables.value(expRoshutsu[num]) + 30);
		//絶頂処理
		var setExValue = Math.round(Math.random() * 10) + 5;
		$gameVariables.setValue(ecstasy[num], $gameVariables.value(ecstasy[num]) + setExValue);
		setExValue = setExValue - Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		if ($gameSwitches.value(ecstasy_milk_sw[num])) {
			setExValue = Math.round(Math.random() * 200) + 80;
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		//セックスの場合
	} else if (type == 3) {
		var setValue = Math.round(Math.random() * 8) + 2;
		$gameVariables.setValue(sex[num], $gameVariables.value(sex[num]) + setValue);
		$gameVariables.setValue(tgt[num], $gameVariables.value(tgt[num]) + setValue);
		$gameVariables.setValue(seitgt[num], $gameVariables.value(seitgt[num]) + setValue);

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(kiss[num], $gameVariables.value(kiss[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expMouse[num], $gameVariables.value(expMouse[num]) + 20);
		}

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(chichimomi[num], $gameVariables.value(chichimomi[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expBust[num], $gameVariables.value(expBust[num]) + 20);
		}

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(teman[num], $gameVariables.value(teman[num]) + setValue);

		$gameVariables.setValue(expInran[num], $gameVariables.value(expInran[num]) + 50);
		$gameVariables.setValue(expVagina[num], $gameVariables.value(expVagina[num]) + 50);
		$gameVariables.setValue(expRoshutsu[num], $gameVariables.value(expRoshutsu[num]) + 30);
		//絶頂処理
		var setExValue = Math.round(Math.random() * 10) + 5;
		$gameVariables.setValue(ecstasy[num], $gameVariables.value(ecstasy[num]) + setExValue);
		setExValue = setExValue - Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		if ($gameSwitches.value(ecstasy_milk_sw[num])) {
			setExValue = Math.round(Math.random() * 200) + 80;
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		//射精処理
		setExValue = Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			setExValue = setExValue * 15;
			$gameVariables.setValue(bukkake[num], $gameVariables.value(bukkake[num]) + setExValue);
		}
		setExValue = Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			setExValue = setExValue * 15;
			$gameVariables.setValue(nakadashi[num], $gameVariables.value(nakadashi[num]) + setExValue);
			//中出しスイッチＯＮ
			$gameSwitches.setValue(215, true);
		}
		//アナルセックスの場合
	} else if (type == 4) {
		var setValue = Math.round(Math.random() * 8) + 2;
		$gameVariables.setValue(anal[num], $gameVariables.value(anal[num]) + setValue);
		$gameVariables.setValue(tgt[num], $gameVariables.value(tgt[num]) + setValue);
		$gameVariables.setValue(seitgt[num], $gameVariables.value(seitgt[num]) + setValue);

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(kiss[num], $gameVariables.value(kiss[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expMouse[num], $gameVariables.value(expMouse[num]) + 20);
		}

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(chichimomi[num], $gameVariables.value(chichimomi[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expBust[num], $gameVariables.value(expBust[num]) + 20);
		}

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(sirimomi[num], $gameVariables.value(sirimomi[num]) + setValue);

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(analijiri[num], $gameVariables.value(analijiri[num]) + setValue);

		$gameVariables.setValue(expInran[num], $gameVariables.value(expInran[num]) + 50);
		$gameVariables.setValue(expAnal[num], $gameVariables.value(expAnal[num]) + 50);
		$gameVariables.setValue(expRoshutsu[num], $gameVariables.value(expRoshutsu[num]) + 30);
		//絶頂処理
		var setExValue = Math.round(Math.random() * 10) + 5;
		$gameVariables.setValue(ecstasy[num], $gameVariables.value(ecstasy[num]) + setExValue);
		setExValue = setExValue - Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		if ($gameSwitches.value(ecstasy_milk_sw[num])) {
			setExValue = Math.round(Math.random() * 200) + 80;
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		//射精処理
		setExValue = Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			setExValue = setExValue * 15;
			$gameVariables.setValue(bukkake[num], $gameVariables.value(bukkake[num]) + setExValue);
		}
		setExValue = Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			setExValue = setExValue * 15;
			$gameVariables.setValue(nakadashi_anal[num], $gameVariables.value(nakadashi_anal[num]) + setExValue);
		}
		//セクハラの場合
	} else if (type == 5) {
		var setValue = Math.round(Math.random() * 4) + 1;
		$gameVariables.setValue(kiss[num], $gameVariables.value(kiss[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expMouse[num], $gameVariables.value(expMouse[num]) + 20);
		}
		var setValueSub = setValue;
		setValue = Math.round(Math.random() * 5) + 1;
		$gameVariables.setValue(chichimomi[num], $gameVariables.value(chichimomi[num]) + setValue);
		$gameVariables.setValue(expBust[num], $gameVariables.value(expBust[num]) + 20);

		setValueSub = setValueSub + setValue;
		setValue = Math.round(Math.random() * 5) + 1;
		$gameVariables.setValue(sirimomi[num], $gameVariables.value(sirimomi[num]) + setValue);
		$gameVariables.setValue(expAnal[num], $gameVariables.value(expAnal[num]) + 20);

		setValueSub = setValueSub + setValue;
		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(teman[num], $gameVariables.value(teman[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expVagina[num], $gameVariables.value(expVagina[num]) + 20);
		}
		setValueSub = setValueSub + setValue;

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(kunni[num], $gameVariables.value(kunni[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expVagina[num], $gameVariables.value(expVagina[num]) + 20);
		}
		setValueSub = setValueSub + setValue;
		setValue = Math.round(Math.random() * 5);
		if (setValue >= 1) {
			$gameVariables.setValue(analijiri[num], $gameVariables.value(analijiri[num]) + setValue);
			$gameVariables.setValue(expAnal[num], $gameVariables.value(expAnal[num]) + 20);
		}
		$gameVariables.setValue(tgt[num], $gameVariables.value(tgt[num]) + setValueSub);
		$gameVariables.setValue(sexualharassment[num], $gameVariables.value(sexualharassment[num]) + setValueSub);

		$gameVariables.setValue(expInran[num], $gameVariables.value(expInran[num]) + 30);
		if ($gameVariables.value(202) == 1) {
			$gameVariables.setValue(roshutsuplay[num], $gameVariables.value(roshutsuplay[num]) + setValueSub);
			$gameVariables.setValue(expRoshutsu[num], $gameVariables.value(expRoshutsu[num]) + 50);
		}
		//絶頂処理
		var setExValue = Math.round(Math.random() * 10) + 5;
		$gameVariables.setValue(ecstasy[num], $gameVariables.value(ecstasy[num]) + setExValue);
		setExValue = setExValue - Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		if ($gameSwitches.value(ecstasy_milk_sw[num])) {
			setExValue = Math.round(Math.random() * 200) + 80;
			$gameVariables.setValue(ecstasy_sio[num], $gameVariables.value(ecstasy_sio[num]) + setExValue);
		}
		//奉仕の場合
	} else if (type == 6) {
		var setValue = Math.round(Math.random() * 4) + 2;
		$gameVariables.setValue(fera[num], $gameVariables.value(fera[num]) + setValue);
		$gameVariables.setValue(expMouse[num], $gameVariables.value(expMouse[num]) + 50);
		var setValueSub = setValue;

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(paizuri[num], $gameVariables.value(paizuri[num]) + setValue);
		if (setValue >= 1) {
			$gameVariables.setValue(expBust[num], $gameVariables.value(expBust[num]) + 30);
		}
		setValueSub = setValueSub + setValue;

		setValue = Math.round(Math.random() * 5);
		$gameVariables.setValue(tekoki[num], $gameVariables.value(tekoki[num]) + setValue);
		setValueSub = setValueSub + setValue;

		$gameVariables.setValue(tgt[num], $gameVariables.value(tgt[num]) + setValueSub);
		$gameVariables.setValue(houshi[num], $gameVariables.value(houshi[num]) + setValueSub);
		$gameVariables.setValue(expHoushi[num], $gameVariables.value(expHoushi[num]) + 50);
		$gameVariables.setValue(expRoshutsu[num], $gameVariables.value(expRoshutsu[num]) + 20);
		//射精処理
		setExValue = Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			setExValue = setExValue * 15;
			$gameVariables.setValue(bukkake[num], $gameVariables.value(bukkake[num]) + setExValue);
		}
		setExValue = Math.round(Math.random() * 5);
		if (setExValue >= 1) {
			setExValue = setExValue * 15;
			$gameVariables.setValue(nakadashi_mouse[num], $gameVariables.value(nakadashi_mouse[num]) + setExValue);
		}
	}
};

//■汎用異種姦の動画ファイル取得処理
var SDN_SetIshukanMovie = function () {
	if ($gameSwitches.value(117)) {
		if ($gameVariables.value(6) == "オーク") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_A07");
			} else {
				$gameVariables.setValue(4, "Hanime_A08");
			}
		} else if ($gameVariables.value(6) == "魔犬") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_A09");
			} else {
				$gameVariables.setValue(4, "Hanime_A10");
			}
		} else if ($gameVariables.value(6) == "魔豚") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_A11");
			} else {
				$gameVariables.setValue(4, "Hanime_A12");
			}
		} else if ($gameVariables.value(6) == "妖馬") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_A13");
			} else {
				$gameVariables.setValue(4, "Hanime_A14");
			}
		}
	} else {
		if ($gameVariables.value(6) == "オーク") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_B07");
			} else {
				$gameVariables.setValue(4, "Hanime_B08");
			}
		} else if ($gameVariables.value(6) == "魔犬") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_B09");
			} else {
				$gameVariables.setValue(4, "Hanime_B10");
			}
		} else if ($gameVariables.value(6) == "魔豚") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_B11");
			} else {
				$gameVariables.setValue(4, "Hanime_B12");
			}
		} else if ($gameVariables.value(6) == "妖馬") {
			if ($gameVariables.value(5) == 0) {
				$gameVariables.setValue(4, "Hanime_B13");
			} else {
				$gameVariables.setValue(4, "Hanime_B14");
			}
		}
	}
	SDN_SetHanimeRef($gameVariables.value(4));
};

//■操作キャラ変更可能フラグ
var SDN_CanChangeChara = function () {
	if (!$gameSwitches.value(116)) {
		return false;
	}
	//ＭＡＰ毎に設定
	if ($gameMap.mapId() == 74) {
		return false;
	}
	//釣り実行中は無効に！
	if ($gameSwitches.value(185)) {
		return false;
	}
	//銭湯ではキャラ変更を不可に！
	if ($gameMap.mapId() == 78 || $gameMap.mapId() == 79 || $gameMap.mapId() == 80) {
		return false;
	}
	//臨月中のキャラがいるとキャラ変更を不可に！
	if (SDN_CharaNowPregnancy()) {
		return false;
	}
	return true;
};

//■引き継ぎプレイのデータ作成処理
var SDN_CreateGameDataEx = function () {
	//装備を全て外す処理
	$gameParty.members()[0].clearEquipments();
	$gameParty.members()[1].clearEquipments();
	//経験値の保管（変数541番）
	$gameVariables.setValue(541, [$gameActors.actor(1).currentExp(), $gameActors.actor(2).currentExp()]);
	//お金の保管（変数542番）
	$gameVariables.setValue(542, $gameParty.gold());
	//アイテムの保管（変数543番）
	var GetDataItems = [];
	for (let i = 2; i < 15; i++) {
		GetDataItems.push($gameParty.numItems($dataItems[i]));
	}
	for (let i = 24; i < 38; i++) {
		GetDataItems.push($gameParty.numItems($dataItems[i]));
	}
	for (let i = 39; i < 48; i++) {
		GetDataItems.push($gameParty.numItems($dataItems[i]));
	}
	for (let i = 54; i < 57; i++) {
		GetDataItems.push($gameParty.numItems($dataItems[i]));
	}
	for (let i = 64; i < 67; i++) {
		GetDataItems.push($gameParty.numItems($dataItems[i]));
	}
	$gameVariables.setValue(543, GetDataItems);
	//アクセの保管（変数544番）
	var GetDataAcc = [];
	for (let i = 4; i < 38; i++) {
		GetDataItems.push($gameParty.numItems($dataWeapons[i]));
	}
	$gameVariables.setValue(544, GetDataAcc);
	ConfigManager.saveCommonVariables();
};

//■引き継ぎプレイのエロステデータ作成処理
var SDN_CreateErosteData = function (name) {
	var GetErosteData = [];
	var GetEroSkillData = [];
	//白雪：変数545番/夜鶴：変数546番
	if (name == "Shirayuki") {
		for (let i = 245; i < 309; i++) {
			GetErosteData.push($gameVariables.value(i));
		}
		$gameVariables.setValue(545, GetErosteData);
		//白雪の性経験を保存
		$gameVariables.setValue(547, $gameVariables.value(69));
		//Ｈスキルの取得状態を保存
		for (let i = 130; i < 141; i++) {
			if ($gameActors.actor(1).hasSkill(i)) {
				GetEroSkillData.push(1);
			} else {
				GetEroSkillData.push(0);
			}
		}
		$gameVariables.setValue(549, GetEroSkillData);
	} else {
		for (let i = 325; i < 389; i++) {
			GetErosteData.push($gameVariables.value(i));
		}
		$gameVariables.setValue(546, GetErosteData);
		//夜鶴の性経験を保存
		$gameVariables.setValue(548, $gameVariables.value(70));
		//Ｈスキルの取得状態を保存
		for (let i = 130; i < 141; i++) {
			if ($gameActors.actor(2).hasSkill(i)) {
				GetEroSkillData.push(1);
			} else {
				GetEroSkillData.push(0);
			}
		}
		$gameVariables.setValue(550, GetEroSkillData);
	}
	ConfigManager.saveCommonVariables();
};

//■引き継ぎデータプレイ
var SDN_SetGameDataEx = function () {
	//経験値の引き継ぎ
	$gameActors.actor(1).changeExp($gameActors.actor(1).currentExp() + $gameVariables.value(541)[0], false);
	$gameActors.actor(2).changeExp($gameActors.actor(2).currentExp() + $gameVariables.value(541)[1], false);
	//お金の引き継ぎ
	$gameParty.gainGold($gameVariables.value(542));
	//アイテムの引き継ぎ
	var setNum = 0;
	for (let i = 2; i < 15; i++) {
		if ($gameVariables.value(543)[setNum] >= 1) {
			$gameParty.gainItem($dataItems[i], $gameVariables.value(543)[setNum]);
		}
		setNum = setNum + 1;
	}
	for (let i = 24; i < 38; i++) {
		if ($gameVariables.value(543)[setNum] >= 1) {
			$gameParty.gainItem($dataItems[i], $gameVariables.value(543)[setNum]);
		}
		setNum = setNum + 1;
	}
	for (let i = 39; i < 48; i++) {
		if ($gameVariables.value(543)[setNum] >= 1) {
			$gameParty.gainItem($dataItems[i], $gameVariables.value(543)[setNum]);
		}
		setNum = setNum + 1;
	}
	for (let i = 54; i < 57; i++) {
		if ($gameVariables.value(543)[setNum] >= 1) {
			$gameParty.gainItem($dataItems[i], $gameVariables.value(543)[setNum]);
		}
		setNum = setNum + 1;
	}
	for (let i = 64; i < 67; i++) {
		if ($gameVariables.value(543)[setNum] >= 1) {
			$gameParty.gainItem($dataItems[i], $gameVariables.value(543)[setNum]);
		}
		setNum = setNum + 1;
	}
	//アクセサリーの引き継ぎ
	setNum = 0;
	for (let i = 4; i < 38; i++) {
		if ($gameVariables.value(544)[setNum] >= 1) {
			$gameParty.gainItem($dataWeapons[i], $gameVariables.value(544)[setNum], true);
		}
		setNum = setNum + 1;
	}
};

//■エロステ引き継ぎ
var SDN_SetErosteData = function (name) {
	var setNum = 0;
	var GetPregnancyData = [];
	if (name == "Shirayuki") {
		for (let i = 245; i < 298; i++) {
			$gameVariables.setValue(i, $gameVariables.value(393)[setNum]);
			setNum = setNum + 1;
		}
		//妊娠関係は別に補完しておく
		for (let i = 298; i < 308; i++) {
			GetPregnancyData.push($gameVariables.value(393)[setNum]);
			setNum = setNum + 1;
		}
		$gameVariables.setValue(308, $gameVariables.value(393)[setNum]);
		$gameVariables.setValue(391, GetPregnancyData);
		//エロスキルの習得
		setNum = 0;
		for (let i = 130; i < 136; i++) {
			if ($gameVariables.value(395)[setNum] == 1) {
				$gameActors.actor(1).learnSkill(i);
			}
			setNum = setNum + 1;
		}
	} else {
		for (let i = 325; i < 378; i++) {
			$gameVariables.setValue(i, $gameVariables.value(394)[setNum]);
			setNum = setNum + 1;
		}
		//妊娠関係は別に補完しておく
		for (let i = 378; i < 388; i++) {
			GetPregnancyData.push($gameVariables.value(394)[setNum]);
			setNum = setNum + 1;
		}
		$gameVariables.setValue(388, $gameVariables.value(394)[setNum]);
		$gameVariables.setValue(392, GetPregnancyData);
		//エロスキルの習得
		setNum = 0;
		for (let i = 130; i < 136; i++) {
			if ($gameVariables.value(396)[setNum] == 1) {
				$gameActors.actor(2).learnSkill(i);
			}
			setNum = setNum + 1;
		}
		//Ｗ系のスキル習得処理
		for (let i = 137; i < 141; i++) {
			if ($gameVariables.value(396)[setNum] == 1) {
				$gameActors.actor(1).learnSkill(i);
				$gameActors.actor(2).learnSkill(i);
			}
			setNum = setNum + 1;
		}
	}
};

//■出産データ引き継ぎ
var SDN_SetBirthData = function (name) {
	var setNum = 0;
	if (name == "Shirayuki") {
		for (let i = 298; i < 308; i++) {
			$gameVariables.setValue(i, $gameVariables.value(391)[setNum]);
			setNum = setNum + 1;
		}
	} else {
		for (let i = 378; i < 388; i++) {
			$gameVariables.setValue(i, $gameVariables.value(392)[setNum]);
			setNum = setNum + 1;
		}
	}
};

//■Ｈアニメ回想登録処理
var SDN_SetHanimeRef = function (filecode) {
	//Ｈアニメ回想登録に使用する変数は522番
	var setVari = 522;
	var v = $gameVariables.value(setVari) || [];
	var ary = [
		"Dummy",
		"BattleHAnime_A01a",
		"BattleHAnime_A01b",
		"BattleHAnime_A02a",
		"BattleHAnime_A02b",
		"BattleHAnime_A03a",
		"BattleHAnime_A03b",
		"BattleHAnime_A04b",
		"BattleHAnime_A05a",
		"BattleHAnime_A05b",
		"BattleHAnime_A06b",
		"BattleHAnime_A07a",
		"BattleHAnime_A07b",
		"BattleHAnime_A08a",
		"BattleHAnime_A08b",
		"BattleHAnime_A09b",
		"BattleHAnime_A10a",
		"BattleHAnime_A10b",
		"BattleHAnime_A11a",
		"BattleHAnime_A11b",
		"BattleHAnime_A12b",
		"BattleHAnime_A13a",
		"BattleHAnime_A13b",
		"BattleHAnime_A14b",
		"BattleHAnime_A15b",
		"BattleHAnime_A16b",
		"BattleHAnime_B01a",
		"BattleHAnime_B01b",
		"BattleHAnime_B02a",
		"BattleHAnime_B02b",
		"BattleHAnime_B03a",
		"BattleHAnime_B03b",
		"BattleHAnime_B04b",
		"BattleHAnime_B05a",
		"BattleHAnime_B05b",
		"BattleHAnime_B06b",
		"BattleHAnime_B07a",
		"BattleHAnime_B07b",
		"BattleHAnime_B08a",
		"BattleHAnime_B08b",
		"BattleHAnime_B09a",
		"BattleHAnime_B09b",
		"BattleHAnime_B10b",
		"BattleHAnime_B11a",
		"BattleHAnime_B11b",
		"BattleHAnime_B12b",
		"BattleHAnime_B13a",
		"BattleHAnime_B13b",
		"BattleHAnime_B14b",
		"BattleHAnime_B15b",
		"BattleHAnime_B16b",
		"Hanime_A01",
		"Hanime_A02",
		"Hanime_A03",
		"Hanime_A04",
		"Hanime_A05",
		"Hanime_A06",
		"Hanime_A07",
		"Hanime_A08",
		"Hanime_A09",
		"Hanime_A10",
		"Hanime_A11",
		"Hanime_A12",
		"Hanime_A13",
		"Hanime_A14",
		"Hanime_A15",
		"Hanime_B01",
		"Hanime_B02",
		"Hanime_B03",
		"Hanime_B04",
		"Hanime_B05",
		"Hanime_B06",
		"Hanime_B07",
		"Hanime_B08",
		"Hanime_B09",
		"Hanime_B10",
		"Hanime_B11",
		"Hanime_B12",
		"Hanime_B13",
		"Hanime_B14",
		"Hanime_B15"
	];
	var idx = ary.findIndex((e) => e && e == filecode);
	if (idx != -1) {
		v[idx] = true;
		$gameVariables.setValue(setVari, v);
		ConfigManager.saveCommonVariables();
	}
};
