Skip to content

Commit

Permalink
fix: check conditions permitted on pz (#1865)
Browse files Browse the repository at this point in the history
Resolves #1656
  • Loading branch information
dudantas authored Nov 21, 2023
1 parent 71bdb2f commit f58413e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,20 @@ ReturnValue Combat::canDoCombat(std::shared_ptr<Creature> attacker, std::shared_
return RETURNVALUE_NOERROR;
}

auto targetPlayer = target ? target->getPlayer() : nullptr;
if (target) {
std::shared_ptr<Tile> tile = target->getTile();
if (tile->hasProperty(CONST_PROP_BLOCKPROJECTILE)) {
return RETURNVALUE_NOTENOUGHROOM;
}
if (tile->hasFlag(TILESTATE_PROTECTIONZONE)) {
return RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE;
auto permittedOnPz = targetPlayer ? targetPlayer->hasPermittedConditionInPZ() : false;
return permittedOnPz ? RETURNVALUE_NOERROR : RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE;
}
}

if (attacker) {
const std::shared_ptr<Creature> attackerMaster = attacker->getMaster();
auto targetPlayer = target ? target->getPlayer() : nullptr;
if (targetPlayer) {
if (targetPlayer->hasFlag(PlayerFlags_t::CannotBeAttacked)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
Expand Down
21 changes: 21 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7716,3 +7716,24 @@ std::shared_ptr<Container> Player::getLootPouch() {

return container;
}

bool Player::hasPermittedConditionInPZ() const {
static const std::unordered_set<ConditionType_t> allowedConditions = {
CONDITION_ENERGY,
CONDITION_FIRE,
CONDITION_POISON,
CONDITION_BLEEDING,
CONDITION_CURSED,
CONDITION_DAZZLED
};

bool hasPermittedCondition = false;
for (auto condition : allowedConditions) {
if (getCondition(condition)) {
hasPermittedCondition = true;
break;
}
}

return hasPermittedCondition;
}
2 changes: 2 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,8 @@ class Player final : public Creature, public Cylinder, public Bankable {

std::shared_ptr<Container> getLootPouch();

bool hasPermittedConditionInPZ() const;

private:
friend class PlayerLock;
std::mutex mutex;
Expand Down

0 comments on commit f58413e

Please sign in to comment.