code:
const REM_RESTORE_DIGIT_HUE = [10, 200, 10, 160];
const REM_RESTORE_DIGIT_DURATION = 280;
const REM_ENERGY_DIGIT_HUE = [255, 10, 10, 160];
const REM_ENERGY_DIGIT_DURATION = 280;
const REM_PLEASURE_DIGIT_HUE = [255, 70, 244, 160];
const REM_PLEASURE_DIGIT_DURATION = 280;

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

/////////
// Game Battler
////////////////

Game_Battler.prototype.startDamagePopup = function() {
    let result = this.result();
	if(!this._damagePopup) this.clearDamagePopup();
	if(result.hpAffected) {
		let copyResult = JsonEx.makeDeepCopy(result);
		copyResult.mpDamage = 0;
		copyResult.tpDamage = 0;
		this._damagePopup.push(copyResult);
    }
    if(result.tpDamage !== 0) {
		let copyResult = JsonEx.makeDeepCopy(result);
		copyResult.hpAffected = false;
		copyResult.mpDamage = 0;
		this._damagePopup.push(copyResult);
    }
    if(result.mpDamage !== 0) {
		let copyResult = JsonEx.makeDeepCopy(result);
		copyResult.hpAffected = false;
		copyResult.tpDamage = 0;
		this._damagePopup.push(copyResult);
    }
};

///////////
// Sprite Damage
////////////////

//damage pop up push
Sprite_Damage.prototype.setup = function(target) {
    this._result = target.shiftDamagePopup();
	let result = this._result;
	let isSexualDamage = result.skillTypeEnemyPetting || result.skillTypeEnemySex || result.skillTypeEnemyBukkake || result.skillTypeEnemyTalk || result.skillTypeEnemySight || result.skillTypeActorOnani;
	let isEnemySelfFeedback = target.isEnemy() && isSexualDamage;
	if(target.isActor() && isSexualDamage && !ConfigManager.remShowSexualDamagePopup) return;
	if(isEnemySelfFeedback) return;

	if (result.evaded) {
		this.createMiss();
	} else if (result.tpDamage !== 0 && result.mpDamage <= 0) {
		if(result.tpDamage < 0 && Math.round(target.getPercentOfOrgasmFromValue(-result.tpDamage)) !== 0) {
			let digitText = '';
			if(ConfigManager.displayPleasureAsPercent)
				digitText = target.getPercentOfOrgasmFromValue(-result.tpDamage);
			else
				digitText = -result.tpDamage;

			this.createDigits(2, digitText);
			if (result.critical) {
				this.setupPleasureEffect();
			}
		}
    } else if (result.hpAffected) {
		if(result.hpDamage < 0)
			this.createDigits(1, result.hpDamage);
		else if(result.hpDamage > 0 && target.hp > 0)
			this.createDigits(0, result.hpDamage);

		if (result.critical) {
			this.setupCriticalEffect();
		}
    } else if (result.mpDamage !== 0) {
		if(target.isActor()) {
			if(result.mpDamage < 0)
				this.createDigits(3, result.mpDamage);
			else if(result.mpDamage > 0) {
				this.createDigits(2, result.mpDamage);
				this.setupPleasureEffect();
			}
		}
    }
};

Sprite_Damage.prototype.createDigits = function(baseRow, value) {
    let string = Math.abs(value).toString();
    let row = baseRow;
    let w = this.digitWidth();
    let h = this.digitHeight();
    for (let i = 0; i < string.length; i++) {
        let sprite = this.createChildSprite();
        let n = Number(string[i]);
        sprite.setFrame(n * w, row * h, w, h);
        sprite.x = (i - (string.length - 1) / 2) * w;
        sprite.dy = -i;
    }
};

Sprite_Damage.prototype.setupRestoreEffect = function() {
    this._flashColor = REM_RESTORE_DIGIT_HUE.slice();
    this._flashDuration = REM_RESTORE_DIGIT_DURATION;
};
Sprite_Damage.prototype.setupEnergyEffect = function() {
    this._flashColor = REM_ENERGY_DIGIT_HUE.slice();
    this._flashDuration = REM_ENERGY_DIGIT_DURATION;
};
Sprite_Damage.prototype.setupPleasureEffect = function() {
    this._flashColor = REM_PLEASURE_DIGIT_HUE.slice();
    this._flashDuration = REM_PLEASURE_DIGIT_DURATION;
};

/////////
// BattleManager
/////////////////

BattleManager.startAction = function() {
	var subject = this._subject;
    if (!subject) return this.endAction();
    var action = subject.currentAction();
    this._action = action;
    if (!this._action) return this.endAction();
    if (!this._action.item()) return this.endAction();

	let itemId = this._action.item().id;
	//console.log(subject.name() + ' ' + itemId); //for testing all skills being used

	switch(itemId) {
	case SKILL_DO_NOTHING_ID:
		subject.doNothing();
		return this.endAction();
	case SKILL_ENEMY_AI_GENERIC_ID:
		subject.enemyBattleAIGeneric();
		return this.endAction();
	case SKILL_ENEMY_AI_TUTORIAL_ID:
		subject.enemyBattleAITutorial();
		return this.endAction();
	case SKILL_ENEMY_AI_CARGILL_ID:
		subject.enemyBattleAICargill();
		return this.endAction();
	case SKILL_ENEMY_AI_YASU_ID:
		subject.enemyBattleAIYasu();
		return this.endAction();
	case SKILL_ENEMY_AI_TEST_ID:
		subject.enemyBattleAITest();
		return this.endAction();
	}

    var targets = action.makeTargets();
    this.setTargets(targets);
    this._allTargets = targets.slice();
    this._individualTargets = targets.slice();

    this._phase = 'phaseChange';
    this._phaseSteps = ['setup', 'whole', 'target', 'follow', 'finish'];
    this._returnPhase = '';
    this._actionList = [];
    subject.useItem(this._action.item());
    this._action.applyGlobal();
    this._logWindow.startAction(this._subject, this._action, this._targets);
};

BattleManager.actionDisplayAction = function() {
	if(this._targets) {
		this._logWindow.displayAction(this._subject, this._action.item(), this._targets[0]);
	}
	else
		this._logWindow.displayAction(this._subject, this._action.item());
    return false;
};

////////////
// Window BattleLog
/////////////////////

Window_BattleLog.prototype.displayAction = function(subject, item, target) {
    var numMethods = this._methods.length;
	let targetName = '';
	let secondVariable = '';
	let thirdVariable = '';
	if(target) {
		targetName = target.displayName();
		secondVariable = targetName;
	}
    if(DataManager.isSkill(item)) {
		let skillId = item.id;
		//console.log(skillId); //for testing all skills being used
		if(skillId === SKILL_MINION_THROW_ATTACK_ID && $gameParty._minionThrow_ammoName)
			thirdVariable = $gameParty._minionThrow_ammoName;
		else if(skillId === SKILL_FEMALE_ORGASM_ONE_ID || skillId === SKILL_FEMALE_ORGASM_TWO_ID)
			secondVariable = TextManager.karrynOrgasmNameType(subject);

		let stateMsg0 = false;
		let stateMsg1 = false;
		if(item.message1) stateMsg0 = item.message1;
		if(item.message2) stateMsg1 = item.message2;
		if(item.hasRemMessageDefault[0]) stateMsg0 = item.remMessageDefault[0];
		if(item.hasRemMessageDefault[1]) stateMsg1 = item.remMessageDefault[1];

		if(TextManager.isEnglish) {
			if(item.hasRemMessageEN[0]) stateMsg0 = item.remMessageEN[0];
			if(item.hasRemMessageEN[1]) stateMsg1 = item.remMessageEN[1];
		}
		else if(TextManager.isJapanese) {
			if(item.hasRemMessageJP[0]) stateMsg0 = item.remMessageJP[0];
			if(item.hasRemMessageJP[1]) stateMsg1 = item.remMessageJP[1];
		}
		else if(TextManager.isSChinese) {
			if(item.hasRemMessageSCH[0]) stateMsg0 = item.remMessageSCH[0];
			if(item.hasRemMessageSCH[1]) stateMsg1 = item.remMessageSCH[1];
		}
		else if(TextManager.isTChinese) {
			if(item.hasRemMessageTCH[0]) stateMsg0 = item.remMessageTCH[0];
			if(item.hasRemMessageTCH[1]) stateMsg1 = item.remMessageTCH[1];
		}
		else if(TextManager.isKorean) {
			if(item.hasRemMessageKR[0]) stateMsg0 = item.remMessageKR[0];
			if(item.hasRemMessageKR[1]) stateMsg1 = item.remMessageKR[1];
		}
		else if(TextManager.isRussian) {
			if(item.hasRemMessageRU[0]) stateMsg0 = item.remMessageRU[0];
			if(item.hasRemMessageRU[1]) stateMsg1 = item.remMessageRU[1];
		}

		if(stateMsg0) {
			stateMsg0 = this.convertEscapeCharacters(stateMsg0);
			stateMsg0 = this.convertExtraEscapeCharacters(stateMsg0);
			this.push('addText', stateMsg0.format(subject.displayName(), secondVariable, thirdVariable));
		}
		if(stateMsg1) {
			stateMsg1 = this.convertEscapeCharacters(stateMsg1);
			stateMsg1 = this.convertExtraEscapeCharacters(stateMsg1);
			this.push('addText', stateMsg1.format(subject.displayName(), secondVariable, thirdVariable));
		}
    }
	else {
        this.push('addText', TextManager.useItem.format(subject.displayName(), item.name));
    }
    if (this._methods.length === numMethods) {
        this.push('wait');
    }
};

/////////
// Window Help
////////////

Window_Help.prototype.drawSpecialSelectionText = function(action) {
    var wx = 0;
    var wy = (this.contents.height - this.lineHeight()) / 2;
    var text = '';
    if (action.isForUser()) {
      text = TextManager.yanflyBattleCoreUser;
    } else if (action.isForRandom()) {
      BattleManager.startAllSelection();
      var fmt = TextManager.yanflyBattleCoreRandomTargets;
      if (action.isForOpponent() && action.numTargets() !== 1) {
        var target = TextManager.yanflyBattleCoreEnemies;
      } else if (action.isForOpponent() && action.numTargets() === 1) {
        var target = TextManager.yanflyBattleCoreEnemy;
      } else if (action.isForFriend() && action.numTargets() !== 1) {
        var target = TextManager.yanflyBattleCoreAllies;
      } else {
       var target = TextManager.yanflyBattleCoreAlly;
      }
      text = fmt.format(target, Yanfly.Util.toGroup(action.numTargets()));
    } else if (action.isForAll()) {
      BattleManager.startAllSelection();
      var fmt = TextManager.yanflyBattleCoreAllTargets;
      if (action.isForOpponent()) {
        var target = TextManager.yanflyBattleCoreEnemies;
      } else {
        var target = TextManager.yanflyBattleCoreAllies;
      }
      text = fmt.format(target);
    }
    this.drawText(text, wx, wy, REM_BHD_HELP_WIDTH, 'center');
};


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

//EB normal battle bgm
const BM_EB_BGM_NAME = "Battle_EB1";
const BM_EB_BGM_VOLUME = 65;

//Level 1 Normal Battle BGM
const BM_PLVL1_NORMAL_BGM_NAME = "Battle1";
const BM_PLVL1_NORMAL_BGM_VOLUME = 65;
//Level 2 Normal Battle BGM
const BM_PLVL2_NORMAL_BGM_NAME = "Battle7";
const BM_PLVL2_NORMAL_BGM_VOLUME = 70;
//Level 3 Normal Battle BGM
const BM_PLVL3_NORMAL_BGM_NAME = "Battle5";
const BM_PLVL3_NORMAL_BGM_VOLUME = 65;
//Level 4 Normal Battle BGM
const BM_PLVL4_NORMAL_BGM_NAME = "Battle8";
const BM_PLVL4_NORMAL_BGM_VOLUME = 90;

//Prison level boss battle bgm
//Yasu Tutorial Battle
const BM_TUTORIAL_BGM_NAME = "Battle3";
const BM_TUTORIAL_BGM_VOLUME = 80;
//Tonkin Battle
const BM_PLVL1_BOSS_BGM_NAME = "Battle3";
const BM_PLVL1_BOSS_BGM_VOLUME = 80;
//Dr. Cargill Battle
const BM_PLVL2_BOSS_BGM_NAME = "Battle3";
const BM_PLVL2_BOSS_BGM_VOLUME = 80;
//Aron Battle -> アロン登場後
const BM_PLVL3_BOSS_START_BGM_NAME = "Battle3";
const BM_PLVL3_BOSS_START_BGM_VOLUME = 80;
const BM_PLVL3_BOSS_ARON_BGM_NAME = "Battle4";
const BM_PLVL3_BOSS_ARON_BGM_VOLUME = 80;
//Noinim Battle
const BM_PLVL4_BOSS_BGM_NAME = "Battle6";
const BM_PLVL4_BOSS_BGM_VOLUME = 90;
//Captain Battle
const BM_PLVL5_BOSS_BGM_NAME = "Battle6";
const BM_PLVL5_BOSS_BGM_VOLUME = 90;
//Final Battle
const BM_FINAL_BOSS_BGM_NAME = "Boss2";
const BM_FINAL_BOSS_BGM_VOLUME = 80;

//Custom Battle
const BM_PLVL5_CUSTOM_BATTLE_BGM_NAME = "Battle_Night2";
const BM_PLVL5_CUSTOM_BATTLE_BGM_VOLUME = 70;
//Endless Battle Start
const BM_PLVL5_ENDLESS_BATTLE_BGM_NAME = "Battle1";
const BM_PLVL5_ENDLESS_BATTLE_BGM_VOLUME = 65;
//Endless
const BM_PLVL5_ENDLESS_WAVE_6_TO_9_BGM_NAME = "Battle7";
const BM_PLVL5_ENDLESS_WAVE_6_TO_9_BGM_VOLUME = 70;
const BM_PLVL5_ENDLESS_WAVE_11_TO_14_BGM_NAME = "Battle5";
const BM_PLVL5_ENDLESS_WAVE_11_TO_14_BGM_VOLUME = 65;
const BM_PLVL5_ENDLESS_WAVE_16_TO_19_BGM_NAME = "Battle8";
const BM_PLVL5_ENDLESS_WAVE_16_TO_19_BGM_VOLUME = 90;
const BM_PLVL5_ENDLESS_WAVE_21_TO_24_BGM_NAME = "Battle_Invasion1";
const BM_PLVL5_ENDLESS_WAVE_21_TO_24_BGM_VOLUME = 90;
const BM_PLVL5_ENDLESS_WAVE_26_TO_29_BGM_NAME = "Battle_EB1";
const BM_PLVL5_ENDLESS_WAVE_26_TO_29_BGM_VOLUME = 65;
const BM_PLVL5_ENDLESS_WAVE_31_TO_34_BGM_NAME = "Battle_Night1";
const BM_PLVL5_ENDLESS_WAVE_31_TO_34_BGM_VOLUME = 80;
const BM_PLVL5_ENDLESS_WAVE_36_TO_39_BGM_NAME = "Battle3";
const BM_PLVL5_ENDLESS_WAVE_36_TO_39_BGM_VOLUME = 80;
const BM_PLVL5_ENDLESS_WAVE_41_TO_44_BGM_NAME = "Battle6";
const BM_PLVL5_ENDLESS_WAVE_41_TO_44_BGM_VOLUME = 90;
const BM_PLVL5_ENDLESS_WAVE_46_TO_49_BGM_NAME = "Boss1";
const BM_PLVL5_ENDLESS_WAVE_46_TO_49_BGM_VOLUME = 90;
const BM_PLVL5_ENDLESS_WAVE_5_TO_25_MOD5_BGM_NAME = "Battle2";
const BM_PLVL5_ENDLESS_WAVE_5_TO_25_MOD5_BGM_VOLUME = 80;
const BM_PLVL5_ENDLESS_WAVE_30_TO_45_MOD5_BGM_NAME = "Battle4";
const BM_PLVL5_ENDLESS_WAVE_30_TO_45_MOD5_BGM_VOLUME = 80;
const BM_PLVL5_ENDLESS_WAVE_50_BGM_NAME = "Title1";
const BM_PLVL5_ENDLESS_WAVE_50_BGM_VOLUME = 80;

//enemy sex pose
const BM_ENEMY_SEX_BGM_NAME = "H_Gangbang1";
const BM_ENEMY_SEX_BGM_PAN = 0;
const BM_ENEMY_SEX_BGM_PITCH = 100;
const BM_ENEMY_SEX_BGM_VOLUME = 75;

//karryn sex pose
const BM_KARRYN_SEX_BGM_NAME = "H_Slut1";
const BM_KARRYN_SEX_BGM_PAN = 0;
const BM_KARRYN_SEX_BGM_PITCH = 100;
const BM_KARRYN_SEX_BGM_VOLUME = 80;

//waitress job
const BM_WAITRESS_JOB_BGM_NAME = "Job1";
const BM_WAITRESS_JOB_BGM_PAN = 0;
const BM_WAITRESS_JOB_BGM_PITCH = 100;
const BM_WAITRESS_JOB_BGM_VOLUME = 95;

//waitress sex
const BM_WAITRESS_SEX_BGM_NAME = "H_Job1";
const BM_WAITRESS_SEX_BGM_PAN = 0;
const BM_WAITRESS_SEX_BGM_PITCH = 100;
const BM_WAITRESS_SEX_BGM_VOLUME = 95;

//receptionist job
const BM_RECEPTIONIST_JOB_BGM_NAME = "Job1";
const BM_RECEPTIONIST_JOB_BGM_PAN = 0;
const BM_RECEPTIONIST_JOB_BGM_PITCH = 100;
const BM_RECEPTIONIST_JOB_BGM_VOLUME = 63;

const BM_RECEPTIONIST_SEX_BGM_NAME = "H_Job1";
const BM_RECEPTIONIST_SEX_BGM_PAN = 0;
const BM_RECEPTIONIST_SEX_BGM_PITCH = 100;
const BM_RECEPTIONIST_SEX_BGM_VOLUME = 95;

//glory hole
const BM_GLORY_START_NORMAL_BGM_NAME = "M_Sofa1";
const BM_GLORY_START_NORMAL_BGM_PAN = 0;
const BM_GLORY_START_NORMAL_BGM_PITCH = 100;
const BM_GLORY_START_NORMAL_BGM_VOLUME = 80;

const BM_GLORY_START_SLUTTY_BGM_NAME = "H_Slut2";
const BM_GLORY_START_SLUTTY_BGM_PAN = 0;
const BM_GLORY_START_SLUTTY_BGM_PITCH = 100;
const BM_GLORY_START_SLUTTY_BGM_VOLUME = 80;

const BM_GLORY_SEX_BGM_NAME = "H_Job1";
const BM_GLORY_SEX_BGM_PAN = 0;
const BM_GLORY_SEX_BGM_PITCH = 100;
const BM_GLORY_SEX_BGM_VOLUME = 95;

//stripper show
const BM_STRIPPER_SHOW_BGM_NAME = "Job2";
const BM_STRIPPER_SHOW_BGM_PAN = 0;
const BM_STRIPPER_SHOW_BGM_PITCH = 100;
const BM_STRIPPER_SHOW_BGM_VOLUME = 80;

//stripper sex
const BM_STRIPPER_SEX_BGM_NAME = "H_Job1";
const BM_STRIPPER_SEX_BGM_PAN = 0;
const BM_STRIPPER_SEX_BGM_PITCH = 100;
const BM_STRIPPER_SEX_BGM_VOLUME = 95;

//down pose - stamina
const BM_DOWN_STAMINA_BGM_NAME = "Down1";
const BM_DOWN_STAMINA_BGM_PAN = 0;
const BM_DOWN_STAMINA_BGM_PITCH = 100;
const BM_DOWN_STAMINA_BGM_VOLUME = 80;

const BM_DOWN_STAMINA_BGM_PITCH_CHANGE = -32; //unused
const BM_DOWN_STAMINA_BGM_VOLUME_CHANGE = 0; //unused

//down pose - other
const BM_DOWN_OTHER_BGM_NAME = "Down2";
const BM_DOWN_OTHER_BGM_PAN = 0;
const BM_DOWN_OTHER_BGM_PITCH = 100;
const BM_DOWN_OTHER_BGM_VOLUME = 80;

//defeated lvl 1 - normal
const BM_DEFEATED_LV1_NORMAL_BGM_NAME = "H_Defeated1";
const BM_DEFEATED_LV1_NORMAL_BGM_PAN = 0;
const BM_DEFEATED_LV1_NORMAL_BGM_PITCH = 100;
const BM_DEFEATED_LV1_NORMAL_BGM_VOLUME = 70;

//defeated lvl 1 - slutty
const BM_DEFEATED_LV1_SLUTTY_BGM_NAME = "H_Slut2";
const BM_DEFEATED_LV1_SLUTTY_BGM_PAN = 0;
const BM_DEFEATED_LV1_SLUTTY_BGM_PITCH = 100;
const BM_DEFEATED_LV1_SLUTTY_BGM_VOLUME = 80;

//defeated lvl 2 - normal
const BM_DEFEATED_LV2_NORMAL_BGM_NAME = "H_Defeated1";
const BM_DEFEATED_LV2_NORMAL_BGM_PAN = 0;
const BM_DEFEATED_LV2_NORMAL_BGM_PITCH = 100;
const BM_DEFEATED_LV2_NORMAL_BGM_VOLUME = 70;

//defeated lvl 2 - slutty
const BM_DEFEATED_LV2_SLUTTY_BGM_NAME = "H_Slut2";
const BM_DEFEATED_LV2_SLUTTY_BGM_PAN = 0;
const BM_DEFEATED_LV2_SLUTTY_BGM_PITCH = 100;
const BM_DEFEATED_LV2_SLUTTY_BGM_VOLUME = 80;

//defeated lvl 3 - normal
const BM_DEFEATED_LV3_NORMAL_BGM_NAME = "H_Defeated1";
const BM_DEFEATED_LV3_NORMAL_BGM_PAN = 0;
const BM_DEFEATED_LV3_NORMAL_BGM_PITCH = 100;
const BM_DEFEATED_LV3_NORMAL_BGM_VOLUME = 70;

//defeated lvl 3 - slutty
const BM_DEFEATED_LV3_SLUTTY_BGM_NAME = "H_Slut2";
const BM_DEFEATED_LV3_SLUTTY_BGM_PAN = 0;
const BM_DEFEATED_LV3_SLUTTY_BGM_PITCH = 100;
const BM_DEFEATED_LV3_SLUTTY_BGM_VOLUME = 80;

//defeated lvl 4 - normal
const BM_DEFEATED_LV4_NORMAL_BGM_NAME = "H_Defeated1";
const BM_DEFEATED_LV4_NORMAL_BGM_PAN = 0;
const BM_DEFEATED_LV4_NORMAL_BGM_PITCH = 100;
const BM_DEFEATED_LV4_NORMAL_BGM_VOLUME = 70;

//defeated lvl 4 - slutty
const BM_DEFEATED_LV4_SLUTTY_BGM_NAME = "H_Slut2";
const BM_DEFEATED_LV4_SLUTTY_BGM_PAN = 0;
const BM_DEFEATED_LV4_SLUTTY_BGM_PITCH = 100;
const BM_DEFEATED_LV4_SLUTTY_BGM_VOLUME = 80;

//defeated lvl 5 - normal
const BM_DEFEATED_LV5_NORMAL_BGM_NAME = "H_Defeated1";
const BM_DEFEATED_LV5_NORMAL_BGM_PAN = 0;
const BM_DEFEATED_LV5_NORMAL_BGM_PITCH = 100;
const BM_DEFEATED_LV5_NORMAL_BGM_VOLUME = 70;

//defeated lvl 5 - slutty
const BM_DEFEATED_LV5_SLUTTY_BGM_NAME = "H_Slut2";
const BM_DEFEATED_LV5_SLUTTY_BGM_PAN = 0;
const BM_DEFEATED_LV5_SLUTTY_BGM_PITCH = 100;
const BM_DEFEATED_LV5_SLUTTY_BGM_VOLUME = 80;

//defeated guard - normal
const BM_DEFEATED_GUARD_NORMAL_BGM_NAME = "H_Defeated1";
const BM_DEFEATED_GUARD_NORMAL_BGM_PAN = 0;
const BM_DEFEATED_GUARD_NORMAL_BGM_PITCH = 100;
const BM_DEFEATED_GUARD_NORMAL_BGM_VOLUME = 70;

//defeated guard - slutty
const BM_DEFEATED_GUARD_SLUTTY_BGM_NAME = "H_Slut2";
const BM_DEFEATED_GUARD_SLUTTY_BGM_PAN = 0;
const BM_DEFEATED_GUARD_SLUTTY_BGM_PITCH = 100;
const BM_DEFEATED_GUARD_SLUTTY_BGM_VOLUME = 80;

//defeated guard - bitch end
const BM_DEFEATED_GUARD_BITCH_END_BGM_NAME = "Ending3";
const BM_DEFEATED_GUARD_BITCH_END_BGM_PAN = 0;
const BM_DEFEATED_GUARD_BITCH_END_BGM_PITCH = 100;
const BM_DEFEATED_GUARD_BITCH_END_BGM_VOLUME = 90;

//night battle - normal
const BM_NIGHT_BATTLE_NORMAL_BGM_NAME = "Battle_Night1";
const BM_NIGHT_BATTLE_NORMAL_BGM_PAN = 0;
const BM_NIGHT_BATTLE_NORMAL_BGM_PITCH = 100;
const BM_NIGHT_BATTLE_NORMAL_BGM_VOLUME = 80;

//night battle - slutty
const BM_NIGHT_BATTLE_SLUTTY_BGM_NAME = "Battle_Night2";
const BM_NIGHT_BATTLE_SLUTTY_BGM_PAN = 0;
const BM_NIGHT_BATTLE_SLUTTY_BGM_PITCH = 95;
const BM_NIGHT_BATTLE_SLUTTY_BGM_VOLUME = 70;

//masturbation battle bgm
const BM_MAS_BGM_NAME = "M_Sofa1";
const BM_MAS_BGM_BGM_PAN = 0;
const BM_MAS_BGM_BGM_PITCH = 100;
const BM_MAS_BGM_VOLUME = 80;

//invasion battle bgm
const BM_INVASION_BATTLE_BGM_NAME = "Battle_Invasion1";
const BM_INVASION_BATTLE_BGM_PAN = 0;
const BM_INVASION_BATTLE_BGM_PITCH = 100;
const BM_INVASION_BATTLE_BGM_VOLUME = 90;

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

///////////
///////////////
// Battle Manager
////////////////
/////////////

//Cast Animation
BattleManager.actionCastAnimation = function() {
  if(!this._action.isAttack() && !this._action.isGuard() &&
  this._action.isSkill()) {
    if(this._action.item().castAnimation > 0 && (!this._subject._tagDontDrawImage && !Karryn.isInShowEnemyImageOnlyDuringValidSelectionPose())) {
      var ani = $dataAnimations[this._action.item().castAnimation]
      this._logWindow.showAnimation(this._subject, [this._subject],
        this._action.item().castAnimation);
    }
  }
  return true;
};

//Can Escape
BattleManager.canEscape = function() {
    return (this._canEscape && $gameActors.actor(ACTOR_KARRYN_ID).canEscape());
};

// Also called in pre battle common event
BattleManager.setBMAllowTachieUpdate = function(allow) {
	$gameParty._allowTachieUpdate = allow;
	if(this.isTachieUpdateAllowed()) {
		var group = $gameParty.members();
		for(var i = 0; i < group.length; i++) {
			var actor = group[i];
			if(!actor) { continue; }
			actor.setCacheChanged();
		}
	}
};

BattleManager.isTachieUpdateAllowed = function() {
	return $gameParty._allowTachieUpdate;
};

BattleManager.setEnemySneakAttackBattle = function() {
	$gameSwitches.setValue(SWITCH_ENEMY_SNEAK_ATTACK_ID, true);
};

////////
// Battle BGM
//////////////

Remtairy.BM.BattleManager_initMembers = BattleManager.initMembers;
BattleManager.initMembers = function() {
    Remtairy.BM.BattleManager_initMembers.call(this);
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
	this._normalBgm = null;
};

BattleManager.playBattleBgm = function() {
	let bgmName = BM_EB_BGM_NAME;
	let bgmVolume = BM_EB_BGM_VOLUME;
	let bgmPan = 0;
	let bgmPitch = 100;
	let mapId = $gameMap._mapId;

	if(Karryn.isInMasturbationCouchPose()) {
		bgmName = BM_MAS_BGM_NAME;
		bgmPan = BM_MAS_BGM_BGM_PAN;
		bgmPitch = BM_MAS_BGM_BGM_PITCH;
		bgmVolume = BM_MAS_BGM_VOLUME;
	}
	else if(Karryn.isInDefeatedPose()) {
		let useSluttyDefeatedVersion = Karryn.getReactionScore() >= VAR_DEF_RS_LV3_REQ;

		if(Karryn.isInDefeatedLevel1Pose()) {
			if(useSluttyDefeatedVersion) {
				bgmName = BM_DEFEATED_LV1_SLUTTY_BGM_NAME;
				bgmPan = BM_DEFEATED_LV1_SLUTTY_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV1_SLUTTY_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV1_SLUTTY_BGM_VOLUME;
			}
			else {
				bgmName = BM_DEFEATED_LV1_NORMAL_BGM_NAME;
				bgmPan = BM_DEFEATED_LV1_NORMAL_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV1_NORMAL_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV1_NORMAL_BGM_VOLUME;
			}
		}
		else if(Karryn.isInDefeatedLevel2Pose()) {
			if(useSluttyDefeatedVersion) {
				bgmName = BM_DEFEATED_LV2_SLUTTY_BGM_NAME;
				bgmPan = BM_DEFEATED_LV2_SLUTTY_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV2_SLUTTY_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV2_SLUTTY_BGM_VOLUME;
			}
			else {
				bgmName = BM_DEFEATED_LV2_NORMAL_BGM_NAME;
				bgmPan = BM_DEFEATED_LV2_NORMAL_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV2_NORMAL_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV2_NORMAL_BGM_VOLUME;
			}
		}
		else if(Karryn.isInDefeatedLevel3Pose()) {
			if(useSluttyDefeatedVersion) {
				bgmName = BM_DEFEATED_LV3_SLUTTY_BGM_NAME;
				bgmPan = BM_DEFEATED_LV3_SLUTTY_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV3_SLUTTY_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV3_SLUTTY_BGM_VOLUME;
			}
			else {
				bgmName = BM_DEFEATED_LV3_NORMAL_BGM_NAME;
				bgmPan = BM_DEFEATED_LV3_NORMAL_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV3_NORMAL_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV3_NORMAL_BGM_VOLUME;
			}
		}
		else if(Karryn.isInDefeatedLevel4Pose()) {
			if(useSluttyDefeatedVersion) {
				bgmName = BM_DEFEATED_LV4_SLUTTY_BGM_NAME;
				bgmPan = BM_DEFEATED_LV4_SLUTTY_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV4_SLUTTY_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV4_SLUTTY_BGM_VOLUME;
			}
			else {
				bgmName = BM_DEFEATED_LV4_NORMAL_BGM_NAME;
				bgmPan = BM_DEFEATED_LV4_NORMAL_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV4_NORMAL_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV4_NORMAL_BGM_VOLUME;
			}
		}
		else if(Karryn.isInDefeatedLevel5Pose()) {
			if(useSluttyDefeatedVersion) {
				bgmName = BM_DEFEATED_LV5_SLUTTY_BGM_NAME;
				bgmPan = BM_DEFEATED_LV5_SLUTTY_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV5_SLUTTY_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV5_SLUTTY_BGM_VOLUME;
			}
			else {
				bgmName = BM_DEFEATED_LV5_NORMAL_BGM_NAME;
				bgmPan = BM_DEFEATED_LV5_NORMAL_BGM_PAN;
				bgmPitch = BM_DEFEATED_LV5_NORMAL_BGM_PITCH;
				bgmVolume = BM_DEFEATED_LV5_NORMAL_BGM_VOLUME;
			}
		}
		else if(Karryn.isInDefeatedGuardPose()) {
			if($gameSwitches.value(SWITCH_BITCH_ENDING_ID)) {
				bgmName = BM_DEFEATED_GUARD_BITCH_END_BGM_NAME;
				bgmPan = BM_DEFEATED_GUARD_BITCH_END_BGM_PAN;
				bgmPitch = BM_DEFEATED_GUARD_BITCH_END_BGM_PITCH;
				bgmVolume = BM_DEFEATED_GUARD_BITCH_END_BGM_VOLUME;
			}
			else if(useSluttyDefeatedVersion) {
				bgmName = BM_DEFEATED_GUARD_SLUTTY_BGM_NAME;
				bgmPan = BM_DEFEATED_GUARD_SLUTTY_BGM_PAN;
				bgmPitch = BM_DEFEATED_GUARD_SLUTTY_BGM_PITCH;
				bgmVolume = BM_DEFEATED_GUARD_SLUTTY_BGM_VOLUME;
			}
			else {
				bgmName = BM_DEFEATED_GUARD_NORMAL_BGM_NAME;
				bgmPan = BM_DEFEATED_GUARD_NORMAL_BGM_PAN;
				bgmPitch = BM_DEFEATED_GUARD_NORMAL_BGM_PITCH;
				bgmVolume = BM_DEFEATED_GUARD_NORMAL_BGM_VOLUME;
			}
		}
		else {
			bgmName = BM_ENEMY_SEX_BGM_NAME;
			bgmVolume = BM_ENEMY_SEX_BGM_VOLUME;
		}
	}
	else if($gameSwitches.value(SWITCH_INVASION_BATTLE_ID)) {
		bgmName = BM_INVASION_BATTLE_BGM_NAME;
		bgmPan = BM_INVASION_BATTLE_BGM_PAN;
		bgmPitch = BM_INVASION_BATTLE_BGM_PITCH;
		bgmVolume = BM_INVASION_BATTLE_BGM_VOLUME;
	}
	else if(Karryn.isInWaitressServingPose()) {
		bgmName = BM_WAITRESS_JOB_BGM_NAME;
		bgmPan = BM_WAITRESS_JOB_BGM_PAN;
		bgmPitch = BM_WAITRESS_JOB_BGM_PITCH;
		bgmVolume = BM_WAITRESS_JOB_BGM_VOLUME;
	}
	else if(Karryn.isInWaitressSexPose()) {
		bgmName = BM_WAITRESS_SEX_BGM_NAME;
		bgmPan = BM_WAITRESS_SEX_BGM_PAN;
		bgmPitch = BM_WAITRESS_SEX_BGM_PITCH;
		bgmVolume = BM_WAITRESS_SEX_BGM_VOLUME;
	}
	else if($gameParty.isInReceptionistBattle) {
		bgmName = BM_RECEPTIONIST_JOB_BGM_NAME;
		bgmPan = BM_RECEPTIONIST_JOB_BGM_PAN;
		bgmPitch = BM_RECEPTIONIST_JOB_BGM_PITCH;
		bgmVolume = BM_RECEPTIONIST_JOB_BGM_VOLUME;
	}
	else if($gameParty.isInGloryBattle) {
		if(Karryn.getReactionScore() >= VAR_DEF_RS_LV3_REQ) {
			bgmName = BM_GLORY_START_SLUTTY_BGM_NAME;
			bgmPan = BM_GLORY_START_SLUTTY_BGM_PAN;
			bgmPitch = BM_GLORY_START_SLUTTY_BGM_PITCH;
			bgmVolume = BM_GLORY_START_SLUTTY_BGM_VOLUME;
		}
		else {
			bgmName = BM_GLORY_START_NORMAL_BGM_NAME;
			bgmPan = BM_GLORY_START_NORMAL_BGM_PAN;
			bgmPitch = BM_GLORY_START_NORMAL_BGM_PITCH;
			bgmVolume = BM_GLORY_START_NORMAL_BGM_VOLUME;
		}
	}
	else if($gameParty.isInStripperBattle) {
		AudioManager.stopBgm();
		AudioManager.stopBgs();
		return;
	}
	else {
		let sluttyVersionBgm = Karryn.getMapReactionScore() >= VAR_DEF_RS_LV2_REQ;
		if(mapId === MAP_ID_KARRYN_OFFICE && $gameVariables.value(VARIABLE_PROLOGUE_PROGRESS_ID) === 5 && !$gameSwitches.value(SWITCH_PROLOGUE_ENDED)) {
			bgmName = BM_TUTORIAL_BGM_NAME;
			bgmVolume = BM_TUTORIAL_BGM_VOLUME;
		}
		else if(Prison.currentlyOutsidePrison()) {
			if(mapId === MAP_ID_EB_CONTROL && $gameParty._isBossBattleFlag) {
				bgmName = BM_FINAL_BOSS_BGM_NAME;
				bgmVolume = BM_FINAL_BOSS_BGM_VOLUME;
			}
			else if((mapId === MAP_ID_EB_HALLWAY || mapId === MAP_ID_YARD || mapId === MAP_ID_OUTSIDE) && $gameParty.isNightBattle()) {
				if(sluttyVersionBgm) {
					bgmName = BM_NIGHT_BATTLE_SLUTTY_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_SLUTTY_BGM_VOLUME;
				}
				else {
					bgmName = BM_NIGHT_BATTLE_NORMAL_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_NORMAL_BGM_VOLUME;
				}
			}
			else {
				bgmName = BM_EB_BGM_NAME;
				bgmVolume = BM_EB_BGM_VOLUME;
			}
		}
		else if(Prison.currentlyPrisonLevelOne()) {
			if(mapId === MAP_ID_RECEPTION && $gameParty._isBossBattleFlag) {
				bgmName = BM_PLVL1_BOSS_BGM_NAME;
				bgmVolume = BM_PLVL1_BOSS_BGM_VOLUME;
			}
			else if((mapId === MAP_ID_LVL1_HALLWAY || mapId === MAP_ID_VISITOR_ROOM || mapId === MAP_ID_VISITOR_ROOM_BROKEN) && $gameParty.isNightBattle()) {
				if(sluttyVersionBgm) {
					bgmName = BM_NIGHT_BATTLE_SLUTTY_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_SLUTTY_BGM_VOLUME;
				}
				else {
					bgmName = BM_NIGHT_BATTLE_NORMAL_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_NORMAL_BGM_VOLUME;
				}
			}
			else {
				bgmName = BM_PLVL1_NORMAL_BGM_NAME;
				bgmVolume = BM_PLVL1_NORMAL_BGM_VOLUME;
			}
		}
		else if(Prison.currentlyPrisonLevelTwo()) {
			if(mapId === MAP_ID_OFFICE_FLOODED && $gameParty._isBossBattleFlag) {
				bgmName = BM_PLVL2_BOSS_BGM_NAME;
				bgmVolume = BM_PLVL2_BOSS_BGM_VOLUME;
			}
			else if(mapId === MAP_ID_LVL2_HALLWAY && $gameParty.isNightBattle()) {
				if(sluttyVersionBgm) {
					bgmName = BM_NIGHT_BATTLE_SLUTTY_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_SLUTTY_BGM_VOLUME;
				}
				else {
					bgmName = BM_NIGHT_BATTLE_NORMAL_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_NORMAL_BGM_VOLUME;
				}
			}
			else {
				bgmName = BM_PLVL2_NORMAL_BGM_NAME;
				bgmVolume = BM_PLVL2_NORMAL_BGM_VOLUME;
			}
		}
		else if(Prison.currentlyPrisonLevelThree()) {
			if(mapId === MAP_ID_COMMON_AREA_NORTH_EAST) {
				if($gameTroop._troopId === 142 && $gameTroop._aronAppeared) {
					bgmName = BM_PLVL3_BOSS_ARON_BGM_NAME;
					bgmVolume = BM_PLVL3_BOSS_ARON_BGM_VOLUME;
				}
				else if($gameTroop._troopId === 141 || ($gameTroop._troopId === 142 && !$gameTroop._aronAppeared)){
					bgmName = BM_PLVL3_BOSS_START_BGM_NAME;
					bgmVolume = BM_PLVL3_BOSS_START_BGM_VOLUME;

				}
			}
			else if(mapId === MAP_ID_COMMON_AREA_SOUTH_EAST && $gameParty.isNightBattle()) {
				if(sluttyVersionBgm) {
					bgmName = BM_NIGHT_BATTLE_SLUTTY_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_SLUTTY_BGM_VOLUME;
				}
				else {
					bgmName = BM_NIGHT_BATTLE_NORMAL_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_NORMAL_BGM_VOLUME;
				}
			}
			else {
				bgmName = BM_PLVL3_NORMAL_BGM_NAME;
				bgmVolume = BM_PLVL3_NORMAL_BGM_VOLUME;
			}

		}
		else if(Prison.currentlyPrisonLevelFour()) {
			if(mapId === MAP_ID_LVL4_STAIRS_TO_LVL5 && $gameParty._isBossBattleFlag) {
				bgmName = BM_PLVL4_BOSS_BGM_NAME;
				bgmVolume = BM_PLVL4_BOSS_BGM_VOLUME;
			}
			else if($gameParty.isNightBattle()) {
				if(sluttyVersionBgm) {
					bgmName = BM_NIGHT_BATTLE_SLUTTY_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_SLUTTY_BGM_VOLUME;
				}
				else {
					bgmName = BM_NIGHT_BATTLE_NORMAL_BGM_NAME;
					bgmVolume = BM_NIGHT_BATTLE_NORMAL_BGM_VOLUME;
				}
			}
			else {
				bgmName = BM_PLVL4_NORMAL_BGM_NAME;
				bgmVolume = BM_PLVL4_NORMAL_BGM_VOLUME;
			}
		}
		else if(Prison.currentlyPrisonLevelFive()) {
			if($gameParty._isBossBattleFlag) {
				bgmName = BM_PLVL5_BOSS_BGM_NAME;
				bgmVolume = BM_PLVL5_BOSS_BGM_VOLUME;
			}
			else if(Prison.isCustomBattle()) {
				bgmName = BM_PLVL5_CUSTOM_BATTLE_BGM_NAME;
				bgmVolume = BM_PLVL5_CUSTOM_BATTLE_BGM_VOLUME;
			}
			else if(Prison.isEndlessBattle()) {
				bgmName = BM_PLVL5_ENDLESS_BATTLE_BGM_NAME;
				bgmVolume = BM_PLVL5_ENDLESS_BATTLE_BGM_VOLUME;
			}
		}
	}

	AudioManager.playBgm({name:bgmName, pan:bgmPan, pitch:bgmPitch, pos:0, volume:bgmVolume});
    AudioManager.stopBgs();
	Karryn.moanMasterManager();
};

BattleManager.playNormalBgm = function() {
    if(this._playingSpecialBgm) {
        AudioManager.replayBgm(this._normalBgm);
		AudioManager.stopBgs();
		this._playingSpecialBgm = false;
	}
	else if(this._playingDownBgmChange) {
		let updateBgm = AudioManager.saveBgm();
		updateBgm.pitch = updateBgm.pitch - BM_DOWN_STAMINA_BGM_PITCH_CHANGE;
		updateBgm.volume = updateBgm.volume - BM_DOWN_STAMINA_BGM_VOLUME_CHANGE;
		AudioManager.playBgm(updateBgm, updateBgm.pos);
		this._playingDownBgmChange = false;
	}
};

//unused
BattleManager.playDownStaminaBgmChange = function() {
    if(!this._playingSpecialBgm && !this._playingDownBgmChange) {
        let updateBgm = AudioManager.saveBgm();
		updateBgm.pitch = updateBgm.pitch + BM_DOWN_STAMINA_BGM_PITCH_CHANGE;
		updateBgm.volume = updateBgm.volume + BM_DOWN_STAMINA_BGM_VOLUME_CHANGE;
		AudioManager.playBgm(updateBgm, updateBgm.pos);

		this._playingDownBgmChange = true;
	}
};

BattleManager.playSpecialBgm_EnemySex = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._normalBgm.pitch = this._normalBgm.pitch - BM_DOWN_STAMINA_BGM_PITCH_CHANGE;
			this._normalBgm.volume = this._normalBgm.volume - BM_DOWN_STAMINA_BGM_VOLUME_CHANGE;
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_ENEMY_SEX_BGM_NAME, pan:BM_ENEMY_SEX_BGM_PAN, pitch:BM_ENEMY_SEX_BGM_PITCH, pos:0, volume: BM_ENEMY_SEX_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playSpecialBgm_KarrynSex = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._normalBgm.pitch = this._normalBgm.pitch - BM_DOWN_STAMINA_BGM_PITCH_CHANGE;
			this._normalBgm.volume = this._normalBgm.volume - BM_DOWN_STAMINA_BGM_VOLUME_CHANGE;
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_KARRYN_SEX_BGM_NAME, pan:BM_KARRYN_SEX_BGM_PAN, pitch:BM_KARRYN_SEX_BGM_PITCH, pos:0, volume: BM_KARRYN_SEX_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playSpecialBgm_DownStamina = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._normalBgm.pitch = this._normalBgm.pitch - BM_DOWN_STAMINA_BGM_PITCH_CHANGE;
			this._normalBgm.volume = this._normalBgm.volume - BM_DOWN_STAMINA_BGM_VOLUME_CHANGE;
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_DOWN_STAMINA_BGM_NAME, pan:BM_DOWN_STAMINA_BGM_PAN, pitch:BM_DOWN_STAMINA_BGM_PITCH, pos:0, volume: BM_DOWN_STAMINA_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playSpecialBgm_DownOther = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._normalBgm.pitch = this._normalBgm.pitch - BM_DOWN_STAMINA_BGM_PITCH_CHANGE;
			this._normalBgm.volume = this._normalBgm.volume - BM_DOWN_STAMINA_BGM_VOLUME_CHANGE;
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_DOWN_OTHER_BGM_NAME, pan:BM_DOWN_OTHER_BGM_PAN, pitch:BM_DOWN_OTHER_BGM_PITCH, pos:0, volume: BM_DOWN_OTHER_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playSpecialBgm_WaitressSex = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_WAITRESS_SEX_BGM_NAME, pan:BM_WAITRESS_SEX_BGM_PAN, pitch:BM_WAITRESS_SEX_BGM_PITCH, pos:0, volume: BM_WAITRESS_SEX_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playSpecialBgm_ReceptionistSex = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_RECEPTIONIST_SEX_BGM_NAME, pan:BM_RECEPTIONIST_SEX_BGM_PAN, pitch:BM_RECEPTIONIST_SEX_BGM_PITCH, pos:0, volume: BM_RECEPTIONIST_SEX_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playSpecialBgm_GlorySex = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_GLORY_SEX_BGM_NAME, pan:BM_GLORY_SEX_BGM_PAN, pitch:BM_GLORY_SEX_BGM_PITCH, pos:0, volume: BM_GLORY_SEX_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playSpecialBgm_StripperShow = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_STRIPPER_SHOW_BGM_NAME, pan:BM_STRIPPER_SHOW_BGM_PAN, pitch:BM_STRIPPER_SHOW_BGM_PITCH, pos:0, volume: BM_STRIPPER_SHOW_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};
BattleManager.playSpecialBgm_StripperSex = function() {
	if(!this._playingSpecialBgm) {
		this._normalBgm = AudioManager.saveBgm();
		if(this._playingDownBgmChange) {
			this._playingDownBgmChange = false;
		}
	}
    AudioManager.playBgm({name:BM_STRIPPER_SEX_BGM_NAME, pan:BM_STRIPPER_SEX_BGM_PAN, pitch:BM_STRIPPER_SEX_BGM_PITCH, pos:0, volume: BM_STRIPPER_SEX_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = true;
};

BattleManager.playBossBgm_AronAppears = function() {
    AudioManager.playBgm({name:BM_PLVL3_BOSS_ARON_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL3_BOSS_ARON_BGM_VOLUME});
	AudioManager.stopBgs();
};

BattleManager.playEndlessBgm_Wave6to9 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_6_TO_9_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_6_TO_9_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave11to14 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_11_TO_14_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_11_TO_14_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave16to19 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_16_TO_19_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_16_TO_19_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave21to24 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_21_TO_24_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_21_TO_24_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave26to29 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_26_TO_29_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_26_TO_29_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave31to34 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_31_TO_34_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_31_TO_34_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave36to39 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_36_TO_39_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_36_TO_39_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave41to44 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_41_TO_44_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_41_TO_44_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave46to49 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_46_TO_49_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_46_TO_49_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave5to25_mod5 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_5_TO_25_MOD5_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_5_TO_25_MOD5_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave30to45_mod5 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_30_TO_45_MOD5_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_30_TO_45_MOD5_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};
BattleManager.playEndlessBgm_Wave50 = function() {
    AudioManager.playBgm({name:BM_PLVL5_ENDLESS_WAVE_50_BGM_NAME, pan:0, pitch:100, pos:0, volume: BM_PLVL5_ENDLESS_WAVE_50_BGM_VOLUME});
	AudioManager.stopBgs();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
};

BattleManager.playVictoryMe = function() {
    AudioManager.playMe($gameSystem.victoryMe());
	this.replayBgmAndBgs();
};

///////////
// Pull Out Enemy
/////////////////

BattleManager.pullOutAllEnemies = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	actor.setAllowTachieUpdate(false);
	//every alive & dead enemy call pullout
	let enemies = $gameTroop.aliveMembers();
	for (let i = 0; i < enemies.length; ++i) {
		this.pullOutEnemy(enemies[i]);
    }
	enemies = $gameTroop.deadMembers();
	for (let i = 0; i < enemies.length; ++i) {
		this.pullOutEnemy(enemies[i]);
    }

	actor.setPostSexPose();
	actor.setAllowTachieUpdate(true);
	actor.setAllowTachieEmoteUpdate(true);
};

BattleManager.pullOutEnemy = function(enemy) {
	if(!enemy || !enemy.isInAPose()) return;
	let actor = enemy.getPoseSkillTarget();

	//Karryn first needs to uninsert ungrope untoy everything the enemy is doing
	//actor.setAllowTachieUpdate(false);

	this.removeEnemyPettedStatus(enemy, actor);
	this.removeEnemyToyStatus(enemy, actor);
	this.removeEnemyPenisStatus(enemy, actor);

	//enemy's using body slot needs to be reset
	enemy.resetUsingBodySlot();
	//set enemy pose status to none
	enemy.resetPoseStatus();
	//reset all self sex targets
	enemy.resetAllTargetsForSex();
	//reset custom enemy sprite
	enemy.setCustomEnemySprite(false);
	//remove all sex pose states
	enemy.removeAllSexPoseStates();
	//reset orgasm skills
	enemy.resetOrgasmSkills();
	//reset can be kissed
	enemy.setCanBeKissed(true);

	//actor.setAllowTachieUpdate(true);

	actor.moanMasterManager();
};

BattleManager.removeEnemyPettedStatus = function(enemy, actor) {
	if(enemy.isUsingBodySlotAnus(MOUTH_ID)) {
		actor.setMouthRimming(false);
		actor.disableRimjobPoseSkills();
	}
	if(enemy.isUsingBodySlotPenis(CLIT_ID)) {
		actor.setPussyCunni(false);
	}
	actor.setKissedChange(false, this);
};
BattleManager.removeEnemyToyStatus = function(enemy, actor) {

};
BattleManager.removeEnemyPenisStatus = function(enemy, actor) {
	if(enemy.isUsingBodySlotPenis(MOUTH_ID)) {
		actor.disableBlowjobPoseSkills();
		actor.setMouthInserted(false);
		actor._tempBlowjobConsUsage = 0;
		actor._tempRimjobConsUsage = 0;
	}
	if(enemy.isUsingBodySlotPenis(RIGHT_HAND_ID)) {
		actor.disableRightHandjobPoseSkills();
		actor.setRightHandInserted(false);
		if(!actor.isBodySlotInserted(LEFT_HAND_ID)) actor._tempHandjobConsUsage = 0;
	}
	if(enemy.isUsingBodySlotPenis(LEFT_HAND_ID)) {
		actor.disableLeftHandjobPoseSkills();
		actor.setLeftHandInserted(false);
		if(!actor.isBodySlotInserted(RIGHT_HAND_ID)) actor._tempHandjobConsUsage = 0;
	}
	if(enemy.isUsingBodySlotPenis(BOOBS_ID)) {
		actor.disableTittyFuckPoseSkills();
		actor.setBoobsInserted(false);
		actor._tempTitjobConsUsage = 0;
	}
	if(enemy.isUsingBodySlotPenis(PUSSY_ID)) {
		actor.disablePussySexPoseSkills();
		actor.setPussyInserted(false);
		actor._tempPussySexConsUsage = 0;
	}
	if(enemy.isUsingBodySlotPenis(ANAL_ID)) {
		actor.disableAnalSexPoseSkills();
		actor.setAnalInserted(false);
		actor._tempAnalSexConsUsage = 0;
	}
	if(enemy.isUsingBodySlotPenis(FEET_ID)) {
		actor.disableFootjobPoseSkills();
		actor.setFeetInserted(false);
		actor._tempFootjobConsUsage = 0;
	}

	if(enemy.isUsingBodySlotPenis(OTHER_1_ID)) {
		actor.setOther1Inserted(false);
	}
	if(enemy.isUsingBodySlotPenis(OTHER_2_ID)) {
		actor.setOther2Inserted(false);
	}
	if(enemy.isUsingBodySlotPenis(OTHER_3_ID)) {
		actor.setOther3Inserted(false);
	}
	if(enemy.isUsingBodySlotPenis(OTHER_4_ID)) {
		actor.setOther4Inserted(false);
	}
};

/////////
// Upgrade Pose
///////////

BattleManager.upgradingPoseReinsertBody = function(actor) {
	$gameTroop.aliveMembers().forEach(function(enemy) {
		if(enemy.isPoseHelper()) {
			BattleManager.reinsertEnemyPenisStatus(enemy, actor);
			BattleManager.reinsertEnemyPettedStatus(enemy, actor);
		}
	});
}

BattleManager.reinsertEnemyPenisStatus = function(enemy, actor) {
	if(enemy.isUsingBodySlotPenis(MOUTH_ID)) {
		actor.setMouthInserted(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(RIGHT_HAND_ID)) {
		if(actor.isBodySlotUnavailable(RIGHT_HAND_ID)) {
			actor.setRightHandInserted(false);
			actor.setBodyPartUnavailable(RIGHT_HAND_ID);
			actor.disableRightHandjobPoseSkills();
			enemy.removeState(STATE_RIGHTHAND_ENEMYPOSE_ID);
			enemy.setBodySlotFree(RIGHT_HAND_ID);
			enemy._targetForHandjob = false;
			enemy.resetPoseStatus();

			if(actor.isBodySlotAvailableForPenis(LEFT_HAND_ID)) {
				enemy.beforeEval_join_generic_lefthand(actor, true);
				enemy.removeState(STATE_JUST_JOINED_ID);
			}
		}
		else {
			actor.setRightHandInserted(true, enemy);
		}
	}
	if(enemy.isUsingBodySlotPenis(LEFT_HAND_ID)) {
		if(actor.isBodySlotUnavailable(LEFT_HAND_ID)) {
			actor.setLeftHandInserted(false);
			actor.setBodyPartUnavailable(LEFT_HAND_ID);
			actor.disableLeftHandjobPoseSkills();
			enemy.removeState(STATE_LEFTHAND_ENEMYPOSE_ID);
			enemy.setBodySlotFree(LEFT_HAND_ID);
			enemy._targetForHandjob = false;
			enemy.resetPoseStatus();

			if(actor.isBodySlotAvailableForPenis(RIGHT_HAND_ID)) {
				enemy.beforeEval_join_generic_righthand(actor, true);
				enemy.removeState(STATE_JUST_JOINED_ID);
			}
		}
		else {
			actor.setLeftHandInserted(true, enemy);
		}
	}
	if(enemy.isUsingBodySlotPenis(BOOBS_ID)) {
		actor.setBoobsInserted(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(PUSSY_ID)) {
		actor.setPussyInserted(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(ANAL_ID)) {
		actor.setAnalInserted(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(FEET_ID)) {
		actor.setFeetInserted(true, enemy);
	}

	if(enemy.isUsingBodySlotPenis(OTHER_1_ID)) {
		actor.setOther1Inserted(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(OTHER_2_ID)) {
		actor.setOther2Inserted(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(OTHER_3_ID)) {
		actor.setOther3Inserted(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(OTHER_4_ID)) {
		actor.setOther4Inserted(true, enemy);
	}
};
BattleManager.reinsertEnemyPettedStatus = function(enemy, actor) {
	if(enemy.isUsingBodySlotAnus(MOUTH_ID)) {
		actor.setMouthRimming(true, enemy);
	}
	if(enemy.isUsingBodySlotPenis(CLIT_ID)) {
		actor.setPussyCunni(true, enemy);
	}
	actor.setKissedChange(false, enemy);
};

/////////
// Swap Master
////////////

BattleManager.swappedPoseMaster = function(leavingMaster) {
	let poseMasterSkillID = leavingMaster.getPoseMasterSkillID();

	if(poseMasterSkillID === SKILL_ENEMY_POSESTART_STANDINGHJ_ID || poseMasterSkillID === SKILL_ENEMY_POSESTART_FOOTJOB_ID || poseMasterSkillID === SKILL_ENEMY_POSESTART_SLIMEPILEDRIVER_ID)
		return false;

	let target = $gameActors.actor(ACTOR_KARRYN_ID);
	let eligibleMasters = this.eligibleEnemyReplacementMasters(leavingMaster);
	let success = false;

	if(eligibleMasters.length > 0) {
		let ran = Math.randomInt(eligibleMasters.length);
		let newMaster = eligibleMasters[ran];
		target._dontResetSexPose = true;
		this.pullOutEnemy(leavingMaster);
		this.pullOutEnemy(newMaster);
		newMaster.useAISkill(poseMasterSkillID, target);
		newMaster.setUsedSkillThisTurn(true);
		success = true;
	}

	return success
};

BattleManager.eligibleEnemyReplacementMasters  = function(leavingMaster) {
	let poseMasterSkillID = leavingMaster.getPoseMasterSkillID();
	let target = $gameActors.actor(ACTOR_KARRYN_ID);
	let enemies = $gameTroop.aliveMembers();
	let eligibleMasters = [];
	for (let i = 0; i < enemies.length; ++i) {
		let enemy = enemies[i];

		if(poseMasterSkillID === SKILL_ENEMY_POSESTART_KICKCOUNTER_ID || poseMasterSkillID === SKILL_ENEMY_POSESTART_KICKCOUNTER_YETI_ID) {
			let counterSkillsArray = enemy.counterSkills();
			if(!enemy.usedSkillThisTurn() && enemy.isErect && counterSkillsArray && counterSkillsArray.includes(poseMasterSkillID)) {
				eligibleMasters.push(enemy);
			}
		}
		else {
			if(!enemy.usedSkillThisTurn() && enemy._aiPoseStartSkills && enemy.isErect
			&& enemy._aiPoseStartSkills.includes(poseMasterSkillID)) {
				eligibleMasters.push(enemy);
			}
		}
    }
	return eligibleMasters;
};

/////////////
// End of All Turns
/////////////////

BattleManager.updateTurn = function() {
    $gameParty.requestMotionRefresh();
    if (!this._subject) {
        this._subject = this.getNextSubject();
    }
	if (!this._subject) {
       //this.preEndTurnManagement();
    }
    if (this._subject) {
        this.processTurn();
    } else {
		//this.setBMAllowTachieUpdate(true);
		this.preEndTurnManagement();
        this.endTurn();
		this.refreshAllBattlerPoses(false);
    }
};

Remtairy.BM.BattleManager_invokeAction = BattleManager.invokeAction;
BattleManager.invokeAction = function(subject, target) {
	Remtairy.BM.BattleManager_invokeAction.call(this, subject, target);

	if(target.isActor()) {
		subject.checkForOrgasm();
		target.checkForOrgasm();
	}
	else {
		if($gameParty.isInGloryBattle) { }
		else {
			target.checkForOrgasm();
			subject.checkForOrgasm();
		}
	}
};

// End of Turn Functions
BattleManager.preEndTurnManagement = function() {
	this.checkForEnemyReinforcements();

	//this.checkForEnemiesOrgasm();
	//this.checkForPartyOrgasm();
	//this.refreshAllBattlerPoses();
};

//Enemy Reinforcement
BattleManager.checkForEnemyReinforcements = function() {
	$gameTroop.noinimReinforcementCheck();
};

//Enemies
//Unused
BattleManager.checkForEnemiesOrgasm = function() {
	let group = $gameTroop.aliveMembers();
	for(let i = 0; i < group.length; i++) {
		let enemy = group[i];
		if(!enemy) continue;
		if(enemy.reachedOrgasmPoint()) {
			this.setBMAllowTachieUpdate(false);
			enemy.orgasm();
		}
	}
};

//Party
//Unused
BattleManager.checkForPartyOrgasm = function() {
	var group = $gameParty.members();
	for(var i = 0; i < group.length; i++) {
		var actor = group[i];
		if(!actor) { continue; }
		if(actor.reachedOrgasmPoint()) {
			this.setBMAllowTachieUpdate(false);
			actor.orgasm();
		}
	}
};

BattleManager.removeImmortalStateFromEveryone = function() {
	let group = $gameTroop.aliveMembers();
	for(let i = 0; i < group.length; i++) {
		group[i].removeImmortal();
	}
	group = $gameParty.aliveMembers();
	for(let i = 0; i < group.length; i++) {
		group[i].removeImmortal();
	}
};
/*
BattleManager.checkCounterEval = function(code, skill, subject, target) {
    let action = this._action;
    let a = subject;
    let user = subject;
    let attacker = subject;
    let b = target;
    let defender = target;
    let item = skill;
    let s = $gameSwitches._data;
    let v = $gameVariables._data;
    let code = code;

	if(skill.id === SKILL_MINION_THROW_ATTACK_ID) {
		attacker = subject._minionThrow_ammoTarget;
	}

    try {
      return eval(code);
    } catch (e) {
      Yanfly.Util.displayError(e, code, 'COUNTER CHECK ERROR');
      return false;
    }
};*/

/////////
// End Of Every Action
////////////

Remtairy.BM.BattleManager_endAction = BattleManager.endAction;
BattleManager.endAction = function() {
    Remtairy.BM.BattleManager_endAction.call(this);
	this.refreshAllBattlerPoses(false);
	//this.resetAllSpriteBattlerPos();
};

BattleManager.refreshAllBattlerPoses = function(onlyChangeIfDifferent) {
	for(var i = 0; i < $gameParty.members().length; i++) {
		if(!$gameParty.members()[i]) { continue; }
		$gameParty.members()[i].refreshPose(onlyChangeIfDifferent);
	}
};

//unused
BattleManager.resetAllSpriteBattlerPos = function() {
	for(var i = 0; i < $gameParty.members().length; i++) {
		if(!$gameParty.members()[i]) { continue; }
		$gameParty.members()[i].resetSpriteBattlerPos();
	}
};

////////
// Battle Start
////////////

// Display Start Messages
Remtairy.BM.BattleManager_displayStartMessages = BattleManager.displayStartMessages;
BattleManager.displayStartMessages = function() {
	Remtairy.BM.BattleManager_displayStartMessages.call(this);

	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	if(actor._startOfInvasionBattle) {
		BattleManager._logWindow.push('addText', TextManager.invasionBattleStart);
		BattleManager.actionRemLines(KARRYN_LINE_INVASION_BATTLE_START);
		actor._startOfInvasionBattle = false;
	}

};

//////////
///////////////
// Game Action
/////////////////
///////////

Game_Action.prototype.isActorAttackSkill = function() {
    if(this.isSkill()) {
        return this.item().hasTag(TAG_ACTOR_ATTACK_SKILL);
    }
	else {
        return false;
    }
};

Game_Action.prototype.isActorSexSkill = function() {
    if(this.isSkill()) {
        return this.item().hasTag(TAG_ACTOR_SEX_SKILL);
    }
	else {
        return false;
    }
};

Game_Action.prototype.isActorKickSkill = function() {
    if(this.isSkill()) {
        return this.item().hasTag(TAG_KICK_SKILL);
    }
	else {
        return false;
    }
};

Game_Action.prototype.isActorCombatStanceSkill = function() {
    if(this.isSkill()) {
        let skillId = this._item._itemId;

		//for testing empty attack skillIds
		//console.log(skillId);

		return skillId === SKILL_CAUTIOUS_STANCE_ID || skillId === SKILL_DEFENSIVE_STANCE_ID || skillId === SKILL_COUNTER_STANCE_ID || (skillId >= SKILL_CAUTIOUS_REVITALIZE_ID && skillId <= SKILL_COUNTER_FIX_CLOTHES_ID);
    }
	else {
        return false;
    }
};

Game_Action.prototype.isActorSexStanceSkill = function() {
    if(this.isSkill()) {
        let skillId = this._item._itemId;
		return skillId === SKILL_ENDURE_PLEASURE_ID || skillId === SKILL_WAIT_OUT_PLEASURE_ID || skillId === SKILL_OPEN_PLEASURE_ID;

    }
	else {
        return false;
    }
};

Game_Action.prototype.isActorWillpowerSkill = function() {
    if(this.isSkill()) {
        let skillId = this._item._itemId;
		return (skillId >= WILLPOWER_SKILL_START && skillId <= WILLPOWER_SKILL_END);
    }
	else {
        return false;
    }
};

Game_Action.prototype.isActorDontMasturbateInBattleSkill = function() {
    if(this.isSkill()) {
        let skillId = this._item._itemId;
		return skillId === SKILL_KARRYN_DONT_MASTURBATE_ID;
    }
	else {
        return false;
    }
};

Game_Action.prototype.isEnemyAttackSkill = function() {
    if(this.isSkill()) {
        return this.item().hasTag(TAG_ENEMY_ATTACK_SKILL);
    } else {
        return false;
    }
};

Game_Action.prototype.isEndMentalPhaseSkill = function() {
    if (this.isSkill()) {
        let skillId = this._item._itemId;
		return skillId === SKILL_END_MENTAL_PHASE_ID;
    } else {
        return false;
    }
};

Game_Action.prototype.targetsForOpponents = function() {
    let targets = [];
    let unit = this.opponentsUnit();

    if(this.isForRandom()) {
        for (let i = 0; i < this.numTargets(); i++) {
            targets.push(unit.randomTarget());
        }
    } else if (this.isForOne()) {
        if(this._targetIndex < 0) {
            targets.push(unit.randomTarget());
        }
		else if(this.isActorSexSkill()) {
			targets.push(unit.members()[this._targetIndex]);
		}
		else {
            targets.push(unit.smoothTarget(this._targetIndex));
        }
    } else {
        targets = unit.aliveMembers();
    }
    return targets;
};

Game_Action.prototype.executeMpDamage = function(target, value) {
	let isFemaleOrgasmSkill = this.item().hasTag(TAG_FEMALE_ORGASM_SKILL);
    if(!this.isMpRecover()) {
        value = Math.min(target.mp, value);
    }
    if(value !== 0 || isFemaleOrgasmSkill) {
        this.makeSuccess(target);
    }
    target.gainMp(-value);
    this.gainDrainedMp(value);

	if(target.energy <= 0 && isFemaleOrgasmSkill) {
		target.passivePostOrgasmRevivalEffect();
	}
};

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

Game_Actor.prototype.clearBattleSkillsFlags = function() {
	this.resetEnergyCosts();
	this.resetWillpowerCosts();
	this.resetAttackSkillConsUsage();
	this.resetSexSkillConsUsage();
	this._isCurrentlyUsingSkewer = false;
	this._usedEscapeCommand = false;
};

Remtairy.BM.Game_Actor_performAction = Game_Actor.prototype.performAction;
Game_Actor.prototype.performAction = function(action) {
	Remtairy.BM.Game_Actor_performAction.call(this, action);

};

///////////////////
//////////////////////
// Battle Results
///////////////////////
/////////////////////

BattleManager.initVictoryData = function() {
    this._victoryPhase = false;
	this._victoryType = -1;
    this._victoryCheerWait = 0;
    this._victoryStep = 0;
};

BattleManager.onStartOfConBat = function() {
	var group = $gameParty.members();
	for(var i = 0; i < group.length; i++) {
		var actor = group[i];
		if(!actor) { continue; }
		actor.onStartOfConBat();
	}
};

BattleManager.displayEscapeSuccessMessage = function() {
	return;
};

BattleManager.processVictory = function() {
	if(this.isConsBattle()) {
		$gameSwitches.setValue(SWITCH_HIDE_STATE_ICONS_ID, true);
	    this.prepareConBat();
		this.onStartOfConBat();
		return;
	}

	this.getDataRewardsCB();

    $gameParty.performVictory();
    if (this.isVictoryPhase()) return;
    if (this._windowLayer) this._windowLayer.x = 0;
    $gameParty.removeBattleStates();
    this._victoryPhase = true;
	this._victoryType = 0;
    if(!$gameSystem.skipVictoryAftermath()) {
		if(!$gameSystem.skipVictoryMusic())
			this.playVictoryMe();
		//$gameParty.gainOrderFromVictory();
		Karryn.commitUncommittedCharmExp();
		this.processNormalVictory();
    }
};

BattleManager.processNormalVictory = function() {
	if($gameParty.isNightBattle() && !$gameParty._nightBattleVariableCounted) {
		$gameParty._nightBattleVariableCounted = true;
		$gameParty.addNightBattleCompletedRecord();
	}
    this.makeRewards();
	this.makeExpResults();
	//$gameParty.calculateParamLvlsGained();
	//$gameParty.calculateMainLvlsGained();
	$gameParty.applyEndOfBattleSpecial();
	$gameParty.applyFatigueResults();
	$gameParty.applyOrderResults();
	$gameParty.checkForNewPassives();
    this.startVictoryPhase();
};

BattleManager.makeRewards = function() {
    this._rewards = {};
    this._rewards.exp = $gameTroop.expTotal();
    this._rewards.items = $gameTroop.makeDropItems();

	//Gold stuff
	this._rewards.gold = 0;
	//Gold bounty
	if($gameParty._fullGoldRewardsFlag) {
		this._rewards.gold = $gameTroop.goldTotal();
	}
	//Half gold
	if($gameParty._halfGoldRewardsFlag)
		this._rewards.gold = $gameTroop.goldTotal() * 0.5;
	//Extra gold
	if($gameParty._extraGoldReward > 0)
		this._rewards.gold += $gameParty._extraGoldReward;
	if(this._rewards.gold > 0)
		this._rewards.gold += Math.random() * this._rewards.gold * 0.1;
	this._rewards.gold = Math.round(this._rewards.gold);
};

BattleManager.makeExpResults = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	//let total = this._rewards.exp;
	//total += Math.round(actor._totalParamExpGained);
	//this._rewards.exp = total;
	this._rewards.exp = 0;
};

///////////
// check Battle End
/////////////////

BattleManager.checkBattleEnd = function() {
	if (this._phase === 'actionList') return false;
    if (this._phase === 'actionTargetList') return false;
    if (this._phase === 'action') return false;
    if (this._phase === 'phaseChange') return false;
    if ($gameTroop.isEventRunning()) return false;

    if(this._phase) {
		if(Karryn.isInJobPose()) {
			return this.checkBattleEndJobs();
		}

		if(Karryn.isInDefeatedPose() && (!ConfigManager.shorterDefeatBattles || Prison.hardMode())) {
			if($gameTroop.isAllDead()) {
				if(Karryn.hasNoStamina() && Karryn.hasNoEnergy()) {
					this.processDefeat();
					return true;
				}
				this.processVictory();
				return true;
			}
			return false;
		}

        if (this.checkAbort()) {
            return true;
        }
		else if ($gameParty.isAllDead()) {
            this.processDefeat();
            return true;
        } else if ($gameTroop.isAllDead()) {
            this.processVictory();
            return true;
        }
    }
    return false;
};

BattleManager.checkBattleEndJobs = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
	if(Karryn.isInWaitressServingPose()) {
		if($gameParty.waitressBattle_getCurrentTimeInSeconds() >= $gameParty._waitressBattle_timeLimit) {
			this.processVictory();
            return true;
		}
		else if($gameParty.waitressBattle_thereAreNoMoreMugsOrGlasses()) {
            this.processDefeat();
            return true;
		}
		else if($gameParty.isAllDead()) {
            this.processDefeat();
            return true;
		}
	}
	else if(Karryn.isInWaitressSexPose()) {
		if($gameParty.isAllDead()) {
            this.processDefeat();
            return true;
        }
		else if($gameTroop.isAllOutOfEjaculationStock()) {
			if(actor._karrynMugContent === ALCOHOL_TYPE_SEMEN && actor._karrynMugAmount > 0)
				return false
			else {
				this.processVictory();
				return true;
			}
        }
	}
	else if($gameParty.isInReceptionistBattle) {
		if($gameParty.receptionistBattle_getCurrentTimeInSeconds() >= $gameParty._receptionistBattle_timeLimit) {
			this.processVictory();
            return true;
		}
		else if($gameParty.isAllDead()) {
            this.processDefeat();
            return true;
		}
	}
	else if($gameParty.isInGloryBattle) {
		if($gameParty.isAllDead() || actor._gloryBattle_badExit) {
            this.processDefeat();
            return true;
        }
		else if(actor._gloryBattle_safeExit) {
			this.processVictory();
				return true;
		}
	}
	else if($gameParty.isInStripperBattle) {
		if(Karryn.isInStripperSexPose()) {
			if($gameTroop.isAllDead()) {
				if(Karryn.hasNoStamina() && Karryn.hasNoEnergy()) {
					this.processDefeat();
					return true;
				}
				this.processVictory();
				return true;
			}
			else if($gameParty.isAllDead()) {
				this.processDefeat();
				return true;
			}
		}

		else if($gameTroop._stripClub_timesUp) {
			BattleManager.processVictory();
			return true;
		}
		else if($gameTroop.stripperBattle_noMorePatrons()) {
			this.processVictory();
            return true;
		}
		else if($gameParty.isAllDead()) {
            this.processDefeat();
            return true;
		}
	}

	return false;
};

//////////
// Process Victory Finish
// Process Abort
// Process Defeat
/////////////

BattleManager.processVictoryFinish = function() {
    $gameParty.clearVictoryData();
    this.endBattle(this._victoryType);
	//AudioManager.stopBgm();
	AudioManager.stopVoice();
	AudioManager.stopMoan();
	this._playingSpecialBgm = false;
	this._playingDownBgmChange = false;
    this.replayBgmAndBgs();
	this._victoryType = -1;
    this._victoryPhase = false;
};

BattleManager.processAbort = function() {
	let actor = $gameActors.actor(ACTOR_KARRYN_ID);
    $gameParty.removeBattleStates();
	$gameParty.addRecordEscaped();
	if(!Prison.easyMode()) $gameParty.increaseFatigueGain(PRISON_FATIGUE_FROM_ESCAPING);
	actor.reduceCockinessFromEscaping();
	actor.turnOnJustEscapedFlag();
	this._phase = 'rem abort';
	this._victoryPhase = true;
	this._victoryType = 1;
    if(!$gameSystem.skipVictoryAftermath()) {
		this.processNormalVictory();
    }
};

BattleManager.processDefeat = function() {
	if($gameSwitches.value(SWITCH_BITCH_ENDING_ID)) {

	}
	else if(!Karryn.isInMasturbationCouchPose() && !$gameParty.isInGloryBattle) {
		$gameParty.addRecordDefeated();
		$gameParty.setDefeatedSwitchesOn();
		//$gameParty._halfGoldRewardsFlag = true;
		this.playDefeatMe();
	}
	else if($gameParty.isInGloryBattle) {
		$gameParty.setDefeatedSwitchesOn();
	}
	if($gameParty.isNightBattle() && !$gameParty._nightBattleVariableCounted) {
		$gameParty._nightBattleVariableCounted = true;
		$gameParty.addNightBattleCompletedRecord();
	}
	this._phase = 'rem defeat';
	this._victoryPhase = true;
	this._victoryType = 2;
    if(!$gameSystem.skipVictoryAftermath()) {
		//$gameParty.gainOrderFromDefeat();
		Karryn.commitUncommittedCharmExp();
		this.processNormalVictory();
    }
};

//////////
// Game Interpreter
//////////////

Game_Interpreter.prototype.command339 = function() {
    this.iterateBattler(this._params[0], this._params[1], function(battler) {
        if (!battler.isDeathStateAffected() || battler.isInNeverDeadPose()) {
            battler.forceAction(this._params[2], this._params[3]);
            BattleManager.forceAction(battler);
            this.setWaitMode('action');
        }
    }.bind(this));
    return true;
};

Game_Interpreter.prototype.changeHp = function(target, value, allowDeath) {
    if(target.isAlive()) {
        if(!allowDeath && target.hp <= -value) {
            value = 1 - target.hp;
        }
        target.gainHp(value);
        if(target.isDead()) {
			target._enemyTempRecordSubduedWithEventCommand = true;
            target.performCollapse();
        }
    }
};

license: unknown


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

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

Game_Actor.prototype.getBattlePoseOffetArray = function () {
	let poseName = this.poseName;
	let offsetArray = [ 0, 0 ];
	let x_offset = 0;
	let y_offset = 0;
	//ここから

	if(poseName == POSE_KICK) {
        x_offset = 100;
        y_offset = 0;
    }
	else if(poseName == POSE_MAP && $gameParty.isInWaitressBattle) {
		x_offset = 230;
        y_offset = 0;

	}

	//ここまで
	offsetArray[0] = x_offset;
	offsetArray[1] = y_offset;
	return offsetArray;
};


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

const VAR_NO_ENERGY_STAMINA_DAMAGE = 0.3;
const VAR_AP_PER_END = 10;
const VAR_OP_PER_END = 30;
const VAR_AP_PER_CLVL = 5;
const VAR_OP_PER_CLVL = 15;

const VAR_STANCE_STRONG_HIT = 0.15;
const VAR_STANCE_WEAK_HIT = -0.1;
const VAR_STANCE_STRONG_DMG = 1.25;
const VAR_STANCE_WEAK_DMG = 0.85;

const VAR_CRITICAL_DAMAGE_MIN = 1.05;
const VAR_CRITICAL_DAMAGE_BASE = 1.33;

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

var STANCE_NONE = 1;
var STANCE_SLASH = 2;
var STANCE_PIERCE = 3;
var STANCE_BLUNT = 4;
var STANCE_RANDOM = 5;

///////
//////////////////
// Game Battlerbase
///////////////////
//////////////

Remtairy.Battler.Game_BattlerBase_initMembers = Game_BattlerBase.prototype.initMembers;
Game_BattlerBase.prototype.initMembers = function() {
	Remtairy.Battler.Game_BattlerBase_initMembers.call(this);
	this._fatigue = 0;
    this._will = 0;
	this._stench = 0;
	this._didNothing = false;
	this._didNothingCount = 1;
	this._arousalBasePoint = 0;
	this._orgasmBasePoint = 0;
	this._baseTalkLvl = 0;
	this._baseSightLvl = 0;
	this._basePettingLvl = 0;
	this._baseToyLvl = 0;
	this._baseSemenLvl = 0;
	this._baseStripLvl = 0;
	this._baseKissLvl = 0;
	this._baseHandjobLvl = 0;
	this._baseBlowjobLvl = 0;
	this._baseFootjobLvl = 0;
	this._baseRimjobLvl = 0;
	this._baseTittyFuckLvl = 0;
	this._basePussySexLvl = 0;
	this._baseAnalSexLvl = 0;
	this._baseMasturbateLvl = 0;
	this._baseMasochismLvl = 0;
	this._baseSadismLvl = 0;
	this._wantedPoints = 0;
	this.setupDoNothingCounts();
	this.resetGotHitBySkillType();
	this.changeStanceToNone();
	this.orgasmLockOff();
	this._performingCollapse = false;
};

//Define Property
Object.defineProperty(Game_BattlerBase.prototype, "isKarryn", {
	get: function () { return false; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "isChatface", {
	get: function () { return false; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "isChatface_Karryn", {
	get: function () { return false; }, configurable: true
});

Object.defineProperty(Game_BattlerBase.prototype, "isHorny", {
	get: function () { return this.isStateAffected(STATE_HORNY_ID); }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "isAngry", {
	get: function () {
		return this.isStateAffected(STATE_ANGRY_ID) || this.isStateAffected(STATE_SLIME_ANGRY_ID) || this.isStateAffected(STATE_ORC_ANGRY_ID);
	}, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "isConfident", {
	get: function () { return this.isStateAffected(STATE_CONFIDENT_ID); }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "isOffBalance", {
	get: function () { return this.isStateAffected(STATE_OFFBALANCE_ID); }, configurable: true
});

Object.defineProperty(Game_BattlerBase.prototype, "isGuarding", {
	get: function () { return this.isStateAffected(STATE_GUARD_ID); }, configurable: true
});

Object.defineProperty(Game_BattlerBase.prototype, "str", {
	get: function () { return this.atk; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "end", {
	get: function () { return this.def; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "dex", {
	get: function () { return this.mat; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "mind", {
	get: function () { return this.mdf; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "charm", {
	get: function () { return this.luk; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "stamina", {
	get: function () { return this._hp; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "maxstamina", {
	get: function () { return this.mhp; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "realMaxStamina", {
	get: function () { return Math.round(this.mhp * (1 / this.fatigueMultipler())); }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "energy", {
	get: function () { return this._mp; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "maxenergy", {
	get: function () { return this.mmp; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "realMaxEnergy", {
	get: function () { return Math.round(this.mmp * (1 / this.fatigueMultipler())); }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "will", {
	get: function () { return this._will; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "maxwill", {
	get: function () { return this.maxWill(); }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "pleasure", {
	get: function () { return this.tp; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "wpatk", {
	get: function () { return Math.round(this.mcr); }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "wpdef", {
	get: function () { return Math.round(this.grd); }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "esc", {
	get: function () { return this.pha; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "wsc", {
	get: function () { return this.pdr; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "ssc", {
	get: function () { return this.mdr; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "asc", {
	get: function () { return this.fdr; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "graze", {
	get: function () { return this.mev; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "staminaregen", {
	get: function () { return this.hrg; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "energyregen", {
	get: function () { return this.mrg; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "willregen", {
	get: function () { return this.tcr; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "stench", {
	get: function () { return this._stench; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "didNothingCount", {
	get: function () { return this._didNothingCount; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "fatigue", {
	get: function () { return this._fatigue; }, configurable: true
});
Object.defineProperty(Game_BattlerBase.prototype, "isErect", {
	get: function () { return this.isAroused() && DEBUG_MODE; }, configurable: true
});

//Getters
Game_BattlerBase.prototype.talkLvl = function() {
	return this._baseTalkLvl;
};
Game_BattlerBase.prototype.sightLvl = function() {
	return this._baseSightLvl;
};
Game_BattlerBase.prototype.pettingLvl = function() {
	return this._basePettingLvl;
};
Game_BattlerBase.prototype.toyLvl = function() {
	return this._baseToyLvl;
};
Game_BattlerBase.prototype.semenLvl = function() {
	return this._baseSemenLvl;
};
Game_BattlerBase.prototype.stripLvl = function() {
	return this._baseStripLvl;
};

Game_BattlerBase.prototype.kissLvl = function() {
	return this._baseKissLvl;
};
Game_BattlerBase.prototype.handjobLvl = function() {
	return this._baseHandjobLvl;
};
Game_BattlerBase.prototype.blowjobLvl = function() {
	return this._baseBlowjobLvl;
};
Game_BattlerBase.prototype.rimjobLvl = function() {
	return this._baseRimjobLvl;
};
Game_BattlerBase.prototype.footjobLvl = function() {
	return this._baseFootjobLvl;
};
Game_BattlerBase.prototype.tittyFuckLvl = function() {
	return this._baseTittyFuckLvl;
};
Game_BattlerBase.prototype.pussySexLvl = function() {
	return this._basePussySexLvl;
};
Game_BattlerBase.prototype.analSexLvl = function() {
	return this._baseAnalSexLvl;
};
Game_BattlerBase.prototype.masturbateLvl = function() {
	return this._baseMasturbateLvl;
};
Game_BattlerBase.prototype.masochismLvl = function() {
	return this._baseMasochismLvl;
};
Game_BattlerBase.prototype.sadismLvl = function() {
	return this._baseSadismLvl;
};

///////
// Display Name
/////////////

Game_BattlerBase.prototype.displayName = function() {
	return this.name();
};

//////
// Param
////////

//Modified to ignore cache for charm for karryn
Game_BattlerBase.prototype.param = function(paramId) {
	this._baseParamCache = this._baseParamCache || [];
	if (this._baseParamCache[paramId] && (this.isActor() && paramId != PARAM_CHARM_ID)) return this._baseParamCache[paramId];
	var base = this.paramBase(paramId);
	var plus = this.paramPlus(paramId);
	var paramRate = this.paramRate(paramId);
	var buffRate = this.paramBuffRate(paramId);
	var flat = this.paramFlat(paramId);
	var minValue = this.paramMin(paramId);
	var maxValue = Math.max(minValue, this.paramMax(paramId));
	var a = this;
	var user = this;
	var subject = this;
	var b = this;
	var target = this;
	var s = $gameSwitches._data;
	var v = $gameVariables._data;
	var code = Yanfly.Param.BPCFormula[paramId];
	try {
	var value = eval(code);
	} catch (e) {
	var value = 0;
	Yanfly.Util.displayError(e, code, 'CUSTOM PARAM FORMULA ERROR');
	}
	value = Math.round(value.clamp(minValue, maxValue));
	this._baseParamCache[paramId] = value;
	return this._baseParamCache[paramId];
};

Game_BattlerBase.prototype.paramMin = function(paramId) {
    return 1;
};

/////
// Stamina
//////////

Game_BattlerBase.prototype.hasNoStamina = function() {
	return this.stamina === 0;
};

Game_BattlerBase.prototype.hasLessThanOneFourthStamina = function() {
	return this.stamina <= this.maxstamina * 0.25;
};

Game_BattlerBase.prototype.hasLessThanOneThirdStamina = function() {
	return this.stamina <= this.maxstamina * 0.33;
};

Game_BattlerBase.prototype.hasLessThanHalfStamina = function() {
	return this.stamina <= this.maxstamina * 0.5;
};

//returns whole numbers, divide by 100 for percent
Game_BattlerBase.prototype.currentPercentOfStamina = function() {
	let value = Math.floor(this.stamina * 100 / this.maxstamina);
	if(value >= 100) value = 100;
	return value;
};

//returns whole numbers, divide by 100 for percent
//MaxHundred = don't return more than 100
Game_BattlerBase.prototype.getPercentOfStaminaFromValue = function(value, maxHundred) {
	let percent = Math.floor(value * 100 / this.maxstamina);
	if(maxHundred) percent = Math.min(100, percent);
	return percent;
};

//returns whole numbers, divide by 100 for percent
Game_BattlerBase.prototype.currentPercentOfStamina_realMax = function() {
	let value = Math.floor(this.stamina * 100 / this.realMaxStamina);
	if(value >= 100) value = 100;
	return value;
};

//////
// Fatigue
///////////

Game_BattlerBase.prototype.setFatigue = function(value) {
	this._fatigue = Math.min(100, Math.max(Math.round(value), 0));
	$gameScreen.setMapInfoRefreshNeeded();
};

Game_BattlerBase.prototype.gainFatigue = function(value) {
	this.setFatigue(this.fatigue + value);
};

Game_BattlerBase.prototype.recoverFatigue = function(value) {
	this.setFatigue(this.fatigue - value);
};

//Used for max stamina and max energy formulas
Game_BattlerBase.prototype.fatigueMultipler = function() {
    let value = (100 - this.fatigue) / 100;

	return Math.max(value,0.01);
};

////////
// Speed

Game_BattlerBase.prototype.bonusActionSpeed = function(item) {
    return 0;
};

Game_BattlerBase.prototype.actionSpeedRate = function(item) {
    return 1;
};

Remtairy.Battler.Game_Action_speed = Game_Action.prototype.speed;
Game_Action.prototype.speed = function() {
    let speed = Remtairy.Battler.Game_Action_speed.call(this);
	let speedRate = this.subject().actionSpeedRate(this.item());
    return speed * speedRate;
};

//////
// Will
//////
Game_BattlerBase.prototype.gainWill = function(value) {
    this.setWill(this.will + value);
};

Game_BattlerBase.prototype.setWill = function(will) {
    this._will = Math.round(will);
	this._will = this._will.clamp(0, this.maxwill);
};

//////////////
// Weapon Attack Weapon Defense
///////////////////

Game_BattlerBase.prototype.moddedWeaponAttack = function() {
    let moddedWpAtk = this.wpatk;

	return moddedWpAtk;
};

Game_BattlerBase.prototype.moddedWeaponDefense = function() {
    let moddedWpDef = this.wpdef;

	if(this.isGuarding) moddedWpDef *= 2;

	return moddedWpDef;
};

//////
// Critical
/////////

////////
// Critical Chance
// Critical Rate

Game_BattlerBase.prototype.criticalChanceFormula = function(target) {
	let value = this.cri - target.cev;
	value *= this.criticalChanceRate();
	value += this.criticalChanceBonus();
	return value;
};

Game_BattlerBase.prototype.criticalChanceRate = function() {
    let rate = 1;

	return rate;
};

Game_BattlerBase.prototype.criticalChanceBonus = function() {
    let bonus = 0;

	return bonus;
};

// Critical Damage
Game_BattlerBase.prototype.criticalDamageFormula = function(target, bonus) {
	let damageMultipler = 0;
	if(target)
		damageMultipler = Math.max(VAR_CRITICAL_DAMAGE_MIN, VAR_CRITICAL_DAMAGE_BASE + bonus + this.dex/200 - target.dex/200);
	else
		damageMultipler = VAR_CRITICAL_DAMAGE_BASE + bonus + this.dex/200;

	damageMultipler = (damageMultipler + this.criticalDamageBonus()) * this.criticalDamageRate();

	//console.log(damageMultipler);

	return damageMultipler;
};
Game_BattlerBase.prototype.criticalDamageRate = function() {
	let rate = 1;
	return rate;
};
Game_BattlerBase.prototype.criticalDamageBonus = function() {
    let bonus = 0;

	return bonus;
};

////////
// Stance
////////////

Game_BattlerBase.prototype.getStance = function() {
    return this._stance;
};
Game_BattlerBase.prototype.isSlashStance = function() {
    return this.getStance() === STANCE_SLASH;
};
Game_BattlerBase.prototype.isPierceStance = function() {
    return this.getStance() === STANCE_PIERCE;
};
Game_BattlerBase.prototype.isBluntStance = function() {
    return this.getStance() === STANCE_BLUNT;
};
Game_BattlerBase.prototype.isNoneStance = function() {
    return this.getStance() === STANCE_NONE;
};

Game_BattlerBase.prototype.setStance = function(stance) {
    this._stance = stance;
};
Game_BattlerBase.prototype.changeStanceToSlash = function() {
    this.setStance(STANCE_SLASH);
};
Game_BattlerBase.prototype.changeStanceToPierce = function() {
    this.setStance(STANCE_PIERCE);
};
Game_BattlerBase.prototype.changeStanceToBlunt = function() {
    this.setStance(STANCE_BLUNT);
};
Game_BattlerBase.prototype.changeStanceToNone = function() {
    this.setStance(STANCE_NONE);
};

Game_BattlerBase.prototype.changeStanceBySkill = function(item) {
	if(item.damage.type !== 1) return;

	let elementId = item.damage.elementId;
	switch(elementId) {
	case ELEMENT_SLASH_ID:
		this.changeStanceToSlash();
	break;
	case ELEMENT_PIERCE_ID:
		this.changeStanceToPierce();
	break;
	case ELEMENT_BLUNT_ID:
		this.changeStanceToBlunt();
	break;
	}
};

Game_BattlerBase.prototype.isInStrongStanceAgainstTarget = function(target) {
	if(this.isNoneStance()) return false;

	if(this.isSlashStance()) {
		if(target.isBluntStance() || target.isNoneStance()) {
			return true;
		}
	}
	else if(this.isPierceStance()) {
		if(target.isSlashStance() || target.isNoneStance()) {
			return true;
		}
	}
	else if(this.isBluntStance()) {
		if(target.isPierceStance() || target.isNoneStance()) {
			return true;
		}
	}

	return false;
};

Game_BattlerBase.prototype.isInSameStanceAsTarget = function(target) {
	return this.getStance() === target.getStance();
};

/////////////
// Stance Triangle
// Slash > Blunt > Pierce > Slash
// Adv: +15 hit, +25% damage Bad: -10 hit, -15% damage
// Used in hit accuracy formula
Game_BattlerBase.prototype.stanceHitAdv = function(target, item) {
	var elementId = item.damage.elementId;
	if(elementId !== ELEMENT_SLASH_ID && elementId !== ELEMENT_PIERCE_ID && elementId !== ELEMENT_BLUNT_ID && elementId !== STANCE_NONE) return 0;

	var neutral = this.isInSameStanceAsTarget(target);
	var strong = this.isInStrongStanceAgainstTarget(target);
	var weak = (!neutral && !strong);

	if(strong) return VAR_STANCE_STRONG_HIT;
	else if(weak) return VAR_STANCE_WEAK_HIT;
	else return 0;
};

Game_BattlerBase.prototype.stanceDmgAdv = function(target, elementId) {
	//var elementId = item.damage.elementId;
	if(elementId !== ELEMENT_SLASH_ID && elementId !== ELEMENT_PIERCE_ID && elementId !== ELEMENT_BLUNT_ID && elementId !== STANCE_NONE) {
		return 1;
	}

	let neutral = this.isInSameStanceAsTarget(target);
	let strong = this.isInStrongStanceAgainstTarget(target);
	let weak = (!neutral && !strong);

	if(strong) return VAR_STANCE_STRONG_DMG;
	else if(weak) return VAR_STANCE_WEAK_DMG;
	else return 1;
};

Game_BattlerBase.prototype.stanceBonusRate = function(elementId) {
	let bonusRate = 1;

	if(elementId === ELEMENT_SLASH_ID && this.isStateAffected(STATE_BONUS_SLASH_DMG_ID)) bonusRate += 0.5;
	else if (elementId === ELEMENT_PIERCE_ID && this.isStateAffected(STATE_BONUS_PIERCE_DMG_ID)) bonusRate += 0.5;
	else if (elementId === ELEMENT_BLUNT_ID && this.isStateAffected(STATE_BONUS_BLUNT_DMG_ID)) bonusRate += 0.5;

	return bonusRate;
};

/////
// Stench
//////////

Game_BattlerBase.prototype.setStench = function(stench) {
    this._stench = Math.max(Math.round(stench),0);
};
Game_BattlerBase.prototype.increaseStench = function(value) {
    this.setStench(this.stench + value);
};

/////////
// Slammed Cleaved Skewered
////////////

Game_BattlerBase.prototype.isSlammedThisBattle = function() {
	return this.isStateAffected(STATE_SLAMMED_THIS_BATTLE_ID);
};
Game_BattlerBase.prototype.isCleavedThisBattle = function() {
	return this.isStateAffected(STATE_CLEAVED_THIS_BATTLE_ID);
};
Game_BattlerBase.prototype.isSkeweredThisBattle = function() {
	return this.isStateAffected(STATE_SKEWERED_THIS_BATTLE_ID);
};

Game_BattlerBase.prototype.isSlammedThisTurn = function() {
	return this.isStateAffected(STATE_SLAMMED_THIS_TURN_ID);
};
Game_BattlerBase.prototype.isCleavedThisTurn = function() {
	return this.isStateAffected(STATE_CLEAVED_THIS_TURN_ID);
};
Game_BattlerBase.prototype.isSkeweredThisTurn = function() {
	return this.isStateAffected(STATE_SKEWERED_THIS_TURN_ID);
};

//////
// Do Nothing Skill
////////////

Game_BattlerBase.prototype.setupDoNothingCounts = function() {
	this._didNothing = false;
	this._enemyTurnCount = 0;
	this._didNothingCount = 0;
	this._didNothingCountThisBattle = 0;
};
Game_BattlerBase.prototype.doNothing = function() {
	this._didNothing = true;
	this._enemyTurnCount++;
	this._didNothingCountThisBattle++;
};
Game_BattlerBase.prototype.resetDidNothingCount = function() {
	this._didNothingCount = 0;
};

Game_BattlerBase.prototype.checkIfDidNothing = function() {
	if(this._didNothing) {
		this._didNothingCount++;
		this._didNothing = false;
	}
	else this.resetDidNothingCount();
};

/////////////
// Evade Reduction

Game_BattlerBase.prototype.resetEvadeReductionStage = function() {
	this._evadeReductionStage = 0;
};
Game_BattlerBase.prototype.increaseEvadeReductionStage = function() {
	this._evadeReductionStage = Math.min(2, this._evadeReductionStage + 1);
};
Game_BattlerBase.prototype.decreaseEvadeReductionStage = function() {
	this._evadeReductionStage = Math.max(0, this._evadeReductionStage - 1);
};
Game_BattlerBase.prototype.evadeReductionStageXParamRate = function() {
	let rate = 1;
	let eachStageEffect = 0.42;
	if(Prison.easyMode()) eachStageEffect = 0.69;
	rate -= eachStageEffect * this._evadeReductionStage;
	return Math.max(0.01, rate);
};

// Counter

Game_Battler.prototype.counterTotal = function() {
    return 2;
};

////////////
// Overblow Protection

Game_BattlerBase.prototype.overblowProtectionRate = function() {
	let op = 1;
	return op;
};
Game_BattlerBase.prototype.hasOverblowProtection = function() {
	return this.overblowProtectionRate() < 1;
};

/////////////
// Use AI Skill
//////////////

Game_BattlerBase.prototype.useAISkill = function(skillId, target) {
	if(!skillId) {
		console.error('useAISkill error: no skillId');
		return;
	}
	if(!target) {
		target = this._targetIndex;
	}
	if(!target) {
		console.error('useAISkill error: skill: ' + skillId + ' target: ' + target);
		return;
	}
	//console.log('useAISkill ' + skillId);
	BattleManager.queueForceAction(this, skillId, target);
};

//////
// Pleasure
////////////

Game_BattlerBase.prototype.arousalPoint = function() {
	let value = this._arousalBasePoint + this.end * VAR_AP_PER_END;
	return value;
};
Game_BattlerBase.prototype.orgasmPoint = function() {
	let value = this._orgasmBasePoint + this.end * VAR_OP_PER_END;
	return value;
};

Game_BattlerBase.prototype.isAroused = function() {
	if(!DEBUG_MODE) return false;
	return this.pleasure >= this.arousalPoint();
};

//Generic Battlerbase version
Game_BattlerBase.prototype.setPleasure = function(value) {
	this.setTp(Math.round(value));
};

Game_BattlerBase.prototype.gainPleasure = function(value, dontAddToResults) {
	if(!dontAddToResults) this._result.tpDamage = -value;
	this.setPleasure(this.pleasure + value);
};

Game_BattlerBase.prototype.setPleasureToArousalPoint = function() {
	this.setPleasure(this.arousalPoint());
};
Game_BattlerBase.prototype.setPleasureToOrgasmPoint = function() {
	this.setPleasure(this.orgasmPoint());
};

Game_BattlerBase.prototype.increaseArousalPoint = function(value) {
	this._arousalBasePoint += value;
};
Game_BattlerBase.prototype.increaseOrgasmPoint = function(value) {
	this._orgasmBasePoint += value;
};

Game_BattlerBase.prototype.reachedOrgasmPoint = function() {
	if(!DEBUG_MODE) return false;
	return this.pleasure >= this.orgasmPoint();
};

Game_BattlerBase.prototype.isTwoThirdsWayToOrgasm = function() {
	return this.currentPercentOfOrgasm(true) >= 66;
};

Game_BattlerBase.prototype.getPercentOfOrgasmFromValue = function(value) {
	let percent = Math.floor(value * 100 / this.orgasmPoint());
	return percent;
};

//whole value, inputting 2 is equal to 2%
Game_BattlerBase.prototype.getValueOfOrgasmFromPercent = function(percent) {
	let value = Math.floor(percent * 0.01 * this.orgasmPoint());
	return value;
};

//oneMax = return max of 100
//returns whole numbers, divide by 100 for percent
Game_BattlerBase.prototype.currentPercentOfOrgasm = function(oneMax) {
	let value = Math.floor(this.pleasure * 100 / this.orgasmPoint());
	if(value >= 100 && oneMax) value = 100;
	return value;
};

//oneMax = return max of 100
Game_BattlerBase.prototype.currentPercentOfArousal = function(oneMax) {
	let value = Math.floor(this.pleasure * 100 / this.arousalPoint());
	if(value > 100 && oneMax) value = 100;
	return value;
};

// Just Got Hit By Skill

Game_BattlerBase.prototype.resetGotHitBySkillType = function() {
	this._justGotHitBySkillType = 0;
};
Game_BattlerBase.prototype.justGotHitBySkillType = function(skillType) {
	this._justGotHitBySkillType = skillType;
};
Game_BattlerBase.prototype.didLastGetHitBySkillType = function(skillType) {
	if(skillType === JUST_SKILLTYPE_ENEMY_TOY_PLAY) {
		return this.didLastGetHitBySkillType(JUST_SKILLTYPE_ENEMY_TOY_PLAY_CLIT) || this.didLastGetHitBySkillType(JUST_SKILLTYPE_ENEMY_TOY_PLAY_PUSSY) || this.didLastGetHitBySkillType(JUST_SKILLTYPE_ENEMY_TOY_PLAY_ANAL);
	}

	return this._justGotHitBySkillType === skillType;
};

Game_BattlerBase.prototype.masochismSensitivity = function() {
	return 0;
};

//////
// State
///////

Game_BattlerBase.prototype.dontDisplayStateLogMessages = function() {
	return !this.isAlive();
};

//////////
// Horny
/////////

Game_BattlerBase.prototype.addHornyState = function() {

};
Game_BattlerBase.prototype.getHornyStateTurns = function() {
	return this.stateTurns(STATE_HORNY_ID);
};
Game_BattlerBase.prototype.increaseHornyStateTurns = function(value) {
	if(!this.isHorny) return;
	this.setStateTurns(STATE_HORNY_ID, this.getHornyStateTurns() + value);
};

//////////
// Stun Till End of Turn

Game_BattlerBase.prototype.addStunTillEndOfTurnState = function() {
	this.addState(STATE_STUN_TILL_TURN_END_ID);
};

Game_BattlerBase.prototype.startWarmups = function() {
	return;
};

///////////
///////////////
// Game Battler
//////////////
////////////

///////
// Regenerate
///////
/*
Game_Battler.prototype.regenerateHp = function() {
	if(this.stamina === 0) return;
	if(this.energy !== 0) {
		var value = Math.floor(this.maxstamina * this.staminaregen);
		if (value !== 0) {
			this.gainHp(value);
		}
	}
	else {
		if(this.isActor()) {
			var value = Math.floor(this.maxstamina * VAR_NO_ENERGY_STAMINA_DAMAGE);
		}
		else {
			var value = Math.floor(this.stamina);
		}
		this.gainHp(-value);
	}
};

Game_Battler.prototype.regenerateMp = function() {
	var value = Math.floor(this.maxenergy * this.energyregen);
	if (value !== 0) {
		this.gainMp(value);
	}
	if(this.isActor()) {
		this.regenerateWill();
		this.regenerateDesires();
		this.regenPussyJuice();
	}
	//regenerateTp aka pleasure is after this function
};

Game_Battler.prototype.regenerateWill = function() {
	var value = Math.floor(this.maxwill * this.willregen);
	if (value !== 0) {
		this.gainWill(value);
	}
};
*/
Game_Battler.prototype.regenerateDesires = function() {
	//Non Actors don't have desire bars.
	return;
};

//In Special Formulas Plugin
Game_Battler.prototype.willRegenMultipler = function() {
	return 1;
};

Game_Battler.prototype.setWillToMax = function() {
	this.setWill(this.maxwill);
};

/////////////
// Check For Orgasm
////////////////

Game_Battler.prototype.checkForOrgasm = function() {
	if(this.reachedOrgasmPoint() && !this.orgasmLocked()) {
		this.orgasm();
	}
};

Game_Battler.prototype.orgasmLocked = function() {
	return this._orgasmLock || this.isStateAffected(STATE_JUST_JOINED_ID);
};

Game_Battler.prototype.orgasmLockOn = function() {
	this._orgasmLock = true;
};
Game_Battler.prototype.orgasmLockOff = function() {
	this._orgasmLock = false;
};

/////////////
// Elemental Weakness
/////////////////

Game_Battler.prototype.weaknessToKiss = function() {
	var value = this.elementRate(ELEMENT_KISS_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToPetting = function() {
	var value = this.elementRate(ELEMENT_PETTING_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToHandjob = function() {
	var value = this.elementRate(ELEMENT_HANDJOB_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToBlowjob = function() {
	var value = this.elementRate(ELEMENT_BLOWJOB_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToRimjob = function() {
	var value = this.elementRate(ELEMENT_RIMJOB_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToFootjob = function() {
	var value = this.elementRate(ELEMENT_FOOTJOB_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToTittyFuck = function() {
	var value = this.elementRate(ELEMENT_TITTYFUCK_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToPussy = function() {
	var value = this.elementRate(ELEMENT_PUSSY_WEAK_ID);
	return value;
};
Game_Battler.prototype.weaknessToAnal = function() {
	var value = this.elementRate(ELEMENT_ANAL_WEAK_ID);
	return value;
};

//////////
// Is there an XXX opponent
// For future, maybe separate functions for active battlers vs onlookers, etc
///////////

Game_Battler.prototype.isThereAnErectOpponent = function() {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isErect) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForMinionThrowAmmoLoading = function(thrower) {
	let group = this.friendsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if(opponent && thrower.name() != opponent.name() && opponent.isValidTargetForMinionThrowAmmoLoading()) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForKiss = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForKiss(this, actorskill)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForCockStare = function() {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForCockStare(this)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForCockPetting = function() {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForCockPetting(this)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForHandjob = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForHandjob(this, actorskill)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForBlowjob = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForBlowjob(this, actorskill)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForRimjob = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForRimjob(this, actorskill)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForFootjob = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForFootjob(this, actorskill)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForTittyFuck = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForTittyFuck(this, actorskill)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForPussySex = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForPussySex(this, actorskill)) {
			return true;
		}
	}
	return false;
};

Game_Battler.prototype.isThereValidTargetForAnalSex = function(actorskill) {
	let group = this.opponentsUnit().aliveMembers();
	for (let i = 0; i < group.length; ++i) {
        let opponent = group[i];
        if (opponent && opponent.isValidTargetForAnalSex(this, actorskill)) {
			return true;
		}
	}
	return false;
};