Junk to Gold

This commit is contained in:
Revision
2023-05-09 22:47:28 +02:00
parent f10ffa8c1b
commit ce01d81a0c
4 changed files with 92 additions and 1 deletions

View File

@@ -1 +1,2 @@
# mod-junk-to-gold # Junk to Gold
This module will automatically sell gray items when the player loots them

1
conf/conf.sh.dist Normal file
View File

@@ -0,0 +1 @@
#!/usr/bin/env bash

8
include.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
MOD_JUNK_TO_GOLD_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )"
source $MOD_JUNK_TO_GOLD_ROOT"/conf/conf.sh.dist"
if [ -f $MOD_JUNK_TO_GOLD_ROOT"/conf/conf.sh" ]; then
source $MOD_JUNK_TO_GOLD_ROOT"/conf/conf.sh"
fi

81
src/mod_junk_to_gold.cpp Normal file
View File

@@ -0,0 +1,81 @@
#include "Chat.h"
#include "Player.h"
#include "ScriptMgr.h"
class JunkToGold : public PlayerScript
{
public:
JunkToGold() : PlayerScript("JunkToGold") {}
void OnLootItem(Player* player, Item* item, uint32 count, ObjectGuid /*lootguid*/) override
{
if (item->GetTemplate()->Quality == ITEM_QUALITY_POOR)
{
SendTransactionInformation(player, item, count);
player->ModifyMoney(item->GetTemplate()->SellPrice * count);
player->DestroyItemCount(item, count, true);
}
}
private:
void SendTransactionInformation(Player* player, Item* item, uint32 count)
{
std::string name;
if (count > 1)
{
name = Acore::StringFormat("[%s] x %i", item->GetTemplate()->Name1, count);
}
else
{
name = Acore::StringFormat("[%s]", item->GetTemplate()->Name1);
}
uint32 money = item->GetTemplate()->SellPrice * count;
uint32 gold = money / GOLD;
uint32 silver = (money % GOLD) / SILVER;
uint32 copper = (money % GOLD) % SILVER;
std::string info;
if (money < SILVER)
{
info = Acore::StringFormat("%s was sold for %i copper.", name, copper);
}
else if (money < GOLD)
{
if (copper > 0)
{
info = Acore::StringFormat("%s was sold for %i silver and %i copper.", name, silver, copper);
}
else
{
info = Acore::StringFormat("%s was sold for %i silver.", name, silver);
}
}
else
{
if (copper > 0 && silver > 0)
{
info = Acore::StringFormat("%s was sold for %i gold, %i silver and %i copper.", name, gold, silver, copper);
}
else if (copper > 0)
{
info = Acore::StringFormat("%s was sold for %i gold and %i copper.", name, gold, copper);
}
else if (silver > 0)
{
info = Acore::StringFormat("%s was sold for %i gold and %i silver.", name, gold, silver);
}
else
{
info = Acore::StringFormat("%s was sold for %i gold.", name, gold);
}
}
ChatHandler(player->GetSession()).SendSysMessage(info);
}
};
void Addmod_junk_to_goldScripts()
{
new JunkToGold();
}