-
-
Notifications
You must be signed in to change notification settings - Fork 666
/
Copy pathdaily_reward.lua
101 lines (93 loc) · 2.77 KB
/
daily_reward.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
DAILY_REWARD_HP_REGENERATION = 2
DAILY_REWARD_MP_REGENERATION = 3
DAILY_REWARD_STAMINA_REGENERATION = 4
DAILY_REWARD_DOUBLE_HP_REGENERATION = 5
DAILY_REWARD_DOUBLE_MP_REGENERATION = 6
DAILY_REWARD_SOUL_REGENERATION = 7
DAILY_REWARD_FIRST = 2
DAILY_REWARD_LAST = 7
-- Global tables
DailyRewardBonus = {
Stamina = {},
Soul = {},
}
function RegenStamina(id, delay)
local staminaEvent = DailyRewardBonus.Stamina[id]
local player = Player(id)
if not player then
stopEvent(staminaEvent)
DailyRewardBonus.Stamina[id] = nil
return false
end
if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
local actualStamina = player:getStamina()
if actualStamina > 2340 and actualStamina < 2520 then
delay = 6 * 60 * 1000 -- Bonus stamina
end
if actualStamina < 2520 then
player:setStamina(actualStamina + 1)
player:sendTextMessage(MESSAGE_FAILURE, "One minute of stamina has been refilled.")
end
end
stopEvent(staminaEvent)
DailyRewardBonus.Stamina[id] = addEvent(RegenStamina, delay, id, delay)
return true
end
function RegenSoul(id, delay)
local soulEvent = DailyRewardBonus.Soul[id]
local player = Player(id)
if not player then
stopEvent(soulEvent)
DailyRewardBonus.Soul[id] = nil
return false
end
local maxsoul = 100
if (configManager.getBoolean(configKeys.VIP_SYSTEM_ENABLED) and player:isVip()) or player:isPremium() then
maxsoul = 200
end
if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
if player:getSoul() < maxsoul then
player:addSoul(1)
player:sendTextMessage(MESSAGE_FAILURE, "One soul point has been restored.")
end
end
stopEvent(soulEvent)
DailyRewardBonus.Soul[id] = addEvent(RegenSoul, delay, id, delay)
return true
end
function string.diff(self)
local format = {
{ "day", self / 60 / 60 / 24 },
{ "hour", self / 60 / 60 % 24 },
{ "minute", self / 60 % 60 },
{ "second", self % 60 },
}
local out = {}
for k, t in ipairs(format) do
local v = math.floor(t[2])
if v > 0 then
table.insert(out, (k < #format and (#out > 0 and ", " or "") or " and ") .. v .. " " .. t[1] .. (v ~= 1 and "s" or ""))
end
end
local ret = table.concat(out)
if ret:len() < 16 and ret:find("second") then
local a, b = ret:find(" and ")
ret = ret:sub(b + 1)
end
return ret
end
function GetDailyRewardLastServerSave()
return RetrieveGlobalStorage(DailyReward.storages.lastServerSave)
end
function UpdateDailyRewardGlobalStorage(key, value)
db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (" .. key .. ", " .. value .. ") ON DUPLICATE KEY UPDATE `value` = " .. value)
end
function RetrieveGlobalStorage(key)
local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key)
if resultId ~= false then
local val = Result.getNumber(resultId, "value")
Result.free(resultId)
return val
end
return 1
end