function Window_EroStatus_kaihatu_select() {
	this.initialize(...arguments);
}

function Window_EroStatus_kaihatu_view() {
	this.initialize(...arguments);
}

(function () {
	// ########################################################
	// ################### 開発セレクト ######################
	// ########################################################
	Window_EroStatus_kaihatu_select.prototype = Object.create(Window_Selectable.prototype);
	Window_EroStatus_kaihatu_select.prototype.constructor = Window_EroStatus_kaihatu_select;

	Window_EroStatus_kaihatu_select.prototype.initialize = function (rect) {
		Window_Selectable.prototype.initialize.call(this, rect);
		this._additionalSprites = {};
		//最初に0番目って指定、commandではデフォでやってるけど

		// デフォではアクティブに
		this.makeList();
		this.select(0);
		this.activate();

		this.disp_list = {
			kou: {
				sira: [
					"I'm not really interested in kissing. If it's with\nsomeone I like, I don't think I'd hate it, but...",
					"Lately, I've started to think that using my mouth\nfor things might not be so bad...",
					"It's something you do with your mouth, but I feel\nlike I've gotten pretty good at it.",
					"I'm really confident in my tongue skills. Whether\nit's a deep kiss or a blowjob, I'm all for it."
				],
				yozu: [
					"I've never really wanted to try kissing or doing\nnaughty things with my mouth.",
					"It's not that I dislike using my mouth for play,\nbut I don't really feel like doing it on my own.",
					"I wonder if my lips are pretty sensitive? When\nthey're stimulated, my whole body gets all hot...",
					"People say my tongue work is pretty erotic. If it\nmakes my partner happy, I guess that's fine too."
				]
			},
			tibu: {
				sira: [
					"I don't like having my chest touched. It's the\nsame even if the other person is a woman.",
					"My chest has gotten a bit more sensitive, or maybe\nI just feel weird when it's touched.",
					"Was my chest always this sensitive? I thought I\ndidn't like being touched there...",
					"My boobs feel insanely good now. Just a little\ntouch and my nipples get hard..."
				],
				yozu: [
					"People say they're jealous of my big boobs, but\nthey just get in the way during training and make\nmy shoulders stiff. They're not that great.",
					"I've started to feel it when my boobs are touched now...",
					"My boobs might be super sensitive. When they're\ntouched, it feels so good.",
					"This is bad... My boobs have gotten way too\nsensitive. Just a little touch and my nipples get\nrock hard."
				]
			},
			man: {
				sira: [
					"Down there, I do feel something if it's touched,\nbut I don't really want to touch it myself.",
					"I feel like my pussy has gotten way more sensitive\nand gets wet more easily than before.",
					"I've started to feel a lot from my pussy. Just a\ntouch and I'm soaking wet...",
					"My pussy has gotten insanely sensitive, and if\nit's stimulated, I feel like I'll cum right away."
				],
				yozu: [
					"It's not that I don't feel anything, but it's a\ndelicate spot, so I don't really want to\noverstimulate it.",
					"It feels good when I touch it, and I've started to\nbe able to cum from it too.",
					"My pussy might be getting way easier to get wet. I\nfeel like it's getting more and more sensitive.",
					"Just imagining something naughty makes me all\nsoaked. I'm so restless I can't stand it."
				]
			},
			ana: {
				sira: [
					"Huh...? Doing stuff with my ass...? I seriously\ndon't even want to think about that.",
					"When my asshole gets touched, it feels kind of weird now.",
					"I've started to feel a lot from my asshole. I know\nit's kind of abnormal, but...",
					"My asshole keeps tingling and I can't calm down.\nMaybe I've just done way too much by now..."
				],
				yozu: [
					"I know there are ass play things out there, but...\nthat's just impossible for me.",
					"My butt hole... just a little, but I think I'm\nstarting to feel good from it...",
					"My asshole feels so good. Just having it played\nwith is enough to make me feel amazing...",
					"Lately, my asshole's gotten looser. I guess I've\nbeen messing with it too much, huh? I try to hold\nback, but it's pretty much impossible."
				]
			},
			hou: {
				sira: [
					"If it's someone I like, I might actually want to\ndo it for them...",
					"Making someone feel good sexually isn't bad. It's\nnot like I want to go out of my way to do it,\nthough...",
					"When I give someone sexual pleasure and see their\nface as they feel good, it sends shivers down my\nspine.",
					"Using my hands or my breasts to turn someone on\nmakes them so happy. Just watching that gets me\nexcited."
				],
				yozu: [
					"If it's with someone I love, I might want to do\nnaughty things for them...",
					"When I do naughty things for someone and they look\nlike they're feeling good, I've started to feel\nhappy about it too.",
					"I think I actually like making someone feel good\nwith naughty stuff. When they enjoy it, I get\nturned on too.",
					"I really love giving naughty service. Seeing their\nlewd face gives me such a sense of satisfaction."
				]
			},
			rosyu: {
				sira: [
					"No way, being naked in front of people is just\nimpossible―unless it's in the bath or something.",
					"When someone sees me naked, my body gets hot, or\nmaybe I just get turned on... I wonder why that\nis?",
					"I've started getting excited just being naked, and\nI can't get enough of being stared at. I never\nknew I had this kind of kink.",
					"When someone gets turned on from seeing me naked,\nit sends chills through me. Just being watched\ngets me all worked up."
				],
				yozu: [
					"Showing my skin to someone is actually kind of\nhard for me...",
					"When someone sees me naked, it's embarrassing, but\nit's not just that... I get this feeling I can't\neven describe.",
					"Lately, I've started fantasizing about what would\nhappen if I got naked here. Maybe I have an\nexhibitionist streak?",
					"I want to strip down and be naked, and have all\nkinds of people stare at me. It gets me so\nexcited."
				]
			},
			sou: {
				sira: [
					"I'm not interested in lewd stuff at all. It has\nnothing to do with me.",
					"Little by little, I've started getting interested\nin lewd things. I guess that's normal for a girl\nmy age.",
					"Maybe I'm actually a pretty lewd woman. I never\nthought I'd end up liking sex this much...",
					"Sometimes, out of nowhere, I start thinking about\nlewd things. My head is just full of dick."
				],
				yozu: [
					"Naughty stuff, huh... I still think it's way too\nsoon for me.",
					"I'm a girl at that age too, so it's not like I'm\nnot interested in naughty things, but...",
					"The more I learn about naughty stuff, the more I\nlike it. I never knew I was such a lewd girl...",
					"If I let my guard down even a little, I want to do\nnaughty things right away. My body aches deep\ninside and I can't take it anymore..."
				]
			}
		};
	};

	Window_EroStatus_kaihatu_select.prototype.numVisibleRows = function () {
		return 5;
	};
	Window_EroStatus_kaihatu_select.prototype.lineHeight = function () {
		return 84;
	};

	Window_EroStatus_kaihatu_select.prototype.makeList = function () {
		this._list = [
			{
				text: "Oral Dev.",
				id: "kou",
				sira: { rank: 246, exp: 253 },
				yozu: { rank: 326, exp: 333 }
			},
			{
				text: "Breast Dev.",
				id: "tibu",
				sira: { rank: 247, exp: 254 },
				yozu: { rank: 327, exp: 334 }
			},
			{
				text: "Pussy Dev.",
				id: "man",
				sira: { rank: 248, exp: 255 },
				yozu: { rank: 328, exp: 335 }
			},
			{
				text: "Anal Dev.",
				id: "ana",
				sira: { rank: 249, exp: 256 },
				yozu: { rank: 329, exp: 336 }
			},
			{
				text: "Service Dev.",
				id: "hou",
				sira: { rank: 251, exp: 258 },
				yozu: { rank: 331, exp: 338 }
			},
			{
				text: "Exhibition Dev.",
				id: "rosyu",
				sira: { rank: 250, exp: 257 },
				yozu: { rank: 330, exp: 337 }
			},
			{
				text: "Lewdness",
				id: "sou",
				sira: { rank: 245, exp: 252 },
				yozu: { rank: 325, exp: 332 }
			}
		];
	};

	Window_EroStatus_kaihatu_select.prototype.maxItems = function () {
		return this._list.length || 0;
	};

	Window_EroStatus_kaihatu_select.prototype.setViewWindow = function (viewWindow) {
		this._viewWindow = viewWindow;
	};

	//右のウィンドウにデータを渡す
	Window_EroStatus_kaihatu_select.prototype.callUpdateHelp = function () {
		if (this.active && this._viewWindow) {
			this.updateHelp();
		}
	};

	// ok押すとここも実行される
	Window_EroStatus_kaihatu_select.prototype.processOk = function () {
		if (this.isCurrentItemEnabled()) {
			this.callOkHandler();
		}
	};

	Window_EroStatus_kaihatu_select.prototype.do_ok = function () {
		var actor = $gameParty.menuActor();
		var chara = actor.name() == "Shirayuki" ? "sira" : "yozu";
		// D→0 A→3
		const info = this._list[this.index()];
		var rank_num = $gameVariables.value(info[chara].rank);
		var exp_val = $gameVariables.value(info[chara].exp);
		var keiken = [100, 350, 850, Infinity];

		if (exp_val >= keiken[rank_num]) {
			$gameVariables.setValue(info[chara].rank, rank_num + 1);

			AudioManager.playSe({ name: "Chime2", volume: 90, pitch: 100, pan: 0 });
			this.refresh();
			this._viewWindow.refresh();

			if (info.id == "sou") {
				var ary = ["exp0", "exp1", "exp2", "exp3"];

				if (chara == "sira") {
					var varNum = 245;

					if ($gameVariables.value(204) == 0) {
						var key = 10;
					} else {
						if ($gameVariables.value(204) == 1) {
							if ($gameSwitches.value(267)) {
								var key = 11;
							} else {
								key = 12;
							}
						} else if ($gameVariables.value(204) == 2) {
							var key = 10;
						} else if ($gameVariables.value(204) == 3) {
							var key = 11;
						}
					}
					// 表示された後妊娠描写をする
					if ($gameVariables.value(204) == 2 || $gameVariables.value(204) == 3) {
						SceneManager._scene.nin_flag = key;
					}
					// 	var key = 10; //"shirayuki_uniform_expression";
					// 	var key = 12; //"shirayuki_holdnaked_expression";
					// 	var key = 11; //"shirayuki_naked_expression";
				} else {
					var varNum = 325;
					if ($gameVariables.value(205) == 0) {
						var key = 13;
					} else {
						if ($gameVariables.value(205) == 1) {
							if ($gameSwitches.value(313)) {
								var key = 14;
							} else {
								var key = 15;
							}
						} else if ($gameVariables.value(205) == 2) {
							var key = 13;
						} else if ($gameVariables.value(205) == 3) {
							var key = 14;
						}
					}
					// 表示された後妊娠描写をする
					if ($gameVariables.value(205) == 2 || $gameVariables.value(205) == 3) {
						SceneManager._scene.nin_flag = key;
					}
					// 	var key = 13; //"yozuru_uniform_expression";
					// 	var key = 15; //"yozuru_holdnaked_expression";
					// 	var key = 14; //"yozuru_naked_expression";
				}
				SceneManager._scene.resetLive2d(key, ary[$gameVariables.value(varNum)]);
			}

			// ここでランクが上がるのでコモンイベント868（Ｈ称号習得処理）を実行
			const commonEvent = $dataCommonEvents[868];
			if (commonEvent) {
				const interpreter = new Game_Interpreter();
				interpreter.setup(commonEvent.list);
				interpreter.update();
			}
		} else {
			SoundManager.playBuzzer();
		}
	};
	Window_EroStatus_kaihatu_select.prototype.updateHelp = function () {
		this._viewWindow.setItem(this._list[this.index()]);
	};

	Window_EroStatus_kaihatu_select.prototype.drawItem = function (index) {
		const info = this._list[index];
		const rect = this.itemRectWithPadding(index);
		this.resetTextColor();
		//this.changePaintOpacity(this.isEnabled(savefileId));
		//this.drawTitle(savefileId, rect.x, rect.y + 4);
		//数値だったら
		//if (Number.isFinite(info)) {
		this.drawContents(info, rect);
		//}
	};

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

	Window_EroStatus_kaihatu_select.prototype.drawContents = function (info, rect) {
		const bottom = rect.y + rect.height;
		this.changeTextColor("#000000");
		this.contents.fontFace = "serif";
		this.contents.fontSize = 22;
		this.drawTextM(info.text, 15, rect.y - 27, 400, "left");

		var actor = $gameParty.menuActor();
		var chara = actor.name() == "Shirayuki" ? "sira" : "yozu";
		this.changeTextColor("#FFFFFF");
		this.contents.fontSize = 14;

		// D→0 A→3
		var rank_num = $gameVariables.value(info[chara].rank);
		this.drawTextExS(this.disp_list[info.id][chara][rank_num], 30, rect.y + 4, 400, "left");

		var exp_val = $gameVariables.value(info[chara].exp);
		var ary = ["D", "C", "B", "A"];
		var keiken = [100, 350, 850, Infinity];

		this.contents.fontSize = 52;
		this.drawTextM(ary[rank_num], 328, rect.y + 14, 100, "left");

		this.changeTextColor("#000000");
		this.contents.fontSize = 14;
		if (exp_val >= keiken[rank_num]) {
			this.contents.blt(this.menu_rank_skin, 0, 0, 208, 26, 175, rect.y + 1);
			this.drawTextM("RANK UP!!", 304, rect.y - 21, 100, "left");
		}
		this.drawTextM(`EXP: ${Math.min(exp_val, 9999)}`, 194, rect.y - 21, 100, "left");

		this.placeGauge(actor, `ero_${info.id}`, rect.x + 180, rect.y - 10, info[chara]);
	};

	Window_EroStatus_kaihatu_select.prototype.placeGauge = function (actor, type, x, y, info) {
		const key = "actor%1-gauge-%2".format(actor.actorId(), type);
		const sprite = this.createInnerSprite(key, Sprite_Gauge_Kaihatu);
		sprite.setup(actor, type, info);
		sprite.move(x, y);
		sprite.show();
	};

	Window_EroStatus_kaihatu_select.prototype.createInnerSprite = function (key, spriteClass) {
		const dict = this._additionalSprites;
		if (dict[key]) {
			return dict[key];
		} else {
			const sprite = new spriteClass();
			dict[key] = sprite;
			this.addInnerChild(sprite);
			return sprite;
		}
	};

	// ################# カーソルの変更 ##################
	Window_EroStatus_kaihatu_select.prototype.updatePadding = function () {
		this.padding = 0;
	};
	Window_EroStatus_kaihatu_select.prototype.colSpacing = function () {
		return 0;
	};

	Window_EroStatus_kaihatu_select.prototype.refreshCursor = function () {
		if (this._cursorAll) {
			this.refreshCursorForAll();
		} else if (this.index() >= 0) {
			const rect = this.itemRect(this.index());
			this.setCursorRect(rect.x, rect.y, 190, 92);
		} else {
			this.setCursorRect(0, 0, 0, 0);
		}
	};

	Window_EroStatus_kaihatu_select.prototype.refreshCursorForAll = function () {
		const maxItems = this.maxItems();
		if (maxItems > 0) {
			const rect = this.itemRect(0);
			rect.enlarge(this.itemRect(maxItems - 1));
			this.setCursorRect(rect.x, rect.y, 190, 92);
		} else {
			this.setCursorRect(0, 0, 0, 0);
		}
	};

	Window_EroStatus_kaihatu_select.prototype.loadWindowskin = function () {
		this.windowskin = ImageManager.loadSystem("Window");
		this.menu_cursor_skin = ImageManager.loadSystem("menu_kaihatu_selected");
		this.menu_rank_skin = ImageManager.loadSystem("erost_kaihatu_rankup");
	};

	Window_EroStatus_kaihatu_select.prototype._refreshCursor = function () {
		const drect = this._cursorRect.clone();
		const srect = { x: 0, y: 0, width: 190, height: 92 };
		const m = 0;
		for (const child of this._cursorSprite.children) {
			child.bitmap = this.menu_cursor_skin;
		}
		this._setRectPartsGeometry(this._cursorSprite, srect, drect, m);
	};

	//未選択コマンドの背景を画像に
	Window_EroStatus_kaihatu_select.prototype.drawItemBackground = function (index) {};

	Window_EroStatus_kaihatu_select.prototype._refreshAllParts = function () {
		//this._refreshBack();
		// this._refreshFrame();
		this._refreshCursor();
		this._refreshArrows();
		this._refreshPauseSign();
	};

	// ########################################################
	// ################### 開発のビュー ######################
	// ########################################################
	Window_EroStatus_kaihatu_view.prototype = Object.create(Window_Base.prototype);
	Window_EroStatus_kaihatu_view.prototype.constructor = Window_EroStatus_kaihatu_view;

	Window_EroStatus_kaihatu_view.prototype.initialize = function (rect) {
		Window_Base.prototype.initialize.call(this, rect);
		this._list = [
			{
				id: "kou",
				sira: { rank: 246, exp: 253 },
				yozu: { rank: 326, exp: 333 }
			},
			{
				id: "man",
				sira: { rank: 248, exp: 255 },
				yozu: { rank: 328, exp: 335 }
			},
			{
				id: "hou",
				sira: { rank: 251, exp: 258 },
				yozu: { rank: 331, exp: 338 }
			},
			{
				id: "tibu",
				sira: { rank: 247, exp: 254 },
				yozu: { rank: 327, exp: 334 }
			},

			{
				id: "ana",
				sira: { rank: 249, exp: 256 },
				yozu: { rank: 329, exp: 336 }
			},
			{
				id: "rosyu",
				sira: { rank: 250, exp: 257 },
				yozu: { rank: 330, exp: 337 }
			}
		];

		this.refresh();
	};

	Window_EroStatus_kaihatu_view.prototype.setItem = function (data) {
		this._data = data;
		this.refresh();
	};

	Window_EroStatus_kaihatu_view.prototype._refreshAllParts = function () {
		//this._refreshFrame();
		this._refreshCursor();
		this._refreshArrows();
		this._refreshPauseSign();
		this._refreshBack();
	};

	Window_EroStatus_kaihatu_view.prototype.loadWindowskin = function () {
		this.windowskin = ImageManager.loadSystem("erost_kaihatu_waku");

		var list_0 = ["sira", "yozu"];
		var list_1 = ["kou", "man", "hou", "tibu", "ana", "rosyu"];
		var list_2 = ["a", "b", "c", "d"];

		this.erost_kai_icon = {
			sira: {},
			yozu: {}
		};

		for (var c = 0; c < 2; c++) {
			this.erost_kai_icon[list_0[c]] = {};
			for (var i = 0; i < 6; i++) {
				this.erost_kai_icon[list_0[c]][list_1[i]] = {};
				for (var k = 0; k < 4; k++) {
					this.erost_kai_icon[list_0[c]][list_1[i]][list_2[k]] = ImageManager.loadSystem(
						`erost_kai_${list_0[c]}_${list_1[i]}_${list_2[k]}`
					);
				}
			}
		}
	};

	Window_EroStatus_kaihatu_view.prototype._refreshBack = function () {
		const sprite = this._backSprite;
		sprite.bitmap = this._windowskin;
	};

	Window_EroStatus_kaihatu_view.prototype.refresh = function () {
		//const rect = this.baseTextRect();
		this.contents.clear();

		var actor = $gameParty.menuActor();
		var chara = actor.name() == "Shirayuki" ? "sira" : "yozu";

		var list_1 = ["kou", "man", "hou", "tibu", "ana", "rosyu"];
		var list_2 = ["a", "b", "c", "d"];

		var x1 = 3;
		var x2 = 635;
		var y1 = 57;
		var y2 = 274;
		var y3 = 490;
		var y4 = 60;
		var rectList = [
			{ x: x1, y: y1 },
			{ x: x1, y: y2 },
			{ x: x1, y: y3 },
			{ x: x2, y: y4 },
			{ x: x2, y: y2 },
			{ x: x2, y: y3 }
		];

		for (var i = 0; i < 6; i++) {
			var info = this._list[i][chara];
			// D→0 A→3
			var rank_num = $gameVariables.value(info.rank);
			var ary = ["d", "c", "b", "a"];

			var img = this.erost_kai_icon[chara][list_1[i]][ary[rank_num]];
			const bitmap = img;
			const pw = img.width;
			const ph = img.height;
			const sx = 0;
			const sy = 0;
			this.contents.blt(bitmap, sx, sy, pw, ph, rectList[i].x, rectList[i].y);
		}
	};

	// 背景（枠）を一番上のレイヤーにする
	Window_EroStatus_kaihatu_view.prototype._createAllParts = function () {
		this._createContainer();
		this._createFrameSprite();
		this._createClientArea();
		this._createContentsBackSprite();
		this._createCursorSprite();
		this._createContentsSprite();
		this._createArrowSprites();
		this._createPauseSignSprites();
		this._createBackSprite();
	};

	Window_EroStatus_kaihatu_view.prototype._createBackSprite = function () {
		this._backSprite = new Sprite();
		this._backSprite.addChild(new TilingSprite());
		this.addChild(this._backSprite);
	};
})();

function Sprite_Gauge_Kaihatu() {
	this.initialize(...arguments);
}
Sprite_Gauge_Kaihatu.prototype = Object.create(Sprite_Gauge.prototype);
Sprite_Gauge_Kaihatu.prototype.constructor = Sprite_Gauge_Kaihatu;

Sprite_Gauge_Kaihatu.prototype.bitmapWidth = function () {
	return 168;
};
Sprite_Gauge_Kaihatu.prototype.gaugeHeight = function () {
	return 11;
};

Sprite_Gauge_Kaihatu.prototype.currentValue = function () {
	if (this._battler) {
		switch (this._statusType) {
			case "hp":
				return this._battler.hp;
			case "ero_kou":
				return $gameVariables.value(this.expVar);
			case "ero_man":
				return $gameVariables.value(this.expVar);
			case "ero_hou":
				return $gameVariables.value(this.expVar);
			case "ero_tibu":
				return $gameVariables.value(this.expVar);
			case "ero_ana":
				return $gameVariables.value(this.expVar);
			case "ero_rosyu":
				return $gameVariables.value(this.expVar);
			case "ero_sou":
				return $gameVariables.value(this.expVar);
		}
	}
	return NaN;
};

Sprite_Gauge_Kaihatu.prototype.currentMaxValue = function () {
	if (this._battler) {
		var keiken = [100, 350, 850, 9999];
		switch (this._statusType) {
			case "hp":
				return this._battler.mhp;
			case "ero_kou":
				return keiken[$gameVariables.value(this.maxRankVar)];
			case "ero_man":
				return keiken[$gameVariables.value(this.maxRankVar)];
			case "ero_hou":
				return keiken[$gameVariables.value(this.maxRankVar)];
			case "ero_tibu":
				return keiken[$gameVariables.value(this.maxRankVar)];
			case "ero_ana":
				return keiken[$gameVariables.value(this.maxRankVar)];
			case "ero_rosyu":
				return keiken[$gameVariables.value(this.maxRankVar)];
			case "ero_sou":
				return keiken[$gameVariables.value(this.maxRankVar)];
		}
	}
	return NaN;
};

Sprite_Gauge_Kaihatu.prototype.setup = function (battler, statusType, info) {
	this._battler = battler;
	this._statusType = statusType;

	this.maxRankVar = info.rank || 0;
	this.expVar = info.exp || 0;

	this._value = this.currentValue();
	this._maxValue = this.currentMaxValue();

	this.updateBitmap();
};

Sprite_Gauge_Kaihatu.prototype.redraw = function () {
	this.bitmap.clear();
	const currentValue = this.currentValue();
	if (!isNaN(currentValue)) {
		this.drawGauge();
	}
};
