Skip to content

Commit

Permalink
Merge branch 'main' into phacUFPE/fix_forge_history
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE authored Nov 19, 2024
2 parents 2e34768 + 5072de8 commit 706f316
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 71 deletions.
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
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
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
8 changes: 4 additions & 4 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 @@ -7849,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 706f316

Please sign in to comment.