Jump to content

Theoretical calculation of raw damage


Go to solution Solved by AbeilleTurbulante,

Recommended Posts

Hello,

I am trying to calculate the damage in the simplest possible case: no bonuses and no weapon involved. However, I'm encountering discrepancies between the theoretical calculation and the actual in-game values, and I can't seem to identify where I might be making a mistake.

Here's an example scenario:

  • Attacker:
    • Race: Warrior
    • Level: 10
    • Strength: 26
    • Dexterity: 10
  • Victim:
    • Monster: Wild dog (vnum: 171)
    • Level: 1
    • Dexterity: 6
    • Vitality: 5
    • Defense: 4

Results from this test:

  • Theoretical damage: 46
  • Official server: 45
  • Private server: 45

I used the source code in this manner to calculate the theoretical damage (I removed unnecessary parts):

void CHARACTER::ComputeBattlePoints()
{
    if (IsPolymorphed())
    {
        ...
    }
    else if (IsPC())
    {
        SetPoint(POINT_ATT_GRADE, 0);
        ...

        int iAtk = GetLevel() * 2; // iAtk = 20 
        int iStatAtk = 0;

        switch (GetJob())
        {
            case JOB_WARRIOR:
                iStatAtk = (2 * GetPoint(POINT_ST)); // iStatAtk = 52
                break;
            ...
        }

        ...

        iAtk += iStatAtk; // iAtk = 72

        ...

        iAtk += GetPoint(POINT_ATT_GRADE_BONUS); // iAtk = 72

        PointChange(POINT_ATT_GRADE, iAtk);

        ...

    }
    else
    {
        ...
    }
}

float CalcAttackRating(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnoreTargetRating)
{
    int iARSrc;
    int iERSrc;

    if (LC_IsYMIR())
    {
        ...
    }
    else 
    {
        int attacker_dx = pkAttacker->GetPolymorphPoint(POINT_DX); // attacker_dx = 10
        int attacker_lv = pkAttacker->GetLevel(); // attacker_lv = 10

        int victim_dx = pkVictim->GetPolymorphPoint(POINT_DX); // victim_dx = 6
        int victim_lv = pkAttacker->GetLevel(); // victim_lv = 1

        iARSrc = MIN(90, (attacker_dx * 4    + attacker_lv * 2) / 6); // iARSrc = 10
        iERSrc = MIN(90, (victim_dx      * 4    + victim_lv   * 2) / 6); // iERSrc = 4
    }

    float fAR = ((float) iARSrc + 210.0f) / 300.0f; // fAR = 0.733333

    if (bIgnoreTargetRating)
        return fAR;

    float fER = ((float) (iERSrc * 2 + 5) / (iERSrc + 95)) * 3.0f / 10.0f; // fER = 0.0393939

    return fAR - fER;
}

int CalcBattleDamage(int iDam, int iAttackerLev, int iVictimLev)
{
    if (iDam < 3)
        iDam = number(1, 5); 

    return iDam;
}

int CalcMeleeDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnoreDefense, bool bIgnoreTargetRating)
{
    LPITEM pWeapon = pkAttacker->GetWear(WEAR_WEAPON);
    bool bPolymorphed = pkAttacker->IsPolymorphed();

    if (pWeapon && !(bPolymorphed && !pkAttacker->IsPolyMaintainStat()))
    {
        ...
    }

    int iDam = 0;
    float fAR = CalcAttackRating(pkAttacker, pkVictim, bIgnoreTargetRating); // fAR = 0.693939
    int iDamMin = 0, iDamMax = 0;


    if (bPolymorphed && !pkAttacker->IsPolyMaintainStat())
    {
        ...
    }
    else if (pWeapon)
    {
        ...
    }
    else if (pkAttacker->IsNPC())
    {
        ...
    }

    iDam = number(iDamMin, iDamMax) * 2; // iDam = 0

    int iAtk = 0;

    iAtk = pkAttacker->GetPoint(POINT_ATT_GRADE) + iDam - (pkAttacker->GetLevel() * 2); // iAtk = 72 + 0 - 2 * 10 = 52
    iAtk = (int) (iAtk * fAR); // iAtk = 36
    iAtk += pkAttacker->GetLevel() * 2; // iAtk = 56

    if (pWeapon)
    {
        ...
    }

    iAtk += pkAttacker->GetPoint(POINT_PARTY_ATTACKER_BONUS); // iAtk = 56
    iAtk = (int) (iAtk * (100 + (pkAttacker->GetPoint(POINT_ATT_BONUS) + pkAttacker->GetPoint(POINT_MELEE_MAGIC_ATT_BONUS_PER))) / 100); // iAtk = 56

    iAtk = CalcAttBonus(pkAttacker, pkVictim, iAtk); // iAtk = 56 (no bonus)

    int iDef = 0;

    if (!bIgnoreDefense)
    {    
        // int iDef = GetLevel() + GetPoint(POINT_HT) + GetMobTable().wDef;
        iDef = (pkVictim->GetPoint(POINT_DEF_GRADE) * (100 + pkVictim->GetPoint(POINT_DEF_BONUS)) / 100); // iDef = 10

        if (!pkAttacker->IsPC())
            ...
    }

    if (pkAttacker->IsNPC())
        ...

    iDam = MAX(0, iAtk - iDef); // iDam = 46


    return CalcBattleDamage(iDam, pkAttacker->GetLevel(), pkVictim->GetLevel()); // = 46
}

 

If anyone could help me pinpoint the issue or offer any suggestions, I would greatly appreciate it. Thank you in advance!

Link to comment
https://metin2.dev/topic/31125-theoretical-calculation-of-raw-damage/
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.