2013-11-30 14:32:25 +01:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- Mob Framework Mod by Sapier
|
|
|
|
--
|
|
|
|
-- You may copy, use, modify or do nearly anything except removing this
|
|
|
|
-- copyright notice.
|
|
|
|
-- And of course you are NOT allow to pretend you have written it.
|
|
|
|
--
|
|
|
|
--! @file step_quota.lua
|
|
|
|
--! @brief class containing mobf step quota handling
|
|
|
|
--! @copyright Sapier
|
|
|
|
--! @author Sapier
|
|
|
|
--! @date 2013-11-30
|
|
|
|
--
|
|
|
|
-- Contact sapier a t gmx net
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
mobf_assert_backtrace(mobf_step_quota == nil)
|
|
|
|
|
|
|
|
--! @class mobf_step_quota
|
|
|
|
--! @brief step_quota handling
|
|
|
|
mobf_step_quota = {}
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
2013-12-01 11:50:07 +01:00
|
|
|
-- @function [parent=#mobf_step_quota] is_exceeded
|
2013-11-30 14:32:25 +01:00
|
|
|
--
|
|
|
|
--! @brief check if quota is exceeded
|
|
|
|
--! @memberof mobf_step_quota
|
|
|
|
--! @public
|
|
|
|
--
|
|
|
|
--! @return true == exceeded false == not exceeded
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
function mobf_step_quota.is_exceeded()
|
|
|
|
return mobf_step_quota.remaining_quota <= 0
|
|
|
|
end
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
2013-12-01 11:50:07 +01:00
|
|
|
-- @function [parent=#mobf_step_quota] remaining()
|
2013-11-30 14:32:25 +01:00
|
|
|
--
|
|
|
|
--! @brief get remaining time this quota
|
|
|
|
--! @memberof mobf_step_quota
|
|
|
|
--! @public
|
|
|
|
--
|
|
|
|
--! @return time left
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
function mobf_step_quota.remaining()
|
|
|
|
if mobf_step_quota.remaining_quota >= 0 then
|
|
|
|
return mobf_step_quota.remaining_quota
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
2013-12-01 11:50:07 +01:00
|
|
|
-- @function [parent=#mobf_step_quota] initialize()
|
2013-11-30 14:32:25 +01:00
|
|
|
--
|
|
|
|
--! @brief initialize quota handling
|
|
|
|
--! @memberof mobf_step_quota
|
|
|
|
--! @public
|
|
|
|
--
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
function mobf_step_quota.initialize()
|
|
|
|
--todo add setting
|
|
|
|
mobf_step_quota.reload_value = 50
|
|
|
|
minetest.register_globalstep(mobf_step_quota.reload)
|
|
|
|
end
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
2013-12-01 11:50:07 +01:00
|
|
|
-- @function [parent=#mobf_step_quota] reload()
|
2013-11-30 14:32:25 +01:00
|
|
|
--
|
|
|
|
--! @brief reload current quota
|
|
|
|
--! @memberof mobf_step_quota
|
|
|
|
--! @public
|
|
|
|
--
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
function mobf_step_quota.reload()
|
|
|
|
mobf_step_quota.remaining_quota = mobf_step_quota.reload_value
|
|
|
|
end
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
2013-12-01 11:50:07 +01:00
|
|
|
-- @function [parent=#mobf_step_quota] cosume(starttime)
|
2013-11-30 14:32:25 +01:00
|
|
|
--
|
|
|
|
--! @brief reduce remaining quota by time passed
|
|
|
|
--! @memberof mobf_step_quota
|
|
|
|
--! @public
|
|
|
|
--
|
|
|
|
--! @param starttime time this operation started
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
function mobf_step_quota.consume(starttime)
|
|
|
|
local now = mobf_get_time_ms()
|
|
|
|
local passed = now - starttime
|
|
|
|
|
2013-12-02 23:18:53 +01:00
|
|
|
if passed >= 0 then
|
2013-11-30 14:32:25 +01:00
|
|
|
mobf_step_quota.remaining_quota = mobf_step_quota.remaining_quota - passed
|
|
|
|
else
|
2013-12-02 23:18:53 +01:00
|
|
|
--mobf_print("MOBF: error calculation consumed time: " .. starttime .. " --> " .. now)
|
2013-11-30 14:32:25 +01:00
|
|
|
end
|
|
|
|
end
|