Skip to content

Commit

Permalink
Update player.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh committed Mar 24, 2024
1 parent dc0cd96 commit 7b6ea0c
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Player::Player(ProtocolGame_ptr p) :
}

Player::~Player() {
for (std::shared_ptr<Item> item : inventory) {
for (const std::shared_ptr<Item> &item : inventory) {
if (item) {
item->resetParent();
item->stopDecaying();
Expand Down Expand Up @@ -1317,7 +1317,7 @@ void Player::getRewardList(std::vector<uint64_t> &rewards) const {
std::vector<std::shared_ptr<Item>> Player::getRewardsFromContainer(std::shared_ptr<Container> container) const {
std::vector<std::shared_ptr<Item>> rewardItemsVector;
if (container) {
for (auto item : container->getItems(false)) {
for (const auto &item : container->getItems(false)) {
if (item->getID() == ITEM_REWARD_CONTAINER) {
auto items = getRewardsFromContainer(item->getContainer());
rewardItemsVector.insert(rewardItemsVector.end(), items.begin(), items.end());
Expand Down Expand Up @@ -1736,7 +1736,7 @@ void Player::onCreatureAppear(std::shared_ptr<Creature> creature, bool isLogin)
offlineTime = 0;
}

for (std::shared_ptr<Condition> condition : getMuteConditions()) {
for (const std::shared_ptr<Condition> &condition : getMuteConditions()) {
condition->setTicks(condition->getTicks() - (offlineTime * 1000));
if (condition->getTicks() <= 0) {
removeCondition(condition);
Expand Down Expand Up @@ -2213,7 +2213,7 @@ uint32_t Player::isMuted() const {
}

int32_t muteTicks = 0;
for (std::shared_ptr<Condition> condition : conditions) {
for (const std::shared_ptr<Condition> &condition : conditions) {
if (condition->getType() == CONDITION_MUTED && condition->getTicks() > muteTicks) {
muteTicks = condition->getTicks();
}
Expand Down Expand Up @@ -2382,7 +2382,7 @@ void Player::addExperience(std::shared_ptr<Creature> target, uint64_t exp, bool
if (!spectators.empty()) {
message.type = MESSAGE_EXPERIENCE_OTHERS;
message.text = getName() + " gained " + expString;
for (std::shared_ptr<Creature> spectator : spectators) {
for (const std::shared_ptr<Creature> &spectator : spectators) {
spectator->getPlayer()->sendTextMessage(message);
}
}
Expand Down Expand Up @@ -2475,7 +2475,7 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) {
if (!spectators.empty()) {
message.type = MESSAGE_EXPERIENCE_OTHERS;
message.text = getName() + " lost " + expString;
for (std::shared_ptr<Creature> spectator : spectators) {
for (const std::shared_ptr<Creature> &spectator : spectators) {
spectator->getPlayer()->sendTextMessage(message);
}
}
Expand Down Expand Up @@ -3533,7 +3533,7 @@ std::shared_ptr<Cylinder> Player::queryDestination(int32_t &index, const std::sh
n--;
}

for (std::shared_ptr<Item> tmpContainerItem : tmpContainer->getItemList()) {
for (const std::shared_ptr<Item> &tmpContainerItem : tmpContainer->getItemList()) {
if (std::shared_ptr<Container> subContainer = tmpContainerItem->getContainer()) {
containers.push_back(subContainer);
}
Expand All @@ -3544,7 +3544,7 @@ std::shared_ptr<Cylinder> Player::queryDestination(int32_t &index, const std::sh

uint32_t n = 0;

for (std::shared_ptr<Item> tmpItem : tmpContainer->getItemList()) {
for (const std::shared_ptr<Item> &tmpItem : tmpContainer->getItemList()) {
if (tmpItem == tradeItem) {
continue;
}
Expand Down Expand Up @@ -3752,7 +3752,7 @@ uint32_t Player::getItemTypeCount(uint16_t itemId, int32_t subType /*= -1*/) con

void Player::stashContainer(StashContainerList itemDict) {
StashItemList stashItemDict; // ItemID - Count
for (auto it_dict : itemDict) {
for (const auto &it_dict : itemDict) {
stashItemDict[(it_dict.first)->getID()] = it_dict.second;
}

Expand All @@ -3772,7 +3772,7 @@ void Player::stashContainer(StashContainerList itemDict) {
uint32_t totalStowed = 0;
std::ostringstream retString;
uint16_t refreshDepotSearchOnItem = 0;
for (auto stashIterator : itemDict) {
for (const auto &stashIterator : itemDict) {
uint16_t iteratorCID = (stashIterator.first)->getID();
if (g_game().internalRemoveItem(stashIterator.first, stashIterator.second) == RETURNVALUE_NOERROR) {
addItemOnStash(iteratorCID, stashIterator.second);
Expand Down Expand Up @@ -3889,7 +3889,7 @@ bool Player::removeItemCountById(uint16_t itemId, uint32_t itemAmount, bool remo

uint32_t amountToRemove = itemAmount;
// Check items from inventory
for (auto item : getAllInventoryItems()) {
for (const auto &item : getAllInventoryItems()) {
if (!item || item->getID() != itemId) {
continue;
}
Expand Down Expand Up @@ -4166,7 +4166,7 @@ void Player::postAddNotification(std::shared_ptr<Thing> thing, std::shared_ptr<C
}
}

for (std::shared_ptr<Container> container : containers) {
for (const std::shared_ptr<Container> &container : containers) {
autoCloseContainers(container);
}
}
Expand Down Expand Up @@ -4473,7 +4473,7 @@ void Player::updateItemsLight(bool internal /*=false*/) {
LightInfo curLight = item->getLightInfo();

if (curLight.level > maxLight.level) {
maxLight = std::move(curLight);
maxLight = curLight;
}
}
}
Expand Down Expand Up @@ -6153,7 +6153,7 @@ uint64_t Player::getMoney() const {
size_t i = 0;
while (i < containers.size()) {
std::shared_ptr<Container> container = containers[i++];
for (std::shared_ptr<Item> item : container->getItemList()) {
for (const std::shared_ptr<Item> &item : container->getItemList()) {
std::shared_ptr<Container> tmpContainer = item->getContainer();
if (tmpContainer) {
containers.push_back(tmpContainer);
Expand Down Expand Up @@ -6213,7 +6213,7 @@ size_t Player::getMaxDepotItems() const {

std::forward_list<std::shared_ptr<Condition>> Player::getMuteConditions() const {
std::forward_list<std::shared_ptr<Condition>> muteConditions;
for (std::shared_ptr<Condition> condition : conditions) {
for (const std::shared_ptr<Condition> &condition : conditions) {
if (condition->getTicks() <= 0) {
continue;
}
Expand Down Expand Up @@ -6419,7 +6419,7 @@ void sendStowItems(const std::shared_ptr<Item> &item, const std::shared_ptr<Item
}

if (auto container = stowItem->getContainer()) {
for (auto stowable_it : container->getStowableItems()) {
for (const auto &stowable_it : container->getStowableItems()) {
if ((stowable_it.first)->getID() == item->getID()) {
itemDict.push_back(stowable_it);
}
Expand Down Expand Up @@ -6452,7 +6452,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 +6463,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 +6473,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 All @@ -6497,14 +6497,14 @@ void Player::openPlayerContainers() {
if (itemContainer) {
auto cid = item->getAttribute<int64_t>(ItemAttribute_t::OPENCONTAINER);
if (cid > 0) {
openContainersList.emplace_back(std::make_pair(cid, itemContainer));
openContainersList.emplace_back(cid, itemContainer);
}
for (ContainerIterator it = itemContainer->iterator(); it.hasNext(); it.advance()) {
std::shared_ptr<Container> subContainer = (*it)->getContainer();
if (subContainer) {
auto subcid = (*it)->getAttribute<uint8_t>(ItemAttribute_t::OPENCONTAINER);
if (subcid > 0) {
openContainersList.emplace_back(std::make_pair(subcid, subContainer));
openContainersList.emplace_back(subcid, subContainer);
}
}
}
Expand Down Expand Up @@ -6710,7 +6710,7 @@ void Player::requestDepotItems() {
return;
}

for (std::shared_ptr<Item> locker : depotLocker->getItemList()) {
for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) {
std::shared_ptr<Container> c = locker->getContainer();
if (!c || c->empty()) {
continue;
Expand Down Expand Up @@ -6776,7 +6776,7 @@ void Player::requestDepotSearchItem(uint16_t itemId, uint8_t tier) {
return;
}

for (std::shared_ptr<Item> locker : depotLocker->getItemList()) {
for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) {
std::shared_ptr<Container> c = locker->getContainer();
if (!c || c->empty()) {
continue;
Expand Down Expand Up @@ -6813,7 +6813,7 @@ void Player::retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool
}

std::vector<std::shared_ptr<Item>> itemsVector;
for (std::shared_ptr<Item> locker : depotLocker->getItemList()) {
for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) {
std::shared_ptr<Container> c = locker->getContainer();
if (!c || c->empty() ||
// Retrieve from inbox.
Expand All @@ -6836,7 +6836,7 @@ void Player::retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool
}

ReturnValue ret = RETURNVALUE_NOERROR;
for (std::shared_ptr<Item> item : itemsVector) {
for (const std::shared_ptr<Item> &item : itemsVector) {
// First lets try to retrieve the item to the stash retrieve container.
if (g_game().tryRetrieveStashItems(static_self_cast<Player>(), item)) {
continue;
Expand Down Expand Up @@ -6882,7 +6882,7 @@ std::shared_ptr<Item> Player::getItemFromDepotSearch(uint16_t itemId, const Posi
}

uint8_t index = 0;
for (std::shared_ptr<Item> locker : depotLocker->getItemList()) {
for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) {
std::shared_ptr<Container> c = locker->getContainer();
if (!c || c->empty() || (c->isInbox() && pos.y != 0x21) || // From inbox.
(!c->isInbox() && pos.y != 0x20)) { // From depot.
Expand Down Expand Up @@ -6920,7 +6920,7 @@ std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_
std::shared_ptr<Container> container = containers[size];
size++;

for (std::shared_ptr<Item> item : container->getItemList()) {
for (const std::shared_ptr<Item> &item : container->getItemList()) {
std::shared_ptr<Container> lockerContainers = item->getContainer();
if (lockerContainers && !lockerContainers->empty()) {
containers.push_back(lockerContainers);
Expand Down Expand Up @@ -6977,7 +6977,7 @@ std::pair<std::vector<std::shared_ptr<Item>>, uint16_t> Player::getLockerItemsAn
std::vector<std::shared_ptr<Item>> lockerItems;
auto [itemVector, itemMap] = requestLockerItems(depotLocker, false, tier);
uint16_t totalCount = 0;
for (auto item : itemVector) {
for (const auto &item : itemVector) {
if (!item || item->getID() != itemId) {
continue;
}
Expand Down Expand Up @@ -7023,7 +7023,7 @@ bool Player::saySpell(

int32_t valueEmote = 0;
// Send to client
for (std::shared_ptr<Creature> spectator : spectators) {
for (const std::shared_ptr<Creature> &spectator : spectators) {
if (std::shared_ptr<Player> tmpPlayer = spectator->getPlayer()) {
if (g_configManager().getBoolean(EMOTE_SPELLS, __FUNCTION__)) {
valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE);
Expand All @@ -7039,7 +7039,7 @@ bool Player::saySpell(
}

// Execute lua event method
for (std::shared_ptr<Creature> spectator : spectators) {
for (const std::shared_ptr<Creature> &spectator : spectators) {
auto tmpPlayer = spectator->getPlayer();
if (!tmpPlayer) {
continue;
Expand Down Expand Up @@ -7683,7 +7683,7 @@ void Player::closeAllExternalContainers() {
}
}

for (std::shared_ptr<Container> container : containerToClose) {
for (const std::shared_ptr<Container> &container : containerToClose) {
autoCloseContainers(container);
}
}
Expand Down Expand Up @@ -7977,7 +7977,7 @@ void Player::sendLootMessage(const std::string &message) const {
if (auto partyLeader = party->getLeader()) {
partyLeader->sendTextMessage(MESSAGE_LOOT, message);
}
for (const auto partyMember : party->getMembers()) {
for (const auto &partyMember : party->getMembers()) {
if (partyMember) {
partyMember->sendTextMessage(MESSAGE_LOOT, message);
}
Expand Down

0 comments on commit 7b6ea0c

Please sign in to comment.