<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/>. 
]]
local M = {}
local commandPosts = {}
local spawnInformations = {}
local commandMonsters = {}
local scheduledFunction = require("scheduled.scheduledFunction")

local M = {}
-- Present in Item scripts of:
-- Item: id_3109_open_pell
function M.UseItem(User, SourceItem)
    local commandPostPos = SourceItem.pos
    if SourceItem:getData("commandPost") == "true" then
        if User:isAdmin() == true then
            gmSelection(User, SourceItem)
        else
            pauseCommandPost(User,SourceItem,commandPostPos)
        end
    end

end

function gmSelection(User, SourceItem)
    local commandPostPos = SourceItem.pos
       
    if commandPosts[tostring(commandPostPos)] == nil then
        setUpCommandPost(User, SourceItem, commandPostPos)
        return
    end
    
    local modes = {"Set Number of Spawn", "Locate Spawns", "Select Monsters", "Number of Monsters", "Effects", "Spawn Marker","Spawn Intervals","Cooldown Time", "Start Spawnpoint","Capture"}
    local cbSetMode = function (dialog)
        if (not dialog:getSuccess()) then
            return
        end

        local index = dialog:getSelectedIndex() + 1
        if index == 1 then
            setUpCommandPost(User, SourceItem, commandPostPos)
        elseif index == 2 then
            selectCommandPostSpawn(User, SourceItem, commandPostPos, index)
        elseif index == 3 then
            selectCommandPostSpawn(User, SourceItem, commandPostPos, index)
        elseif index == 4 then
            selectCommandPostSpawn(User, SourceItem, commandPostPos, index)
        elseif index == 5 then
            setCommandPostEffects(User, SourceItem, commandPostPos)
        elseif index == 6 then
            setCommandPostMarker(User, SourceItem, commandPostPos)
        elseif index == 7 then
            setCommandPostIntervals(User, SourceItem, commandPostPos)
        elseif index == 8 then
            setCommandPostCooldown(User, SourceItem, commandPostPos)
        elseif index == 10 then
            pauseCommandPost(User,SourceItem,commandPostPos)
        else
            local check = checkCommandPost(User, SourceItem, commandPostPos)
           
            if check == true then
                initiateSpawns(User, SourceItem, commandPostPos)
            end
           
        end
    end
    local sd = SelectionDialog("Set the mode of this Spawnpoint.", "To which mode do you want to change it?", cbSetMode)
    for _,m in ipairs(modes) do
        sd:addOption(0,m)
    end
    User:requestSelectionDialog(sd)

end

-- What will happen if the Command Post is used by a Player -> Either pause it or tell that it is already paused
function pauseCommandPost(User,SourceItem,targetPosition)
    if SourceItem:getData("descriptionDe") == "Aktiver Befehlsstand" then
    if User:getPlayerLanguage() == Player.english then
    User:inform("You have captured the Command Post.")
    else
    User:inform("Du hast den Befehlsstand eingenommen.")
    end
    commandPosts[tostring(targetPosition)][1]["time"]= world:getTime("unix")+commandPosts[tostring(targetPosition)][1]["cooldown"]*60
    SourceItem:setData("descriptionDe","Eingenommener Befehlsstand")
    SourceItem:setData("descriptionEn","Captured Command Post")
    world:changeItem(SourceItem)
    elseif User:getPlayerLanguage() == Player.english then
    User:inform("The Command Post is already captured.")
    else
    User:inform("Der Befehlsstand ist bereits eingenommen.")

    
    end
end

-- Initialize the commandPost in the table
function setUpCommandPost(User, SourceItem, targetPosition)
    commandPosts[tostring(targetPosition)] = {}<commit_msg>Add Remove function and test mode for the CommandPost<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/>. 
]]
local M = {}
local commandPosts = {}
local spawnInformations = {}
local commandMonsters = {}
local scheduledFunction = require("scheduled.scheduledFunction")

local M = {}
-- Present in Item scripts of:
-- Item: id_3109_open_pell
function M.UseItem(User, SourceItem)
    local commandPostPos = SourceItem.pos
    if SourceItem:getData("commandPost") == "true" then
        if User:isAdmin() == true then
            gmSelection(User, SourceItem)
        else
            if SourceItem:getData("test") == "true" then
                gmSelection(User, SourceItem)
                return
            end
            if commandPosts[tostring(commandPostPos)] == nil then
                return
            end

                pauseCommandPost(User,SourceItem,commandPostPos)

        end
    end

end

function gmSelection(User, SourceItem)
    local commandPostPos = SourceItem.pos
       
    if commandPosts[tostring(commandPostPos)] == nil then
        setUpCommandPost(User, SourceItem, commandPostPos)
        return
    end
    
    local modes = {"Set Number of Spawn", "Locate Spawns", "Select Monsters", "Number of Monsters", "Effects", "Spawn Marker","Spawn Intervals","Cooldown Time", "Start Command Post","Capture","Remove Command Post"}
    local cbSetMode = function (dialog)
        if (not dialog:getSuccess()) then
            return
        end

        local index = dialog:getSelectedIndex() + 1
        if index == 1 then
            setUpCommandPost(User, SourceItem, commandPostPos)
        elseif index == 2 then
            selectCommandPostSpawn(User, SourceItem, commandPostPos, index)
        elseif index == 3 then
            selectCommandPostSpawn(User, SourceItem, commandPostPos, index)
        elseif index == 4 then
            selectCommandPostSpawn(User, SourceItem, commandPostPos, index)
        elseif index == 5 then
            setCommandPostEffects(User, SourceItem, commandPostPos)
        elseif index == 6 then
            setCommandPostMarker(User, SourceItem, commandPostPos)
        elseif index == 7 then
            setCommandPostIntervals(User, SourceItem, commandPostPos)
        elseif index == 8 then
            setCommandPostCooldown(User, SourceItem, commandPostPos)
        elseif index == 10 then
            pauseCommandPost(User,SourceItem,commandPostPos)
        elseif index == 11 then
            deleteCommandPost(User,SourceItem,commandPostPos)
        else
            local check = checkCommandPost(User, SourceItem, commandPostPos)
           
            if check == true then
                initiateSpawns(User, SourceItem, commandPostPos)
            end
           
        end
    end
    local sd = SelectionDialog("Set the mode of this Spawnpoint.", "To which mode do you want to change it?", cbSetMode)
    for _,m in ipairs(modes) do
        sd:addOption(0,m)
    end
    User:requestSelectionDialog(sd)

end

-- What will happen if the Command Post is used by a Player -> Either pause it or tell that it is already paused
function pauseCommandPost(User,SourceItem,targetPosition)
    if SourceItem:getData("descriptionDe") == "Aktiver Befehlsstand" then
    if User:getPlayerLanguage() == Player.english then
    User:inform("You have captured the Command Post.")
    else
    User:inform("Du hast den Befehlsstand eingenommen.")
    end
    commandPosts[tostring(targetPosition)][1]["time"]= world:getTime("unix")+commandPosts[tostring(targetPosition)][1]["cooldown"]*60
    SourceItem:setData("descriptionDe","Eingenommener Befehlsstand")
    SourceItem:setData("descriptionEn","Captured Command Post")
    world:changeItem(SourceItem)
    elseif User:getPlayerLanguage() == Player.english then
    User:inform("The Command Post is already captured.")
    else
    User:inform("Der Befehlsstand ist bereits eingenommen.")

    
    end
end

-- Remove a commandPost
function deleteCommandPost(User,SourceItem,commandPostPos)
    for i=#spawnInformations,1,-1 do
        if spawnInformations[i] == commandPosts[tostring(commandPostPos)] then
            table.remove(spawnInformations, i)
            table.remove(commandMonsters, i)
            commandPosts[tostring(commandPostPos)] = nil
        end
    end
end

-- Initialize the commandPost in the table
function setUpCommandPost(User, SourceItem, targetPosition)
    commandPosts[tostring(targetPosition)] = {}
{'fraction_non_alphanumeric': 0.0806796324000855, 'fraction_numerical': 0.004915580252190639, 'mean_word_length': 3.2081834532374103, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5959507', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2506, 'n_words': 821}