Skip to content

Commit

Permalink
fix: Fix receiving the wrong items upon selecting them
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyeriah committed Sep 25, 2024
1 parent d435c9d commit d05ba65
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/ZoneDifficulty.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ZoneDifficulty
std::string GetContentTypeString(uint32 type);
void AddMythicmodeScore(Map* map, uint32 type, uint32 score);
void DeductMythicmodeScore(Player* player, uint32 type, uint32 score);
void SendItem(Player* player, uint32 category, uint32 itemType, uint32 id);
void SendItem(Player* player, ZoneDifficultyRewardData data);
std::list<Unit*> GetTargetList(Unit* unit, uint32 entry, uint32 key);
void MythicmodeEvent(Unit* unit, uint32 entry, uint32 key);
bool HasNormalMode(int8 mode) { return (mode & MODE_NORMAL) == MODE_NORMAL; }
Expand Down
50 changes: 13 additions & 37 deletions src/mod_zone_difficulty_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,26 +580,16 @@ void ZoneDifficulty::DeductMythicmodeScore(Player* player, uint32 type, uint32 s
* @brief Send and item to the player using the data from sZoneDifficulty->Rewards.
*
* @param player The recipient of the mail.
* @param category The content level e.g. TYPE_HEROIC_TBC.
* @param itemType The type of the item e.g. ITEMTYPE_CLOTH.
* @param id the id in the vector.
* @param data The reward data e.g item entry, etc.
*/
void ZoneDifficulty::SendItem(Player* player, uint32 category, uint32 itemType, uint32 id)
void ZoneDifficulty::SendItem(Player* player, ZoneDifficultyRewardData data)
{
//Check if a full tier cleareance reward is meant (itemType 99)
ItemTemplate const* itemTemplate;
if (itemType == 99)
{
itemTemplate = sObjectMgr->GetItemTemplate(sZoneDifficulty->TierRewards[category].Entry);
}
else
{
itemTemplate = sObjectMgr->GetItemTemplate(sZoneDifficulty->Rewards[category][itemType][id].Entry);
}
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(data.Entry);

if (!itemTemplate)
{
LOG_ERROR("module", "MOD-ZONE-DIFFICULTY: itemTemplate could not be constructed in sZoneDifficulty->SendItem for category {}, itemType {}, id {}.", category, itemType, id);
LOG_ERROR("module", "MOD-ZONE-DIFFICULTY: itemTemplate could not be constructed in sZoneDifficulty->SendItem for item {}.", data.Entry);
return;
}

Expand All @@ -609,32 +599,18 @@ void ZoneDifficulty::SendItem(Player* player, uint32 category, uint32 itemType,
MailDraft draft(REWARD_MAIL_SUBJECT, REWARD_MAIL_BODY);
MailSender sender(MAIL_NORMAL, senderGuid, MAIL_STATIONERY_GM);
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
if (itemType == 99)
{
if (Item* item = Item::CreateItem(sZoneDifficulty->TierRewards[category].Entry, 1, player))
{
if (sZoneDifficulty->TierRewards[category].EnchantSlot != 0 && sZoneDifficulty->TierRewards[category].Enchant != 0)
{
item->SetEnchantment(EnchantmentSlot(sZoneDifficulty->TierRewards[category].EnchantSlot), sZoneDifficulty->TierRewards[category].Enchant, 0, 0, player->GetGUID());
player->ApplyEnchantment(item, EnchantmentSlot(sZoneDifficulty->TierRewards[category].EnchantSlot), true, true, true);
}
item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
draft.AddItem(item);
}
}
else

if (Item* item = Item::CreateItem(data.Entry, 1, player))
{
if (Item* item = Item::CreateItem(sZoneDifficulty->Rewards[category][itemType][id].Entry, 1, player))
if (data.EnchantSlot != 0 && data.Enchant != 0)
{
if (sZoneDifficulty->Rewards[category][itemType][id].EnchantSlot != 0 && sZoneDifficulty->Rewards[category][itemType][id].Enchant != 0)
{
item->SetEnchantment(EnchantmentSlot(sZoneDifficulty->Rewards[category][itemType][id].EnchantSlot), sZoneDifficulty->Rewards[category][itemType][id].Enchant, 0, 0, player->GetGUID());
player->ApplyEnchantment(item, EnchantmentSlot(sZoneDifficulty->Rewards[category][itemType][id].EnchantSlot), true, true, true);
}
item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
draft.AddItem(item);
item->SetEnchantment(EnchantmentSlot(data.EnchantSlot), data.Enchant, 0, 0, player->GetGUID());
player->ApplyEnchantment(item, EnchantmentSlot(data.EnchantSlot), true, true, true);
}
item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
draft.AddItem(item);
}

draft.SendMailTo(trans, MailReceiver(player, senderGuid), sender);
CharacterDatabase.CommitTransaction(trans);
}
Expand Down Expand Up @@ -1065,7 +1041,7 @@ void ZoneDifficulty::RewardItem(Player* player, uint8 category, uint8 itemType,

//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Sending item with category {}, itemType {}, counter {}", category, itemType, counter);
sZoneDifficulty->DeductMythicmodeScore(player, category, reward.Price);
sZoneDifficulty->SendItem(player, category, itemType, counter);
sZoneDifficulty->SendItem(player, reward);

if (player->GetSession())
if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(reward.Entry))
Expand Down
2 changes: 1 addition & 1 deletion src/mod_zone_difficulty_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript

//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Sending full tier clearance reward for category {}", category);
sZoneDifficulty->DeductMythicmodeScore(player, category, sZoneDifficulty->TierRewards[category].Price);
sZoneDifficulty->SendItem(player, category, 99, 0);
sZoneDifficulty->SendItem(player, sZoneDifficulty->TierRewards[category]);

return true;
}
Expand Down

0 comments on commit d05ba65

Please sign in to comment.