Jump to content

Improvement on mail_level_reward. Sending items


Guest ifilgud

Recommended Posts

Hi! I've modified MaNGOS so you can define some entries in mail_level_reward that allows you to send items to players automatically when the reach specific level. The already implemented system only allows sending mail templates to players without items.

This is useful for admins to reward players with whatever the want :)

Modifications:

SQL -> table mail_level_reward has now three more columns: 'item', 'subject' and 'text'.

If you want to send a custom mail with one item, you have to set field 'mailTemplateId' to 0, if you dont do that, the entry will be handled as normal templated mail. Once you set 'mailTemplateId' to 0, you have to provide a vaild itemId, raceMask, sender (choose a creature :)), mail subject and mail body.

I will also attach the core patch in addition to SQL patch, and I've also posted this on UDB forum :)

If anyone has suggestions, please post!

Edit: I dont know how to attach files (cant see the option!) so I will include the patches in the post:

diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index ba3ffde..b12fb26 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -8197,7 +8197,7 @@ void ObjectMgr::LoadMailLevelRewards()
    m_mailLevelRewardMap.clear();                           // for reload case

    uint32 count = 0;
-    QueryResult *result = WorldDatabase.Query("SELECT level, raceMask, mailTemplateId, senderEntry FROM mail_level_reward");
+    QueryResult *result = WorldDatabase.Query("SELECT level, raceMask, mailTemplateId, senderEntry, item, subject, text FROM mail_level_reward");

    if( !result )
    {
@@ -8222,6 +8222,9 @@ void ObjectMgr::LoadMailLevelRewards()
        uint32 raceMask       = fields[1].GetUInt32();
        uint32 mailTemplateId = fields[2].GetUInt32();
        uint32 senderEntry    = fields[3].GetUInt32();
+        uint32 item           = fields[4].GetUInt32();
+        std::string subject   = fields[5].GetCppString();
+        std::string text      = fields[6].GetCppString();

        if(level > MAX_LEVEL)
        {
@@ -8237,8 +8240,19 @@ void ObjectMgr::LoadMailLevelRewards()

        if(!sMailTemplateStore.LookupEntry(mailTemplateId))
        {
-            sLog.outErrorDb("Table `mail_level_reward` have invalid mailTemplateId (%u) for level %u that invalid not include any player races, ignoring.",mailTemplateId,level);
-            continue;
+            if (mailTemplateId == 0) // item must have valid id
+            {
+                if (!sItemStorage.LookupEntry<ItemPrototype >(item))
+                {
+                    sLog.outErrorDb("Table `mail_level_reward` have invalid mailTemplateId (%u) and item (%u) for level %u that invalid not include any player races, ignoring.",mailTemplateId,item,level);
+                    continue;
+                }
+            }
+            else
+            {
+                sLog.outErrorDb("Table `mail_level_reward` have invalid mailTemplateId (%u) for level %u that invalid not include any player races, ignoring.",mailTemplateId,level);
+                continue;
+            }
        }

        if(!GetCreatureTemplateStore(senderEntry))
@@ -8247,7 +8261,7 @@ void ObjectMgr::LoadMailLevelRewards()
            continue;
        }

-        m_mailLevelRewardMap[level].push_back(MailLevelReward(raceMask,mailTemplateId,senderEntry));
+        m_mailLevelRewardMap[level].push_back(MailLevelReward(raceMask,mailTemplateId,senderEntry,item,subject,text));

        ++count;
    }
diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h
index d2fac42..c11415e 100644
--- a/src/game/ObjectMgr.h
+++ b/src/game/ObjectMgr.h
@@ -226,12 +226,15 @@ struct PetLevelInfo

struct MailLevelReward
{
-    MailLevelReward() : raceMask(0), mailTemplateId(0), senderEntry(0) {}
-    MailLevelReward(uint32 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) {}
+    MailLevelReward() : raceMask(0), mailTemplateId(0), senderEntry(0), item(0), subject(NULL), text(NULL) {}
+    MailLevelReward(uint32 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry, uint32 _item, std::string _subject, std::string _text) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry), item(_item), subject(_subject), text(_text){}

    uint32 raceMask;
    uint32 mailTemplateId;
    uint32 senderEntry;
+    uint32 item;
+    std::string subject;
+    std::string text;
};

typedef std::list<MailLevelReward> MailLevelRewardList;
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index ea98e3d..41f7781 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -2627,7 +2627,17 @@ void Player::GiveLevel(uint32 level)
        pet->SynchronizeLevelWithOwner();

    if (MailLevelReward const* mailReward = sObjectMgr.GetMailLevelReward(level,getRaceMask()))
-        MailDraft(mailReward->mailTemplateId).SendMailTo(this,MailSender(MAIL_CREATURE,mailReward->senderEntry));
+    {
+        if (mailReward->mailTemplateId != 0) // Send mail with customItem instead of a template
+            MailDraft(mailReward->mailTemplateId).SendMailTo(this,MailSender(MAIL_CREATURE,mailReward->senderEntry));
+        else
+        {
+            MailDraft mail (mailReward->subject.c_str(), mailReward->text.c_str());
+            Item* item = Item::CreateItem(mailReward->item, 1);
+            mail.AddItem(item);
+            mail.SendMailTo(this,MailSender(MAIL_CREATURE,mailReward->senderEntry));
+        }
+    }

    GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_LEVEL);
}

ALTER TABLE mail_level_reward
ADD COLUMN `item` mediumint(8) unsigned NOT NULL DEFAULT '0',
ADD COLUMN `subject` varchar(30) DEFAULT NULL,
ADD COLUMN `text` varchar(100) DEFAULT NULL;

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use