require "recipecode"
require "TimedActions/ISHandcraftAction"

Recipe = Recipe or {}
Recipe.GetItemTypes = Recipe.GetItemTypes or {}
Recipe.OnCanPerform = Recipe.OnCanPerform or {}
Recipe.OnCreate = Recipe.OnCreate or {}
Recipe.OnGiveXP = Recipe.OnGiveXP or {}
Recipe.OnTest = Recipe.OnTest or {}

    --Smolpity
function Recipe.OnCreate.Snowpity(sources, result, character, item)
    local player = getPlayer();
    local result = sources:getAllCreatedItems():get(0);
    local level = player:getPerkLevel(Perks.Tailoring) + 1;
    
    local harvest = 1 + ZombRand(math.floor(level*0.3));
    --between 1 and 3 snowpity harvested based on tailoring level
    result:setUsedDelta(result:getUseDelta() * harvest);
    
    --copied from dismantle code and modified, rarely gives thread back
    if ZombRand(4) < level then
        local max = 1+ZombRand(math.floor(level/0.5)); --between 1 and 5
        local thread = instanceItem("Base.Thread");
        thread:setUsedDelta(thread:getUseDelta()*max);
        player:getInventory():AddItem(thread);
      -- no more xp for murdering your friends, as we want players making things for crafting xp
        if level < (SandboxVars.LevelForDismantleXPCutoff) then
            player:getXp():AddXP(Perks.Tailoring, 1);
        end
    end
end