I've added the old mana cost system to spells.
Berserk(exori) for example, used to cost "level * 4" mana, with this you can add manaxlevel="X"(X can be anything you like and is a multiplier) into spells.xml.
Source: Berserk (https://tibia.fandom.com/wiki/Berserk)
Okay here goes:
And that should be all, if you have any questions feel free to ask them here. If you have any improvements or find an issue feel free to share.
Hope you enjoy it!
EDIT: I took the liberty of fixing spellbook.lua so they're compatible with this edit (Keep in mind that I've changed it to show Magic Level instead of Level):
Berserk(exori) for example, used to cost "level * 4" mana, with this you can add manaxlevel="X"(X can be anything you like and is a multiplier) into spells.xml.
Source: Berserk (https://tibia.fandom.com/wiki/Berserk)
Okay here goes:
spells.cpp
Under
Add
In Spell::getManaCost
Under
Add
spells.h
Under
Add
Under
Add
luascript.cpp
Under
Add
Under
Add
Under
Add
Under
Add
Under
Add
luascript.h
Under
Add
Under
Add
weapons.cpp
Under
Add
Switch
To
weapons.h
Under
Add
Under
Add
Under
C++:
if ((attr = node.attribute("mana"))) {
mana = pugi::cast<uint32_t>(attr.value());
}
C++:
if ((attr = node.attribute("manaxlevel"))) {
manaXLevel = pugi::cast<uint32_t>(attr.value());
}
In Spell::getManaCost
Under
C++:
if (mana != 0) {
return mana;
}
C++:
if (manaXLevel != 0) {
uint32_t currentLevel = player->getLevel();
uint32_t manaCost = (currentLevel * manaXLevel);
return manaCost;
}
spells.h
Under
C++:
uint32_t getMana() const {
return mana;
}
void setMana(uint32_t m) {
mana = m;
}
C++:
uint32_t getManaXLevel() const {
return manaXLevel;
}
void setManaXLevel(uint32_t m) {
manaXLevel = m;
}
Under
C++:
uint32_t mana = 0;
C++:
uint32_t manaXLevel = 0;
luascript.cpp
Under
C++:
setField(L, "mana", spell.getMana());
C++:
setField(L, "manaxlevel", spell.getManaXLevel());
Under
C++:
registerMethod("Spell", "mana", LuaScriptInterface::luaSpellMana);
C++:
registerMethod("Spell", "manaXLevel", LuaScriptInterface::luaSpellManaXLevel);
Under
C++:
registerMethod("Weapon", "mana", LuaScriptInterface::luaWeaponMana);
C++:
registerMethod("Weapon", "manaXLevel", LuaScriptInterface::luaWeaponManaXLevel);
Under
C++:
int LuaScriptInterface::luaSpellMana(lua_State* L)
{
// spell:mana(mana)
Spell* spell = getUserdata<Spell>(L, 1);
if (spell) {
if (lua_gettop(L) == 1) {
lua_pushnumber(L, spell->getMana());
} else {
spell->setMana(getNumber<uint32_t>(L, 2));
pushBoolean(L, true);
}
} else {
lua_pushnil(L);
}
return 1;
}
C++:
int LuaScriptInterface::luaSpellManaXLevel(lua_State* L)
{
// spell:manaXLevel(multiplier)
Spell* spell = getUserdata<Spell>(L, 1);
if (spell) {
if (lua_gettop(L) == 1) {
lua_pushnumber(L, spell->getManaXLevel());
} else {
spell->setManaXLevel(getNumber<uint32_t>(L, 2));
pushBoolean(L, true);
}
} else {
lua_pushnil(L);
}
return 1;
}
Under
C++:
int LuaScriptInterface::luaWeaponMana(lua_State* L)
{
// weapon:mana(mana)
Weapon* weapon = getUserdata<Weapon>(L, 1);
if (weapon) {
weapon->setMana(getNumber<uint32_t>(L, 2));
pushBoolean(L, true);
} else {
lua_pushnil(L);
}
return 1;
}
C++:
int LuaScriptInterface::luaWeaponManaXLevel(lua_State* L)
{
// weapon:manaXLevel(multiplier)
Weapon* weapon = getUserdata<Weapon>(L, 1);
if (weapon) {
weapon->setManaXLevel(getNumber<uint32_t>(L, 2));
pushBoolean(L, true);
} else {
lua_pushnil(L);
}
return 1;
}
luascript.h
Under
C++:
static int luaSpellMana(lua_State* L);
C++:
static int luaSpellManaXLevel(lua_State* L);
Under
C++:
static int luaWeaponMana(lua_State* L);
C++:
static int luaWeaponManaXLevel(lua_State* L);
weapons.cpp
Under
C++:
if ((attr = node.attribute("mana"))) {
mana = pugi::cast<uint32_t>(attr.value());
}
C++:
if ((attr = node.attribute("manaxlevel"))) {
manaXLevel = pugi::cast<uint32_t>(attr.value());
}
Switch
C++:
uint32_t Weapon::getManaCost(const Player* player) const
{
if (mana != 0) {
return mana;
}
if (manaPercent == 0) {
return 0;
}
return (player->getMaxMana() * manaPercent) / 100;
}
C++:
uint32_t Weapon::getManaCost(const Player* player) const
{
if (mana != 0) {
return mana;
}
if (manaXLevel != 0) {
uint32_t currentLevel = player->getLevel();
uint32_t manaCost = (currentLevel * manaXLevel);
return manaCost;
}
if (manaPercent != 0) {
uint32_t maxMana = player->getMaxMana();
uint32_t manaCost = (maxMana * manaPercent) / 100;
return manaCost;
}
return 0;
}
weapons.h
Under
C++:
uint32_t getMana() const {
return mana;
}
void setMana(uint32_t m) {
mana = m;
}
C++:
uint32_t getManaXLevel() const {
return manaXLevel;
}
void setManaXLevel(uint32_t m) {
manaXLevel = m;
}
Under
C++:
uint32_t mana = 0;
C++:
uint32_t manaXLevel = 0;
And that should be all, if you have any questions feel free to ask them here. If you have any improvements or find an issue feel free to share.
Hope you enjoy it!
EDIT: I took the liberty of fixing spellbook.lua so they're compatible with this edit (Keep in mind that I've changed it to show Magic Level instead of Level):
Lua:
local spellbook = Action()
function spellbook.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local text = {}
local spells = {}
for _, spell in ipairs(player:getInstantSpells()) do
if spell.mlevel ~= 0 then
if spell.manaxlevel > 0 then
spell.mana = spell.manaxlevel * player:getLevel()
elseif spell.manapercent > 0 then
spell.mana = spell.manapercent .. "%"
end
spells[#spells + 1] = spell
end
end
table.sort(spells, function(a, b) return a.mlevel < b.mlevel end)
local prevmlevel = -1
for i, spell in ipairs(spells) do
if prevmlevel ~= spell.mlevel then
if i == 1 then
text[#text == nil and 1 or #text+1] = "Spells for Magic Level "
else
text[#text+1] = "\nSpells for Magic Level "
end
text[#text+1] = spell.mlevel .. "\n"
prevmlevel = spell.mlevel
end
text[#text+1] = spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
end
player:showTextDialog(item:getId(), table.concat(text))
return true
end
spellbook:id(2175, 6120, 8900, 8901, 8902, 8903, 8904, 8918, 23771)
spellbook:register()
Last edited: