mixrmastr-bartender-droid.lua

self:onSpeech("mixdrink", function(self, speaker, fullText)
    -- respond to droid's owner.
    --if speaker:getName() == "Xerakon" then
    -- remove the command "mixdrink" from the string
    local input = removeFirstWord(fullText)
    -- save the strength value from the string, then remove it
    local strength = trim(input:gmatch("%w+")())
    strength = strength:lower()
    drink = removeFirstWord(input)
    -- assign the correct strength table
    strengthTable = {}
    drinkBP = ""
    if string.find(strength, "triple") then
        strengthTable = { 20 }
        drinkBP = "a mind-blasting alcoholic beverage"
    elseif string.find(strength, "double") then
        strengthTable = { 16, 17 }
        drinkBP = "a double-shot strength alcoholic beverage"
    elseif string.find(strength, "stiff") then
        strengthTable = { 2, 5, 7, 8, 19 }
        drinkBP = "a strong alcoholic beverage"
    elseif string.find(strength, "weak") then
        strengthTable = { 1, 3, 4, 13, 14 }
        drinkBP = "a weak alcoholic beverage"
    elseif string.find(strength, "virgin") then
        strengthTable = { 0, 6, 9, 10, 11, 12, 15, 18 }
        drinkBP = "a non-alcoholic beverage"
    end
    -- generate variables for insertion into custom drink template
    local drinkName = "((xcd " .. LOTJ.stripColor(drink)
    local drinkBlueprint = drinkBP
    local drinkShort = drink
    local drinkLong = drink .. " &Dhas been abandoned here."
    local randStrength = strengthTable[math.random(#strengthTable)]
    -- invoke the custom drink template ((xcd and insert new data
    local newDrink = Object.invoke(36691)
    newDrink:toChar(self)
    newDrink:setName(drinkName)
    newDrink:setBlueprint(drinkBlueprint)
    newDrink:setShortDescription(drinkShort)
    newDrink:setLongDescription(drinkLong)
    newDrink:setValue2(randStrength)
    -- pop out a cold one
    self:echo("&rThe sounds of sloshing and mixing emanate from {1} for a moment before it "..
        "dings and produces {2} upon its tray.&G", self, newDrink)
    newDrink:toChar(speaker)
    --else
    --    self:echo("&r{1} produces a single negatory beep.&G", self)
    --end
end)

-- trim whitespaces around a string
function trim(str)
    str = str:gsub("%s+", "")
    str = string.gsub(str, "%s+", "")
    return str
end

-- remove the first word from a given string
function removeFirstWord(str)
    str, i = str:gsub("1", "", 1)
    str = ( i > 0 ) and str or str:gsub("^.-%s", "", 1)
    return str
end
generated by LDoc 1.5.0 Last updated 2024-10-22 16:05:00