Created
July 25, 2010 01:06
-
-
Save Emtec/489162 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/sql/updates/10205_a_mangos_mail_template.sql b/sql/updates/10205_a_mangos_mail_template.sql | |
new file mode 100644 | |
index 0000000..06f302e | |
--- /dev/null | |
+++ b/sql/updates/10205_a_mangos_mail_template.sql | |
@@ -0,0 +1,16 @@ | |
+CREATE TABLE IF NOT EXISTS `mail_template` ( | |
+ `id` mediumint(8) NOT NULL, | |
+ `title` text character set utf8 NOT NULL, | |
+ `text` text character set utf8 NOT NULL, | |
+ `item1` mediumint(8) NOT NULL default '0', | |
+ `item1_count` mediumint(8) NOT NULL default '0', | |
+ `item2` mediumint(8) NOT NULL default '0', | |
+ `item2_count` mediumint(8) NOT NULL default '0', | |
+ `item3` mediumint(8) NOT NULL default '0', | |
+ `item3_count` mediumint(8) NOT NULL default '0', | |
+ `item4` mediumint(8) NOT NULL default '0', | |
+ `item4_count` mediumint(8) NOT NULL default '0', | |
+ `item5` mediumint(8) NOT NULL default '0', | |
+ `item5_count` mediumint(8) NOT NULL default '0', | |
+ PRIMARY KEY (`id`) | |
+) ENGINE=MyISAM DEFAULT CHARSET=latin1; | |
\ No newline at end of file | |
diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp | |
index eb6ba1b..a52b257 100644 | |
--- a/src/game/BattleGround.cpp | |
+++ b/src/game/BattleGround.cpp | |
@@ -951,7 +951,7 @@ void BattleGround::SendRewardMarkByMail(Player *plr,uint32 mark, uint32 count) | |
std::string textFormat = plr->GetSession()->GetMangosString(LANG_BG_MARK_BY_MAIL); | |
char textBuf[300]; | |
snprintf(textBuf, 300, textFormat.c_str(), GetName(), GetName()); | |
- | |
+ | |
MailDraft(subject, textBuf) | |
.AddItem(markItem) | |
.SendMailTo(plr, MailSender(MAIL_CREATURE, bmEntry)); | |
diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp | |
index 8dc9148..f736448 100644 | |
--- a/src/game/Chat.cpp | |
+++ b/src/game/Chat.cpp | |
@@ -464,6 +464,7 @@ ChatCommand * ChatHandler::getCommandTable() | |
{ "locales_quest", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLocalesQuestCommand, "", NULL }, | |
{ "mail_level_reward", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadMailLevelRewardCommand, "", NULL }, | |
{ "mail_loot_template", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLootTemplatesMailCommand, "", NULL }, | |
+ { "mail_template" , SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadMailTemplateCommand, "", NULL }, | |
{ "mangos_string", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadMangosStringCommand, "", NULL }, | |
{ "milling_loot_template", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLootTemplatesMillingCommand, "", NULL }, | |
{ "npc_gossip", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadNpcGossipCommand, "", NULL }, | |
diff --git a/src/game/Chat.h b/src/game/Chat.h | |
index b82899e..6574103 100644 | |
--- a/src/game/Chat.h | |
+++ b/src/game/Chat.h | |
@@ -377,6 +377,7 @@ class ChatHandler | |
bool HandleReloadLootTemplatesSkinningCommand(const char* args); | |
bool HandleReloadLootTemplatesSpellCommand(const char* args); | |
bool HandleReloadMailLevelRewardCommand(const char* args); | |
+ bool HandleReloadMailTemplateCommand(const char* args); | |
bool HandleReloadMangosStringCommand(const char* args); | |
bool HandleReloadNpcGossipCommand(const char* args); | |
bool HandleReloadNpcTrainerCommand(const char* args); | |
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp | |
index d3bcbb8..5e74a12 100644 | |
--- a/src/game/Level3.cpp | |
+++ b/src/game/Level3.cpp | |
@@ -197,6 +197,7 @@ bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/) | |
HandleReloadLocalesGameobjectCommand("a"); | |
HandleReloadLocalesGossipMenuOptionCommand("a"); | |
HandleReloadLocalesItemCommand("a"); | |
+ HandleReloadMailTemplateCommand("a"); | |
HandleReloadLocalesNpcTextCommand("a"); | |
HandleReloadLocalesPageTextCommand("a"); | |
HandleReloadLocalesPointsOfInterestCommand("a"); | |
@@ -851,6 +852,14 @@ bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/) | |
return true; | |
} | |
+bool ChatHandler::HandleReloadMailTemplateCommand(const char* /*args*/) | |
+{ | |
+ sLog.outString(" Re-Loading Mail Template ..."); | |
+ sObjectMgr.LoadMailTemplate(); | |
+ SendGlobalSysMessage("DB table `mail_template` reloaded."); | |
+ return true; | |
+} | |
+ | |
bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/) | |
{ | |
sLog.outString( "Re-Loading Locales NPC Text ... "); | |
diff --git a/src/game/Map.cpp b/src/game/Map.cpp | |
index decc5bc..12a5fc2 100644 | |
--- a/src/game/Map.cpp | |
+++ b/src/game/Map.cpp | |
@@ -25,6 +25,7 @@ | |
#include "CellImpl.h" | |
#include "InstanceData.h" | |
#include "Map.h" | |
+#include "Mail.h" | |
#include "GridNotifiersImpl.h" | |
#include "Transports.h" | |
#include "ObjectAccessor.h" | |
@@ -2870,6 +2871,83 @@ void Map::ScriptsProcess() | |
break; | |
} | |
+ case SCRIPT_COMMAND_SEND_MAIL: | |
+ { | |
+ if (!target && !source) | |
+ { | |
+ sLog.outError("SCRIPT_COMMAND_SEND_MAIL (script id %u) call for NULL object.", step.script->id); | |
+ break; | |
+ } | |
+ | |
+ // only Player | |
+ if ((!target || target->GetTypeId() != TYPEID_PLAYER) && (!source || source->GetTypeId() != TYPEID_PLAYER)) | |
+ { | |
+ sLog.outError("SCRIPT_COMMAND_SEND_MAIL (script id %u) call for non-player (TypeIdSource: %u)(TypeIdTarget: %u), skipping.", step.script->id, source ? source->GetTypeId() : 0, target ? target->GetTypeId() : 0); | |
+ break; | |
+ } | |
+ | |
+ Player* pReceiver = target && target->GetTypeId() == TYPEID_PLAYER ? (Player*)target : (Player*)source; | |
+ if(!pReceiver) | |
+ break; | |
+ | |
+ if(MailTemplate const *mail_template = sObjectMgr.GetMailTemplate(step.script->datalong)) | |
+ { | |
+ MailDraft draft(mail_template->title, mail_template->text); | |
+ | |
+ if(ItemPrototype const* item1 = ObjectMgr::GetItemPrototype(mail_template->item1)) | |
+ if (Item* cItem1 = Item::CreateItem(mail_template->item1,mail_template->item1_c,pReceiver)) | |
+ { | |
+ cItem1->SaveToDB(); | |
+ draft.AddItem(cItem1); | |
+ } | |
+ | |
+ if(ItemPrototype const* item2 = ObjectMgr::GetItemPrototype(mail_template->item2)) | |
+ if (Item* cItem2 = Item::CreateItem(mail_template->item2,mail_template->item2_c,pReceiver)) | |
+ { | |
+ cItem2->SaveToDB(); | |
+ draft.AddItem(cItem2); | |
+ } | |
+ | |
+ if(ItemPrototype const* item3 = ObjectMgr::GetItemPrototype(mail_template->item3)) | |
+ if (Item* cItem3 = Item::CreateItem(mail_template->item3,mail_template->item3_c,pReceiver)) | |
+ { | |
+ cItem3->SaveToDB(); | |
+ draft.AddItem(cItem3); | |
+ } | |
+ | |
+ if(ItemPrototype const* item4 = ObjectMgr::GetItemPrototype(mail_template->item4)) | |
+ if (Item* cItem4 = Item::CreateItem(mail_template->item4,mail_template->item4_c,pReceiver)) | |
+ { | |
+ cItem4->SaveToDB(); | |
+ draft.AddItem(cItem4); | |
+ } | |
+ | |
+ if(ItemPrototype const* item5 = ObjectMgr::GetItemPrototype(mail_template->item5)) | |
+ if (Item* cItem5 = Item::CreateItem(mail_template->item5,mail_template->item5_c,pReceiver)) | |
+ { | |
+ cItem5->SaveToDB(); | |
+ draft.AddItem(cItem5); | |
+ } | |
+ | |
+ switch(step.script->datalong2) | |
+ { | |
+ case 3: // creature | |
+ draft.SendMailTo(pReceiver, MailSender(MAIL_CREATURE, step.script->datalong3)); | |
+ break; | |
+ case 4: // object | |
+ draft.SendMailTo(pReceiver, MailSender(MAIL_GAMEOBJECT, step.script->datalong3)); | |
+ break; | |
+ default: | |
+ break; | |
+ } | |
+ }else{ | |
+ sLog.outError("SCRIPT_COMMAND_SEND_MAIL (script id %u) can't find mail_template (mail_id: %u) ", step.script->id, step.script->datalong); | |
+ break; | |
+ } | |
+ | |
+ break; | |
+ } | |
+ | |
default: | |
sLog.outError("Unknown SCRIPT_COMMAND_ %u called for script id %u.",step.script->command, step.script->id); | |
break; | |
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp | |
index facd70b..7583cb9 100644 | |
--- a/src/game/ObjectMgr.cpp | |
+++ b/src/game/ObjectMgr.cpp | |
@@ -4576,6 +4576,31 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) | |
} | |
break; | |
} | |
+ case SCRIPT_COMMAND_SEND_MAIL: | |
+ { | |
+ if (!sObjectMgr.GetMailTemplate(tmp.datalong)) | |
+ { | |
+ sLog.outErrorDb("Table `%s` column datalong(mail_id) is not valid (mail_id: %u) for record id %u", | |
+ tablename, tmp.datalong, tmp.id); | |
+ continue; | |
+ } | |
+ | |
+ if( tmp.datalong2 != 3 && tmp.datalong2 != 4) | |
+ { | |
+ sLog.outErrorDb("Table '%s' Invalid value datalong2 in record id %u (only 3 or 4)", | |
+ tablename, tmp.id); | |
+ continue; | |
+ } | |
+ | |
+ if (!tmp.datalong3) | |
+ { | |
+ sLog.outErrorDb("Table '%s' empty value datalong3 in record id %u (only 3 or 4)", | |
+ tablename, tmp.id); | |
+ continue; | |
+ } | |
+ | |
+ break; | |
+ } | |
} | |
if (scripts.find(tmp.id) == scripts.end()) | |
@@ -4955,6 +4980,56 @@ void ObjectMgr::LoadGossipText() | |
delete result; | |
} | |
+void ObjectMgr::LoadMailTemplate() | |
+{ | |
+ mMailTemplateMap.clear(); | |
+ | |
+ QueryResult *result = WorldDatabase.Query("SELECT id, title, text, item1, item1_count, item2, item2_count, item3, item3_count, item4, item4_count, item5, item5_count FROM mail_template"); | |
+ | |
+ if(!result) | |
+ { | |
+ barGoLink bar(1); | |
+ | |
+ bar.step(); | |
+ | |
+ sLog.outString(); | |
+ sLog.outString(">> Loaded 0 Mail template. DB table 'mail_template' is empty."); | |
+ return; | |
+ } | |
+ | |
+ barGoLink bar((int)result->GetRowCount()); | |
+ | |
+ do | |
+ { | |
+ Field *fields = result->Fetch(); | |
+ bar.step(); | |
+ | |
+ uint32 id = fields[0].GetUInt32(); | |
+ | |
+ MailTemplate& data = mMailTemplateMap[id]; | |
+ | |
+ data.title = fields[1].GetString(); | |
+ data.text = fields[2].GetString(); | |
+ data.item1 = fields[3].GetUInt32(); // item 1 | |
+ data.item1_c = fields[4].GetUInt32(); | |
+ data.item2 = fields[5].GetUInt32(); // item 2 | |
+ data.item2_c = fields[6].GetUInt32(); | |
+ data.item3 = fields[7].GetUInt32(); // item 3 | |
+ data.item3_c = fields[8].GetUInt32(); | |
+ data.item4 = fields[9].GetUInt32(); // item 4 | |
+ data.item4_c = fields[10].GetUInt32(); | |
+ data.item5 = fields[11].GetUInt32(); // item 5 | |
+ data.item5_c = fields[12].GetUInt32(); | |
+ | |
+ | |
+ }while(result->NextRow()); | |
+ | |
+ delete result; | |
+ | |
+ sLog.outString(); | |
+ sLog.outString( ">> Loaded %lu Mail template", (unsigned long)mMailTemplateMap.size() ); | |
+} | |
+ | |
void ObjectMgr::LoadNpcTextLocales() | |
{ | |
mNpcTextLocaleMap.clear(); // need for reload case | |
diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h | |
index 78b79b9..e91027f 100644 | |
--- a/src/game/ObjectMgr.h | |
+++ b/src/game/ObjectMgr.h | |
@@ -237,6 +237,26 @@ struct MailLevelReward | |
typedef std::list<MailLevelReward> MailLevelRewardList; | |
typedef UNORDERED_MAP<uint8,MailLevelRewardList> MailLevelRewardMap; | |
+struct MailTemplate | |
+{ | |
+ std::string title; | |
+ std::string text; | |
+ | |
+ uint32 item1; // item 1 | |
+ uint32 item1_c; | |
+ uint32 item2; // item 2 | |
+ uint32 item2_c; | |
+ uint32 item3; // item 3 | |
+ uint32 item3_c; | |
+ uint32 item4; // item 4 | |
+ uint32 item4_c; | |
+ uint32 item5; // item 5 | |
+ uint32 item5_c; | |
+}; | |
+ | |
+typedef UNORDERED_MAP<uint8, MailTemplate> MailTemplateMap; | |
+ | |
+ | |
struct ReputationOnKillEntry | |
{ | |
uint32 repfaction1; | |
@@ -660,6 +680,7 @@ class ObjectMgr | |
void LoadItemRequiredTarget(); | |
void LoadItemLocales(); | |
void LoadQuestLocales(); | |
+ void LoadMailTemplate(); | |
void LoadNpcTextLocales(); | |
void LoadPageTextLocales(); | |
void LoadGossipMenuItemsLocales(); | |
@@ -742,6 +763,15 @@ class ObjectMgr | |
return NULL; | |
} | |
+ MailTemplate const* GetMailTemplate(uint32 id) const | |
+ { | |
+ MailTemplateMap::const_iterator map_itr = mMailTemplateMap.find(id); | |
+ if(map_itr != mMailTemplateMap.end()) | |
+ return &map_itr->second; | |
+ | |
+ return NULL; | |
+ } | |
+ | |
WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const | |
{ | |
WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id); | |
@@ -1073,6 +1103,7 @@ class ObjectMgr | |
GameObjectLocaleMap mGameObjectLocaleMap; | |
ItemLocaleMap mItemLocaleMap; | |
QuestLocaleMap mQuestLocaleMap; | |
+ MailTemplateMap mMailTemplateMap; | |
NpcTextLocaleMap mNpcTextLocaleMap; | |
PageTextLocaleMap mPageTextLocaleMap; | |
MangosStringLocaleMap mMangosStringLocaleMap; | |
diff --git a/src/game/World.cpp b/src/game/World.cpp | |
index 5c87bcc..e9352fc 100644 | |
--- a/src/game/World.cpp | |
+++ b/src/game/World.cpp | |
@@ -947,6 +947,7 @@ void World::SetInitialWorldSettings() | |
sObjectMgr.LoadGameObjectLocales(); | |
sObjectMgr.LoadItemLocales(); | |
sObjectMgr.LoadQuestLocales(); | |
+ sObjectMgr.LoadMailTemplate(); | |
sObjectMgr.LoadNpcTextLocales(); | |
sObjectMgr.LoadPageTextLocales(); | |
sObjectMgr.LoadGossipMenuItemsLocales(); | |
diff --git a/src/game/World.h b/src/game/World.h | |
index f7826cb..1a8c36a 100644 | |
--- a/src/game/World.h | |
+++ b/src/game/World.h | |
@@ -415,6 +415,7 @@ enum RealmZone | |
#define SCRIPT_COMMAND_CREATE_ITEM 17 // source or target must be player, datalong = item entry, datalong2 = amount | |
#define SCRIPT_COMMAND_DESPAWN_SELF 18 // source or target must be creature, datalong = despawn delay | |
#define SCRIPT_COMMAND_PLAY_MOVIE 19 // target can only be a player, datalog = movie id | |
+#define SCRIPT_COMMAND_SEND_MAIL 20 // | |
/// Storage class for commands issued for delayed execution | |
struct CliCommandHolder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment