@@ -3338,8 +3338,8 @@ bool Player::isPzLocked() const {
3338
3338
BlockType_t Player::blockHit (const std::shared_ptr<Creature> &attacker, const CombatType_t &combatType, int32_t &damage, bool checkDefense, bool checkArmor, bool field) {
3339
3339
BlockType_t blockType = Creature::blockHit (attacker, combatType, damage, checkDefense, checkArmor, field);
3340
3340
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 );
3343
3343
}
3344
3344
3345
3345
if (blockType != BLOCK_NONE) {
@@ -5809,7 +5809,7 @@ void Player::onEndCondition(ConditionType_t type) {
5809
5809
clearAttacked ();
5810
5810
5811
5811
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 ()));
5813
5813
}
5814
5814
5815
5815
if (getSkull () != SKULL_RED && getSkull () != SKULL_BLACK) {
@@ -5912,8 +5912,8 @@ void Player::onAttackedCreature(const std::shared_ptr<Creature> &target) {
5912
5912
}
5913
5913
5914
5914
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);
5917
5917
}
5918
5918
5919
5919
addInFightTicks ();
@@ -6525,6 +6525,45 @@ void Player::clearAttacked() {
6525
6525
attackedSet.clear ();
6526
6526
}
6527
6527
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
+
6528
6567
void Player::addUnjustifiedDead (const std::shared_ptr<Player> &attacked) {
6529
6568
if (hasFlag (PlayerFlags_t::NotGainInFight) || attacked == getPlayer () || g_game ().getWorldType () == WORLD_TYPE_PVP_ENFORCED) {
6530
6569
return ;
@@ -7830,7 +7869,7 @@ void Player::onThink(uint32_t interval) {
7830
7869
wheel ()->onThink ();
7831
7870
7832
7871
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 ()));
7834
7873
}
7835
7874
7836
7875
g_callbacks ().executeCallback (EventCallback_t::playerOnThink, &EventCallback::playerOnThink, getPlayer (), interval);
@@ -8039,9 +8078,9 @@ void Player::sendPrivateMessage(const std::shared_ptr<Player> &speaker, SpeakCla
8039
8078
}
8040
8079
}
8041
8080
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 {
8043
8082
if (client) {
8044
- client->sendCreatureSquare (creature, color, length );
8083
+ client->sendCreatureSquare (creature, color, type );
8045
8084
}
8046
8085
}
8047
8086
@@ -10083,8 +10122,8 @@ void Player::onCreatureAppear(const std::shared_ptr<Creature> &creature, bool is
10083
10122
Creature::onCreatureAppear (creature, isLogin);
10084
10123
10085
10124
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);
10088
10127
}
10089
10128
10090
10129
if (isLogin && creature == getPlayer ()) {
@@ -10805,6 +10844,42 @@ uint16_t Player::getPlayerVocationEnum() const {
10805
10844
return Vocation_t::VOCATION_NONE;
10806
10845
}
10807
10846
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
+
10808
10883
bool Player::hasPvpActivity (const std::shared_ptr<Player> &player, bool guildAndParty /* = false*/ ) const {
10809
10884
if (!g_configManager ().getBoolean (TOGGLE_EXPERT_PVP) || !player || player.get () == this ) {
10810
10885
return false ;
@@ -10836,7 +10911,7 @@ bool Player::hasPvpActivity(const std::shared_ptr<Player> &player, bool guildAnd
10836
10911
return false ;
10837
10912
}
10838
10913
10839
- bool Player::isInPvpSituation () {
10914
+ bool Player::isInPvpSituation () const {
10840
10915
if (!isPvpSituation) {
10841
10916
return false ;
10842
10917
}
@@ -10851,18 +10926,35 @@ bool Player::isInPvpSituation() {
10851
10926
continue ;
10852
10927
}
10853
10928
10854
- if (itPlayer->hasAttacked (getPlayer ())) {
10929
+ if (itPlayer->hasAttacked (std::const_pointer_cast<Player>( getPlayer () ))) {
10855
10930
return true ;
10856
10931
}
10857
10932
}
10858
10933
10859
10934
return false ;
10860
10935
}
10861
10936
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
+ }
10864
10948
10865
- if (squareColor == SQ_COLOR_YELLOW) {
10866
- sendCreatureSquare (creature, squareColor, 2 );
10949
+ return isAggressiveCreature (creature->getMaster (), guildAndParty, time);
10867
10950
}
10951
+
10952
+ if (player == getPlayer ()) {
10953
+ return true ;
10954
+ }
10955
+ else if (isPartner (player)) {
10956
+ return false ;
10957
+ }
10958
+
10959
+ return hasPvpActivity (player, guildAndParty);
10868
10960
}
0 commit comments