Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 committed Nov 19, 2024
2 parents b9dcdcb + e0cee27 commit b17dad3
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 117 deletions.
2 changes: 1 addition & 1 deletion data-canary/scripts/actions/other/destroy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ local setting = {
local destroy = Action()

function destroy.onUse(player, item, fromPosition, target, toPosition, isHotkey)
return ActionsLib.destroyItem(player, target, toPosition)
return destroyItem(player, target, toPosition)
end

for index, value in ipairs(setting) do
Expand Down
12 changes: 0 additions & 12 deletions data-canary/scripts/actions/other/sewer.lua

This file was deleted.

6 changes: 3 additions & 3 deletions data-otservbr-global/lib/quests/soul_war.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ function Player:getSoulWarZoneMonster()
return zoneMonsterName
end

function Player:isInBoatSpot()
function Creature:isInBoatSpot()
-- Get ebb and flow zone and check if player is in zone
local zone = SoulWarQuest.ebbAndFlow.getZone()
local tile = Tile(self:getPosition())
Expand All @@ -1464,11 +1464,11 @@ function Player:isInBoatSpot()
groundId = tile:getGround():getId()
end
if zone and zone:isInZone(self:getPosition()) and tile and groundId == SoulWarQuest.ebbAndFlow.boatId then
logger.trace("Player {} is in boat spot", self:getName())
logger.trace("Creature {} is in boat spot", self:getName())
return true
end

logger.trace("Player {} is not in boat spot", self:getName())
logger.trace("Creature {} is not in boat spot", self:getName())
return false
end

Expand Down
19 changes: 0 additions & 19 deletions data-otservbr-global/scripts/actions/other/teleport.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,25 @@ local function updateWaterPoolsSize()
end

local function loadMapEmpty()
if SoulWarQuest.ebbAndFlow.getZone():countPlayers() > 0 then
local players = SoulWarQuest.ebbAndFlow.getZone():getPlayers()
for _, player in ipairs(players) do
if player:getPosition().z == 8 then
if player:isInBoatSpot() then
local teleportPosition = player:getPosition()
teleportPosition.z = 9
player:teleportTo(teleportPosition)
logger.trace("Teleporting player to down.")
local playersInZone = SoulWarQuest.ebbAndFlow.getZone():countPlayers()
local monstersInZone = SoulWarQuest.ebbAndFlow.getZone():countMonsters()
if playersInZone > 0 or monstersInZone > 0 then
local creatures = SoulWarQuest.ebbAndFlow.getZone():getCreatures()
for _, creature in ipairs(creatures) do
local creatureMaster = creature:getMaster()
local player = creature:getPlayer()
if creature:isPlayer() or (creature:isMonster() and creatureMaster and creatureMaster:getPlayer()) then
if creature:getPosition().z == 8 then
if creature:isInBoatSpot() then
local teleportPosition = creature:getPosition()
teleportPosition.z = 9
creature:teleportTo(teleportPosition)
logger.trace("Teleporting player to down.")
end
if player then
player:sendCreatureAppear()
end
end
player:sendCreatureAppear()
end
end
end
Expand Down Expand Up @@ -72,22 +80,30 @@ local function findNearestRoomPosition(playerPosition)
end

local function loadMapInundate()
if SoulWarQuest.ebbAndFlow.getZone():countPlayers() > 0 then
local players = SoulWarQuest.ebbAndFlow.getZone():getPlayers()
for _, player in ipairs(players) do
local playerPosition = player:getPosition()
if playerPosition.z == 9 then
if player:isInBoatSpot() then
local nearestCenterPosition = findNearestRoomPosition(playerPosition)
player:teleportTo(nearestCenterPosition)
logger.trace("Teleporting player to the near center position room and updating tile.")
else
player:teleportTo(SoulWarQuest.ebbAndFlow.waitPosition)
logger.trace("Teleporting player to wait position and updating tile.")
local playersInZone = SoulWarQuest.ebbAndFlow.getZone():countPlayers()
local monstersInZone = SoulWarQuest.ebbAndFlow.getZone():countMonsters()
if playersInZone > 0 or monstersInZone > 0 then
local creatures = SoulWarQuest.ebbAndFlow.getZone():getCreatures()
for _, creature in ipairs(creatures) do
local creatureMaster = creature:getMaster()
local player = creature:getPlayer()
if creature:isPlayer() or (creature:isMonster() and creatureMaster and creatureMaster:getPlayer()) then
local creaturePosition = creature:getPosition()
if creaturePosition.z == 9 then
if creature:isInBoatSpot() then
local nearestCenterPosition = findNearestRoomPosition(creaturePosition)
creature:teleportTo(nearestCenterPosition)
logger.trace("Teleporting player to the near center position room and updating tile.")
else
creature:teleportTo(SoulWarQuest.ebbAndFlow.waitPosition)
logger.trace("Teleporting player to wait position and updating tile.")
end
creaturePosition:sendMagicEffect(CONST_ME_TELEPORT)
end
if player then
player:sendCreatureAppear()
end
playerPosition:sendMagicEffect(CONST_ME_TELEPORT)
end
player:sendCreatureAppear()
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local setting = { 1948, 1968, 5542, 20474, 20475, 28656, 31262 }
local ladderTable = Game.getLadderIds()

local ladder = Action()

function ladder.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if table.contains(setting, item.itemid) then
if table.contains(ladderTable, item.itemid) then
fromPosition:moveUpstairs()
else
fromPosition.z = fromPosition.z + 1
Expand All @@ -18,8 +18,5 @@ function ladder.onUse(player, item, fromPosition, target, toPosition, isHotkey)
return true
end

for index, value in ipairs(setting) do
ladder:id(value)
end

ladder:id(435, unpack(ladderTable))
ladder:register()
4 changes: 2 additions & 2 deletions data/scripts/spells/support/sharpshooter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local speed = Condition(CONDITION_HASTE)
local speed = Condition(CONDITION_PARALYZE)
speed:setParameter(CONDITION_PARAM_TICKS, spellDuration)
speed:setFormula(0.7, 0, 0.7, 0)
speed:setFormula(0.7, 56, 0.7, 56)
combat:addCondition(speed)

local exhaustHealGroup = Condition(CONDITION_SPELLGROUPCOOLDOWN)
Expand Down
3 changes: 0 additions & 3 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include "lua/scripts/scripts.hpp"
#include "lib/di/container.hpp"

std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 };
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 };

Spells::Spells() = default;
Spells::~Spells() = default;

Expand Down
6 changes: 3 additions & 3 deletions src/creatures/combat/spells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#pragma once

#include "lua/creature/actions.hpp"

enum class WheelSpellBoost_t : uint8_t;
enum class WheelSpellGrade_t : uint8_t;
#include "creatures/players/wheel/wheel_definitions.hpp"

class InstantSpell;
class RuneSpell;
Expand Down Expand Up @@ -256,6 +254,8 @@ class Spell : public BaseSpell {
bool pzLocked = false;

bool whellOfDestinyUpgraded = false;
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 };
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 };

private:
uint32_t mana = 0;
Expand Down
14 changes: 11 additions & 3 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,10 @@ uint16_t Player::getGrindingXpBoost() const {
return grindingXpBoost;
}

uint16_t Player::getDisplayGrindingXpBoost() const {
return std::clamp<uint16_t>(grindingXpBoost * (baseXpGain / 100), 0, std::numeric_limits<uint16_t>::max());
}

void Player::setGrindingXpBoost(uint16_t value) {
grindingXpBoost = std::min<uint16_t>(std::numeric_limits<uint16_t>::max(), value);
}
Expand All @@ -2747,6 +2751,10 @@ uint16_t Player::getXpBoostPercent() const {
return xpBoostPercent;
}

uint16_t Player::getDisplayXpBoostPercent() const {
return std::clamp<uint16_t>(xpBoostPercent * (baseXpGain / 100), 0, std::numeric_limits<uint16_t>::max());
}

void Player::setXpBoostPercent(uint16_t percent) {
xpBoostPercent = percent;
}
Expand Down Expand Up @@ -3517,7 +3525,7 @@ void Player::death(const std::shared_ptr<Creature> &lastHitCreature) {
}

// Level loss
auto expLoss = static_cast<uint64_t>(std::ceil((experience * deathLossPercent) / 100.));
auto expLoss = static_cast<uint64_t>(std::ceil(experience * deathLossPercent));
g_logger().debug("[{}] - experience lost {}", __FUNCTION__, expLoss);

g_events().eventPlayerOnLoseExperience(static_self_cast<Player>(), expLoss);
Expand Down Expand Up @@ -6323,9 +6331,9 @@ double Player::getLostPercent() const {
g_logger().debug("[{}] - after promotion {}", __FUNCTION__, percentReduction);
}

g_logger().debug("[{}] - total lost percent {}", __FUNCTION__, lossPercent - (lossPercent * percentReduction));
g_logger().debug("[{}] - total lost percent {}", __FUNCTION__, (lossPercent * (1 - percentReduction)) / 100.);

return lossPercent - (lossPercent * percentReduction);
return (lossPercent * (1 - percentReduction)) / 100.;
}

[[nodiscard]] const std::string &Player::getGuildNick() const {
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,10 @@ class Player final : public Creature, public Cylinder, public Bankable {
uint16_t getVoucherXpBoost() const;
void setVoucherXpBoost(uint16_t value);
uint16_t getGrindingXpBoost() const;
uint16_t getDisplayGrindingXpBoost() const;
void setGrindingXpBoost(uint16_t value);
uint16_t getXpBoostPercent() const;
uint16_t getDisplayXpBoostPercent() const;
void setXpBoostPercent(uint16_t percent);
uint16_t getStaminaXpBoost() const;
void setStaminaXpBoost(uint16_t value);
Expand Down
4 changes: 2 additions & 2 deletions src/io/io_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace InternalPlayerWheel {
return;
}

auto spell = g_spells().getInstantSpellByName(name);
const auto &spell = g_spells().getInstantSpellByName(name);
if (spell) {
g_logger().trace("[{}] registering instant spell with name {}", __FUNCTION__, spell->getName());
// Increase data
Expand Down Expand Up @@ -127,7 +127,7 @@ bool IOWheel::initializeGlobalData(bool reload /* = false*/) {
// Register spells for druid
for (const auto &data : getWheelBonusData().spells.druid) {
for (size_t i = 1; i < 3; ++i) {
const auto grade = data.grade[i];
const auto &grade = data.grade[i];
InternalPlayerWheel::registerWheelSpellTable(grade, data.name, static_cast<WheelSpellGrade_t>(i));
}
}
Expand Down
30 changes: 1 addition & 29 deletions src/items/weapons/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,35 +942,7 @@ void WeaponWand::configureWeapon(const ItemType &it) {
}

int32_t WeaponWand::getWeaponDamage(const std::shared_ptr<Player> &player, const std::shared_ptr<Creature> &, const std::shared_ptr<Item> &, bool maxDamage /* = false*/) const {
if (!g_configManager().getBoolean(TOGGLE_CHAIN_SYSTEM)) {
// Returns maximum damage or a random value between minChange and maxChange
return maxDamage ? -maxChange : -normal_random(minChange, maxChange);
}

// If chain system is enabled, calculates magic-based damage
int32_t attackSkill = 0;
int32_t attackValue = 0;
float attackFactor = 0.0;
[[maybe_unused]] int16_t elementAttack = 0;
[[maybe_unused]] CombatDamage combatDamage;
calculateSkillFormula(player, attackSkill, attackValue, attackFactor, elementAttack, combatDamage);

const auto magLevel = player->getMagicLevel();
const auto level = player->getLevel();

// Check if level is greater than zero before performing division
const auto levelDivision = level > 0 ? level / 5.0 : 0.0;

const auto totalAttackValue = magLevel + attackValue;

// Check if magLevel is greater than zero before performing division
const auto magicLevelDivision = totalAttackValue > 0 ? totalAttackValue / 3.0 : 0.0;

const double min = levelDivision + magicLevelDivision;
const double max = levelDivision + totalAttackValue;

// Returns the calculated maximum damage or a random value between the calculated minimum and maximum
return maxDamage ? -max : -normal_random(min, max);
return maxDamage ? -maxChange : -normal_random(minChange, maxChange);
}

int16_t WeaponWand::getElementDamageValue() const {
Expand Down
29 changes: 19 additions & 10 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3480,8 +3480,8 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() {
msg.add<uint16_t>(player->getLevel());
msg.addByte(player->getLevelPercent());
msg.add<uint16_t>(player->getBaseXpGain()); // BaseXPGainRate
msg.add<uint16_t>(player->getGrindingXpBoost()); // LowLevelBonus
msg.add<uint16_t>(player->getXpBoostPercent()); // XPBoost
msg.add<uint16_t>(player->getDisplayGrindingXpBoost()); // LowLevelBonus
msg.add<uint16_t>(player->getDisplayXpBoostPercent()); // XPBoost
msg.add<uint16_t>(player->getStaminaXpBoost()); // StaminaMultiplier(100=x1.0)
msg.add<uint16_t>(player->getXpBoostTime()); // xpBoostRemainingTime
msg.addByte(player->getXpBoostTime() > 0 ? 0x00 : 0x01); // canBuyXpBoost
Expand Down Expand Up @@ -5745,14 +5745,23 @@ void ProtocolGame::sendForgeHistory(uint8_t page) {
page = page + 1;
auto historyVector = player->getForgeHistory();
auto historyVectorLen = historyVector.size();
uint16_t lastPage = (1 < std::floor((historyVectorLen - 1) / 9) + 1) ? static_cast<uint16_t>(std::floor((historyVectorLen - 1) / 9) + 1) : 1;
uint16_t currentPage = (lastPage < page) ? lastPage : page;

uint16_t currentPage = 1;
uint16_t lastPage = 1;
uint16_t pageFirstEntry = 0;
uint16_t pageLastEntry = 0;

std::vector<ForgeHistory> historyPerPage;
uint16_t pageFirstEntry = (0 < historyVectorLen - (currentPage - 1) * 9) ? historyVectorLen - (currentPage - 1) * 9 : 0;
uint16_t pageLastEntry = (0 < historyVectorLen - currentPage * 9) ? historyVectorLen - currentPage * 9 : 0;
for (uint16_t entry = pageFirstEntry; entry > pageLastEntry; --entry) {
historyPerPage.emplace_back(historyVector[entry - 1]);
if (historyVectorLen > 0) {
lastPage = std::clamp<uint16_t>(std::floor((historyVectorLen - 1) / 9) + 1, 0, std::numeric_limits<uint16_t>::max());
currentPage = (lastPage < page) ? lastPage : page;

pageFirstEntry = std::clamp<uint16_t>(historyVectorLen - (currentPage - 1) * 9, 0, std::numeric_limits<uint16_t>::max());
pageLastEntry = historyVectorLen > currentPage * 9 ? std::clamp<uint16_t>(historyVectorLen - currentPage * 9, 0, std::numeric_limits<uint16_t>::max()) : 0;

for (uint16_t entry = pageFirstEntry; entry > pageLastEntry; --entry) {
historyPerPage.emplace_back(historyVector[entry - 1]);
}
}

auto historyPageToSend = historyPerPage.size();
Expand Down Expand Up @@ -7840,8 +7849,8 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) {
msg.add<uint16_t>(player->getVoucherXpBoost()); // xp voucher
}

msg.add<uint16_t>(player->getGrindingXpBoost()); // low level bonus
msg.add<uint16_t>(player->getXpBoostPercent()); // xp boost
msg.add<uint16_t>(player->getDisplayGrindingXpBoost()); // low level bonus
msg.add<uint16_t>(player->getDisplayXpBoostPercent()); // xp boost
msg.add<uint16_t>(player->getStaminaXpBoost()); // stamina multiplier (100 = 1.0x)

if (!oldProtocol) {
Expand Down

0 comments on commit b17dad3

Please sign in to comment.