Sphereserver / Source-X

Ultima Online server emulator
Apache License 2.0
53 stars 40 forks source link

[Question] Weapon_GetAttack #1217

Closed canerksk closed 3 months ago

canerksk commented 4 months ago
int CItem::Weapon_GetAttack(bool fGetRange) const
{
    ADDTOCALLSTACK("CItem::Weapon_GetAttack");
    // Get the base attack for the weapon plus magic modifiers.
    // Subtract for low hitpoints.
    if ( ! IsTypeWeapon())  // anything can act as a weapon.
        return 1;

    int iVal = m_attackBase + m_ModAr;
    if ( fGetRange )
        iVal += m_attackRange;

    if ( IsSetOF(OF_ScaleDamageByDurability) && m_itArmor.m_wHitsMax > 0 && m_itArmor.m_dwHitsCur < m_itArmor.m_wHitsMax )
    {
        int iRepairPercent = 50 + ((50 * m_itArmor.m_dwHitsCur) / m_itArmor.m_wHitsMax);
        iVal = (int)IMulDivLL( iVal, iRepairPercent, 100 );
    }
    if ( IsAttr(ATTR_MAGIC) && ! IsType(IT_WAND))
        iVal += g_Cfg.GetSpellEffect( SPELL_Enchant, m_itArmor.m_spelllevel );
    if ( iVal < 0 )
        iVal = 0;
    return iVal;
}

While calculating the damage of the weapon in this field, ATTR_MAGIC

iVal += g_Cfg.GetSpellEffect( SPELL_Enchant, m_itArmor.m_spelllevel );

surplus value has been calculated. Here SPELL_Enchant, m_itArmor.m_spelllevel The value of m_itArmor.m_spelllevel is taken as basis. Doesn't this value take the Morey value of the armor? Shouldn't this be m_itWeapon.m_spelllevel?

        struct
        {
            word m_dwHitsCur;       // more1l=eqiv to quality of the item (armor/weapon).
            word m_wHitsMax;        // more1h=can only be repaired up to this level.
            int32 m_spellcharges;   // more2=for a wand etc.
            word m_spell;           // morex=SPELL_TYPE = The magic spell cast on this. (daemons breath)(boots of strength) etc
            word m_spelllevel;      // morey=level of the spell. (0-1000) <-------- Isn't this how the magic weapon's damage works?
            byte m_poison_skill;    // morez=0-100 = Is the weapon poisoned ? 
            byte m_nonused;         // morem
        } m_itWeapon;

in summary;

if ( IsAttr(ATTR_MAGIC) && ! IsType(IT_WAND))
        iVal += g_Cfg.GetSpellEffect( SPELL_Enchant, m_itArmor.m_spelllevel );

Shouldn't this section change like this?

if ( IsAttr(ATTR_MAGIC) && ! IsType(IT_WAND))
        iVal += g_Cfg.GetSpellEffect( SPELL_Enchant, m_itWeapon.m_spelllevel );

m_itArmor.m_spelllevel -> m_itWeapon.m_spelllevel

xwerswoodx commented 3 months ago

It's silly but it was changed on Sphere 0.52 version, and it never touched after that day but it's not a big deal, as Weapons also work fine with m_itArmor. Because most of the global checks done with m_itArmor for weapons and armors. Like repairable armor and weapons check with m_itArmor or any variable like HITPOINTS, MAXHITS return the m_itArmor value for weapons and armors, so typing m_itWeapon or m_itArmor doesn't not make any difference in that case.

xwerswoodx commented 3 months ago

As It's not a bug, I am closing it, but if you think that causes any issue, you can re-open (or ask someone to re-open from discord) or just create new issue about it and I can take a look for it.