Welcome to the Builder Academy

Question Help me understand why melee crit damage is not being calculated

More
20 Feb 2023 03:16 - 20 Feb 2023 03:18 #10248 by Nero
For some reason my melee_crit_damage is not factoring into the fight.
In the provided screenshot my character is a level 40 berserker with melee crit damage of 20%
yet when I crit I am not showing a 20% increase in damage when I should be:
Code:
int adjust_damage(struct char_data *ch, struct char_data *victim, int dam, int attacktype, bool critical_hit, int crit_multiplier) {   int perk_mod = 0, activator = 0, wbranch;   //DAMAGE INCREASORS GO HERE   if ((HAPPY_DMG >= .0001) && ((!IS_NPC(ch)) || (AFF_FLAGGED(ch, AFF_CHARM))))     dam += ((int)((float)((dam * HAPPY_DMG)/100)));   if (critical_hit) {     if (!IS_NPC(ch)) {       if (WIELDED_WEAPON(ch) && GET_OBJ_TYPE(WIELDED_WEAPON(ch)) == ITEM_WEAPON) {         wbranch = (GET_OBJ_VAL(WIELDED_WEAPON(ch), 0));         for (int i = 0; i < NUM_PERK_SLOTS; i++) {           if (GET_PERK_SLOTS(ch, i) == 85) {             if (wbranch == SKILL_WP_SLASH)               perk_mod += 20;           }           if (GET_PERK_SLOTS(ch, i) == 86) {             if (wbranch == SKILL_WP_BLUDGEON)               perk_mod += 20;           }           if (GET_PERK_SLOTS(ch, i) == 87) {             if (wbranch == SKILL_WP_PIERCE)               perk_mod += 20;           }           if (GET_PERK_SLOTS(ch, i) == 114) {             if (wbranch == SKILL_WP_SPECIAL)               perk_mod += 20;           }           if (GET_PERK_SLOTS(ch, i) == 128) {             if (wbranch == SKILL_WP_SLASH)               perk_mod += 20;           }         }       }     }     // Print statement to see value of get_melee_crit_dmg_bonus     int melee_crit_dmg_bonus = get_melee_crit_dmg_bonus(ch);     send_to_char(ch, "Melee Crit Damage Bonus: %d\n", melee_crit_dmg_bonus);     if ((con_app[GET_TOT_CON(ch)].crit_resist) > 0) {       dam += ((dam * ((melee_crit_dmg_bonus + perk_mod) / 100)) * ((100 - ((float)(con_app[GET_TOT_CON(ch)].crit_resist))) / ((float)100)));       send_to_char(ch, "Total Dam: %d\n", dam);     } else {       dam += (dam * ((melee_crit_dmg_bonus + perk_mod) / 100));       send_to_char(ch, "Total Dam: %d\n", dam);     }   }


 
Attachments:
Last edit: 20 Feb 2023 03:18 by Nero.

Please Log in or Create an account to join the conversation.

More
20 Feb 2023 11:19 #10249 by thomas
This does not do what you think it does:
Code:
dam += ((int)((float)((dam * HAPPY_DMG)/100)));
(you are doing "int * float / int" which is an int and then cast the result to float and then back to int.)
Try this:
Code:
dam += (int)((float)dam * HAPPY_DMG)/100.0);
(this casts the first int to float so we get float * float / float which is a float and then cast it to int)
The following user(s) said Thank You: Nero

Please Log in or Create an account to join the conversation.

More
22 Feb 2023 05:54 - 22 Feb 2023 05:55 #10250 by Nero
Yes thank you sorry for just now responding it has been a busy week
I figured it was how it was written that was the problem. I fixed that snippet but the main part was the bottom.
Fixed:
Code:
    // Calculate the melee crit damage bonus     int melee_crit_dmg_bonus = get_melee_crit_dmg_bonus(ch);     if ((con_app[GET_TOT_CON(ch)].crit_resist) > 0) {      dam += (dam *(melee_crit_dmg_bonus / 100.0 + perk_mod / 100.0)) * ((100.0 - ((float)(con_app[GET_TOT_CON(ch)].crit_resist))) / ((float)100.0));     } else {      dam += (dam *(melee_crit_dmg_bonus / 100.0 + perk_mod / 100.0));     }   }   /*
Last edit: 22 Feb 2023 05:55 by Nero.

Please Log in or Create an account to join the conversation.

Time to create page: 0.192 seconds