mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-04-30 01:29:21 +02:00
Merge branch '6-introduce-stamina-in-the-server-side' into 'master'
Resolve "Introduce stamina in the server-side" Closes #6 See merge request ErikasKontenis/Sabrehaven!11
This commit is contained in:
commit
ae7672ee55
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<creaturescripts>
|
||||
<event type="login" name="PlayerLogin" script="login.lua"/>
|
||||
<event type="logout" name="PlayerLogout" script="logout.lua" />
|
||||
<event type="login" name="FirstItems" script="firstitems.lua"/>
|
||||
<event type="login" name="RegenerateStamina" script="regeneratestamina.lua" />
|
||||
<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
|
||||
</creaturescripts>
|
||||
|
@ -12,6 +12,9 @@ function onLogin(player)
|
||||
end
|
||||
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
|
||||
|
||||
-- Stamina
|
||||
nextUseStaminaTime[player.uid] = 0
|
||||
|
||||
-- Promotion
|
||||
if player:isPremium() then
|
||||
if player:getVocation():getId() ~= 0 and player:getVocation():getId() < 5 and player:getStorageValue(30018) == 1 then
|
||||
|
7
data/creaturescripts/scripts/logout.lua
Normal file
7
data/creaturescripts/scripts/logout.lua
Normal file
@ -0,0 +1,7 @@
|
||||
function onLogout(player)
|
||||
local playerId = player:getId()
|
||||
if nextUseStaminaTime[playerId] then
|
||||
nextUseStaminaTime[playerId] = nil
|
||||
end
|
||||
return true
|
||||
end
|
@ -3,6 +3,9 @@ local maxDeathRecords = 50
|
||||
|
||||
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
|
||||
local playerId = player:getId()
|
||||
if nextUseStaminaTime[playerId] then
|
||||
nextUseStaminaTime[playerId] = nil
|
||||
end
|
||||
|
||||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.")
|
||||
|
||||
|
27
data/creaturescripts/scripts/regeneratestamina.lua
Normal file
27
data/creaturescripts/scripts/regeneratestamina.lua
Normal file
@ -0,0 +1,27 @@
|
||||
function onLogin(player)
|
||||
if not configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
|
||||
return true
|
||||
end
|
||||
|
||||
local lastLogout = player:getLastLogout()
|
||||
local offlineTime = lastLogout ~= 0 and math.min(os.time() - lastLogout, 86400 * 21) or 0
|
||||
offlineTime = offlineTime - 600
|
||||
|
||||
if offlineTime < 180 then
|
||||
return true
|
||||
end
|
||||
|
||||
local staminaMinutes = player:getStamina()
|
||||
local maxNormalStaminaRegen = 3240 - math.min(3240, staminaMinutes)
|
||||
|
||||
local regainStaminaMinutes = offlineTime / 180
|
||||
if regainStaminaMinutes > maxNormalStaminaRegen then
|
||||
local happyHourStaminaRegen = (offlineTime - (maxNormalStaminaRegen * 180)) / 600
|
||||
staminaMinutes = math.min(3360, math.max(3240, staminaMinutes) + happyHourStaminaRegen)
|
||||
else
|
||||
staminaMinutes = staminaMinutes + regainStaminaMinutes
|
||||
end
|
||||
|
||||
player:setStamina(staminaMinutes)
|
||||
return true
|
||||
end
|
@ -135,6 +135,33 @@ local soulCondition = Condition(CONDITION_SOUL, CONDITIONID_DEFAULT)
|
||||
soulCondition:setTicks(4 * 60 * 1000)
|
||||
soulCondition:setParameter(CONDITION_PARAM_SOULGAIN, 1)
|
||||
|
||||
local function useStamina(player)
|
||||
local staminaMinutes = player:getStamina()
|
||||
if staminaMinutes == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local playerId = player:getId()
|
||||
local currentTime = os.time()
|
||||
local timePassed = currentTime - nextUseStaminaTime[playerId]
|
||||
if timePassed <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if timePassed > 60 then
|
||||
if staminaMinutes > 2 then
|
||||
staminaMinutes = staminaMinutes - 2
|
||||
else
|
||||
staminaMinutes = 0
|
||||
end
|
||||
nextUseStaminaTime[playerId] = currentTime + 120
|
||||
else
|
||||
staminaMinutes = staminaMinutes - 1
|
||||
nextUseStaminaTime[playerId] = currentTime + 60
|
||||
end
|
||||
player:setStamina(staminaMinutes)
|
||||
end
|
||||
|
||||
function Player:onGainExperience(source, exp, rawExp)
|
||||
if not source or source:isPlayer() then
|
||||
return exp
|
||||
@ -150,6 +177,18 @@ function Player:onGainExperience(source, exp, rawExp)
|
||||
-- Apply experience stage multiplier
|
||||
exp = exp * Game.getExperienceStage(self:getLevel())
|
||||
|
||||
-- Stamina modifier
|
||||
if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
|
||||
useStamina(self)
|
||||
|
||||
local staminaMinutes = self:getStamina()
|
||||
if staminaMinutes > 2400 and self:isPremium() then
|
||||
exp = exp * 1.5
|
||||
elseif staminaMinutes <= 840 then
|
||||
exp = exp * 0.5
|
||||
end
|
||||
end
|
||||
|
||||
return exp
|
||||
end
|
||||
|
||||
|
@ -45,3 +45,7 @@ end
|
||||
function isNumber(str)
|
||||
return tonumber(str) ~= nil
|
||||
end
|
||||
|
||||
if not nextUseStaminaTime then
|
||||
nextUseStaminaTime = {}
|
||||
end
|
@ -19,7 +19,7 @@ SET time_zone = "+00:00";
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Database: `nostalrius`
|
||||
-- Database: `sabrehaven`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
@ -1171,8 +1171,8 @@ CREATE TABLE `players` (
|
||||
--
|
||||
|
||||
INSERT INTO `players` (`id`, `name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `skull`, `skulltime`, `lastlogout`, `blessings`, `onlinetime`, `deletion`, `balance`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `deleted`) VALUES
|
||||
(1, 'GM Nostalrius', 3, 1234567, 2, 0, 155, 155, 105, 106, 95, 78, 58, 75, 100, 5, 5, 0, 100, 1, 32370, 32231, 7, '', 405, 0, 1547336581, 75260863, 1, 0, 0, 1547336668, 0, 7631, 0, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 0),
|
||||
(2, 'GM Nostalrius 2', 3, 1234567, 2, 0, 155, 155, 105, 106, 95, 78, 58, 75, 0, 5, 5, 0, 100, 10, 33211, 31646, 13, 0x018000000002000000000360361e001c0000000013d70000001408000000151027000016aecb0300fe, 405, 0, 1547183307, 75260863, 1, 0, 0, 1547183320, 0, 781, 0, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 0),
|
||||
(1, 'GM Sabrehaven', 3, 1234567, 2, 0, 155, 155, 105, 106, 95, 78, 58, 75, 100, 5, 5, 0, 100, 1, 32370, 32231, 7, '', 405, 0, 1547336581, 75260863, 1, 0, 0, 1547336668, 0, 7631, 0, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 0),
|
||||
(2, 'GM Sabrehaven 2', 3, 1234567, 2, 0, 155, 155, 105, 106, 95, 78, 58, 75, 0, 5, 5, 0, 100, 10, 33211, 31646, 13, 0x018000000002000000000360361e001c0000000013d70000001408000000151027000016aecb0300fe, 405, 0, 1547183307, 75260863, 1, 0, 0, 1547183320, 0, 781, 0, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 0),
|
||||
(3, 'Mage', 1, 1234567, 89, 2, 1171, 2045, 10982400, 106, 95, 78, 58, 128, 62, 10, 4770, 7200, 2, 1, 32367, 32230, 7, '', 1490, 232, 1547334403, 75260863, 1, 0, 0, 1547335694, 0, 7330, 0, 0, 10, 0, 10, 19, 10, 0, 10, 0, 10, 0, 39, 10439596, 10, 0, 0);
|
||||
|
||||
--
|
Loading…
x
Reference in New Issue
Block a user