Skip to content

Commit 09bf705

Browse files
committed
* Fixes to pvp expert
1 parent 66f34da commit 09bf705

File tree

9 files changed

+138
-225
lines changed

9 files changed

+138
-225
lines changed

.github/workflows/analysis-reviewdog-cppcheck.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/analysis-reviewdog.yml

Lines changed: 0 additions & 121 deletions
This file was deleted.

src/creatures/players/player.cpp

Lines changed: 108 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,8 +3338,8 @@ bool Player::isPzLocked() const {
33383338
BlockType_t Player::blockHit(const std::shared_ptr<Creature> &attacker, const CombatType_t &combatType, int32_t &damage, bool checkDefense, bool checkArmor, bool field) {
33393339
BlockType_t blockType = Creature::blockHit(attacker, combatType, damage, checkDefense, checkArmor, field);
33403340

3341-
if (!g_configManager().getBoolean(TOGGLE_EXPERT_PVP) && attacker) {
3342-
sendCreatureSquare(attacker, SQ_COLOR_BLACK);
3341+
if (attacker) {
3342+
//sendCreatureSquare(attacker, SQ_COLOR_BLACK, SQUARE_FLASH);
33433343
}
33443344

33453345
if (blockType != BLOCK_NONE) {
@@ -5809,7 +5809,7 @@ void Player::onEndCondition(ConditionType_t type) {
58095809
clearAttacked();
58105810

58115811
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
5812-
g_game().updateSpectatorsPvp(std::const_pointer_cast<Player>(getPlayer()));
5812+
g_game().updateCreatureSquare(std::const_pointer_cast<Player>(getPlayer()));
58135813
}
58145814

58155815
if (getSkull() != SKULL_RED && getSkull() != SKULL_BLACK) {
@@ -5912,8 +5912,8 @@ void Player::onAttackedCreature(const std::shared_ptr<Creature> &target) {
59125912
}
59135913

59145914
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
5915-
g_game().updateSpectatorsPvp(std::const_pointer_cast<Player>(getPlayer()));
5916-
g_game().updateSpectatorsPvp(targetPlayer);
5915+
g_game().updateCreatureSquare(std::const_pointer_cast<Player>(getPlayer()));
5916+
g_game().updateCreatureSquare(targetPlayer);
59175917
}
59185918

59195919
addInFightTicks();
@@ -6525,6 +6525,45 @@ void Player::clearAttacked() {
65256525
attackedSet.clear();
65266526
}
65276527

6528+
bool Player::isAttackedBy(const std::shared_ptr<Player> &attacker) const
6529+
{
6530+
if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacker) {
6531+
return false;
6532+
}
6533+
6534+
return attackedBySet.find(attacker->guid) != attackedBySet.end();
6535+
}
6536+
6537+
void Player::addAttackedBy(const std::shared_ptr<Player> &attacker)
6538+
{
6539+
if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacker || attacker == getPlayer()) {
6540+
return;
6541+
}
6542+
6543+
attackedBySet.emplace(attacker->guid);
6544+
}
6545+
6546+
void Player::removeAttackedBy(const std::shared_ptr<Player> &attacker)
6547+
{
6548+
if (!attacker || attacker == getPlayer()) {
6549+
return;
6550+
}
6551+
6552+
attackedBySet.erase(attacker->guid);
6553+
}
6554+
6555+
void Player::clearAttackedBy()
6556+
{
6557+
for (auto it : attackedBySet) {
6558+
if (const auto &attacker = g_game().getPlayerByGUID(it)) {
6559+
attacker->removeAttacked(getPlayer());
6560+
g_game().updateCreatureSquare(attacker);
6561+
}
6562+
}
6563+
6564+
attackedBySet.clear();
6565+
}
6566+
65286567
void Player::addUnjustifiedDead(const std::shared_ptr<Player> &attacked) {
65296568
if (hasFlag(PlayerFlags_t::NotGainInFight) || attacked == getPlayer() || g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) {
65306569
return;
@@ -7830,7 +7869,7 @@ void Player::onThink(uint32_t interval) {
78307869
wheel()->onThink();
78317870

78327871
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
7833-
g_game().updateSpectatorsPvp(std::const_pointer_cast<Player>(getPlayer()));
7872+
g_game().updateCreatureSquare(std::const_pointer_cast<Player>(getPlayer()));
78347873
}
78357874

78367875
g_callbacks().executeCallback(EventCallback_t::playerOnThink, &EventCallback::playerOnThink, getPlayer(), interval);
@@ -8039,9 +8078,9 @@ void Player::sendPrivateMessage(const std::shared_ptr<Player> &speaker, SpeakCla
80398078
}
80408079
}
80418080

8042-
void Player::sendCreatureSquare(const std::shared_ptr<Creature> &creature, SquareColor_t color, uint8_t length) const {
8081+
void Player::sendCreatureSquare(const std::shared_ptr<Creature> &creature, SquareColor_t color, SquareType_t type) const {
80438082
if (client) {
8044-
client->sendCreatureSquare(creature, color, length);
8083+
client->sendCreatureSquare(creature, color, type);
80458084
}
80468085
}
80478086

@@ -10083,8 +10122,8 @@ void Player::onCreatureAppear(const std::shared_ptr<Creature> &creature, bool is
1008310122
Creature::onCreatureAppear(creature, isLogin);
1008410123

1008510124
if (g_configManager().getBoolean(TOGGLE_EXPERT_PVP)) {
10086-
g_game().updateSpectatorsPvp(getPlayer());
10087-
g_game().updateSpectatorsPvp(creature);
10125+
g_game().updateCreatureSquare(getPlayer());
10126+
g_game().updateCreatureSquare(creature);
1008810127
}
1008910128

1009010129
if (isLogin && creature == getPlayer()) {
@@ -10805,6 +10844,42 @@ uint16_t Player::getPlayerVocationEnum() const {
1080510844
return Vocation_t::VOCATION_NONE;
1080610845
}
1080710846

10847+
SquareColor_t Player::getCreatureSquare(const std::shared_ptr<Creature> &creature) const
10848+
{
10849+
if (!creature) {
10850+
return SQ_COLOR_NONE;
10851+
}
10852+
10853+
if (creature == getPlayer()) {
10854+
if (isInPvpSituation()) {
10855+
return SQ_COLOR_YELLOW;
10856+
}
10857+
return SQ_COLOR_NONE;
10858+
}
10859+
else if (creature->isSummon()) {
10860+
return getCreatureSquare(creature->getMaster());
10861+
}
10862+
10863+
const auto &otherPlayer = creature->getPlayer();
10864+
if (!otherPlayer || otherPlayer->isAccessPlayer()) {
10865+
return SQ_COLOR_NONE;
10866+
}
10867+
10868+
if (isAggressiveCreature(otherPlayer)) {
10869+
return SQ_COLOR_YELLOW;
10870+
}
10871+
else if (otherPlayer->isInPvpSituation()) {
10872+
if (isAggressiveCreature(otherPlayer, true)) {
10873+
return SQ_COLOR_ORANGE;
10874+
}
10875+
else {
10876+
return SQ_COLOR_BROWN;
10877+
}
10878+
}
10879+
10880+
return SQ_COLOR_NONE;
10881+
}
10882+
1080810883
bool Player::hasPvpActivity(const std::shared_ptr<Player> &player, bool guildAndParty /* = false*/) const {
1080910884
if (!g_configManager().getBoolean(TOGGLE_EXPERT_PVP) || !player || player.get() == this) {
1081010885
return false;
@@ -10836,7 +10911,7 @@ bool Player::hasPvpActivity(const std::shared_ptr<Player> &player, bool guildAnd
1083610911
return false;
1083710912
}
1083810913

10839-
bool Player::isInPvpSituation() {
10914+
bool Player::isInPvpSituation() const {
1084010915
if (!isPvpSituation) {
1084110916
return false;
1084210917
}
@@ -10851,18 +10926,35 @@ bool Player::isInPvpSituation() {
1085110926
continue;
1085210927
}
1085310928

10854-
if (itPlayer->hasAttacked(getPlayer())) {
10929+
if (itPlayer->hasAttacked(std::const_pointer_cast<Player>(getPlayer()))) {
1085510930
return true;
1085610931
}
1085710932
}
1085810933

1085910934
return false;
1086010935
}
1086110936

10862-
void Player::sendPvpSquare(const std::shared_ptr<Creature> &creature, SquareColor_t squareColor) {
10863-
sendCreatureSquare(creature, squareColor, 2);
10937+
bool Player::isAggressiveCreature(const std::shared_ptr<Creature> &creature, bool guildAndParty /*= false*/, uint32_t time /*= 0*/) const
10938+
{
10939+
if (!creature) {
10940+
return false;
10941+
}
10942+
10943+
const auto &player = creature->getPlayer();
10944+
if (!player) {
10945+
if (!creature->isSummon()) {
10946+
return false;
10947+
}
1086410948

10865-
if (squareColor == SQ_COLOR_YELLOW) {
10866-
sendCreatureSquare(creature, squareColor, 2);
10949+
return isAggressiveCreature(creature->getMaster(), guildAndParty, time);
1086710950
}
10951+
10952+
if (player == getPlayer()) {
10953+
return true;
10954+
}
10955+
else if (isPartner(player)) {
10956+
return false;
10957+
}
10958+
10959+
return hasPvpActivity(player, guildAndParty);
1086810960
}

0 commit comments

Comments
 (0)