Skip to content

Commit 548488f

Browse files
committed
Merge branch 'main' into expert-pvp
2 parents 60932b1 + bdfaf3c commit 548488f

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

markdowns/CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
- Protocol 14.05 support. ([Tryller](https://github.com/jprzimba))
99
- New protocol 14.05 assets. ([Tryller](https://github.com/jprzimba))
10-
- Optimized the `onPlayerSellAllLoot` code to prevent prolonged freezes. ([Tryller](https://github.com/jprzimba))
1110
- Add new configurable featurees in `config.lua`: `chainSystemVipOnly`, `fieldOwnershipDuration`, `bedsOnlyPremium`, `loginProtectionPeriod`, `chainSystemModifyMagic`, `logPlayersStatements`. ([Tryller](https://github.com/jprzimba))
1211
- Added a new commands for players: `!randomoutfit`, `!spellwords`. ([Tryller](https://github.com/jprzimba))
1312
- Moved emote spells to `kv` instead of `storage`. ([Tryller](https://github.com/jprzimba))
@@ -134,7 +133,6 @@
134133
- Fixed V.I.P List ([Tryller](https://github.com/jprzimba)).
135134
- Fixed damage reflection not working properly ([Tryller](https://github.com/jprzimba)).
136135
- Fixed imbuement system when the player adds imbuement or cancels imbuement and the imbuement window is open not updating ([Tryller](https://github.com/jprzimba)).
137-
- Optimized onPlayerSellAllLoot in npc code to avoid long freeze ([Tryller](https://github.com/jprzimba)).
138136
- Fixed data/scripts/talkactions/player/refill.lua, now check if player has capacity to receive items. ([Tryller](https://github.com/jprzimba)).
139137
- Fixed Loot pouch using in the Obtain method ([carlospess0a](https://github.com/carlospess0a)).
140138
- Fixed destroy field is working inside pz ([carlospess0a](https://github.com/carlospess0a)).

src/creatures/npcs/npc.cpp

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -443,57 +443,45 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u
443443
if (!player) {
444444
return;
445445
}
446-
447446
if (itemId == ITEM_GOLD_POUCH) {
448447
const auto &container = player->getLootPouch();
449448
if (!container) {
450449
return;
451450
}
452-
451+
bool hasMore = false;
453452
uint64_t toSellCount = 0;
454453
phmap::flat_hash_map<uint16_t, uint16_t> toSell;
455-
ContainerIterator it = container->iterator();
456-
457-
while (it.hasNext()) {
458-
auto item = *it;
454+
for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) {
455+
if (toSellCount >= 500) {
456+
hasMore = true;
457+
break;
458+
}
459+
const auto &item = *it;
459460
if (!item) {
460461
continue;
461462
}
462-
463463
toSell[item->getID()] += item->getItemAmount();
464464
if (item->isStackable()) {
465465
toSellCount++;
466466
} else {
467467
toSellCount += item->getItemAmount();
468468
}
469-
470-
if (toSellCount >= 100) {
471-
break;
472-
}
473-
474-
it.advance();
475469
}
476-
477-
if (toSell.empty()) {
478-
std::stringstream ss;
470+
for (const auto &[m_itemId, amount] : toSell) {
471+
onPlayerSellItem(player, m_itemId, 0, amount, ignore, totalPrice, container);
472+
}
473+
auto ss = std::stringstream();
474+
if (totalPrice == 0) {
479475
ss << "You have no items in your loot pouch.";
480476
player->sendTextMessage(MESSAGE_FAILURE, ss.str());
481477
return;
482478
}
483-
484-
for (auto &[itemId, amount] : toSell) {
485-
onPlayerSellItem(player, itemId, 0, amount, ignore, totalPrice, container);
479+
if (hasMore) {
480+
g_dispatcher().scheduleEvent(
481+
SCHEDULER_MINTICKS, [this, playerId = player->getID(), itemId, ignore, totalPrice] { onPlayerSellAllLoot(playerId, itemId, ignore, totalPrice); }, __FUNCTION__
482+
);
483+
return;
486484
}
487-
488-
const auto &task = player->createPlayerTask(
489-
100, [this, playerId, itemId, ignore, totalPrice]() {
490-
onPlayerSellAllLoot(playerId, itemId, ignore, totalPrice);
491-
},
492-
__FUNCTION__
493-
);
494-
player->setNextActionPushTask(task);
495-
496-
auto ss = std::stringstream();
497485
ss << "You sold all of the items from your loot pouch for ";
498486
ss << totalPrice << " gold.";
499487
player->sendTextMessage(MESSAGE_LOOK, ss.str());

src/database/database.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ void Database::createDatabaseBackup(bool compress) const {
138138
for (const auto &file : std::filesystem::directory_iterator(entry)) {
139139
if (file.path().extension() == ".gz") {
140140
auto fileTime = std::filesystem::last_write_time(file);
141-
auto fileTimeSystemClock = std::chrono::clock_cast<std::chrono::system_clock>(fileTime);
142-
if (fileTimeSystemClock < sevenDaysAgo) {
141+
auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(fileTime - std::filesystem::file_time_type::clock::now() + std::chrono::system_clock::now());
142+
143+
if (sctp < sevenDaysAgo) {
143144
std::filesystem::remove(file);
144145
g_logger().info("Deleted old backup file: {}", file.path().string());
145146
}

0 commit comments

Comments
 (0)