require 'TimedActions/ISEatFoodAction.lua'
require 'TimedActions/ISDrinkFromBottle.lua'
require 'TimedActions/ISTakePillAction.lua'

Kinkocalypse = Kinkocalypse or {}
Kinkocalypse.ISEatFoodActionOrigIsValid = ISEatFoodAction.isValid;
Kinkocalypse.ISDrinkFromBottleOrigIsValid = ISDrinkFromBottle.isValid;
Kinkocalypse.ISTakePillActionOrigIsValid = ISTakePillAction.isValid;

Kinkocalypse.IsGagEquiped = function(player)
	local wornItem = player:getWornItem("RestraintsMouth")
	return wornItem ~= nil and Kinkocalypse.IsHasTag(wornItem, "SteelGag")
end

Kinkocalypse.IsGagEquipedAndClosed = function(player)
	local wornItem = player:getWornItem("RestraintsMouth")
	if wornItem ~= nil and Kinkocalypse.IsHasTag(wornItem, "SteelGag") == true then
		return wornItem:getModData().GagClosed == true
	end
	return false
end

ISEatFoodAction.isValid = function(self)
	if Kinkocalypse.IsGagEquipedAndClosed(getPlayer()) == true then
		Kinkocalypse.Say(getText("UI_Kincalypse_NeedUnplugGag"))
		return false
	end	
	if self.item:getEatType() and self.item:getEatType() ~= "" then
		if Kinkocalypse.ControllCenterIsOn() == true and Kinkocalypse.IsPunishmentActive("NoSmoke") == true and self.item:getEatType() == "Cigarettes" then
			Kinkocalypse.AddPunishmentScore(20, getText("UI_Kincalypse_ViolateNoSmokeRule"))
			Kinkocalypse.AddPunishment("NoSmoke", 60 + ZombRand(120))
			Kinkocalypse.AddPunishment("Gaged", 120)
			return false
		end
	end
	
	if Kinkocalypse.ControllCenterIsOn() == true and Kinkocalypse.IsPunishmentActive("NoEat") then
		Kinkocalypse.AddPunishmentScore(20, getText("UI_Kincalypse_ViolateNoEatRule"))
		Kinkocalypse.AddPunishment("NoEat", 60 + ZombRand(120))
		Kinkocalypse.AddPunishment("Gaged", 120)
		return false
	end
	
	return Kinkocalypse.ISEatFoodActionOrigIsValid(self)
end

ISDrinkFromBottle.isValid = function(self)
	if Kinkocalypse.IsGagEquipedAndClosed(getPlayer()) == true then
		Kinkocalypse.Say(getText("UI_Kincalypse_NeedUnplugGag"))
		return false
	end	
	return Kinkocalypse.ISDrinkFromBottleOrigIsValid(self)
end

ISTakePillAction.isValid = function(self)
	if Kinkocalypse.IsGagEquipedAndClosed(getPlayer()) == true then
		Kinkocalypse.Say(getText("UI_Kincalypse_NeedUnplugGag"))
		return false
	end	
	return Kinkocalypse.ISTakePillActionOrigIsValid(self)
end