Module:Number: Difference between revisions

no edit summary
(Force removal of scientific notation on formatnum)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 232: Line 232:
end
end


-- Creates a TimeSpan object from a total amount of seconds.
-- Returns the probability of getting at least one drop, provided
function p.secondsToTimeSpan(totalSeconds)
-- the drop rate and the current amount of drops.
return p.actionTimeToTimeSpan(totalSeconds * 100)
function p.getDropProbability(dropRate, totalDrops)
dropRate = p.clamp(dropRate, 0, 1)
return 1 - (1- dropRate) ^ 500
end
end


--- Creates a TimeSpan object from action time (hundreds of a second).
-- Returns the amount of drops required for a certain drop probability.
-- @param str (number) The amount of action time to convert to a TimeSpan
function p.getDropsForProbability(dropRate, probability)
-- @return (TimeSpan) A TimeSpan object containing the seconds, minutes, hours and days the input amount of action time amounts to.
dropRate = p.clamp(dropRate, 0, 1)
function p.actionTimeToTimeSpan(totalActionTime)
probability = p.clamp(probability, 0, 1)
    local days = math.floor(totalActionTime / 8640000)
    local remainder = totalActionTime % 8640000
return math.log(1 - probability) / math.log(1 - dropRate)
 
    local hours = math.floor(remainder / 360000)
    remainder = remainder % 360000
 
    local minutes = math.floor(remainder / 6000)
    remainder = remainder % 6000
   
    local seconds = math.floor(remainder / 100)
 
    return {
        days = days,
        hours = hours,
        minutes = minutes,
        seconds = seconds,
       
        totalDays = totalActionTime / 8640000,
        totalHours = totalActionTime / 360000,
        totalMinutes = totalActionTime / 6000,
        totalSeconds = totalActionTime / 100
    }
end
end


return p
return p
915

edits