Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 16 additions & 8 deletions modules/game_prey_html/game_prey_html.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ function PreyController:handleResources()

local player = g_game.getLocalPlayer()
if not player then return end
self.wildcards = player:getResourceBalance(ResourceTypes.PREY_WILDCARDS)
self.bankGold = player:getResourceBalance(ResourceTypes.BANK_BALANCE)
self.inventoryGold = player:getResourceBalance(ResourceTypes.GOLD_EQUIPPED)
self.rawPlayerGold = player:getTotalMoney() or 0
self.playerGold = comma_value(self.rawPlayerGold)
self.wildcards = player:getResourceBalance(ResourceTypes.PREY_WILDCARDS)
end

function show()
Expand All @@ -56,6 +58,7 @@ function toggle()
end

function PreyController:hide()
PreyController:handleResources()
if PreyController.ui then
PreyController:unloadHtml()
end
Expand Down Expand Up @@ -289,8 +292,10 @@ function onPreySelectionChangeMonster(slot, names, outfits, bonusType, bonusValu
PreyController.preyData[slotId].percentFreeReroll = Helper.getProgress(timeUntilFreeReroll, Helper.freeRerollHours,
Helper.freeRerollBarWidth)
PreyController.preyData[slotId].timeUntilFreeReroll = timeleftTranslation(timeUntilFreeReroll)
PreyController.preyData[slotId].isFreeReroll = timeUntilFreeReroll == 0
PreyController.preyData[slotId].disableFreeReroll = PreyController.rawRerollGoldPrice > PreyController.rawPlayerGold
local isFreeReroll = timeUntilFreeReroll == 0
PreyController.preyData[slotId].isFreeReroll = isFreeReroll
PreyController.preyData[slotId].disableFreeReroll = PreyController.rawRerollGoldPrice > PreyController.rawPlayerGold and
not isFreeReroll
end

function onPreyInactive(slot, timeUntilFreeReroll, wildcards)
Expand Down Expand Up @@ -576,8 +581,10 @@ function onPreySelection(slot, names, outfits, timeUntilFreeReroll, wildcards)
PreyController.preyData[slotId].timeUntilFreeReroll = timeleftTranslation(timeUntilFreeReroll)
PreyController.preyData[slotId].type = SLOT_STATE_SELECTION
PreyController.preyData[slotId].monsterName = "Select your prey creature"
PreyController.preyData[slotId].isFreeReroll = timeUntilFreeReroll == 0
PreyController.preyData[slotId].disableFreeReroll = PreyController.rawRerollGoldPrice > PreyController.rawPlayerGold
local isFreeReroll = timeUntilFreeReroll == 0
PreyController.preyData[slotId].isFreeReroll = isFreeReroll
PreyController.preyData[slotId].disableFreeReroll = PreyController.rawRerollGoldPrice > PreyController.rawPlayerGold and
not isFreeReroll
end

function PreyController:onGameStart()
Expand Down Expand Up @@ -689,9 +696,10 @@ function onPreyActive(slot, currentHolderName, currentHolderOutfit, bonusType, b
PreyController.preyData[slotId].bonusType = bonusType
PreyController.preyData[slotId].timeUntilFreeReroll = timeleftTranslation(rawTimeUntilFreeReroll)
PreyController:handleResources()
PreyController.preyData[slotId].isFreeReroll = rawTimeUntilFreeReroll == 0
PreyController.preyData[slotId].disableFreeReroll = PreyController.rawRerollGoldPrice >
PreyController.rawPlayerGold
local isFreeReroll = rawTimeUntilFreeReroll == 0
PreyController.preyData[slotId].isFreeReroll = isFreeReroll
PreyController.preyData[slotId].disableFreeReroll = PreyController.rawRerollGoldPrice > PreyController.rawPlayerGold and
not isFreeReroll
end

function PreyController:onMouseWheel(slotId, hoveredIndex)
Expand Down
2 changes: 1 addition & 1 deletion modules/game_prey_html/prey_html.css
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@

.gold-container {
--image-source: "/modules/game_prey_html/images/player-gold-bg.png";
width: 200px;
width: 130px;
height: 20px;
text-align: center;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion modules/game_prey_html/prey_html.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
<img
onhover="self:onHover(slot.slotId, 'rerollButton')"
class="base-img-clip"
*disabled="self.rawRerollGoldPrice > self.rawPlayerGold"
*disabled="slot.disableFreeReroll"
src="/modules/game_prey_html/images/prey-reroll-button.png"
onclick="self:listReroll(slot.slotId)"
/>
Expand Down
18 changes: 9 additions & 9 deletions src/client/animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Animator::unserialize(const int animationPhases, const FileStreamPtr& fin)
m_loopCount = fin->get32();
m_startPhase = fin->get8();

for (int i = 0; i < m_animationPhases; ++i) {
for (int i = 0; std::cmp_less(i, m_animationPhases); ++i) {
int minimum = fin->getU32();
int maximum = fin->getU32();
m_phaseDurations.emplace_back(minimum, maximum);
Expand Down Expand Up @@ -79,7 +79,7 @@ void Animator::serialize(const FileStreamPtr& fin) const

void Animator::setPhase(const int phase)
{
if (m_phase == phase)
if (std::cmp_equal(m_phase, phase))
return;

if (!m_async) {
Expand All @@ -91,7 +91,7 @@ void Animator::setPhase(const int phase)
m_phase = 0;
else if (phase == AnimPhaseRandom)
m_phase = stdext::random_range(0, m_animationPhases);
else if (phase >= 0 && phase < m_animationPhases)
else if (phase >= 0 && std::cmp_less(phase, m_animationPhases))
m_phase = phase;
else
m_phase = getStartPhase();
Expand All @@ -107,14 +107,14 @@ int Animator::getPhase()
const ticks_t ticks = g_clock.millis();
if (ticks != m_lastPhaseTicks && !m_isComplete) {
const int elapsedTicks = static_cast<int>(ticks - m_lastPhaseTicks);
if (elapsedTicks >= m_currentDuration) {
if (std::cmp_greater_equal(elapsedTicks, m_currentDuration)) {
int phase;
if (m_loopCount < 0)
phase = getPingPongPhase();
else
phase = getLoopPhase();

if (m_phase != phase) {
if (std::cmp_not_equal(m_phase, phase)) {
const int duration = getPhaseDuration(phase) - (elapsedTicks - m_currentDuration);
if (duration < 0 && !m_async) {
calculateSynchronous();
Expand Down Expand Up @@ -171,7 +171,7 @@ int Animator::getPingPongPhase()
{
int count = m_currentDirection == AnimDirForward ? 1 : -1;
const int nextPhase = m_phase + count;
if (nextPhase < 0 || nextPhase >= m_animationPhases) {
if (nextPhase < 0 || std::cmp_greater_equal(nextPhase, m_animationPhases)) {
m_currentDirection = m_currentDirection == AnimDirForward ? AnimDirBackward : AnimDirForward;
count *= -1;
}
Expand All @@ -181,7 +181,7 @@ int Animator::getPingPongPhase()
int Animator::getLoopPhase()
{
const int nextPhase = m_phase + 1;
if (nextPhase < m_animationPhases)
if (std::cmp_less(nextPhase, m_animationPhases))
return nextPhase;

if (m_loopCount == 0)
Expand All @@ -208,13 +208,13 @@ int Animator::getPhaseDuration(const int phase) const
void Animator::calculateSynchronous()
{
int totalDuration = 0;
for (int i = 0; i < m_animationPhases; ++i)
for (int i = 0; std::cmp_less(i, m_animationPhases); ++i)
totalDuration += getPhaseDuration(i);

const ticks_t ticks = g_clock.millis();
const int elapsedTicks = static_cast<int>(ticks % totalDuration);
int totalTime = 0;
for (int i = 0; i < m_animationPhases; ++i) {
for (int i = 0; std::cmp_less(i, m_animationPhases); ++i) {
const int duration = getPhaseDuration(i);
if (elapsedTicks >= totalTime && elapsedTicks < totalTime + duration) {
m_phase = i;
Expand Down
2 changes: 1 addition & 1 deletion src/client/attachedeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void AttachedEffect::draw(const Point& dest, const bool isOnTop, const LightView
return;

const int animation = getCurrentAnimationPhase();
if (m_loop > -1 && animation != m_lastAnimation) {
if (m_loop > -1 && std::cmp_not_equal(animation, m_lastAnimation)) {
m_lastAnimation = animation;
if (animation == 0 && --m_loop == 0)
return;
Expand Down
6 changes: 3 additions & 3 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Client : public ApplicationDrawEvents
void preLoad() override;
void draw(DrawPoolType type) override;

bool canDraw(DrawPoolType type) const override;
[[nodiscard]] bool canDraw(DrawPoolType type) const override;
bool isLoadingAsyncTexture() override;
bool isUsingProtobuf() override;

Expand All @@ -47,10 +47,10 @@ class Client : public ApplicationDrawEvents

UIMapPtr getMapWidget() { return m_mapWidget; }

float getEffectAlpha() const { return m_effectAlpha; }
[[nodiscard]] float getEffectAlpha() const { return m_effectAlpha; }
void setEffectAlpha(const float v) { m_effectAlpha = v; }

float getMissileAlpha() const { return m_missileAlpha; }
[[nodiscard]] float getMissileAlpha() const { return m_missileAlpha; }
void setMissileAlpha(const float v) { m_missileAlpha = v; }

private:
Expand Down
6 changes: 3 additions & 3 deletions src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,11 @@ namespace Otc
FIRST = KNIGHT,
LAST = DRUID,
};

enum PartyAnalyzerAction_t : uint8_t {

enum PartyAnalyzerAction_t : uint8_t
{
PARTYANALYZERACTION_RESET = 0,
PARTYANALYZERACTION_PRICETYPE = 1,
PARTYANALYZERACTION_PRICEVALUE = 2,
};

}
21 changes: 13 additions & 8 deletions src/client/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
*/

#include "container.h"

#include "item.h"

ItemPtr Container::getItem(const int slot)
{
if (slot < 0 || slot >= static_cast<int>(m_items.size()))
if (slot < 0 || std::cmp_greater_equal(slot, m_items.size())
)
return nullptr;
return m_items[slot];
}
Expand All @@ -46,7 +48,7 @@ void Container::onAddItem(const ItemPtr& item, int slot)
slot -= m_firstIndex;

// indicates that there is a new item on next page
if (m_hasPages && slot > m_capacity) {
if (m_hasPages && std::cmp_greater(slot, m_capacity)) {
callLuaField("onSizeChange", ++m_size);
return;
}
Expand All @@ -58,7 +60,7 @@ void Container::onAddItem(const ItemPtr& item, int slot)

m_items.insert(m_items.begin() + slot, item);
++m_size;

updateItemsPositions();

callLuaField("onSizeChange", m_size);
Expand All @@ -83,7 +85,8 @@ void Container::onAddItems(const std::vector<ItemPtr>& items)
void Container::onUpdateItem(int slot, const ItemPtr& item)
{
slot -= m_firstIndex;
if (slot < 0 || slot >= static_cast<int>(m_items.size())) {
if (slot < 0 || std::cmp_greater_equal(slot, m_items.size())
) {
g_logger.traceError("slot not found");
return;
}
Expand All @@ -100,12 +103,14 @@ void Container::onRemoveItem(int slot, const ItemPtr& lastItem)
slot -= m_firstIndex;

// indicates that there has been deleted an item on next page
if (m_hasPages && slot >= static_cast<int>(m_items.size())) {
if (m_hasPages && std::cmp_greater_equal(slot, m_items.size())
) {
callLuaField("onSizeChange", --m_size);
return;
}

if (slot < 0 || slot >= static_cast<int>(m_items.size())) {
if (slot < 0 || std::cmp_greater_equal(slot, m_items.size())
) {
g_logger.traceError("slot not found");
return;
}
Expand All @@ -128,6 +133,6 @@ void Container::onRemoveItem(int slot, const ItemPtr& lastItem)

void Container::updateItemsPositions()
{
for (int slot = 0; slot < static_cast<int>(m_items.size()); ++slot)
for (int slot = 0; std::cmp_less(slot, m_items.size()); ++slot)
m_items[slot]->setPosition(getSlotPosition(slot));
}
}
7 changes: 4 additions & 3 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void Creature::updateWalkAnimation()
const int footDelay = std::clamp<int>(walkSpeed / footAnimDelay, minFootDelay, maxFootDelay);

if (m_footTimer.ticksElapsed() >= footDelay) {
if (m_walkAnimationPhase == footAnimPhases) m_walkAnimationPhase = 1;
if (std::cmp_equal(m_walkAnimationPhase, footAnimPhases)) m_walkAnimationPhase = 1;
else ++m_walkAnimationPhase;

m_footTimer.restart();
Expand Down Expand Up @@ -916,7 +916,8 @@ void Creature::setIconsTexture(const std::string& filename, const Rect& clip, co
m_icons->numberText.setAlign(Fw::AlignCenter);
}

m_icons->atlasGroups.emplace_back(IconRenderData::AtlasIconGroup{ g_textures.getTexture(filename), clip, count });
m_icons->atlasGroups.emplace_back(IconRenderData::AtlasIconGroup{ .texture = g_textures.getTexture(filename),
.clip = clip, .count = count });
}
void Creature::setSkullTexture(const std::string& filename) { m_skullTexture = g_textures.getTexture(filename); }
void Creature::setEmblemTexture(const std::string& filename) { m_emblemTexture = g_textures.getTexture(filename); }
Expand Down Expand Up @@ -1014,7 +1015,7 @@ uint16_t Creature::getStepDuration(const bool ignoreDiagonal, const Otc::Directi
if (groundSpeed == 0)
groundSpeed = 150;

if (groundSpeed != m_stepCache.groundSpeed || m_speed != m_stepCache.speed) {
if (std::cmp_not_equal(groundSpeed, m_stepCache.groundSpeed) || m_speed != m_stepCache.speed) {
m_stepCache.speed = m_speed;
m_stepCache.groundSpeed = groundSpeed;

Expand Down
2 changes: 1 addition & 1 deletion src/client/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ minHeight,
uint16_t walkDuration{ 0 };
uint16_t diagonalDuration{ 0 };

uint16_t getDuration(const Otc::Direction dir) const { return Position::isDiagonal(dir) ? diagonalDuration : duration; }
[[nodiscard]] uint16_t getDuration(const Otc::Direction dir) const { return Position::isDiagonal(dir) ? diagonalDuration : duration; }
};

struct IconRenderData
Expand Down
2 changes: 1 addition & 1 deletion src/client/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool Effect::waitFor(const EffectPtr& effect)
uint16_t minDuration = getIdleAnimator() ? getIdleAnimator()->getMinDuration() : g_gameConfig.getEffectTicksPerFrame();
minDuration = minDuration * std::max<uint8_t>(getAnimationPhases() / 3, 1);

if (ticksElapsed <= minDuration)
if (std::cmp_less_equal(ticksElapsed, minDuration))
return false;

const int duration = effect->m_duration / (g_app.mustOptimize() || g_app.isForcedEffectOptimization() ? 1.5 : 3);
Expand Down
7 changes: 3 additions & 4 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ void Game::buyStoreOffer(const uint32_t offerId, const uint8_t action, const std
if (!canPerformGameAction())
return;

m_protocolGame->sendBuyStoreOffer(offerId, action, name, type,location);
m_protocolGame->sendBuyStoreOffer(offerId, action, name, type, location);
}

void Game::requestTransactionHistory(const uint32_t page, const uint32_t entriesPerPage)
Expand Down Expand Up @@ -1579,7 +1579,7 @@ void Game::sendRequestStoreOfferById(const uint32_t offerId, const uint8_t sortO
if (!canPerformGameAction())
return;

m_protocolGame->sendRequestStoreOfferById(offerId, sortOrder , serviceType);
m_protocolGame->sendRequestStoreOfferById(offerId, sortOrder, serviceType);
}

void Game::sendRequestStoreSearch(const std::string_view searchText, const uint8_t sortOrder, const uint8_t serviceType)
Expand Down Expand Up @@ -2043,5 +2043,4 @@ void Game::processCyclopediaCharacterDefenceStats(const CyclopediaCharacterDefen
void Game::processCyclopediaCharacterMiscStats(const CyclopediaCharacterMiscStats& data)
{
g_lua.callGlobalField("g_game", "onCyclopediaCharacterMiscStats", data);
}

}
6 changes: 3 additions & 3 deletions src/client/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ class Game
void sendPartyAnalyzerPriceType();
void sendPartyAnalyzerPriceValue(); // For action 3, will get items from cyclopedia
void sendPartyAnalyzerAction(uint8_t action, const std::vector<std::tuple<uint16_t, uint64_t>>& items = {});

// outfit related
void requestOutfit();
void changeOutfit(const Outfit& outfit);
Expand Down Expand Up @@ -887,15 +887,15 @@ class Game
void setCustomOs(const Otc::OperatingSystem_t os) { m_clientCustomOs = os; }
Otc::OperatingSystem_t getOs();

bool canPerformGameAction() const;
[[nodiscard]] bool canPerformGameAction() const;

bool isOnline() { return m_online; }
bool isLogging() { return !m_online && m_protocolGame; }
bool isDead() { return m_dead; }
bool isAttacking() { return !!m_attackingCreature && !m_attackingCreature->isRemoved(); }
bool isFollowing() { return !!m_followingCreature && !m_followingCreature->isRemoved(); }
bool isConnectionOk() { return m_protocolGame && m_protocolGame->getElapsedTicksSinceLastRead() < 5000; }
auto mapUpdatedAt() const { return m_mapUpdatedAt; }
[[nodiscard]] auto mapUpdatedAt() const { return m_mapUpdatedAt; }
void resetMapUpdatedAt() { m_mapUpdatedAt = 0; }

int getPing() { return m_ping; }
Expand Down
Loading
Loading