<commit_before>-- Generic Routine Collection
module("base.common", package.seeall)

--- Select the proper text upon the language flag of the character
-- @param User The character who's language flag matters
-- @param textInDe german text
-- @param textInEn english text
-- @return Text german or english text version

function GetNLS(User, textInDe, textInEn)
    return (User:getPlayerLanguage() == Player.german and textInDe or textInEn);
end;

--- Send a inform to the player in the language the player speaks
-- @param User The character who receives the message
-- @param textInDe german text
-- @param textInEn english text
-- @param informPriority Player.[low|medium|high]Priority

-- Default: Medium priority
function InformNLS(User, textInDe, textInEn)
    User:inform(textInDe, textInEn)
end

-- Temp: Low priority
function TempInformNLS(User, textInDe, textInEn)
    User:inform(textInDe, textInEn, Player.lowPriority)
end

-- High: High priority
function HighInformNLS(User, textInDe, textInEn)
    User:inform(textInDe, textInEn, Player.highPriority)
end

--- Triggers a multi language talking for a character
-- In case there is no player in range who could hear the talking nothing is
-- said
-- @param User The character who should say the message
-- @param method The method that is used to speak Character.say, Character.yell, Character.whisper
-- @param textInDe german text
-- @param textInEn english text
function TalkNLS(User, method, textInDe, textInEN)
    if (User == nil) then
        return;
    end
    local Range = 0;
    if (method == Character.whisper) then
        Range = 2;
    elseif (method == Character.yell) then
        Range = 30;
    else
        Range = 12;
        method = Character.say;
    end;

    local players = world:getPlayersInRangeOf(User.pos, Range);

    if (table.getn(players) == 0) then
        return;
    end;

    if (textInDe == nil and textInEN ~= nil) then
        User:talk( method, textInEN );
        return;
    elseif (textInDe ~= nil and textInEN == nil) then
        User:talk( method, textInDe );
        return;
    end;

    local foundDE = false;
    local foundEN = false;

    for _, char in pairs(players) do
        if (char:getPlayerLanguage() == Player.german) then
            foundDE = true;
        else
            foundEN = true;
        end;

        if foundDE and foundEN then
            break;
        end;
    end;

    if foundDE then
        User:talkLanguage(method, Player.german,  textInDe);
    end;

    if foundEN then
        User:talkLanguage(method, Player.english, textInEN);
    end;
end;

--- Get a text based on the gender of the character.
-- @param User The character used to choose the text
-- @param textMale The text returned in case the character is male
-- @param textFemale The text returned in case the character is female
-- @return textMale or textFemale, based on the gender of User
function GetGenderText(User, textMale, textFemale)
    return (User:increaseAttrib("sex", 0) == 1 and textFemale or textMale);
end;

--- This function uses the random value generator to produce a random chance.
-- This function returns true in a specified amount of cases. The optional
-- Base parameter is used to set the value of 100%. By default this value is 1.
-- For example in case the value is set to 80 and the base is set to 100 the
-- function will return true in 80% of the calls. The same result would be
-- produced in case the value is set to 8 and the base is set to 10 or in case
-- the Value is set to 0.8 and the base is not set, or set to 1.
-- @param Value The chance value
-- @param Base The value of 100% (optional)
-- @return true in (Value/Base*100)% of the calls
function Chance(Value, Base)
    if (Base ~= nil and Value >= Base) or (Base == nil and Value >= 1) then
        return true;
    end;
    if (Value <= 0) then
        return false;
    end;
    
    if (Base ~= nil) and (Base ~= 1) then
        Value = Value / Base;
    end;
    
    return (math.random() <= Value);
end;

--- Determine if a character is looking at a position or not
-- @param User The character whos looking direction matters
-- @param Location The position the character should look at
-- @return true in case the character looks at the position, else false
function IsLookingAt(User, Location)
    if not User or not Location then
        return false;
    end;

    if User.pos == Location then
		debug("equal")
        return true;
    end

    local richtung = User:getFaceTo();
	debug("richtung "..richtung.." char "..tostring(Character.southeast))
	debug("Loc y: "..Location.y.." x: "..Location.x)
	debug("User y: "..User.pos.y.." y: "..User.pos.x)
	
    return (((richtung == Character.north) and (Location.y < User.pos.y)) or
            ((richtung == Character.northeast) and
                ((Location.y < User.pos.y) or (Location.x > User.pos.x))) or
            ((richtung == Character.east) and (Location.x > User.pos.x)) or
            ((richtung == Character.southeast) and
                ((Location.y > User.pos.y) and (Location.x > User.pos.x))) or
            ((richtung == Character.south) and (Location.y > User.pos.y)) or
            ((richtung == Character.southwest) and
                ((Location.y > User.pos.y) or (Location.x < User.pos.x))) or
            ((richtung == Character.west) and (Location.x < User.pos.x)) or
            ((richtung == Character.northwest) and
                ((Location.y < User.pos.y) or (Location.x < User.pos.x))));
end;

--- Check if a character sequence (string) is nil or empty.<commit_msg>turning of chars by a 45 angle<commit_after>-- Generic Routine Collection
module("base.common", package.seeall)

--- Select the proper text upon the language flag of the character
-- @param User The character who's language flag matters
-- @param textInDe german text
-- @param textInEn english text
-- @return Text german or english text version

function GetNLS(User, textInDe, textInEn)
    return (User:getPlayerLanguage() == Player.german and textInDe or textInEn);
end;

--- Send a inform to the player in the language the player speaks
-- @param User The character who receives the message
-- @param textInDe german text
-- @param textInEn english text
-- @param informPriority Player.[low|medium|high]Priority

-- Default: Medium priority
function InformNLS(User, textInDe, textInEn)
    User:inform(textInDe, textInEn)
end

-- Temp: Low priority
function TempInformNLS(User, textInDe, textInEn)
    User:inform(textInDe, textInEn, Player.lowPriority)
end

-- High: High priority
function HighInformNLS(User, textInDe, textInEn)
    User:inform(textInDe, textInEn, Player.highPriority)
end

--- Triggers a multi language talking for a character
-- In case there is no player in range who could hear the talking nothing is
-- said
-- @param User The character who should say the message
-- @param method The method that is used to speak Character.say, Character.yell, Character.whisper
-- @param textInDe german text
-- @param textInEn english text
function TalkNLS(User, method, textInDe, textInEN)
    if (User == nil) then
        return;
    end
    local Range = 0;
    if (method == Character.whisper) then
        Range = 2;
    elseif (method == Character.yell) then
        Range = 30;
    else
        Range = 12;
        method = Character.say;
    end;

    local players = world:getPlayersInRangeOf(User.pos, Range);

    if (table.getn(players) == 0) then
        return;
    end;

    if (textInDe == nil and textInEN ~= nil) then
        User:talk( method, textInEN );
        return;
    elseif (textInDe ~= nil and textInEN == nil) then
        User:talk( method, textInDe );
        return;
    end;

    local foundDE = false;
    local foundEN = false;

    for _, char in pairs(players) do
        if (char:getPlayerLanguage() == Player.german) then
            foundDE = true;
        else
            foundEN = true;
        end;

        if foundDE and foundEN then
            break;
        end;
    end;

    if foundDE then
        User:talkLanguage(method, Player.german,  textInDe);
    end;

    if foundEN then
        User:talkLanguage(method, Player.english, textInEN);
    end;
end;

--- Get a text based on the gender of the character.
-- @param User The character used to choose the text
-- @param textMale The text returned in case the character is male
-- @param textFemale The text returned in case the character is female
-- @return textMale or textFemale, based on the gender of User
function GetGenderText(User, textMale, textFemale)
    return (User:increaseAttrib("sex", 0) == 1 and textFemale or textMale);
end;

--- This function uses the random value generator to produce a random chance.
-- This function returns true in a specified amount of cases. The optional
-- Base parameter is used to set the value of 100%. By default this value is 1.
-- For example in case the value is set to 80 and the base is set to 100 the
-- function will return true in 80% of the calls. The same result would be
-- produced in case the value is set to 8 and the base is set to 10 or in case
-- the Value is set to 0.8 and the base is not set, or set to 1.
-- @param Value The chance value
-- @param Base The value of 100% (optional)
-- @return true in (Value/Base*100)% of the calls
function Chance(Value, Base)
    if (Base ~= nil and Value >= Base) or (Base == nil and Value >= 1) then
        return true;
    end;
    if (Value <= 0) then
        return false;
    end;
    
    if (Base ~= nil) and (Base ~= 1) then
        Value = Value / Base;
    end;
    
    return (math.random() <= Value);
end;

--- Determine if a character is looking at a position or not
-- @param User The character whos looking direction matters
-- @param Location The position the character should look at
-- @return true in case the character looks at the position, else false
function IsLookingAt(User, Location)
    if not User or not Location then
        return false;
    end;

    if User.pos == Location then
		debug("equal")
        return true;
    end

    local richtung = User:getFaceTo();
	debug("richtung "..richtung.." char "..tostring(Character.southeast))
	debug("Loc y: "..Location.y.." x: "..Location.x)
	debug("User y: "..User.pos.y.." y: "..User.pos.x)
	
    return (((richtung == Character.north) and (Location.y < User.pos.y)) or
            ((richtung == Character.northeast) and
                ((Location.y < User.pos.y) and (Location.x > User.pos.x))) or
            ((richtung == Character.east) and (Location.x > User.pos.x)) or
            ((richtung == Character.southeast) and
                ((Location.y > User.pos.y) and (Location.x > User.pos.x))) or
            ((richtung == Character.south) and (Location.y > User.pos.y)) or
            ((richtung == Character.southwest) and
                ((Location.y > User.pos.y) and (Location.x < User.pos.x))) or
            ((richtung == Character.west) and (Location.x < User.pos.x)) or
            ((richtung == Character.northwest) and
                ((Location.y < User.pos.y) and (Location.x < User.pos.x))));
end;

--- Check if a character sequence (string) is nil or empty.
{'fraction_non_alphanumeric': 0.10417787340864264, 'fraction_numerical': 0.006455083378160301, 'mean_word_length': 2.7220553887220555, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7361284', 'n_tokens_mistral': 3386, 'n_tokens_neox': 3228, 'n_words': 1319}