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

Add exhaustion to npc say and sell/buy item #459

Merged
merged 4 commits into from
Jul 27, 2022
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
9 changes: 9 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5613,6 +5613,15 @@ bool Player::isMarketExhausted() const {
return (OTSYS_TIME() - lastMarketInteraction < exhaust_time);
}

// Player talk with npc exhausted
bool Player::isNpcExhausted(uint32_t exhaustionTime /*= 250*/) const {
return (OTSYS_TIME() - lastNpcInteraction < exhaustionTime);
}

void Player::updateNpcExhausted() {
lastNpcInteraction = OTSYS_TIME();
}

uint64_t Player::getItemCustomPrice(uint16_t itemId, bool buyPrice/* = false*/) const
{
auto it = itemPriceMap.find(itemId);
Expand Down
6 changes: 5 additions & 1 deletion src/creatures/players/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,9 @@ class Player final : public Creature, public Cylinder
lastMarketInteraction = OTSYS_TIME();
}

bool isNpcExhausted(uint32_t exhaustionTime = 150) const;
void updateNpcExhausted();

bool isQuickLootListedItem(const Item* item) const {
if (!item) {
return false;
Expand Down Expand Up @@ -2211,7 +2214,8 @@ class Player final : public Creature, public Cylinder
int64_t skullTicks = 0;
int64_t lastWalkthroughAttempt = 0;
int64_t lastToggleMount = 0;
int64_t lastMarketInteraction = 0; // Market exhaust.
int64_t lastMarketInteraction = 0;
int64_t lastNpcInteraction = 0;
int64_t lastStashInteraction = 0;
int64_t lastDepotSearchInteraction = 0;
int64_t lastPing;
Expand Down
27 changes: 27 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4359,7 +4359,14 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint
return;
}

// Check npc say exhausted
if (player->isNpcExhausted()) {
player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED);
return;
}

merchant->onPlayerBuyItem(player, it.id, count, amount, ignoreCap, inBackpacks);
player->updateNpcExhausted();
}

void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint8_t amount, bool ignoreEquipped)
Expand All @@ -4383,7 +4390,14 @@ void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uin
return;
}

// Check npc say exhausted
if (player->isNpcExhausted()) {
player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED);
return;
}

merchant->onPlayerSellItem(player, it.id, count, amount, ignoreEquipped);
player->updateNpcExhausted();
}

void Game::playerCloseShop(uint32_t playerId)
Expand Down Expand Up @@ -5309,13 +5323,26 @@ bool Game::playerSpeakTo(Player* player, SpeakClasses type, const std::string& r

void Game::playerSpeakToNpc(Player* player, const std::string& text)
{
if (player == nullptr) {
SPDLOG_ERROR("[Game::playerSpeakToNpc] - Player is nullptr");
return;
}

// Check npc say exhausted
if (player->isNpcExhausted()) {
player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED);
return;
}

SpectatorHashSet spectators;
map.getSpectators(spectators, player->getPosition());
for (Creature* spectator : spectators) {
if (spectator->getNpc()) {
spectator->onCreatureSay(player, TALKTYPE_PRIVATE_PN, text);
}
}

player->updateNpcExhausted();
}

//--
Expand Down