<commit_before>-- ALCHEMY
-- reworked version
-- bases upon Falk's original script
-- by Merung

require("base.common")
require("druid.base.alchemy")

module("druid.base.brewing_plants_gemdust", package.seeall)

function UseItem(User,SourceItem,TargetItem,Counter,Param,ltstate)
   
   -- infront of a cauldron?
   if base.common.GetFrontItemID(User) == 1008 then
	  
       -- if there is a cauldron, it will become our object of changes; let's save it
	   local cauldron = base.common.GetFrontItem( User );
	   
	   -- is the char an alchemist?
	    if User:getMagicType() ~= 3 then
		  base.common.TempInformNLS( User,
				"Nur jene, die in die Kunst der Alchemie eingefhrt worden sind, knnen hier ihr Werk vollrichten.",
				"Only those who have been introduced to the art of alchemy are able to work here."
							);
		  return;
	    end
	   
	    -- there is a complete potions; we cannot add anything to it
		if (cauldron:getData("potionID") ~= "") then 
	        base.common.TempInformNLS( User,
		    "Einem fertigen Trank kannst Du nichts mehr beifgen.",
		    "You cannot add something to a completed potion."
			   );
		    return;
	    end
	
		local AlchemyPlant = druid.base.alchemy.CheckIfAlchemyPlant(User,SourceItem);
	    local GemDust = druid.base.alchemy.CheckIfGemDust(User,SourceItem);
		-- check if the SourceItem is a herb used for alchemy
		if AlchemyPlant or SourceItem.id == 157 then
		    BrewingPlant(User,SourceItem,cauldron)
	        
		    -- bucket with water
		elseif (SourceItem.id == 52) then
		    WaterCauldron(User,SourceItem,cauldron)   
			
			-- check if it is gem dust
	    elseif GemDust then
		   BrewingGemDust(User,SourceItem,cauldron)
	    end
    end
end

function BrewingPlant(User,SourceItem,cauldron)
	-- no stock and char tries to filter it
	if (cauldron:getData("stockData") == "") and (SourceItem.id == 157) then
			base.common.TempInformNLS( User,
			"Es befindet sich nichts zum Filtern im Kessel.",
			"There is nothing to filter in the cauldron."
			   );
			return
	end
	
	if ( ltstate == Action.abort ) then
		base.common.TempInformNLS( User,
		"Du brichst Deine Arbeit ab.",
		"You abort your work."
			   );
		return;
	end
	
	if (ltstate == Action.none) then
	   User:startAction(20,21,5,0,0);
	   return
	end
	
	local dataZList = druid.base.alchemy.SplitCauldronData(User,cauldronData);
	if SourceItem.id == 157 then -- rotten treebark
		-- try to neutralize a already neutral stock -> boom!
		if (cauldron:getData("stockData") == "55555555") then
			druid.base.alchemy.StockExplosion(User, SourceItem, cauldron);
			return;
		end
		
		-- there is a not neutral stock
		for i=1,8 do
			if dataZList < 5 then 
				dataZList[i] = dataZList[i] + 1
			elseif dataZList > 5 then
				dataZList[i] = dataZList[i] - 1
			end	
		end
	end
	
	-- if there is no cauldronData, we will create one    
	if (cauldron:getData("stockData") == "") then
	   cauldron:setData("stockData","55555555");
	end
	
	local cauldronData = tonumber(cauldron:getData("stockData"));
	
	if SourceItem.id ~= 157 then -- not a rotten tree bark; a normal alchemy herb
		
		local Plant = SourceItem.id
		local plusWertPos,minusWertPos = druid.base.alchemy.SplitPlantData(Plant);
		-- "overflow" leads to explosion of the stock
		if dataZList[plusWertPos] == 9 or dataZList[minusWertPos] == 1 then
		  druid.base.alchemy.StockExplosion(User, SourceItem, cauldron);
		  return;
		end 

		if plusWertPos == 0 then
		   dataZList[minusWertPos] = dataZList[minusWertPos] - 1 ;
		elseif minusWertPos == 0 then
			   dataZList[plusWertPos] = dataZList[plusWertPos] + 1 ;
		else
			dataZList[plusWertPos] = dataZList[plusWertPos] + 1 ;
			dataZList[minusWertPos] = dataZList[minusWertPos] - 1 ;
		end
	end
	
	-- delete the plant
	world:makeSound(10,cauldron.pos);
	User:increaseAtPos(SourceItem.itempos,-1);
	
	-- learn!
	User:learn("alchemy",6,10,100,User:increaseAttrib("perception",0))
	
	-- the new data value is being created
	local newStockData = druid.base.alchemy.PasteCauldronData(User,dataZList);
	cauldron:setData("stockData",""..newStockData);
	world:changeItem(cauldron)
end

function WaterCauldron(User,SourceItem,cauldron) 
    -- check if water has been filled into the cauldron already
	if (SourceItem:getData("cauldronFilledWith") ~= "") then
        base.common.TempInformNLS( User,
		"Der Kessel ist bereits mit etwas gefllt - noch mehr und er wrde berlaufen.",
		"The cauldron is already filled with something - more and it will spill over."
			   );
		return;
    else
	    if ( ltstate == Action.abort ) then
			base.common.TempInformNLS( User,
			"Du brichst Deine Arbeit ab.",
			"You abort your work."
				   );
			return;
	    end
        
		if (ltstate == Action.none) then
	        User:startAction(20,21,5,0,0);
	        return
	    end
		
		cauldron:setData("cauldronFilledWith","water");
	    world:changeItem(cauldron)
		
		SourceItem.id = 51;
	    SourceItem.data = 0;
	    world:changeItem(SourceItem);
    end
end

function BrewingGemDust(User,SourceItem,cauldron)
	
	-- no stock, no potion!	
	if (cauldron:getData("stockData") == "") then
	   base.common.TempInformNLS( User,
		"Im Kessel muss sich ein Sud befinden, um diesen zu verazaubern.",
		"There has to be a stock in the cauldron so that you can enchant it."
			   );
		return;
	end
	
	if ( ltstate == Action.abort ) then
		base.common.TempInformNLS( User,
		"Du brichst Deine Arbeit ab.",
		"You abort your work."
			   );
		return;
	end
	<commit_msg>debugging<commit_after>-- ALCHEMY
-- reworked version
-- bases upon Falk's original script
-- by Merung

require("base.common")
require("druid.base.alchemy")

module("druid.base.brewing_plants_gemdust", package.seeall)

function UseItem(User,SourceItem,TargetItem,Counter,Param,ltstate)
   
   -- infront of a cauldron?
   if base.common.GetFrontItemID(User) == 1008 then
	  
       -- if there is a cauldron, it will become our object of changes; let's save it
	   local cauldron = base.common.GetFrontItem( User );
	   
	   -- is the char an alchemist?
	    if User:getMagicType() ~= 3 then
		  base.common.TempInformNLS( User,
				"Nur jene, die in die Kunst der Alchemie eingefhrt worden sind, knnen hier ihr Werk vollrichten.",
				"Only those who have been introduced to the art of alchemy are able to work here."
							);
		  return;
	    end
	   
	    -- there is a complete potions; we cannot add anything to it
		if (cauldron:getData("potionID") ~= "") then 
	        base.common.TempInformNLS( User,
		    "Einem fertigen Trank kannst Du nichts mehr beifgen.",
		    "You cannot add something to a completed potion."
			   );
		    return;
	    end
	
		local AlchemyPlant = druid.base.alchemy.CheckIfAlchemyPlant(User,SourceItem);
	    local GemDust = druid.base.alchemy.CheckIfGemDust(User,SourceItem);
		-- check if the SourceItem is a herb used for alchemy
		if AlchemyPlant or SourceItem.id == 157 then
		    BrewingPlant(User,SourceItem,cauldron)
	        
		    -- bucket
		elseif (SourceItem.id == 51) or (SourceItem.id == 52) then
		    WaterCauldron(User,SourceItem,cauldron)   
			
			-- check if it is gem dust
	    elseif GemDust then
		   BrewingGemDust(User,SourceItem,cauldron)
	    end
    end
end

function BrewingPlant(User,SourceItem,cauldron)
	-- no stock and char tries to filter it
	if (cauldron:getData("stockData") == "") and (SourceItem.id == 157) then
			base.common.TempInformNLS( User,
			"Es befindet sich nichts zum Filtern im Kessel.",
			"There is nothing to filter in the cauldron."
			   );
			return
	end
	
	if ( ltstate == Action.abort ) then
		base.common.TempInformNLS( User,
		"Du brichst Deine Arbeit ab.",
		"You abort your work."
			   );
		return;
	end
	
	if (ltstate == Action.none) then
	   User:startAction(20,21,5,0,0);
	   return
	end
	
	local dataZList = druid.base.alchemy.SplitCauldronData(User,cauldronData);
	if SourceItem.id == 157 then -- rotten treebark
		-- try to neutralize a already neutral stock -> boom!
		if (cauldron:getData("stockData") == "55555555") then
			druid.base.alchemy.StockExplosion(User, SourceItem, cauldron);
			return;
		end
		
		-- there is a not neutral stock
		for i=1,8 do
			if dataZList < 5 then 
				dataZList[i] = dataZList[i] + 1
			elseif dataZList > 5 then
				dataZList[i] = dataZList[i] - 1
			end	
		end
	end
	
	-- if there is no cauldronData, we will create one    
	if (cauldron:getData("stockData") == "") then
	   cauldron:setData("stockData","55555555");
	end
	
	local cauldronData = tonumber(cauldron:getData("stockData"));
	
	if SourceItem.id ~= 157 then -- not a rotten tree bark; a normal alchemy herb
		
		local Plant = SourceItem.id
		local plusWertPos,minusWertPos = druid.base.alchemy.SplitPlantData(Plant);
		-- "overflow" leads to explosion of the stock
		if dataZList[plusWertPos] == 9 or dataZList[minusWertPos] == 1 then
		  druid.base.alchemy.StockExplosion(User, SourceItem, cauldron);
		  return;
		end 

		if plusWertPos == 0 then
		   dataZList[minusWertPos] = dataZList[minusWertPos] - 1 ;
		elseif minusWertPos == 0 then
			   dataZList[plusWertPos] = dataZList[plusWertPos] + 1 ;
		else
			dataZList[plusWertPos] = dataZList[plusWertPos] + 1 ;
			dataZList[minusWertPos] = dataZList[minusWertPos] - 1 ;
		end
	end
	
	-- delete the plant
	world:makeSound(10,cauldron.pos);
	User:increaseAtPos(SourceItem.itempos,-1);
	
	-- learn!
	User:learn("alchemy",6,10,100,User:increaseAttrib("perception",0))
	
	-- the new data value is being created
	local newStockData = druid.base.alchemy.PasteCauldronData(User,dataZList);
	cauldron:setData("stockData",""..newStockData);
	world:changeItem(cauldron)
end

function WaterCauldron(User,SourceItem,cauldron) 
    
	if (SourceItem.id == 52) and (cauldron:getData("cauldronFilledWith") ~= "") then
        base.common.TempInformNLS( User,
		"Der Kessel ist bereits mit etwas gefllt - noch mehr und er wrde berlaufen.",
		"The cauldron is already filled with something - more and it will spill over."
			   );
		return;
    elseif (SourceItem.id == 51) and (cauldron:getData("cauldronFilledWith") ~= "water")
	    base.common.TempInformNLS( User,
		"Hier ist kein Wasser im Kessel, dass Du abschpfen knntest.",
		"There is no water in the cauldon for you to scoop out."
			   );
		return;
	
	else	
		
		if (SourceItem.id == 51) then
		    newFilled = ""
			newBucketId = 52
		else
		    newFilled = "water"
			newBucketId = 51
		end	
		
		if ( ltstate == Action.abort ) then
			base.common.TempInformNLS( User,
			"Du brichst Deine Arbeit ab.",
			"You abort your work."
				   );
			return;
	    end
        
		if (ltstate == Action.none) then
	        User:startAction(20,21,5,0,0);
	        return
	    end
		
		cauldron:setData("cauldronFilledWith",newFilled);
	    world:changeItem(cauldron)
		
		SourceItem.id = newBucketId;
	    SourceItem.data = 0;
	    world:changeItem(SourceItem);
    end
end

function BrewingGemDust(User,SourceItem,cauldron)
	
	-- no stock, no potion!	
	if (cauldron:getData("stockData") == "") then
	   base.common.TempInformNLS( User,
		"Im Kessel muss sich ein Sud befinden, um diesen zu verazaubern.",
		"There has to be a stock in the cauldron so that you can enchant it."
			   );
		return;
	end
	
	if ( ltstate == Action.abort ) then
		base.common.TempInformNLS( User,
		"Du brichst Deine Arbeit ab.",
		"You abort your work."
			   );
		return;
	end
	
{'fraction_non_alphanumeric': 0.10564437770514973, 'fraction_numerical': 0.014309689956717605, 'mean_word_length': 3.257991726212862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5200492', 'n_tokens_mistral': 4499, 'n_tokens_neox': 3894, 'n_words': 1064}