Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Jan 3, 2024
1 parent 460f78d commit 98dc5a4
Show file tree
Hide file tree
Showing 84 changed files with 1,336 additions and 463 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/**'
- "src/**"
merge_group:
push:
paths:
- 'src/**'
- "src/**"
branches:
- main

env:
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'
MAKEFLAGS: "-j 2"

jobs:
cancel-runs:
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

job:
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/build-windows-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/**'
- "src/**"
merge_group:
push:
paths:
- 'src/**'
- "src/**"
branches:
- main
env:
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'
MAKEFLAGS: "-j 2"
jobs:
cancel-runs:
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

job:
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ client_assertions.txt
*-house.xml
*-monster.xml
*-npc.xml
monster_count.txt

# SFTP for Sublime
sftp-config.json
Expand Down
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,30 @@ endif()
# === IPO ===
option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON)
if(OPTIONS_ENABLE_IPO)
log_option_enabled("ipo")

include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
log_war("IPO is not supported: ${output}")
endif()
log_option_enabled("IPO/LTO")
if(MSVC)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
else()
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=auto")
message(STATUS "IPO/LTO enabled with -flto=auto for non-MSVC compiler.")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
log_war("IPO/LTO not supported: ${output}")
endif()
else()
log_option_disabled("IPO/LTO")
endif ()
endif()
else()
log_option_disabled("ipo")
log_option_disabled("IPO/LTO")
endif()

option(BUILD_TESTS "Build tests" OFF) # By default, tests will not be built
Expand Down
20 changes: 16 additions & 4 deletions cmake/modules/CanaryLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@ if (CMAKE_COMPILER_IS_GNUCXX)
endif()

# === IPO ===
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(TARGET ${PROJECT_NAME}_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
if(MSVC)
target_compile_options(${PROJECT_NAME}_lib PRIVATE "/GL")
set_target_properties(${PROJECT_NAME}_lib PROPERTIES
STATIC_LINKER_FLAGS "/LTCG"
SHARED_LINKER_FLAGS "/LTCG"
MODULE_LINKER_FLAGS "/LTCG"
EXE_LINKER_FLAGS "/LTCG")
else()
message(WARNING "IPO is not supported: ${output}")
include(CheckIPOSupported)
check_ipo_supported(RESULT result)
if(result)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=auto")
message(STATUS "IPO/LTO enabled with -flto=auto for non-MSVC compiler.")
set_property(TARGET ${PROJECT_NAME}_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO/LTO is not supported: ${output}")
endif()
endif()

# === UNITY BUILD (compile time reducer) ===
Expand Down
9 changes: 9 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ hazardCriticalInterval = 2000
hazardCriticalChance = 750
hazardCriticalMultiplier = 25
hazardDamageMultiplier = 200
hazardDefenseMultiplier = 0
hazardDodgeMultiplier = 85
hazardPodsDropMultiplier = 87
hazardPodsTimeToDamage = 2000
Expand Down Expand Up @@ -373,13 +374,20 @@ showScriptsLogInConsole = false
criticalChance = 10
inventoryGlowOnFiveBless = false
adventurersBlessingLevel = 21
skulledDeathLoseStoreItem = false
experienceDisplayRates = true
-- configure attack base on Fist Fighting skill/experience
-- multiplierSpeedOnFist * 5 (multiplies the value obtained from the player fist skill and multiplies it * 5) max 25 is recommended due minTicks limits else player stop attack
-- maxSpeedOnFist 500 miliseconds (The maximum attack speed that can be obtained no matter how high the player has the Fist Fighting skill.)
toggleAttackSpeedOnFist = false
multiplierSpeedOnFist = 5
maxSpeedOnFist = 500
disableLegacyRaids = false -- disable legacy XML raids
disableMonsterArmor = false
combatChainDelay = 50 -- minimum: 50 miliseconds
minElementalResistance = -200
maxElementalResistance = 200
maxDamageReflection = 200

-- Global server Save
-- NOTE: globalServerSaveNotifyDuration in minutes
Expand Down Expand Up @@ -466,6 +474,7 @@ location = "USA"
-- The URL layout is https://discord.com/api/webhooks/:id/:token
-- Leave empty if you wish to disable.
discordWebhookURL = ""
discordSendFooter = true

-- Vip System (Get more info in: https://github.com/opentibiabr/canary/pull/1063)
-- NOTE: set vipSystemEnabled to true to enable the vip system functionalities (this overrides premium checks)
Expand Down
4 changes: 2 additions & 2 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ int CanaryServer::run() {
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);
g_webhook().sendMessage(":yellow_square: Server is now **online** _(access restricted to staff)_");
} else {
g_game().setGameState(GAME_STATE_NORMAL);
g_webhook().sendMessage("Server is now online", "Server has successfully started.", WEBHOOK_COLOR_ONLINE);
g_webhook().sendMessage(":green_circle: Server is now **online**");
}

loaderStatus = LoaderStatus::LOADED;
Expand Down
9 changes: 9 additions & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum ConfigKey_t : uint16_t {
CHECK_EXPIRED_MARKET_OFFERS_EACH_MINUTES,
CLASSIC_ATTACK_SPEED,
CLEAN_PROTECTION_ZONES,
COMBAT_CHAIN_DELAY,
COMPRESSION_LEVEL,
CONVERT_UNSAFE_SCRIPTS,
CORE_DIRECTORY,
Expand All @@ -48,6 +49,9 @@ enum ConfigKey_t : uint16_t {
DEFAULT_PRIORITY,
DEPOTCHEST,
DEPOT_BOXES,
DISABLE_LEGACY_RAIDS,
DISABLE_MONSTER_ARMOR,
DISCORD_SEND_FOOTER,
DISCORD_WEBHOOK_DELAY_MS,
DISCORD_WEBHOOK_URL,
EMOTE_SPELLS,
Expand Down Expand Up @@ -88,6 +92,7 @@ enum ConfigKey_t : uint16_t {
HAZARD_CRITICAL_INTERVAL,
HAZARD_CRITICAL_MULTIPLIER,
HAZARD_DAMAGE_MULTIPLIER,
HAZARD_DEFENSE_MULTIPLIER,
HAZARD_DODGE_MULTIPLIER,
HAZARD_EXP_BONUS_MULTIPLIER,
HAZARD_LOOT_BONUS_MULTIPLIER,
Expand Down Expand Up @@ -127,6 +132,8 @@ enum ConfigKey_t : uint16_t {
MAX_ALLOWED_ON_A_DUMMY,
MAX_CONTAINER,
MAX_CONTAINER_ITEM,
MAX_DAMAGE_REFLECTION,
MAX_ELEMENTAL_RESISTANCE,
MAX_MARKET_OFFERS_AT_A_TIME_PER_PLAYER,
MAX_MESSAGEBUFFER,
MAX_PACKETS_PER_SECOND,
Expand All @@ -138,6 +145,7 @@ enum ConfigKey_t : uint16_t {
METRICS_ENABLE_PROMETHEUS,
METRICS_OSTREAM_INTERVAL,
METRICS_PROMETHEUS_ADDRESS,
MIN_ELEMENTAL_RESISTANCE,
MONTH_KILLS_TO_RED,
MULTIPLIER_ATTACKONFIST,
MYSQL_DB,
Expand Down Expand Up @@ -218,6 +226,7 @@ enum ConfigKey_t : uint16_t {
SCRIPTS_CONSOLE_LOGS,
SERVER_MOTD,
SERVER_NAME,
SKULLED_DEATH_LOSE_STORE_ITEM,
SORT_LOOT_BY_CHANCE,
SQL_PORT,
STAIRHOP_DELAY,
Expand Down
10 changes: 10 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ bool ConfigManager::load() {
loadIntConfig(L, STASH_ITEMS, "stashItemCount", 5000);

loadBoolConfig(L, OLD_PROTOCOL, "allowOldProtocol", true);
loadBoolConfig(L, DISABLE_LEGACY_RAIDS, "disableLegacyRaids", false);
}

loadBoolConfig(L, ALLOW_CHANGEOUTFIT, "allowChangeOutfit", true);
Expand All @@ -97,6 +98,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, CONVERT_UNSAFE_SCRIPTS, "convertUnsafeScripts", true);
loadBoolConfig(L, CLASSIC_ATTACK_SPEED, "classicAttackSpeed", false);
loadBoolConfig(L, TOGGLE_ATTACK_SPEED_ONFIST, "toggleAttackSpeedOnFist", false);
loadBoolConfig(L, DISABLE_MONSTER_ARMOR, "disableMonsterArmor", false);
loadIntConfig(L, MULTIPLIER_ATTACKONFIST, "multiplierSpeedOnFist", 5);
loadIntConfig(L, MAX_SPEED_ATTACKONFIST, "maxSpeedOnFist", 500);
loadBoolConfig(L, SCRIPTS_CONSOLE_LOGS, "showScriptsLogInConsole", true);
Expand Down Expand Up @@ -150,6 +152,7 @@ bool ConfigManager::load() {
loadStringConfig(L, WORLD_TYPE, "worldType", "pvp");
loadStringConfig(L, STORE_IMAGES_URL, "coinImagesURL", "");
loadStringConfig(L, DISCORD_WEBHOOK_URL, "discordWebhookURL", "");
loadBoolConfig(L, DISCORD_SEND_FOOTER, "discordSendFooter", true);
loadStringConfig(L, SAVE_INTERVAL_TYPE, "saveIntervalType", "");
loadStringConfig(L, GLOBAL_SERVER_SAVE_TIME, "globalServerSaveTime", "06:00");
loadStringConfig(L, DATA_DIRECTORY, "dataPackDirectory", "data-otservbr-global");
Expand Down Expand Up @@ -218,6 +221,7 @@ bool ConfigManager::load() {
loadIntConfig(L, CRITICALCHANCE, "criticalChance", 10);

loadIntConfig(L, ADVENTURERSBLESSING_LEVEL, "adventurersBlessingLevel", 21);
loadBoolConfig(L, SKULLED_DEATH_LOSE_STORE_ITEM, "skulledDeathLoseStoreItem", false);
loadIntConfig(L, FORGE_MAX_ITEM_TIER, "forgeMaxItemTier", 10);
loadIntConfig(L, FORGE_COST_ONE_SLIVER, "forgeCostOneSliver", 20);
loadIntConfig(L, FORGE_SLIVER_AMOUNT, "forgeSliverAmount", 3);
Expand Down Expand Up @@ -246,6 +250,7 @@ bool ConfigManager::load() {
loadFloatConfig(L, RATE_ATTACK_SPEED, "rateAttackSpeed", 1.0);
loadFloatConfig(L, RATE_OFFLINE_TRAINING_SPEED, "rateOfflineTrainingSpeed", 1.0);
loadFloatConfig(L, RATE_EXERCISE_TRAINING_SPEED, "rateExerciseTrainingSpeed", 1.0);
loadIntConfig(L, COMBAT_CHAIN_DELAY, "combatChainDelay", 50);

loadFloatConfig(L, RATE_MONSTER_HEALTH, "rateMonsterHealth", 1.0);
loadFloatConfig(L, RATE_MONSTER_ATTACK, "rateMonsterAttack", 1.0);
Expand All @@ -256,6 +261,10 @@ bool ConfigManager::load() {
loadIntConfig(L, BOSS_DEFAULT_TIME_TO_FIGHT_AGAIN, "bossDefaultTimeToFightAgain", 20 * 60 * 60);
loadIntConfig(L, BOSS_DEFAULT_TIME_TO_DEFEAT, "bossDefaultTimeToDefeat", 20 * 60);

loadIntConfig(L, MIN_ELEMENTAL_RESISTANCE, "minElementalResistance", -200);
loadIntConfig(L, MAX_ELEMENTAL_RESISTANCE, "maxElementalResistance", 200);
loadIntConfig(L, MAX_DAMAGE_REFLECTION, "maxDamageReflection", 200);

loadFloatConfig(L, RATE_NPC_HEALTH, "rateNpcHealth", 1.0);
loadFloatConfig(L, RATE_NPC_ATTACK, "rateNpcAttack", 1.0);
loadFloatConfig(L, RATE_NPC_DEFENSE, "rateNpcDefense", 1.0);
Expand Down Expand Up @@ -297,6 +306,7 @@ bool ConfigManager::load() {
loadIntConfig(L, HAZARD_CRITICAL_CHANCE, "hazardCriticalChance", 750);
loadIntConfig(L, HAZARD_CRITICAL_MULTIPLIER, "hazardCriticalMultiplier", 25);
loadIntConfig(L, HAZARD_DAMAGE_MULTIPLIER, "hazardDamageMultiplier", 200);
loadIntConfig(L, HAZARD_DEFENSE_MULTIPLIER, "hazardDefenseMultiplier", 0);
loadIntConfig(L, HAZARD_DODGE_MULTIPLIER, "hazardDodgeMultiplier", 85);
loadIntConfig(L, HAZARD_PODS_DROP_MULTIPLIER, "hazardPodsDropMultiplier", 87);
loadIntConfig(L, HAZARD_PODS_TIME_TO_DAMAGE, "hazardPodsTimeToDamage", 2000);
Expand Down
36 changes: 26 additions & 10 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ void Combat::combatTileEffects(const CreatureVector &spectators, std::shared_ptr

std::shared_ptr<Item> item = Item::CreateItem(itemId);
if (caster) {
item->setAttribute(ItemAttribute_t::OWNER, caster->getID());
item->setOwner(caster);
}

ReturnValue ret = g_game().internalAddItem(tile, item);
Expand Down Expand Up @@ -937,15 +937,26 @@ bool Combat::doCombatChain(std::shared_ptr<Creature> caster, std::shared_ptr<Cre
return false;
}

auto affected = targets.size();
int i = 0;
for (const auto &[from, toVector] : targets) {
auto combat = this;
auto delay = i * std::max<int32_t>(50, g_configManager().getNumber(COMBAT_CHAIN_DELAY, __FUNCTION__));
++i;
for (auto to : toVector) {
auto nextTarget = g_game().getCreatureByID(to);
if (!nextTarget) {
continue;
}
combat->doChainEffect(from, nextTarget->getPosition(), combat->params.chainEffect);
combat->doCombat(caster, nextTarget, from);
g_dispatcher().scheduleEvent(
delay, [combat, caster, nextTarget, from, affected]() {
if (combat && caster && nextTarget) {
combat->doChainEffect(from, nextTarget->getPosition(), combat->params.chainEffect);
combat->doCombat(caster, nextTarget, from, affected);
}
},
"Combat::doCombatChain"
);
}
}

Expand All @@ -960,10 +971,11 @@ bool Combat::doCombat(std::shared_ptr<Creature> caster, std::shared_ptr<Creature
return doCombat(caster, target, caster != nullptr ? caster->getPosition() : Position());
}

bool Combat::doCombat(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const Position &origin) const {
bool Combat::doCombat(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const Position &origin, int affected /* = 1 */) const {
// target combat callback function
if (params.combatType != COMBAT_NONE) {
CombatDamage damage = getCombatDamage(caster, target);
damage.affected = affected;
if (damage.primary.type != COMBAT_MANADRAIN) {
doCombatHealth(caster, target, origin, damage, params);
} else {
Expand Down Expand Up @@ -1987,14 +1999,18 @@ void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
const ItemType &it = items[getID()];
if (it.conditionDamage) {
auto conditionCopy = it.conditionDamage->clone();
auto ownerId = getAttribute<uint32_t>(ItemAttribute_t::OWNER);
auto ownerId = getOwnerId();
if (ownerId) {
bool harmfulField = true;
auto itemTile = getTile();
if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE)) {
std::shared_ptr<Creature> owner = g_game().getCreatureByID(ownerId);
if (owner) {
if (owner->getPlayer() || (owner->isSummon() && owner->getMaster()->getPlayer())) {
auto ownerPlayer = g_game().getPlayerByGUID(ownerId);
if (ownerPlayer) {
harmfulField = false;
}
auto ownerCreature = g_game().getCreatureByID(ownerId);
if (ownerCreature) {
if (ownerCreature->getPlayer() || (ownerCreature->isSummon() && ownerCreature->getMaster()->getPlayer())) {
harmfulField = false;
}
}
Expand Down Expand Up @@ -2049,14 +2065,14 @@ void Combat::applyExtensions(std::shared_ptr<Creature> caster, std::shared_ptr<C
}
}
} else if (monster) {
chance = monster->critChance();
chance = monster->critChance() * 100;
}

bonus += damage.criticalDamage;
double multiplier = 1.0 + static_cast<double>(bonus) / 100;
chance += (uint16_t)damage.criticalChance;

if (chance != 0 && uniform_random(1, 100) <= chance) {
if (chance != 0 && uniform_random(1, 10000) <= chance) {
damage.critical = true;
damage.primary.value *= multiplier;
damage.secondary.value *= multiplier;
Expand Down
Loading

0 comments on commit 98dc5a4

Please sign in to comment.