mod-mxwow-token NPC Scripted
This commit is contained in:
		
							parent
							
								
									4f8e35d69d
								
							
						
					
					
						commit
						c61c671ecc
					
				| @ -7,6 +7,7 @@ | ||||
| #include "ScriptMgr.h" | ||||
| #include "Player.h" | ||||
| #include "Chat.h" | ||||
| #include <ScriptedGossip.h> | ||||
| 
 | ||||
| class mxwow_token : public PlayerScript | ||||
| { | ||||
| @ -55,7 +56,7 @@ public: | ||||
|                     GiveToken(player, tokenQtyDungeonNormal); | ||||
|                 } | ||||
|             } | ||||
|         }        | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void GiveToken(const Player* player, const uint32 qty) | ||||
| @ -70,13 +71,180 @@ public: | ||||
|             tQty = (*queryPlayerTokenQty)[1].Get<int>(); | ||||
|             ntQty = tQty + qty; | ||||
|             LoginDatabase.Execute("UPDATE mxw_account_token SET token='{}' WHERE aid='{}'", ntQty, aId); | ||||
|             ss << "|cffabeeff[MxW] Vous obtenez |cff00ff00%i|cffabeeff MxWToken. Vous avez un total de |cff00ff00%i|cffabeeff MxWToken."; | ||||
|             ss << "|cffabeeff[MxW] Vous obtenez |cff00ff00%i|cffabeeff MxWToken. Vous en avez un total de |cff00ff00%i|cffabeeff."; | ||||
|             ChatHandler(player->GetSession()).PSendSysMessage(ss.str().c_str(), qty, ntQty); | ||||
|         } | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| class mxwow_tokenCreature : public CreatureScript | ||||
| { | ||||
| public: | ||||
| 
 | ||||
|     mxwow_tokenCreature() : CreatureScript("mxwow_tokenCreature") { } | ||||
| 
 | ||||
|     bool OnGossipHello(Player* player, Creature* creature) override | ||||
|     { | ||||
|         if (!sConfigMgr->GetOption<bool>("MxWoW_Token.Enabled", true)) | ||||
|             return false; | ||||
| 
 | ||||
|         AddGossipItemFor(player, 10, GetItemIcon(44974, 30, 30, -18, 0) + "Mascotte(s)", GOSSIP_SENDER_MAIN, 1); | ||||
|         AddGossipItemFor(player, 10, GetItemIcon(41508, 30, 30, -18, 0) + "Monture(s)", GOSSIP_SENDER_MAIN, 2); | ||||
|         //AddGossipItemFor(player, 10, GetItemIcon(45978, 30, 30, -18, 0) + "Héritage(s)", GOSSIP_SENDER_MAIN, 3);
 | ||||
|         //AddGossipItemFor(player, 10, GetItemIcon(34803, 30, 30, -18, 0) + "Service(s)", GOSSIP_SENDER_MAIN, 4);
 | ||||
| 
 | ||||
|         SendGossipMenuFor(player, 20000000, creature->GetGUID()); | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool OnGossipSelect(Player* player, Creature* creature, uint32 page, uint32 action) override | ||||
|     { | ||||
|         player->PlayerTalkClass->ClearMenus(); | ||||
| 
 | ||||
|         if (action < 10) { | ||||
|             ShowVendor(player, creature, action); | ||||
|             return true; | ||||
|         } | ||||
|         else if (action == 10) { | ||||
|             OnGossipHello(player, creature); | ||||
|             return true; | ||||
|         } | ||||
|         else if (action > 10) { | ||||
|             uint32 price = GetPrice(action); | ||||
|             if (CheckToken(player, price)) { | ||||
|                 AdjustToken(player, price, false); | ||||
|                 ItemPosCountVec dest; | ||||
|                 InventoryResult msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, action, 1); | ||||
|                 if (msg == EQUIP_ERR_OK) | ||||
|                 { | ||||
|                     Item* item = player->StoreNewItem(dest, action, true); | ||||
|                     player->SendNewItem(item, 1, true, false); | ||||
|                 } | ||||
|                 OnGossipHello(player, creature); | ||||
|             } | ||||
|             else { | ||||
|                 OnGossipHello(player, creature); | ||||
|             } | ||||
|             return true; | ||||
|         }                         | ||||
|     } | ||||
| 
 | ||||
|     bool CheckToken(Player* player, uint32 qty) | ||||
|     { | ||||
|         std::ostringstream ss; | ||||
|         uint32 aId = player->GetSession()->GetAccountId(); | ||||
|         uint32 tQty = 0; | ||||
|         uint32 ntQty = 0; | ||||
|         QueryResult queryPlayerTokenQty = LoginDatabase.Query("SELECT * FROM mxw_account_token WHERE aid = {}", aId); | ||||
|         if (queryPlayerTokenQty) | ||||
|         { | ||||
|             tQty = (*queryPlayerTokenQty)[1].Get<int>(); | ||||
|             if (tQty >= qty) { | ||||
|                 ntQty = tQty - qty; | ||||
|                 ss << "|cffabeeff[MxW] Vous dépensez |cff00ff00%i|cffabeeff MxWToken. Il vous en reste un total de |cff00ff00%i|cffabeeff."; | ||||
|                 ChatHandler(player->GetSession()).PSendSysMessage(ss.str().c_str(), qty, ntQty); | ||||
|                 return true; | ||||
|             } | ||||
|             else { | ||||
|                 ss << "|cffabeeff[MxW] Vous n'avez pas assez de MxWToken. Vous en avez un total de |cff00ff00%i|cffabeeff."; | ||||
|                 ChatHandler(player->GetSession()).PSendSysMessage(ss.str().c_str(), tQty); | ||||
|                 return false; | ||||
|             }                       | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void AdjustToken(Player* player, uint32 qty, bool augment) | ||||
|     { | ||||
|         std::ostringstream ss; | ||||
|         uint32 aId = player->GetSession()->GetAccountId(); | ||||
|         uint32 tQty = 0; | ||||
|         uint32 ntQty = 0; | ||||
|         QueryResult queryPlayerTokenQty = LoginDatabase.Query("SELECT * FROM mxw_account_token WHERE aid = {}", aId); | ||||
|         if (queryPlayerTokenQty) | ||||
|         { | ||||
|             tQty = (*queryPlayerTokenQty)[1].Get<int>(); | ||||
|             if (augment) { | ||||
|                 ntQty = tQty + qty; | ||||
|             } | ||||
|             else { | ||||
|                 ntQty = tQty - qty; | ||||
|             } | ||||
|             LoginDatabase.Execute("UPDATE mxw_account_token SET token='{}' WHERE aid='{}'", ntQty, aId); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     uint32 GetPrice(uint32 entry) | ||||
|     { | ||||
|         QueryResult queryEntryPrice = LoginDatabase.Query("SELECT * FROM mxw_vendor_token WHERE entry = {}", entry); | ||||
|         if (queryEntryPrice) { | ||||
|             return (*queryEntryPrice)[2].Get<uint32>(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void ShowVendor(Player* player, Creature* creature, uint32 type) | ||||
|     { | ||||
|         uint32 vc = 0; | ||||
|         QueryResult queryTypeCount = LoginDatabase.Query("SELECT * FROM mxw_vendor_token WHERE type = {}", type); | ||||
|         if (queryTypeCount) { | ||||
|             vc = queryTypeCount->GetRowCount(); | ||||
|         } | ||||
|         WorldSession* session = player->GetSession(); | ||||
|         std::string query = "SELECT * FROM mxw_vendor_token WHERE type = " + std::to_string(type); | ||||
|         session->GetQueryProcessor().AddCallback(LoginDatabase.AsyncQuery(query).WithCallback([=, this](QueryResult result) | ||||
|             { | ||||
|         uint32 startValue = 0; | ||||
|         uint32 endValue = vc; | ||||
|         std::map<uint32, uint32> entryToAmountMap; | ||||
|         std::vector<uint32> itemEntries; | ||||
|         if (result) { | ||||
|             do { | ||||
|                 uint32 itemEntry = (*result)[0].Get<uint32>(); | ||||
|                 AddGossipItemFor(player, 10, GetItemIcon(itemEntry, 30, 30, -18, 0) + GetItemLink(itemEntry, session) + " " + std::to_string((*result)[2].Get<uint32>()), GOSSIP_SENDER_MAIN, itemEntry); | ||||
|             } while (result->NextRow()); | ||||
|         } | ||||
|         AddGossipItemFor(player, 10, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tRetour...", GOSSIP_SENDER_MAIN, 10); | ||||
|         SendGossipMenuFor(player, 20000000, creature->GetGUID()); | ||||
|         })); | ||||
|     } | ||||
| 
 | ||||
|     std::string GetItemLink(uint32 entry, WorldSession* session) const | ||||
|     { | ||||
|         int loc_idx = session->GetSessionDbLocaleIndex(); | ||||
|         const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry); | ||||
|         std::string name = temp->Name1; | ||||
|         if (ItemLocale const* il = sObjectMgr->GetItemLocale(temp->ItemId)) | ||||
|             ObjectMgr::GetLocaleString(il->Name, loc_idx, name); | ||||
| 
 | ||||
|         std::ostringstream oss; | ||||
|         oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec << | ||||
|             "|Hitem:" << temp->ItemId << ":" << | ||||
|             (uint32)0 << "|h[" << name << "]|h|r"; | ||||
| 
 | ||||
|         return oss.str(); | ||||
|     } | ||||
| 
 | ||||
|     std::string GetItemIcon(uint32 entry, uint32 width, uint32 height, int x, int y) const | ||||
|     { | ||||
|         std::ostringstream ss; | ||||
|         ss << "|TInterface"; | ||||
|         const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry); | ||||
|         const ItemDisplayInfoEntry* dispInfo = NULL; | ||||
|         if (temp) | ||||
|         { | ||||
|             dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID); | ||||
|             if (dispInfo) | ||||
|                 ss << "/ICONS/" << dispInfo->inventoryIcon; | ||||
|         } | ||||
|         if (!dispInfo) | ||||
|             ss << "/InventoryItems/WoWUnknownItem01"; | ||||
|         ss << ":" << width << ":" << height << ":" << x << ":" << y << "|t"; | ||||
|         return ss.str(); | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| void AddMxWoWTokenScripts() | ||||
| { | ||||
|     new mxwow_token(); | ||||
|     new mxwow_tokenCreature(); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user