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

Improve save #5

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
70575b0
Update creatures_definitions.hpp
luanluciano93 Mar 22, 2024
f8a692d
Update player.hpp
luanluciano93 Mar 22, 2024
788aa0b
Update player.hpp
luanluciano93 Mar 22, 2024
cc360c6
Update player.hpp
luanluciano93 Mar 22, 2024
979ac0e
Code format - (Clang-format)
github-actions[bot] Mar 22, 2024
292412d
Update player.hpp
luanluciano93 Mar 22, 2024
6e4308a
Update creatures_definitions.hpp
luanluciano93 Mar 22, 2024
c687580
Update iologindata_save_player.cpp
luanluciano93 Mar 22, 2024
539626e
Update iologindata_load_player.cpp
luanluciano93 Mar 22, 2024
ecf87cf
Update iologindata.cpp
luanluciano93 Mar 23, 2024
61df230
Update iologindata_save_player.cpp
luanluciano93 Mar 23, 2024
fee8d64
Update player.hpp
luanluciano93 Mar 24, 2024
7eaf782
Update iologindata_save_player.cpp
luanluciano93 Mar 24, 2024
afd1515
Update iologindata_load_player.cpp
luanluciano93 Mar 24, 2024
a8e95ff
Update player.cpp
luanluciano93 Mar 24, 2024
cfaca94
Update iologindata.cpp
luanluciano93 Mar 24, 2024
cc579db
Update iologindata.cpp
luanluciano93 Mar 24, 2024
1147e6c
Update player.cpp
luanluciano93 Mar 24, 2024
ec25123
Update iologindata_save_player.cpp
luanluciano93 Mar 24, 2024
5e19ef7
Update player.hpp
luanluciano93 Mar 24, 2024
9ccfe62
fix: guard all depot in stash (#2491)
beats-dh Mar 25, 2024
8dec6f9
fix: auto loot reachable corpses only (#2473)
lezinhu0 Mar 26, 2024
baf4666
Merge branch 'opentibiabr:main' into improve-save
luanluciano93 Mar 28, 2024
d0f8c7b
Update iologindata.cpp
luanluciano93 Mar 28, 2024
284f594
Code format - (Clang-format)
github-actions[bot] Mar 28, 2024
049faf0
Update game.hpp
luanluciano93 Mar 28, 2024
e46005b
Update game.hpp
luanluciano93 Mar 28, 2024
469a678
Code format - (Clang-format)
github-actions[bot] Mar 28, 2024
f36707d
Update game.hpp
luanluciano93 Mar 28, 2024
de84832
Code format - (Clang-format)
github-actions[bot] Mar 28, 2024
fdfdb9b
Update game.hpp
luanluciano93 Mar 28, 2024
9f21018
Update game.cpp
luanluciano93 Mar 28, 2024
43b6495
Update iologindata.cpp
luanluciano93 Mar 28, 2024
1f3eed0
Code format - (Clang-format)
github-actions[bot] Mar 28, 2024
3647958
Update game.hpp
luanluciano93 Mar 28, 2024
873ac28
update
luanluciano93 Mar 29, 2024
33a9c37
Update save_manager.cpp
luanluciano93 Mar 29, 2024
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
12 changes: 11 additions & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,17 @@ bool Creature::dropCorpse(std::shared_ptr<Creature> lastHitCreature, std::shared
player->sendLootMessage(lootMessage.str());
}

if (player->checkAutoLoot(monster->isRewardBoss()) && corpseContainer && mostDamageCreature->getPlayer()) {
stdext::arraylist<Direction> dirList(128);
FindPathParams fpp;
fpp.minTargetDist = 0;
fpp.maxTargetDist = 1;
fpp.fullPathSearch = true;
fpp.clearSight = true;
fpp.maxSearchDist = 0;

auto isReachable = g_game().map.getPathMatching(player->getPosition(), dirList, FrozenPathingConditionCall(corpse->getPosition()), fpp);

if (player->checkAutoLoot(monster->isRewardBoss()) && corpseContainer && mostDamageCreature->getPlayer() && isReachable) {
g_dispatcher().addEvent([player, corpseContainer, corpsePosition = corpse->getPosition()] {
g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition);
},
Expand Down
11 changes: 7 additions & 4 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5158,6 +5158,7 @@ void Player::addUnjustifiedDead(std::shared_ptr<Player> attacked) {
sendTextMessage(MESSAGE_EVENT_ADVANCE, "Warning! The murder of " + attacked->getName() + " was not justified.");

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

uint8_t dayKills = 0;
uint8_t weekKills = 0;
Expand Down Expand Up @@ -5248,11 +5249,13 @@ double Player::getLostPercent() const {
void Player::learnInstantSpell(const std::string &spellName) {
if (!hasLearnedInstantSpell(spellName)) {
learnedInstantSpellList.push_front(spellName);
setSaveSpells(true);
}
}

void Player::forgetInstantSpell(const std::string &spellName) {
learnedInstantSpellList.remove(spellName);
setSaveSpells(true);
}

bool Player::hasLearnedInstantSpell(const std::string &spellName) const {
Expand Down Expand Up @@ -6452,7 +6455,7 @@ void Player::stowItem(std::shared_ptr<Item> item, uint32_t count, bool allItems)
// Stow locker items
std::shared_ptr<DepotLocker> depotLocker = getDepotLocker(getLastDepotId());
auto [itemVector, itemMap] = requestLockerItems(depotLocker);
for (auto lockerItem : itemVector) {
for (const auto &lockerItem : itemVector) {
if (lockerItem == nullptr) {
break;
}
Expand All @@ -6463,7 +6466,7 @@ void Player::stowItem(std::shared_ptr<Item> item, uint32_t count, bool allItems)
}
} else if (item->getContainer()) {
itemDict = item->getContainer()->getStowableItems();
for (std::shared_ptr<Item> containerItem : item->getContainer()->getItems(true)) {
for (const std::shared_ptr<Item> &containerItem : item->getContainer()->getItems(true)) {
uint32_t depotChest = g_configManager().getNumber(DEPOTCHEST, __FUNCTION__);
bool validDepot = depotChest > 0 && depotChest < 21;
if (g_configManager().getBoolean(STASH_MOVING, __FUNCTION__) && containerItem && !containerItem->isStackable() && validDepot) {
Expand All @@ -6473,10 +6476,10 @@ void Player::stowItem(std::shared_ptr<Item> item, uint32_t count, bool allItems)
}
}
} else {
itemDict.push_back(std::pair<std::shared_ptr<Item>, uint32_t>(item, count));
itemDict.emplace_back(item, count);
}

if (itemDict.size() == 0) {
if (itemDict.empty()) {
sendCancelMessage("There is no stowable items on this container.");
return;
}
Expand Down
28 changes: 28 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
auto it = stashItems.find(itemId);
if (it != stashItems.end()) {
stashItems[itemId] += amount;
setSaveStash(true);
return;
}

Expand All @@ -711,6 +712,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
} else {
return false;
}
setSaveStash(true);
return true;
}
return false;
Expand Down Expand Up @@ -2597,6 +2599,25 @@ class Player final : public Creature, public Cylinder, public Bankable {

bool canSpeakWithHireling(uint8_t speechbubble);

bool hasSaveStash() {
return saveStash;
}
void setSaveStash(bool onOff) {
saveStash = onOff;
}
bool hasSaveUnjustifiedKills() {
return saveUnjustifiedKills;
}
void setSaveUnjustifiedKills(bool onOff) {
saveUnjustifiedKills = onOff;
}
bool hasSaveSpells() {
return saveSpells;
}
void setSaveSpells(bool onOff) {
saveSpells = onOff;
}

private:
friend class PlayerLock;
std::mutex mutex;
Expand Down Expand Up @@ -2819,6 +2840,8 @@ class Player final : public Creature, public Cylinder, public Bankable {
uint16_t storeXpBoost = 0;
uint16_t staminaXpBoost = 100;
int16_t lastDepotId = -1;

// Stash
StashItemList stashItems; // [ItemID] = amount
uint32_t movedItems = 0;

Expand Down Expand Up @@ -2889,6 +2912,11 @@ class Player final : public Creature, public Cylinder, public Bankable {
bool dead = false;
bool imbuementTrackerWindowOpen = false;

// Otimize Save Players
bool saveStash = false;
bool saveUnjustifiedKills = false;
bool saveSpells = false;

// Hazard system
int64_t lastHazardSystemCriticalHit = 0;
bool reloadHazardSystemPointsCounter = true;
Expand Down
18 changes: 11 additions & 7 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ void Game::setGameState(GameState_t newState) {
}

case GAME_STATE_SHUTDOWN: {
g_logger().info("Total save: {}", g_game().getImproveSave(1));
g_logger().info("Improve Save Stash: {}", g_game().getImproveSave(2));
g_logger().info("Improve Save Spells: {}", g_game().getImproveSave(3));
g_logger().info("Improve Save Kills: {}", g_game().getImproveSave(4));
g_globalEvents().execute(GLOBALEVENT_SHUTDOWN);

// kick all players that are still online
Expand Down Expand Up @@ -1518,11 +1522,6 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
return;
}

if (!item->isPushable() || item->hasAttribute(ItemAttribute_t::UNIQUEID)) {
player->sendCancelMessage(RETURNVALUE_NOTMOVABLE);
return;
}

const Position &playerPos = player->getPosition();
auto cylinderTile = fromCylinder->getTile();
const Position &mapFromPos = cylinderTile ? cylinderTile->getPosition() : item->getPosition();
Expand Down Expand Up @@ -1649,12 +1648,17 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
return;
}
}

if (isTryingToStow(toPos, toCylinder)) {
player->stowItem(item, count, false);
return;
}


if (!item->isPushable() || item->hasAttribute(ItemAttribute_t::UNIQUEID)) {
player->sendCancelMessage(RETURNVALUE_NOTMOVABLE);
return;
}

ReturnValue ret = internalMoveItem(fromCylinder, toCylinder, toIndex, item, count, nullptr, 0, player);
if (ret != RETURNVALUE_NOERROR) {
player->sendCancelMessage(ret);
Expand Down
30 changes: 30 additions & 0 deletions src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "items/items_classification.hpp"
#include "modal_window/modal_window.hpp"
#include "enums/object_category.hpp"
#include "lib/logging/logger.hpp"

// Forward declaration for protobuf class
namespace Canary {
Expand Down Expand Up @@ -717,6 +718,30 @@ class Game {
std::vector<Achievement> getPublicAchievements();
std::map<uint16_t, Achievement> getAchievements();

void addImproveSave(uint8_t x) {
if (x == 1) {
totalImproveSave++;
} else if (x == 2) {
totalImproveSaveStash++;
} else if (x == 3) {
totalImproveSaveSpells++;
} else if (x == 4) {
totalImproveSaveKills++;
}
}
int32_t getImproveSave(uint8_t x) {
if (x == 1) {
return totalImproveSave;
} else if (x == 2) {
return totalImproveSaveStash;
} else if (x == 3) {
return totalImproveSaveSpells;
} else if (x == 4) {
return totalImproveSaveKills;
}
return 0;
}

private:
std::map<uint16_t, Achievement> m_achievements;
std::map<std::string, uint16_t> m_achievementsNameToId;
Expand Down Expand Up @@ -944,6 +969,11 @@ class Game {
std::string generateHighscoreQueryForOurRank(const std::string &categoryName, uint8_t entriesPerPage, uint32_t playerGUID, uint32_t vocation);
std::string generateHighscoreOrGetCachedQueryForEntries(const std::string &categoryName, uint32_t page, uint8_t entriesPerPage, uint32_t vocation);
std::string generateHighscoreOrGetCachedQueryForOurRank(const std::string &categoryName, uint8_t entriesPerPage, uint32_t playerGUID, uint32_t vocation);

uint32_t totalImproveSave = 0;
uint32_t totalImproveSaveStash = 0;
uint32_t totalImproveSaveSpells = 0;
uint32_t totalImproveSaveKills = 0;
};

constexpr auto g_game = Game::getInstance;
4 changes: 4 additions & 0 deletions src/game/scheduling/save_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ SaveManager &SaveManager::getInstance() {
void SaveManager::saveAll() {
Benchmark bm_saveAll;
logger.info("Saving server...");
logger.info("Total save: {}", g_game().getImproveSave(1));
logger.info("Improve Save Stash: {}", g_game().getImproveSave(2));
logger.info("Improve Save Spells: {}", g_game().getImproveSave(3));
logger.info("Improve Save Kills: {}", g_game().getImproveSave(4));
const auto players = game.getPlayers();

for (const auto &[_, player] : players) {
Expand Down
3 changes: 3 additions & 0 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ void IOLoginDataLoad::loadPlayerKills(std::shared_ptr<Player> player, DBResult_p
time_t killTime = result->getNumber<time_t>("time");
if ((time(nullptr) - killTime) <= g_configManager().getNumber(FRAG_TIME, __FUNCTION__)) {
player->unjustifiedKills.emplace_back(result->getNumber<uint32_t>("target"), killTime, result->getNumber<bool>("unavenged"));
} else {
player->setSaveUnjustifiedKills(true);
}
} while (result->next());
}
Expand Down Expand Up @@ -399,6 +401,7 @@ void IOLoginDataLoad::loadPlayerStashItems(std::shared_ptr<Player> player, DBRes
player->addItemOnStash(result->getNumber<uint16_t>("item_id"), result->getNumber<uint32_t>("item_count"));
} while (result->next());
}
player->setSaveStash(false);
}

void IOLoginDataLoad::loadPlayerBestiaryCharms(std::shared_ptr<Player> player, DBResult_ptr result) {
Expand Down
6 changes: 6 additions & 0 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ bool IOLoginDataSave::savePlayerStash(std::shared_ptr<Player> player) {
if (!stashQuery.execute()) {
return false;
}

player->setSaveStash(false);
return true;
}

Expand Down Expand Up @@ -369,6 +371,8 @@ bool IOLoginDataSave::savePlayerSpells(std::shared_ptr<Player> player) {
if (!spellsQuery.execute()) {
return false;
}

player->setSaveSpells(false);
return true;
}

Expand Down Expand Up @@ -398,6 +402,8 @@ bool IOLoginDataSave::savePlayerKills(std::shared_ptr<Player> player) {
if (!killsQuery.execute()) {
return false;
}

player->setSaveUnjustifiedKills(false);
return true;
}

Expand Down
23 changes: 17 additions & 6 deletions src/io/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,31 @@ bool IOLoginData::savePlayerGuard(std::shared_ptr<Player> player) {
throw DatabaseException("Player nullptr in function: " + std::string(__FUNCTION__));
}

g_game().addImproveSave(1);

if (!IOLoginDataSave::savePlayerFirst(player)) {
throw DatabaseException("[" + std::string(__FUNCTION__) + "] - Failed to save player first: " + player->getName());
}

if (!IOLoginDataSave::savePlayerStash(player)) {
throw DatabaseException("[IOLoginDataSave::savePlayerFirst] - Failed to save player stash: " + player->getName());
if (player->hasSaveStash()) {
if (!IOLoginDataSave::savePlayerStash(player)) {
throw DatabaseException("[IOLoginDataSave::savePlayerFirst] - Failed to save player stash: " + player->getName());
}
g_game().addImproveSave(2);
}

if (!IOLoginDataSave::savePlayerSpells(player)) {
throw DatabaseException("[IOLoginDataSave::savePlayerSpells] - Failed to save player spells: " + player->getName());
if (player->hasSaveSpells()) {
if (!IOLoginDataSave::savePlayerSpells(player)) {
throw DatabaseException("[IOLoginDataSave::savePlayerSpells] - Failed to save player spells: " + player->getName());
}
g_game().addImproveSave(3);
}

if (!IOLoginDataSave::savePlayerKills(player)) {
throw DatabaseException("IOLoginDataSave::savePlayerKills] - Failed to save player kills: " + player->getName());
if (player->hasSaveUnjustifiedKills()) {
if (!IOLoginDataSave::savePlayerKills(player)) {
throw DatabaseException("IOLoginDataSave::savePlayerKills] - Failed to save player kills: " + player->getName());
}
g_game().addImproveSave(4);
}

if (!IOLoginDataSave::savePlayerBestiarySystem(player)) {
Expand Down
Loading