-
-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing librarys; daily reward, modal windows and reward boss (#294)
Added somes missing librarys: daily reward, modal window, reward boss Added new scripts for: monsters and spells Resolves #276
- Loading branch information
Showing
380 changed files
with
23,421 additions
and
1,815 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
if not ModalWindows then | ||
ModalWindows = { | ||
ModalWindowConstructor = ModalWindow, | ||
NextFreeId = 500, | ||
|
||
Windows = {} | ||
} | ||
end | ||
|
||
local MT = {} | ||
MT.__index = MT | ||
|
||
function ModalWindow(...) | ||
local args = {...} | ||
if type(args[1]) == 'table' then | ||
local self = setmetatable(args[1], MT) | ||
local id = ModalWindows.NextFreeId | ||
self.id = id | ||
self.buttons = {} | ||
self.choices = {} | ||
self.players = {} | ||
self.created = false | ||
|
||
ModalWindows.NextFreeId = id + 1 | ||
table.insert(ModalWindows.Windows, self) | ||
return self | ||
end | ||
|
||
return ModalWindows.ModalWindowConstructor(...) | ||
end | ||
|
||
function MT:setDefaultCallback(callback) | ||
self.defaultCallback = callback | ||
end | ||
|
||
function MT:addButton(text, callback) | ||
local button = {text = tostring(text), callback = callback} | ||
table.insert(self.buttons, button) | ||
return button | ||
end | ||
|
||
function MT:addButtons(...) | ||
for _, text in ipairs({...}) do | ||
table.insert(self.buttons, {text = tostring(text)}) | ||
end | ||
end | ||
|
||
function MT:addChoice(text) | ||
local choice = {text = tostring(text)} | ||
table.insert(self.choices, choice) | ||
return choice | ||
end | ||
|
||
function MT:addChoices(...) | ||
for _, text in ipairs({...}) do | ||
table.insert(self.choices, {text = tostring(text)}) | ||
end | ||
end | ||
|
||
function MT:setDefaultEnterButton(text) | ||
self.defaultEnterButton = text | ||
end | ||
|
||
function MT:setDefaultEscapeButton(text) | ||
self.defaultEscapeButton = text | ||
end | ||
|
||
function MT:setTitle(title) | ||
self.title = tostring(title) | ||
end | ||
|
||
function MT:setMessage(message) | ||
self.message = tostring(message) | ||
end | ||
|
||
local buttonOrder = { | ||
[4] = {3, 4, 2, 1}, | ||
[3] = {2, 3, 1}, | ||
[2] = {1, 2}, | ||
[1] = {1} | ||
} | ||
function MT:create() | ||
local modalWindow = ModalWindows.ModalWindowConstructor(self.id, self.title, self.message) | ||
local order = buttonOrder[math.min(#self.buttons, 4)] | ||
|
||
if order then | ||
for _, i in ipairs(order) do | ||
local button = self.buttons[i] | ||
modalWindow:addButton(i, button.text) | ||
button.id = i | ||
|
||
if button.text == self.defaultEnterButton then | ||
modalWindow:setDefaultEnterButton(i) | ||
elseif button.text == self.defaultEscapeButton then | ||
modalWindow:setDefaultEscapeButton(i) | ||
end | ||
end | ||
end | ||
|
||
for _, choice in ipairs(self.choices) do | ||
modalWindow:addChoice(_, choice.text) | ||
choice.id = _ | ||
end | ||
|
||
self.modalWindow = modalWindow | ||
end | ||
|
||
function MT:sendToPlayer(player) | ||
if not self.modalWindow then | ||
self:create() | ||
end | ||
|
||
player:registerEvent('ModalWindowHelper') | ||
self.players[player:getId()] = true | ||
return self.modalWindow:sendToPlayer(player) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
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 maxsoul = 0 | ||
local player = Player(id) | ||
if not player then | ||
stopEvent(soulEvent) | ||
DailyRewardBonus.Soul[id] = nil | ||
return false | ||
end | ||
if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then | ||
if player:isPremium() then | ||
maxsoul = 200 | ||
else | ||
maxsoul = 100 | ||
end | ||
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 |
Oops, something went wrong.