Skip to content

Commit

Permalink
Merge pull request #22 from TheGlitchLab/fix-root-condition
Browse files Browse the repository at this point in the history
Fix: root condition implementation
  • Loading branch information
jprzimba authored Jan 16, 2025
2 parents e9c5fc8 + 7c21666 commit 4da4360
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,18 @@ bool Combat::checkFearConditionAffected(const std::shared_ptr<Player> &player) {
return true;
}

bool Combat::checkRootConditionAffected(const std::shared_ptr<Player> &player) {
if (player->isImmuneRoot()) {
return false;
}

if (player->hasCondition(CONDITION_ROOTED)) {
return false;
}

return true;
}

void Combat::CombatConditionFunc(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Creature> &target, const CombatParams &params, CombatDamage* data) {
if (params.origin == ORIGIN_MELEE && data && data->primary.value == 0 && data->secondary.value == 0) {
return;
Expand Down Expand Up @@ -805,6 +817,11 @@ void Combat::CombatConditionFunc(const std::shared_ptr<Creature> &caster, const
if (condition->getType() == CONDITION_FEARED && !checkFearConditionAffected(player)) {
return;
}

if (condition->getType() == CONDITION_ROOTED && !checkRootConditionAffected(player)) {
return;
}

}

if (caster == target || (target && !target->isImmune(condition->getType()))) {
Expand Down
1 change: 1 addition & 0 deletions src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class Combat {
* @return true if the fear condition can be applied, false otherwise.
*/
static bool checkFearConditionAffected(const std::shared_ptr<Player> &player);
static bool checkRootConditionAffected(const std::shared_ptr<Player> &player);
static void CombatConditionFunc(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Creature> &target, const CombatParams &params, CombatDamage* data);
static void CombatDispelFunc(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Creature> &target, const CombatParams &params, CombatDamage* data);
static void CombatNullFunc(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Creature> &target, const CombatParams &params, CombatDamage* data);
Expand Down
50 changes: 50 additions & 0 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ std::shared_ptr<Condition> Condition::createCondition(ConditionId_t id, Conditio
return std::make_shared<ConditionFeared>(id, type, ticks, buff, subId);

case CONDITION_ROOTED:
return std::make_shared<ConditionRooted>(id, type, ticks, buff, subId);

case CONDITION_INFIGHT:
case CONDITION_DRUNK:
case CONDITION_EXHAUST:
Expand Down Expand Up @@ -2230,6 +2232,54 @@ std::shared_ptr<Condition> ConditionFeared::clone() const {
return std::make_shared<ConditionFeared>(*this);
}

/**
* Condition Root
*/

ConditionRooted::ConditionRooted(ConditionId_t intiId, ConditionType_t initType, int32_t initTicks, bool initBuff, uint32_t initSubId) :
Condition(intiId, initType, initTicks, initBuff, initSubId) { }

bool ConditionRooted::startCondition(std::shared_ptr<Creature> creature) {
g_logger().debug("[ConditionRooted::executeCondition] Condition started for {}", creature->getName());
return Condition::startCondition(creature);
}

bool ConditionRooted::executeCondition(const std::shared_ptr<Creature> &creature, int32_t interval) {
Position currentPos = creature->getPosition();

g_logger().debug("[ConditionRooted::executeCondition] Executing condition, current position is {}", currentPos.toString());

return Condition::executeCondition(creature, interval);
}

void ConditionRooted::addCondition(std::shared_ptr<Creature>, const std::shared_ptr<Condition> addCondition) {
if (updateCondition(addCondition)) {
setTicks(addCondition->getTicks());
}
}

void ConditionRooted::endCondition(std::shared_ptr<Creature> creature) {
creature->stopEventWalk();
/*
* After a player is feared there's a 30 seconds before they can can feared again.
*/
const auto &player = creature->getPlayer();
if (player) {
player->setImmuneRoot();
}
}

std::unordered_set<PlayerIcon> ConditionRooted::getIcons() const {
auto icons = Condition::getIcons();

icons.insert(PlayerIcon::Rooted);
return icons;
}

std::shared_ptr<Condition> ConditionRooted::clone() const {
return std::make_shared<ConditionRooted>(*this);
}

/**
* ConditionSpeed
*/
Expand Down
14 changes: 14 additions & 0 deletions src/creatures/combat/condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@ class ConditionFeared final : public Condition {
uint8_t fleeIndx = 99;
};

class ConditionRooted final : public Condition {
public:
ConditionRooted() = default;
ConditionRooted(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff, uint32_t initSubId);

bool startCondition(std::shared_ptr<Creature> creature) override;
bool executeCondition(const std::shared_ptr<Creature> &creature, int32_t interval) override;
void endCondition(std::shared_ptr<Creature> creature) override;
void addCondition(std::shared_ptr<Creature> creature, std::shared_ptr<Condition> condition) override;
std::unordered_set<PlayerIcon> getIcons() const override;

std::shared_ptr<Condition> clone() const override;
};

class ConditionSpeed final : public Condition {
public:
ConditionSpeed(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff, uint32_t initSubId, int32_t initChangeSpeed);
Expand Down
10 changes: 10 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,16 @@ bool Player::isImmuneFear() const {
return (m_fearCondition.first == CONDITION_FEARED) && (timenow <= m_fearCondition.second);
}

void Player::setImmuneRoot() {
m_rootCondition.first = CONDITION_ROOTED;
m_rootCondition.second = OTSYS_TIME() + 30000;
}

bool Player::isImmuneRoot() const {
const uint64_t timenow = OTSYS_TIME();
return (m_rootCondition.first == CONDITION_ROOTED) && (timenow <= m_rootCondition.second);
}

uint16_t Player::parseRacebyCharm(charmRune_t charmId, bool set, uint16_t newRaceid) {
uint16_t raceid = 0;
switch (charmId) {
Expand Down
3 changes: 3 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,8 @@ class Player final : public Creature, public Cylinder, public Bankable {
bool isImmuneCleanse(ConditionType_t conditiontype) const;
void setImmuneFear();
bool isImmuneFear() const;
void setImmuneRoot();
bool isImmuneRoot() const;
uint16_t parseRacebyCharm(charmRune_t charmId, bool set, uint16_t newRaceid);

uint64_t getItemCustomPrice(uint16_t itemId, bool buyPrice = false) const;
Expand Down Expand Up @@ -1532,6 +1534,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
std::pair<ConditionType_t, uint64_t> cleanseCondition = { CONDITION_NONE, 0 };

std::pair<ConditionType_t, uint64_t> m_fearCondition = { CONDITION_NONE, 0 };
std::pair<ConditionType_t, uint64_t> m_rootCondition = { CONDITION_NONE, 0 };

uint8_t soul = 0;
uint8_t levelPercent = 0;
Expand Down

0 comments on commit 4da4360

Please sign in to comment.