<commit_before>--[[
Illarion Server

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
details.

You should have received a copy of the GNU Affero General Public License along
with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

-- trees

-- additional tool: axe ( 74 )

local common = require("base.common")
local gathering = require("content.gathering")

module("content.gatheringcraft.woodchopping", package.seeall)


local TreeItems = {}
local function AddTree(TreeId, TrunkId, LogId, BoughId, Amount, BoughProbability)
    local treeTable = {};
    treeTable.TrunkId = TrunkId;
    treeTable.LogId = LogId;
    treeTable.BoughId = BoughId;
    treeTable.Amount = Amount;
    treeTable.BoughProbability = BoughProbability;
    TreeItems[TreeId] = treeTable
end

AddTree(  11,125,2560,  56,10,0.4); -- apple tree
AddTree(  14,125,2560,  56,10,0.4); -- apple tree
AddTree( 299,541, 543,2786,15,0.4); -- cherry tree
AddTree( 300,541, 543,2786,15,0.4); -- cherry tree
AddTree( 308,309,   3,   56,12,0.4); -- fir tree
AddTree( 586,587, 544,  56,10,0.4); -- cachdern tree
AddTree(1804,542, 544,  56,15,0.4); -- naldor tree
AddTree(1809,584, 544,  56,24,0.4); -- eldan oak
AddTree(1817,585,   3,   56,19,0.4); -- scandrel pine

local unchoppableTrees = {}
unchoppableTrees[203] = true
unchoppableTrees[892] = true
unchoppableTrees[893] = true
unchoppableTrees[894] = true
unchoppableTrees[910] = true
unchoppableTrees[911] = true
unchoppableTrees[912] = true
unchoppableTrees[913] = true
unchoppableTrees[959] = true
unchoppableTrees[960] = true
unchoppableTrees[961] = true
unchoppableTrees[962] = true
unchoppableTrees[963] = true
unchoppableTrees[1193] = true
unchoppableTrees[1194] = true
unchoppableTrees[1195] = true
unchoppableTrees[1198] = true
unchoppableTrees[1807] = true
unchoppableTrees[1808] = true

function StartGathering(User, SourceItem, ltstate)

    gathering.InitGathering();
    local theCraft = gathering.woodchopping;

    common.ResetInterruption( User, ltstate );
    if ( ltstate == Action.abort ) then -- work interrupted
        return
    end

    if not common.CheckItem( User, SourceItem ) then -- security check
        return
    end

    -- additional tool item is needed
    if (User:countItemAt("all",74)==0) then
        common.HighInformNLS( User,
        "Du brauchst ein Beil um Holz zu hacken.",
        "You need a hatchet to chop wood." );
        return
    end
    local toolItem = User:getItemAt(5);
    if ( toolItem.id ~= 74 ) then
        toolItem = User:getItemAt(6);
        if ( toolItem.id ~= 74 ) then
            common.HighInformNLS( User,
            "Du musst das Beil in der Hand haben!",
            "You have to hold the hatchet in your hand!" );
            return
        end
    end

    if not common.FitForWork( User ) then -- check minimal food points
        return
    end

    common.TurnTo( User, SourceItem.pos ); -- turn if necessary

    -- check if it is a special and therefore uncuttable tree
    if SourceItem:getData("treeProtectionType") ~= "" then
        preventCutting(User, toolItem, SourceItem)
        return
    end

    local tree = TreeItems[SourceItem.id];

    -- check the amount
    local changeItem = false;
    local amount = SourceItem:getData("wood_amount");
    if ( amount == "" ) then
        amount = tree.Amount;
        SourceItem:setData("wood_amount", "" .. amount);
        changeItem = true;
    else
        amount = tonumber(amount);
    end

    if ( amount <= 0 ) then
        -- should never happen, but handle it nevertheless
        world:erase(SourceItem, SourceItem.number);
        world:createItemFromId(tree.TrunkId, 1, SourceItem.pos, true, 333, nil);
        common.HighInformNLS( User,
        "Hier gibt es kein Holz mehr zu holen. Gib dem Baum Zeit um nachzuwachsen.",
        "There is no wood anymore that you can chop. Give the tree time to grow again." );
        return;
    end

    -- user feedback per nice animation
    User:performAnimation(5)

    if ( ltstate == Action.none ) then -- currently not working -> let's go
        theCraft.SavedWorkTime[User.id] = theCraft:GenWorkTime(User,toolItem);
        User:startAction( theCraft.SavedWorkTime[User.id], 0, 0, 6, 0);
        if ( changeItem ) then
            world:changeItem(SourceItem);
        end
        return;
    end

    -- since we're here, we're working
    if theCraft:FindRandomItem(User) then
        if ( changeItem ) then
            world:changeItem(SourceItem);
        end
        return
    end

    User:learn( theCraft.LeadSkill, theCraft.SavedWorkTime[User.id], theCraft.LearnLimit);
    amount = amount - 1;
    SourceItem:setData("wood_amount", "" .. amount);
    world:changeItem(SourceItem);

    local producedItemId = tree.LogId;
    if (math.random() <= tree.BoughProbability ) then
        producedItemId = tree.BoughId;
    end
    local created = common.CreateItem(User, producedItemId, 1, 333, nil) -- create the new produced items<commit_msg>#11393 change wood output to distinct source plan and add heartwood to drops<commit_after>--[[
Illarion Server

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
details.

You should have received a copy of the GNU Affero General Public License along
with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

-- trees

-- additional tool: axe ( 74 )

local common = require("base.common")
local gathering = require("content.gathering")

module("content.gatheringcraft.woodchopping", package.seeall)


local TreeItems = {}
local function AddTree(TreeId, TrunkId, LogId, HeartwoodId, BoughId, Amount, BoughProbability, HeartwoodProbability)
    local treeTable = {};
    treeTable.TrunkId = TrunkId;
    treeTable.LogId = LogId;
    treeTable.HeartwoodId = HeartwoodId;
    treeTable.BoughId = BoughId;
    treeTable.Amount = Amount;
    treeTable.BoughProbability = BoughProbability;
    treeTable.HeartwoodProbability = HeartwoodProbability;
    TreeItems[TreeId] = treeTable
end

AddTree(  11,125,2560,3786,  56,11,0.075,0); -- apple tree
AddTree(  14,125,2560,3786,  56,11,0.075,0); -- apple tree
AddTree( 299,541, 543,3786,  56,11,0.075,0); -- cherry tree
AddTree( 300,541, 543,3786,  56,11,0.075,0); -- cherry tree
AddTree( 308,309,   3,3786,  56,10,0.075,0); -- fir tree
AddTree( 586,587, 544,3786,  56,10,0.075,0.06); -- cachdern tree
AddTree(1804,542, 544,3786,  56,11,0.075,0.06); -- naldor tree
AddTree(1809,584, 544,3786,  56,11,0.075,0); -- eldan oak
AddTree(1817,585,   3,3786,  56,11,0.075,0); -- scandrel pine

local unchoppableTrees = {}
unchoppableTrees[203] = true
unchoppableTrees[892] = true
unchoppableTrees[893] = true
unchoppableTrees[894] = true
unchoppableTrees[910] = true
unchoppableTrees[911] = true
unchoppableTrees[912] = true
unchoppableTrees[913] = true
unchoppableTrees[959] = true
unchoppableTrees[960] = true
unchoppableTrees[961] = true
unchoppableTrees[962] = true
unchoppableTrees[963] = true
unchoppableTrees[1193] = true
unchoppableTrees[1194] = true
unchoppableTrees[1195] = true
unchoppableTrees[1198] = true
unchoppableTrees[1807] = true
unchoppableTrees[1808] = true

function StartGathering(User, SourceItem, ltstate)

    gathering.InitGathering();
    local theCraft = gathering.woodchopping;

    common.ResetInterruption( User, ltstate );
    if ( ltstate == Action.abort ) then -- work interrupted
        return
    end

    if not common.CheckItem( User, SourceItem ) then -- security check
        return
    end

    -- additional tool item is needed
    if (User:countItemAt("all",74)==0) then
        common.HighInformNLS( User,
        "Du brauchst ein Beil um Holz zu hacken.",
        "You need a hatchet to chop wood." );
        return
    end
    local toolItem = User:getItemAt(5);
    if ( toolItem.id ~= 74 ) then
        toolItem = User:getItemAt(6);
        if ( toolItem.id ~= 74 ) then
            common.HighInformNLS( User,
            "Du musst das Beil in der Hand haben!",
            "You have to hold the hatchet in your hand!" );
            return
        end
    end

    if not common.FitForWork( User ) then -- check minimal food points
        return
    end

    common.TurnTo( User, SourceItem.pos ); -- turn if necessary

    -- check if it is a special and therefore uncuttable tree
    if SourceItem:getData("treeProtectionType") ~= "" then
        preventCutting(User, toolItem, SourceItem)
        return
    end

    local tree = TreeItems[SourceItem.id];

    -- check the amount
    local changeItem = false;
    local amount = SourceItem:getData("wood_amount");
    if ( amount == "" ) then
        amount = tree.Amount;
        SourceItem:setData("wood_amount", "" .. amount);
        changeItem = true;
    else
        amount = tonumber(amount);
    end

    if ( amount <= 0 ) then
        -- should never happen, but handle it nevertheless
        world:erase(SourceItem, SourceItem.number);
        world:createItemFromId(tree.TrunkId, 1, SourceItem.pos, true, 333, nil);
        common.HighInformNLS( User,
        "Hier gibt es kein Holz mehr zu holen. Gib dem Baum Zeit um nachzuwachsen.",
        "There is no wood anymore that you can chop. Give the tree time to grow again." );
        return;
    end

    -- user feedback per nice animation
    User:performAnimation(5)

    if ( ltstate == Action.none ) then -- currently not working -> let's go
        theCraft.SavedWorkTime[User.id] = theCraft:GenWorkTime(User,toolItem);
        User:startAction( theCraft.SavedWorkTime[User.id], 0, 0, 6, 0);
        if ( changeItem ) then
            world:changeItem(SourceItem);
        end
        return;
    end

    -- since we're here, we're working
    if theCraft:FindRandomItem(User) then
        if ( changeItem ) then
            world:changeItem(SourceItem);
        end
        return
    end

    User:learn( theCraft.LeadSkill, theCraft.SavedWorkTime[User.id], theCraft.LearnLimit);
    amount = amount - 1;
    SourceItem:setData("wood_amount", "" .. amount);
    world:changeItem(SourceItem);

    local producedItemId = tree.LogId;
    if (math.random() <= tree.HeartwoodProbability ) then
        producedItemId = tree.HeartwoodId;
    elseif (math.random() <= tree.BoughProbability ) then
        producedItemId = tree.BoughId;
    end
    local created = common.CreateItem(User, producedItemId, 1, 333, nil) -- create the new produced items
{'fraction_non_alphanumeric': 0.10278372591006424, 'fraction_numerical': 0.04675231977159172, 'mean_word_length': 3.159183673469388, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1199501', 'n_tokens_mistral': 3892, 'n_tokens_neox': 3523, 'n_words': 1047}