Core/Misc: converted more raw pointers to smart pointers
This commit is contained in:
1 parent
8340960a7d
commit
4f08f34e26
5 files changed
+95
-93
No files matched your search
@@ -76,45 +76,43 @@ void AddItemsSetItem(Player* player, Item* item)
|
||||
|
||||
ItemSetEffect* eff = nullptr;
|
||||
|
||||
for (size_t x = 0; x < player->ItemSetEff.size(); ++x)
|
||||
// Check for existing effects (equipping an additional set item)
|
||||
for (std::unique_ptr<ItemSetEffect> const& itemSetEffect : player->ItemSetEff)
|
||||
{
|
||||
if (player->ItemSetEff[x] && player->ItemSetEff[x]->setid == setid)
|
||||
{
|
||||
eff = player->ItemSetEff[x];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!eff)
|
||||
{
|
||||
eff = new ItemSetEffect();
|
||||
eff->setid = setid;
|
||||
|
||||
size_t x = 0;
|
||||
for (; x < player->ItemSetEff.size(); ++x)
|
||||
if (!player->ItemSetEff[x])
|
||||
break;
|
||||
|
||||
if (x < player->ItemSetEff.size())
|
||||
player->ItemSetEff[x]=eff;
|
||||
else
|
||||
player->ItemSetEff.push_back(eff);
|
||||
}
|
||||
|
||||
++eff->item_count;
|
||||
|
||||
for (uint32 x = 0; x < MAX_ITEM_SET_SPELLS; ++x)
|
||||
{
|
||||
if (!set->SetSpellID[x])
|
||||
if (!itemSetEffect || itemSetEffect->setid != setid)
|
||||
continue;
|
||||
|
||||
//not enough for spell
|
||||
if (set->SetThreshold[x] > eff->item_count)
|
||||
eff = itemSetEffect.get();
|
||||
break;
|
||||
}
|
||||
|
||||
// No effect found, create new one (first set item equipped)
|
||||
if (!eff)
|
||||
{
|
||||
std::unique_ptr<ItemSetEffect> itemSetEffect = std::make_unique<ItemSetEffect>();
|
||||
itemSetEffect->setid = setid;
|
||||
|
||||
eff = itemSetEffect.get();
|
||||
|
||||
player->ItemSetEff.push_back(std::move(itemSetEffect));
|
||||
}
|
||||
|
||||
// increment the amount of set items
|
||||
++eff->item_count;
|
||||
|
||||
for (uint8 i = 0; i < MAX_ITEM_SET_SPELLS; ++i)
|
||||
{
|
||||
// Check for a set spell Id
|
||||
if (!set->SetSpellID[i])
|
||||
continue;
|
||||
|
||||
// Check if we are wearing enough set pieces to for the bonus
|
||||
if (set->SetThreshold[i] > eff->item_count)
|
||||
continue;
|
||||
|
||||
uint32 z = 0;
|
||||
for (; z < MAX_ITEM_SET_SPELLS; ++z)
|
||||
if (eff->spells[z] && eff->spells[z]->Id == set->SetSpellID[x])
|
||||
if (eff->spells[z] && eff->spells[z]->Id == set->SetSpellID[i])
|
||||
break;
|
||||
|
||||
if (z < MAX_ITEM_SET_SPELLS)
|
||||
@@ -125,10 +123,10 @@ void AddItemsSetItem(Player* player, Item* item)
|
||||
{
|
||||
if (!eff->spells[y]) // free slot
|
||||
{
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(set->SetSpellID[x]);
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(set->SetSpellID[i]);
|
||||
if (!spellInfo)
|
||||
{
|
||||
TC_LOG_ERROR("entities.player.items", "WORLD: unknown spell id %u in items set %u effects", set->SetSpellID[x], setid);
|
||||
TC_LOG_ERROR("entities.player.items", "WORLD: unknown spell id %u in items set %u effects", set->SetSpellID[i], setid);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -141,7 +139,7 @@ void AddItemsSetItem(Player* player, Item* item)
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveItemsSetItem(Player*player, ItemTemplate const* proto)
|
||||
void RemoveItemsSetItem(Player* player, ItemTemplate const* proto)
|
||||
{
|
||||
uint32 setid = proto->GetItemSet();
|
||||
|
||||
@@ -154,14 +152,17 @@ void RemoveItemsSetItem(Player*player, ItemTemplate const* proto)
|
||||
}
|
||||
|
||||
ItemSetEffect* eff = nullptr;
|
||||
size_t setindex = 0;
|
||||
for (; setindex < player->ItemSetEff.size(); setindex++)
|
||||
size_t setIndex = 0;
|
||||
for (std::unique_ptr<ItemSetEffect> const& itemSetEffect : player->ItemSetEff)
|
||||
{
|
||||
if (player->ItemSetEff[setindex] && player->ItemSetEff[setindex]->setid == setid)
|
||||
if (itemSetEffect->setid != setid)
|
||||
{
|
||||
eff = player->ItemSetEff[setindex];
|
||||
break;
|
||||
++setIndex;
|
||||
continue;
|
||||
}
|
||||
|
||||
eff = itemSetEffect.get();
|
||||
break;
|
||||
}
|
||||
|
||||
// can be in case now enough skill requirement for set appling but set has been appliend when skill requirement not enough
|
||||
@@ -191,11 +192,10 @@ void RemoveItemsSetItem(Player*player, ItemTemplate const* proto)
|
||||
}
|
||||
}
|
||||
|
||||
if (!eff->item_count) //all items of a set were removed
|
||||
if (!eff->item_count) // all items of a set were removed
|
||||
{
|
||||
ASSERT(eff == player->ItemSetEff[setindex]);
|
||||
delete eff;
|
||||
player->ItemSetEff[setindex] = nullptr;
|
||||
ASSERT(eff == player->ItemSetEff[setIndex].get());
|
||||
player->ItemSetEff.erase(player->ItemSetEff.begin() + setIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -373,6 +373,7 @@ void Pet::SavePetToDB(PetSaveMode mode)
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
PlayerPetData* playerPetData = GetOwner()->GetPlayerPetDataById(m_charmInfo->GetPetNumber());
|
||||
std::unique_ptr<PlayerPetData> newPlayerPetData; // used when creating a new pet
|
||||
|
||||
// save as new if no data for Pet in PlayerPetDataStore
|
||||
if (mode < PET_SAVE_NEW_PET && !playerPetData)
|
||||
@@ -385,7 +386,8 @@ void Pet::SavePetToDB(PetSaveMode mode)
|
||||
if (slot)
|
||||
{
|
||||
SetSlot(*slot);
|
||||
playerPetData = new PlayerPetData();
|
||||
newPlayerPetData = std::make_unique<PlayerPetData>();
|
||||
playerPetData = newPlayerPetData.get();
|
||||
}
|
||||
else
|
||||
mode = PET_SAVE_AS_DELETED;
|
||||
@@ -455,9 +457,8 @@ void Pet::SavePetToDB(PetSaveMode mode)
|
||||
playerPetData->SummonSpellId = GetUInt32Value(UNIT_CREATED_BY_SPELL);
|
||||
playerPetData->Type = getPetType();
|
||||
|
||||
if (mode == PET_SAVE_NEW_PET)
|
||||
GetOwner()->AddToPlayerPetDataStore(playerPetData);
|
||||
|
||||
if (mode == PET_SAVE_NEW_PET && newPlayerPetData)
|
||||
GetOwner()->AddToPlayerPetDataStore(std::move(newPlayerPetData));
|
||||
}
|
||||
// delete
|
||||
else
|
||||
|
||||
@@ -368,12 +368,6 @@ Player::~Player()
|
||||
for (ItemMap::iterator iter = mMitems.begin(); iter != mMitems.end(); ++iter)
|
||||
delete iter->second; //if item is duplicated... then server may crash ... but that item should be deallocated
|
||||
|
||||
for (size_t x = 0; x < ItemSetEff.size(); x++)
|
||||
delete ItemSetEff[x];
|
||||
|
||||
for (uint8 i = 0; i < PlayerPetDataStore.size(); i++)
|
||||
delete PlayerPetDataStore[i];
|
||||
|
||||
ClearResurrectRequestData();
|
||||
|
||||
sWorld->DecreasePlayerCount();
|
||||
@@ -7794,20 +7788,18 @@ void Player::UpdateEquipSpellsAtFormChange()
|
||||
}
|
||||
|
||||
// item set bonuses not dependent from item broken state
|
||||
for (size_t setindex = 0; setindex < ItemSetEff.size(); ++setindex)
|
||||
for (std::unique_ptr<ItemSetEffect> const& itemEffect : ItemSetEff)
|
||||
{
|
||||
ItemSetEffect* eff = ItemSetEff[setindex];
|
||||
if (!eff)
|
||||
if (!itemEffect)
|
||||
continue;
|
||||
|
||||
for (uint32 y = 0; y < MAX_ITEM_SET_SPELLS; ++y)
|
||||
for (uint8 i = 0; i < MAX_ITEM_SET_SPELLS; ++i)
|
||||
{
|
||||
SpellInfo const* spellInfo = eff->spells[y];
|
||||
if (!spellInfo)
|
||||
continue;
|
||||
|
||||
ApplyEquipSpell(spellInfo, nullptr, false, true); // remove spells that not fit to form
|
||||
ApplyEquipSpell(spellInfo, nullptr, true, true); // add spells that fit form but not active
|
||||
if (SpellInfo const* spellInfo = itemEffect->spells[i])
|
||||
{
|
||||
ApplyEquipSpell(spellInfo, nullptr, false, true); // remove spells that not fit to form
|
||||
ApplyEquipSpell(spellInfo, nullptr, true, true); // add spells that fit form but not active
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17804,7 +17796,7 @@ void Player::LoadPetsFromDB(PreparedQueryResult result)
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
PlayerPetData* playerPetData = new PlayerPetData();
|
||||
std::unique_ptr<PlayerPetData> playerPetData = std::make_unique<PlayerPetData>();
|
||||
|
||||
uint8 slot = fields[7].GetUInt8();
|
||||
uint32 petId = fields[0].GetUInt32();
|
||||
@@ -17833,43 +17825,51 @@ void Player::LoadPetsFromDB(PreparedQueryResult result)
|
||||
playerPetData->SummonSpellId = fields[15].GetUInt32();
|
||||
playerPetData->Type = PetType(fields[16].GetUInt8());
|
||||
|
||||
PlayerPetDataStore.push_back(playerPetData);
|
||||
PlayerPetDataStore.push_back(std::move(playerPetData));
|
||||
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
PlayerPetData* Player::GetPlayerPetDataById(uint32 petId)
|
||||
{
|
||||
for (PlayerPetData* p : PlayerPetDataStore)
|
||||
if (p->PetId == petId)
|
||||
return p;
|
||||
for (std::unique_ptr<PlayerPetData> const& petData : PlayerPetDataStore)
|
||||
{
|
||||
if (petData->PetId == petId)
|
||||
return petData.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PlayerPetData* Player::GetPlayerPetDataBySlot(uint8 slot)
|
||||
{
|
||||
for (PlayerPetData* p : PlayerPetDataStore)
|
||||
if (p->Slot == slot)
|
||||
return p;
|
||||
for (std::unique_ptr<PlayerPetData> const& petData : PlayerPetDataStore)
|
||||
{
|
||||
if (petData->Slot == slot)
|
||||
return petData.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PlayerPetData* Player::GetPlayerPetDataByCreatureId(uint32 creatureId)
|
||||
{
|
||||
for (PlayerPetData* p : PlayerPetDataStore)
|
||||
if (p->CreatureId == creatureId)
|
||||
return p;
|
||||
for (std::unique_ptr<PlayerPetData> const& petData : PlayerPetDataStore)
|
||||
{
|
||||
if (petData->CreatureId == creatureId)
|
||||
return petData.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PlayerPetData* Player::GetPlayerPetDataCurrent()
|
||||
{
|
||||
for (PlayerPetData* p : PlayerPetDataStore)
|
||||
if (p->Active == true)
|
||||
return p;
|
||||
for (std::unique_ptr<PlayerPetData> const& petData : PlayerPetDataStore)
|
||||
{
|
||||
if (petData->Active)
|
||||
return petData.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -17878,9 +17878,11 @@ Optional<uint8> Player::GetFirstUnusedActivePetSlot()
|
||||
{
|
||||
std::set<uint8> unusedActiveSlot = { 0, 1, 2, 3, 4 }; //unfiltered
|
||||
|
||||
for (PlayerPetData* p : PlayerPetDataStore)
|
||||
if (unusedActiveSlot.find(p->Slot) != unusedActiveSlot.end())
|
||||
unusedActiveSlot.erase(p->Slot);
|
||||
for (std::unique_ptr<PlayerPetData> const& petData : PlayerPetDataStore)
|
||||
{
|
||||
if (unusedActiveSlot.find(petData->Slot) != unusedActiveSlot.end())
|
||||
unusedActiveSlot.erase(petData->Slot);
|
||||
}
|
||||
|
||||
if (!unusedActiveSlot.empty())
|
||||
return *unusedActiveSlot.begin();
|
||||
@@ -17895,9 +17897,11 @@ Optional<uint8> Player::GetFirstUnusedPetSlot()
|
||||
for (uint8 i = 0; i < PET_SLOT_LAST; i++) // 4 MAX StableSlots (256 theoretically)
|
||||
unusedSlot.insert(i);
|
||||
|
||||
for (PlayerPetData* p : PlayerPetDataStore)
|
||||
if (unusedSlot.find(p->Slot) != unusedSlot.end())
|
||||
unusedSlot.erase(p->Slot);
|
||||
for (std::unique_ptr<PlayerPetData> const& petData : PlayerPetDataStore)
|
||||
{
|
||||
if (unusedSlot.find(petData->Slot) != unusedSlot.end())
|
||||
unusedSlot.erase(petData->Slot);
|
||||
}
|
||||
|
||||
if (!unusedSlot.empty())
|
||||
return *unusedSlot.begin();
|
||||
@@ -17910,16 +17914,13 @@ void Player::DeleteFromPlayerPetDataStore(uint32 petNumber)
|
||||
for (uint8 i = 0; i < PlayerPetDataStore.size(); ++i)
|
||||
{
|
||||
if (PlayerPetDataStore[i]->PetId == petNumber)
|
||||
{
|
||||
delete PlayerPetDataStore[i];
|
||||
PlayerPetDataStore.erase(PlayerPetDataStore.begin() + (i--));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::AddToPlayerPetDataStore(PlayerPetData* playerPetData)
|
||||
void Player::AddToPlayerPetDataStore(std::unique_ptr<PlayerPetData> playerPetData)
|
||||
{
|
||||
PlayerPetDataStore.push_back(playerPetData);
|
||||
PlayerPetDataStore.push_back(std::move(playerPetData));
|
||||
}
|
||||
|
||||
void Player::_LoadQuestStatus(PreparedQueryResult result)
|
||||
|
||||
@@ -2088,7 +2088,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
|
||||
void SendAurasForTarget(Unit* target) const;
|
||||
|
||||
std::unique_ptr<PlayerMenu> PlayerTalkClass;
|
||||
std::vector<ItemSetEffect*> ItemSetEff;
|
||||
std::vector<std::unique_ptr<ItemSetEffect>> ItemSetEff;
|
||||
|
||||
void SendLoot(ObjectGuid guid, LootType loot_type);
|
||||
void SendLootError(ObjectGuid guid, LootError error) const;
|
||||
@@ -2416,7 +2416,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
|
||||
Optional<uint8> GetFirstUnusedActivePetSlot();
|
||||
Optional<uint8> GetFirstUnusedPetSlot();
|
||||
void DeleteFromPlayerPetDataStore(uint32 petNumber);
|
||||
void AddToPlayerPetDataStore(PlayerPetData* playerPetData);
|
||||
void AddToPlayerPetDataStore(std::unique_ptr<PlayerPetData> playerPetData);
|
||||
|
||||
protected:
|
||||
// Gamemaster whisper whitelist
|
||||
@@ -2784,7 +2784,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
|
||||
|
||||
std::unique_ptr<Archaeology> _archaeology;
|
||||
|
||||
std::vector<PlayerPetData*> PlayerPetDataStore;
|
||||
std::vector<std::unique_ptr<PlayerPetData>> PlayerPetDataStore;
|
||||
|
||||
TimeTrackerSmall m_petScalingSynchTimer;
|
||||
};
|
||||
|
||||
@@ -325,7 +325,7 @@ void WorldSession::SendStablePet(ObjectGuid guid)
|
||||
data << uint8(_player->PlayerPetDataStore.size());
|
||||
data << uint8(PET_SLOT_LAST_STABLE_SLOT); // Stable Slots
|
||||
|
||||
for (PlayerPetData* p : _player->PlayerPetDataStore)
|
||||
for (std::unique_ptr<PlayerPetData> const& p : _player->PlayerPetDataStore)
|
||||
{
|
||||
uint32 petSlot = p->Slot;
|
||||
uint8 flags = PET_STABLE_ACTIVE;
|
||||
|
||||
Reference in new issue
Block a user