Skip to content

Commit

Permalink
* Optimizations on expert pvp
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Jan 10, 2025
1 parent 71df111 commit 66f34da
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ bool Player::isPzLocked() const {
BlockType_t Player::blockHit(const std::shared_ptr<Creature> &attacker, const CombatType_t &combatType, int32_t &damage, bool checkDefense, bool checkArmor, bool field) {
BlockType_t blockType = Creature::blockHit(attacker, combatType, damage, checkDefense, checkArmor, field);

if (!g_game().isExpertPvpEnabled() && attacker) {
if (!g_configManager().getBoolean(TOGGLE_EXPERT_PVP) && attacker) {
sendCreatureSquare(attacker, SQ_COLOR_BLACK);
}

Expand Down Expand Up @@ -5808,7 +5808,7 @@ void Player::onEndCondition(ConditionType_t type) {
pzLocked = false;
clearAttacked();

if (g_game().isExpertPvpEnabled()) {
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
g_game().updateSpectatorsPvp(std::const_pointer_cast<Player>(getPlayer()));
}

Expand Down Expand Up @@ -5878,7 +5878,7 @@ void Player::onAttackedCreature(const std::shared_ptr<Creature> &target) {

const auto &targetPlayer = target->getPlayer();
if (targetPlayer) {
if (!g_game().isExpertPvpEnabled() && (isPartner(targetPlayer) || isGuildMate(targetPlayer))) {
if (!g_configManager().getBoolean(TOGGLE_EXPERT_PVP) && (isPartner(targetPlayer) || isGuildMate(targetPlayer))) {
addInFightTicks();
return;
}
Expand Down Expand Up @@ -5911,7 +5911,7 @@ void Player::onAttackedCreature(const std::shared_ptr<Creature> &target) {
}
}

if (g_game().isExpertPvpEnabled()) {
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
g_game().updateSpectatorsPvp(std::const_pointer_cast<Player>(getPlayer()));
g_game().updateSpectatorsPvp(targetPlayer);
}
Expand Down Expand Up @@ -7829,7 +7829,7 @@ void Player::onThink(uint32_t interval) {
// Wheel of destiny major spells
wheel()->onThink();

if (g_game().isExpertPvpEnabled()) {
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
g_game().updateSpectatorsPvp(std::const_pointer_cast<Player>(getPlayer()));
}

Expand Down Expand Up @@ -10082,7 +10082,7 @@ void Player::onRemoveTileItem(const std::shared_ptr<Tile> &fromTile, const Posit
void Player::onCreatureAppear(const std::shared_ptr<Creature> &creature, bool isLogin) {
Creature::onCreatureAppear(creature, isLogin);

if (g_game().isExpertPvpEnabled()) {
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
g_game().updateSpectatorsPvp(getPlayer());
g_game().updateSpectatorsPvp(creature);
}
Expand Down Expand Up @@ -10806,7 +10806,7 @@ uint16_t Player::getPlayerVocationEnum() const {
}

bool Player::hasPvpActivity(const std::shared_ptr<Player> &player, bool guildAndParty /* = false*/) const {
if (!g_game().isExpertPvpEnabled() || !player || player.get() == this) {
if (!g_configManager().getBoolean(TOGGLE_EXPERT_PVP) || !player || player.get() == this) {
return false;
}

Expand Down
20 changes: 6 additions & 14 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5953,14 +5953,11 @@ void Game::playerSetFightModes(uint32_t playerId, FightMode_t fightMode, PvpMode
return;
}

PvpMode_t oldPvpMode = player->getPvPMode();
bool expertPvp = isExpertPvpEnabled();

player->setFightMode(fightMode);
player->setChaseMode(chaseMode);

if (expertPvp) {
WorldType_t worldType = getWorldType();
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
auto oldPvpMode = player->pvpMode;
if (worldType == WORLD_TYPE_NO_PVP && pvpMode == PVP_MODE_RED_FIST) {
player->setPvpMode(player->pvpMode);
} else if (worldType == WORLD_TYPE_PVP_ENFORCED && pvpMode != PVP_MODE_RED_FIST) {
Expand All @@ -5972,19 +5969,18 @@ void Game::playerSetFightModes(uint32_t playerId, FightMode_t fightMode, PvpMode
if ((worldType == WORLD_TYPE_NO_PVP && !secureMode) || (worldType == WORLD_TYPE_PVP_ENFORCED && secureMode)) {
player->setSecureMode(!secureMode);
} else {
if (player->getPvPMode() == PVP_MODE_RED_FIST) {
if (player->getPvPMode() == PVP_MODE_RED_FIST && oldPvpMode != PVP_MODE_RED_FIST) {
player->setSecureMode(false);
} else if (player->pvpMode != PVP_MODE_RED_FIST && oldPvpMode == PVP_MODE_RED_FIST) {
player->setSecureMode(true);
} else {
player->setSecureMode(secureMode);
}

if (oldPvpMode == PVP_MODE_RED_FIST) {
player->setSecureMode(true);
}
}

player->sendFightModes();
} else {
player->setPvpMode(pvpMode);
player->setSecureMode(secureMode);
}
}
Expand Down Expand Up @@ -10957,10 +10953,6 @@ void Game::updatePlayersOnline() const {
}
}

bool Game::isExpertPvpEnabled() {
return g_configManager().getBoolean(TOGGLE_EXPERT_PVP);
}

void Game::updateSpectatorsPvp(const std::shared_ptr<Thing> &thing) {
if (!thing) {
return;
Expand Down
1 change: 0 additions & 1 deletion src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ class Game {
bool addUniqueItem(uint16_t uniqueId, std::shared_ptr<Item> item);
void removeUniqueItem(uint16_t uniqueId);

bool isExpertPvpEnabled();
void updateSpectatorsPvp(const std::shared_ptr<Thing> &thing);

bool hasEffect(uint16_t effectId);
Expand Down
5 changes: 3 additions & 2 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6848,8 +6848,9 @@ void ProtocolGame::sendAddCreature(const std::shared_ptr<Creature> &creature, co
}
}

msg.addByte(0x00); // can change pvp framing option
msg.addByte(g_game().isExpertPvpEnabled() ? 0x01 : 0x00); // expert mode button enabled
bool expertPvp = g_configManager().getBoolean(TOGGLE_EXPERT_PVP);
msg.addByte(expertPvp ? 0x01 : 0x00); // can change pvp framing option
msg.addByte(expertPvp ? 0x01 : 0x00); // expert mode button enabled

msg.addString(g_configManager().getString(STORE_IMAGES_URL));
msg.add<uint16_t>(static_cast<uint16_t>(g_configManager().getNumber(STORE_COIN_PACKET)));
Expand Down

0 comments on commit 66f34da

Please sign in to comment.