mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-20 23:11:56 -04:00
Core/Misc: Add a bunch of examples for 67418a1aee
(cherry picked from commit 00223f3bee)
# Conflicts:
# src/server/game/Entities/Player/Player.cpp
# src/server/game/Globals/ObjectMgr.cpp
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include "Util.h"
|
||||
#include "WaypointDefines.h"
|
||||
#include "WaypointManager.h"
|
||||
#include "advstd.h"
|
||||
#include <algorithm>
|
||||
|
||||
#define TC_SAI_IS_BOOLEAN_VALID(e, value) \
|
||||
@@ -2030,7 +2031,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (std::ranges::none_of(InventoryTypesEquipable, [dbcItem](InventoryType inventoryType) { return inventoryType == dbcItem->InventoryType; }))
|
||||
if (!advstd::ranges::contains(InventoryTypesEquipable, dbcItem->InventoryType))
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "SmartScript: SMART_ACTION_EQUIP uses item {} (slot {}) not equipable in a hand for creature {}, skipped.", itemEntry, slot, e.entryOrGuid);
|
||||
return false;
|
||||
|
||||
@@ -77,11 +77,8 @@ uint32 AchievementMgr::GetAchievementPoints() const
|
||||
|
||||
std::vector<uint32> AchievementMgr::GetCompletedAchievementIds() const
|
||||
{
|
||||
std::vector<uint32> achievementIds;
|
||||
std::transform(_completedAchievements.begin(), _completedAchievements.end(), std::back_inserter(achievementIds), [](std::pair<uint32 const, CompletedAchievementData> const& achievement)
|
||||
{
|
||||
return achievement.first;
|
||||
});
|
||||
std::vector<uint32> achievementIds(_completedAchievements.size());
|
||||
std::ranges::transform(_completedAchievements, achievementIds.begin(), Trinity::Containers::MapKey);
|
||||
return achievementIds;
|
||||
}
|
||||
|
||||
|
||||
@@ -910,10 +910,10 @@ void AuctionHouseObject::AddAuction(CharacterDatabaseTransaction trans, AuctionP
|
||||
|
||||
if (ItemModifiedAppearanceEntry const* itemModifiedAppearance = auction.Items[0]->GetItemModifiedAppearance())
|
||||
{
|
||||
auto itr = std::ranges::find(bucket->ItemModifiedAppearanceId, itemModifiedAppearance->ID, &std::pair<uint32, uint32>::first);
|
||||
auto itr = std::ranges::find(bucket->ItemModifiedAppearanceId, itemModifiedAppearance->ID, Trinity::TupleElement<0>);
|
||||
|
||||
if (itr == bucket->ItemModifiedAppearanceId.end())
|
||||
itr = std::ranges::find(bucket->ItemModifiedAppearanceId, 0u, &std::pair<uint32, uint32>::first);
|
||||
itr = std::ranges::find(bucket->ItemModifiedAppearanceId, 0u, Trinity::TupleElement<0>);
|
||||
|
||||
if (itr != bucket->ItemModifiedAppearanceId.end())
|
||||
{
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace BattlePets
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::unordered_map<uint16 /*BreedID*/, std::unordered_map<BattlePetState /*state*/, int32 /*value*/, std::hash<std::underlying_type<BattlePetState>::type> >> _battlePetBreedStates;
|
||||
std::unordered_map<uint32 /*SpeciesID*/, std::unordered_map<BattlePetState /*state*/, int32 /*value*/, std::hash<std::underlying_type<BattlePetState>::type> >> _battlePetSpeciesStates;
|
||||
std::unordered_map<uint16 /*BreedID*/, std::unordered_map<BattlePetState /*state*/, int32 /*value*/>> _battlePetBreedStates;
|
||||
std::unordered_map<uint32 /*SpeciesID*/, std::unordered_map<BattlePetState /*state*/, int32 /*value*/>> _battlePetSpeciesStates;
|
||||
std::unordered_map<uint32 /*CreatureID*/, BattlePetSpeciesEntry const*> _battlePetSpeciesByCreature;
|
||||
std::unordered_map<uint32 /*SpellID*/, BattlePetSpeciesEntry const*> _battlePetSpeciesBySpell;
|
||||
std::unordered_map<uint32 /*SpeciesID*/, std::unordered_set<uint8 /*breed*/>> _availableBreedsPerSpecies;
|
||||
@@ -47,18 +47,14 @@ std::unordered_map<uint32 /*SpeciesID*/, uint8 /*quality*/> _defaultQualityPerSp
|
||||
|
||||
void BattlePet::CalculateStats()
|
||||
{
|
||||
float health = 0.0f;
|
||||
float power = 0.0f;
|
||||
float speed = 0.0f;
|
||||
|
||||
// get base breed stats
|
||||
auto breedState = _battlePetBreedStates.find(PacketInfo.Breed);
|
||||
if (breedState == _battlePetBreedStates.end()) // non existing breed id
|
||||
return;
|
||||
|
||||
health = breedState->second[STATE_STAT_STAMINA];
|
||||
power = breedState->second[STATE_STAT_POWER];
|
||||
speed = breedState->second[STATE_STAT_SPEED];
|
||||
float health = breedState->second[STATE_STAT_STAMINA];
|
||||
float power = breedState->second[STATE_STAT_POWER];
|
||||
float speed = breedState->second[STATE_STAT_SPEED];
|
||||
|
||||
// modify stats depending on species - not all pets have this
|
||||
auto speciesState = _battlePetSpeciesStates.find(PacketInfo.Species);
|
||||
@@ -538,7 +534,7 @@ void BattlePetMgr::ModifyName(ObjectGuid guid, std::string const& name, std::uni
|
||||
summonedBattlePet->SetBattlePetCompanionNameTimestamp(pet->NameTimestamp);
|
||||
}
|
||||
|
||||
bool BattlePetMgr::IsPetInSlot(ObjectGuid guid)
|
||||
bool BattlePetMgr::IsPetInSlot(ObjectGuid guid) const
|
||||
{
|
||||
for (WorldPackets::BattlePet::BattlePetSlot const& slot : _slots)
|
||||
if (slot.Pet.Guid == guid)
|
||||
@@ -549,21 +545,21 @@ bool BattlePetMgr::IsPetInSlot(ObjectGuid guid)
|
||||
|
||||
uint8 BattlePetMgr::GetPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const
|
||||
{
|
||||
return uint8(std::count_if(_pets.begin(), _pets.end(), [battlePetSpecies, ownerGuid](std::pair<uint64 const, BattlePet> const& pet)
|
||||
return uint8(std::ranges::count_if(_pets, [battlePetSpecies, ownerGuid](BattlePet const& pet)
|
||||
{
|
||||
if (pet.second.PacketInfo.Species != battlePetSpecies->ID)
|
||||
if (pet.PacketInfo.Species != battlePetSpecies->ID)
|
||||
return false;
|
||||
|
||||
if (pet.second.SaveInfo == BATTLE_PET_REMOVED)
|
||||
if (pet.SaveInfo == BATTLE_PET_REMOVED)
|
||||
return false;
|
||||
|
||||
if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::NotAccountWide))
|
||||
if (!ownerGuid.IsEmpty() && pet.second.PacketInfo.OwnerInfo)
|
||||
if (pet.second.PacketInfo.OwnerInfo->Guid != ownerGuid)
|
||||
if (!ownerGuid.IsEmpty() && pet.PacketInfo.OwnerInfo)
|
||||
if (pet.PacketInfo.OwnerInfo->Guid != ownerGuid)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}));
|
||||
}, Trinity::Containers::MapValue));
|
||||
}
|
||||
|
||||
bool BattlePetMgr::HasMaxPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const
|
||||
@@ -576,10 +572,10 @@ bool BattlePetMgr::HasMaxPetCount(BattlePetSpeciesEntry const* battlePetSpecies,
|
||||
uint32 BattlePetMgr::GetPetUniqueSpeciesCount() const
|
||||
{
|
||||
std::set<uint32> speciesIds;
|
||||
std::transform(_pets.begin(), _pets.end(), std::inserter(speciesIds, speciesIds.end()), [](std::pair<uint64 const, BattlePet> const& pet)
|
||||
std::ranges::transform(_pets, std::inserter(speciesIds, speciesIds.end()), [](BattlePet const& pet)
|
||||
{
|
||||
return pet.second.PacketInfo.Species;
|
||||
});
|
||||
return pet.PacketInfo.Species;
|
||||
}, Trinity::Containers::MapValue);
|
||||
return speciesIds.size();
|
||||
}
|
||||
|
||||
@@ -889,7 +885,7 @@ void BattlePetMgr::SendJournal()
|
||||
battlePetJournal.Pets.push_back(std::ref(pet.second.PacketInfo));
|
||||
|
||||
battlePetJournal.Slots.reserve(_slots.size());
|
||||
std::transform(_slots.begin(), _slots.end(), std::back_inserter(battlePetJournal.Slots), [](WorldPackets::BattlePet::BattlePetSlot& slot) { return std::ref(slot); });
|
||||
std::ranges::transform(_slots, std::back_inserter(battlePetJournal.Slots), [](WorldPackets::BattlePet::BattlePetSlot& slot) { return std::ref(slot); });
|
||||
_owner->SendPacket(battlePetJournal.Write());
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ public:
|
||||
void RemovePet(ObjectGuid guid);
|
||||
void ClearFanfare(ObjectGuid guid);
|
||||
void ModifyName(ObjectGuid guid, std::string const& name, std::unique_ptr<DeclinedName> declinedName);
|
||||
bool IsPetInSlot(ObjectGuid guid);
|
||||
bool IsPetInSlot(ObjectGuid guid) const;
|
||||
|
||||
uint8 GetPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const;
|
||||
bool HasMaxPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const;
|
||||
|
||||
@@ -2102,7 +2102,8 @@ MapDifficultyEntry const* DB2Manager::GetDefaultMapDifficulty(uint32 mapId, Diff
|
||||
|
||||
// first find any valid difficulty
|
||||
auto foundDifficulty = std::ranges::find_if(difficultiesForMap->begin(), difficultyEnd,
|
||||
[](std::pair<uint32 const, MapDifficultyEntry const*> const& p) { return sDifficultyStore.HasRecord(p.first); });
|
||||
[](uint32 difficultyId) { return sDifficultyStore.HasRecord(difficultyId); },
|
||||
Trinity::Containers::MapKey);
|
||||
|
||||
if (foundDifficulty == difficultyEnd)
|
||||
return nullptr; // nothing valid was found
|
||||
|
||||
@@ -312,7 +312,7 @@ bool CreatureGroup::CanLeaderStartMoving() const
|
||||
|
||||
bool CreatureGroup::HasAliveMembers() const
|
||||
{
|
||||
return std::ranges::any_of(_members, [](Creature const* member) { return member->IsAlive(); }, &MembersMap::value_type::first);
|
||||
return std::ranges::any_of(_members, [](Creature const* member) { return member->IsAlive(); }, Trinity::Containers::MapKey);
|
||||
}
|
||||
|
||||
bool CreatureGroup::LeaderHasStringId(std::string_view id) const
|
||||
|
||||
@@ -3042,7 +3042,7 @@ void Player::RemoveSpell(uint32 spell_id, bool disabled /*= false*/, bool learn_
|
||||
if (!learnNode->Active)
|
||||
return false;
|
||||
return HasSpell(learnNode->SourceSpell);
|
||||
}, &SpellLearnedBySpellMap::value_type::second);
|
||||
}, Trinity::Containers::MapValue);
|
||||
|
||||
if (hasOtherSpellTeachingThis)
|
||||
continue;
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
#include "VMapManager2.h"
|
||||
#include "Vehicle.h"
|
||||
#include "World.h"
|
||||
#include "advstd.h"
|
||||
#include <G3D/g3dmath.h>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
@@ -1549,7 +1550,7 @@ void ObjectMgr::LoadEquipmentTemplates()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::ranges::none_of(InventoryTypesEquipable, [dbcItem](InventoryType inventoryType) { return inventoryType == dbcItem->InventoryType; }))
|
||||
if (!advstd::ranges::contains(InventoryTypesEquipable, dbcItem->InventoryType))
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Item (ID={}) in creature_equip_template.ItemID{} for CreatureID = {} and ID = {} is not equipable in a hand, forced to 0.",
|
||||
equipmentInfo.Items[i].ItemId, i + 1, entry, id);
|
||||
|
||||
@@ -216,10 +216,7 @@ Optional<LootSlotType> LootItem::GetUiTypeForPlayer(Player const* player, Loot c
|
||||
{
|
||||
if (NotNormalLootItemList const* ffaItems = Trinity::Containers::MapGetValuePtr(loot.GetPlayerFFAItems(), player->GetGUID()))
|
||||
{
|
||||
auto ffaItemItr = std::ranges::find_if(*ffaItems, [&](NotNormalLootItem const& ffaItem)
|
||||
{
|
||||
return ffaItem.LootListId == LootListId;
|
||||
});
|
||||
auto ffaItemItr = std::ranges::find(*ffaItems, LootListId, &NotNormalLootItem::LootListId);
|
||||
if (ffaItemItr != ffaItems->end() && !ffaItemItr->is_looted)
|
||||
return loot.GetLootMethod() == FREE_FOR_ALL ? LOOT_SLOT_TYPE_OWNER : LOOT_SLOT_TYPE_ALLOW_LOOT;
|
||||
}
|
||||
@@ -1092,7 +1089,7 @@ bool Loot::hasItemFor(Player const* player) const
|
||||
return true;
|
||||
|
||||
if (NotNormalLootItemList const* ffaItems = Trinity::Containers::MapGetValuePtr(GetPlayerFFAItems(), player->GetGUID()))
|
||||
if (std::ranges::any_of(*ffaItems, std::identity(), &NotNormalLootItem::is_looted))
|
||||
if (std::ranges::any_of(*ffaItems, &NotNormalLootItem::is_looted))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -213,7 +213,7 @@ uint32 LootStore::LoadAndCollectLootIds(LootIdSet& lootIdSet)
|
||||
{
|
||||
uint32 count = LoadLootTable();
|
||||
|
||||
std::ranges::transform(m_LootTemplates, std::inserter(lootIdSet, lootIdSet.end()), &LootTemplateMap::value_type::first);
|
||||
std::ranges::transform(m_LootTemplates, std::inserter(lootIdSet, lootIdSet.end()), Trinity::Containers::MapKey);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -9303,10 +9303,7 @@ void SelectRandomInjuredTargets(std::list<WorldObject*>& targets, size_t maxTarg
|
||||
return std::make_pair(target, negativePoints);
|
||||
});
|
||||
|
||||
std::sort(tempTargets.begin(), tempTargets.end(), [](std::pair<WorldObject*, int32> const& left, std::pair<WorldObject*, int32> const& right)
|
||||
{
|
||||
return left.second < right.second;
|
||||
});
|
||||
std::ranges::sort(tempTargets, {}, Trinity::TupleElement<1>);
|
||||
|
||||
std::size_t foundTargets = 0;
|
||||
for (std::ptrdiff_t countForPriority : countsByPriority)
|
||||
@@ -9324,7 +9321,7 @@ void SelectRandomInjuredTargets(std::list<WorldObject*>& targets, size_t maxTarg
|
||||
}
|
||||
|
||||
targets.resize(maxTargets);
|
||||
std::transform(tempTargets.begin(), tempTargets.begin() + maxTargets, targets.begin(), std::mem_fn(&std::pair<WorldObject*, int32>::first));
|
||||
std::ranges::transform(tempTargets.begin(), tempTargets.begin() + maxTargets, targets.begin(), Trinity::TupleElement<0>);
|
||||
}
|
||||
} //namespace Trinity
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ EndScriptData */
|
||||
#include "Language.h"
|
||||
#include "Loot.h"
|
||||
#include "Map.h"
|
||||
#include "MapUtils.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "ObjectAccessor.h"
|
||||
@@ -1313,7 +1314,7 @@ public:
|
||||
|
||||
Loot const* loot = creatureTarget->m_loot.get();
|
||||
if ((!loot || loot->isLooted())
|
||||
&& !std::ranges::count_if(creatureTarget->m_personalLoot, std::not_fn(&Loot::isLooted), &std::unordered_map<ObjectGuid, std::unique_ptr<Loot>>::value_type::second))
|
||||
&& !std::ranges::count_if(creatureTarget->m_personalLoot, std::not_fn(&Loot::isLooted), Trinity::Containers::MapValue))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_NOT_DEAD_OR_NO_LOOT, creatureTarget->GetName().c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
|
||||
Reference in New Issue
Block a user