Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spell Groups: Adapt revscript loading to spell groups #33

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ enum SpellGroup_t : uint8_t {
SPELLGROUP_HEALING = 2,
SPELLGROUP_SUPPORT = 3,
SPELLGROUP_SPECIAL = 4,

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

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 @@ -16671,7 +16671,7 @@ int LuaScriptInterface::luaSpellGroup(lua_State* L)
pushBoolean(L, true);
} else if (isString(L, 2)) {
group = stringToSpellGroup(getString(L, 2));
if (group != SPELLGROUP_NONE) {
if (group != SPELLGROUP_UNKNOWN) {
spell->setGroup(group);
} else {
std::cout << "[Warning - Spell::group] Unknown group: " << getString(L, 2) << std::endl;
Expand All @@ -16693,15 +16693,15 @@ int LuaScriptInterface::luaSpellGroup(lua_State* L)
pushBoolean(L, true);
} else if (isString(L, 2) && isString(L, 3)) {
primaryGroup = stringToSpellGroup(getString(L, 2));
if (primaryGroup != SPELLGROUP_NONE) {
if (primaryGroup != SPELLGROUP_UNKNOWN) {
spell->setGroup(primaryGroup);
} else {
std::cout << "[Warning - Spell::group] Unknown primaryGroup: " << getString(L, 2) << std::endl;
pushBoolean(L, false);
return 1;
}
secondaryGroup = stringToSpellGroup(getString(L, 3));
if (secondaryGroup != SPELLGROUP_NONE) {
if (secondaryGroup != SPELLGROUP_UNKNOWN) {
spell->setSecondaryGroup(secondaryGroup);
} else {
std::cout << "[Warning - Spell::group] Unknown secondaryGroup: " << getString(L, 3) << std::endl;
Expand Down
64 changes: 22 additions & 42 deletions src/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ bool Spell::configureSpell(const pugi::xml_node& node)
std::string tmpStr = asLowerCaseString(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 Down Expand Up @@ -761,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 (groupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group);
player->addCondition(condition);
}

if (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 @@ -878,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 (groupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group);
player->addCondition(condition);
}

if (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 @@ -938,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 (groupCooldown > 0) {
Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group);
player->addCondition(condition);
}

if (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
4 changes: 4 additions & 0 deletions src/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class Spell : public BaseSpell
}
void setGroup(SpellGroup_t g) {
group = g;
if(group == SPELLGROUP_NONE) {
groupCooldown = 0;
}
}
SpellGroup_t getSecondaryGroup() const {
return secondaryGroup;
Expand Down Expand Up @@ -277,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
8 changes: 5 additions & 3 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,9 @@ int64_t OTSYS_TIME()
SpellGroup_t stringToSpellGroup(const std::string& value)
{
std::string tmpStr = asLowerCaseString(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 @@ -1254,7 +1256,7 @@ SpellGroup_t stringToSpellGroup(const std::string& value)
return SPELLGROUP_SPECIAL;
}

return SPELLGROUP_NONE;
return SPELLGROUP_UNKNOWN;
}

std::vector<uint16_t> depotBoxes = {
Expand Down Expand Up @@ -1300,4 +1302,4 @@ std::string getStatName(uint8_t id)
default:
return "unknown";
}
}
}
Loading