• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Triggering onManaChange for spells

Leo32

Getting back into it...
Joined
Sep 21, 2007
Messages
987
Solutions
14
Reaction score
532
I've got a curly one here.
I'm using this function:

Lua:
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
end

Works perfectly, for mana changes for everything (Manadrain, potions etc) EXCEPT for spells.
I've noticed other ppl have mentioned this:


Is it currently an open ticket here:

spells.cpp
C++:
void Spell::postCastSpell(Player* player, uint32_t manaCost, uint32_t soulCost)
{
    if (manaCost > 0) {
        player->addManaSpent(manaCost);
        player->changeMana(-static_cast<int32_t>(manaCost)); // this is the line that needs to change AFAIK
    }

    if (!player->hasFlag(PlayerFlag_HasInfiniteSoul)) {
        if (soulCost > 0) {
            player->changeSoul(-static_cast<int32_t>(soulCost));
        }
    }
}

I would like manachanges from player spells to go through the same CREATURE_EVENT_MANACHANGE function like everything else:
Which should solve the issue yeah?

game.cpp
C++:
bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage& damage)
...
...
        if (damage.origin != ORIGIN_NONE) {
            const auto& events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE);
            if (!events.empty()) {
                for (CreatureEvent* creatureEvent : events) {
                    creatureEvent->executeManaChange(target, attacker, damage);
                }
                damage.origin = ORIGIN_NONE;
                return combatChangeMana(attacker, target, damage);
            }
        }
...
...

The purpose is so these numbers can be manipulated and Mana Costs: -XX% attributes can be added to items.
Because my c++ is absolute trash, does anyone have any idea on what changes I'd need to make to spells.cpp(?) to do this?
 
Last edited:
It's not going to work because postCastSpell does not call combatChangeMana, player->changeMana is not a combat, just a simple reduction.
All you need to do is reduce manaCost in postCastSpell depending on the attributes currently affecting the player.

Something like this:

C++:
manaCost -= static_cast<int32_t>(manaCost * (player->getManaCostReduction() / 100.));
player->changeMana(-static_cast<int32_t>(manaCost));

And create a new player method for getManaCostReduction, copy Player::getArmor() for reference and just get the attribute you're looking for instead of armor.
 
It's not going to work because postCastSpell does not call combatChangeMana, player->changeMana is not a combat, just a simple reduction.
All you need to do is reduce manaCost in postCastSpell depending on the attributes currently affecting the player.

Something like this:

C++:
manaCost -= static_cast<int32_t>(manaCost * (player->getManaCostReduction() / 100.));
player->changeMana(-static_cast<int32_t>(manaCost));

And create a new player method for getManaCostReduction, copy Player::getArmor() for reference and just get the attribute you're looking for instead of armor.
Sadly my attribute system as a whole isn't implemented by adding big brain actual attributes to items, it's all based of pulling data from the item description string.

Lua:
if slotitemdesc:find "%[Stun Chance" then
     local stunchance = tonumber(string.match(slotitemdesc, '%[Stun Chance: %+(%d+)%%%]'))
...
...

My thinking is that pushing spellcast manacosts through combatChangeMana would be a quicker win than rebuilding everything from scratch.
Or settling for a Potions: +XX% attribute instead, as that will work as-is.

I'll sit on this for a bit and do a little more research.
 
Last edited:
Back
Top