code:
var Remtairy = Remtairy || {};
Remtairy.KarrynGlory = Remtairy.KarrynGlory || {};

//敵の位置
const GLORYHOLE_POS_LEFT_X = 275;
const GLORYHOLE_POS_LEFT_Y = 402;
const GLORYHOLE_POS_RIGHT_X = 1135;
const GLORYHOLE_POS_RIGHT_Y = 402;

const BATTLEBACK1_GLORYHOLE_NAME = 'Toilet1';

//=============================================================================
 /*:
 * @plugindesc Karryn Glory
 * @author Remtairy
 *
 * @help
 * This is a private plugin.
 * Do not redistribute, use, or modify this plugin
 * without explicit written permission from Remtairy.
 *
 */
//=============================================================================

const GLORY_SKILL_START = 1650;
const GLORY_SKILL_END = 1664;

const GLORY_CHANCE_OF_GUEST_IN_STALL_HEARING = 10;
const GLORY_CHANCE_OF_GUEST_AT_STALL_QUEUE_HEARING = 6;
const GLORY_CHANCE_OF_GUEST_AT_URINAL_HEARING = 2;
const GLORY_CHANCE_OF_GUEST_AT_URINAL_QUEUE_HEARING = 4;
const GLORY_CHANCE_OF_GUEST_AT_WASHING_QUEUE_HEARING = 1;

const GLORY_SPAWN_BASE_CHANCE = 5;
const GLORY_SPAWN_BASE_RANDOM_INT = 75;
const GLORY_SPAWN_RANDOM_INT_DEC_SINCE_LAST_SPAWN = 15;
const GLORY_SPAWN_EATERS_REP_LIMIT = 5;

const ENEMYTYPE_TOILET_OBS_TAG = 'toilet_obs';
const TOILET_OBS_ENEMY_ID = 38;

const GLORY_URINAL_A_ID = 2;
const GLORY_URINAL_B_ID = 3;
const GLORY_URINAL_C_ID = 4;
const GLORY_URINAL_D_ID = 5;
const GLORY_LEFT_STALL_ID = 6;
const GLORY_RIGHT_STALL_ID = 7;

const GLORY_FATIGUE_RECOVER_BASE = 2;
const GLORY_FATIGUE_RECOVER_RESTING = 0.2;
const GLORY_REST_TURNS = 10; //todo: change back to 5
const GLORY_MENTAL_PHASE_COOLDOWN = 3;

const GLORY_GUEST_ACTION_COOLDOWN = 2;
const GLORY_GUEST_BASE_PATIENCE = 8;
const GLORY_GUEST_SATISFACTION_GAIN_FROM_EMPTY_STOCK = 3;
const GLORY_GUEST_SATISFACTION_GAIN_FROM_FAVORED_SEX = 1;
const GLORY_GUEST_SATISFACTION_LOST_FROM_UNFAVORED_SEX = -1;
const GLORY_GUEST_SATISFACTION_LOST_FROM_NOT_GETTING_TO_HOLE = -2;
const GLORY_GUEST_SATISFACTION_LOST_FROM_NOT_EMPTY_STOCK = -4;

//////////
///////////////////
// Game Party
////////////////////
///////////////

Object.defineProperty(Game_Party.prototype, "isInGloryBattle", {
	get: function () { return this._isInGloryBattle; }, configurable: true
});
Game_Party.prototype.setIsInGloryBattleFlag = function(status) {
	this._isInGloryBattle = status;
};

Game_Party.prototype.preGloryBattleSetup = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	this.preBattleSetup();
	$gameMap.changeBattleback(BATTLEBACK1_GLORYHOLE_NAME, null);
	this.setIsInGloryBattleFlag(true);

	this.increaseFatigueGain(GLORY_FATIGUE_RECOVER_BASE * -1, true)

	this._gloryBattle_guestSatisfaction = 0;

	actor.preGloryBattleSetup();
};

Game_Party.prototype.postGloryBattleCleanup = function() {
	this.setIsInGloryBattleFlag(false);
	$gameSwitches.setValue(SWITCH_TODAY_GLORYHOLE_BATTLE_ID, true);

	if(this._gloryBattle_guestSatisfaction > 0) {
		let addRep = 1;
		if(this._gloryReputation <= 10 && Math.randomInt(100) < this._gloryBattle_guestSatisfaction) addRep++;
		this.increaseGloryReputation(addRep);
		//$gameSwitches.setValue(SWITCH_TODAY_BAR_REP_UP_ID, true);
	}
	else if(this._gloryBattle_guestSatisfaction < 0) {
		let addRep = -1;
		if(Math.randomInt(100) < this._gloryBattle_guestSatisfaction * -1) addRep--;
		this.increaseGloryReputation(addRep);
	}

	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	actor.putOnGlovesAndHat();
	actor.changeToWardenClothing();

};

Game_Party.prototype.applyEndOfBattleSpecial_gloryBattle = function() {
	for(let i = 0; i < $gameTroop._gloryWashingQueue.length; ++i) {
		$gameTroop._gloryWashingQueue[i].gloryBattle_pollSatisfaction(true);
	}
	for(let i = 0; i < $gameTroop._gloryStallQueue.length; ++i) {
		$gameTroop._gloryStallQueue[i].gloryBattle_pollSatisfaction(true);
	}
	if(this._gloryLeftStall) {
		this._gloryLeftStall.gloryBattle_pollSatisfaction(true);
	}
	if(this._gloryRightStall) {
		this._gloryRightStall.gloryBattle_pollSatisfaction(true);
	}
};

Game_Party.prototype.setGloryReputation = function(value) {
	let minGloryRep = 0;

	this._gloryReputation = Math.max(minGloryRep, value);
	$gameVariables.setValue(VARIABLE_GLORY_REPUTATION_ID, this._gloryReputation);
};
Game_Party.prototype.increaseGloryReputation = function(value) {
	this.setGloryReputation(this._gloryReputation + value);
};

Game_Party.prototype.increaseGloryGuestSatisfaction = function(value) {
	this._gloryBattle_guestSatisfaction += value;
};

////////////////
// Game Actor
////////////////

Game_Actor.prototype.preGloryBattleSetup = function() {
	this.preBattleSetup();
	this.setAsNoHalberdBattle();
	this.removeState(STATE_CONFIDENT_ID);
	this.takeOffPanties();
	this.removeClothing();

	this.setTachiePussyToyExtension_gloryBattle('left');
	this.setTachieAnalToyExtension_gloryBattle('right');
	this.setToiletSittingPose();
	this.setTachieLegs('close');

	this._gloryBattle_restingTilTurn = -1;
	this._gloryBattle_turnsTillMentalPhase = 0;
	this._gloryBattle_cocksAppeared = 0;
	this._gloryBattle_safeExit = false;
	this._gloryBattle_badExit = false;

	this._dirty = true;
};

// Tachie
Game_Actor.prototype.setTachiePussyToyExtension_gloryBattle = function(name) {
	this._gloryBattle_tachiePussyToyExtension = name;
};
Game_Actor.prototype.setTachieAnalToyExtension_gloryBattle = function(name) {
	this._gloryBattle_tachieAnalToyExtension = name;
};

Game_Actor.prototype.getTachiePussyToyExtension_gloryBattle = function() {
	return this._gloryBattle_tachiePussyToyExtension;
};
Game_Actor.prototype.getTachieAnalToyExtension_gloryBattle = function() {
	return this._gloryBattle_tachieAnalToyExtension;
};

Game_Actor.prototype.gloryBattle_makeSexualNoise = function(value) {
	let noiseMultipler = 1;
	let generalReactionScore = this.getReactionScore();

	if(generalReactionScore >= VAR_DEF_RS_LV3_REQ)
		noiseMultipler = 6;
	else if(generalReactionScore >= VAR_DEF_RS_LV2_REQ)
		noiseMultipler = 3.5;
	else if(generalReactionScore >= VAR_DEF_RS_LV1_REQ)
		noiseMultipler = 2;

	let noiseValue = value * noiseMultipler;
	if(noiseValue <= 1) return;

	if($gameTroop._gloryLeftStall) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_IN_STALL_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryLeftStall._guest_intentIsForHole) {
				$gameTroop._gloryLeftStall._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryLeftStall.gloryBattle_increasePleasureFromHearing_close();
			}
		}
	}
	if($gameTroop._gloryRightStall) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_IN_STALL_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryRightStall._guest_intentIsForHole) {
				$gameTroop._gloryRightStall._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryRightStall.gloryBattle_increasePleasureFromHearing_close();
			}
		}
	}
	if($gameTroop._gloryUrinalA) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_AT_URINAL_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryUrinalA._guest_intentIsForHole) {
				$gameTroop._gloryUrinalA._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryUrinalA.gloryBattle_increasePleasureFromHearing_far();
			}
		}
	}
	if($gameTroop._gloryUrinalB) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_AT_URINAL_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryUrinalB._guest_intentIsForHole) {
				$gameTroop._gloryUrinalB._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryUrinalB.gloryBattle_increasePleasureFromHearing_far();
			}
		}
	}
	if($gameTroop._gloryUrinalC) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_AT_URINAL_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryUrinalC._guest_intentIsForHole) {
				$gameTroop._gloryUrinalC._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryUrinalC.gloryBattle_increasePleasureFromHearing_far();
			}
		}
	}
	if($gameTroop._gloryUrinalD) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_AT_URINAL_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryUrinalD._guest_intentIsForHole) {
				$gameTroop._gloryUrinalD._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryUrinalD.gloryBattle_increasePleasureFromHearing_far();
			}
		}
	}

	for(let i = 0; i < $gameTroop._gloryStallQueue; ++i) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_AT_STALL_QUEUE_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryStallQueue[i]._guest_intentIsForHole) {
				$gameTroop._gloryStallQueue[i]._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryStallQueue[i].gloryBattle_increasePleasureFromHearing_close();
			}
		}
	}
	for(let i = 0; i < $gameTroop._gloryUrinalQueue; ++i) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_AT_URINAL_QUEUE_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryUrinalQueue[i]._guest_intentIsForHole) {
				$gameTroop._gloryUrinalQueue[i]._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryUrinalQueue[i].gloryBattle_increasePleasureFromHearing_far();
			}
		}
	}
	for(let i = 0; i < $gameTroop._gloryWashingQueue; ++i) {
		let hearingChance = GLORY_CHANCE_OF_GUEST_AT_WASHING_QUEUE_HEARING;
		let guestHeard = Math.randomInt(100) < hearingChance * noiseValue;
		if(guestHeard) {
			if(!$gameTroop._gloryWashingQueue[i]._guest_intentIsForHole) {
				$gameTroop._gloryWashingQueue[i]._guest_intentIsForHole = true;
			}
			else {
				$gameTroop._gloryWashingQueue[i].gloryBattle_increasePleasureFromHearing_far();
			}
		}
	}
};

Game_Actor.prototype.gloryXParamRate = function(id) {
	let passiveRate = 1;
	if($gameParty.isInGloryBattle) {
		if(id === XPARAM_STA_REGEN_ID) {
			passiveRate = 0.25;

			if($gameTroop.getCurrentTurn_gloryBattle() < this._gloryBattle_restingTilTurn) {
				passiveRate *= 5;
			}
		}

	}

	return passiveRate;
};

Game_Actor.prototype.glorySParamRate = function(id) {
	let passiveRate = 1;
	if($gameParty.isInGloryBattle) {
		if(id === SPARAM_WP_REGEN_ID) {
			passiveRate = 0.2;
		}
	}
	return passiveRate;
};

Game_Actor.prototype.gloryBattle_reactToNewCock = function() {
	//todo: maybe don't say anything if head is 'close' ?
	if(this._gloryBattle_cocksAppeared === 0) {
		BattleManager.actionRemLines(KARRYN_LINE_GLORY_HOLE_APPEAR_FIRST);
	}
	else if(!this.justOrgasmed()){
		let numOfCocks = 0;
		if(!$gameTroop.gloryBattle_leftHoleIsEmpty()) numOfCocks++;
		if(!$gameTroop.gloryBattle_rightHoleIsEmpty()) numOfCocks++;
		if(numOfCocks === 1)
			BattleManager.actionRemLines(KARRYN_LINE_GLORY_HOLE_APPEAR_MID);
	}

	this._gloryBattle_cocksAppeared++;
	this._playthroughRecordGloryCocksAppearedCount++;

	this.emoteMasterManager_GloryBattle();
};

Game_Actor.prototype.gloryBattle_bodySlotsWithPenis = function() {
	let count = 0;

	if(this.isBodySlotPenis(LEFT_HAND_ID)) count++;
	if(this.isBodySlotPenis(RIGHT_HAND_ID)) count++;
	if(this.isBodySlotPenis(MOUTH_ID)) count++;
	if(this.isBodySlotPenis(PUSSY_ID)) count++;
	if(this.isBodySlotPenis(ANAL_ID)) count++;

	return count;

};

Game_Actor.prototype.gloryBattle_fatigueGainPerTurn = function() {
	if(!this.isInToiletSittingPose()) {
		$gameParty.increaseFatigueGain(PRISON_FATIGUE_PER_TURN_OTHER);
	}
};

//Post sex acts
Game_Actor.prototype.postDamage_basicSex_gloryBattle = function(target, sexAct) {
	let enemyWeakness = 1;
	if(sexAct == SEXACT_BLOWJOB) {
		enemyWeakness = target.weaknessToBlowjob();
		this.gloryBattle_makeSexualNoise(3);
	}
	else if(sexAct == SEXACT_HANDJOB) {
		enemyWeakness = target.weaknessToHandjob();
		this.gloryBattle_makeSexualNoise(2);
	}
	else if(sexAct == SEXACT_PUSSYSEX) {
		enemyWeakness = target.weaknessToPussy();
		this.gloryBattle_makeSexualNoise(4);
	}
	else if(sexAct == SEXACT_ANALSEX) {
		enemyWeakness = target.weaknessToAnal();
		this.gloryBattle_makeSexualNoise(4);
	}

	if(enemyWeakness > 1) target._guest_gotFavoredSex = true;
	else if(enemyWeakness < 1) target._guest_gotUnfavoredSex = true;
};

Game_Actor.prototype.postDamage_ejaculation_gloryBattle = function(target, area, semen) {
	if(area == CUM_CREAMPIE_PUSSY || area == CUM_CREAMPIE_ANAL) {
		this.gloryBattle_makeSexualNoise(4);
		this._playthroughRecordGloryCreampieML += semen;
	}
	else if(area == CUM_SWALLOW_MOUTH) {
		this.gloryBattle_makeSexualNoise(4);
		this._playthroughRecordGlorySwallowML += semen;
	}
	else {
		this.gloryBattle_makeSexualNoise(3);
	}

};

Game_Actor.prototype.postDamage_femaleOrgasm_gloryBattle = function(orgasmCount) {
	this.gloryBattle_makeSexualNoise(6 * orgasmCount);

	if($gameTroop._gloryLeftStall && $gameTroop._gloryLeftStall._guest_currentlyEating) {
		this._playthroughRecordGloryOrgasmWhileGuestEatingCount++;
	}
	if($gameTroop._gloryLeftStall && $gameTroop._gloryLeftStall._guest_currentlyEating) {
		this._playthroughRecordGloryOrgasmWhileGuestEatingCount++;
	}
};

//////
// Skills

Game_Actor.prototype.showEval_gloryBreather = function() {
	return this.gloryBattle_bodySlotsWithPenis() > 0;
};
Game_Actor.prototype.customReq_gloryBreather = function() {
	return true;
};
Game_Actor.prototype.afterEval_gloryBreather = function() {
	//reduce enemy patiences?
	this.emoteMasterManager_GloryBattle();
};

Game_Actor.prototype.customReq_gloryRest = function() {
	return true;
};
Game_Actor.prototype.skillCost_gloryRest = function() {
	let cost = 3 + this.realMaxEnergy * 0.1;

	return Math.round(cost * this.esc);
};
Game_Actor.prototype.afterEval_gloryRest = function() {
	BattleManager.pullOutAllEnemies();
	this.setToiletSittingPose();
	if(this.justOrgasmed())
		this.setTachieLegs('spread');
	else
		this.setTachieLegs('close');

	this._gloryBattle_restingTilTurn = $gameTroop.getCurrentTurn_gloryBattle() + GLORY_REST_TURNS;
	this.emoteMasterManager_GloryBattle();
};
Game_Actor.prototype.gloryRestTurnEffect = function() {
	if(this.stamina === this.maxstamina) {
		$gameParty.increaseFatigueGain(GLORY_FATIGUE_RECOVER_RESTING * -1, true)
	}
};

Game_Actor.prototype.afterEval_glorySkillExit = function() {
	if($gameTroop._gloryWashingQueue.length > 0 || $gameTroop._gloryStallQueue.length > 0 || $gameTroop._gloryUrinalQueue.length > 0)
		this._gloryBattle_badExit = true;
	else if($gameTroop._gloryUrinalA || $gameTroop._gloryUrinalB || $gameTroop._gloryUrinalC || $gameTroop._gloryUrinalD)
		this._gloryBattle_badExit = true;
	else if(!$gameTroop.gloryBattle_bothHolesAreEmpty())
		this._gloryBattle_badExit = true;
	else
		this._gloryBattle_safeExit = true;
};

Game_Actor.prototype.showEval_karrynSexSkills_gloryBattle = function() {
	if($gameTroop.gloryBattle_bothHolesAreEmpty()) {
		return false;
	}
	else return true;
};

///////
// Posejoin

Game_Actor.prototype.gloryBattle_beforePoseJoin = function(target, sexAct, isRightHJ, isLeftHJ) {
	let currentlyInToiletSittingPose = this.isInToiletSittingPose();
	let currentlyInToiletSitLeftPose = this.isInToiletSitLeftPose();
	let currentlyInToiletSitRightPose = this.isInToiletSitRightPose();
	let currentlyInToiletStandLeftPose = this.isInToiletStandLeftPose();
	let currentlyInToiletStandRightPose = this.isInToiletStandRightPose();

	let currentlyGivingLeftHoleHJ = this.isBodySlotPenis(RIGHT_HAND_ID);
	let currentlyGivingRightHoleHJ = this.isBodySlotPenis(LEFT_HAND_ID);
	let currentlyGivingBJ = this.isBodySlotPenis(MOUTH_ID);
	let currentlyHavingPussySex = this.isBodySlotPenis(PUSSY_ID);
	let currentlyHavingAnalSex = this.isBodySlotPenis(ANAL_ID);

	let currentlyLegsAreSpread = this.tachieLegs === 'spread';
	let currentlyLegsAreClose = this.tachieLegs === 'close';

	let leftHoleIsEmpty = $gameTroop.gloryBattle_leftHoleIsEmpty();
	let rightHoleIsEmpty = $gameTroop.gloryBattle_rightHoleIsEmpty();
	let targetIsLeftHole = target._guest_atStall === GLORY_LEFT_STALL_ID;
	let targetIsRightHole = target._guest_atStall === GLORY_RIGHT_STALL_ID;

	if(sexAct === SEXACT_HANDJOB) {
		if(currentlyInToiletSitLeftPose || currentlyInToiletSitRightPose) {
			if(currentlyInToiletSitLeftPose && targetIsRightHole) {
				if(!leftHoleIsEmpty) {
					BattleManager.pullOutEnemy($gameTroop._gloryLeftStall);
				}
				this.setToiletSittingPose();
			}
			else if(currentlyInToiletSitRightPose && targetIsLeftHole) {
				if(!rightHoleIsEmpty) {
					BattleManager.pullOutEnemy($gameTroop._gloryRightStall);
				}
				this.setToiletSittingPose();
			}
			else if(currentlyInToiletStandRightPose && targetIsRightHole) {
				BattleManager.pullOutEnemy($gameTroop._gloryLeftStall);
				BattleManager.pullOutEnemy($gameTroop._gloryRightStall);
				this.setToiletSitRightPose();
			}
			else if(currentlyInToiletStandLeftPose && targetIsLeftHole) {
				BattleManager.pullOutEnemy($gameTroop._gloryLeftStall);
				BattleManager.pullOutEnemy($gameTroop._gloryRightStall);
				this.setToiletSitLeftPose();
			}

			let changedToSittingPose = this.isInToiletSittingPose();

			if(changedToSittingPose) {
				if(currentlyLegsAreSpread || currentlyInToiletStandLeftPose || currentlyInToiletStandRightPose)
					this.setTachieLegs('spread');
				else
					this.setTachieLegs('close');

				if(targetIsRightHole && !leftHoleIsEmpty && currentlyGivingLeftHoleHJ) {
					$gameTroop._gloryLeftStall.beforeEval_join_generic_righthand(this, true);
				}
				else if(targetIsLeftHole && !rightHoleIsEmpty && currentlyGivingRightHoleHJ) {
					$gameTroop._gloryRightStall.beforeEval_join_generic_lefthand(this, true);
				}
			}
		}
		else if(currentlyInToiletStandLeftPose || currentlyInToiletStandRightPose) {

		}
	}
	else if(sexAct === SEXACT_BLOWJOB) {
		if(targetIsLeftHole) {
			if(currentlyInToiletStandRightPose) {
				return;
			}

			if(!rightHoleIsEmpty) {
				BattleManager.pullOutEnemy($gameTroop._gloryRightStall);
			}

			if(!currentlyGivingLeftHoleHJ) {
				BattleManager.pullOutEnemy($gameTroop._gloryLeftStall);
			}

			this.setToiletSitLeftPose();

			if(currentlyLegsAreSpread || currentlyInToiletStandLeftPose || currentlyInToiletStandRightPose)
				this.setTachieLegs('spread');
			else
				this.setTachieLegs('close');

			if(currentlyGivingLeftHoleHJ) {
				$gameTroop._gloryLeftStall.beforeEval_join_generic_righthand(this, true);
			}
		}
		else if(targetIsRightHole) {
			if(currentlyInToiletStandLeftPose) {
				return;
			}

			if(!leftHoleIsEmpty) {
				BattleManager.pullOutEnemy($gameTroop._gloryLeftStall);
			}

			if(!currentlyGivingRightHoleHJ) {
				BattleManager.pullOutEnemy($gameTroop._gloryRightStall);
			}

			this.setToiletSitRightPose();

			if(currentlyLegsAreSpread || currentlyInToiletStandLeftPose || currentlyInToiletStandRightPose)
				this.setTachieLegs('spread');
			else
				this.setTachieLegs('close');

			if(currentlyGivingRightHoleHJ) {
				$gameTroop._gloryRightStall.beforeEval_join_generic_lefthand(this, true);
			}
		}
	}
	else if(sexAct === SEXACT_PUSSYSEX || sexAct === SEXACT_ANALSEX) {
		if(targetIsLeftHole) {
			BattleManager.pullOutEnemy($gameTroop._gloryLeftStall);

			if(currentlyInToiletStandLeftPose) {
				return;
			}

			if(!rightHoleIsEmpty) {
				BattleManager.pullOutEnemy($gameTroop._gloryRightStall);
			}

			this.setToiletStandLeftPose();

			if(!rightHoleIsEmpty) {
				if(currentlyGivingRightHoleHJ) {
					$gameTroop._gloryRightStall.beforeEval_join_generic_lefthand(this, true);
				}
				if(currentlyInToiletSitRightPose && currentlyGivingBJ) {
					$gameTroop._gloryRightStall.beforeEval_join_generic_mouth(this, true);
				}

			}

		}
		else if(targetIsRightHole) {
			BattleManager.pullOutEnemy($gameTroop._gloryRightStall);

			if(currentlyInToiletStandRightPose) {
				return;
			}

			if(!leftHoleIsEmpty) {
				BattleManager.pullOutEnemy($gameTroop._gloryLeftStall);
			}

			this.setToiletStandRightPose();

			if(!leftHoleIsEmpty) {
				if(currentlyGivingLeftHoleHJ) {
					$gameTroop._gloryLeftStall.beforeEval_join_generic_righthand(this, true);
				}
				if(currentlyInToiletSitLeftPose && currentlyGivingBJ) {
					$gameTroop._gloryLeftStall.beforeEval_join_generic_mouth(this, true);
				}

			}

		}
	}

};

Game_Actor.prototype.gloryBattle_postEnemyPullout = function() {
	let currentlyInToiletSittingPose = this.isInToiletSittingPose();
	let currentlyInToiletSitLeftPose = this.isInToiletSitLeftPose();
	let currentlyInToiletSitRightPose = this.isInToiletSitRightPose();
	let currentlyInToiletStandLeftPose = this.isInToiletStandLeftPose();
	let currentlyInToiletStandRightPose = this.isInToiletStandRightPose();

	let currentlyGivingLeftHoleHJ = this.isBodySlotPenis(RIGHT_HAND_ID);
	let currentlyGivingRightHoleHJ = this.isBodySlotPenis(LEFT_HAND_ID);
	let currentlyGivingBJ = this.isBodySlotPenis(MOUTH_ID);
	let currentlyHavingPussySex = this.isBodySlotPenis(PUSSY_ID);
	let currentlyHavingAnalSex = this.isBodySlotPenis(ANAL_ID);

	let leftHoleIsEmpty = $gameTroop.gloryBattle_leftHoleIsEmpty();
	let rightHoleIsEmpty = $gameTroop.gloryBattle_rightHoleIsEmpty();

	if(currentlyInToiletSitLeftPose || currentlyInToiletSitRightPose) {
		if(!currentlyGivingBJ) {
			this.setToiletSittingPose();
			if(this.justOrgasmed())
				this.setTachieLegs('spread');
			else
				this.setTachieLegs('close');

			if(currentlyGivingLeftHoleHJ && !leftHoleIsEmpty) {
				$gameTroop._gloryLeftStall.beforeEval_join_generic_righthand(this, true);
			}
			if(currentlyGivingRightHoleHJ && !rightHoleIsEmpty) {
				$gameTroop._gloryLeftStall.beforeEval_join_generic_lefthand(this, true);
			}
		}
	}

	if(currentlyHavingPussySex || currentlyHavingAnalSex) {
		if(!currentlyGivingBJ && !currentlyHavingPussySex && !currentlyHavingAnalSex) {
			this.setToiletSittingPose();
			if(this.justOrgasmed())
				this.setTachieLegs('spread');
			else
				this.setTachieLegs('close');

			if(currentlyGivingLeftHoleHJ && !leftHoleIsEmpty) {
				$gameTroop._gloryLeftStall.beforeEval_join_generic_righthand(this, true);
			}
			if(currentlyGivingRightHoleHJ && !rightHoleIsEmpty) {
				$gameTroop._gloryLeftStall.beforeEval_join_generic_lefthand(this, true);
			}
		}

	}

};

//////////////
////////////////
// Game Troop
////////////////
//////////////

//////
// Setup

//troop setup
Game_Troop.prototype.setupGloryBattle = function(troopId) {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	this._gloryStallQueue = [];
	this._gloryUrinalQueue = [];
	this._gloryWashingQueue = [];

	this._gloryLeftStall = false;
	this._gloryRightStall = false;
	this._gloryUrinalA = false;
	this._gloryUrinalB = false;
	this._gloryUrinalC = false;
	this._gloryUrinalD = false;

	this._gloryTurnCounter = 0;

	this._gloryGuestsSpawnedCount = 0;
	this._gloryGuestLastSpawnedTurn = 0;

	this.calculateGloryGuestsSpawnLimit();

	this._toiletObs = new Game_Enemy(TOILET_OBS_ENEMY_ID, 0, 0, false, TOILET_OBS_ENEMY_ID);
	this._enemies.push(this._toiletObs);

};

Game_Troop.prototype.calculateGloryGuestsSpawnLimit = function() {
	this._gloryGuestsSpawnLimit = 5;

	//Food & Drugs Edicts
	if(!Karryn.hasEdict(EDICT_REPAIR_KITCHEN_AND_MESS_HALL)) {
		this._gloryGuestsSpawnLimit -= 3;
	}
	else {
		if(Karryn.hasEdict(EDICT_HIRE_COOKS)) {
			this._gloryGuestsSpawnLimit += 1;
		}
		if(Karryn.hasEdict(EDICT_BULK_FOOD_SUPPLIER)) {
			this._gloryGuestsSpawnLimit += 1;
		}
		if(Karryn.hasEdict(EDICT_EXPAND_INMATE_MENU)) {
			this._gloryGuestsSpawnLimit += 1;
		}
		if(Karryn.hasEdict(EDICT_APHRODISIACS_IN_INMATE_FOOD)) {
			this._gloryGuestsSpawnLimit += 1;
		}
		if(Karryn.hasEdict(EDICT_APHRODISIACS_DRUGS_FOR_INMATES)) {
			this._gloryGuestsSpawnLimit += 1;
		}
		if(Karryn.hasEdict(EDICT_PAY_FOR_BETTER_FOOD)) {
			this._gloryGuestsSpawnLimit -= 1;
		}
	}

	//Level 2 Edicts
	if(Karryn.hasEdict(EDICT_GIVE_IN_TO_NERD_BLACKMAIL)) {
		this._gloryGuestsSpawnLimit += 2;
	}

	if(Karryn.hasEdict(EDICT_FIGHT_ROGUE_DISTRACTIONS_WITH_DISTRACTIONS)) {
		this._gloryGuestsSpawnLimit += 2;
	}
	else if(Karryn.hasEdict(EDICT_FORCE_ROGUES_INTO_LABOR)) {
		this._gloryGuestsSpawnLimit -= 1;
	}

	//Passives
	if(Karryn.hasPassive(PASSIVE_URINAL_COUNT_THREE_ID)) {
		this._gloryGuestsSpawnLimit += 3;
	}
	else if(Karryn.hasPassive(PASSIVE_URINAL_COUNT_TWO_ID)) {
		this._gloryGuestsSpawnLimit += 2;
	}
	else if(Karryn.hasPassive(PASSIVE_URINAL_COUNT_ONE_ID)) {
		this._gloryGuestsSpawnLimit += 1;
	}

	//Levels Status
	if(Prison.prisonLevelOneIsRioting()) {
		this._gloryGuestsSpawnLimit -= 2;
	}
	else if(Karryn.hasEdict(EDICT_THUGS_STRESS_RELIEF)) {
		this._gloryGuestsSpawnLimit += 1;
	}
	if(Prison.prisonLevelTwoIsRioting()) {
		this._gloryGuestsSpawnLimit -= 2;
	}
	if(!Prison.prisonLevelThreeIsRioting() && Karryn.hasEdict(EDICT_LEVEL_THREE_SUBJUGATED)) {
		this._gloryGuestsSpawnLimit += 1;
	}
	if(!Prison.prisonLevelFourIsRioting() && Karryn.hasEdict(EDICT_LEVEL_FOUR_SUBJUGATED)) {
		this._gloryGuestsSpawnLimit += 1;
	}

	if($gameParty._gloryReputation >= 10) {
		this._gloryGuestsSpawnLimit += 5 + Math.round(($gameParty._gloryReputation - 10) * 0.2);
	}
	else {
		this._gloryGuestsSpawnLimit += Math.round($gameParty._gloryReputation * 0.5);
	}
};

Game_Troop.prototype.getCurrentTurn_gloryBattle = function() {
	return this._gloryTurnCounter;
};

Game_Troop.prototype.gloryBattle_leftHoleIsEmpty = function() {
	return !this._gloryLeftStall ||
	(this._gloryLeftStall && !this._gloryLeftStall._guest_showedThroughHole);
};
Game_Troop.prototype.gloryBattle_rightHoleIsEmpty = function() {
	return !this._gloryRightStall ||
	(this._gloryRightStall && !this._gloryRightStall._guest_showedThroughHole);
};
Game_Troop.prototype.gloryBattle_bothHolesAreEmpty = function() {
	return this.gloryBattle_leftHoleIsEmpty() && this.gloryBattle_rightHoleIsEmpty();
};

Game_Troop.prototype.gloryBattle_calculateChanceToSpawnGuest = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let chance = GLORY_SPAWN_BASE_CHANCE;

	chance += 2 * $gameParty._gloryReputation;
	chance += 2 * $gameParty._gloryBattle_guestSatisfaction;

	// Karryn's noise level (masturbating, orgasming, sex)
	// Is Level 2 rioting?
	// Certain level 2 work related edicts

	return chance;
};

Game_Troop.prototype.gloryBattle_calculateChanceForSpawnedGuestIsHereForHole = function(enemy) {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let chance = 0;

	chance += enemy._enemyRecordGloryBattleEjaculationCount * 5;
	chance += $gameParty._gloryReputation * 2;
	chance += $gameParty._gloryBattle_guestSatisfaction * 5;

	chance += 100; //todo: remove

	return chance;
};

Game_Troop.prototype.gloryBattle_calculateChanceForSpawnedGuestIsHereForEating = function(enemy) {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let chance = 35;

	chance -= enemy._enemyRecordGloryBattleEjaculationCount * 10;
	chance -= $gameParty._gloryReputation * 2;
	chance -= $gameParty._gloryBattle_guestSatisfaction * 5;

	if(enemy.hasHungryPrefix())
		chance += 60;
	else if(enemy.hasStarvingPrefix())
		chance += 120;
	else if(enemy.hasVirginPrefix() || enemy.hasWeakPrefix() || enemy.hasBadPrefix() || enemy.hasSlowPrefix() || enemy.hasIneptPrefix())
		chance += 25;
	else if(enemy.hasGoodPrefix() || enemy.hasStrongPrefix() || enemy.hasDexterousPrefix() || enemy.hasSadoPrefix() || enemy.hasAgilePrefix())
		chance -= 25;
	else if(enemy.hasElitePrefix())
		chance -= 45;

	if(enemy.isNerdType)
		chance *= 1.5;

	return chance;
};

//on turn end
Game_Troop.prototype.onTurnEndSpecial_gloryBattle = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);

	////////////
	//Turn counter increment and spawn guest
	this._gloryTurnCounter++;
	actor._gloryBattle_turnsTillMentalPhase = Math.max(0, actor._gloryBattle_turnsTillMentalPhase - 1);
	this.gloryBattle_spawnGuest(false);

	//////////
	//Queues

	//Washing Queue
	if(this._gloryWashingQueue.length > 0) {
		let frontWashingGuest = this._gloryWashingQueue[0];
		if(frontWashingGuest._guest_currentlyWashing) {
			frontWashingGuest.gloryBattle_leaveWashingQueue();

			if(frontWashingGuest._guest_intentIsForHole && !frontWashingGuest._guest_showedThroughHole) {
				frontWashingGuest.gloryBattle_joinStallQueue();
			}
			else {
				frontWashingGuest.gloryBattle_leaveBathroom();
			}
		}
		else {
			frontWashingGuest._guest_currentlyWashing = true;
		}

		for(let i = 1; i < this._gloryWashingQueue.length; ++i) {
			if(this._gloryWashingQueue[i]._guest_intentIsForHole && !this._gloryWashingQueue[i]._guest_showedThroughHole) {
				this._gloryWashingQueue[i].gloryBattle_leaveWashingQueue();
				this._gloryWashingQueue[i].gloryBattle_joinStallQueue();
			}
		}
	}

	//Urinal Queue
	if(this._gloryUrinalQueue.length > 0) {
		let frontUrinalGuest = this._gloryUrinalQueue[0];

		let availableUrinalsArray = [];
		if(!this._gloryUrinalA) availableUrinalsArray.push(GLORY_URINAL_A_ID);
		if(!this._gloryUrinalB) availableUrinalsArray.push(GLORY_URINAL_B_ID);
		if(!this._gloryUrinalC) availableUrinalsArray.push(GLORY_URINAL_C_ID);
		if(!this._gloryUrinalD) availableUrinalsArray.push(GLORY_URINAL_D_ID);

		if(availableUrinalsArray.length > 0) {
			let assignedUrinalId = availableUrinalsArray[Math.randomInt(availableUrinalsArray.length)];
			if(assignedUrinalId === GLORY_URINAL_A_ID)
				this._gloryUrinalA = frontUrinalGuest;
			if(assignedUrinalId === GLORY_URINAL_B_ID)
				this._gloryUrinalB = frontUrinalGuest;
			if(assignedUrinalId === GLORY_URINAL_C_ID)
				this._gloryUrinalC = frontUrinalGuest;
			if(assignedUrinalId === GLORY_URINAL_D_ID)
				this._gloryUrinalD = frontUrinalGuest;

			frontUrinalGuest.gloryBattle_leaveUrinalQueue();
		}

		for(let i = 0; i < this._gloryUrinalQueue.length; ++i) {
			if(this._gloryUrinalQueue[i]._guest_intentIsForHole) {
				this._gloryUrinalQueue[i].gloryBattle_leaveUrinalQueue();
				this._gloryUrinalQueue[i].gloryBattle_joinStallQueue();
			}
		}
	}

	//Stall Queue
	if(this._gloryStallQueue.length > 0) {
		let availableStallsArray = [];
		if(!this._gloryLeftStall) availableStallsArray.push(GLORY_LEFT_STALL_ID);
		if(!this._gloryRightStall) availableStallsArray.push(GLORY_RIGHT_STALL_ID);

		while(this._gloryStallQueue.length > 0 && availableStallsArray.length > 0) {
			let arrayPos = Math.randomInt(availableStallsArray.length);
			let assignedStallId = availableStallsArray[arrayPos];
			let frontStallGuest = this._gloryStallQueue[0];

			if(assignedStallId === GLORY_LEFT_STALL_ID) {
				this._gloryStallQueue[0].gloryBattle_enterLeftStall();
			}
			if(assignedStallId === GLORY_RIGHT_STALL_ID) {
				this._gloryStallQueue[0].gloryBattle_enterRightStall();
			}

			frontStallGuest.gloryBattle_leaveStallQueue();
			availableStallsArray.splice(arrayPos, 1);
		}
	}

	////////
	//Assigned Spots
	if(this._gloryUrinalA) {
		if(!this._gloryUrinalA._guest_currentlyPissing && !this._gloryUrinalA._guest_finishedPissing) {
			this._gloryUrinalA._guest_currentlyPissing = true;
			this._gloryUrinalA._guest_finishPissingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryUrinalA._guest_takeToPeeTurns;
		}
		if(this._gloryUrinalA._guest_currentlyPissing && this._gloryUrinalA._guest_finishPissingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryUrinalA._guest_currentlyPissing = false;
			this._gloryUrinalA._guest_finishedPissing = true;
			if(this._gloryUrinalA._guest_intentIsForHole) {
				this._gloryUrinalA.gloryBattle_joinStallQueue();
			}
			else {
				this._gloryUrinalA.gloryBattle_joinWashingQueue();
			}
			this._gloryUrinalA = false;
		}
	}

	if(this._gloryUrinalB) {
		if(!this._gloryUrinalB._guest_currentlyPissing && !this._gloryUrinalB._guest_finishedPissing) {
			this._gloryUrinalB._guest_currentlyPissing = true;
			this._gloryUrinalB._guest_finishPissingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryUrinalB._guest_takeToPeeTurns;
		}
		if(this._gloryUrinalB._guest_currentlyPissing && this._gloryUrinalB._guest_finishPissingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryUrinalB._guest_currentlyPissing = false;
			this._gloryUrinalB._guest_finishedPissing = true;
			if(this._gloryUrinalB._guest_intentIsForHole) {
				this._gloryUrinalB.gloryBattle_joinStallQueue();
			}
			else {
				this._gloryUrinalB.gloryBattle_joinWashingQueue();
			}
			this._gloryUrinalB = false;
		}
	}

	if(this._gloryUrinalC) {
		if(!this._gloryUrinalC._guest_currentlyPissing && !this._gloryUrinalC._guest_finishedPissing) {
			this._gloryUrinalC._guest_currentlyPissing = true;
			this._gloryUrinalC._guest_finishPissingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryUrinalC._guest_takeToPeeTurns;
		}
		if(this._gloryUrinalC._guest_currentlyPissing && this._gloryUrinalC._guest_finishPissingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryUrinalC._guest_currentlyPissing = false;
			this._gloryUrinalC._guest_finishedPissing = true;
			if(this._gloryUrinalC._guest_intentIsForHole) {
				this._gloryUrinalC.gloryBattle_joinStallQueue();
			}
			else {
				this._gloryUrinalC.gloryBattle_joinWashingQueue();
			}
			this._gloryUrinalC = false;
		}
	}

	if(this._gloryUrinalD) {
		if(!this._gloryUrinalD._guest_currentlyPissing && !this._gloryUrinalD._guest_finishedPissing) {
			this._gloryUrinalD._guest_currentlyPissing = true;
			this._gloryUrinalD._guest_finishPissingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryUrinalD._guest_takeToPeeTurns;
		}
		if(this._gloryUrinalD._guest_currentlyPissing && this._gloryUrinalD._guest_finishPissingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryUrinalD._guest_currentlyPissing = false;
			this._gloryUrinalD._guest_finishedPissing = true;
			if(this._gloryUrinalD._guest_intentIsForHole) {
				this._gloryUrinalD.gloryBattle_joinStallQueue();
			}
			else {
				this._gloryUrinalD.gloryBattle_joinWashingQueue();
			}
			this._gloryUrinalD = false;
		}
	}

	//Left Stall
	if(this._gloryLeftStall) {
		if(!this._gloryLeftStall._guest_currentlyPissing && !this._gloryLeftStall._guest_finishedPissing && !this._gloryLeftStall._guest_intentIsForHole && !this._gloryLeftStall._guest_intentIsForEating) {
			this._gloryLeftStall._guest_currentlyPissing = true;
			this._gloryLeftStall._guest_finishPissingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryLeftStall._guest_takeToPeeTurns;
		}

		if(this._gloryLeftStall._guest_currentlyPissing && this._gloryLeftStall._guest_finishPissingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryLeftStall._guest_currentlyPissing = false;
			this._gloryLeftStall._guest_finishedPissing = true;
			if(this._gloryLeftStall._guest_intentIsForHole) {

			}
			else {
				this._gloryLeftStall.gloryBattle_joinWashingQueue();
				this._gloryLeftStall.gloryBattle_leaveLeftStall();
			}
		}

		if(this._gloryLeftStall._guest_intentIsForEating && !this._gloryLeftStall._guest_currentlyEating && !this._gloryLeftStall._guest_finishedEating && !this._gloryLeftStall._guest_intentIsForHole) {
			this._gloryLeftStall._guest_currentlyEating = true;
			this._gloryLeftStall._guest_finishEatingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryLeftStall._guest_takeToEatTurns;
		}

		if(this._gloryLeftStall._guest_currentlyEating && this._gloryLeftStall._guest_finishEatingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryLeftStall._guest_currentlyEating = false;
			this._gloryLeftStall._guest_finishedEating = true;
			if(this._gloryLeftStall._guest_intentIsForHole) {

			}
			else {
				this._gloryLeftStall.gloryBattle_joinWashingQueue();
				this._gloryLeftStall.gloryBattle_leaveLeftStall();
			}
		}
	}
	//Left Stall End

	//Right Stall
	if(this._gloryRightStall) {
		if(!this._gloryRightStall._guest_currentlyPissing && !this._gloryRightStall._guest_finishedPissing && !this._gloryRightStall._guest_intentIsForHole && !this._gloryRightStall._guest_intentIsForEating) {
			this._gloryRightStall._guest_currentlyPissing = true;
			this._gloryRightStall._guest_finishPissingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryRightStall._guest_takeToPeeTurns;
		}

		if(this._gloryRightStall._guest_currentlyPissing && this._gloryRightStall._guest_finishPissingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryRightStall._guest_currentlyPissing = false;
			this._gloryRightStall._guest_finishedPissing = true;
			if(this._gloryRightStall._guest_intentIsForHole) {

			}
			else {
				this._gloryRightStall.gloryBattle_joinWashingQueue();
				this._gloryRightStall.gloryBattle_leaveRightStall();
			}
		}

		if(this._gloryRightStall._guest_intentIsForEating && !this._gloryRightStall._guest_currentlyEating && !this._gloryRightStall._guest_finishedEating && !this._gloryRightStall._guest_intentIsForHole) {
			this._gloryRightStall._guest_currentlyEating = true;
			this._gloryRightStall._guest_finishEatingOnTurn = this.getCurrentTurn_gloryBattle() + this._gloryRightStall._guest_takeToEatTurns;
		}

		if(this._gloryRightStall._guest_currentlyEating && this._gloryRightStall._guest_finishEatingOnTurn <= this.getCurrentTurn_gloryBattle()) {
			this._gloryRightStall._guest_currentlyEating = false;
			this._gloryRightStall._guest_finishedEating = true;
			if(this._gloryRightStall._guest_intentIsForHole) {

			}
			else {
				this._gloryRightStall.gloryBattle_joinWashingQueue();
				this._gloryRightStall.gloryBattle_leaveRightStall();
			}
		}
	}
	//Right Stall End

	/////////////
	//Karryn
	let skipTurn = false;

	if(this.getCurrentTurn_gloryBattle() < actor._gloryBattle_restingTilTurn) {
		skipTurn = true;
		actor._gloryBattle_restingTilTurn -= 1;
		actor.gloryRestTurnEffect();
	}

	if(!skipTurn) {
		actor.removeState(STATE_DISABLED_ID);

		if(actor._gloryBattle_turnsTillMentalPhase <= 0 || actor.justOrgasmed()) {
			actor.enterMentalPhase();
			actor._gloryBattle_turnsTillMentalPhase = GLORY_MENTAL_PHASE_COOLDOWN;
		}
		else {
			actor.enterActionPhase();
		}

	}
	else {
		actor.addState(STATE_DISABLED_ID);
	}

};

////////
// Spawn

Game_Troop.prototype.gloryBattle_spawnGuest = function(forceSpawn) {

	let chanceToSpawn = 0;
	let spawningNewGuest = false;

	chanceToSpawn = this.gloryBattle_calculateChanceToSpawnGuest();

	let spawnRandomInt = GLORY_SPAWN_BASE_RANDOM_INT + (this._gloryGuestsSpawnedCount * this._gloryGuestsSpawnedCount);
	spawnRandomInt -= GLORY_SPAWN_RANDOM_INT_DEC_SINCE_LAST_SPAWN * ($gameTroop.getCurrentTurn_gloryBattle() - this._gloryGuestLastSpawnedTurn);
	if(forceSpawn || ((Math.randomInt(spawnRandomInt) + this._gloryGuestsSpawnedCount) <= chanceToSpawn)) {
		if(this._gloryGuestsSpawnedCount < this._gloryGuestsSpawnLimit) {
			spawningNewGuest = true;
		}
	}

	if(spawningNewGuest) {
		this._gloryGuestsSpawnedCount++;
		this._gloryGuestLastSpawnedTurn = $gameTroop.getCurrentTurn_gloryBattle();
		let enemyId = this.gloryBattle_validGuestId();
		let enemy = this.setup_gloryBattle_guest(enemyId);
		enemy.makeUniqueNames();
		enemy.onBattleStart();
		enemy.midBattleSpawn_setupDreamX();
		SceneManager._scene._spriteset.addEnemy(enemy);
	}

	return spawningNewGuest;
};

Game_Troop.prototype.setup_gloryBattle_guest = function(enemyId) {
	let originalEnemyId = enemyId;
	let wanted = false;
	wanted = Prison.findAvailableWanted($dataEnemies[enemyId], 1);
	if(wanted) {
		enemyId = wanted._enemyId;
	}

	if(!wanted) enemyId = this.checkEnemyIdForPossibleDowngradeOrUpgrade(enemyId);
	let enemy = new Game_Enemy(enemyId, 0, 0, wanted, originalEnemyId);
	enemy._guest_number = this._gloryGuestsSpawnedCount;
	this._enemies.push(enemy);
	enemy.setupForGloryBattle_Guest(wanted);

	let chanceForIntentIsHole = this.gloryBattle_calculateChanceForSpawnedGuestIsHereForHole(enemy);

	if(Math.randomInt(100) < chanceForIntentIsHole) {
		enemy._guest_intentIsForHole = true;
		enemy.gloryBattle_joinStallQueue();
	}
	else if($gameParty._gloryReputation <= GLORY_SPAWN_EATERS_REP_LIMIT && (enemy.isNerdType || enemy.isPrisonerType)) {
		let chanceForIntentIsEating = this.gloryBattle_calculateChanceForSpawnedGuestIsHereForEating(enemy);
		if(Math.randomInt(100) < chanceForIntentIsEating) {
			enemy._guest_intentIsForEating = true;
			enemy.gloryBattle_joinStallQueue();
		}
	}

	if(!enemy._guest_intentIsForHole && !enemy._guest_intentIsForEating) {
		let chanceToUseStall = 0;
		if(this._gloryLeftStall) chanceToUseStall += 20;
		if(this._gloryRightStall) chanceToUseStall += 20;

		if(this._gloryUrinalA || this._gloryUrinalB || this._gloryUrinalC || this._gloryUrinalD) {
			chanceToUseStall += 10;
			if(this._gloryUrinalA) chanceToUseStall += 10;
			if(this._gloryUrinalB) chanceToUseStall += 10;
			if(this._gloryUrinalC) chanceToUseStall += 10;
			if(this._gloryUrinalD) chanceToUseStall += 10;
		}

		if(Math.randomInt(100) < chanceToUseStall) {
			enemy.gloryBattle_joinStallQueue();
		}
		else {
			enemy.gloryBattle_joinUrinalQueue();
		}
	}

	return enemy;
};

Game_Troop.prototype.gloryBattle_validGuestId = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let validEnemyTypes = [ 51,52,53,54 ];

	//Thugs
	if(Karryn.hasEdict(EDICT_NO_THUG_LABOR)) {
		validEnemyTypes.push(94);
	}
	else if(Karryn.hasEdict(EDICT_THUGS_STRESS_RELIEF)) {
		validEnemyTypes.push(92);
		validEnemyTypes.push(95);
	}

	//Goblins
	if(Karryn.hasEdict(EDICT_BAIT_GOBLINS)) {
		validEnemyTypes.push(82);
		validEnemyTypes.push(83);
	}
	else if(Karryn.hasEdict(EDICT_DEMEAN_GOBLINS)) {
		validEnemyTypes.push(81);
	}

	//Nerds
	if(Karryn.hasEdict(EDICT_PAY_NERD_BLACKMAIL)) {
		validEnemyTypes.push(122);
		validEnemyTypes.push(123);
	}
	else if(Karryn.hasEdict(EDICT_GIVE_IN_TO_NERD_BLACKMAIL)) {
		validEnemyTypes.push(121);
		validEnemyTypes.push(122);
		validEnemyTypes.push(123);
	}
	else {
		validEnemyTypes.push(121);
	}

	//Rogues
	if(Karryn.hasEdict(EDICT_FORCE_ROGUES_INTO_LABOR)) {

	}
	else if(Karryn.hasEdict(EDICT_FIGHT_ROGUE_DISTRACTIONS_WITH_DISTRACTIONS)) {
		validEnemyTypes.push(141);
		validEnemyTypes.push(142);
		validEnemyTypes.push(143);
	}
	else {
		validEnemyTypes.push(141);
	}

	return validEnemyTypes[Math.randomInt(validEnemyTypes.length)];
};

/////////////
//////////////////
// Game Enemy
///////////////////
/////////////

////////
// Name
Game_Enemy.prototype.name_gloryHoleBattle = function() {
	return this.displayName_gloryHoleBattle();
};

Game_Enemy.prototype.displayName_gloryHoleBattle = function() {
	let name = '';

	if(this._guest_atStall === GLORY_LEFT_STALL_ID) name = TextManager.gloryLeftStallCockName;
	else if(this._guest_atStall === GLORY_RIGHT_STALL_ID) name = TextManager.gloryRightStallCockName;

	return name;
};

Game_Enemy.prototype.battlerName_gloryHoleBattle = function() {
	return 'glory_target';
};

Game_Enemy.prototype.gloryParamRateEffect = function(paramId) {
	let rate = 1;

	if($gameParty.isInGloryBattle) {
		if(paramId === PARAM_AGILITY_ID) {
			rate *= 0.001;
		}
	}

	return rate;
};

//enemy setup
Game_Enemy.prototype.setupForGloryBattle_Guest = function(wanted) {
	this._guest_takeToPeeTurns = 3 + Math.randomInt(2);
	if(this.hasAgilePrefix() || this.hasVirginPrefix())
		this._guest_takeToPeeTurns--;
	else if(this.hasHungryPrefix() || this.hasStarvingPrefix())
		this._guest_takeToPeeTurns -= 1 + Math.randomInt(2);
	else if(this.hasSlowPrefix() || this.hasIneptPrefix() || this.hasGoodPrefix())
		this._guest_takeToPeeTurns++;
	else if(this.hasElitePrefix() || this.hasBigPrefix() || this.hasEnduringPrefix() || this.hasDrunkPrefix())
		this._guest_takeToPeeTurns += 1 + Math.randomInt(2);

	this._guest_takeToPeeTurns = Math.max(2, this._guest_takeToPeeTurns);

	this._guest_givenHolePatienceTurns = 5 + Math.randomInt(3);
	if(this.isPrisonerType)
		this._guest_givenHolePatienceTurns += 1;
	else if(this.isThugType && !Karryn.hasEdict(EDICT_THUGS_STRESS_RELIEF))
		this._guest_givenHolePatienceTurns -= 2;
	else if(this.isRogueType)
		this._guest_givenHolePatienceTurns -= 1;
	else if(this.isGoblinType && Karryn.hasEdict(EDICT_BAIT_GOBLINS))
		this._guest_givenHolePatienceTurns += 1;
	else if(this.isNerdType)
		this._guest_givenHolePatienceTurns += 2;

	if(this.hasVirginPrefix() || this.hasSlowPrefix())
		this._guest_givenHolePatienceTurns += 2;
	else if(this.hasIneptPrefix() || this.hasBigPrefix() || this.hasEnduringPrefix() || this.hasMasoPrefix() || this.hasSadoPrefix())
		this._guest_givenHolePatienceTurns++;
	else if(this.hasGoodPrefix() || this.hasDrunkPrefix())
		this._guest_givenHolePatienceTurns--;
	else if(this.hasAgilePrefix() || this.hasElitePrefix() || this.hasHungryPrefix() || this.hasStarvingPrefix() || this.hasMetalPrefix())
		this._guest_givenHolePatienceTurns -= 2;

	this._guest_takeToEatTurns = 8 + Math.randomInt(4);
	if(this.isNerdType)
		this._guest_takeToEatTurns += 1 + Math.randomInt(2);
	if(this.hasHungryPrefix() || this.hasSlowPrefix())
		this._guest_takeToEatTurns += 1 + Math.randomInt(2);
	else if(this.hasStarvingPrefix() || this.hasElitePrefix())
		this._guest_takeToEatTurns += 1 + Math.randomInt(2);

	this._guest_inQueue = false;
	this._guest_atStall = false;
	this._guest_currentlyPissing = false;
	this._guest_finishedPissing = false;
	this._guest_currentlyEating = false;
	this._guest_finishedEating = false;
	this._guest_currentlyWashing = false;
	this._guest_intentIsForHole = false;
	this._guest_intentIsForEating = false;
	this._guest_showedThroughHole = false;
	this._guest_gotFavoredSex = false;
	this._guest_gotUnfavoredSex = false;

	this._guest_actionCooldown = 0;
	this._guest_finishEatingOnTurn = -1;
	this._guest_finishPissingOnTurn = -1;
	this._guest_holePatienceTurnLimit = -1;

	BattleManager._logWindow.push('addText', TextManager.gloryGuestEnterBathroom);
};

Game_Enemy.prototype.gloryBattle_pollSatisfaction = function(endOfBattle) {
	if(this._guest_intentIsForHole) {
		let guestSat = 0;

		if(this._ejaculationStock > 0 && this.energy > 0) {
			if(!endOfBattle)
				guestSat += GLORY_GUEST_SATISFACTION_LOST_FROM_NOT_EMPTY_STOCK;
		}
		else {
			guestSat += GLORY_GUEST_SATISFACTION_GAIN_FROM_EMPTY_STOCK;
		}

		if(this._guest_showedThroughHole) {
			if(this._guest_gotFavoredSex)
				guestSat += GLORY_GUEST_SATISFACTION_GAIN_FROM_FAVORED_SEX;
			if(this._guest_gotUnfavoredSex)
				guestSat += GLORY_GUEST_SATISFACTION_LOST_FROM_UNFAVORED_SEX;
		}
		else {
			if(!endOfBattle)
				guestSat += GLORY_GUEST_SATISFACTION_LOST_FROM_NOT_GETTING_TO_HOLE;
		}

		$gameParty.increaseGloryGuestSatisfaction(guestSat);
	}

};

Game_Enemy.prototype.gloryBattle_leaveBathroom = function() {
	BattleManager._logWindow.push('addText', TextManager.gloryGuestLeaveBathroom);

	this.gloryBattle_pollSatisfaction(false);

	this.hide();
	this.clearActions();
    this.clearStates();
};

Game_Enemy.prototype.gloryBattle_joinStallQueue = function() {
	this._guest_inQueue = true;
	$gameTroop._gloryStallQueue.push(this);
};
Game_Enemy.prototype.gloryBattle_joinUrinalQueue = function() {
	this._guest_inQueue = true;
	$gameTroop._gloryUrinalQueue.push(this);
};
Game_Enemy.prototype.gloryBattle_joinWashingQueue = function() {
	this._guest_inQueue = true;
	$gameTroop._gloryWashingQueue.push(this);
};

Game_Enemy.prototype.gloryBattle_leaveStallQueue = function() {
	this._guest_inQueue = false;

	let assignedQueue = $gameTroop._gloryStallQueue;

	if(assignedQueue[0]._guest_number === this._guest_number) {
		assignedQueue.shift();
	}
	else {
		let currentQueueSpot = 0;
		for(let i = 0; i < assignedQueue.length; ++i) {
			if(assignedQueue[i]._guest_number === this._guest_number) {
				currentQueueSpot = i;
				break;
			}
		}
		assignedQueue.splice(currentQueueSpot, 1);
	}
};
Game_Enemy.prototype.gloryBattle_leaveUrinalQueue = function() {
	this._guest_inQueue = false;

	let assignedQueue = $gameTroop._gloryUrinalQueue;

	if(assignedQueue[0]._guest_number === this._guest_number) {
		assignedQueue.shift();
	}
	else {
		let currentQueueSpot = 0;
		for(let i = 0; i < assignedQueue.length; ++i) {
			if(assignedQueue[i]._guest_number === this._guest_number) {
				currentQueueSpot = i;
				break;
			}
		}
		assignedQueue.splice(currentQueueSpot, 1);
	}
};
Game_Enemy.prototype.gloryBattle_leaveWashingQueue = function() {
	this._guest_inQueue = false;

	let assignedQueue = $gameTroop._gloryWashingQueue;

	if(assignedQueue[0]._guest_number === this._guest_number) {
		assignedQueue.shift();
	}
	else {
		let currentQueueSpot = 0;
		for(let i = 0; i < assignedQueue.length; ++i) {
			if(assignedQueue[i]._guest_number === this._guest_number) {
				currentQueueSpot = i;
				break;
			}
		}
		assignedQueue.splice(currentQueueSpot, 1);
	}
};

Game_Enemy.prototype.gloryBattle_enterLeftStall = function() {
	this._guest_atStall = GLORY_LEFT_STALL_ID;
	$gameTroop._gloryLeftStall = this;
	BattleManager._logWindow.push('addText', TextManager.gloryGuestEnterLeftStall);
};
Game_Enemy.prototype.gloryBattle_enterRightStall = function() {
	this._guest_atStall = GLORY_RIGHT_STALL_ID;
	$gameTroop._gloryRightStall = this;
	BattleManager._logWindow.push('addText', TextManager.gloryGuestEnterRightStall);
};
Game_Enemy.prototype.gloryBattle_leaveLeftStall = function() {
	this._guest_atStall = false;
	$gameTroop._gloryLeftStall = false;
	BattleManager._logWindow.push('addText', TextManager.gloryGuestLeaveLeftStall);
};
Game_Enemy.prototype.gloryBattle_leaveRightStall = function() {
	this._guest_atStall = false;
	$gameTroop._gloryRightStall = false;
	BattleManager._logWindow.push('addText', TextManager.gloryGuestLeaveRightStall);
};

Game_Enemy.prototype.gloryBattle_showThroughHole = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);

	this._guest_showedThroughHole = true;

	if(this._guest_atStall === GLORY_LEFT_STALL_ID) {
		BattleManager._logWindow.push('addText', TextManager.gloryGuestShowedThroughLeftHole);
		this.didLastGetHitBySkillType(JUST_SKILLTYPE_GLORY_LEFT_HOLE_SHOWED);
	}
	else if(this._guest_atStall === GLORY_RIGHT_STALL_ID) {
		BattleManager._logWindow.push('addText', TextManager.gloryGuestShowedThroughRightHole);
		this.didLastGetHitBySkillType(JUST_SKILLTYPE_GLORY_RIGHT_HOLE_SHOWED);
	}

	actor.gloryBattle_reactToNewCock();
};

Game_Enemy.prototype.gloryBattle_calculatePatience = function() {
	let patience = GLORY_GUEST_BASE_PATIENCE;
	if(this.hasElitePrefix() || this.hasAgilePrefix() || this.hasStarvingPrefix() || this.hasHungryPrefix() || this.hasAngryPrefix())
		patience -= 3;
	else if(this.hasGoodPrefix() || this.hasSadoPrefix() || this.hasSensitivePrefix() || this.hasDrunkPrefix())
		patience -= 2;
	else if(this.hasStrongPrefix() || this.hasDexterousPrefix() || this.hasMetalPrefix() || this.hasBigPrefix())
		patience -= 1;
	else if(this.isHorny || this.hasVirginPrefix() || this.hasHornyPrefix() || this.hasEnduringPrefix() || this.hasSlowPrefix() || this.hasMasoPrefix())
		patience += 1;

	return patience;
};

//Enemy Pleasure
Game_Enemy.prototype.bonusPpt_gloryBattle = function() {
	//hp degen
	let degenAmt = Math.ceil(this.mhp / this.gloryBattle_calculatePatience());
	this._hp = Math.max(1, this._hp - degenAmt);

	//pleasure
	let value = 0;
	//todo: ?
	return value;
};

Game_Enemy.prototype.gloryBattle_increasePleasureFromHearing_close = function() {
	let limit = Math.max(this.orgasmPoint() * 0.5, this.arousalPoint() * 1.3);
	if(this.pleasure > limit) return;

	let karrynCharm = Karryn.inBattleCharm;
	let enemyCharmReq = this.charm;
	if(this.isHorny) {
		enemyCharmReq *= 0.8;
	}

	let pleasureGain = 0;
	if(enemyCharmReq > karrynCharm) {
		pleasureGain = Math.floor(karrynCharm * VAR_CHARM_MULTIPLER_WHEN_LESS);
	}
	else {
		pleasureGain = Math.round(karrynCharm * 1.33 - enemyCharmReq);
	}

	if(pleasureGain + this.pleasure > limit)
		pleasureGain = limit - this.pleasure;
	this.gainPleasure(pleasureGain);
};

Game_Enemy.prototype.gloryBattle_increasePleasureFromHearing_far = function() {
	let limit = this.arousalPoint() * 1.1;
	if(this.pleasure > limit) return;

	let karrynCharm = Karryn.inBattleCharm;
	let enemyCharmReq = this.charm;
	if(this.isHorny) {
		enemyCharmReq *= 0.8;
	}

	let pleasureGain = 0;
	if(enemyCharmReq > karrynCharm) {
		pleasureGain = Math.floor(karrynCharm * VAR_CHARM_MULTIPLER_WHEN_LESS);
	}
	else {
		pleasureGain = Math.round(karrynCharm * 1.33 - enemyCharmReq);
	}

	if(pleasureGain + this.pleasure > limit)
		pleasureGain = limit - this.pleasure;
	this.gainPleasure(pleasureGain);
};

///////////
// Valid Target

Game_Enemy.prototype.isValidTargetForCockStare_gloryBattle = function(actor) {
	if(!this._guest_atStall || !this._guest_showedThroughHole ) return false;

	if(actor.isInToiletSittingPose()) {
		return true;
	}
	else if(actor.isInToiletSitLeftPose()) {
		return true;
	}
	else if(actor.isInToiletSitRightPose()) {
		return true;
	}
	else if(actor.currentlyInToiletStandLeftPose()) {
		return false;
	}
	else if(actor.currentlyInToiletStandRightPose()) {
		return false;
	}
	else return false;
};

Game_Enemy.prototype.isValidTargetForCockPetting_gloryBattle = function(actor) {
	if(!this._guest_atStall || !this._guest_showedThroughHole ) return false;

	if(actor.isInToiletSittingPose()) {
		return true;
	}
	else if(actor.isInToiletSitLeftPose()) {
		if(this._guest_atStall === GLORY_LEFT_STALL_ID)
			return true;
		else
			return false;
	}
	else if(actor.isInToiletSitRightPose()) {
		if(this._guest_atStall === GLORY_RIGHT_STALL_ID)
			return true;
		else
			return false;
	}
	else if(actor.currentlyInToiletStandLeftPose()) {
		if(this._guest_atStall === GLORY_RIGHT_STALL_ID)
			return true;
		else
			return false;
	}
	else if(actor.currentlyInToiletStandRightPose()) {
		if(this._guest_atStall === GLORY_LEFT_STALL_ID)
			return true;
		else
			return false;
	}
	else return false;
};

Game_Enemy.prototype.isValidTargetForHandjobOrBlowjob_gloryBattle = function(actor) {
	if(!this._guest_atStall || !this._guest_showedThroughHole ) return false;
	else return true;
};
Game_Enemy.prototype.isValidTargetForPussyOrAnalSex_gloryBattle = function(actor) {
	if(!this._guest_atStall || !this._guest_showedThroughHole || !this.isErect ) return false;
	else return true;
};

/////////////
// Glory Hole Battle AI
///////////

Game_Enemy.prototype.enemyBattleAIGloryHole = function(target) {
	if(this.enemyType() == ENEMYTYPE_TOILET_OBS_TAG) return;
	if(this._guest_inQueue || !this._guest_atStall) return;

	//console.log('ai ' + this._guest_atStall)

	this._guest_actionCooldown = Math.max(this._guest_actionCooldown - 1, 0);

	if(this._guest_currentlyPissing) {
		if(this._guest_actionCooldown === 0) {
			if(this._guest_atStall === GLORY_LEFT_STALL_ID)
				BattleManager._logWindow.push('addText', TextManager.gloryGuestPissingLeftStall);
			else if(this._guest_atStall === GLORY_RIGHT_STALL_ID)
				BattleManager._logWindow.push('addText', TextManager.gloryGuestPissingRightStall);

			this._guest_actionCooldown = GLORY_GUEST_ACTION_COOLDOWN;
		}
	}

	if(this._guest_currentlyEating) {
		if(this._guest_actionCooldown === 0) {
			if(this._guest_atStall === GLORY_LEFT_STALL_ID)
				BattleManager._logWindow.push('addText', TextManager.gloryGuestEatingLeftStall);
			else if(this._guest_atStall === GLORY_RIGHT_STALL_ID)
				BattleManager._logWindow.push('addText', TextManager.gloryGuestEatingRightStall);

			this._guest_actionCooldown = GLORY_GUEST_ACTION_COOLDOWN;
		}
	}

	if(this._ejaculationStock < 1 || this.energy < 1) {
		BattleManager.pullOutEnemy(this);
		target.gloryBattle_postEnemyPullout();
		if(this._guest_atStall === GLORY_LEFT_STALL_ID)
			this.gloryBattle_leaveLeftStall();
		else if(this._guest_atStall === GLORY_RIGHT_STALL_ID)
			this.gloryBattle_leaveRightStall();

		this.gloryBattle_joinWashingQueue();
		target.emoteMasterManager_GloryBattle();
		return;
	}
	else {
		if(this._guest_intentIsForHole && !this._guest_showedThroughHole) {
			this.gloryBattle_showThroughHole();
			return;
		}
		else if(this._guest_intentIsForHole && this._guest_showedThroughHole) {
			if(this.isInAPose() && this._guest_actionCooldown === 0) {
				if(this.usePoseSkill(target))
					this._guest_actionCooldown = GLORY_GUEST_ACTION_COOLDOWN;
			}
			else if(!this.isInAPose() && this.stamina === 1) {
				if(this._guest_atStall === GLORY_LEFT_STALL_ID)
					this.gloryBattle_leaveLeftStall();
				else if(this._guest_atStall === GLORY_RIGHT_STALL_ID)
					this.gloryBattle_leaveRightStall();

				this.gloryBattle_joinWashingQueue();
				target.emoteMasterManager_GloryBattle();
			}
		}
	}

};


code:
var Remtairy = Remtairy || {};
Remtairy.KarrynLimit = Remtairy.KarrynLimit || {};

//=============================================================================
 /*:
 * @plugindesc Karryn Limit
 * @author Remtairy
 *
 * @help
 * This is a private plugin.
 * Do not redistribute, use, or modify this plugin
 * without explicit written permission from Remtairy.
 *
 */
//=============================================================================

var LIMIT_GUARD_AGGRESSION = 42;

var LIMIT_ESCAPE_TOTAL_COUNT = 15;

var LIMIT_SUBDUED_ERECT_WITH_ATTACK_COUNT = 40;
var LIMIT_SUBDUED_ANGRY_COUNT = 30;
var LIMIT_SUBDUED_TOTAL_COUNT = 200;

var LIMIT_DEFEATED_TOTAL_COUNT = 15;
var LIMIT_DEFEATED_LEVEL_ONE_COUNT = 15;
var LIMIT_DEFEATED_LEVEL_TWO_COUNT = 15;
var LIMIT_DEFEATED_LEVEL_THREE_COUNT = 15;
var LIMIT_DEFEATED_LEVEL_FOUR_COUNT = 15;
var LIMIT_DEFEATED_LEVEL_FIVE_COUNT = 15;

var LIMIT_INVASION_BATTLE_TOTAL_COUNT = 10;
var LIMIT_INVASION_BATTLE_OFFICE_COUNT = 10;
var LIMIT_INVASION_BATTLE_LEVEL_ONE_COUNT = 10;
var LIMIT_INVASION_BATTLE_LEVEL_TWO_COUNT = 10;
var LIMIT_INVASION_BATTLE_LEVEL_THREE_COUNT = 10;
var LIMIT_INVASION_BATTLE_LEVEL_FOUR_COUNT = 10;
var LIMIT_INVASION_BATTLE_LEVEL_FIVE_COUNT = 10;

var LIMIT_MASTURBATED_OFFICE_COUNT = 10;
var LIMIT_MASTURBATED_GUARD_STATION_COUNT = 10;
var LIMIT_MASTURBATED_TOTAL_COUNT = 15;

var LIMIT_FIX_CLOTHES_USAGE_COUNT = 40;
var LIMIT_COCK_KICK_USAGE_COUNT = 30;
var LIMIT_KISS_USAGE_COUNT = 50;
var LIMIT_COCK_STARE_USAGE_COUNT = 30;
var LIMIT_COCK_PET_USAGE_COUNT = 30;
var LIMIT_HANDJOB_USAGE_COUNT = 50;
var LIMIT_BLOWJOB_USAGE_COUNT = 30;
var LIMIT_RIMJOB_USAGE_COUNT = 30;
var LIMIT_FOOTJOB_USAGE_COUNT = 30;
var LIMIT_TITTY_FUCK_USAGE_COUNT = 30;
var LIMIT_PUSSY_SEX_USAGE_COUNT = 30;
var LIMIT_ANAL_SEX_USAGE_COUNT = 30;

var LIMIT_CLOTHES_STRIPPED = 75;
var LIMIT_PANTIES_STRIPPED = 10;

var LIMIT_KISSED_COUNT = 100;
var LIMIT_HANDJOB_COUNT = 70;
var LIMIT_BLOWJOB_COUNT = 70;
var LIMIT_TITTYFUCK_COUNT = 50;
var LIMIT_PUSSYFUCKED_COUNT = 15;
var LIMIT_ANALFUCKED_COUNT = 35;
var LIMIT_BOOBS_PETTED_COUNT = 250;
var LIMIT_NIPPLES_PETTED_COUNT = 50;
var LIMIT_BUTT_PETTED_COUNT = 250;
var LIMIT_ANAL_PETTED_COUNT = 50;
var LIMIT_PUSSY_PETTED_COUNT = 50;
var LIMIT_CLIT_PETTED_COUNT = 250;
var LIMIT_JOB_PETTED_COUNT = 200;

var LIMIT_TALKED_AT_COUNT = 150;
var LIMIT_TALKED_COCK_COUNT = 50;
var LIMIT_SEEN_MOUTH_COUNT = 20;
var LIMIT_SEEN_BOOBS_COUNT = 20;
var LIMIT_SEEN_NIPPLES_COUNT = 20;
var LIMIT_SEEN_CLIT_COUNT = 20;
var LIMIT_SEEN_PUSSY_COUNT = 20;
var LIMIT_SEEN_BUTT_COUNT = 20;
var LIMIT_SEEN_ANAL_COUNT = 20;
var LIMIT_SEEN_ANAL_CREAMPIE_COUNT = 20;
var LIMIT_SEEN_PUSSY_CREAMPIE_COUNT = 20;
var LIMIT_SEEN_BUKKAKE_FACE_COUNT = 20;
var LIMIT_SEEN_BUKKAKE_BOOBS_COUNT = 20;
var LIMIT_SEEN_BUKKAKE_BUTT_COUNT = 20;
var LIMIT_SEEN_MOUTH_SWALLOW_COUNT = 20;
var LIMIT_SEEN_TOTAL_COUNT = 80;

var LIMIT_BUTTSPANKED_COUNT = 50;
var LIMIT_SEEJERKOFF_COUNT = 20;
var LIMIT_FINGERS_SUCKED_COUNT = 20;
var LIMIT_CUNNILINGUS_COUNT = 20;
var LIMIT_RIMJOB_COUNT = 20;
var LIMIT_FOOTJOB_COUNT = 20;
var LIMIT_COCK_PETTED_COUNT = 20;
var LIMIT_KARRYN_TAUNT_COUNT = 40;
var LIMIT_KARRYN_FLAUNT_COUNT = 40;
var LIMIT_KARRYN_DOGEZA_COUNT = 20;
var LIMIT_COCKINESS_MAX_COUNT = 4;
var LIMIT_COCKINESS_GAINED_COUNT = 400;

var LIMIT_HORNY_COUNT = 42;
var LIMIT_DEBUFF_OFF_BALANCED_COUNT = 30;
var LIMIT_DEBUFF_FALLEN_COUNT = 20;
var LIMIT_DEBUFF_DISARMED_COUNT = 30;
var LIMIT_DEBUFF_DOWN_STAMINA_COUNT = 30;

var LIMIT_KISSED_PEOPLE = 40;
var LIMIT_HANDJOB_PEOPLE = 40;
var LIMIT_BLOWJOB_PEOPLE = 40;
var LIMIT_TITTYFUCK_PEOPLE = 25;
var LIMIT_PUSSYFUCKED_PEOPLE = 15;
var LIMIT_ANALFUCKED_PEOPLE = 35;
var LIMIT_BUKKAKE_PEOPLE = 30;
var LIMIT_SWALLOW_PEOPLE = 30;
var LIMIT_PUSSYCREAMPIE_PEOPLE = 30;
var LIMIT_ANALCREAMPIE_PEOPLE = 30;
var LIMIT_ORGASMPRESENCE_PEOPLE = 10;
var LIMIT_CUNNILINGUS_PEOPLE = 10;
var LIMIT_RIMJOB_PEOPLE = 10;
var LIMIT_FOOTJOB_PEOPLE = 10;
var LIMIT_BUTTSPANKED_PEOPLE = 35;
var LIMIT_FINGERS_SUCKED_PEOPLE = 15;
var LIMIT_BOOBS_PETTED_PEOPLE = 50;
var LIMIT_NIPPLES_PETTED_PEOPLE = 35;
var LIMIT_CLIT_PETTED_PEOPLE = 50;
var LIMIT_PUSSY_PETTED_PEOPLE = 35;
var LIMIT_BUTT_PETTED_PEOPLE = 50;
var LIMIT_ANAL_PETTED_PEOPLE = 50;
var LIMIT_TALKED_AT_PEOPLE = 100;
var LIMIT_TALKED_COCK_PEOPLE = 25;
var LIMIT_SEEN_PEOPLE = 50;
var LIMIT_SEEJERKOFF_PEOPLE = 25;
var LIMIT_COCK_PETTED_PEOPLE = 15;
var LIMIT_KARRYN_TAUNT_PEOPLE = 100;
var LIMIT_KARRYN_FLAUNT_PEOPLE = 100;
var LIMIT_KARRYN_DOGEZA_PEOPLE = 30;
var LIMIT_KARRYN_TOYS_INSERTED_BY_ENEMY_PEOPLE = 15;

var LIMIT_MOUTH_PLEASURE = 750;
var LIMIT_BOOBS_PLEASURE = 750;
var LIMIT_NIPPLES_PLEASURE = 750;
var LIMIT_PUSSY_PLEASURE = 750;
var LIMIT_CLIT_PLEASURE = 750;
var LIMIT_BUTT_PLEASURE = 750;
var LIMIT_ANAL_PLEASURE = 750;
var LIMIT_FINGERS_PLEASURE = 750;
var LIMIT_TOYS_PLEASURE = 750;
var LIMIT_TALK_PLEASURE = 750;
var LIMIT_SIGHT_PLEASURE = 750;
var LIMIT_BUKKAKE_PLEASURE = 750;
var LIMIT_SWALLOW_PLEASURE = 750;
var LIMIT_PUSSYCREAMPIE_PLEASURE = 750;
var LIMIT_ANALCREAMPIE_PLEASURE = 750;
var LIMIT_MASOCHISM_PLEASURE = 750;
var LIMIT_SADISM_PLEASURE = 750;

var LIMIT_BUKKAKE_FACE_COUNT = 15;
var LIMIT_BUKKAKE_ARMS_COUNT = 15;
var LIMIT_BUKKAKE_BOOBS_COUNT = 15;
var LIMIT_BUKKAKE_BUTT_COUNT = 15;
var LIMIT_BUKKAKE_TOTAL_COUNT = 15;

var LIMIT_BUKKAKE_FACE_ML = 200;
var LIMIT_BUKKAKE_ARMS_ML = 200;
var LIMIT_BUKKAKE_LEGS_ML = 200;
var LIMIT_BUKKAKE_BOOBS_ML = 200;
var LIMIT_BUKKAKE_BUTT_ML = 200;
var LIMIT_BUKKAKE_TOTAL_ML = 1000;

var LIMIT_SWALLOW_COUNT = 15;
var LIMIT_ANALCREAMPIE_COUNT = 15;
var LIMIT_PUSSYCREAMPIE_COUNT = 15;
var LIMIT_ALL_HOLES_CREAMED_COUNT = 15;

var LIMIT_SWALLOW_ML = 500;
var LIMIT_ANALCREAMPIE_ML = 200;
var LIMIT_PUSSYCREAMPIE_ML = 200;

var LIMIT_ORGASM_COUNT = 50;
var LIMIT_ORGASM_ML = 100;
var LIMIT_PUSSY_DRIP_TENTHML = 1000;

var LIMIT_ORGASM_FROM_KISS = 5;
var LIMIT_ORGASM_FROM_TALK = 5;
var LIMIT_ORGASM_FROM_SIGHT = 5;
var LIMIT_ORGASM_FROM_PETTING = 5;
var LIMIT_ORGASM_FROM_CUNNILINGUS = 5;
var LIMIT_ORGASM_FROM_HANDJOB = 5;
var LIMIT_ORGASM_FROM_BLOWJOB = 5;
var LIMIT_ORGASM_FROM_TITTYFUCK = 5;
var LIMIT_ORGASM_FROM_PUSSYSEX = 5;
var LIMIT_ORGASM_FROM_ANALSEX = 5;
var LIMIT_ORGASM_FROM_CUMSWALLOW = 5;
var LIMIT_ORGASM_FROM_PUSSYCREAMPIE = 5;
var LIMIT_ORGASM_FROM_ANALCREAMPIE = 5;
var LIMIT_ORGASM_FROM_BUKKAKE = 5;
var LIMIT_ORGASM_FROM_SPANKING = 5;
var LIMIT_ORGASM_FROM_MASOCHISM = 5;
var LIMIT_ORGASM_FROM_SADISM = 5;
var LIMIT_ORGASM_FROM_MASTURBATION = 5;
var LIMIT_ORGASM_FROM_TOYS = 5;

var LIMIT_TOTAL_EJACULATION_COUNT = 25;
var LIMIT_TOTAL_EJACULATION_ML = 200;

var LIMIT_SEXUAL_PARTNERS_PRISONER = 20;
var LIMIT_SEXUAL_PARTNERS_GUARD = 22;
var LIMIT_SEXUAL_PARTNERS_GOBLIN = 22;
var LIMIT_SEXUAL_PARTNERS_THUG = 22;
var LIMIT_SEXUAL_PARTNERS_SLIME = 22;
var LIMIT_SEXUAL_PARTNERS_NERD = 22;
var LIMIT_SEXUAL_PARTNERS_ROGUE = 22;
var LIMIT_SEXUAL_PARTNERS_LIZARDMAN = 22;
var LIMIT_SEXUAL_PARTNERS_ORC = 22;
var LIMIT_SEXUAL_PARTNERS_HOMELESS = 22;
var LIMIT_SEXUAL_PARTNERS_VISITOR = 32;

var LIMIT_VIRGINITIES_TAKEN_VIA_PUSSY = 15;
var LIMIT_VIRGINITIES_TAKEN_VIA_ANAL = 15;

var LIMIT_MAX_REACHED_MOUTH_DESIRE_COUNT = 20;
var LIMIT_MAX_REACHED_BOOBS_DESIRE_COUNT = 20;
var LIMIT_MAX_REACHED_PUSSY_DESIRE_COUNT = 20;
var LIMIT_MAX_REACHED_BUTT_DESIRE_COUNT = 20;
var LIMIT_MAX_REACHED_COCK_DESIRE_COUNT = 20;
var LIMIT_MAX_REACHED_ALL_DESIRE_COUNT = 20;

var LIMIT_KICK_COUNTER_SEX_COUNT = 30;
var LIMIT_DOUBLE_PENETRATION_COUNT = 69;
var LIMIT_TRIPLE_PENETRATION_COUNT = 30;
var LIMIT_BLOWBANG_COUNT = 999;
var LIMIT_URINAL_COUNT = 999;

var LIMIT_MANUALLY_REMOVED_CLIT_TOY_COUNT = 20;
var LIMIT_MANUALLY_REMOVED_PUSSY_TOY_COUNT = 20;
var LIMIT_MANUALLY_REMOVED_ANAL_TOY_COUNT = 20;

var LIMIT_CLIT_TOY_INSERTED_COUNT = 10;
var LIMIT_PUSSY_TOY_INSERTED_COUNT = 10;
var LIMIT_ANAL_TOY_INSERTED_COUNT = 10;

var LIMIT_CLIT_TOY_USED_BY_ENEMY_COUNT = 20;
var LIMIT_PUSSY_TOY_USED_BY_ENEMY_COUNT = 20;
var LIMIT_ANAL_TOY_USED_BY_ENEMY_COUNT = 20;

repo_name: Rexhunk/karryn

license: unknown


code:
var Remtairy = Remtairy || {};
Remtairy.KarrynOnani = Remtairy.KarrynOnani || {};

//オナニーレベル１
const BATTLEBACK1_MASTURBATION_LV1_NAME = 'Mas01';
const MASTURBATION_LV1_BATTLERNAME = 'mas_target';

const MASTURBATION_LV1_X_OFFSET = 0;
const MASTURBATION_LV1_Y_OFFSET = -50;

const MASTURBATION_LV1_FINGERS_CLOSE_X = 912;
const MASTURBATION_LV1_FINGERS_CLOSE_Y = 260;

const MASTURBATION_LV1_FINGERS_CLOSE_SUCK_FINGERS_X = 890;
const MASTURBATION_LV1_FINGERS_CLOSE_SUCK_FINGERS_Y = 262;

const MASTURBATION_LV1_FINGERS_FAR_X = 985;
const MASTURBATION_LV1_FINGERS_FAR_Y = 265;

const MASTURBATION_LV1_BOOBS_NORMAL_X = 830;
const MASTURBATION_LV1_BOOBS_NORMAL_Y = 415;

const MASTURBATION_LV1_BOOBS_MOVED_X = 860;
const MASTURBATION_LV1_BOOBS_MOVED_Y = 365;

const MASTURBATION_LV1_NIPPLES_NORMAL_X = 530;
const MASTURBATION_LV1_NIPPLES_NORMAL_Y = 305;

const MASTURBATION_LV1_NIPPLES_TOUCH_X = 598;
const MASTURBATION_LV1_NIPPLES_TOUCH_Y = 290;

const MASTURBATION_LV1_CLIT_X = 665;
const MASTURBATION_LV1_CLIT_Y = 612;

const MASTURBATION_LV1_PUSSY_X = 642;
const MASTURBATION_LV1_PUSSY_Y = 714;

const MASTURBATION_LV1_ANAL_X = 641;
const MASTURBATION_LV1_ANAL_Y = 810;

//=============================================================================
 /*:
 * @plugindesc Karryn Onani
 * @author Remtairy
 *
 * @help
 * This is a private plugin.
 * Do not redistribute, use, or modify this plugin
 * without explicit written permission from Remtairy.
 *
 */
//=============================================================================

const VAR_BASE_MASTURBATE_TURNS = 7;
const VAR_NOISE_LEVEL_MIN_EFFECT = 5;
const VAR_NOISE_LEVEL_INVASION_CHANCE = 0.2;

const TROOP_ONANI_LV1_ID = 15;

const SLOT_M_MOUTH = 70;
const SLOT_M_BOOBS = 71;
const SLOT_M_NIPPLES = 72;
const SLOT_M_CLIT = 73;
const SLOT_M_PUSSY = 74;
const SLOT_M_BUTT = 75;
const SLOT_M_ANAL = 76;
const SLOT_M_FINGERS = 77;

const ENEMYTYPE_MASTURBATE_MOUTH_TAG = 'm_mouth';
const ENEMYTYPE_MASTURBATE_FINGERS_TAG = 'm_fingers';
const ENEMYTYPE_MASTURBATE_BOOBS_TAG = 'm_boobs';
const ENEMYTYPE_MASTURBATE_NIPPLES_TAG = 'm_nipples';
const ENEMYTYPE_MASTURBATE_CLIT_TAG = 'm_clit';
const ENEMYTYPE_MASTURBATE_PUSSY_TAG = 'm_pussy';
const ENEMYTYPE_MASTURBATE_BUTT_TAG = 'm_butt';
const ENEMYTYPE_MASTURBATE_ANAL_TAG = 'm_anal';

////////////////
// Game Troop
////////////////

Game_Troop.prototype.setup_masturbationPose = function(troopId) {
	this._troopId = troopId;
    this._enemies = [];

	if(Karryn.isInMasturbationLevel1Pose()) {
		this.troop().members.forEach(function(member) {
			if ($dataEnemies[member.enemyId]) {
				let enemyId = member.enemyId;
				let x = MASTURBATION_LV1_X_OFFSET;
				let y = MASTURBATION_LV1_Y_OFFSET;

				let enemy = new Game_Enemy(enemyId, x, y, false);
				let spriteName = MASTURBATION_LV1_BATTLERNAME;
				let bodyType = enemy.enemyType();
				if(bodyType == ENEMYTYPE_MASTURBATE_FINGERS_TAG) {
					enemy._screenX = x + MASTURBATION_LV1_FINGERS_CLOSE_X;
					enemy._screenY = y + MASTURBATION_LV1_FINGERS_CLOSE_Y;
				}
				else if(bodyType == ENEMYTYPE_MASTURBATE_BOOBS_TAG) {
					enemy._screenX = x + MASTURBATION_LV1_BOOBS_NORMAL_X;
					enemy._screenY = y + MASTURBATION_LV1_BOOBS_NORMAL_Y;
				}
				else if(bodyType == ENEMYTYPE_MASTURBATE_NIPPLES_TAG) {
					enemy._screenX = x + MASTURBATION_LV1_NIPPLES_NORMAL_X;
					enemy._screenY = y + MASTURBATION_LV1_NIPPLES_NORMAL_Y;
				}
				else if(bodyType == ENEMYTYPE_MASTURBATE_CLIT_TAG) {
					enemy._screenX = x + MASTURBATION_LV1_CLIT_X;
					enemy._screenY = y + MASTURBATION_LV1_CLIT_Y;
				}
				else if(bodyType == ENEMYTYPE_MASTURBATE_PUSSY_TAG) {
					enemy._screenX = x + MASTURBATION_LV1_PUSSY_X;
					enemy._screenY = y + MASTURBATION_LV1_PUSSY_Y;
				}
				else if(bodyType == ENEMYTYPE_MASTURBATE_ANAL_TAG) {
					enemy._screenX = x + MASTURBATION_LV1_ANAL_X;
					enemy._screenY = y + MASTURBATION_LV1_ANAL_Y;
				}

				enemy.setCustomEnemySprite(spriteName);
				//enemy.setCustomEnemySpritePosition(x, y);

				this._enemies.push(enemy);
			}
		}, this);
	}
	else console.log('Error with troop setup_masturbationPose');
};

////////////////
// Game Actor
////////////////

//Pre Battle
//Pre Masturbation Battle
Game_Actor.prototype.preMasturbationBattleSetup = function() {
	this.preBattleSetup();
	this.disableMentalPhase();
	this.resetInvasionNoiseLevel();
	this.setAsNoHalberdBattle();
	this.clearBattleSkillsFlags();

	this.addToActorMasturbatedRecord();
	this._masturbatedBeforeRestToday = true;
	this._orgasmCallQueuedUp = false;
	this._startOfInvasionBattle = false;
	this.removeState(STATE_CONFIDENT_ID);

	//Masturbate Battle Level 1
	$gameMap.changeBattleback(BATTLEBACK1_MASTURBATION_LV1_NAME, null);
	this.setMasturbationLevel1Pose();
	$gameVariables.setValue(VARIABLE_TROOPID_ID, TROOP_ONANI_LV1_ID);

	this._dirty = true;
};

//Post Battle
//Post Masturbation Battle
Game_Actor.prototype.postMasturbationBattleCleanup = function() {
	let invasionChance = this.getInvasionChance();
	let invasionNoiseLevel = this.getInvasionNoiseLevel();
	let invasionNoiseLevelEffect = Math.max(invasionChance * VAR_NOISE_LEVEL_INVASION_CHANCE, VAR_NOISE_LEVEL_MIN_EFFECT);

	if(invasionChance > 0)
		invasionChance += invasionNoiseLevel * invasionNoiseLevelEffect;

	if(Math.randomInt(100) < invasionChance) {
		$gameSwitches.setValue(SWITCH_INVASION_BATTLE_ID, true);
		this._startOfInvasionBattle = true;
		if(this._tempRecordOrgasmCount > 0)
			BattleManager.setEnemySneakAttackBattle();
		this.refreshSlutLvlStageVariables_General();
	}
	else {
		$gameSwitches.setValue(SWITCH_INVASION_BATTLE_ID, false);
		this._startOfInvasionBattle = false;
		this.postBattleCleanup();
		$gameActors.actor(ACTOR_KARRYN_ID).setPleasure(0);
	}

	$gameActors.actor(ACTOR_KARRYN_ID).setWardenMapPose(0);
};

//Skill cost
Game_Actor.prototype.staminaCost_masturbateBattleSkills = function() {
	let cost = Math.round(this.maxstamina /
	(VAR_BASE_MASTURBATE_TURNS + this.masturbateLvl() * 2))
	return cost;
};

// Masturbate Battle Body Slots
Game_Actor.prototype.masturbateBattle_setRightHandOn = function(slotPart) {
	this.setBodyPart(RIGHT_HAND_ID, slotPart);
};
Game_Actor.prototype.masturbateBattle_setLeftHandOn = function(slotPart) {
	this.setBodyPart(LEFT_HAND_ID, slotPart);
};
Game_Actor.prototype.masturbateBattle_setMouthOn = function(slotPart) {
	this.setBodyPart(MOUTH_ID, slotPart);
};

Game_Actor.prototype.masturbateBattle_rightHandIsOn = function(slotPart) {
	return this.getBodySlotStatus(RIGHT_HAND_ID) === slotPart;
};
Game_Actor.prototype.masturbateBattle_leftHandIsOn = function(slotPart) {
	return this.getBodySlotStatus(LEFT_HAND_ID) === slotPart;
};
Game_Actor.prototype.masturbateBattle_MouthIsOn = function(slotPart) {
	return this.getBodySlotStatus(MOUTH_ID) === slotPart;
};

Game_Actor.prototype.masturbateBattle_rightHandIsFree = function() {
	return this.getBodySlotStatus(RIGHT_HAND_ID) === SLOT_FREE;
};
Game_Actor.prototype.masturbateBattle_LeftHandIsFree = function() {
	return this.getBodySlotStatus(LEFT_HAND_ID) === SLOT_FREE;
};
Game_Actor.prototype.masturbateBattle_MouthIsFree = function() {
	return this.getBodySlotStatus(MOUTH_ID) === SLOT_FREE;
};

////////
// Noise

Game_Actor.prototype.resetInvasionNoiseLevel = function() {
	this._invasionNoiseLevel = 0;
	this._invasionNoise = 0;
};
Game_Actor.prototype.increaseInvasionNoise = function(value) {
	let noiseMultipler = 1;
	let generalReactionScore = this.getReactionScore();

	if(generalReactionScore >= VAR_DEF_RS_LV3_REQ)
		noiseMultipler = 2;
	else if(generalReactionScore >= VAR_DEF_RS_LV2_REQ)
		noiseMultipler = 1.5;
	else if(generalReactionScore >= VAR_DEF_RS_LV1_REQ)
		noiseMultipler = 1;
	else
		noiseMultipler = 0.5;

	let noiseValue = value * noiseMultipler;
	this._invasionNoise += noiseValue;
	if(this._invasionNoise >= 10) {
		if(Math.randomInt(5) < this._invasionNoise - 8) {
			this.increaseInvasionNoiseLevel(1);
			this._invasionNoise = 0;
		}
	}
};
Game_Actor.prototype.increaseInvasionNoiseLevel = function(levels) {
	this._invasionNoiseLevel += levels;

	let invasionNoiseLevelText = '';

	if(this._invasionNoiseLevel <= 2) invasionNoiseLevelText = TextManager.invasionNoiseLevelOne;
	else if(this._invasionNoiseLevel <= 4) invasionNoiseLevelText = TextManager.invasionNoiseLevelTwo;
	else if(this._invasionNoiseLevel <= 6) invasionNoiseLevelText = TextManager.invasionNoiseLevelThree;
	else invasionNoiseLevelText = TextManager.invasionNoiseLevelFour;

	BattleManager._logWindow.push('addText', invasionNoiseLevelText);

	if(this.hasEdict(EDICT_OFFICE_SELL_ONANI_VIDEO))
		$gameParty.increaseExtraGoldReward(Math.randomInt(20 * levels));
};

Game_Actor.prototype.getInvasionNoiseLevel = function() {
	return this._invasionNoiseLevel;
};

////////
// Is Valid Target

Game_Enemy.prototype.isValidTargetForMasturbateBattle_skillTouch = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let bodyType = this.enemyType();
	let validTarget = (
	bodyType == ENEMYTYPE_MASTURBATE_BOOBS_TAG || bodyType == ENEMYTYPE_MASTURBATE_CLIT_TAG ||
	(bodyType == ENEMYTYPE_MASTURBATE_NIPPLES_TAG && actor.boobsDesire >= actor.nipplesPettingBoobsDesireRequirement()) ||
	(bodyType == ENEMYTYPE_MASTURBATE_ANAL_TAG && actor.buttDesire >= actor.analPettingButtDesireRequirement()) ||
	(bodyType == ENEMYTYPE_MASTURBATE_PUSSY_TAG && actor.pussyDesire >= actor.pussyPettingPussyDesireRequirement())
	);
	if(validTarget) {
		this._selectionShowName = true;
		this.masturbateBattleSpritePos_nipples();
		this.masturbateBattleSpritePos_boobs();
		return true;
	}
	else {
		this._selectionShowName = false;
		return false;
	}
};

Game_Enemy.prototype.isValidTargetForMasturbateBattle_skillFinger = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let bodyType = this.enemyType();
	let validTarget = (
	(bodyType == ENEMYTYPE_MASTURBATE_PUSSY_TAG && actor.pussyDesire >= actor.pussySexPussyDesireRequirement() && actor.isWet) ||
	(bodyType == ENEMYTYPE_MASTURBATE_ANAL_TAG && actor.buttDesire >= actor.analSexButtDesireRequirement()) );
	if(validTarget) {
		this._selectionShowName = true;
		return true;
	}
	else {
		this._selectionShowName = false;
		return false;
	}
};

Game_Enemy.prototype.isValidTargetForMasturbateBattle_skillSuck = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let bodyType = this.enemyType();
	let validTarget = (
	(bodyType == ENEMYTYPE_MASTURBATE_FINGERS_TAG) ||
	(bodyType == ENEMYTYPE_MASTURBATE_NIPPLES_TAG && actor.boobsDesire + actor.mouthDesire >= actor.nipplesPettingBoobsDesireRequirement() * 2)
	);
	if(validTarget) {
		this._selectionShowName = true;
		this.masturbateBattleSpritePos_fingers();
		this.masturbateBattleSpritePos_nipples();
		return true;
	}
	else {
		this._selectionShowName = false;
		return false;
	}
};

///////////
// Masturbation Sprite Pos

Game_Enemy.prototype.masturbateBattleSpritePos_fingers = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let bodyType = this.enemyType();

	if(bodyType == ENEMYTYPE_MASTURBATE_FINGERS_TAG) {
		if(actor.tachieHead == 'far')
			this.setCustomEnemySpritePosition(MASTURBATION_LV1_X_OFFSET + MASTURBATION_LV1_FINGERS_FAR_X, MASTURBATION_LV1_Y_OFFSET + MASTURBATION_LV1_FINGERS_FAR_Y);
		else if(actor.tachieHead == 'close') {
			if(actor.tachieRightArm == 'suck_fingers')
				this.setCustomEnemySpritePosition(MASTURBATION_LV1_X_OFFSET + MASTURBATION_LV1_FINGERS_CLOSE_SUCK_FINGERS_X, MASTURBATION_LV1_Y_OFFSET + MASTURBATION_LV1_FINGERS_CLOSE_SUCK_FINGERS_Y);
			else
				this.setCustomEnemySpritePosition(MASTURBATION_LV1_X_OFFSET + MASTURBATION_LV1_FINGERS_CLOSE_X, MASTURBATION_LV1_Y_OFFSET + MASTURBATION_LV1_FINGERS_CLOSE_Y);
		}
	}
};

Game_Enemy.prototype.masturbateBattleSpritePos_boobs = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let bodyType = this.enemyType();

	if(bodyType == ENEMYTYPE_MASTURBATE_BOOBS_TAG) {
		if(actor.tachieLeftBoob == 'normal' || actor.tachieLeftBoob == 'touch_oppai')
			this.setCustomEnemySpritePosition(MASTURBATION_LV1_X_OFFSET + MASTURBATION_LV1_BOOBS_NORMAL_X, MASTURBATION_LV1_Y_OFFSET + MASTURBATION_LV1_BOOBS_NORMAL_Y);
		else {
			this.setCustomEnemySpritePosition(MASTURBATION_LV1_X_OFFSET + MASTURBATION_LV1_BOOBS_MOVED_X, MASTURBATION_LV1_Y_OFFSET + MASTURBATION_LV1_BOOBS_MOVED_Y);
		}
	}
};

Game_Enemy.prototype.masturbateBattleSpritePos_nipples = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	let bodyType = this.enemyType();

	if(bodyType == ENEMYTYPE_MASTURBATE_NIPPLES_TAG) {
		if(actor.tachieRightBoob == 'touch_chikubi')
			this.setCustomEnemySpritePosition(MASTURBATION_LV1_X_OFFSET + MASTURBATION_LV1_NIPPLES_TOUCH_X, MASTURBATION_LV1_Y_OFFSET + MASTURBATION_LV1_NIPPLES_TOUCH_Y);
		else {
			this.setCustomEnemySpritePosition(MASTURBATION_LV1_X_OFFSET + MASTURBATION_LV1_NIPPLES_NORMAL_X, MASTURBATION_LV1_Y_OFFSET + MASTURBATION_LV1_NIPPLES_NORMAL_Y);
		}
	}
};

//////////
// Release

Game_Actor.prototype.masturbateBattle_resetLeftHand = function() {
	if(this.masturbateBattle_leftHandIsOn(SLOT_M_MOUTH)) {
		this.masturbateBattle_setMouthOn(SLOT_FREE);
		this.setMaxTachieDroolFingersId(0);
		this.setMaxTachieDroolNipplesId(0);
		//if(this.tachieHead == 'far')
		//	this.setTachieMouth('far_1');
		//else
		//	this.setTachieMouth('close_1');
	}
	this.masturbateBattle_setLeftHandOn(SLOT_FREE);
	this.setTachieLeftArmInFrontOfBody(true);

	this.setTachieLeftArm('normal');
	this.setTachieLeftBoob('normal');

};

Game_Actor.prototype.masturbateBattle_resetRightHand = function() {
	if(this.masturbateBattle_rightHandIsOn(SLOT_M_MOUTH)) {
		this.masturbateBattle_setMouthOn(SLOT_FREE);
		this.setMaxTachieDroolFingersId(0);
		this.setMaxTachieDroolNipplesId(0);
		//if(this.tachieHead == 'far')
		//	this.setTachieMouth('far_1');
		//else
		//	this.setTachieMouth('close_1');
	}
	this.masturbateBattle_setRightHandOn(SLOT_FREE);
	this.setTachieRightArmInFrontOfBody(false);
	this.setTachieRightArmInFrontOfBoobs(true);
	this.setTachieRightArmInFrontOfHeadAndBehindBody(false);

	this.setTachieRightArm('normal');
	this.setTachieRightBoob('normal');

};

////////
// Before Eval

//Touch
Game_Actor.prototype.beforeEval_masturbateBattle_skillTouch = function(target) {
	let bodyType = target.enemyType();
	let onaniLvl = this.masturbateLvl();
	let extraGoldReward = 0;
	if(this.hasEdict(EDICT_OFFICE_SELL_ONANI_VIDEO))
		extraGoldReward = Math.randomInt(onaniLvl * 5 + 12);

	if(bodyType == ENEMYTYPE_MASTURBATE_CLIT_TAG) {
		if(!this.masturbateBattle_rightHandIsOn(SLOT_M_CLIT))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetRightHand();
		this.masturbateBattle_setRightHandOn(SLOT_M_CLIT);
		this.resetTachieRightArm();
		this.setTachieRightBoob('touch_mame');
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleTouchClit);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_TOUCH_CLIT);
		$gameParty.increaseExtraGoldReward(extraGoldReward);
	}
	else if(bodyType == ENEMYTYPE_MASTURBATE_PUSSY_TAG) {
		if(!this.masturbateBattle_leftHandIsOn(SLOT_M_PUSSY))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetLeftHand();
		this.masturbateBattle_setLeftHandOn(SLOT_M_PUSSY);
		this.setTachieLeftArm('touch_omanko');
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleTouchPussy);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_TOUCH_PUSSY);
		$gameParty.increaseExtraGoldReward(extraGoldReward * 1.2);
	}
	else if(bodyType == ENEMYTYPE_MASTURBATE_ANAL_TAG) {
		if(!this.masturbateBattle_leftHandIsOn(SLOT_M_ANAL))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetLeftHand();
		this.masturbateBattle_setLeftHandOn(SLOT_M_ANAL);
		this.setTachieLeftArm('touch_anaru');
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleTouchAnal);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_TOUCH_ANUS);
		$gameParty.increaseExtraGoldReward(extraGoldReward * 1.2);
	}
	else if(bodyType == ENEMYTYPE_MASTURBATE_BOOBS_TAG) {
		if(!this.masturbateBattle_leftHandIsOn(SLOT_M_BOOBS))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetLeftHand();
		this.masturbateBattle_setLeftHandOn(SLOT_M_BOOBS);
		this.resetTachieLeftArm();
		this.setTachieLeftBoob('touch_oppai');
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleTouchBoobs);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_TOUCH_BOOBS);
		$gameParty.increaseExtraGoldReward(extraGoldReward);
	}
	else if(bodyType == ENEMYTYPE_MASTURBATE_NIPPLES_TAG) {
		if(!this.masturbateBattle_rightHandIsOn(SLOT_M_NIPPLES))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetRightHand();
		this.masturbateBattle_resetLeftHand();
		this.masturbateBattle_setRightHandOn(SLOT_M_NIPPLES);
		this.masturbateBattle_setLeftHandOn(SLOT_M_NIPPLES);
		this.resetTachieRightArm();
		this.resetTachieLeftArm();
		this.setTachieRightBoob('touch_chikubi');
		this.setTachieLeftBoob('touch_chikubi');
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleTouchNipples);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_TOUCH_NIPPLES);
		$gameParty.increaseExtraGoldReward(extraGoldReward * 1.2);
	}

	this.emoteMasturbateBattleOne();
};//End Touch

//Finger
Game_Actor.prototype.beforeEval_masturbateBattle_skillFinger = function(target) {
	let bodyType = target.enemyType();
	let onaniLvl = this.masturbateLvl();
	let extraGoldReward = 0;
	if(this.hasEdict(EDICT_OFFICE_SELL_ONANI_VIDEO))
		extraGoldReward = Math.randomInt(onaniLvl * 7 + 15);

	if(bodyType == ENEMYTYPE_MASTURBATE_PUSSY_TAG) {

		if(this.masturbateBattle_rightHandIsFree() || (this.masturbateBattle_rightHandIsFree() === this.masturbateBattle_LeftHandIsFree() && !this.masturbateBattle_rightHandIsOn(SLOT_M_CLIT) )) {
			if(!this.masturbateBattle_rightHandIsOn(SLOT_M_PUSSY))
				this.increaseInvasionNoise(2);

			this.masturbateBattle_resetRightHand();
			this.masturbateBattle_setRightHandOn(SLOT_M_PUSSY);
			this.setTachieRightArmInFrontOfBody(true);
			this.setTachieRightArmInFrontOfBoobs(false);
			if(Karryn.isCensored())
				this.setTachieRightArm('finger_omanko_cen');
			else
				this.setTachieRightArm('finger_omanko');
		}
		else {
			if(!this.masturbateBattle_leftHandIsOn(SLOT_M_PUSSY))
				this.increaseInvasionNoise(2);

			this.masturbateBattle_resetLeftHand();
			this.masturbateBattle_setLeftHandOn(SLOT_M_PUSSY);
			if(Karryn.isCensored())
				this.setTachieLeftArm('finger_omanko_cen');
			else
				this.setTachieLeftArm('finger_omanko');

		}

		if(Karryn.isCensored())
			this.setTachieHolePussy('open_cen');
		else
			this.setTachieHolePussy('open');
		if(this.masturbateBattle_MouthIsFree()) {
			//this.setTachieEyes('far_1');
			//this.setTachieMouth('far_1');
			this.setTachieHead('far');
			//this.setTachieHair('far');
		}

		BattleManager._logWindow.push('addText', TextManager.masturbateBattleFingerPussy);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_FINGER_PUSSY);
		$gameParty.increaseExtraGoldReward(extraGoldReward);
	}
	else if(bodyType == ENEMYTYPE_MASTURBATE_ANAL_TAG) {
		if(!this.masturbateBattle_leftHandIsOn(SLOT_M_ANAL))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetLeftHand();
		this.masturbateBattle_setLeftHandOn(SLOT_M_ANAL);
		if(Karryn.isCensored())
			this.setTachieLeftArm('finger_anaru_cen');
		else
			this.setTachieLeftArm('finger_anaru');
		this.setTachieHoleAnus('open');
		if(this.masturbateBattle_MouthIsFree()) {
			//this.setTachieEyes('far_1');
			//this.setTachieMouth('far_1');
			this.setTachieHead('far');
			//this.setTachieHair('far');
		}
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleFingerAnal);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_FINGER_ANUS);
		$gameParty.increaseExtraGoldReward(extraGoldReward);
	}
	this.emoteMasturbateBattleOne();
};//End Finger

//Suck
Game_Actor.prototype.beforeEval_masturbateBattle_skillSuck = function(target) {
	let bodyType = target.enemyType();
	let onaniLvl = this.masturbateLvl();
	let extraGoldReward = 0;
	if(this.hasEdict(EDICT_OFFICE_SELL_ONANI_VIDEO))
		extraGoldReward = Math.randomInt(onaniLvl * 5 + 8);

	if(bodyType == ENEMYTYPE_MASTURBATE_FINGERS_TAG) {
		if(!this.masturbateBattle_MouthIsOn(SLOT_M_FINGERS))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetRightHand();
		if(this.masturbateBattle_leftHandIsOn(SLOT_M_MOUTH)) this.masturbateBattle_resetLeftHand();

		this.masturbateBattle_setRightHandOn(SLOT_M_MOUTH);
		this.masturbateBattle_setMouthOn(SLOT_M_FINGERS);
		this.setTachieRightArm('suck_fingers');
		this.setTachieRightArmInFrontOfBody(false);
		this.setTachieRightArmInFrontOfBoobs(false);
		this.setTachieRightArmInFrontOfHeadAndBehindBody(true);
		//this.setTachieEyes('close_1');
		//this.resetTachieMouth();
		this.setTachieHead('close');
		//this.setTachieHair('close');
		this.increaseLiquidDroolFingers(1);
		this.setMaxTachieDroolFingersId(3);
		this.setMaxTachieDroolNipplesId(0);
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleSuckFingers);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_SUCK_FINGERS);
		$gameParty.increaseExtraGoldReward(extraGoldReward);
	}
	else if(bodyType == ENEMYTYPE_MASTURBATE_NIPPLES_TAG) {
		if(!this.masturbateBattle_MouthIsOn(SLOT_M_NIPPLES))
			this.increaseInvasionNoise(2);

		this.masturbateBattle_resetLeftHand();
		if(this.masturbateBattle_rightHandIsOn(SLOT_M_MOUTH)) this.masturbateBattle_resetRightHand();

		this.masturbateBattle_setLeftHandOn(SLOT_M_MOUTH);
		this.masturbateBattle_setMouthOn(SLOT_M_NIPPLES);
		this.resetTachieLeftArm();
		this.setTachieLeftBoob('suck_chikubi');
		//this.setTachieEyes('close_1');
		//this.resetTachieMouth();
		this.setTachieHead('close');
		//this.setTachieHair('close');
		this.increaseLiquidDroolNipples(1);
		this.setMaxTachieDroolFingersId(0);
		this.setMaxTachieDroolNipplesId(3);
		BattleManager._logWindow.push('addText', TextManager.masturbateBattleSuckNipples);
		BattleManager.actionRemLines(LINE_KARRYN_MAS_SUCK_NIPPLES);
		$gameParty.increaseExtraGoldReward(extraGoldReward * 1.5);
	}
	this.emoteMasturbateBattleOne();
};//End Suck

////////
// Damage Formula

Game_Actor.prototype.dmgFormula_masturbateBattle = function(target) {
	let activeAreas = 0;
	let mouthDesireGain = 0;
	let boobsDesireGain = 0;
	let pussyDesireGain = 0;
	let buttDesireGain = 0;
	let randomDesireGainFromMouth = 0;
	let randomDesireGainFromRightHand = 0;
	let randomDesireGainFromLeftHand = 0;

	let skillLvl = this.masturbateLvl();
	let skillRating = this.masturbateSkillRating();
	let pettingRate = this.elementRate(ELEMENT_PETTING_ID);

	let pleasureFeedback = 0;

	//Right Hand
	if(!this.masturbateBattle_rightHandIsFree()) {
		activeAreas++;

		if(this.masturbateBattle_rightHandIsOn(SLOT_M_NIPPLES)) {
			let baseDmg = BASEDMG_PETTING_NIPPLES;
			let sensitivityRating = this.nipplesSensitivity();
			let desireTotal = this.boobsDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			boobsDesireGain += desireGain * 0.3;
			randomDesireGainFromRightHand += desireGain * 0.7;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorNipplesPleasureRecord(possiblePleasure);
			}

			this.addToActorNipplesPettedRecord(false);
		}
		else if(this.masturbateBattle_rightHandIsOn(SLOT_M_CLIT)) {
			let baseDmg = BASEDMG_PETTING_CLIT;
			let sensitivityRating = this.clitSensitivity();
			let desireTotal = this.pussyDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			pussyDesireGain += desireGain * 0.4;
			randomDesireGainFromRightHand += desireGain * 0.6;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorClitPleasureRecord(possiblePleasure);
			}

			this.addToActorClitPettedRecord(false);
		}
		else if(this.masturbateBattle_rightHandIsOn(SLOT_M_PUSSY)) {
			let baseDmg = BASEDMG_PETTING_PUSSY;
			let sensitivityRating = this.pussySensitivity();
			let desireTotal = this.pussyDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			pussyDesireGain += desireGain * 0.3;
			randomDesireGainFromRightHand += desireGain * 0.7;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorPussyPleasureRecord(possiblePleasure);
			}

			this.addToActorPussyPettedRecord(false);
		}
	}//End right hand

	//Left Hand
	if(!this.masturbateBattle_LeftHandIsFree()) {
		activeAreas++;

		if(this.masturbateBattle_leftHandIsOn(SLOT_M_BOOBS)) {
			let baseDmg = BASEDMG_PETTING_BOOBS;
			let sensitivityRating = this.boobsSensitivity();
			let desireTotal = this.boobsDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			boobsDesireGain += desireGain * 0.4;
			randomDesireGainFromLeftHand += desireGain * 0.6;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorBoobsPleasureRecord(possiblePleasure);
			}

			this.addToActorBoobsPettedRecord(false);
		}
		else if(this.masturbateBattle_leftHandIsOn(SLOT_M_NIPPLES)) {
			let baseDmg = BASEDMG_PETTING_NIPPLES;
			let sensitivityRating = this.nipplesSensitivity();
			let desireTotal = this.boobsDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			boobsDesireGain += desireGain * 0.3;
			randomDesireGainFromLeftHand += desireGain * 0.7;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorNipplesPleasureRecord(possiblePleasure);
			}

			if(!this.masturbateBattle_rightHandIsOn(SLOT_M_NIPPLES))
				this.addToActorNipplesPettedRecord(false);
		}
		else if(this.masturbateBattle_leftHandIsOn(SLOT_M_CLIT)) {
			let baseDmg = BASEDMG_PETTING_CLIT;
			let sensitivityRating = this.clitSensitivity();
			let desireTotal = this.pussyDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			pussyDesireGain += desireGain * 0.4;
			randomDesireGainFromLeftHand += desireGain * 0.6;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorClitPleasureRecord(possiblePleasure);
			}

			this.addToActorClitPettedRecord(false);
		}
		else if(this.masturbateBattle_leftHandIsOn(SLOT_M_PUSSY)) {
			let baseDmg = BASEDMG_PETTING_PUSSY + 2;
			let sensitivityRating = this.pussySensitivity();
			let desireTotal = this.pussyDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			pussyDesireGain += desireGain * 0.3;
			randomDesireGainFromLeftHand += desireGain * 0.7;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorPussyPleasureRecord(possiblePleasure);
			}

			this.addToActorPussyPettedRecord(false);
		}
		else if(this.masturbateBattle_leftHandIsOn(SLOT_M_ANAL)) {
			let baseDmg = BASEDMG_PETTING_ANAL;
			let sensitivityRating = this.analSensitivity();
			let desireTotal = this.buttDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			buttDesireGain += desireGain * 0.3;
			randomDesireGainFromLeftHand += desireGain * 0.7;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorAnalPleasureRecord(possiblePleasure);
			}

			this.addToActorAnalPettedRecord(false);
		}
	} //End left hand

	//Mouth
	if(!this.masturbateBattle_MouthIsFree()) {
		activeAreas++;

		if(this.masturbateBattle_MouthIsOn(SLOT_M_NIPPLES)) {
			let baseDmg = BASEDMG_PETTING_NIPPLES;
			let sensitivityRating = this.nipplesSensitivity();
			let desireTotal = this.boobsDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			boobsDesireGain += desireGain * 0.3;
			randomDesireGainFromMouth += desireGain * 0.7;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorNipplesPleasureRecord(possiblePleasure);
			}

			this.increaseLiquidDroolNipples(1);
			this.addToActorNipplesPettedRecord(false);
		}
		else if(this.masturbateBattle_MouthIsOn(SLOT_M_FINGERS)) {
			let baseDmg = BASEDMG_SUCKING_FINGERS;
			let sensitivityRating = this.mouthSensitivity();
			let desireTotal = this.mouthDesire + this.cockDesire;

			let desireGain = (baseDmg + skillLvl) * pettingRate;
			mouthDesireGain += desireGain * 0.3;
			randomDesireGainFromMouth += desireGain * 0.7;

			let possiblePleasure = (desireGain + this.dex) * skillRating * pettingRate * sensitivityRating;
			possiblePleasure -= (this.end * (0.5 - desireTotal / 400));

			if(possiblePleasure > 0) {
				pleasureFeedback += possiblePleasure;
				this.addToActorMouthPleasureRecord(possiblePleasure);
			}

			this.increaseLiquidDroolFingers(1);
			this.addToActorFingersSuckedRecord(false);
		}
	}//End mouth

	target.result().pleasureFeedback = pleasureFeedback;
	this.gainMouthDesire(mouthDesireGain);
	this.gainBoobsDesire(boobsDesireGain);
	this.gainPussyDesire(pussyDesireGain);
	this.gainButtDesire(buttDesireGain);
	this.gainRandomDesire(randomDesireGainFromMouth);
	this.gainRandomDesire(randomDesireGainFromRightHand);
	this.gainRandomDesire(randomDesireGainFromLeftHand);

	this.gainHp(-this.staminaCost_masturbateBattleSkills());

	let noiseGain = 0;

	if(activeAreas === 1) {
		this.gainDexterityExp(10, this.level);
		this.gainEnduranceExp(15, this.level);
	}
	else if(activeAreas === 2) {
		this.gainDexterityExp(15, this.level);
		this.gainEnduranceExp(25, this.level);
	}
	else if(activeAreas === 3) {
		this.gainDexterityExp(20, this.level);
		this.gainEnduranceExp(40, this.level);
	}

	if(this.tachieMouth == 'close_3' || this.tachieMouth == 'far_3') {
		noiseGain += 8;
	}
	else if(this.tachieMouth == 'close_2' || this.tachieMouth == 'far_2') {
		noiseGain += 5;
	}
	else if(this.tachieMouth == 'close_1' || this.tachieMouth == 'far_1') {
		noiseGain += 2;
	}
	else {
		noiseGain += 4;
	}
	if(this.isWet) {
		if(this.tachieLeftArm == 'finger_omanko' || this.tachieRightArm == 'finger_omanko' ||
		this.tachieLeftArm == 'finger_omanko_cen' || this.tachieRightArm == 'finger_omanko_cen')
			noiseGain += 3;
		else
			noiseGain += 1;
	}

	this.increaseInvasionNoise(noiseGain);

	this.justGotHitBySkillType(JUST_SKILLTYPE_KARRYN_MASTURBATE);

	if(this.hasEdict(EDICT_OFFICE_SELL_ONANI_VIDEO)) {
		$gameParty.increaseExtraGoldReward(Math.randomInt(2 * activeAreas * this.masturbateLvl()));
	}

	return 0;
};

///////
// Orgasm

Game_Actor.prototype.masturbationBattleOrgasm = function(orgasmCount) {
	if(this.isInMasturbationLevel1Pose()) {
		this.masturbateBattle_resetLeftHand();
		this.masturbateBattle_resetRightHand();
		this.setTachieHead('far');
		this.setTachieEyes('far_1');
		this.setTachieMouth('far_3');
		this.setTachieHair('far');
		this.setTachieFrontA('climax');
	}

	if(this.isInMasturbationPose()) {
		this.increaseInvasionNoiseLevel(orgasmCount);
	}
};