Skip to content

Commit

Permalink
Merge branch 'main' into expert-pvp
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Jan 13, 2025
2 parents 60932b1 + bdfaf3c commit 548488f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
2 changes: 0 additions & 2 deletions markdowns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

- Protocol 14.05 support. ([Tryller](https://github.com/jprzimba))
- New protocol 14.05 assets. ([Tryller](https://github.com/jprzimba))
- Optimized the `onPlayerSellAllLoot` code to prevent prolonged freezes. ([Tryller](https://github.com/jprzimba))
- Add new configurable featurees in `config.lua`: `chainSystemVipOnly`, `fieldOwnershipDuration`, `bedsOnlyPremium`, `loginProtectionPeriod`, `chainSystemModifyMagic`, `logPlayersStatements`. ([Tryller](https://github.com/jprzimba))
- Added a new commands for players: `!randomoutfit`, `!spellwords`. ([Tryller](https://github.com/jprzimba))
- Moved emote spells to `kv` instead of `storage`. ([Tryller](https://github.com/jprzimba))
Expand Down Expand Up @@ -134,7 +133,6 @@
- Fixed V.I.P List ([Tryller](https://github.com/jprzimba)).
- Fixed damage reflection not working properly ([Tryller](https://github.com/jprzimba)).
- Fixed imbuement system when the player adds imbuement or cancels imbuement and the imbuement window is open not updating ([Tryller](https://github.com/jprzimba)).
- Optimized onPlayerSellAllLoot in npc code to avoid long freeze ([Tryller](https://github.com/jprzimba)).
- Fixed data/scripts/talkactions/player/refill.lua, now check if player has capacity to receive items. ([Tryller](https://github.com/jprzimba)).
- Fixed Loot pouch using in the Obtain method ([carlospess0a](https://github.com/carlospess0a)).
- Fixed destroy field is working inside pz ([carlospess0a](https://github.com/carlospess0a)).
Expand Down
46 changes: 17 additions & 29 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,57 +443,45 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u
if (!player) {
return;
}

if (itemId == ITEM_GOLD_POUCH) {
const auto &container = player->getLootPouch();
if (!container) {
return;
}

bool hasMore = false;
uint64_t toSellCount = 0;
phmap::flat_hash_map<uint16_t, uint16_t> toSell;
ContainerIterator it = container->iterator();

while (it.hasNext()) {
auto item = *it;
for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) {
if (toSellCount >= 500) {
hasMore = true;
break;
}
const auto &item = *it;
if (!item) {
continue;
}

toSell[item->getID()] += item->getItemAmount();
if (item->isStackable()) {
toSellCount++;
} else {
toSellCount += item->getItemAmount();
}

if (toSellCount >= 100) {
break;
}

it.advance();
}

if (toSell.empty()) {
std::stringstream ss;
for (const auto &[m_itemId, amount] : toSell) {
onPlayerSellItem(player, m_itemId, 0, amount, ignore, totalPrice, container);
}
auto ss = std::stringstream();
if (totalPrice == 0) {
ss << "You have no items in your loot pouch.";
player->sendTextMessage(MESSAGE_FAILURE, ss.str());
return;
}

for (auto &[itemId, amount] : toSell) {
onPlayerSellItem(player, itemId, 0, amount, ignore, totalPrice, container);
if (hasMore) {
g_dispatcher().scheduleEvent(
SCHEDULER_MINTICKS, [this, playerId = player->getID(), itemId, ignore, totalPrice] { onPlayerSellAllLoot(playerId, itemId, ignore, totalPrice); }, __FUNCTION__
);
return;
}

const auto &task = player->createPlayerTask(
100, [this, playerId, itemId, ignore, totalPrice]() {
onPlayerSellAllLoot(playerId, itemId, ignore, totalPrice);
},
__FUNCTION__
);
player->setNextActionPushTask(task);

auto ss = std::stringstream();
ss << "You sold all of the items from your loot pouch for ";
ss << totalPrice << " gold.";
player->sendTextMessage(MESSAGE_LOOK, ss.str());
Expand Down
5 changes: 3 additions & 2 deletions src/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ void Database::createDatabaseBackup(bool compress) const {
for (const auto &file : std::filesystem::directory_iterator(entry)) {
if (file.path().extension() == ".gz") {
auto fileTime = std::filesystem::last_write_time(file);
auto fileTimeSystemClock = std::chrono::clock_cast<std::chrono::system_clock>(fileTime);
if (fileTimeSystemClock < sevenDaysAgo) {
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());

if (sctp < sevenDaysAgo) {
std::filesystem::remove(file);
g_logger().info("Deleted old backup file: {}", file.path().string());
}
Expand Down

0 comments on commit 548488f

Please sign in to comment.