Skip to content

Commit

Permalink
Remove increment rune name to item name (#220)
Browse files Browse the repository at this point in the history
Item name was being replaced by rune name in "register" function
Added the condition to only replace if the item name is empty, so that some system that checks the name of the pre-established item cannot be bugged
  • Loading branch information
dudantas authored Apr 17, 2022
1 parent d0003ec commit 08087b0
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/lua/functions/creatures/combat/spell_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,37 @@ int SpellFunctions::luaSpellRegister(lua_State* L) {
// spell:register()
Spell* spell = getUserdata<Spell>(L, 1);

if (spell) {
if (spell->spellType == SPELL_INSTANT) {
InstantSpell* instant = dynamic_cast<InstantSpell*>(getUserdata<Spell>(L, 1));
if (!instant->isScripted()) {
pushBoolean(L, false);
return 1;
}
pushBoolean(L, g_spells->registerInstantLuaEvent(instant));
} else if (spell->spellType == SPELL_RUNE) {
RuneSpell* rune = dynamic_cast<RuneSpell*>(getUserdata<Spell>(L, 1));
if (rune->getMagicLevel() != 0 || rune->getLevel() != 0) {
//Change information in the ItemType to get accurate description
ItemType& iType = Item::items.getItemType(rune->getRuneItemId());
if (!spell) {
reportErrorFunc(getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

if (spell->spellType == SPELL_INSTANT) {
InstantSpell* instant = dynamic_cast<InstantSpell*>(getUserdata<Spell>(L, 1));
if (!instant->isScripted()) {
pushBoolean(L, false);
return 1;
}
pushBoolean(L, g_spells->registerInstantLuaEvent(instant));
} else if (spell->spellType == SPELL_RUNE) {
RuneSpell* rune = dynamic_cast<RuneSpell*>(getUserdata<Spell>(L, 1));
if (rune->getMagicLevel() != 0 || rune->getLevel() != 0) {
// Change information in the ItemType to get accurate description
ItemType& iType = Item::items.getItemType(rune->getRuneItemId());
// If the item is not registered in items.xml then we will register it by rune name
if (iType.name.empty()) {
iType.name = rune->getName();
iType.runeMagLevel = rune->getMagicLevel();
iType.runeLevel = rune->getLevel();
iType.charges = rune->getCharges();
}
if (!rune->isScripted()) {
pushBoolean(L, false);
return 1;
}
pushBoolean(L, g_spells->registerRuneLuaEvent(rune));
iType.runeMagLevel = rune->getMagicLevel();
iType.runeLevel = rune->getLevel();
iType.charges = rune->getCharges();
}
} else {
lua_pushnil(L);
if (!rune->isScripted()) {
pushBoolean(L, false);
return 1;
}
pushBoolean(L, g_spells->registerRuneLuaEvent(rune));
}
return 1;
}
Expand Down

0 comments on commit 08087b0

Please sign in to comment.