Skip to content

Commit

Permalink
Avoid code repeat, better enum description
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofame committed Dec 10, 2024
1 parent dcc9221 commit ea088e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ enum SpellGroup_t : uint8_t {
SPELLGROUP_SUPPORT = 3,
SPELLGROUP_SPECIAL = 4,

SPELLGROUP_UNKNOWN = 255, // last, unspecified
SPELLGROUP_UNKNOWN = 255 // when no group set in revscript
};

enum SpellType_t : uint8_t {
Expand Down
63 changes: 21 additions & 42 deletions src/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,24 +762,29 @@ bool Spell::playerRuneSpellCheck(Player* player, const Position& toPos)
return true;
}

void Spell::addCooldowns(Player* player) const
{
if (cooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, cooldown, 0, false, spellId);
player->addCondition(condition);
}

if (group != SPELLGROUP_NONE && groupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group);
player->addCondition(condition);
}

if (secondaryGroup != SPELLGROUP_NONE && secondaryGroupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, secondaryGroupCooldown, 0, false, secondaryGroup);
player->addCondition(condition);
}
}

void Spell::postCastSpell(Player* player, bool finishedCast /*= true*/, bool payCost /*= true*/) const
{
if (finishedCast) {
if (!player->hasFlag(PlayerFlag_HasNoExhaustion)) {
if (cooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, cooldown, 0, false, spellId);
player->addCondition(condition);
}

if (group != SPELLGROUP_NONE && groupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group);
player->addCondition(condition);
}

if (secondaryGroup != SPELLGROUP_NONE && secondaryGroupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, secondaryGroupCooldown, 0, false, secondaryGroup);
player->addCondition(condition);
}
addCooldowns(player);
}

if (aggressive) {
Expand Down Expand Up @@ -879,20 +884,7 @@ bool InstantSpell::playerCastInstant(Player* player, std::string& param)
target = playerTarget;
if (!target || target->isRemoved() || target->isDead()) {
if (!casterTargetOrDirection) {
if (cooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, cooldown, 0, false, spellId);
player->addCondition(condition);
}

if (group != SPELLGROUP_NONE && groupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group);
player->addCondition(condition);
}

if (secondaryGroup != SPELLGROUP_NONE && secondaryGroupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, secondaryGroupCooldown, 0, false, secondaryGroup);
player->addCondition(condition);
}
addCooldowns(player);

player->sendCancelMessage(ret);
g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
Expand Down Expand Up @@ -939,20 +931,7 @@ bool InstantSpell::playerCastInstant(Player* player, std::string& param)
ReturnValue ret = g_game.getPlayerByNameWildcard(param, playerTarget);

if (ret != RETURNVALUE_NOERROR) {
if (cooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, cooldown, 0, false, spellId);
player->addCondition(condition);
}

if (group != SPELLGROUP_NONE && groupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group);
player->addCondition(condition);
}

if (secondaryGroup != SPELLGROUP_NONE && secondaryGroupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, secondaryGroupCooldown, 0, false, secondaryGroup);
player->addCondition(condition);
}
addCooldowns(player);

player->sendCancelMessage(ret);
g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
Expand Down
1 change: 1 addition & 0 deletions src/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class Spell : public BaseSpell
bool playerSpellCheck(Player* player) const;
bool playerInstantSpellCheck(Player* player, const Position& toPos);
bool playerRuneSpellCheck(Player* player, const Position& toPos);
void addCooldowns(Player* player) const;

VocSpellMap vocSpellMap;

Expand Down

0 comments on commit ea088e5

Please sign in to comment.