MCPcopy Create free account
hub / github.com/TurningWheel/Barony / displayAttackPower

Function displayAttackPower

src/interface/updatecharactersheet.cpp:28–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include "../prng.hpp"
27
28Sint32 displayAttackPower(const int player, AttackHoverText_t& output)
29{
30 Sint32 attack = 0;
31 Entity* entity = nullptr;
32 if ( players[player] )
33 {
34 entity = players[player]->entity;
35 if ( stats[player] )
36 {
37 bool shapeshiftUseMeleeAttack = false;
38 if ( entity && entity->effectShapeshift != NOTHING )
39 {
40 shapeshiftUseMeleeAttack = true;
41 if ( entity && entity->effectShapeshift == CREATURE_IMP
42 && stats[player]->weapon && itemCategory(stats[player]->weapon) == MAGICSTAFF )
43 {
44 shapeshiftUseMeleeAttack = false;
45 }
46 }
47
48 if ( !stats[player]->weapon || shapeshiftUseMeleeAttack )
49 {
50 // fists
51 int weaponAttack = 0;
52 attack += Entity::getAttack(players[player]->entity, stats[player], true, -1, &weaponAttack);
53 output.hoverType = AttackHoverText_t::ATK_HOVER_TYPE_UNARMED; // melee
54 output.totalAttack = attack;
55 output.proficiencyBonus = (stats[player]->getModifiedProficiency(PRO_UNARMED) / 20); // bonus from proficiency
56 Sint32 attr = statGetSTR(stats[player], entity); // bonus from main attribute
57 Sint32 prevStat = stats[player]->STR;
58 stats[player]->STR += -attr;
59 output.mainAttributeBonus = output.totalAttack - Entity::getAttack(players[player]->entity, stats[player], true);
60 stats[player]->STR = prevStat;
61 output.equipmentAndEffectBonus = weaponAttack - BASE_PLAYER_UNARMED_DAMAGE - output.proficiencyBonus; // bonus from equipment
62
63 {
64 real_t variance = 20;
65 real_t baseSkillModifier = 50.0; // 40-60 base
66 Entity::setMeleeDamageSkillModifiers(players[player]->entity, stats[player], PRO_UNARMED, baseSkillModifier, variance, nullptr);
67 real_t skillModifierMin = baseSkillModifier - (variance / 2) + (stats[player]->getModifiedProficiency(PRO_UNARMED) / 2.0);
68 real_t skillModifierMax = skillModifierMin + variance;
69 skillModifierMin /= 100.0;
70 skillModifierMin = std::min(skillModifierMin, 1.0);
71 skillModifierMax /= 100.0;
72 skillModifierMax = std::min(skillModifierMax, 1.0);
73 output.proficiencyVariance = variance;
74 output.attackMaxRange = attack - static_cast<int>((1.0 - skillModifierMax) * attack);
75 output.attackMinRange = attack - static_cast<int>((1.0 - skillModifierMin) * attack);
76 output.proficiency = PRO_UNARMED;
77 output.totalAttack = output.attackMaxRange - ((output.attackMaxRange - output.attackMinRange) / 2.0);
78 }
79 }
80 else
81 {
82 int weaponskill = getWeaponSkill(stats[player]->weapon);
83 if ( weaponskill == PRO_RANGED )
84 {
85 if ( isRangedWeapon(*stats[player]->weapon) )

Callers

nothing calls this directly

Calls 15

statGetSTRFunction · 0.85
getWeaponSkillFunction · 0.85
isRangedWeaponFunction · 0.85
statGetDEXFunction · 0.85
itemTypeIsThrownBallFunction · 0.85
weaponGetAttackMethod · 0.80
getRangedAttackMethod · 0.80
getThrownAttackMethod · 0.80
getProficiencyMethod · 0.80

Tested by

no test coverage detected