Skip to content

Commit

Permalink
Adapting revscript to loading 'none'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofame committed Dec 10, 2024
1 parent 504a603 commit bc056f6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ enum SpellGroup_t : uint8_t
SPELLGROUP_CRIPPLING = 6,
SPELLGROUP_FOCUS = 7,
SPELLGROUP_ULTIMATESTRIKES = 8,

SPELLGROUP_UNKNOWN = 255, // last, unspecified
};

enum SpellType_t : uint8_t
Expand Down
6 changes: 3 additions & 3 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16375,7 +16375,7 @@ int LuaScriptInterface::luaSpellGroup(lua_State* L)
tfs::lua::pushBoolean(L, true);
} else if (lua_isstring(L, 2)) {
group = stringToSpellGroup(tfs::lua::getString(L, 2));
if (group != SPELLGROUP_NONE) {
if (group != SPELLGROUP_UNKNOWN) {
spell->setGroup(group);
} else {
std::cout << "[Warning - Spell::group] Unknown group: " << tfs::lua::getString(L, 2) << '\n';
Expand All @@ -16397,15 +16397,15 @@ int LuaScriptInterface::luaSpellGroup(lua_State* L)
tfs::lua::pushBoolean(L, true);
} else if (lua_isstring(L, 2) && lua_isstring(L, 3)) {
primaryGroup = stringToSpellGroup(tfs::lua::getString(L, 2));
if (primaryGroup != SPELLGROUP_NONE) {
if (primaryGroup != SPELLGROUP_UNKNOWN) {
spell->setGroup(primaryGroup);
} else {
std::cout << "[Warning - Spell::group] Unknown primaryGroup: " << tfs::lua::getString(L, 2) << '\n';
tfs::lua::pushBoolean(L, false);
return 1;
}
secondaryGroup = stringToSpellGroup(tfs::lua::getString(L, 3));
if (secondaryGroup != SPELLGROUP_NONE) {
if (secondaryGroup != SPELLGROUP_UNKNOWN) {
spell->setSecondaryGroup(secondaryGroup);
} else {
std::cout << "[Warning - Spell::group] Unknown secondaryGroup: " << tfs::lua::getString(L, 3)
Expand Down
16 changes: 9 additions & 7 deletions src/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ bool Spell::configureSpell(const pugi::xml_node& node)
std::string tmpStr = boost::algorithm::to_lower_copy<std::string>(attr.as_string());
if (tmpStr == "none" || tmpStr == "0") {
group = SPELLGROUP_NONE;
groupCooldown = 0;
} else if (tmpStr == "attack" || tmpStr == "1") {
group = SPELLGROUP_ATTACK;
} else if (tmpStr == "healing" || tmpStr == "2") {
Expand All @@ -406,6 +407,7 @@ bool Spell::configureSpell(const pugi::xml_node& node)
std::string tmpStr = boost::algorithm::to_lower_copy<std::string>(attr.as_string());
if (tmpStr == "none" || tmpStr == "0") {
secondaryGroup = SPELLGROUP_NONE;
secondaryGroupCooldown = 0;
} else if (tmpStr == "attack" || tmpStr == "1") {
secondaryGroup = SPELLGROUP_ATTACK;
} else if (tmpStr == "healing" || tmpStr == "2") {
Expand Down Expand Up @@ -551,7 +553,7 @@ bool Spell::playerSpellCheck(Player* player) const
return false;
}

if (player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, group) ||
if ((group != SPELLGROUP_NONE && player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, group)) ||
player->hasCondition(CONDITION_SPELLCOOLDOWN, spellId) ||
(secondaryGroup != SPELLGROUP_NONE && player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, secondaryGroup))) {
player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED);
Expand Down Expand Up @@ -741,13 +743,13 @@ void Spell::postCastSpell(Player* player, bool finishedCast /*= true*/, bool pay
player->addCondition(condition);
}

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

if (secondaryGroupCooldown > 0) {
if (secondaryGroup != SPELLGROUP_NONE && secondaryGroupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN,
secondaryGroupCooldown, 0, false, secondaryGroup);
player->addCondition(condition);
Expand Down Expand Up @@ -857,13 +859,13 @@ bool InstantSpell::playerCastInstant(Player* player, std::string& param)
player->addCondition(condition);
}

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

if (secondaryGroupCooldown > 0) {
if (secondaryGroup != SPELLGROUP_NONE && secondaryGroupCooldown > 0) {
Condition* condition =
Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN,
secondaryGroupCooldown, 0, false, secondaryGroup);
Expand Down Expand Up @@ -921,13 +923,13 @@ bool InstantSpell::playerCastInstant(Player* player, std::string& param)
player->addCondition(condition);
}

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

if (secondaryGroupCooldown > 0) {
if (secondaryGroup != SPELLGROUP_NONE && secondaryGroupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN,
secondaryGroupCooldown, 0, false, secondaryGroup);
player->addCondition(condition);
Expand Down
7 changes: 6 additions & 1 deletion src/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ class Spell : public BaseSpell
}

SpellGroup_t getGroup() const { return group; }
void setGroup(SpellGroup_t g) { group = g; }
void setGroup(SpellGroup_t g) {
group = g;
if(group == SPELLGROUP_NONE) {
groupCooldown = 0;
}
}
SpellGroup_t getSecondaryGroup() const { return secondaryGroup; }
void setSecondaryGroup(SpellGroup_t g) { secondaryGroup = g; }

Expand Down
6 changes: 4 additions & 2 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ int64_t OTSYS_TIME()
SpellGroup_t stringToSpellGroup(const std::string& value)
{
std::string tmpStr = boost::algorithm::to_lower_copy(value);
if (tmpStr == "attack" || tmpStr == "1") {
if (tmpStr == "none" || tmpStr == "0") {
return SPELLGROUP_NONE;
} else if (tmpStr == "attack" || tmpStr == "1") {
return SPELLGROUP_ATTACK;
} else if (tmpStr == "healing" || tmpStr == "2") {
return SPELLGROUP_HEALING;
Expand All @@ -1125,7 +1127,7 @@ SpellGroup_t stringToSpellGroup(const std::string& value)
return SPELLGROUP_SPECIAL;
}

return SPELLGROUP_NONE;
return SPELLGROUP_UNKNOWN;
}

const std::vector<Direction>& getShuffleDirections()
Expand Down

0 comments on commit bc056f6

Please sign in to comment.