Ok, I think I found the equip/unequip item handlers. And it seems to be bugged in Daggerfall classic.
Long story short, the spell cost (calculated using my previous post function) for
the last "on held" effect is reduced from item's health when equipping. The cost is calculated using current player stats.
Longer version : a given item can have up to 10 enchantment, most of the time (on stroke, or when time is passing) each enchantment will reduce item's health (for example 10pt per stroke per enchantment with "cast strikes"). Except for equipping item callback (zipped code below):
Code: Select all
SC_OBJECT_DATA *__fastcall SC_inven::96CCF_EquipMagicItem(SC_OBJECT *pItemObj, char inventorySlot)
{
unsigned __int16 effectType; // ax
signed int cost; // eax
signed int effectIdx; // [esp+Ch] [ebp-24h]
SC_OBJECT_DATA *pItem; // [esp+14h] [ebp-1Ch]
SC_OBJECT *pNewSpellObj; // [esp+18h] [ebp-18h]
ELE_SpellsSTDEntry *pLastHeldSpellEffect; // [esp+1Ch] [ebp-14h]
effectIdx = 0;
pItem = &pItemObj.u;
pLastHeldSpellEffect = 0;
while ( effectIdx < 10 )
{
if ( pItem->type2_item.magics[effectIdx].effectType == -1 )
break;
effectType = pItem->type2_item.magics[effectIdx].effectType;
if ( effectType == CAST_HELD )
{
for (int i = 0; gFile_Spells_std[i].SpellID != pItem->type2_item.magics[effectIdx].spellID; ++i )
;
pNewSpellObj = SC_Object::InsertNewObject(gObjRoot, 0, sizeof(ELE_SpellsSTDEntry));
pNewSpellObj->h.type = SC_OBJECT_TYPE_SPELL;
pNewSpellObj->h.field_15 = 3;
SC_jmem::memcpy(&pNewSpellObj->u, &gFile_Spells_std[i], sizeof(ELE_SpellsSTDEntry), "inven.c" , 2092, 4);
pLastHeldSpellEffect = &pNewSpellObj->u;
pNewSpellObj->u.type9_spell.Icon = inventorySlot - 56;
for (int j = 0; j < 3; ++j )
{
if ( pLastHeldSpellEffect->types[j].major != 255 )
{
pLastHeldSpellEffect->duration[j].base = -1;
pLastHeldSpellEffect->duration[j].x = 0;
pLastHeldSpellEffect->duration[j].div = 0;
}
}
ELE_SPELL::ApplyEffect_qqq(pNewSpellObj, &pNewSpellObj->u);
}
}
//...
effectIdx++;
}
if ( !effectIdx )
return 0;
if ( !pLastHeldSpellEffect )
return effectIdx;
cost = SC_spells::_3A0C0_GetCost_qqq(pLastHeldSpellEffect, gPlayerData);
return SC_OBJECT_TYPE2::ReduceEnchantment(pItemObj, cost);
}
This code is iterating over the 10 possible effects, and is applying every "on held" effect . But cost is calculated using pLastHeldSpellEffect which is overwritten for each effects... So, for an item with multiple "on held" effect, only last one is used for cost calculation. I don't know if this is the intended behaviour, it may be more coherent to reduce item health by each effect cost.
Interkarma: it should be noted that this function use current player stats for spell cost, item maker uses a dummy player with every skills at 50 for calculating cost (*10).
Once more, it's my current understanding of Daggerfall, it should be validated by in-game experimenting