Skip to content

Commit

Permalink
Merge branch 'main' into dudantas/feat-soul-war-quest
Browse files Browse the repository at this point in the history
  • Loading branch information
s2leandro155 committed Sep 7, 2024
2 parents e97412f + 762de9b commit ae3bd68
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 58 deletions.
18 changes: 18 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
},
{
"name": "windows-debug-asan",
"inherits": "windows-release",
"displayName": "Windows - Debug + ASAN",
"description": "Debug Mode with ASAN",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"DEBUG_LOG": "ON",
"ASAN_ENABLED": "ON",
"BUILD_STATIC_LIBRARY": "OFF",
"SPEED_UP_BUILD_UNITY": "OFF",
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
},
{
"name": "linux-release",
"inherits": "base",
Expand Down Expand Up @@ -122,6 +136,10 @@
{
"name": "windows-Xdebug",
"configurePreset": "windows-debug"
},
{
"name": "windows-Xdebug-asan",
"configurePreset": "windows-debug-asan"
}
]
}
19 changes: 15 additions & 4 deletions data/scripts/spells/support/magic_shield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local spell = Spell("instant")

local function calculateMagicShieldCapacity(player, Level, MagicLevel)
local grade = player:upgradeSpellsWOD("Magic Shield")
if grade >= WHEEL_GRADE_REGULAR then
local base = 8 * MagicLevel + 8.6 * Level
else
local base = 7 * MagicLevel + 7.6 * Level
end
local base = 7 * MagicLevel + 7.6 * Level
local bonus = math.max(300, 0.4 * Level)
local MagicShieldCapacity = base + bonus
print(MagicShieldCapacity)
return MagicShieldCapacity
end

function spell.onCastSpell(creature, var)
local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, 180000)
local player = creature:getPlayer()
local grade = player:upgradeSpellsWOD("Magic Shield")
local shield = 300 + 7.6 * player:getLevel() + 7 * player:getMagicLevel()
if grade >= WHEEL_GRADE_REGULAR then
shield = shield * 1.25
end
local shield = calculateMagicShieldCapacity(player, player:getLevel(), player:getMagicLevel())
if player then
condition:setParameter(CONDITION_PARAM_MANASHIELD, math.min(player:getMaxMana(), shield))
end
Expand Down
6 changes: 5 additions & 1 deletion src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,11 @@ bool ConditionRegeneration::executeCondition(std::shared_ptr<Creature> creature,
auto player = creature->getPlayer();
int32_t dailyStreak = 0;
if (player) {
dailyStreak = static_cast<int32_t>(player->kv()->scoped("daily-reward")->get("streak")->getNumber());
auto scopedDailyReward = player->kv()->scoped("daily-reward")->get("streak");
if (!scopedDailyReward || !scopedDailyReward.has_value()) {
return false;
}
dailyStreak = static_cast<int32_t>(scopedDailyReward->getNumber());
}
if (creature->getZoneType() != ZONE_PROTECTION || dailyStreak >= DAILY_REWARD_HP_REGENERATION) {
if (internalHealthTicks >= getHealthTicks(creature)) {
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@ class Creature : virtual public Thing, public SharedObject {
int32_t health = 1000;
int32_t healthMax = 1000;

uint16_t manaShield = 0;
uint16_t maxManaShield = 0;
uint32_t manaShield = 0;
uint32_t maxManaShield = 0;
int32_t varBuffs[BUFF_LAST + 1] = { 100, 100, 100 };

std::array<int32_t, COMBAT_COUNT> reflectPercent = { 0 };
Expand Down
9 changes: 7 additions & 2 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5773,9 +5773,14 @@ void Player::sendUnjustifiedPoints() {
uint8_t Player::getLastMount() const {
int32_t value = getStorageValue(PSTRG_MOUNTS_CURRENTMOUNT);
if (value > 0) {
return value;
return static_cast<uint8_t>(value);
}
auto lastMountOpt = kv()->get("last-mount");
if (lastMountOpt && lastMountOpt->get<int>()) {
return static_cast<uint8_t>(lastMountOpt->get<int>());
}
return static_cast<uint8_t>(kv()->get("last-mount")->get<int>());

return 0;
}

uint8_t Player::getCurrentMount() const {
Expand Down
13 changes: 5 additions & 8 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,19 @@ class Player final : public Creature, public Cylinder, public Bankable {
class PlayerLock {
public:
explicit PlayerLock(const std::shared_ptr<Player> &p) :
player(p) {
player->mutex.lock();
player(p), lock(player->mutex) {
}

PlayerLock(const PlayerLock &) = delete;

~PlayerLock() {
player->mutex.unlock();
}
PlayerLock &operator=(const PlayerLock &) = delete;

private:
const std::shared_ptr<Player> &player;
std::shared_ptr<Player> player;
std::scoped_lock<std::mutex> lock;
};

explicit Player(ProtocolGame_ptr p);
~Player();
~Player() override;

// non-copyable
Player(const Player &) = delete;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/wheel/player_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ std::vector<PlayerWheelGem> PlayerWheel::getActiveGems() const {
for (auto affinity : magic_enum::enum_values<WheelGemAffinity_t>()) {
std::string key(magic_enum::enum_name(affinity));
auto uuidKV = gemsKV()->scoped("active")->get(key);
if (!uuidKV.has_value()) {
if (!uuidKV || !uuidKV.has_value()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10189,7 +10189,7 @@ bool Game::removeFiendishMonster(uint32_t id, bool create /* = true*/) {

void Game::updateForgeableMonsters() {
forgeableMonsters.clear();
for (auto [monsterId, monster] : monsters) {
for (const auto &[monsterId, monster] : monsters) {
auto monsterTile = monster->getTile();
if (!monsterTile) {
continue;
Expand Down
19 changes: 9 additions & 10 deletions src/game/scheduling/save_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ SaveManager &SaveManager::getInstance() {
void SaveManager::saveAll() {
Benchmark bm_saveAll;
logger.info("Saving server...");
const auto players = game.getPlayers();

for (const auto &[_, player] : players) {
for (const auto &[_, player] : game.getPlayers()) {
player->loginPosition = player->getPosition();
doSavePlayer(player);
}

auto guilds = game.getGuilds();
for (const auto &[_, guild] : guilds) {
for (const auto &[_, guild] : game.getGuilds()) {
saveGuild(guild);
}

Expand Down Expand Up @@ -66,20 +64,20 @@ void SaveManager::schedulePlayer(std::weak_ptr<Player> playerPtr) {
return;
}

logger.debug("Scheduling player {} for saving.", playerToSave->getName());
logger.debug("Scheduling player {} for asynchronous saving.", playerToSave->getName());
auto scheduledAt = std::chrono::steady_clock::now();
m_playerMap[playerToSave->getGUID()] = scheduledAt;
threadPool.detach_task([this, playerPtr, scheduledAt]() {
auto player = playerPtr.lock();
if (!player) {

threadPool.detach_task([this, scheduledAt, playerToSave]() {
if (!playerToSave) {
logger.debug("Skipping save for player because player is no longer online.");
return;
}
if (m_playerMap[player->getGUID()] != scheduledAt) {
if (m_playerMap[playerToSave->getGUID()] != scheduledAt) {
logger.warn("Skipping save for player because another save has been scheduled.");
return;
}
doSavePlayer(player);
doSavePlayer(playerToSave);
});
}

Expand All @@ -92,6 +90,7 @@ bool SaveManager::doSavePlayer(std::shared_ptr<Player> player) {
Benchmark bm_savePlayer;
Player::PlayerLock lock(player);
m_playerMap.erase(player->getGUID());

if (g_game().getGameState() == GAME_STATE_NORMAL) {
logger.debug("Saving player {}.", player->getName());
}
Expand Down
39 changes: 18 additions & 21 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "creatures/players/wheel/player_wheel.hpp"
#include "creatures/players/achievement/player_achievement.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
#include "creatures/players/cyclopedia/player_cyclopedia.hpp"
#include "creatures/players/cyclopedia/player_title.hpp"
#include "game/game.hpp"
#include "io/iologindata.hpp"
Expand Down Expand Up @@ -2270,23 +2271,10 @@ int PlayerFunctions::luaPlayerGetParty(lua_State* L) {
}

int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) {
// player:addOutfit(lookType or name, addon = 0)
// player:addOutfit(lookType)
std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1);
if (player) {
auto addon = getNumber<uint8_t>(L, 3, 0);
if (lua_isnumber(L, 2)) {
player->addOutfit(getNumber<uint16_t>(L, 2), addon);
} else if (lua_isstring(L, 2)) {
const std::string &outfitName = getString(L, 2);
const auto &outfit = Outfits::getInstance().getOutfitByName(player->getSex(), outfitName);
if (!outfit) {
reportErrorFunc("Outfit not found");
return 1;
}

player->addOutfit(outfit->lookType, addon);
}

player->addOutfit(getNumber<uint16_t>(L, 2), 0);
pushBoolean(L, true);
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -2745,15 +2733,15 @@ int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) {
}

int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) {
// player:getBlessingCount(index)
// player:getBlessingCount(index[, storeCount = false])
std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1);
uint8_t index = getNumber<uint8_t>(L, 2);
if (index == 0) {
index = 1;
}

if (player) {
lua_pushnumber(L, player->getBlessingCount(index));
lua_pushnumber(L, player->getBlessingCount(index, getBoolean(L, 3, false)));
} else {
lua_pushnil(L);
}
Expand Down Expand Up @@ -4369,15 +4357,24 @@ int PlayerFunctions::luaPlayerSetCurrentTitle(lua_State* L) {
return 1;
}

int PlayerFunctions::luaPlayerSendCreatureAppear(lua_State* L) {
auto player = getUserdataShared<Player>(L, 1);
int PlayerFunctions::luaPlayerCreateTransactionSummary(lua_State* L) {
// player:createTransactionSummary(type, amount[, id = 0])
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
return 1;
}

bool isLogin = getBoolean(L, 2, false);
player->sendCreatureAppear(player, player->getPosition(), isLogin);
auto type = getNumber<uint8_t>(L, 2, 0);
if (type == 0) {
reportErrorFunc(getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND));
return 1;
}

auto amount = getNumber<uint16_t>(L, 3, 1);
auto id = getString(L, 4, "");

player->cyclopedia()->updateStoreSummary(type, amount, id);
pushBoolean(L, true);
return 1;
}
5 changes: 3 additions & 2 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ class PlayerFunctions final : LuaScriptInterface {
registerMethod(L, "Player", "getTitles", PlayerFunctions::luaPlayerGetTitles);
registerMethod(L, "Player", "setCurrentTitle", PlayerFunctions::luaPlayerSetCurrentTitle);

registerMethod(L, "Player", "sendCreatureAppear", PlayerFunctions::luaPlayerSendCreatureAppear);
// Store Summary
registerMethod(L, "Player", "createTransactionSummary", PlayerFunctions::luaPlayerCreateTransactionSummary);

GroupFunctions::init(L);
GuildFunctions::init(L);
Expand Down Expand Up @@ -734,7 +735,7 @@ class PlayerFunctions final : LuaScriptInterface {
static int luaPlayerGetTitles(lua_State* L);
static int luaPlayerSetCurrentTitle(lua_State* L);

static int luaPlayerSendCreatureAppear(lua_State* L);
static int luaPlayerCreateTransactionSummary(lua_State* L);

friend class CreatureFunctions;
};
8 changes: 2 additions & 6 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,13 +733,9 @@ uint32_t Map::clean() {
continue;
}

if (const auto items = tile->getItemList()) {
if (const auto &items = tile->getItemList()) {
++qntTiles;
for (const auto &item : *items) {
if (item->isCleanable()) {
toRemove.emplace_back(item);
}
}
std::copy_if(items->begin(), items->end(), std::back_inserter(toRemove), [](const auto &item) { return item->isCleanable(); });
}
}

Expand Down
Empty file added test.txt
Empty file.

0 comments on commit ae3bd68

Please sign in to comment.