First Commit

This commit is contained in:
mikx
2025-03-18 19:19:03 -04:00
commit 93073b0be2
10024 changed files with 9034050 additions and 0 deletions

View File

@@ -0,0 +1,298 @@
//// MxWoW Official Module
//// Token
//// Dev: mikx
//// Git: https://mxgit.ovh/MxWoW/mod_mxwow_token
#include "Configuration/Config.h"
#include "ScriptMgr.h"
#include "Player.h"
#include "Chat.h"
#include <ScriptedGossip.h>
class mxwow_token : public PlayerScript
{
public:
mxwow_token() : PlayerScript("mxwow_token") { }
void OnPlayerLogin(Player* player) override
{
std::ostringstream ss;
ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00MxW Token |rmodule.");
uint32 aId = player->GetSession()->GetAccountId();
QueryResult queryPlayerTokenEntry = LoginDatabase.Query("SELECT * FROM mxw_account_token WHERE aid = {}", aId);
if (!queryPlayerTokenEntry) {
LoginDatabase.Execute("INSERT INTO mxw_account_token (aid, token) VALUES ({}, {})", aId, 0);
}
else {
uint32 tokenQty = (*queryPlayerTokenEntry)[1].Get<int>();
ss << "|cffabeeff[MxW] Vous avez un total de |cff00ff00"<< tokenQty <<"|cffabeeff MxWToken.";
ChatHandler(player->GetSession()).PSendSysMessage(ss.str().c_str());
}
}
void OnPlayerCreatureKill(Player* player, Creature* boss)
{
if (sConfigMgr->GetOption<bool>("MxWoW_Token.Enabled", true)) {
uint32 tokenQtyDungeonLowLevel = sConfigMgr->GetOption<int>("MxWoW_Token.Dungeon.LowLevel", true);
uint32 tokenQtyRaidHeroic = sConfigMgr->GetOption<int>("MxWoW_Token.Raid.Heroic", true);
uint32 tokenQtyRaidNormal = sConfigMgr->GetOption<int>("MxWoW_Token.Raid.Normal", true);
uint32 tokenQtyDungeonHeroic = sConfigMgr->GetOption<int>("MxWoW_Token.Dungeon.Heroic", true);
uint32 tokenQtyDungeonNormal = sConfigMgr->GetOption<int>("MxWoW_Token.Dungeon.Normal", true);
std::string bMap;
if (!player->GetGroup()) {
if (boss->isWorldBoss()) {
if (player->GetMap()->IsHeroic()) {
GiveToken(player, tokenQtyRaidHeroic);
}
else {
GiveToken(player, tokenQtyRaidNormal);
}
}
else if (boss->IsDungeonBoss()) {
if (player->GetLevel() < 80) {
GiveToken(player, tokenQtyDungeonLowLevel);
}
else {
if (player->GetMap()->IsHeroic()) {
GiveToken(player, tokenQtyDungeonHeroic);
}
else {
GiveToken(player, tokenQtyDungeonNormal);
}
}
}
}
else {
Group* group = player->GetGroup();
Group::MemberSlotList const& groupSlot = group->GetMemberSlots();
for (Group::member_citerator itr = groupSlot.begin(); itr != groupSlot.end(); itr++)
{
Player* p = ObjectAccessor::FindPlayer(itr->guid);
if (boss->isWorldBoss()) {
if (player->GetMap()->IsHeroic()) {
GiveToken(p, tokenQtyRaidHeroic);
}
else {
GiveToken(p, tokenQtyRaidNormal);
}
}
else if (boss->IsDungeonBoss()) {
if (player->GetLevel() < 80) {
GiveToken(p, tokenQtyDungeonLowLevel);
}
else {
if (player->GetMap()->IsHeroic()) {
GiveToken(p, tokenQtyDungeonHeroic);
}
else {
GiveToken(p, tokenQtyDungeonNormal);
}
}
}
}
}
}
}
void GiveToken(const Player* player, const 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>();
ntQty = tQty + qty;
LoginDatabase.Execute("UPDATE mxw_account_token SET token='{}' WHERE aid='{}'", ntQty, aId);
ss << "|cffabeeff[MxW] Vous obtenez |cff00ff00"<<qty<<"|cffabeeff MxWToken. Vous en avez un total de |cff00ff00"<<ntQty<<"|cffabeeff.";
ChatHandler(player->GetSession()).PSendSysMessage(ss.str().c_str());
}
}
};
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;
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);
tQty = (*queryPlayerTokenQty)[1].Get<int>();
ss << "Token: "<<tQty;
AddGossipItemFor(player, 10, GetItemIcon(50355, 30, 30, -18, 0) + ss.str().c_str(), GOSSIP_SENDER_MAIN, 0);
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(41599, 30, 30, -18, 0) + "Sac(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"<<qty<<"|cffabeeff MxWToken. Il vous en reste un total de |cff00ff00"<< ntQty <<"|cffabeeff.";
ChatHandler(player->GetSession()).PSendSysMessage(ss.str().c_str());
return true;
}
else {
ss << "|cffabeeff[MxW] Vous n'avez pas assez de MxWToken. Vous en avez un total de |cff00ff00"<< tQty <<"|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();
}

View File

@@ -0,0 +1,11 @@
//// MxWoW Official Module
//// Token
//// Dev: mikx
//// Git: https://mxgit.ovh/MxWoW/mod_mxwow_token
void AddMxWoWTokenScripts();
void Addmod_mxwow_tokenScripts()
{
AddMxWoWTokenScripts();
}