Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/elsongabriel/canary into ti…
Browse files Browse the repository at this point in the history
…tle-system-bkp

# Conflicts:
#	data/scripts/talkactions/god/manage_badge.lua
#	data/scripts/talkactions/god/manage_title.lua
#	src/canary_server.cpp
#	src/creatures/CMakeLists.txt
#	src/creatures/players/cyclopedia/player_badge.cpp
#	src/creatures/players/cyclopedia/player_badge.hpp
#	src/creatures/players/cyclopedia/player_title.cpp
#	src/creatures/players/cyclopedia/player_title.hpp
#	src/creatures/players/player.cpp
#	src/creatures/players/player.hpp
#	src/game/game.cpp
#	src/game/game.hpp
#	src/game/game_definitions.hpp
#	src/io/functions/iologindata_load_player.cpp
#	src/lua/functions/core/game/game_functions.cpp
#	src/lua/functions/creatures/player/player_functions.cpp
#	src/lua/functions/creatures/player/player_functions.hpp
#	src/server/network/protocol/protocolgame.cpp
#	src/server/network/protocol/protocolgame.hpp
#	src/server/server_definitions.hpp
#	vcproj/canary.vcxproj
  • Loading branch information
elsongabriel committed May 11, 2024
2 parents ffcdec3 + 529c7a4 commit d94ee0c
Show file tree
Hide file tree
Showing 48 changed files with 1,073 additions and 500 deletions.
4 changes: 2 additions & 2 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ resetSessionsOnStartup = false
-- Misc.
-- NOTE: experienceDisplayRates: set to false to ignore exp rate or true to include exp rate
-- NOTE: disableLegacyRaids: set to true to disable legacy XML raids
-- NOTE: combatChainDelay: set to minimum 50 miliseconds
allowChangeOutfit = true
toggleMountInProtectionZone = false
freePremium = false
Expand Down Expand Up @@ -430,7 +429,8 @@ maxElementalResistance = 200
maxDamageReflection = 200

-- Chain system
toggleChainSystem = true
-- NOTE: combatChainDelay: set to minimum 50 miliseconds
toggleChainSystem = false
combatChainDelay = 50
combatChainTargets = 5
combatChainSkillFormulaAxe = 0.9
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/migrations/43.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function onUpdateDatabase()
logger.info("Updating database to version 43 (feat frags_limit, payment and duration_days in guild wars)")
logger.info("Updating database to version 44 (feat frags_limit, payment and duration_days in guild wars)")

db.query([[
ALTER TABLE `guild_wars`
Expand Down
10 changes: 9 additions & 1 deletion data-otservbr-global/migrations/44.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
logger.info("Updating database to version 45 (fix: mana shield column size for more than 65k)")

db.query([[
ALTER TABLE `players`
MODIFY COLUMN `manashield` INT UNSIGNED NOT NULL DEFAULT '0',
MODIFY COLUMN `max_manashield` INT UNSIGNED NOT NULL DEFAULT '0';
]])

return true
end
3 changes: 3 additions & 0 deletions data-otservbr-global/migrations/45.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
end
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,26 @@ function teleportBoss.onStepIn(creature, item, position, fromPosition)
end
local player = creature
if player:getLevel() < config.requiredLevel then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to be level " .. config.requiredLevel .. " or higher.")
return true
end
if locked then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There's already someone fighting with " .. config.bossName .. ".")
return false
end
if zone:countPlayers(IgnoredByMonsters) >= 5 then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The boss room is full.")
return false
end
local timeLeft = player:getBossCooldown(config.bossName) - os.time()
if timeLeft > 0 then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have to wait " .. getTimeInWords(timeLeft) .. " to face " .. config.bossName .. " again!")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
Expand Down
36 changes: 22 additions & 14 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ local function useStaminaXpBoost(player)
return false
end

local staminaMinutes = player:getExpBoostStamina() / 60
if staminaMinutes == 0 then
local xpBoostMinutes = player:getXpBoostTime() / 60
if xpBoostMinutes == 0 then
return
end

Expand All @@ -156,18 +156,26 @@ local function useStaminaXpBoost(player)
return
end

local xpBoostLeftMinutesByDailyReward = player:kv():get("daily-reward-xp-boost") or 0
if timePassed > 60 then
if staminaMinutes > 2 then
staminaMinutes = staminaMinutes - 2
if xpBoostMinutes > 2 then
xpBoostMinutes = xpBoostMinutes - 2
if xpBoostLeftMinutesByDailyReward > 2 then
player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 2)
end
else
staminaMinutes = 0
xpBoostMinutes = 0
player:kv():remove("daily-reward-xp-boost")
end
_G.NextUseXpStamina[playerId] = currentTime + 120
else
staminaMinutes = staminaMinutes - 1
xpBoostMinutes = xpBoostMinutes - 1
if xpBoostLeftMinutesByDailyReward > 0 then
player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 1)
end
_G.NextUseXpStamina[playerId] = currentTime + 60
end
player:setExpBoostStamina(staminaMinutes * 60)
player:setXpBoostTime(xpBoostMinutes * 60)
end

local function useConcoctionTime(player)
Expand Down Expand Up @@ -519,14 +527,14 @@ function Player:onGainExperience(target, exp, rawExp)
self:addCondition(soulCondition)
end

-- Store Bonus
useStaminaXpBoost(self) -- Use store boost stamina
-- XP Boost Bonus
useStaminaXpBoost(self) -- Use stamina XP boost (store or daily reward)

local Boost = self:getExpBoostStamina()
local stillHasBoost = Boost > 0
local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0
local xpBoostTimeLeft = self:getXpBoostTime()
local stillHasXpBoost = xpBoostTimeLeft > 0
local xpBoostPercent = stillHasXpBoost and self:getXpBoostPercent() or 0

self:setStoreXpBoost(storeXpBoostAmount)
self:setXpBoostPercent(xpBoostPercent)

-- Stamina Bonus
local staminaBonusXp = 1
Expand Down Expand Up @@ -564,7 +572,7 @@ function Player:onGainExperience(target, exp, rawExp)
local lowLevelBonuxExp = self:getFinalLowLevelBonus()
local baseRate = self:getFinalBaseRateExperience()

return (exp + (exp * (storeXpBoostAmount / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate
return (exp + (exp * (xpBoostPercent / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate
end

function Player:onLoseExperience(exp)
Expand Down
4 changes: 4 additions & 0 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75422,6 +75422,7 @@ Granted by TibiaGoals.com"/>
<attribute key="firemagiclevelpoints" value="1"/>
<attribute key="energymagiclevelpoints" value="1"/>
<attribute key="criticalhitdamage" value="1200"/>
<attribute key="range" value="6"/>
<attribute key="criticalhitchance" value="1000"/>
<attribute key="weight" value="2200"/>
<attribute key="imbuementslot" value="2">
Expand Down Expand Up @@ -75449,6 +75450,7 @@ Granted by TibiaGoals.com"/>
<attribute key="magiclevelpoints" value="5"/>
<attribute key="firemagiclevelpoints" value="1"/>
<attribute key="energymagiclevelpoints" value="1"/>
<attribute key="range" value="6"/>
<attribute key="criticalhitdamage" value="1200"/>
<attribute key="criticalhitchance" value="1000"/>
<attribute key="weight" value="2100"/>
Expand Down Expand Up @@ -75492,6 +75494,7 @@ Granted by TibiaGoals.com"/>
<attribute key="weaponType" value="wand"/>
<attribute key="shootType" value="earth"/>
<attribute key="absorbpercentdeath" value="7"/>
<attribute key="range" value="6"/>
<attribute key="magiclevelpoints" value="5"/>
<attribute key="earthmagiclevelpoints" value="1"/>
<attribute key="icemagiclevelpoints" value="1"/>
Expand Down Expand Up @@ -75522,6 +75525,7 @@ Granted by TibiaGoals.com"/>
<attribute key="absorbpercentdeath" value="7"/>
<attribute key="magiclevelpoints" value="5"/>
<attribute key="earthmagiclevelpoints" value="1"/>
<attribute key="range" value="6"/>
<attribute key="icemagiclevelpoints" value="1"/>
<attribute key="criticalhitdamage" value="500"/>
<attribute key="criticalhitchance" value="1000"/>
Expand Down
11 changes: 9 additions & 2 deletions data/modules/scripts/daily_reward/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,15 @@ function Player.selectDailyReward(self, msg)
end
dailyRewardMessage = "Picked items: " .. description
elseif dailyTable.type == DAILY_REWARD_TYPE_XP_BOOST then
self:setExpBoostStamina(self:getExpBoostStamina() + (rewardCount * 60))
self:setStoreXpBoost(50)
local rewardCountReviewed = rewardCount
local xpBoostLeftMinutes = self:kv():get("daily-reward-xp-boost") or 0
if xpBoostLeftMinutes > 0 then
rewardCountReviewed = rewardCountReviewed - xpBoostLeftMinutes
end

self:setXpBoostTime(self:getXpBoostTime() + (rewardCountReviewed * 60))
self:kv():set("daily-reward-xp-boost", rewardCount)
self:setXpBoostPercent(50)
dailyRewardMessage = "Picked reward: XP Bonus for " .. rewardCount .. " minutes."
elseif dailyTable.type == DAILY_REWARD_TYPE_PREY_REROLL then
self:addPreyCards(rewardCount)
Expand Down
8 changes: 4 additions & 4 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ function Player.canBuyOffer(self, offer)
disabled = 1
disabledReason = "You can't buy XP Boost for today."
end
if self:getExpBoostStamina() > 0 then
if self:getXpBoostTime() > 0 then
disabled = 1
disabledReason = "You already have an active XP boost."
end
Expand Down Expand Up @@ -1769,11 +1769,11 @@ function GameStore.processSexChangePurchase(player)
end

function GameStore.processExpBoostPurchase(player)
local currentExpBoostTime = player:getExpBoostStamina()
local currentXpBoostTime = player:getXpBoostTime()
local expBoostCount = player:getStorageValue(GameStore.Storages.expBoostCount)

player:setStoreXpBoost(50)
player:setExpBoostStamina(currentExpBoostTime + 3600)
player:setXpBoostPercent(50)
player:setXpBoostTime(currentXpBoostTime + 3600)

if expBoostCount == -1 or expBoostCount == 6 then
expBoostCount = 1
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/actions/items/exercise_training_weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ end
local exerciseTraining = Action()

function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target or not target:getId() then
if not target or type(target) == "table" or not target:getId() then
return true
end

Expand Down
3 changes: 1 addition & 2 deletions data/scripts/talkactions/god/add_skill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ function addSkill.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace()

local count = 1
if split[3] then
Expand Down
8 changes: 4 additions & 4 deletions data/scripts/talkactions/god/charms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function addCharm.onSay(player, words, param)
player:sendCancelMessage("A player with that name is not online.")
return true
end
--trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")

split[2] = split[2]:trimSpace()

player:sendCancelMessage("Added " .. split[2] .. " charm points to character '" .. target:getName() .. "'.")
target:sendCancelMessage("Received " .. split[2] .. " charm points!")
Expand Down Expand Up @@ -133,8 +133,8 @@ function setBestiary.onSay(player, words, param)
return true
end

split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left
split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left
split[2] = split[2]:trimSpace()
split[3] = split[3]:trimSpace()

local monsterName = split[2]
local mType = MonsterType(monsterName)
Expand Down
6 changes: 3 additions & 3 deletions data/scripts/talkactions/god/create_monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ function createMonster.onSay(player, words, param)
local monsterName = split[1]
local monsterCount = 0
if split[2] then
split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left
split[2] = split[2]:trimSpace()
monsterCount = tonumber(split[2])
end

local monsterForge = nil
if split[3] then
split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left
split[3] = split[3]:trimSpace()
monsterForge = split[3]
end

if monsterCount > 1 then
local spawnRadius = 5
if split[4] then
split[4] = split[4]:gsub("^%s*(.-)$", "%1") --Trim left
split[4] = split[4]:trimSpace()
spawnRadius = split[4]
print(spawnRadius)
end
Expand Down
8 changes: 5 additions & 3 deletions data/scripts/talkactions/god/manage_badge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ function addBadge.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace()
local id = tonumber(split[2])
target:addBadge(id)
if target:addBadge(id) then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format('You added a badge with ID "%i" to player "%s".', id, target:getName()))
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s added a badge to you.", player:getName()))
end
return true
end

Expand Down
3 changes: 1 addition & 2 deletions data/scripts/talkactions/god/manage_storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ function Player.getStorageValueTalkaction(self, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace()

-- Try to convert the second parameter to a number. If it's not a number, treat it as a storage name
local storageKey = tonumber(split[2])
Expand Down
12 changes: 7 additions & 5 deletions data/scripts/talkactions/god/manage_title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ function addTitle.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace()
local id = tonumber(split[2])
target:addTitle(id)
if target:addTitle(id) then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format('You added a title with ID "%i" to player "%s".', id, target:getName()))
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s added a title to you.", player:getName()))
end

return true
end

Expand Down Expand Up @@ -56,8 +59,7 @@ function setTitle.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace()
local id = tonumber(split[2])
target:setCurrentTitle(id)
return true
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS `server_config` (
CONSTRAINT `server_config_pk` PRIMARY KEY (`config`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '44'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');
INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '45'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');

-- Table structure `accounts`
CREATE TABLE IF NOT EXISTS `accounts` (
Expand Down Expand Up @@ -127,8 +127,8 @@ CREATE TABLE IF NOT EXISTS `players` (
`skill_lifeleech_amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`skill_manaleech_chance` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`skill_manaleech_amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0',
`max_manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0',
`manashield` INT UNSIGNED NOT NULL DEFAULT '0',
`max_manashield` INT UNSIGNED NOT NULL DEFAULT '0',
`xpboost_stamina` smallint(5) UNSIGNED DEFAULT NULL,
`xpboost_value` tinyint(4) UNSIGNED DEFAULT NULL,
`marriage_status` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
Expand Down
1 change: 1 addition & 0 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ void CanaryServer::loadModules() {
g_game().loadBoostedCreature();
g_ioBosstiary().loadBoostedBoss();
g_ioprey().initializeTaskHuntOptions();
g_game().logCyclopediaStats();
g_game().getCyclopediaStatistics();
}

Expand Down
4 changes: 4 additions & 0 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ CombatDamage Combat::applyImbuementElementalDamage(std::shared_ptr<Player> attac
continue;
}

if (damage.primary.type != COMBAT_PHYSICALDAMAGE) {
break;
}

float damagePercent = imbuementInfo.imbuement->elementDamage / 100.0;

damage.secondary.type = imbuementInfo.imbuement->combatType;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ void ConditionManaShield::addCondition(std::shared_ptr<Creature> creature, const

bool ConditionManaShield::unserializeProp(ConditionAttr_t attr, PropStream &propStream) {
if (attr == CONDITIONATTR_MANASHIELD) {
return propStream.read<uint16_t>(manaShield);
return propStream.read<uint32_t>(manaShield);
}
return Condition::unserializeProp(attr, propStream);
}
Expand All @@ -1317,7 +1317,7 @@ void ConditionManaShield::serialize(PropWriteStream &propWriteStream) {
Condition::serialize(propWriteStream);

propWriteStream.write<uint8_t>(CONDITIONATTR_MANASHIELD);
propWriteStream.write<uint16_t>(manaShield);
propWriteStream.write<uint32_t>(manaShield);
}

bool ConditionManaShield::setParam(ConditionParam_t param, int32_t value) {
Expand Down
Loading

0 comments on commit d94ee0c

Please sign in to comment.