Skip to content

Commit

Permalink
Merge branch 'main' into dudantas/fix-create-item-talkaction
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas authored Nov 24, 2023
2 parents 298b155 + 0ba46fe commit 12f4b11
Show file tree
Hide file tree
Showing 78 changed files with 513 additions and 435 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
local function removeEmpowermentItem(position)
for x = -1, 1 do
for y = -1, 1 do
local tile = Tile(Position(position.x + x, position.y + y, position.z))
if tile then
local item = tile:getItemById(ITEM_DIVINE_EMPOWERMENT)
if item then
item:remove()
end
end
end
end
end

local spell = Spell("instant")

function spell.onCastSpell(creature, var)
Expand Down Expand Up @@ -29,10 +43,12 @@ function spell.onCastSpell(creature, var)
for y = -1, 1 do
local item = Game.createItem(ITEM_DIVINE_EMPOWERMENT, 1, Position(position.x + x, position.y + y, position.z))
if item then
item:setDuration(5, 5, 0, false)
item:setAttribute(ITEM_ATTRIBUTE_OWNER, creature:getId())
end
end
end

addEvent(removeEmpowermentItem, 5000, position)
creature:onThinkWheelOfDestiny(true)
return true
end
Expand Down
2 changes: 1 addition & 1 deletion data/libs/functions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ function Player:calculateLootFactor(monster)

local participants = { self }
local factor = 1
if configManager.getBoolean(PARTY_SHARE_LOOT_BOOSTS) then
if configManager.getBoolean(configKeys.PARTY_SHARE_LOOT_BOOSTS) then
local party = self:getParty()
if party and party:isSharedExperienceEnabled() then
participants = party:getMembers()
Expand Down
2 changes: 1 addition & 1 deletion data/libs/loyalty_lib.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local loyaltySystem = {
enable = configManager.getBoolean(LOYALTY_ENABLED),
enable = configManager.getBoolean(configKeys.LOYALTY_ENABLED),
titles = {
[1] = { name = "Scout of Tibia", points = 50 },
[2] = { name = "Sentinel of Tibia", points = 100 },
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/ondroploot_hazard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function callback.monsterOnDropLoot(monster, corpse)
rolls = math.floor(rolls)
end

if configManager.getBoolean(PARTY_SHARE_LOOT_BOOSTS) and rolls > 1 then
if configManager.getBoolean(configKeys.PARTY_SHARE_LOOT_BOOSTS) and rolls > 1 then
msgSuffix = msgSuffix .. " (hazard system, " .. rolls .. " extra rolls)"
elseif rolls == 1 then
msgSuffix = msgSuffix .. " (hazard system)"
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/ondroploot_prey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function callback.monsterOnDropLoot(monster, corpse)
local factor = 1.0
local msgSuffix = ""
local participants = { player }
if configManager.getBoolean(PARTY_SHARE_LOOT_BOOSTS) then
if configManager.getBoolean(configKeys.PARTY_SHARE_LOOT_BOOSTS) then
local party = player:getParty()
if party and party:isSharedExperienceEnabled() then
participants = party:getMembers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function callback.monsterOnDropLoot(monster, corpse)
local factor = 1.0
local msgSuffix = ""
local participants = { player }
if configManager.getBoolean(PARTY_SHARE_LOOT_BOOSTS) then
if configManager.getBoolean(configKeys.PARTY_SHARE_LOOT_BOOSTS) then
local party = player:getParty()
if party and party:isSharedExperienceEnabled() then
participants = party:getMembers()
Expand Down Expand Up @@ -57,7 +57,7 @@ function callback.monsterOnDropLoot(monster, corpse)
return
end

if configManager.getBoolean(PARTY_SHARE_LOOT_BOOSTS) and rolls > 1 then
if configManager.getBoolean(configKeys.PARTY_SHARE_LOOT_BOOSTS) and rolls > 1 then
msgSuffix = msgSuffix .. " (active wealth duplex, " .. rolls .. " extra rolls)"
else
msgSuffix = msgSuffix .. " (active wealth duplex)"
Expand Down
34 changes: 17 additions & 17 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int CanaryServer::run() {
try {
loadConfigLua();

logger.info("Server protocol: {}.{}{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER, g_configManager().getBoolean(OLD_PROTOCOL) ? " and 10x allowed!" : "");
logger.info("Server protocol: {}.{}{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER, g_configManager().getBoolean(OLD_PROTOCOL, __FUNCTION__) ? " and 10x allowed!" : "");

rsa.start();
initializeDatabase();
Expand Down Expand Up @@ -89,7 +89,7 @@ int CanaryServer::run() {

g_game().start(&serviceManager);
g_game().setGameState(GAME_STATE_NORMAL);
if (g_configManager().getBoolean(TOGGLE_MAINTAIN_MODE)) {
if (g_configManager().getBoolean(TOGGLE_MAINTAIN_MODE, __FUNCTION__)) {
g_game().setGameState(GAME_STATE_CLOSED);
g_logger().warn("Initialized in maintain mode!");
g_webhook().sendMessage("Server is now online", "The server is now online. Access is currently restricted to administrators only.", WEBHOOK_COLOR_ONLINE);
Expand Down Expand Up @@ -123,7 +123,7 @@ int CanaryServer::run() {
return EXIT_FAILURE;
}

logger.info("{} {}", g_configManager().getString(SERVER_NAME), "server online!");
logger.info("{} {}", g_configManager().getString(SERVER_NAME, __FUNCTION__), "server online!");

serviceManager.run();

Expand All @@ -132,7 +132,7 @@ int CanaryServer::run() {
}

void CanaryServer::setWorldType() {
std::string worldType = asLowerCaseString(g_configManager().getString(WORLD_TYPE));
const std::string worldType = asLowerCaseString(g_configManager().getString(WORLD_TYPE, __FUNCTION__));
if (worldType == "pvp") {
g_game().setWorldType(WORLD_TYPE_PVP);
} else if (worldType == "no-pvp") {
Expand All @@ -143,7 +143,7 @@ void CanaryServer::setWorldType() {
throw FailedToInitializeCanary(
fmt::format(
"Unknown world type: {}, valid world types are: pvp, no-pvp and pvp-enforced",
g_configManager().getString(WORLD_TYPE)
g_configManager().getString(WORLD_TYPE, __FUNCTION__)
)
);
}
Expand All @@ -153,11 +153,11 @@ void CanaryServer::setWorldType() {

void CanaryServer::loadMaps() const {
try {
g_game().loadMainMap(g_configManager().getString(MAP_NAME));
g_game().loadMainMap(g_configManager().getString(MAP_NAME, __FUNCTION__));

// If "mapCustomEnabled" is true on config.lua, then load the custom map
if (g_configManager().getBoolean(TOGGLE_MAP_CUSTOM)) {
g_game().loadCustomMaps(g_configManager().getString(DATA_DIRECTORY) + "/world/custom/");
if (g_configManager().getBoolean(TOGGLE_MAP_CUSTOM, __FUNCTION__)) {
g_game().loadCustomMaps(g_configManager().getString(DATA_DIRECTORY, __FUNCTION__) + "/world/custom/");
}
Zone::refreshAll();
} catch (const std::exception &err) {
Expand All @@ -167,7 +167,7 @@ void CanaryServer::loadMaps() const {

void CanaryServer::setupHousesRent() {
RentPeriod_t rentPeriod;
std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD));
std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD, __FUNCTION__));

if (strRentPeriod == "yearly") {
rentPeriod = RENTPERIOD_YEARLY;
Expand Down Expand Up @@ -214,8 +214,8 @@ void CanaryServer::logInfos() {
*/
void CanaryServer::toggleForceCloseButton() {
#ifdef OS_WINDOWS
HWND hwnd = GetConsoleWindow();
HMENU hmenu = GetSystemMenu(hwnd, FALSE);
const HWND hwnd = GetConsoleWindow();
const HMENU hmenu = GetSystemMenu(hwnd, FALSE);
EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED);
#endif
}
Expand Down Expand Up @@ -280,7 +280,7 @@ void CanaryServer::loadConfigLua() {
modulesLoadHelper(g_configManager().load(), g_configManager().getConfigFileLua());

#ifdef _WIN32
const std::string &defaultPriority = g_configManager().getString(DEFAULT_PRIORITY);
const std::string &defaultPriority = g_configManager().getString(DEFAULT_PRIORITY, __FUNCTION__);
if (strcasecmp(defaultPriority.c_str(), "high") == 0) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
} else if (strcasecmp(defaultPriority.c_str(), "above-normal") == 0) {
Expand All @@ -306,16 +306,16 @@ void CanaryServer::initializeDatabase() {

DatabaseManager::updateDatabase();

if (g_configManager().getBoolean(OPTIMIZE_DATABASE)
if (g_configManager().getBoolean(OPTIMIZE_DATABASE, __FUNCTION__)
&& !DatabaseManager::optimizeTables()) {
logger.debug("No tables were optimized");
}
}

void CanaryServer::loadModules() {
// If "USE_ANY_DATAPACK_FOLDER" is set to true then you can choose any datapack folder for your server
auto useAnyDatapack = g_configManager().getBoolean(USE_ANY_DATAPACK_FOLDER);
auto datapackName = g_configManager().getString(DATA_DIRECTORY);
const auto useAnyDatapack = g_configManager().getBoolean(USE_ANY_DATAPACK_FOLDER, __FUNCTION__);
auto datapackName = g_configManager().getString(DATA_DIRECTORY, __FUNCTION__);
if (!useAnyDatapack && (datapackName != "data-canary" && datapackName != "data-otservbr-global" || datapackName != "data-otservbr-global" && datapackName != "data-canary")) {
throw FailedToInitializeCanary(fmt::format(
"The datapack folder name '{}' is wrong, please select valid "
Expand All @@ -330,12 +330,12 @@ void CanaryServer::loadModules() {
g_luaEnvironment().initState();
}

auto coreFolder = g_configManager().getString(CORE_DIRECTORY);
auto coreFolder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__);
// Load items dependencies
modulesLoadHelper((g_game().loadAppearanceProtobuf(coreFolder + "/items/appearances.dat") == ERROR_NONE), "appearances.dat");
modulesLoadHelper(Item::items.loadFromXml(), "items.xml");

auto datapackFolder = g_configManager().getString(DATA_DIRECTORY);
const auto datapackFolder = g_configManager().getString(DATA_DIRECTORY, __FUNCTION__);
logger.debug("Loading core scripts on folder: {}/", coreFolder);
// Load first core Lua libs
modulesLoadHelper((g_luaEnvironment().loadFile(coreFolder + "/core.lua", "core.lua") == 0), "core.lua");
Expand Down
18 changes: 9 additions & 9 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ bool ConfigManager::load() {

bool ConfigManager::reload() {
const bool result = load();
if (transformToSHA1(getString(SERVER_MOTD)) != g_game().getMotdHash()) {
if (transformToSHA1(getString(SERVER_MOTD, __FUNCTION__)) != g_game().getMotdHash()) {
g_game().incrementMotdNum();
}
return result;
Expand Down Expand Up @@ -404,35 +404,35 @@ float ConfigManager::loadFloatConfig(lua_State* L, const ConfigKey_t &key, const
return value;
}

const std::string &ConfigManager::getString(const ConfigKey_t &key) const {
const std::string &ConfigManager::getString(const ConfigKey_t &key, std::string_view context) const {
static const std::string dummyStr;
if (configs.contains(key) && std::holds_alternative<std::string>(configs.at(key))) {
return std::get<std::string>(configs.at(key));
}
g_logger().warn("[ConfigManager::getString] - Accessing invalid or wrong type index: {}", fmt::underlying(key));
g_logger().warn("[ConfigManager::getString] - Accessing invalid or wrong type index: {}[{}], Function: {}", magic_enum::enum_name(key), fmt::underlying(key), context);
return dummyStr;
}

int32_t ConfigManager::getNumber(const ConfigKey_t &key) const {
int32_t ConfigManager::getNumber(const ConfigKey_t &key, std::string_view context) const {
if (configs.contains(key) && std::holds_alternative<int32_t>(configs.at(key))) {
return std::get<int32_t>(configs.at(key));
}
g_logger().warn("[ConfigManager::getNumber] - Accessing invalid or wrong type index: {}", fmt::underlying(key));
g_logger().warn("[ConfigManager::getNumber] - Accessing invalid or wrong type index: {}[{}], Function: {}", magic_enum::enum_name(key), fmt::underlying(key), context);
return 0;
}

bool ConfigManager::getBoolean(const ConfigKey_t &key) const {
bool ConfigManager::getBoolean(const ConfigKey_t &key, std::string_view context) const {
if (configs.contains(key) && std::holds_alternative<bool>(configs.at(key))) {
return std::get<bool>(configs.at(key));
}
g_logger().warn("[ConfigManager::getBoolean] - Accessing invalid or wrong type index: {}", fmt::underlying(key));
g_logger().warn("[ConfigManager::getBoolean] - Accessing invalid or wrong type index: {}[{}], Function: {}", magic_enum::enum_name(key), fmt::underlying(key), context);
return false;
}

float ConfigManager::getFloat(const ConfigKey_t &key) const {
float ConfigManager::getFloat(const ConfigKey_t &key, std::string_view context) const {
if (configs.contains(key) && std::holds_alternative<float>(configs.at(key))) {
return std::get<float>(configs.at(key));
}
g_logger().warn("[ConfigManager::getFloat] - Accessing invalid or wrong type index: {}", fmt::underlying(key));
g_logger().warn("[ConfigManager::getFloat] - Accessing invalid or wrong type index: {}[{}], Function: {}", magic_enum::enum_name(key), fmt::underlying(key), context);
return 0.0f;
}
8 changes: 4 additions & 4 deletions src/config/configmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class ConfigManager {
return configFileLua;
};

[[nodiscard]] const std::string &getString(const ConfigKey_t &key) const;
[[nodiscard]] int32_t getNumber(const ConfigKey_t &key) const;
[[nodiscard]] bool getBoolean(const ConfigKey_t &key) const;
[[nodiscard]] float getFloat(const ConfigKey_t &key) const;
[[nodiscard]] const std::string &getString(const ConfigKey_t &key, std::string_view context) const;
[[nodiscard]] int32_t getNumber(const ConfigKey_t &key, std::string_view context) const;
[[nodiscard]] bool getBoolean(const ConfigKey_t &key, std::string_view context) const;
[[nodiscard]] float getFloat(const ConfigKey_t &key, std::string_view context) const;

private:
phmap::flat_hash_map<ConfigKey_t, ConfigValue> configs;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/appearance/mounts/mounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bool Mounts::reload() {

bool Mounts::loadFromXml() {
pugi::xml_document doc;
auto folder = g_configManager().getString(CORE_DIRECTORY) + "/XML/mounts.xml";
auto folder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__) + "/XML/mounts.xml";
pugi::xml_parse_result result = doc.load_file(folder.c_str());
if (!result) {
printXMLError(__FUNCTION__, folder, result);
Expand All @@ -30,7 +30,7 @@ bool Mounts::loadFromXml() {

for (auto mountNode : doc.child("mounts").children()) {
uint16_t lookType = pugi::cast<uint16_t>(mountNode.attribute("clientid").value());
if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && lookType != 0 && !g_game().isLookTypeRegistered(lookType)) {
if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS, __FUNCTION__) && lookType != 0 && !g_game().isLookTypeRegistered(lookType)) {
g_logger().warn("{} - An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", __FUNCTION__, lookType);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/appearance/outfit/outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

bool Outfits::loadFromXml() {
pugi::xml_document doc;
auto folder = g_configManager().getString(CORE_DIRECTORY) + "/XML/outfits.xml";
auto folder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__) + "/XML/outfits.xml";
pugi::xml_parse_result result = doc.load_file(folder.c_str());
if (!result) {
printXMLError(__FUNCTION__, folder, result);
Expand Down Expand Up @@ -47,7 +47,7 @@ bool Outfits::loadFromXml() {
}

if (uint16_t lookType = pugi::cast<uint16_t>(lookTypeAttribute.value());
g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && lookType != 0
g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS, __FUNCTION__) && lookType != 0
&& !g_game().isLookTypeRegistered(lookType)) {
g_logger().warn("[Outfits::loadFromXml] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", lookType);
return false;
Expand Down
7 changes: 5 additions & 2 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ bool Combat::isInPvpZone(std::shared_ptr<Creature> attacker, std::shared_ptr<Cre
}

bool Combat::isProtected(std::shared_ptr<Player> attacker, std::shared_ptr<Player> target) {
uint32_t protectionLevel = g_configManager().getNumber(PROTECTION_LEVEL);
uint32_t protectionLevel = g_configManager().getNumber(PROTECTION_LEVEL, __FUNCTION__);
if (target->getLevel() < protectionLevel || attacker->getLevel() < protectionLevel) {
return true;
}
Expand Down Expand Up @@ -569,7 +569,7 @@ void Combat::CombatHealthFunc(std::shared_ptr<Creature> caster, std::shared_ptr<
targetPlayer = target->getPlayer();
}

if (caster && attackerPlayer) {
if (attackerPlayer) {
std::shared_ptr<Item> item = attackerPlayer->getWeapon();
damage = applyImbuementElementalDamage(attackerPlayer, item, damage);
g_events().eventPlayerOnCombat(attackerPlayer, target, item, damage);
Expand All @@ -582,6 +582,9 @@ void Combat::CombatHealthFunc(std::shared_ptr<Creature> caster, std::shared_ptr<
damage.secondary.value /= 2;
}
}

damage.damageMultiplier += attackerPlayer->wheel()->getMajorStatConditional("Divine Empowerment", WheelMajor_t::DAMAGE);
g_logger().debug("Wheel Divine Empowerment damage multiplier {}", damage.damageMultiplier);
}

if (g_game().combatBlockHit(damage, caster, target, params.blockedByShield, params.blockedByArmor, params.itemId != 0)) {
Expand Down
8 changes: 4 additions & 4 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ uint32_t ConditionRegeneration::getHealthTicks(std::shared_ptr<Creature> creatur
std::shared_ptr<Player> player = creature->getPlayer();

if (player != nullptr && isBuff) {
return healthTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN);
return healthTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__);
}

return healthTicks;
Expand All @@ -1258,7 +1258,7 @@ uint32_t ConditionRegeneration::getManaTicks(std::shared_ptr<Creature> creature)
std::shared_ptr<Player> player = creature->getPlayer();

if (player != nullptr && isBuff) {
return manaTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN);
return manaTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__);
}

return manaTicks;
Expand Down Expand Up @@ -2257,7 +2257,7 @@ void ConditionOutfit::serialize(PropWriteStream &propWriteStream) {
}

bool ConditionOutfit::startCondition(std::shared_ptr<Creature> creature) {
if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) {
if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS, __FUNCTION__) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) {
g_logger().warn("[ConditionOutfit::startCondition] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType);
return false;
}
Expand Down Expand Up @@ -2289,7 +2289,7 @@ void ConditionOutfit::endCondition(std::shared_ptr<Creature> creature) {
}

void ConditionOutfit::addCondition(std::shared_ptr<Creature> creature, const std::shared_ptr<Condition> addCondition) {
if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) {
if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS, __FUNCTION__) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) {
g_logger().warn("[ConditionOutfit::addCondition] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr
void Spell::applyCooldownConditions(std::shared_ptr<Player> player) const {
WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName());
bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast<uint8_t>(spellGrade) > 0;
auto rate_cooldown = (int32_t)g_configManager().getFloat(RATE_SPELL_COOLDOWN);
auto rate_cooldown = (int32_t)g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__);
if (cooldown > 0) {
int32_t spellCooldown = cooldown;
if (isUpgraded) {
Expand Down Expand Up @@ -981,7 +981,7 @@ bool RuneSpell::executeUse(std::shared_ptr<Player> player, std::shared_ptr<Item>
}

postCastSpell(player);
if (hasCharges && item && g_configManager().getBoolean(REMOVE_RUNE_CHARGES)) {
if (hasCharges && item && g_configManager().getBoolean(REMOVE_RUNE_CHARGES, __FUNCTION__)) {
int32_t newCount = std::max<int32_t>(0, item->getItemCount() - 1);
g_game().transformItem(item, item->getID(), newCount);
player->updateSupplyTracker(item);
Expand Down
Loading

0 comments on commit 12f4b11

Please sign in to comment.