Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: convergence wrong price calculation #2918

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,11 @@
if (icons.size() < 9) {
icons.insert(PlayerIcon::Pigeon);
}
client->sendRestingStatus(1);

Check warning on line 492 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

icons.erase(PlayerIcon::Swords);
} else {
client->sendRestingStatus(0);

Check warning on line 496 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

return icons;
Expand Down Expand Up @@ -571,7 +571,7 @@
for (auto [key, item] : getAllSlotItems()) {
// Iterate through all imbuement slots on the item

for (uint8_t slotid = 0; slotid < item->getImbuementSlot(); slotid++) {

Check warning on line 574 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
ImbuementInfo imbuementInfo;
// Get the imbuement information for the current slot
if (!item->getImbuementInfo(slotid, &imbuementInfo)) {
Expand Down Expand Up @@ -619,7 +619,7 @@

phmap::flat_hash_map<uint8_t, std::shared_ptr<Item>> Player::getAllSlotItems() const {
phmap::flat_hash_map<uint8_t, std::shared_ptr<Item>> itemMap;
for (uint8_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) {

Check warning on line 622 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
std::shared_ptr<Item> item = inventory[i];
if (!item) {
continue;
Expand All @@ -643,15 +643,15 @@

uint16_t Player::getLoyaltySkill(skills_t skill) const {
uint16_t level = getBaseSkill(skill);
absl::uint128 currReqTries = vocation->getReqSkillTries(skill, level);

Check warning on line 646 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
absl::uint128 nextReqTries = vocation->getReqSkillTries(skill, level + 1);

Check warning on line 647 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (currReqTries >= nextReqTries) {
// player has reached max skill
return skills[skill].level;
}

absl::uint128 tries = skills[skill].tries;
absl::uint128 totalTries = vocation->getTotalSkillTries(skill, skills[skill].level) + tries;

Check warning on line 654 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
absl::uint128 loyaltyTries = (totalTries * getLoyaltyBonus()) / 100;
while ((tries + loyaltyTries) >= nextReqTries) {
loyaltyTries -= nextReqTries - tries;
Expand All @@ -659,7 +659,7 @@
tries = 0;

currReqTries = nextReqTries;
nextReqTries = vocation->getReqSkillTries(skill, level + 1);

Check warning on line 662 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (currReqTries >= nextReqTries) {
loyaltyTries = 0;
break;
Expand All @@ -669,8 +669,8 @@
}

void Player::addSkillAdvance(skills_t skill, uint64_t count) {
uint64_t currReqTries = vocation->getReqSkillTries(skill, skills[skill].level);

Check warning on line 672 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint64_t nextReqTries = vocation->getReqSkillTries(skill, skills[skill].level + 1);

Check warning on line 673 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (currReqTries >= nextReqTries) {
// player has reached max skill
return;
Expand All @@ -690,7 +690,7 @@
skills[skill].percent = 0;

std::ostringstream ss;
ss << "You advanced to " << getSkillName(skill) << " level " << skills[skill].level << '.';

Check warning on line 693 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
if (skill == SKILL_LEVEL) {
sendTakeScreenshot(SCREENSHOT_TYPE_LEVELUP);
Expand All @@ -702,7 +702,7 @@

sendUpdateSkills = true;
currReqTries = nextReqTries;
nextReqTries = vocation->getReqSkillTries(skill, skills[skill].level + 1);

Check warning on line 705 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (currReqTries >= nextReqTries) {
count = 0;
break;
Expand Down Expand Up @@ -852,7 +852,7 @@
return it.first;
}
}
return -1;

Check warning on line 855 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

uint16_t Player::getContainerIndex(uint8_t cid) const {
Expand Down Expand Up @@ -1393,7 +1393,7 @@
if (client) {
client->logout(true, true);
} else {
g_game().removeCreature(static_self_cast<Player>(), true);

Check warning on line 1396 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
}
}
}
Expand Down Expand Up @@ -1455,7 +1455,7 @@
return;
}

const auto items = imbuement->getItems();

Check warning on line 1458 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

unnecessary-copy-initialization

the const qualified variable 'items' is copy-constructed from a const reference; consider making it a const reference
for (auto &[key, value] : items) {
const ItemType &itemType = Item::items[key];
if (static_self_cast<Player>()->getItemTypeCount(key) + this->getStashItemCount(itemType.id) < value) {
Expand Down Expand Up @@ -1487,7 +1487,7 @@

uint32_t inventoryItemCount = getItemTypeCount(key);
if (inventoryItemCount >= value) {
removeItemOfType(key, value, -1, true);

Check warning on line 1490 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
continue;
}

Expand Down Expand Up @@ -1748,9 +1748,9 @@
g_game().checkPlayersRecord();
IOLoginData::updateOnlineStatus(guid, true);
if (getLevel() < g_configManager().getNumber(ADVENTURERSBLESSING_LEVEL, __FUNCTION__) && getVocationId() > VOCATION_NONE) {
for (uint8_t i = 2; i <= 6; i++) {

Check warning on line 1751 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (!hasBlessing(i)) {
addBlessing(i, 1);

Check warning on line 1753 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
}
sendBlessStatus();
Expand Down Expand Up @@ -2343,7 +2343,7 @@

manaSpent += amount;

uint8_t oldPercent = magLevelPercent;

Check warning on line 2346 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (nextReqMana > currReqMana) {
magLevelPercent = Player::getPercentLevel(manaSpent, nextReqMana);
} else {
Expand All @@ -2366,7 +2366,7 @@
uint64_t rawExp = exp;
if (currLevelExp >= nextLevelExp) {
// player has reached max level
levelPercent = 0;

Check warning on line 2369 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
sendStats();
return;
}
Expand Down Expand Up @@ -2400,7 +2400,7 @@
if (sendText) {
std::string expString = fmt::format("{} experience point{}.", exp, (exp != 1 ? "s" : ""));
if (isVip()) {
uint8_t expPercent = g_configManager().getNumber(VIP_BONUS_EXP, __FUNCTION__);

Check warning on line 2403 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (expPercent > 0) {
expString = expString + fmt::format(" (VIP bonus {}%)", expPercent > 100 ? 100 : expPercent);
}
Expand Down Expand Up @@ -2473,9 +2473,9 @@
}

if (nextLevelExp > currLevelExp) {
levelPercent = Player::getPercentLevel(experience - currLevelExp, nextLevelExp - currLevelExp);

Check warning on line 2476 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
} else {
levelPercent = 0;

Check warning on line 2478 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
sendStats();
sendExperienceTracker(rawExp, exp);
Expand Down Expand Up @@ -2558,9 +2558,9 @@

uint64_t nextLevelExp = Player::getExpForLevel(level + 1);
if (nextLevelExp > currLevelExp) {
levelPercent = Player::getPercentLevel(experience - currLevelExp, nextLevelExp - currLevelExp);

Check warning on line 2561 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
} else {
levelPercent = 0;

Check warning on line 2563 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
sendStats();
sendExperienceTracker(0, -static_cast<int64_t>(exp));
Expand Down Expand Up @@ -2678,7 +2678,7 @@
}
}

for (uint8_t slotid = 0; slotid < item->getImbuementSlot(); slotid++) {

Check warning on line 2681 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
ImbuementInfo imbuementInfo;
if (!item->getImbuementInfo(slotid, &imbuementInfo)) {
continue;
Expand Down Expand Up @@ -2714,7 +2714,7 @@

g_game().sendSingleSoundEffect(static_self_cast<Player>()->getPosition(), sex == PLAYERSEX_FEMALE ? SoundEffect_t::HUMAN_FEMALE_DEATH : SoundEffect_t::HUMAN_MALE_DEATH, getPlayer());
if (skillLoss) {
uint8_t unfairFightReduction = 100;

Check warning on line 2717 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
int playerDmg = 0;
int othersDmg = 0;
uint32_t sumLevels = 0;
Expand All @@ -2737,7 +2737,7 @@
}
if (pvpDeath && sumLevels > level) {
double reduce = level / static_cast<double>(sumLevels);
unfairFightReduction = std::max<uint8_t>(20, std::floor((reduce * 100) + 0.5));

Check warning on line 2740 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

Check warning on line 2740 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

// Magic level loss
Expand Down Expand Up @@ -2842,9 +2842,9 @@
uint64_t currLevelExp = Player::getExpForLevel(level);
uint64_t nextLevelExp = Player::getExpForLevel(level + 1);
if (nextLevelExp > currLevelExp) {
levelPercent = Player::getPercentLevel(experience - currLevelExp, nextLevelExp - currLevelExp);

Check warning on line 2845 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
} else {
levelPercent = 0;

Check warning on line 2847 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
}

Expand All @@ -2869,12 +2869,12 @@
: blessOutput << "You were blessed with " << bless;

// Make player lose bless
uint8_t maxBlessing = 8;

Check warning on line 2872 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (pvpDeath && hasBlessing(1)) {

Check warning on line 2873 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
removeBlessing(1, 1); // Remove TOF only

Check warning on line 2874 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

Check warning on line 2874 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
} else {
for (int i = 2; i <= maxBlessing; i++) {
removeBlessing(i, 1);

Check warning on line 2877 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

Check warning on line 2877 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
}
}
Expand Down Expand Up @@ -3073,7 +3073,7 @@
if (client) {
client->logout(displayEffect, forced);
} else {
g_game().removeCreature(static_self_cast<Player>());

Check warning on line 3076 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
}
}

Expand All @@ -3093,9 +3093,9 @@
}

for (uint32_t containerId : closeList) {
closeContainer(containerId);

Check warning on line 3096 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (client) {
client->sendCloseContainer(containerId);

Check warning on line 3098 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
}
}
Expand Down Expand Up @@ -3672,7 +3672,7 @@
}

int32_t Player::getThingIndex(std::shared_ptr<Thing> thing) const {
for (uint8_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) {

Check warning on line 3675 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (inventory[i] == thing) {
return i;
}
Expand Down Expand Up @@ -3939,7 +3939,7 @@
}

void Player::calculateDamageReductionFromEquipedItems(std::array<double_t, COMBAT_COUNT> &combatReductionArray) const {
for (uint8_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) {

Check warning on line 3942 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
std::shared_ptr<Item> item = inventory[slot];
if (item) {
calculateDamageReductionFromItem(combatReductionArray, item);
Expand All @@ -3957,7 +3957,7 @@
void Player::updateDamageReductionFromItemImbuement(
std::array<double_t, COMBAT_COUNT> &combatReductionArray, std::shared_ptr<Item> item, uint16_t combatTypeIndex
) const {
for (uint8_t imbueSlotId = 0; imbueSlotId < item->getImbuementSlot(); imbueSlotId++) {

Check warning on line 3960 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
ImbuementInfo imbuementInfo;
if (item->getImbuementInfo(imbueSlotId, &imbuementInfo) && imbuementInfo.imbuement) {
int16_t imbuementAbsorption = imbuementInfo.imbuement->absorbPercent[combatTypeIndex];
Expand Down Expand Up @@ -4908,7 +4908,7 @@
if (soulChange > 0) {
soul += std::min<int32_t>(soulChange * g_configManager().getFloat(RATE_SOUL_REGEN, __FUNCTION__), vocation->getSoulMax() - soul);
} else {
soul = std::max<int32_t>(0, soul + soulChange);

Check warning on line 4911 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

sendStats();
Expand Down Expand Up @@ -5013,7 +5013,7 @@

bool Player::getOutfitAddons(const std::shared_ptr<Outfit> &outfit, uint8_t &addons) const {
if (group->access) {
addons = 3;

Check warning on line 5016 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
return true;
}

Expand All @@ -5034,7 +5034,7 @@
return false;
}

addons = 0;

Check warning on line 5037 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
return true;
}

Expand Down Expand Up @@ -5200,9 +5200,9 @@

unjustifiedKills.emplace_back(attacked->getGUID(), time(nullptr), true);

uint8_t dayKills = 0;

Check warning on line 5203 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint8_t weekKills = 0;

Check warning on line 5204 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint8_t monthKills = 0;

Check warning on line 5205 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

for (const auto &kill : unjustifiedKills) {
const auto diff = time(nullptr) - kill.time;
Expand Down Expand Up @@ -5254,7 +5254,7 @@
int32_t blessingCount = 0;
uint8_t maxBlessing = (operatingSystem == CLIENTOS_NEW_WINDOWS || operatingSystem == CLIENTOS_NEW_MAC) ? 8 : 6;
for (int i = 2; i <= maxBlessing; i++) {
if (hasBlessing(i)) {

Check warning on line 5257 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
blessingCount++;
}
}
Expand Down Expand Up @@ -5386,7 +5386,7 @@
auto skillLevel = getLoyaltySkill(skill);
skillLevel = std::max<int32_t>(0, skillLevel + varSkills[skill]);

if (auto it = maxValuePerSkill.find(skill);

Check warning on line 5389 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
it != maxValuePerSkill.end()) {
skillLevel = std::min<int32_t>(it->second, skillLevel);
}
Expand Down Expand Up @@ -5568,14 +5568,14 @@
}

double_t Player::getReflectPercent(CombatType_t combat, bool useCharges) const {
double_t result = reflectPercent[combatTypeToIndex(combat)];

Check warning on line 5571 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-5

MISRA 5-0-5: There shall be no implicit floating-integral conversions
for (const auto item : getEquippedItems()) {

Check warning on line 5572 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

for-range-copy

the loop variable's type is not a reference type; this creates a copy in each iteration; consider making this a reference
const ItemType &itemType = Item::items[item->getID()];
if (!itemType.abilities) {
continue;
}

double_t reflectPercent = itemType.abilities->reflectPercent[combatTypeToIndex(combat)];

Check warning on line 5578 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-5

MISRA 5-0-5: There shall be no implicit floating-integral conversions
if (reflectPercent != 0) {
result += reflectPercent;
uint16_t charges = item->getCharges();
Expand Down Expand Up @@ -5709,7 +5709,7 @@

void Player::clearPartyInvitations() {
for (const auto &invitingParty : invitePartyList) {
invitingParty->removeInvite(getPlayer(), false);

Check warning on line 5712 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
}
invitePartyList.clear();
}
Expand Down Expand Up @@ -5764,21 +5764,21 @@
auto weekMax = ((isRed ? 2 : 1) * g_configManager().getNumber(WEEK_KILLS_TO_RED, __FUNCTION__));
auto monthMax = ((isRed ? 2 : 1) * g_configManager().getNumber(MONTH_KILLS_TO_RED, __FUNCTION__));

uint8_t dayProgress = std::min(std::round(dayKills / dayMax * 100), 100.0);

Check warning on line 5767 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint8_t weekProgress = std::min(std::round(weekKills / weekMax * 100), 100.0);

Check warning on line 5768 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint8_t monthProgress = std::min(std::round(monthKills / monthMax * 100), 100.0);

Check warning on line 5769 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint8_t skullDuration = 0;

Check warning on line 5770 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (skullTicks != 0) {
skullDuration = std::floor<uint8_t>(skullTicks / (24 * 60 * 60 * 1000));

Check warning on line 5772 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
client->sendUnjustifiedPoints(dayProgress, std::max(dayMax - dayKills, 0.0), weekProgress, std::max(weekMax - weekKills, 0.0), monthProgress, std::max(monthMax - monthKills, 0.0), skullDuration);

Check warning on line 5774 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

Check warning on line 5774 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

Check warning on line 5774 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
}

uint8_t Player::getLastMount() const {
int32_t value = getStorageValue(PSTRG_MOUNTS_CURRENTMOUNT);
if (value > 0) {
return value;

Check warning on line 5781 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
return static_cast<uint8_t>(kv()->get("last-mount")->get<int>());
}
Expand All @@ -5786,9 +5786,9 @@
uint8_t Player::getCurrentMount() const {
int32_t value = getStorageValue(PSTRG_MOUNTS_CURRENTMOUNT);
if (value > 0) {
return value;

Check warning on line 5789 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
return 0;

Check warning on line 5791 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

void Player::setCurrentMount(uint8_t mount) {
Expand Down Expand Up @@ -5902,7 +5902,7 @@
return false;
}

const uint8_t tmpMountId = mountId - 1;

Check warning on line 5905 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
const uint32_t key = PSTRG_MOUNTS_RANGE_START + (tmpMountId / 31);

int32_t value = getStorageValue(key);
Expand All @@ -5921,7 +5921,7 @@
return false;
}

const uint8_t tmpMountId = mountId - 1;

Check warning on line 5924 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
const uint32_t key = PSTRG_MOUNTS_RANGE_START + (tmpMountId / 31);

int32_t value = getStorageValue(key);
Expand Down Expand Up @@ -5954,7 +5954,7 @@
return false;
}

const uint8_t tmpMountId = mount->id - 1;

Check warning on line 5957 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

int32_t value = getStorageValue(PSTRG_MOUNTS_RANGE_START + (tmpMountId / 31));
if (value == -1) {
Expand Down Expand Up @@ -6026,10 +6026,10 @@

uint8_t newPercent;
if (nextReqMana > currReqMana) {
newPercent = Player::getPercentLevel(manaSpent, nextReqMana);

Check warning on line 6029 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
newPercentToNextLevel = static_cast<long double>(manaSpent * 100) / nextReqMana;
} else {
newPercent = 0;

Check warning on line 6032 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
newPercentToNextLevel = 0;
}

Expand All @@ -6040,7 +6040,7 @@

newSkillValue = magLevel;
} else {
uint64_t currReqTries = vocation->getReqSkillTries(skill, skills[skill].level);

Check warning on line 6043 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint64_t nextReqTries = vocation->getReqSkillTries(skill, skills[skill].level + 1);
if (currReqTries >= nextReqTries) {
return false;
Expand All @@ -6064,7 +6064,7 @@

sendUpdate = true;
currReqTries = nextReqTries;
nextReqTries = vocation->getReqSkillTries(skill, skills[skill].level + 1);

Check warning on line 6067 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

if (currReqTries >= nextReqTries) {
tries = 0;
Expand All @@ -6076,7 +6076,7 @@

if (currSkillLevel != skills[skill].level) {
std::ostringstream ss;
ss << "You advanced to " << getSkillName(skill) << " level " << skills[skill].level << '.';

Check warning on line 6079 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
if (skill == SKILL_LEVEL) {
sendTakeScreenshot(SCREENSHOT_TYPE_LEVELUP);
Expand All @@ -6087,7 +6087,7 @@

uint8_t newPercent;
if (nextReqTries > currReqTries) {
newPercent = Player::getPercentLevel(skills[skill].tries, nextReqTries);

Check warning on line 6090 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
newPercentToNextLevel = static_cast<long double>(skills[skill].tries * 100) / nextReqTries;
} else {
newPercent = 0;
Expand All @@ -6109,7 +6109,7 @@

std::string message = fmt::format(
"Your {} skill changed from level {} (with {:.2f}% progress towards level {}) to level {} (with {:.2f}% progress towards level {})",
ucwords(getSkillName(skill)),

Check warning on line 6112 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
oldSkillValue,
oldPercentToNextLevel,
oldSkillValue + 1,
Expand Down Expand Up @@ -6170,7 +6170,7 @@

void Player::sendClosePrivate(uint16_t channelId) {
if (channelId == CHANNEL_GUILD || channelId == CHANNEL_PARTY) {
g_chat().removeUserFromChannel(getPlayer(), channelId);

Check warning on line 6173 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
}

if (client) {
Expand Down Expand Up @@ -6335,7 +6335,7 @@
guildRank = nullptr;

if (newGuild) {
const auto rank = newGuild->getRankByLevel(1);

Check warning on line 6338 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (!rank) {
return;
}
Expand Down Expand Up @@ -6840,10 +6840,10 @@

if (itemMap_it == itemMap.end()) {
std::map<uint8_t, uint32_t> itemTierMap;
itemTierMap[0] = itemCount;

Check warning on line 6843 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
itemMap[itemId] = itemTierMap;
count++;
} else if (auto itemTier_it = itemMap[itemId].find(0); itemTier_it == itemMap[itemId].end()) {

Check warning on line 6846 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
itemMap[itemId][0] = itemCount;
count++;
} else {
Expand All @@ -6851,7 +6851,7 @@
}
}

setDepotSearchIsOpen(1, 0);

Check warning on line 6854 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
sendDepotItems(itemMap, count);
}

Expand Down Expand Up @@ -6968,7 +6968,7 @@
return;
}

g_actions().useItem(static_self_cast<Player>(), pos, 0, container, false);

Check warning on line 6971 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

std::shared_ptr<Item> Player::getItemFromDepotSearch(uint16_t itemId, const Position &pos) {
Expand Down Expand Up @@ -7202,7 +7202,7 @@
auto configKey = convergence ? FORGE_CONVERGENCE_FUSION_DUST_COST : FORGE_FUSION_DUST_COST;
auto dustCost = static_cast<uint64_t>(g_configManager().getNumber(configKey, __FUNCTION__));
if (convergence) {
firstForgedItem->setTier(tier + 1);

Check warning on line 7205 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
history.dustCost = dustCost;
setForgeDusts(getForgeDusts() - dustCost);

Expand All @@ -7213,7 +7213,7 @@
}

for (const auto &[mapTier, mapPrice] : itemClassification->tiers) {
if (mapTier == firstForgingItem->getTier()) {
if (mapTier == firstForgingItem->getTier() + 1) {
cost = mapPrice.convergenceFusionPrice;
break;
}
Expand Down Expand Up @@ -7246,7 +7246,7 @@
}

if (success) {
firstForgedItem->setTier(tier + 1);

Check warning on line 7249 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

if (bonus != 1) {
history.dustCost = dustCost;
Expand Down Expand Up @@ -7285,10 +7285,10 @@

if (bonus == 4) {
if (tier > 0) {
secondForgedItem->setTier(tier - 1);

Check warning on line 7288 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}
} else if (bonus == 6) {
secondForgedItem->setTier(tier + 1);

Check warning on line 7291 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
} else if (bonus == 7 && tier + 2 <= firstForgedItem->getClassification()) {
firstForgedItem->setTier(tier + 2);
}
Expand All @@ -7306,7 +7306,7 @@
auto isTierLost = uniform_random(1, 100) <= (reduceTierLoss ? g_configManager().getNumber(FORGE_TIER_LOSS_REDUCTION, __FUNCTION__) : 100);
if (isTierLost) {
if (secondForgedItem->getTier() >= 1) {
secondForgedItem->setTier(tier - 1);

Check warning on line 7309 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
} else {
returnValue = g_game().internalRemoveItem(secondForgedItem, 1);
if (returnValue != RETURNVALUE_NOERROR) {
Expand All @@ -7317,7 +7317,7 @@
}
}
}
bonus = (isTierLost ? 0 : 8);

Check warning on line 7320 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
history.coresCost = coreCount;

if (getForgeDusts() < dustCost) {
Expand All @@ -7339,12 +7339,12 @@
if (itemClassification->id != firstForgingItem->getClassification()) {
continue;
}
if (!itemClassification->tiers.contains(firstForgingItem->getTier() + 1)) {

Check warning on line 7342 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
g_logger().error("[{}] Failed to find tier {} for item {} in classification {}", __FUNCTION__, firstForgingItem->getTier() + 1, firstForgingItem->getClassification(), itemClassification->id);
sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR);
break;
}
cost = itemClassification->tiers.at(firstForgingItem->getTier() + 1).regularPrice;

Check warning on line 7347 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
break;
}
if (!g_game().removeMoney(static_self_cast<Player>(), cost, 0, true)) {
Expand Down Expand Up @@ -7373,7 +7373,7 @@
history.convergence = convergence;
registerForgeHistoryDescription(history);

sendForgeResult(actionType, firstItemId, tier, secondItemId, tier + 1, success, bonus, coreCount, convergence);

Check warning on line 7376 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

void Player::forgeTransferItemTier(ForgeAction_t actionType, uint16_t donorItemId, uint8_t tier, uint16_t receiveItemId, bool convergence) {
Expand Down Expand Up @@ -7457,7 +7457,7 @@
return;
}

uint8_t coresAmount = 0;

Check warning on line 7460 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
uint64_t cost = 0;
for (const auto &itemClassification : g_game().getItemsClassifications()) {
if (itemClassification->id != donorItem->getClassification()) {
Expand Down Expand Up @@ -7502,7 +7502,7 @@
history.convergence = convergence;
registerForgeHistoryDescription(history);

sendForgeResult(actionType, donorItemId, tier, receiveItemId, convergence ? tier : tier - 1, true, 0, 0, convergence);

Check warning on line 7505 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

Check warning on line 7505 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values

Check warning on line 7505 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
}

void Player::forgeResourceConversion(ForgeAction_t actionType) {
Expand Down Expand Up @@ -8108,7 +8108,7 @@
if (inventoryItems.empty()) {
return nullptr;
}
auto containerItem = inventoryItems.front();

Check warning on line 8111 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

unnecessary-copy-initialization

the variable 'containerItem' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference
if (!containerItem) {
return nullptr;
}
Expand Down Expand Up @@ -8171,7 +8171,7 @@

if (willNotLoseBless) {
auto addedBless = false;
for (uint8_t i = 2; i <= 6; i++) {

Check warning on line 8174 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

misra-cpp2008-5-0-11

MISRA 5-0-11: The plain char type shall only be used for the storage and use of character values
if (!hasBlessing(i)) {
addBlessing(i, 1);
addedBless = true;
Expand Down
Loading