Skip to content

Commit

Permalink
Add missing librarys; daily reward, modal windows and reward boss (#294)
Browse files Browse the repository at this point in the history
Added somes missing librarys: daily reward, modal window, reward boss
Added new scripts for: monsters and spells

Resolves #276
  • Loading branch information
dudantas committed Apr 17, 2022
1 parent 0e75d7b commit c45f1d2
Show file tree
Hide file tree
Showing 380 changed files with 23,421 additions and 1,815 deletions.
8 changes: 8 additions & 0 deletions data/events/scripts/monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ function Monster:onDropLoot(corpse)
return
end

-- Register reward function from reward boss lib
self:registerRewardBoss(corpse)

local player = Player(corpse:getCorpseOwner())
local mType = self:getType()
if not player or player:getStamina() > 840 then
Expand Down Expand Up @@ -33,3 +36,8 @@ function Monster:onDropLoot(corpse)
end
end
end

function Monster:onSpawn(position)
-- Register reward function from reward boss lib
self:setRewardBoss()
end
3 changes: 3 additions & 0 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
end
end

-- Execute event function from reward boss lib
self:executeRewardEvents(item, toPosition)

return true
end

Expand Down
1 change: 1 addition & 0 deletions data/lib/core/functions/load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dofile('data/lib/core/functions/functions.lua')
dofile('data/lib/core/functions/game.lua')
dofile('data/lib/core/functions/item.lua')
dofile('data/lib/core/functions/itemtype.lua')
dofile('data/lib/core/functions/modal_window.lua')
dofile('data/lib/core/functions/monster.lua')
dofile('data/lib/core/functions/party.lua')
dofile('data/lib/core/functions/player.lua')
Expand Down
116 changes: 116 additions & 0 deletions data/lib/core/functions/modal_window.lua
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
61 changes: 30 additions & 31 deletions data/lib/core/functions/player.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-- Functions from The Forgotten Server
local foodCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)

function Player.feed(self, food)
local condition = self:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
Expand All @@ -11,6 +9,7 @@ function Player.feed(self, food)
return nil
end

local foodCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
foodCondition:setTicks(food * 1000)
foodCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, vocation:getHealthGainAmount())
foodCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, vocation:getHealthGainTicks())
Expand Down Expand Up @@ -272,35 +271,35 @@ function Player.getMarriageDescription(thing)
end

function Player.sendWeatherEffect(self, groundEffect, fallEffect, thunderEffect)
local position, random = self:getPosition(), math.random
position.x = position.x + random(-7, 7)
position.y = position.y + random(-5, 5)
local fromPosition = Position(position.x + 1, position.y, position.z)
fromPosition.x = position.x - 7
fromPosition.y = position.y - 5
local tile, getGround
for Z = 1, 7 do
fromPosition.z = Z
position.z = Z
tile = Tile(position)
if tile then -- If there is a tile, stop checking floors
fromPosition:sendDistanceEffect(position, fallEffect)
local position, random = self:getPosition(), math.random
position.x = position.x + random(-7, 7)
position.y = position.y + random(-5, 5)
local fromPosition = Position(position.x + 1, position.y, position.z)
fromPosition.x = position.x - 7
fromPosition.y = position.y - 5
local tile, getGround
for Z = 1, 7 do
fromPosition.z = Z
position.z = Z
tile = Tile(position)
if tile then -- If there is a tile, stop checking floors
fromPosition:sendDistanceEffect(position, fallEffect)
position:sendMagicEffect(groundEffect, self)
getGround = tile:getGround()
if getGround and ItemType(getGround:getId()):getFluidSource() == 1 then
position:sendMagicEffect(CONST_ME_LOSEENERGY, self)
end
break
end
end
if thunderEffect and tile and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
if random(2) == 1 then
local topCreature = tile:getTopCreature()
if topCreature and topCreature:isPlayer() and topCreature:getAccountType() < ACCOUNT_TYPE_SENIORTUTOR then
position:sendMagicEffect(CONST_ME_BIGCLOUDS, self)
doTargetCombatHealth(0, self, COMBAT_ENERGYDAMAGE, -weatherConfig.minDMG, -weatherConfig.maxDMG, CONST_ME_NONE)
--self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You were hit by lightning and lost some health.")
end
end
end
if getGround and ItemType(getGround:getId()):getFluidSource() == 1 then
position:sendMagicEffect(CONST_ME_LOSEENERGY, self)
end
break
end
end
if thunderEffect and tile and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
if random(2) == 1 then
local topCreature = tile:getTopCreature()
if topCreature and topCreature:isPlayer() and topCreature:getAccountType() < ACCOUNT_TYPE_SENIORTUTOR then
position:sendMagicEffect(CONST_ME_BIGCLOUDS, self)
doTargetCombatHealth(0, self, COMBAT_ENERGYDAMAGE, -weatherConfig.minDMG, -weatherConfig.maxDMG, CONST_ME_NONE)
--self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You were hit by lightning and lost some health.")
end
end
end
end
29 changes: 29 additions & 0 deletions data/lib/core/functions/position.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,32 @@ function Position:removeItem(itemId, effect)
Position(self):sendMagicEffect(effect)
end
end

function Position:relocateTo(toPos)
if self == toPos then
return false
end

local fromTile = Tile(self)
if fromTile == nil then
return false
end

if Tile(toPos) == nil then
return false
end

for i = fromTile:getThingCount() - 1, 0, -1 do
local thing = fromTile:getThing(i)
if thing then
if thing:isItem() then
if ItemType(thing:getId()):isMovable() then
thing:moveTo(toPos)
end
elseif thing:isCreature() then
thing:teleportTo(toPos)
end
end
end
return true
end
103 changes: 103 additions & 0 deletions data/lib/daily_reward/daily_reward.lua
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

0 comments on commit c45f1d2

Please sign in to comment.