Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Expert PvP #5

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cac5b95
* Initial expert pvp
jprzimba Dec 24, 2024
da4ea7d
Code format - (Clang-format)
github-actions[bot] Dec 24, 2024
04a8706
* Enabled expert pvp
jprzimba Dec 25, 2024
4d958ec
Code format - (Clang-format)
github-actions[bot] Dec 25, 2024
319c213
Merge branch 'main' into expert-pvp
jprzimba Dec 28, 2024
c50d8ec
Code format - (Clang-format)
github-actions[bot] Dec 28, 2024
2a2b043
Merge branch 'main' into expert-pvp
jprzimba Jan 4, 2025
133b447
Lua code format - (Stylua)
github-actions[bot] Jan 4, 2025
fa6bda4
Merge branch 'main' into expert-pvp
jprzimba Jan 6, 2025
53c452d
Code format - (Clang-format)
github-actions[bot] Jan 6, 2025
c537d56
Merge branch 'main' into expert-pvp
jprzimba Jan 8, 2025
836a8dc
Lua code format - (Stylua)
github-actions[bot] Jan 8, 2025
71df111
Merge branch 'main' into expert-pvp
jprzimba Jan 10, 2025
66f34da
* Optimizations on expert pvp
jprzimba Jan 10, 2025
09bf705
* Fixes to pvp expert
jprzimba Jan 10, 2025
0870b81
Code format - (Clang-format)
github-actions[bot] Jan 10, 2025
a07888d
* PvP Expert WalkThrough
jprzimba Jan 10, 2025
90f6968
Merge branch 'main' into expert-pvp
jprzimba Jan 10, 2025
eb50fe5
* PvP expert fixes
jprzimba Jan 10, 2025
78370fd
Code format - (Clang-format)
github-actions[bot] Jan 10, 2025
793b540
* Clear not in use
jprzimba Jan 10, 2025
f04149e
* Fix hasPvpActivity in isAggressiveCreature
jprzimba Jan 10, 2025
7f8bf5e
* Fixes to expert pbp
jprzimba Jan 11, 2025
e101a54
Code format - (Clang-format)
github-actions[bot] Jan 11, 2025
aa479d3
* clean for teste
jprzimba Jan 11, 2025
698a956
* Add this action again
jprzimba Jan 11, 2025
da1db30
* Agressive field
jprzimba Jan 11, 2025
60932b1
Merge branch 'main' into expert-pvp
jprzimba Jan 13, 2025
548488f
Merge branch 'main' into expert-pvp
jprzimba Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ blackSkulledDeathMana = 0
fieldOwnershipDuration = 5 * 1000
loginProtectionPeriod = 10 * 1000

-- Expert PvP
-- NOTE: toggleExpertPvp enables the PvP frames, similar to Tibia RL.
toggleExpertPvp = true
canWalkThroughOtherPlayers = false
canWalkThroughMagicWalls = false

cleanProtectionZones = false

-- Connection Config
Expand Down
3 changes: 3 additions & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ enum ConfigKey_t : uint16_t {
FIELD_OWNERSHIP,
BEDS_ONLY_PREMIUM,
LOGIN_PROTECTION,
TOGGLE_EXPERT_PVP,
EXPERT_PVP_CANWALKTHROUGHOTHERPLAYERS,
EXPERT_PVP_CANWALKTHROUGHMAGICWALLS,
SPELL_NAME_INSTEAD_WORDS,
LOG_PLAYERS_STATEMENTS,
ROOK_SYSTEM,
Expand Down
3 changes: 3 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ bool ConfigManager::load() {
loadBoolConfig(L, HALF_LOSS_MAGIC, "halfLossMagicLevel", true);
loadBoolConfig(L, CHAIN_SYSTEM_VIP_ONLY, "chainSystemVipOnly", false);
loadBoolConfig(L, BEDS_ONLY_PREMIUM, "bedsOnlyPremium", true);
loadBoolConfig(L, TOGGLE_EXPERT_PVP, "toggleExpertPvp", false);
loadBoolConfig(L, EXPERT_PVP_CANWALKTHROUGHOTHERPLAYERS, "canWalkThroughOtherPlayers", false);
loadBoolConfig(L, EXPERT_PVP_CANWALKTHROUGHMAGICWALLS, "canWalkThroughMagicWalls", false);
loadBoolConfig(L, SPELL_NAME_INSTEAD_WORDS, "spellNameInsteadOfWords", false);
loadBoolConfig(L, LOG_PLAYERS_STATEMENTS, "logPlayersStatements", false);
loadBoolConfig(L, ROOK_SYSTEM, "toggleRookSystem", false);
Expand Down
42 changes: 40 additions & 2 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@

if (isProtected(attackerPlayer, targetPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
} else if (!attackerPlayer->canCombat(targetPlayer)) {
return RETURNVALUE_ADJUSTYOURCOMBAT;
}

// nopvp-zone
Expand Down Expand Up @@ -374,6 +376,8 @@

if (isProtected(masterAttackerPlayer, targetPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
} else if (!masterAttackerPlayer->canCombat(targetPlayer)) {
return RETURNVALUE_ADJUSTYOURCOMBAT;
}
}
}
Expand All @@ -393,8 +397,14 @@
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}

if (target->isSummon() && target->getMaster()->getPlayer() && target->getZoneType() == ZONE_NOPVP) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
if (g_game().getOwnerPlayer(target)) {
if (target->getZoneType() == ZONE_NOPVP) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
} else if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP) && isProtected(attackerPlayer, targetPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
} else if (!attackerPlayer->canCombat(target)) {
return RETURNVALUE_ADJUSTYOURCOMBAT;
}
}
} else if (attacker->getMonster()) {
const auto &targetMaster = target->getMaster();
Expand All @@ -403,6 +413,16 @@
if (!attackerMaster || !attackerMaster->getPlayer()) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}
} else if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
if (g_game().getOwnerPlayer(target)) {
if (target->getZoneType() == ZONE_NOPVP) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
} else if (isProtected(attackerPlayer, targetPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
} else if (!attackerPlayer->canCombat(target)) {
return RETURNVALUE_ADJUSTYOURCOMBAT;
}
}
}
}
} else if (target && target->getNpc()) {
Expand Down Expand Up @@ -2235,6 +2255,11 @@
//**********************************************************//

void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
const auto &target = g_game().getOwnerPlayer(creature);
if (target && !isAggressive(target)) {
return;
}

// remove magic walls/wild growth
if ((!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE) || id == ITEM_WILDGROWTH_SAFE) {
if (!creature->isInGhostMode()) {
Expand Down Expand Up @@ -2375,6 +2400,19 @@
return 0;
}

bool MagicField::isAggressive(const std::shared_ptr<Player> &player) const {
if (!g_configManager().getBoolean(TOGGLE_EXPERT_PVP) && g_configManager().getBoolean(EXPERT_PVP_CANWALKTHROUGHMAGICWALLS)) {
return true;
}

const auto &caster = g_game().getOwnerPlayer(getOwnerId());
if (!caster || pvpMode == PVP_MODE_RED_FIST) {
return true;
}

return caster->isAggressiveCreature(player, pvpMode == PVP_MODE_WHITE_HAND, createTime) || pvpMode == PVP_MODE_YELLOW_HAND && player->getSkull() != SKULL_NONE;

Check warning on line 2413 in src/creatures/combat/combat.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]

Check warning on line 2413 in src/creatures/combat/combat.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
}

MatrixArea::MatrixArea(uint32_t initRows, uint32_t initCols) :
centerX(0), centerY(0), rows(initRows), cols(initCols) {
data_ = new bool*[rows];
Expand Down
4 changes: 4 additions & 0 deletions src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "items/item.hpp"
#include "lua/global/baseevents.hpp"
#include "creatures/creatures_definitions.hpp"

class Condition;
class Creature;
Expand Down Expand Up @@ -327,6 +328,9 @@ class MagicField final : public Item {
CombatType_t getCombatType() const;
int32_t getDamage() const;
void onStepInField(const std::shared_ptr<Creature> &creature);
bool isAggressive(const std::shared_ptr<Player> &player) const;

PvpMode_t pvpMode = PVP_MODE_DOVE;

private:
int64_t createTime;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,7 @@ bool ConditionDamage::doDamage(const std::shared_ptr<Creature> &creature, int32_
}

if (!creature->isAttackable() || Combat::canDoCombat(attacker, creature, damage.primary.type != COMBAT_HEALING) != RETURNVALUE_NOERROR) {
if (!creature->isInGhostMode() && !creature->getNpc()) {
if (!creature->isInGhostMode() && !creature->getNpc() && !g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
g_game().addMagicEffect(creature->getPosition(), CONST_ME_POFF);
}
return false;
Expand Down
Loading
Loading